mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Cleanup code
This commit is contained in:
parent
fdc7ba9228
commit
74f0c9d86b
@ -37,13 +37,14 @@ class SettingsParentTab(QtWidgets.QTabWidget):
|
|||||||
# Use a custom tab bar
|
# Use a custom tab bar
|
||||||
tab_bar = TabBar()
|
tab_bar = TabBar()
|
||||||
self.setTabBar(tab_bar)
|
self.setTabBar(tab_bar)
|
||||||
settings_tab = SettingsTab(self.common, 0)
|
settings_tab = SettingsTab(self.common, 0, parent=self)
|
||||||
self.tor_settings_tab = TorSettingsTab(
|
self.tor_settings_tab = TorSettingsTab(
|
||||||
self.common,
|
self.common,
|
||||||
1,
|
1,
|
||||||
self.parent.are_tabs_active(),
|
self.parent.are_tabs_active(),
|
||||||
self.parent.status_bar,
|
self.parent.status_bar,
|
||||||
from_autoconnect,
|
parent=self,
|
||||||
|
from_autoconnect=from_autoconnect,
|
||||||
)
|
)
|
||||||
self.addTab(
|
self.addTab(
|
||||||
self.tor_settings_tab, strings._("gui_tor_settings_window_title")
|
self.tor_settings_tab, strings._("gui_tor_settings_window_title")
|
||||||
|
@ -33,9 +33,7 @@ class SettingsTab(QtWidgets.QWidget):
|
|||||||
Settings dialog.
|
Settings dialog.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
close_this_tab = QtCore.Signal()
|
def __init__(self, common, tab_id, parent=None):
|
||||||
|
|
||||||
def __init__(self, common, tab_id):
|
|
||||||
super(SettingsTab, self).__init__()
|
super(SettingsTab, self).__init__()
|
||||||
|
|
||||||
self.common = common
|
self.common = common
|
||||||
@ -43,6 +41,7 @@ class SettingsTab(QtWidgets.QWidget):
|
|||||||
|
|
||||||
self.system = platform.system()
|
self.system = platform.system()
|
||||||
self.tab_id = tab_id
|
self.tab_id = tab_id
|
||||||
|
self.parent = parent
|
||||||
|
|
||||||
# Automatic updates options
|
# Automatic updates options
|
||||||
|
|
||||||
@ -283,7 +282,7 @@ class SettingsTab(QtWidgets.QWidget):
|
|||||||
|
|
||||||
# Save the new settings
|
# Save the new settings
|
||||||
settings.save()
|
settings.save()
|
||||||
self.close_this_tab.emit()
|
self.parent.close_this_tab.emit()
|
||||||
|
|
||||||
def help_clicked(self):
|
def help_clicked(self):
|
||||||
"""
|
"""
|
||||||
|
@ -98,9 +98,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
# Clean up each tab
|
# Clean up each tab
|
||||||
for tab_id in self.tabs:
|
for tab_id in self.tabs:
|
||||||
if not (
|
if not (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsParentTab
|
||||||
or type(self.tabs[tab_id]) is SettingsParentTab
|
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
|
||||||
or type(self.tabs[tab_id]) is AutoConnectTab
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
self.tabs[tab_id].cleanup()
|
self.tabs[tab_id].cleanup()
|
||||||
@ -140,9 +138,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
|
|
||||||
# If it's Settings or Tor Settings, ignore
|
# If it's Settings or Tor Settings, ignore
|
||||||
if (
|
if (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsParentTab
|
||||||
or type(self.tabs[tab_id]) is SettingsParentTab
|
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
|
||||||
or type(self.tabs[tab_id]) is AutoConnectTab
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
# Blank the server status indicator
|
# Blank the server status indicator
|
||||||
@ -243,39 +239,14 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
|
|
||||||
settings_tab = SettingsParentTab(self.common, self.current_tab_id,active_tab=active_tab, parent=self, from_autoconnect=from_autoconnect)
|
settings_tab = SettingsParentTab(self.common, self.current_tab_id,active_tab=active_tab, parent=self, from_autoconnect=from_autoconnect)
|
||||||
settings_tab.close_this_tab.connect(self.close_settings_tab)
|
settings_tab.close_this_tab.connect(self.close_settings_tab)
|
||||||
settings_tab.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected)
|
self.tor_settings_tab = settings_tab.tor_settings_tab
|
||||||
settings_tab.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected)
|
self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected)
|
||||||
|
self.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected)
|
||||||
self.tabs[self.current_tab_id] = settings_tab
|
self.tabs[self.current_tab_id] = settings_tab
|
||||||
self.current_tab_id += 1
|
self.current_tab_id += 1
|
||||||
index = self.addTab(settings_tab, strings._("gui_settings_window_title"))
|
index = self.addTab(settings_tab, strings._("gui_settings_window_title"))
|
||||||
self.setCurrentIndex(index)
|
self.setCurrentIndex(index)
|
||||||
|
|
||||||
# def open_tor_settings_tab(self, from_autoconnect=False):
|
|
||||||
# self.common.log("TabWidget", "open_tor_settings_tab")
|
|
||||||
|
|
||||||
# # See if a settings tab is already open, and if so switch to it
|
|
||||||
# for tab_id in self.tabs:
|
|
||||||
# if type(self.tabs[tab_id]) is TorSettingsTab:
|
|
||||||
# self.setCurrentIndex(self.indexOf(self.tabs[tab_id]))
|
|
||||||
# return
|
|
||||||
|
|
||||||
# self.tor_settings_tab = TorSettingsTab(
|
|
||||||
# self.common,
|
|
||||||
# self.current_tab_id,
|
|
||||||
# self.are_tabs_active(),
|
|
||||||
# self.status_bar,
|
|
||||||
# from_autoconnect,
|
|
||||||
# )
|
|
||||||
# self.tor_settings_tab.close_this_tab.connect(self.close_tor_settings_tab)
|
|
||||||
# self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected)
|
|
||||||
# self.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected)
|
|
||||||
# self.tabs[self.current_tab_id] = self.tor_settings_tab
|
|
||||||
# self.current_tab_id += 1
|
|
||||||
# index = self.addTab(
|
|
||||||
# self.tor_settings_tab, strings._("gui_tor_settings_window_title")
|
|
||||||
# )
|
|
||||||
# self.setCurrentIndex(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:
|
||||||
@ -319,9 +290,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
persistent_tabs = []
|
persistent_tabs = []
|
||||||
for tab_id in self.tabs:
|
for tab_id in self.tabs:
|
||||||
if not (
|
if not (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsParentTab
|
||||||
or type(self.tabs[tab_id]) is SettingsParentTab
|
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
|
||||||
or type(self.tabs[tab_id]) is AutoConnectTab
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
tab = self.widget(self.indexOf(self.tabs[tab_id]))
|
tab = self.widget(self.indexOf(self.tabs[tab_id]))
|
||||||
@ -338,14 +307,12 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
tab_id = tab.tab_id
|
tab_id = tab.tab_id
|
||||||
|
|
||||||
if (
|
if (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsParentTab
|
||||||
or type(self.tabs[tab_id]) is SettingsParentTab
|
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
|
||||||
or type(self.tabs[tab_id]) is AutoConnectTab
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
self.common.log("TabWidget", "closing a settings tab")
|
self.common.log("TabWidget", "closing a settings tab")
|
||||||
|
|
||||||
if type(self.tabs[tab_id]) is TorSettingsTab:
|
if type(self.tabs[tab_id]) is SettingsParentTab:
|
||||||
self.tor_settings_tab = None
|
self.tor_settings_tab = None
|
||||||
|
|
||||||
# Remove the tab
|
# Remove the tab
|
||||||
@ -386,16 +353,8 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
self.close_tab(index)
|
self.close_tab(index)
|
||||||
return
|
return
|
||||||
|
|
||||||
# def close_settings_tab(self):
|
|
||||||
# self.common.log("TabWidget", "close_settings_tab")
|
|
||||||
# for tab_id in self.tabs:
|
|
||||||
# if type(self.tabs[tab_id]) is SettingsTab:
|
|
||||||
# index = self.indexOf(self.tabs[tab_id])
|
|
||||||
# self.close_tab(index)
|
|
||||||
# return
|
|
||||||
|
|
||||||
def close_settings_tab(self):
|
def close_settings_tab(self):
|
||||||
self.common.log("TabWidget", "close_tor_settings_tab")
|
self.common.log("TabWidget", "close_settings_tab")
|
||||||
for tab_id in list(self.tabs):
|
for tab_id in list(self.tabs):
|
||||||
if type(self.tabs[tab_id]) is AutoConnectTab:
|
if type(self.tabs[tab_id]) is AutoConnectTab:
|
||||||
# If we are being returned to the AutoConnectTab, but
|
# If we are being returned to the AutoConnectTab, but
|
||||||
@ -405,7 +364,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
if self.common.gui.onion.is_authenticated():
|
if self.common.gui.onion.is_authenticated():
|
||||||
self.common.log(
|
self.common.log(
|
||||||
"TabWidget",
|
"TabWidget",
|
||||||
"close_tor_settings_tab",
|
"close_settings_tab",
|
||||||
"Tor is connected and we can auto-connect, so closing the tab",
|
"Tor is connected and we can auto-connect, so closing the tab",
|
||||||
)
|
)
|
||||||
index = self.indexOf(self.tabs[tab_id])
|
index = self.indexOf(self.tabs[tab_id])
|
||||||
@ -414,13 +373,13 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
self.tabs[tab_id].reload_settings()
|
self.tabs[tab_id].reload_settings()
|
||||||
self.common.log(
|
self.common.log(
|
||||||
"TabWidget",
|
"TabWidget",
|
||||||
"close_tor_settings_tab",
|
"close_settings_tab",
|
||||||
"Reloading settings in case they changed in the TorSettingsTab. Not auto-connecting",
|
"Reloading settings in case they changed in the TorSettingsTab. Not auto-connecting",
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
# List of indices may have changed due to the above, so we loop over it again as another copy
|
# List of indices may have changed due to the above, so we loop over it again as another copy
|
||||||
for tab_id in list(self.tabs):
|
for tab_id in list(self.tabs):
|
||||||
if type(self.tabs[tab_id]) is TorSettingsTab:
|
if type(self.tabs[tab_id]) is SettingsParentTab:
|
||||||
index = self.indexOf(self.tabs[tab_id])
|
index = self.indexOf(self.tabs[tab_id])
|
||||||
self.close_tab(index)
|
self.close_tab(index)
|
||||||
return
|
return
|
||||||
@ -431,9 +390,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
"""
|
"""
|
||||||
for tab_id in self.tabs:
|
for tab_id in self.tabs:
|
||||||
if not (
|
if not (
|
||||||
type(self.tabs[tab_id]) is SettingsTab
|
type(self.tabs[tab_id]) is SettingsParentTab
|
||||||
or type(self.tabs[tab_id]) is SettingsParentTab
|
|
||||||
or type(self.tabs[tab_id]) is TorSettingsTab
|
|
||||||
or type(self.tabs[tab_id]) is AutoConnectTab
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
):
|
):
|
||||||
mode = self.tabs[tab_id].get_mode()
|
mode = self.tabs[tab_id].get_mode()
|
||||||
@ -456,29 +413,23 @@ class TabWidget(QtWidgets.QTabWidget):
|
|||||||
|
|
||||||
def tor_is_connected(self):
|
def tor_is_connected(self):
|
||||||
for tab_id in self.tabs:
|
for tab_id in self.tabs:
|
||||||
if type(self.tabs[tab_id]) is SettingsTab:
|
if not (
|
||||||
self.tabs[tab_id].tor_is_connected()
|
type(self.tabs[tab_id]) is SettingsParentTab
|
||||||
else:
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
if not (
|
):
|
||||||
type(self.tabs[tab_id]) is TorSettingsTab
|
mode = self.tabs[tab_id].get_mode()
|
||||||
or type(self.tabs[tab_id]) is AutoConnectTab
|
if mode:
|
||||||
):
|
mode.tor_connection_started()
|
||||||
mode = self.tabs[tab_id].get_mode()
|
|
||||||
if mode:
|
|
||||||
mode.tor_connection_started()
|
|
||||||
|
|
||||||
def tor_is_disconnected(self):
|
def tor_is_disconnected(self):
|
||||||
for tab_id in self.tabs:
|
for tab_id in self.tabs:
|
||||||
if type(self.tabs[tab_id]) is SettingsTab:
|
if not (
|
||||||
self.tabs[tab_id].tor_is_disconnected()
|
type(self.tabs[tab_id]) is SettingsParentTab
|
||||||
else:
|
or type(self.tabs[tab_id]) is AutoConnectTab
|
||||||
if not (
|
):
|
||||||
type(self.tabs[tab_id]) is TorSettingsTab
|
mode = self.tabs[tab_id].get_mode()
|
||||||
or type(self.tabs[tab_id]) is AutoConnectTab
|
if mode:
|
||||||
):
|
mode.tor_connection_stopped()
|
||||||
mode = self.tabs[tab_id].get_mode()
|
|
||||||
if mode:
|
|
||||||
mode.tor_connection_stopped()
|
|
||||||
|
|
||||||
|
|
||||||
class TabBar(QtWidgets.QTabBar):
|
class TabBar(QtWidgets.QTabBar):
|
||||||
|
@ -43,7 +43,7 @@ class TorSettingsTab(QtWidgets.QWidget):
|
|||||||
tor_is_disconnected = QtCore.Signal()
|
tor_is_disconnected = QtCore.Signal()
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, common, tab_id, are_tabs_active, status_bar, from_autoconnect=False
|
self, common, tab_id, are_tabs_active, status_bar, from_autoconnect=False, parent=None
|
||||||
):
|
):
|
||||||
super(TorSettingsTab, self).__init__()
|
super(TorSettingsTab, self).__init__()
|
||||||
|
|
||||||
@ -55,6 +55,7 @@ class TorSettingsTab(QtWidgets.QWidget):
|
|||||||
|
|
||||||
self.system = platform.system()
|
self.system = platform.system()
|
||||||
self.tab_id = tab_id
|
self.tab_id = tab_id
|
||||||
|
self.parent = parent
|
||||||
self.from_autoconnect = from_autoconnect
|
self.from_autoconnect = from_autoconnect
|
||||||
|
|
||||||
# Connection type: either automatic, control port, or socket file
|
# Connection type: either automatic, control port, or socket file
|
||||||
@ -746,9 +747,9 @@ class TorSettingsTab(QtWidgets.QWidget):
|
|||||||
self.tor_con.show()
|
self.tor_con.show()
|
||||||
self.tor_con.start(settings)
|
self.tor_con.start(settings)
|
||||||
else:
|
else:
|
||||||
self.close_this_tab.emit()
|
self.parent.close_this_tab.emit()
|
||||||
else:
|
else:
|
||||||
self.close_this_tab.emit()
|
self.parent.close_this_tab.emit()
|
||||||
|
|
||||||
def tor_con_success(self):
|
def tor_con_success(self):
|
||||||
"""
|
"""
|
||||||
@ -779,7 +780,7 @@ class TorSettingsTab(QtWidgets.QWidget):
|
|||||||
# Tell the tabs that Tor is connected
|
# Tell the tabs that Tor is connected
|
||||||
self.tor_is_connected.emit()
|
self.tor_is_connected.emit()
|
||||||
# Close the tab
|
# Close the tab
|
||||||
self.close_this_tab.emit()
|
self.parent.close_this_tab.emit()
|
||||||
|
|
||||||
self.tor_con_type = None
|
self.tor_con_type = None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user