mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-23 13:11:21 -05:00
Refactor TorSettingsDialog into TorSettingsTab
This commit is contained in:
parent
55d6ac4e3d
commit
0fb7d7d761
@ -246,9 +246,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
Open the TorSettingsTab
|
||||
"""
|
||||
self.common.log("MainWindow", "open_tor_settings")
|
||||
# d = TorSettingsDialog(self.common)
|
||||
# d.settings_saved.connect(self.settings_have_changed)
|
||||
# d.exec_()
|
||||
self.tabs.open_tor_settings_tab()
|
||||
|
||||
def open_settings(self):
|
||||
"""
|
||||
@ -256,9 +254,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
"""
|
||||
self.common.log("MainWindow", "open_settings")
|
||||
self.tabs.open_settings_tab()
|
||||
# d = SettingsDialog(self.common)
|
||||
# d.settings_saved.connect(self.settings_have_changed)
|
||||
# d.exec_()
|
||||
|
||||
def settings_have_changed(self):
|
||||
self.common.log("OnionShareGui", "settings_have_changed")
|
||||
|
@ -92,8 +92,9 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
|
||||
# Clean up each tab
|
||||
for index in range(self.count()):
|
||||
tab = self.widget(index)
|
||||
tab.cleanup()
|
||||
if not self.is_settings_tab(index):
|
||||
tab = self.widget(index)
|
||||
tab.cleanup()
|
||||
|
||||
def move_new_tab_button(self):
|
||||
# Find the width of all tabs
|
||||
@ -186,7 +187,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
|
||||
# See if a settings tab is already open, and if so switch to it
|
||||
for index in range(self.count()):
|
||||
if self.is_settings_tab(index):
|
||||
if type(self.tabs[index]) is SettingsTab:
|
||||
self.setCurrentIndex(index)
|
||||
return
|
||||
|
||||
@ -200,6 +201,27 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
if self.common.platform == "Darwin":
|
||||
self.macos_create_close_button(settings_tab, index)
|
||||
|
||||
def open_tor_settings_tab(self):
|
||||
self.common.log("TabWidget", "open_tor_settings_tab")
|
||||
|
||||
# See if a settings tab is already open, and if so switch to it
|
||||
for index in range(self.count()):
|
||||
if type(self.tabs[index]) is TorSettingsTab:
|
||||
self.setCurrentIndex(index)
|
||||
return
|
||||
|
||||
tor_settings_tab = TorSettingsTab(self.common, self.current_tab_id)
|
||||
self.tabs[self.current_tab_id] = tor_settings_tab
|
||||
self.current_tab_id += 1
|
||||
index = self.addTab(
|
||||
tor_settings_tab, strings._("gui_tor_settings_window_title")
|
||||
)
|
||||
self.setCurrentIndex(index)
|
||||
|
||||
# In macOS, manually create a close button because tabs don't seem to have them otherwise
|
||||
if self.common.platform == "Darwin":
|
||||
self.macos_create_close_button(tor_settings_tab, index)
|
||||
|
||||
def change_title(self, tab_id, title):
|
||||
shortened_title = title
|
||||
if len(shortened_title) > 11:
|
||||
@ -280,10 +302,11 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
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:
|
||||
if mode.server_status.status != mode.server_status.STATUS_STOPPED:
|
||||
return True
|
||||
if not self.is_settings_tab(tab_id):
|
||||
mode = self.tabs[tab_id].get_mode()
|
||||
if mode:
|
||||
if mode.server_status.status != mode.server_status.STATUS_STOPPED:
|
||||
return True
|
||||
return False
|
||||
|
||||
def paintEvent(self, event):
|
||||
|
@ -319,15 +319,10 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||
self.test_tor_button.clicked.connect(self.test_tor_clicked)
|
||||
self.save_button = QtWidgets.QPushButton(strings._("gui_settings_button_save"))
|
||||
self.save_button.clicked.connect(self.save_clicked)
|
||||
self.cancel_button = QtWidgets.QPushButton(
|
||||
strings._("gui_settings_button_cancel")
|
||||
)
|
||||
self.cancel_button.clicked.connect(self.cancel_clicked)
|
||||
buttons_layout = QtWidgets.QHBoxLayout()
|
||||
buttons_layout.addWidget(self.test_tor_button)
|
||||
buttons_layout.addStretch()
|
||||
buttons_layout.addWidget(self.save_button)
|
||||
buttons_layout.addWidget(self.cancel_button)
|
||||
|
||||
# Layout
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
@ -337,7 +332,6 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||
layout.addLayout(buttons_layout)
|
||||
|
||||
self.setLayout(layout)
|
||||
self.cancel_button.setFocus()
|
||||
|
||||
self.reload_settings()
|
||||
|
||||
@ -686,23 +680,27 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||
self.settings_saved.emit()
|
||||
self.close()
|
||||
|
||||
def cancel_clicked(self):
|
||||
def close_tab(self):
|
||||
"""
|
||||
Cancel button clicked.
|
||||
Tab is closed
|
||||
"""
|
||||
self.common.log("TorSettingsTab", "cancel_clicked")
|
||||
if (
|
||||
not self.common.gui.local_only
|
||||
and not self.common.gui.onion.is_authenticated()
|
||||
):
|
||||
Alert(
|
||||
self.common,
|
||||
strings._("gui_tor_connection_canceled"),
|
||||
QtWidgets.QMessageBox.Warning,
|
||||
)
|
||||
sys.exit()
|
||||
else:
|
||||
self.close()
|
||||
return True
|
||||
|
||||
# TODO: Figure out flow for first connecting, when closing settings when not connected
|
||||
|
||||
# if (
|
||||
# not self.common.gui.local_only
|
||||
# and not self.common.gui.onion.is_authenticated()
|
||||
# ):
|
||||
# Alert(
|
||||
# self.common,
|
||||
# strings._("gui_tor_connection_canceled"),
|
||||
# QtWidgets.QMessageBox.Warning,
|
||||
# )
|
||||
# sys.exit()
|
||||
# else:
|
||||
# self.close()
|
||||
|
||||
def settings_from_fields(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user