mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-25 15:29:42 -05:00
Updates autoconnect to use tab widget
This commit is contained in:
parent
3422364fa1
commit
3283fb7607
@ -24,16 +24,25 @@ from onionshare_cli.settings import Settings
|
|||||||
|
|
||||||
from . import strings
|
from . import strings
|
||||||
from .gui_common import GuiCommon
|
from .gui_common import GuiCommon
|
||||||
|
from .tor_connection import TorConnectionWidget
|
||||||
|
|
||||||
|
|
||||||
class AutoConnect(QtWidgets.QWidget):
|
class AutoConnectTab(QtWidgets.QWidget):
|
||||||
"""
|
"""
|
||||||
GUI window that appears in the very beginning to ask user if
|
Initial Tab that appears in the very beginning to ask user if
|
||||||
should auto connect.
|
should auto connect.
|
||||||
"""
|
"""
|
||||||
def __init__(self, common, parent=None):
|
|
||||||
super(AutoConnect, self).__init__(parent)
|
close_this_tab = QtCore.Signal()
|
||||||
common.log("AutoConnect", "__init__")
|
tor_is_connected = QtCore.Signal()
|
||||||
|
tor_is_disconnected = QtCore.Signal()
|
||||||
|
def __init__(self, common, tab_id, status_bar):
|
||||||
|
super(AutoConnectTab, self).__init__()
|
||||||
|
self.common = common
|
||||||
|
self.common.log("AutoConnectTab", "__init__")
|
||||||
|
|
||||||
|
self.status_bar = status_bar
|
||||||
|
self.tab_id = tab_id
|
||||||
|
|
||||||
# Was auto connected?
|
# Was auto connected?
|
||||||
self.curr_settings = Settings(common)
|
self.curr_settings = Settings(common)
|
||||||
@ -76,8 +85,20 @@ class AutoConnect(QtWidgets.QWidget):
|
|||||||
description_widget = QtWidgets.QWidget()
|
description_widget = QtWidgets.QWidget()
|
||||||
description_widget.setLayout(description_layout)
|
description_widget.setLayout(description_layout)
|
||||||
|
|
||||||
|
# Tor connection widget
|
||||||
|
self.tor_con = TorConnectionWidget(self.common, self.status_bar)
|
||||||
|
self.tor_con.success.connect(self.tor_con_success)
|
||||||
|
self.tor_con.fail.connect(self.tor_con_fail)
|
||||||
|
self.tor_con.hide()
|
||||||
|
|
||||||
|
# Error label
|
||||||
|
self.error_label = QtWidgets.QLabel()
|
||||||
|
self.error_label.setStyleSheet(self.common.gui.css["tor_settings_error"])
|
||||||
|
self.error_label.setWordWrap(True)
|
||||||
|
|
||||||
# CTA buttons
|
# CTA buttons
|
||||||
self.connect_button = QtWidgets.QPushButton(strings._("gui_autoconnect_start"))
|
self.connect_button = QtWidgets.QPushButton(strings._("gui_autoconnect_start"))
|
||||||
|
self.connect_button.clicked.connect(self.connect_clicked)
|
||||||
self.connect_button.setStyleSheet(
|
self.connect_button.setStyleSheet(
|
||||||
common.gui.css["autoconnect_start_button"]
|
common.gui.css["autoconnect_start_button"]
|
||||||
)
|
)
|
||||||
@ -98,6 +119,7 @@ class AutoConnect(QtWidgets.QWidget):
|
|||||||
content_layout.addStretch()
|
content_layout.addStretch()
|
||||||
content_layout.addWidget(self.image)
|
content_layout.addWidget(self.image)
|
||||||
content_layout.addWidget(description_widget)
|
content_layout.addWidget(description_widget)
|
||||||
|
content_layout.addWidget(self.tor_con)
|
||||||
content_layout.addWidget(cta_widget)
|
content_layout.addWidget(cta_widget)
|
||||||
content_layout.addStretch()
|
content_layout.addStretch()
|
||||||
content_layout.setAlignment(QtCore.Qt.AlignCenter)
|
content_layout.setAlignment(QtCore.Qt.AlignCenter)
|
||||||
@ -111,7 +133,52 @@ class AutoConnect(QtWidgets.QWidget):
|
|||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
def toggle_auto_connect(self):
|
def toggle_auto_connect(self):
|
||||||
|
"""
|
||||||
|
Auto connect checkbox clicked
|
||||||
|
"""
|
||||||
|
self.common.log("AutoConnectTab", "autoconnect_checkbox_clicked")
|
||||||
self.curr_settings.set(
|
self.curr_settings.set(
|
||||||
"auto_connect", self.enable_autoconnect_checkbox.isChecked()
|
"auto_connect", self.enable_autoconnect_checkbox.isChecked()
|
||||||
)
|
)
|
||||||
self.curr_settings.save()
|
self.curr_settings.save()
|
||||||
|
|
||||||
|
def connect_clicked(self):
|
||||||
|
"""
|
||||||
|
Connect button clicked. Try to connect to tor.
|
||||||
|
"""
|
||||||
|
self.common.log("AutoConnectTab", "connect_clicked")
|
||||||
|
|
||||||
|
self.error_label.setText("")
|
||||||
|
self.connect_button.hide()
|
||||||
|
self.configure_button.hide()
|
||||||
|
|
||||||
|
if not self.common.gui.local_only:
|
||||||
|
self.tor_con.show()
|
||||||
|
self.tor_con.start(self.curr_settings)
|
||||||
|
else:
|
||||||
|
self.close_this_tab.emit()
|
||||||
|
|
||||||
|
def tor_con_success(self):
|
||||||
|
"""
|
||||||
|
Finished testing tor connection.
|
||||||
|
"""
|
||||||
|
self.tor_con.hide()
|
||||||
|
self.connect_button.show()
|
||||||
|
self.configure_button.show()
|
||||||
|
if (
|
||||||
|
self.common.gui.onion.is_authenticated()
|
||||||
|
and not self.tor_con.wasCanceled()
|
||||||
|
):
|
||||||
|
# Tell the tabs that Tor is connected
|
||||||
|
self.tor_is_connected.emit()
|
||||||
|
# Close the tab
|
||||||
|
self.close_this_tab.emit()
|
||||||
|
|
||||||
|
def tor_con_fail(self, msg):
|
||||||
|
"""
|
||||||
|
Finished testing tor connection.
|
||||||
|
"""
|
||||||
|
self.tor_con.hide()
|
||||||
|
self.connect_button.show()
|
||||||
|
self.configure_button.show()
|
||||||
|
self.error_label.setText(msg)
|
@ -155,19 +155,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
layout = QtWidgets.QVBoxLayout()
|
layout = QtWidgets.QVBoxLayout()
|
||||||
layout.addWidget(self.tabs)
|
layout.addWidget(self.tabs)
|
||||||
|
|
||||||
self.connected_central_widget = QtWidgets.QWidget()
|
central_widget = QtWidgets.QWidget()
|
||||||
self.connected_central_widget.setLayout(layout)
|
central_widget.setLayout(layout)
|
||||||
|
self.setCentralWidget(central_widget)
|
||||||
|
self.show()
|
||||||
# Auto connect OnionShare?
|
|
||||||
auto_connect = AutoConnect(self.common, self)
|
|
||||||
if not auto_connect.auto_connect_enabled:
|
|
||||||
auto_connect.configure_button.clicked.connect(
|
|
||||||
lambda: self.open_tor_settings("autoconnect")
|
|
||||||
)
|
|
||||||
auto_connect.connect_button.clicked.connect(self.start_onionshare)
|
|
||||||
self.setCentralWidget(auto_connect)
|
|
||||||
self.show()
|
|
||||||
|
|
||||||
# Create the close warning dialog -- the dialog widget needs to be in the constructor
|
# Create the close warning dialog -- the dialog widget needs to be in the constructor
|
||||||
# in order to test it
|
# in order to test it
|
||||||
@ -183,25 +174,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
)
|
)
|
||||||
self.close_dialog.setDefaultButton(self.close_dialog.reject_button)
|
self.close_dialog.setDefaultButton(self.close_dialog.reject_button)
|
||||||
|
|
||||||
def start_onionshare(self):
|
|
||||||
"""
|
|
||||||
Once the user clicks on connect in the initial screen, start tor connection
|
|
||||||
and show new tab screen
|
|
||||||
"""
|
|
||||||
self.setCentralWidget(self.connected_central_widget)
|
|
||||||
self.show()
|
|
||||||
|
|
||||||
# Start the "Connecting to Tor" dialog, which calls onion.connect()
|
|
||||||
tor_con = TorConnectionDialog(self.common)
|
|
||||||
tor_con.canceled.connect(self.tor_connection_canceled)
|
|
||||||
tor_con.open_tor_settings.connect(self.tor_connection_open_tor_settings)
|
|
||||||
if not self.common.gui.local_only:
|
|
||||||
tor_con.start()
|
|
||||||
self.settings_have_changed()
|
|
||||||
|
|
||||||
# After connecting to Tor, check for updates
|
|
||||||
self.check_for_updates()
|
|
||||||
|
|
||||||
def tor_connection_canceled(self):
|
def tor_connection_canceled(self):
|
||||||
"""
|
"""
|
||||||
If the user cancels before Tor finishes connecting, ask if they want to
|
If the user cancels before Tor finishes connecting, ask if they want to
|
||||||
|
@ -28,6 +28,7 @@ from .threads import EventHandlerThread
|
|||||||
from .gui_common import GuiCommon
|
from .gui_common import GuiCommon
|
||||||
from .tor_settings_tab import TorSettingsTab
|
from .tor_settings_tab import TorSettingsTab
|
||||||
from .settings_tab import SettingsTab
|
from .settings_tab import SettingsTab
|
||||||
|
from .connection_tab import AutoConnectTab
|
||||||
|
|
||||||
|
|
||||||
class TabWidget(QtWidgets.QTabWidget):
|
class TabWidget(QtWidgets.QTabWidget):
|
||||||
@ -98,6 +99,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
if not (
|
if not (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsTab
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
or type(self.tabs[tab_id]) is TorSettingsTab
|
||||||
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
self.tabs[tab_id].cleanup()
|
self.tabs[tab_id].cleanup()
|
||||||
|
|
||||||
@ -138,6 +140,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
if (
|
if (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsTab
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
or type(self.tabs[tab_id]) is TorSettingsTab
|
||||||
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
# Blank the server status indicator
|
# Blank the server status indicator
|
||||||
self.status_bar.server_status_image_label.clear()
|
self.status_bar.server_status_image_label.clear()
|
||||||
@ -159,8 +162,12 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def new_tab_clicked(self):
|
def new_tab_clicked(self):
|
||||||
# Create a new tab
|
# if already connected to tor, create a new tab
|
||||||
self.add_tab()
|
# Else open the initial connection tab
|
||||||
|
if self.common.gui.onion.is_authenticated():
|
||||||
|
self.add_tab()
|
||||||
|
else:
|
||||||
|
self.open_connection_tab()
|
||||||
|
|
||||||
def load_tab(self, mode_settings_id):
|
def load_tab(self, mode_settings_id):
|
||||||
# Load the tab's mode settings
|
# Load the tab's mode settings
|
||||||
@ -198,6 +205,22 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
# Bring the window to front, in case this is being added by an event
|
# Bring the window to front, in case this is being added by an event
|
||||||
self.bring_to_front.emit()
|
self.bring_to_front.emit()
|
||||||
|
|
||||||
|
def open_connection_tab(self):
|
||||||
|
self.common.log("TabWidget", "open_connection_tab")
|
||||||
|
|
||||||
|
# See if a connection tab is already open, and if so switch to it
|
||||||
|
for tab_id in self.tabs:
|
||||||
|
if type(self.tabs[tab_id]) is AutoConnectTab:
|
||||||
|
self.setCurrentIndex(self.indexOf(self.tabs[tab_id]))
|
||||||
|
return
|
||||||
|
|
||||||
|
connection_tab = AutoConnectTab(self.common, self.current_tab_id, self.status_bar)
|
||||||
|
connection_tab.close_this_tab.connect(self.close_connection_tab)
|
||||||
|
self.tabs[self.current_tab_id] = connection_tab
|
||||||
|
self.current_tab_id += 1
|
||||||
|
index = self.addTab(connection_tab, strings._("gui_settings_window_title"))
|
||||||
|
self.setCurrentIndex(index)
|
||||||
|
|
||||||
def open_settings_tab(self):
|
def open_settings_tab(self):
|
||||||
self.common.log("TabWidget", "open_settings_tab")
|
self.common.log("TabWidget", "open_settings_tab")
|
||||||
|
|
||||||
@ -281,6 +304,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
if not (
|
if not (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsTab
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
or type(self.tabs[tab_id]) is TorSettingsTab
|
||||||
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
tab = self.widget(self.indexOf(self.tabs[tab_id]))
|
tab = self.widget(self.indexOf(self.tabs[tab_id]))
|
||||||
if tab.settings.get("persistent", "enabled"):
|
if tab.settings.get("persistent", "enabled"):
|
||||||
@ -298,6 +322,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
if (
|
if (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsTab
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
or type(self.tabs[tab_id]) is TorSettingsTab
|
||||||
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
self.common.log("TabWidget", "closing a settings tab")
|
self.common.log("TabWidget", "closing a settings tab")
|
||||||
|
|
||||||
@ -333,6 +358,14 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
else:
|
else:
|
||||||
self.common.log("TabWidget", "user does not want to close the tab")
|
self.common.log("TabWidget", "user does not want to close the tab")
|
||||||
|
|
||||||
|
def close_connection_tab(self):
|
||||||
|
self.common.log("TabWidget", "close_connection_tab")
|
||||||
|
for tab_id in self.tabs:
|
||||||
|
if type(self.tabs[tab_id]) is AutoConnectTab:
|
||||||
|
index = self.indexOf(self.tabs[tab_id])
|
||||||
|
self.close_tab(index)
|
||||||
|
return
|
||||||
|
|
||||||
def close_settings_tab(self):
|
def close_settings_tab(self):
|
||||||
self.common.log("TabWidget", "close_settings_tab")
|
self.common.log("TabWidget", "close_settings_tab")
|
||||||
for tab_id in self.tabs:
|
for tab_id in self.tabs:
|
||||||
@ -357,6 +390,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
if not (
|
if not (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsTab
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
or type(self.tabs[tab_id]) is TorSettingsTab
|
||||||
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
mode = self.tabs[tab_id].get_mode()
|
mode = self.tabs[tab_id].get_mode()
|
||||||
if mode:
|
if mode:
|
||||||
@ -381,7 +415,10 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
if type(self.tabs[tab_id]) is SettingsTab:
|
if type(self.tabs[tab_id]) is SettingsTab:
|
||||||
self.tabs[tab_id].tor_is_connected()
|
self.tabs[tab_id].tor_is_connected()
|
||||||
else:
|
else:
|
||||||
if not type(self.tabs[tab_id]) is TorSettingsTab:
|
if not (
|
||||||
|
type(self.tabs[tab_id]) is TorSettingsTab
|
||||||
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
|
):
|
||||||
mode = self.tabs[tab_id].get_mode()
|
mode = self.tabs[tab_id].get_mode()
|
||||||
if mode:
|
if mode:
|
||||||
mode.tor_connection_started()
|
mode.tor_connection_started()
|
||||||
@ -391,7 +428,10 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
if type(self.tabs[tab_id]) is SettingsTab:
|
if type(self.tabs[tab_id]) is SettingsTab:
|
||||||
self.tabs[tab_id].tor_is_disconnected()
|
self.tabs[tab_id].tor_is_disconnected()
|
||||||
else:
|
else:
|
||||||
if not type(self.tabs[tab_id]) is TorSettingsTab:
|
if not (
|
||||||
|
type(self.tabs[tab_id]) is TorSettingsTab
|
||||||
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
|
):
|
||||||
mode = self.tabs[tab_id].get_mode()
|
mode = self.tabs[tab_id].get_mode()
|
||||||
if mode:
|
if mode:
|
||||||
mode.tor_connection_stopped()
|
mode.tor_connection_stopped()
|
||||||
|
Loading…
Reference in New Issue
Block a user