Add warning about closing a persistent tab

This commit is contained in:
Micah Lee 2019-10-27 16:01:30 -07:00
parent 216fbd4e87
commit 654fccc009
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 51 additions and 44 deletions

View File

@ -117,7 +117,7 @@ class Tab(QtWidgets.QWidget):
self.timer.timeout.connect(self.timer_callback) self.timer.timeout.connect(self.timer_callback)
# Settings for this tab # Settings for this tab
self.tab_settings = {"persistence": False} self.tab_settings = {"persistent": False}
# Persistence button # Persistence button
self.persistence_button = QtWidgets.QPushButton() self.persistence_button = QtWidgets.QPushButton()
@ -502,15 +502,15 @@ class Tab(QtWidgets.QWidget):
def persistence_button_clicked(self): def persistence_button_clicked(self):
self.common.log("Tab", "persistence_button_clicked") self.common.log("Tab", "persistence_button_clicked")
if self.tab_settings["persistence"]: if self.tab_settings["persistent"]:
self.tab_settings["persistence"] = False self.tab_settings["persistent"] = False
else: else:
self.tab_settings["persistence"] = True self.tab_settings["persistent"] = True
self.update_persistence_button() self.update_persistence_button()
def update_persistence_button(self): def update_persistence_button(self):
self.common.log("Tab", "update_persistence_button") self.common.log("Tab", "update_persistence_button")
if self.tab_settings["persistence"]: if self.tab_settings["persistent"]:
self.persistence_button.setIcon( self.persistence_button.setIcon(
QtGui.QIcon( QtGui.QIcon(
self.common.get_resource_path("images/persistent_enabled.png") self.common.get_resource_path("images/persistent_enabled.png")
@ -528,52 +528,58 @@ class Tab(QtWidgets.QWidget):
if self.mode is None: if self.mode is None:
return True return True
if self.mode == self.common.gui.MODE_SHARE: if self.tab_settings["persistent"]:
server_status = self.share_mode.server_status dialog_text = strings._("gui_close_tab_warning_persistent_description")
elif self.mode == self.common.gui.MODE_RECEIVE:
server_status = self.receive_mode.server_status
else: else:
server_status = self.website_mode.server_status
if server_status.status == server_status.STATUS_STOPPED:
return True
else:
self.common.log("Tab", "close_tab, opening warning dialog")
dialog = QtWidgets.QMessageBox()
dialog.setWindowTitle(strings._("gui_close_tab_warning_title"))
if self.mode == self.common.gui.MODE_SHARE: if self.mode == self.common.gui.MODE_SHARE:
dialog.setText(strings._("gui_close_tab_warning_share_description")) server_status = self.share_mode.server_status
elif self.mode == self.common.gui.MODE_RECEIVE: elif self.mode == self.common.gui.MODE_RECEIVE:
dialog.setText(strings._("gui_close_tab_warning_receive_description")) server_status = self.receive_mode.server_status
else: else:
dialog.setText(strings._("gui_close_tab_warning_website_description")) server_status = self.website_mode.server_status
dialog.setIcon(QtWidgets.QMessageBox.Critical)
dialog.addButton(
strings._("gui_close_tab_warning_close"), QtWidgets.QMessageBox.YesRole
)
cancel_button = dialog.addButton(
strings._("gui_close_tab_warning_cancel"), QtWidgets.QMessageBox.NoRole
)
dialog.setDefaultButton(cancel_button)
reply = dialog.exec_()
# Close if server_status.status == server_status.STATUS_STOPPED:
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.app.cleanup()
return True return True
# Cancel
else: else:
self.common.log("Tab", "close_tab", "cancel, keeping tab open") if self.mode == self.common.gui.MODE_SHARE:
return False dialog_text = strings._("gui_close_tab_warning_share_description")
elif self.mode == self.common.gui.MODE_RECEIVE:
dialog_text = strings._("gui_close_tab_warning_receive_description")
else:
dialog_text = strings._("gui_close_tab_warning_website_description")
# Open the warning dialog
self.common.log("Tab", "close_tab, opening warning dialog")
dialog = QtWidgets.QMessageBox()
dialog.setWindowTitle(strings._("gui_close_tab_warning_title"))
dialog.setText(dialog_text)
dialog.setIcon(QtWidgets.QMessageBox.Critical)
dialog.addButton(
strings._("gui_close_tab_warning_close"), QtWidgets.QMessageBox.YesRole
)
cancel_button = dialog.addButton(
strings._("gui_close_tab_warning_cancel"), QtWidgets.QMessageBox.NoRole
)
dialog.setDefaultButton(cancel_button)
reply = dialog.exec_()
# 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.app.cleanup()
return True
# Cancel
else:
self.common.log("Tab", "close_tab", "cancel, keeping tab open")
return False
def cleanup(self): def cleanup(self):
self.app.cleanup() self.app.cleanup()

View File

@ -189,6 +189,7 @@
"gui_new_tab_website_button": "Publish Website", "gui_new_tab_website_button": "Publish Website",
"gui_new_tab_website_description": "Host a static HTML onion website from your computer.", "gui_new_tab_website_description": "Host a static HTML onion website from your computer.",
"gui_close_tab_warning_title": "Are you sure?", "gui_close_tab_warning_title": "Are you sure?",
"gui_close_tab_warning_persistent_description": "This tab is persistent. If you close it you'll lose the onion address that it's using. Are you sure you want to close it?",
"gui_close_tab_warning_share_description": "You're in the process of sending files. Are you sure you want to close this tab?", "gui_close_tab_warning_share_description": "You're in the process of sending files. Are you sure you want to close this tab?",
"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_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_website_description": "You're actively hosting a website. Are you sure you want to close this tab?",