mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-01 12:44:21 -04:00
Refactor TorSettingsDialog into TorSettingsTab
This commit is contained in:
parent
cfa7597555
commit
0f9cb2a732
3 changed files with 49 additions and 33 deletions
|
@ -246,9 +246,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
Open the TorSettingsTab
|
Open the TorSettingsTab
|
||||||
"""
|
"""
|
||||||
self.common.log("MainWindow", "open_tor_settings")
|
self.common.log("MainWindow", "open_tor_settings")
|
||||||
# d = TorSettingsDialog(self.common)
|
self.tabs.open_tor_settings_tab()
|
||||||
# d.settings_saved.connect(self.settings_have_changed)
|
|
||||||
# d.exec_()
|
|
||||||
|
|
||||||
def open_settings(self):
|
def open_settings(self):
|
||||||
"""
|
"""
|
||||||
|
@ -256,9 +254,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
"""
|
"""
|
||||||
self.common.log("MainWindow", "open_settings")
|
self.common.log("MainWindow", "open_settings")
|
||||||
self.tabs.open_settings_tab()
|
self.tabs.open_settings_tab()
|
||||||
# d = SettingsDialog(self.common)
|
|
||||||
# d.settings_saved.connect(self.settings_have_changed)
|
|
||||||
# d.exec_()
|
|
||||||
|
|
||||||
def settings_have_changed(self):
|
def settings_have_changed(self):
|
||||||
self.common.log("OnionShareGui", "settings_have_changed")
|
self.common.log("OnionShareGui", "settings_have_changed")
|
||||||
|
|
|
@ -92,8 +92,9 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||||
|
|
||||||
# Clean up each tab
|
# Clean up each tab
|
||||||
for index in range(self.count()):
|
for index in range(self.count()):
|
||||||
tab = self.widget(index)
|
if not self.is_settings_tab(index):
|
||||||
tab.cleanup()
|
tab = self.widget(index)
|
||||||
|
tab.cleanup()
|
||||||
|
|
||||||
def move_new_tab_button(self):
|
def move_new_tab_button(self):
|
||||||
# Find the width of all tabs
|
# 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
|
# See if a settings tab is already open, and if so switch to it
|
||||||
for index in range(self.count()):
|
for index in range(self.count()):
|
||||||
if self.is_settings_tab(index):
|
if type(self.tabs[index]) is SettingsTab:
|
||||||
self.setCurrentIndex(index)
|
self.setCurrentIndex(index)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -200,6 +201,27 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||||
if self.common.platform == "Darwin":
|
if self.common.platform == "Darwin":
|
||||||
self.macos_create_close_button(settings_tab, index)
|
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):
|
def change_title(self, tab_id, title):
|
||||||
shortened_title = title
|
shortened_title = title
|
||||||
if len(shortened_title) > 11:
|
if len(shortened_title) > 11:
|
||||||
|
@ -280,10 +302,11 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||||
See if there are active servers in any open tabs
|
See if there are active servers in any open tabs
|
||||||
"""
|
"""
|
||||||
for tab_id in self.tabs:
|
for tab_id in self.tabs:
|
||||||
mode = self.tabs[tab_id].get_mode()
|
if not self.is_settings_tab(tab_id):
|
||||||
if mode:
|
mode = self.tabs[tab_id].get_mode()
|
||||||
if mode.server_status.status != mode.server_status.STATUS_STOPPED:
|
if mode:
|
||||||
return True
|
if mode.server_status.status != mode.server_status.STATUS_STOPPED:
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def paintEvent(self, event):
|
def paintEvent(self, event):
|
||||||
|
|
|
@ -319,15 +319,10 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||||
self.test_tor_button.clicked.connect(self.test_tor_clicked)
|
self.test_tor_button.clicked.connect(self.test_tor_clicked)
|
||||||
self.save_button = QtWidgets.QPushButton(strings._("gui_settings_button_save"))
|
self.save_button = QtWidgets.QPushButton(strings._("gui_settings_button_save"))
|
||||||
self.save_button.clicked.connect(self.save_clicked)
|
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 = QtWidgets.QHBoxLayout()
|
||||||
buttons_layout.addWidget(self.test_tor_button)
|
buttons_layout.addWidget(self.test_tor_button)
|
||||||
buttons_layout.addStretch()
|
buttons_layout.addStretch()
|
||||||
buttons_layout.addWidget(self.save_button)
|
buttons_layout.addWidget(self.save_button)
|
||||||
buttons_layout.addWidget(self.cancel_button)
|
|
||||||
|
|
||||||
# Layout
|
# Layout
|
||||||
layout = QtWidgets.QVBoxLayout()
|
layout = QtWidgets.QVBoxLayout()
|
||||||
|
@ -337,7 +332,6 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||||
layout.addLayout(buttons_layout)
|
layout.addLayout(buttons_layout)
|
||||||
|
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
self.cancel_button.setFocus()
|
|
||||||
|
|
||||||
self.reload_settings()
|
self.reload_settings()
|
||||||
|
|
||||||
|
@ -686,23 +680,27 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||||
self.settings_saved.emit()
|
self.settings_saved.emit()
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def cancel_clicked(self):
|
def close_tab(self):
|
||||||
"""
|
"""
|
||||||
Cancel button clicked.
|
Tab is closed
|
||||||
"""
|
"""
|
||||||
self.common.log("TorSettingsTab", "cancel_clicked")
|
self.common.log("TorSettingsTab", "cancel_clicked")
|
||||||
if (
|
return True
|
||||||
not self.common.gui.local_only
|
|
||||||
and not self.common.gui.onion.is_authenticated()
|
# TODO: Figure out flow for first connecting, when closing settings when not connected
|
||||||
):
|
|
||||||
Alert(
|
# if (
|
||||||
self.common,
|
# not self.common.gui.local_only
|
||||||
strings._("gui_tor_connection_canceled"),
|
# and not self.common.gui.onion.is_authenticated()
|
||||||
QtWidgets.QMessageBox.Warning,
|
# ):
|
||||||
)
|
# Alert(
|
||||||
sys.exit()
|
# self.common,
|
||||||
else:
|
# strings._("gui_tor_connection_canceled"),
|
||||||
self.close()
|
# QtWidgets.QMessageBox.Warning,
|
||||||
|
# )
|
||||||
|
# sys.exit()
|
||||||
|
# else:
|
||||||
|
# self.close()
|
||||||
|
|
||||||
def settings_from_fields(self):
|
def settings_from_fields(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue