diff --git a/onionshare_gui/main_window.py b/onionshare_gui/main_window.py index c2db80ec..a518ab33 100644 --- a/onionshare_gui/main_window.py +++ b/onionshare_gui/main_window.py @@ -268,8 +268,32 @@ class MainWindow(QtWidgets.QMainWindow): def closeEvent(self, e): self.common.log("MainWindow", "closeEvent") + + if self.tabs.are_tabs_active(): + # Open the warning dialog + dialog = QtWidgets.QMessageBox() + dialog.setWindowTitle(strings._("gui_quit_warning_title")) + dialog.setText(strings._("gui_quit_warning_description")) + dialog.setIcon(QtWidgets.QMessageBox.Critical) + dialog.addButton( + strings._("gui_quit_warning_quit"), QtWidgets.QMessageBox.YesRole + ) + cancel_button = dialog.addButton( + strings._("gui_quit_warning_cancel"), QtWidgets.QMessageBox.NoRole + ) + dialog.setDefaultButton(cancel_button) + reply = dialog.exec_() + + # Close + if reply == 0: + self.system_tray.hide() + e.accept() + # Cancel + else: + e.ignore() + return + self.system_tray.hide() - # TODO: Run the tab's close_event e.accept() def cleanup(self): diff --git a/onionshare_gui/tab/tab.py b/onionshare_gui/tab/tab.py index 316012c6..4b4127fd 100644 --- a/onionshare_gui/tab/tab.py +++ b/onionshare_gui/tab/tab.py @@ -500,6 +500,14 @@ class Tab(QtWidgets.QWidget): """ self.status_bar.clearMessage() + def get_mode(self): + if self.mode == self.common.gui.MODE_SHARE: + return self.share_mode + elif self.mode == self.common.gui.MODE_RECEIVE: + return self.receive_mode + else: + return self.website_mode + def persistence_button_clicked(self): self.common.log("Tab", "persistence_button_clicked") if self.tab_settings["persistent"]: @@ -531,13 +539,7 @@ class Tab(QtWidgets.QWidget): if self.tab_settings["persistent"]: dialog_text = strings._("gui_close_tab_warning_persistent_description") else: - if self.mode == self.common.gui.MODE_SHARE: - server_status = self.share_mode.server_status - elif self.mode == self.common.gui.MODE_RECEIVE: - server_status = self.receive_mode.server_status - else: - server_status = self.website_mode.server_status - + server_status = self.get_mode().server_status if server_status.status == server_status.STATUS_STOPPED: return True else: @@ -566,14 +568,7 @@ class Tab(QtWidgets.QWidget): # Close if reply == 0: self.common.log("Tab", "close_tab", "close, closing tab") - - if self.mode == self.common.gui.MODE_SHARE: - self.share_mode.stop_server() - elif self.mode == self.common.gui.MODE_RECEIVE: - self.receive_mode.stop_server() - else: - self.website_mode.stop_server() - + self.get_mode().stop_server() self.app.cleanup() return True # Cancel diff --git a/onionshare_gui/tab_widget.py b/onionshare_gui/tab_widget.py index 73dea2bd..f9e48951 100644 --- a/onionshare_gui/tab_widget.py +++ b/onionshare_gui/tab_widget.py @@ -116,6 +116,16 @@ class TabWidget(QtWidgets.QTabWidget): if self.count() == 0: self.new_tab_clicked() + def are_tabs_active(self): + """ + See if there are active servers in any open tabs + """ + for tab_id in self.tabs: + mode = self.tabs[tab_id].get_mode() + if mode.server_status.status != mode.server_status.STATUS_STOPPED: + return True + return False + def resizeEvent(self, event): # Make sure to move new tab button on each resize super(TabWidget, self).resizeEvent(event) diff --git a/share/locale/en.json b/share/locale/en.json index 387e57b3..8948d317 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -30,11 +30,6 @@ "gui_copied_hidservauth": "HidServAuth line copied to clipboard", "gui_waiting_to_start": "Scheduled to start in {}. Click to cancel.", "gui_please_wait": "Starting… Click to cancel.", - "gui_quit_title": "Not so fast", - "gui_share_quit_warning": "You're in the process of sending files. Are you sure you want to quit OnionShare?", - "gui_receive_quit_warning": "You're in the process of receiving files. Are you sure you want to quit OnionShare?", - "gui_quit_warning_quit": "Quit", - "gui_quit_warning_dont_quit": "Cancel", "error_rate_limit": "Someone has made too many wrong attempts to guess your password, so OnionShare has stopped the server. Start sharing again and send the recipient a new address to share.", "zip_progress_bar_format": "Compressing: %p%", "error_stealth_not_supported": "To use client authorization, you need at least both Tor 0.2.9.1-alpha (or Tor Browser 6.5) and python3-stem 1.5.0.", @@ -194,5 +189,9 @@ "gui_close_tab_warning_receive_description": "You're in the process of receiving files. Are you sure you want to close this tab?", "gui_close_tab_warning_website_description": "You're actively hosting a website. Are you sure you want to close this tab?", "gui_close_tab_warning_close": "Close", - "gui_close_tab_warning_cancel": "Cancel" + "gui_close_tab_warning_cancel": "Cancel", + "gui_quit_warning_title": "Are you sure?", + "gui_quit_warning_description": "Sharing is active in some of your tabs. If you quit, all of your tabs will close. Are you sure you want to quit?", + "gui_quit_warning_quit": "Quit", + "gui_quit_warning_cancel": "Cancel" } \ No newline at end of file