mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-27 08:19:41 -05:00
Allow closing tabs, and throw warning when trying to close tabs that contain an active server
This commit is contained in:
parent
fd2046b976
commit
df658a0e70
@ -50,7 +50,7 @@ class Tab(QtWidgets.QWidget):
|
||||
self.status_bar = status_bar
|
||||
self.filenames = filenames
|
||||
|
||||
self.mode = self.common.gui.MODE_SHARE
|
||||
self.mode = None
|
||||
|
||||
# Start the OnionShare app
|
||||
self.app = OnionShare(common, self.common.gui.onion, self.common.gui.local_only)
|
||||
@ -511,44 +511,57 @@ class Tab(QtWidgets.QWidget):
|
||||
"""
|
||||
self.status_bar.clearMessage()
|
||||
|
||||
def close_event(self, e):
|
||||
self.common.log("Tab", "close_event")
|
||||
try:
|
||||
if self.mode == self.common.gui.MODE_WEBSITE:
|
||||
server_status = self.share_mode.server_status
|
||||
if self.mode == self.common.gui.MODE_WEBSITE:
|
||||
server_status = self.website_mode.server_status
|
||||
def close_tab(self):
|
||||
self.common.log("Tab", "close_tab")
|
||||
if self.mode is None:
|
||||
return True
|
||||
|
||||
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
|
||||
|
||||
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:
|
||||
dialog.setText(strings._("gui_close_tab_warning_share_description"))
|
||||
elif self.mode == self.common.gui.MODE_RECEIVE:
|
||||
dialog.setText(strings._("gui_close_tab_warning_receive_description"))
|
||||
else:
|
||||
server_status = self.receive_mode.server_status
|
||||
if server_status.status != server_status.STATUS_STOPPED:
|
||||
self.common.log("MainWindow", "closeEvent, opening warning dialog")
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
dialog.setWindowTitle(strings._("gui_quit_title"))
|
||||
if self.mode == self.common.gui.MODE_WEBSITE:
|
||||
dialog.setText(strings._("gui_share_quit_warning"))
|
||||
else:
|
||||
dialog.setText(strings._("gui_receive_quit_warning"))
|
||||
dialog.setIcon(QtWidgets.QMessageBox.Critical)
|
||||
quit_button = dialog.addButton(
|
||||
strings._("gui_quit_warning_quit"), QtWidgets.QMessageBox.YesRole
|
||||
)
|
||||
dont_quit_button = dialog.addButton(
|
||||
strings._("gui_quit_warning_dont_quit"),
|
||||
QtWidgets.QMessageBox.NoRole,
|
||||
)
|
||||
dialog.setDefaultButton(dont_quit_button)
|
||||
reply = dialog.exec_()
|
||||
dialog.setText(strings._("gui_close_tab_warning_website_description"))
|
||||
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_()
|
||||
|
||||
# Quit
|
||||
if reply == 0:
|
||||
self.stop_server()
|
||||
e.accept()
|
||||
# Don't Quit
|
||||
else:
|
||||
e.ignore()
|
||||
# Close
|
||||
if reply == 0:
|
||||
self.common.log("Tab", "close_tab", "close, closing tab")
|
||||
|
||||
except:
|
||||
e.accept()
|
||||
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):
|
||||
self.app.cleanup()
|
||||
|
@ -60,6 +60,8 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
self.setTabsClosable(True)
|
||||
self.setUsesScrollButtons(True)
|
||||
|
||||
self.tabCloseRequested.connect(self.close_tab)
|
||||
|
||||
self.move_new_tab_button()
|
||||
|
||||
def move_new_tab_button(self):
|
||||
@ -81,11 +83,6 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
self.new_tab_button.move(pos)
|
||||
self.new_tab_button.raise_()
|
||||
|
||||
def resizeEvent(self, event):
|
||||
# Make sure to move new tab button on each resize
|
||||
super(TabWidget, self).resizeEvent(event)
|
||||
self.move_new_tab_button()
|
||||
|
||||
def new_tab_clicked(self):
|
||||
# Create the tab
|
||||
tab = Tab(self.common, self.tab_id, self.system_tray, self.status_bar)
|
||||
@ -101,6 +98,18 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
index = self.indexOf(self.tabs[tab_id])
|
||||
self.setTabText(index, title)
|
||||
|
||||
def close_tab(self, index):
|
||||
self.common.log("TabWidget", "close_tab", f"{index}")
|
||||
tab = self.widget(index)
|
||||
if tab.close_tab():
|
||||
self.removeTab(index)
|
||||
del self.tabs[tab.tab_id]
|
||||
|
||||
def resizeEvent(self, event):
|
||||
# Make sure to move new tab button on each resize
|
||||
super(TabWidget, self).resizeEvent(event)
|
||||
self.move_new_tab_button()
|
||||
|
||||
|
||||
class TabBar(QtWidgets.QTabBar):
|
||||
"""
|
||||
|
@ -187,5 +187,11 @@
|
||||
"gui_new_tab_receive_button": "Receive Files",
|
||||
"gui_new_tab_receive_description": "Turn your computer into an online dropbox. People will be able to use Tor Browser to send files to your computer.",
|
||||
"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_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_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"
|
||||
}
|
Loading…
Reference in New Issue
Block a user