In all modes, if Tor isn't connected display a message instead of showing the mode content

This commit is contained in:
Micah Lee 2021-11-06 20:05:20 -07:00
parent 1d4d841239
commit 8919e2924b
10 changed files with 98 additions and 19 deletions

View File

@ -281,6 +281,11 @@ class GuiCommon:
QLabel { QLabel {
color: #cc0000; color: #cc0000;
}""", }""",
"tor_not_connected_label": """
QLabel {
font-size: 16px;
font-style: italic;
}""",
# New tab # New tab
"new_tab_button_image": """ "new_tab_button_image": """
QLabel { QLabel {

View File

@ -229,5 +229,6 @@
"moat_captcha_reload": "Reload", "moat_captcha_reload": "Reload",
"moat_bridgedb_error": "Error contacting BridgeDB.", "moat_bridgedb_error": "Error contacting BridgeDB.",
"moat_captcha_error": "The solution is not correct. Please try again.", "moat_captcha_error": "The solution is not correct. Please try again.",
"moat_solution_empty_error": "You must enter the characters from the image" "moat_solution_empty_error": "You must enter the characters from the image",
"mode_tor_not_connected_label": "OnionShare is not connected to the Tor network"
} }

View File

@ -28,7 +28,7 @@ from .mode_settings_widget import ModeSettingsWidget
from ..server_status import ServerStatus from ..server_status import ServerStatus
from ... import strings from ... import strings
from ...threads import OnionThread, AutoStartTimer from ...threads import OnionThread, AutoStartTimer
from ...widgets import Alert from ...widgets import Alert, MinimumSizeWidget
class Mode(QtWidgets.QWidget): class Mode(QtWidgets.QWidget):
@ -101,6 +101,35 @@ class Mode(QtWidgets.QWidget):
self.primary_action = QtWidgets.QWidget() self.primary_action = QtWidgets.QWidget()
self.primary_action.setLayout(self.primary_action_layout) self.primary_action.setLayout(self.primary_action_layout)
# It's up to the downstream Mode to add stuff to self.content_layout
# self.content_layout shows the actual content of the mode
# self.tor_not_connected_layout is displayed when Tor isn't connected
self.content_layout = QtWidgets.QVBoxLayout()
self.content_widget = QtWidgets.QWidget()
self.content_widget.setLayout(self.content_layout)
tor_not_connected_label = QtWidgets.QLabel(
strings._("mode_tor_not_connected_label")
)
tor_not_connected_label.setAlignment(QtCore.Qt.AlignHCenter)
tor_not_connected_label.setStyleSheet(
self.common.gui.css["tor_not_connected_label"]
)
self.tor_not_connected_layout = QtWidgets.QVBoxLayout()
self.tor_not_connected_layout.addStretch()
self.tor_not_connected_layout.addWidget(tor_not_connected_label)
self.tor_not_connected_layout.addWidget(MinimumSizeWidget(700, 0))
self.tor_not_connected_layout.addStretch()
self.tor_not_connected_widget = QtWidgets.QWidget()
self.tor_not_connected_widget.setLayout(self.tor_not_connected_layout)
self.wrapper_layout = QtWidgets.QVBoxLayout()
self.wrapper_layout.addWidget(self.content_widget)
self.wrapper_layout.addWidget(self.tor_not_connected_widget)
self.setLayout(self.wrapper_layout)
self.tor_connection_init()
def init(self): def init(self):
""" """
Add custom initialization here. Add custom initialization here.
@ -524,3 +553,26 @@ class Mode(QtWidgets.QWidget):
Used in both Share and Website modes, so implemented here. Used in both Share and Website modes, so implemented here.
""" """
self.history.cancel(event["data"]["id"]) self.history.cancel(event["data"]["id"])
def tor_connection_init(self):
"""
Figure out if Tor is connected and display the right widget
"""
if self.common.gui.onion.is_authenticated():
self.tor_connection_started()
else:
self.tor_connection_stopped()
def tor_connection_started(self):
"""
This is called on every Mode when Tor is connected
"""
self.content_widget.show()
self.tor_not_connected_widget.hide()
def tor_connection_stopped(self):
"""
This is called on every Mode when Tor is disconnected
"""
self.content_widget.hide()
self.tor_not_connected_widget.show()

View File

@ -98,10 +98,8 @@ class ChatMode(Mode):
self.column_layout.addWidget(self.image) self.column_layout.addWidget(self.image)
self.column_layout.addLayout(self.main_layout) self.column_layout.addLayout(self.main_layout)
# Wrapper layout # Content layout
self.wrapper_layout = QtWidgets.QVBoxLayout() self.content_layout.addLayout(self.column_layout)
self.wrapper_layout.addLayout(self.column_layout)
self.setLayout(self.wrapper_layout)
def get_type(self): def get_type(self):
""" """

View File

@ -198,10 +198,8 @@ class ReceiveMode(Mode):
self.column_layout.addLayout(row_layout) self.column_layout.addLayout(row_layout)
self.column_layout.addWidget(self.history, stretch=1) self.column_layout.addWidget(self.history, stretch=1)
# Wrapper layout # Content layout
self.wrapper_layout = QtWidgets.QVBoxLayout() self.content_layout.addLayout(self.column_layout)
self.wrapper_layout.addLayout(self.column_layout)
self.setLayout(self.wrapper_layout)
def get_type(self): def get_type(self):
""" """

View File

@ -169,10 +169,8 @@ class ShareMode(Mode):
self.column_layout.addLayout(self.main_layout) self.column_layout.addLayout(self.main_layout)
self.column_layout.addWidget(self.history, stretch=1) self.column_layout.addWidget(self.history, stretch=1)
# Wrapper layout # Content layout
self.wrapper_layout = QtWidgets.QVBoxLayout() self.content_layout.addLayout(self.column_layout)
self.wrapper_layout.addLayout(self.column_layout)
self.setLayout(self.wrapper_layout)
# Always start with focus on file selection # Always start with focus on file selection
self.file_selection.setFocus() self.file_selection.setFocus()

View File

@ -167,10 +167,8 @@ class WebsiteMode(Mode):
self.column_layout.addLayout(self.main_layout) self.column_layout.addLayout(self.main_layout)
self.column_layout.addWidget(self.history, stretch=1) self.column_layout.addWidget(self.history, stretch=1)
# Wrapper layout # Content layout
self.wrapper_layout = QtWidgets.QVBoxLayout() self.content_layout.addLayout(self.column_layout)
self.wrapper_layout.addLayout(self.column_layout)
self.setLayout(self.wrapper_layout)
# Always start with focus on file selection # Always start with focus on file selection
self.file_selection.setFocus() self.file_selection.setFocus()

View File

@ -96,7 +96,6 @@ class Tab(QtWidgets.QWidget):
tab_id, tab_id,
system_tray, system_tray,
status_bar, status_bar,
mode_settings=None,
filenames=None, filenames=None,
): ):
super(Tab, self).__init__() super(Tab, self).__init__()

