From e51be47844e9ec7215fe28550dd6c8d11ade7e59 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 20 Oct 2019 20:05:08 -0700 Subject: [PATCH] Move MODE_SHARE, MODE_RECEIVE, and MODE_WEBSITE into GuiCommon --- onionshare_gui/gui_common.py | 4 ++++ onionshare_gui/main_window.py | 40 +++++++++++++++------------------ onionshare_gui/server_status.py | 28 ++++++++++------------- 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/onionshare_gui/gui_common.py b/onionshare_gui/gui_common.py index fac17bd1..9964a322 100644 --- a/onionshare_gui/gui_common.py +++ b/onionshare_gui/gui_common.py @@ -24,6 +24,10 @@ class GuiCommon: The shared code for all of the OnionShare GUI. """ + MODE_SHARE = "share" + MODE_RECEIVE = "receive" + MODE_WEBSITE = "website" + def __init__(self, common): self.common = common diff --git a/onionshare_gui/main_window.py b/onionshare_gui/main_window.py index 4c26e118..de658a1b 100644 --- a/onionshare_gui/main_window.py +++ b/onionshare_gui/main_window.py @@ -39,10 +39,6 @@ class MainWindow(QtWidgets.QMainWindow): MainWindow is the OnionShare main window, which contains the GUI elements, including all open tabs """ - MODE_SHARE = "share" - MODE_RECEIVE = "receive" - MODE_WEBSITE = "website" - def __init__( self, common, onion, qtapp, app, filenames, config=False, local_only=False ): @@ -58,7 +54,7 @@ class MainWindow(QtWidgets.QMainWindow): self.app = app self.local_only = local_only - self.mode = self.MODE_SHARE + self.mode = self.common.gui.MODE_SHARE self.setWindowTitle("OnionShare") self.setWindowIcon( @@ -296,7 +292,7 @@ class MainWindow(QtWidgets.QMainWindow): def update_mode_switcher(self): # Based on the current mode, switch the mode switcher button styles, # and show and hide widgets to switch modes - if self.mode == self.MODE_SHARE: + if self.mode == self.common.gui.MODE_SHARE: self.share_mode_button.setStyleSheet( self.common.gui.css["mode_switcher_selected_style"] ) @@ -310,7 +306,7 @@ class MainWindow(QtWidgets.QMainWindow): self.receive_mode.hide() self.share_mode.show() self.website_mode.hide() - elif self.mode == self.MODE_WEBSITE: + elif self.mode == self.common.gui.MODE_WEBSITE: self.share_mode_button.setStyleSheet( self.common.gui.css["mode_switcher_unselected_style"] ) @@ -342,26 +338,26 @@ class MainWindow(QtWidgets.QMainWindow): self.update_server_status_indicator() def share_mode_clicked(self): - if self.mode != self.MODE_SHARE: + if self.mode != self.common.gui.MODE_SHARE: self.common.log("MainWindow", "share_mode_clicked") - self.mode = self.MODE_SHARE + self.mode = self.common.gui.MODE_SHARE self.update_mode_switcher() def receive_mode_clicked(self): - if self.mode != self.MODE_RECEIVE: + if self.mode != self.common.gui.MODE_RECEIVE: self.common.log("MainWindow", "receive_mode_clicked") - self.mode = self.MODE_RECEIVE + self.mode = self.common.gui.MODE_RECEIVE self.update_mode_switcher() def website_mode_clicked(self): - if self.mode != self.MODE_WEBSITE: + if self.mode != self.common.gui.MODE_WEBSITE: self.common.log("MainWindow", "website_mode_clicked") - self.mode = self.MODE_WEBSITE + self.mode = self.common.gui.MODE_WEBSITE self.update_mode_switcher() def update_server_status_indicator(self): # Set the status image - if self.mode == self.MODE_SHARE: + if self.mode == self.common.gui.MODE_SHARE: # Share mode if self.share_mode.server_status.status == ServerStatus.STATUS_STOPPED: self.server_status_image_label.setPixmap( @@ -389,7 +385,7 @@ class MainWindow(QtWidgets.QMainWindow): self.server_status_label.setText( strings._("gui_status_indicator_share_started") ) - elif self.mode == self.MODE_WEBSITE: + elif self.mode == self.common.gui.MODE_WEBSITE: # Website mode if self.website_mode.server_status.status == ServerStatus.STATUS_STOPPED: self.server_status_image_label.setPixmap( @@ -591,9 +587,9 @@ class MainWindow(QtWidgets.QMainWindow): self.website_mode.handle_tor_broke() # Process events from the web object - if self.mode == self.MODE_SHARE: + if self.mode == self.common.gui.MODE_SHARE: mode = self.share_mode - elif self.mode == self.MODE_WEBSITE: + elif self.mode == self.common.gui.MODE_WEBSITE: mode = self.website_mode else: mode = self.receive_mode @@ -700,11 +696,11 @@ class MainWindow(QtWidgets.QMainWindow): """ if active: self.settings_button.hide() - if self.mode == self.MODE_SHARE: + if self.mode == self.common.gui.MODE_SHARE: self.share_mode_button.show() self.receive_mode_button.hide() self.website_mode_button.hide() - elif self.mode == self.MODE_WEBSITE: + elif self.mode == self.common.gui.MODE_WEBSITE: self.share_mode_button.hide() self.receive_mode_button.hide() self.website_mode_button.show() @@ -725,9 +721,9 @@ class MainWindow(QtWidgets.QMainWindow): self.common.log("MainWindow", "closeEvent") self.system_tray.hide() try: - if self.mode == OnionShareGui.MODE_SHARE: + if self.mode == self.common.gui.MODE_WEBSITE: server_status = self.share_mode.server_status - if self.mode == OnionShareGui.MODE_WEBSITE: + if self.mode == self.common.gui.MODE_WEBSITE: server_status = self.website_mode.server_status else: server_status = self.receive_mode.server_status @@ -735,7 +731,7 @@ class MainWindow(QtWidgets.QMainWindow): self.common.log("MainWindow", "closeEvent, opening warning dialog") dialog = QtWidgets.QMessageBox() dialog.setWindowTitle(strings._("gui_quit_title")) - if self.mode == OnionShareGui.MODE_SHARE: + if self.mode == self.common.gui.MODE_WEBSITE: dialog.setText(strings._("gui_share_quit_warning")) else: dialog.setText(strings._("gui_receive_quit_warning")) diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py index f1ec4559..18352109 100644 --- a/onionshare_gui/server_status.py +++ b/onionshare_gui/server_status.py @@ -39,10 +39,6 @@ class ServerStatus(QtWidgets.QWidget): url_copied = QtCore.pyqtSignal() hidservauth_copied = QtCore.pyqtSignal() - MODE_SHARE = "share" - MODE_RECEIVE = "receive" - MODE_WEBSITE = "website" - STATUS_STOPPED = 0 STATUS_WORKING = 1 STATUS_STARTED = 2 @@ -192,8 +188,8 @@ class ServerStatus(QtWidgets.QWidget): """ self.mode = share_mode - if (self.mode == ServerStatus.MODE_SHARE) or ( - self.mode == ServerStatus.MODE_WEBSITE + if (self.mode == self.common.gui.MODE_SHARE) or ( + self.mode == self.common.gui.MODE_WEBSITE ): self.file_selection = file_selection @@ -248,11 +244,11 @@ class ServerStatus(QtWidgets.QWidget): info_image = self.common.get_resource_path("images/info.png") - if self.mode == ServerStatus.MODE_SHARE: + if self.mode == self.common.gui.MODE_SHARE: self.url_description.setText( strings._("gui_share_url_description").format(info_image) ) - elif self.mode == ServerStatus.MODE_WEBSITE: + elif self.mode == self.common.gui.MODE_WEBSITE: self.url_description.setText( strings._("gui_website_url_description").format(info_image) ) @@ -263,7 +259,7 @@ class ServerStatus(QtWidgets.QWidget): # Show a Tool Tip explaining the lifecycle of this URL if self.common.settings.get("save_private_key"): - if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get( + if self.mode == self.common.gui.MODE_SHARE and self.common.settings.get( "close_after_first_download" ): self.url_description.setToolTip( @@ -272,7 +268,7 @@ class ServerStatus(QtWidgets.QWidget): else: self.url_description.setToolTip(strings._("gui_url_label_persistent")) else: - if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get( + if self.mode == self.common.gui.MODE_SHARE and self.common.settings.get( "close_after_first_download" ): self.url_description.setToolTip(strings._("gui_url_label_onetime")) @@ -317,12 +313,12 @@ class ServerStatus(QtWidgets.QWidget): # Button if ( - self.mode == ServerStatus.MODE_SHARE + self.mode == self.common.gui.MODE_SHARE and self.file_selection.get_num_files() == 0 ): self.server_button.hide() elif ( - self.mode == ServerStatus.MODE_WEBSITE + self.mode == self.common.gui.MODE_WEBSITE and self.file_selection.get_num_files() == 0 ): self.server_button.hide() @@ -334,9 +330,9 @@ class ServerStatus(QtWidgets.QWidget): self.common.gui.css["server_status_button_stopped"] ) self.server_button.setEnabled(True) - if self.mode == ServerStatus.MODE_SHARE: + if self.mode == self.common.gui.MODE_SHARE: self.server_button.setText(strings._("gui_share_start_server")) - elif self.mode == ServerStatus.MODE_WEBSITE: + elif self.mode == self.common.gui.MODE_WEBSITE: self.server_button.setText(strings._("gui_share_start_server")) else: self.server_button.setText(strings._("gui_receive_start_server")) @@ -350,9 +346,9 @@ class ServerStatus(QtWidgets.QWidget): self.common.gui.css["server_status_button_started"] ) self.server_button.setEnabled(True) - if self.mode == ServerStatus.MODE_SHARE: + if self.mode == self.common.gui.MODE_SHARE: self.server_button.setText(strings._("gui_share_stop_server")) - elif self.mode == ServerStatus.MODE_WEBSITE: + elif self.mode == self.common.gui.MODE_WEBSITE: self.server_button.setText(strings._("gui_share_stop_server")) else: self.server_button.setText(strings._("gui_receive_stop_server"))