View File

@ -235,6 +235,8 @@ class TabWidget(QtWidgets.QTabWidget):
self.common, self.current_tab_id, self.are_tabs_active(), self.status_bar self.common, self.current_tab_id, self.are_tabs_active(), self.status_bar
) )
self.tor_settings_tab.close_this_tab.connect(self.close_tor_settings_tab) self.tor_settings_tab.close_this_tab.connect(self.close_tor_settings_tab)
self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected)
self.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected)
self.tabs[self.current_tab_id] = self.tor_settings_tab self.tabs[self.current_tab_id] = self.tor_settings_tab
self.current_tab_id += 1 self.current_tab_id += 1
index = self.addTab( index = self.addTab(
@ -399,6 +401,26 @@ class TabWidget(QtWidgets.QTabWidget):
close_button.clicked.connect(close_tab) close_button.clicked.connect(close_tab)
self.tabBar().setTabButton(index, QtWidgets.QTabBar.RightSide, tab.close_button) self.tabBar().setTabButton(index, QtWidgets.QTabBar.RightSide, tab.close_button)
def tor_is_connected(self):
for tab_id in self.tabs:
if not (
type(self.tabs[tab_id]) is SettingsTab
or type(self.tabs[tab_id]) is TorSettingsTab
):
mode = self.tabs[tab_id].get_mode()
if mode:
mode.tor_connection_started()
def tor_is_disconnected(self):
for tab_id in self.tabs:
if not (
type(self.tabs[tab_id]) is SettingsTab
or type(self.tabs[tab_id]) is TorSettingsTab
):
mode = self.tabs[tab_id].get_mode()
if mode:
mode.tor_connection_stopped()
class TabBar(QtWidgets.QTabBar): class TabBar(QtWidgets.QTabBar):
""" """

View File

@ -40,6 +40,8 @@ class TorSettingsTab(QtWidgets.QWidget):
""" """
close_this_tab = QtCore.Signal() close_this_tab = QtCore.Signal()
tor_is_connected = QtCore.Signal()
tor_is_disconnected = QtCore.Signal()
def __init__(self, common, tab_id, are_tabs_active, status_bar): def __init__(self, common, tab_id, are_tabs_active, status_bar):
super(TorSettingsTab, self).__init__() super(TorSettingsTab, self).__init__()
@ -699,6 +701,9 @@ class TorSettingsTab(QtWidgets.QWidget):
# Do we need to reinitialize Tor? # Do we need to reinitialize Tor?
if reboot_onion: if reboot_onion:
# Tell the tabs that Tor is disconnected
self.tor_is_disconnected.emit()
# Reinitialize the Onion object # Reinitialize the Onion object
self.common.log( self.common.log(
"TorSettingsTab", "save_clicked", "rebooting the Onion" "TorSettingsTab", "save_clicked", "rebooting the Onion"
@ -742,6 +747,9 @@ class TorSettingsTab(QtWidgets.QWidget):
self.common.gui.onion.is_authenticated() self.common.gui.onion.is_authenticated()
and not self.tor_con.wasCanceled() 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() self.close_this_tab.emit()
self.tor_con_type = None self.tor_con_type = None