mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-25 10:42:58 -03:00
Starting to make persistent tabs persistent
This commit is contained in:
parent
1b36fe4036
commit
a5f8fee065
9 changed files with 115 additions and 25 deletions
|
@ -28,12 +28,13 @@ class ModeSettings:
|
||||||
is only one TabSettings, and in the GUI there is a separate TabSettings for each tab
|
is only one TabSettings, and in the GUI there is a separate TabSettings for each tab
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, common, filename=None):
|
def __init__(self, common, filename=None, id=None):
|
||||||
self.common = common
|
self.common = common
|
||||||
|
|
||||||
self.default_settings = {
|
self.default_settings = {
|
||||||
"persistent": {
|
"persistent": {
|
||||||
"enabled": False,
|
"enabled": False,
|
||||||
|
"mode": None,
|
||||||
"private_key": None,
|
"private_key": None,
|
||||||
"hidservauth": None,
|
"hidservauth": None,
|
||||||
"password": None,
|
"password": None,
|
||||||
|
@ -52,7 +53,10 @@ class ModeSettings:
|
||||||
self._settings = {}
|
self._settings = {}
|
||||||
|
|
||||||
self.just_created = False
|
self.just_created = False
|
||||||
self.id = self.common.build_password(3)
|
if id:
|
||||||
|
self.id = id
|
||||||
|
else:
|
||||||
|
self.id = self.common.build_password(3)
|
||||||
|
|
||||||
self.load(filename)
|
self.load(filename)
|
||||||
|
|
||||||
|
@ -104,7 +108,6 @@ class ModeSettings:
|
||||||
if filename:
|
if filename:
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
else:
|
else:
|
||||||
# Give it a persistent filename
|
|
||||||
self.filename = os.path.join(
|
self.filename = os.path.join(
|
||||||
self.common.build_persistent_dir(), f"{self.id}.json"
|
self.common.build_persistent_dir(), f"{self.id}.json"
|
||||||
)
|
)
|
||||||
|
|
|
@ -112,6 +112,7 @@ class Settings(object):
|
||||||
"tor_bridges_use_obfs4": False,
|
"tor_bridges_use_obfs4": False,
|
||||||
"tor_bridges_use_meek_lite_azure": False,
|
"tor_bridges_use_meek_lite_azure": False,
|
||||||
"tor_bridges_use_custom_bridges": "",
|
"tor_bridges_use_custom_bridges": "",
|
||||||
|
"persistent_tabs": [],
|
||||||
"locale": None, # this gets defined in fill_in_defaults()
|
"locale": None, # this gets defined in fill_in_defaults()
|
||||||
}
|
}
|
||||||
self._settings = {}
|
self._settings = {}
|
||||||
|
|
|
@ -120,8 +120,13 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
# Tabs
|
# Tabs
|
||||||
self.tabs = TabWidget(self.common, self.system_tray, self.status_bar)
|
self.tabs = TabWidget(self.common, self.system_tray, self.status_bar)
|
||||||
|
|
||||||
# Start with opening the first tab
|
# If we have saved persistent tabs, try opening those
|
||||||
self.tabs.new_tab_clicked()
|
if len(self.common.settings.get("persistent_tabs")) > 0:
|
||||||
|
for mode_settings_id in self.common.settings.get("persistent_tabs"):
|
||||||
|
self.tabs.load_tab(mode_settings_id)
|
||||||
|
else:
|
||||||
|
# Start with opening the first tab
|
||||||
|
self.tabs.new_tab_clicked()
|
||||||
|
|
||||||
# Layout
|
# Layout
|
||||||
layout = QtWidgets.QVBoxLayout()
|
layout = QtWidgets.QVBoxLayout()
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Mode(QtWidgets.QWidget):
|
||||||
def __init__(self, tab):
|
def __init__(self, tab):
|
||||||
super(Mode, self).__init__()
|
super(Mode, self).__init__()
|
||||||
self.tab = tab
|
self.tab = tab
|
||||||
self.settings = tab.mode_settings
|
self.settings = tab.settings
|
||||||
|
|
||||||
self.common = tab.common
|
self.common = tab.common
|
||||||
self.qtapp = self.common.gui.qtapp
|
self.qtapp = self.common.gui.qtapp
|
||||||
|
@ -69,7 +69,7 @@ class Mode(QtWidgets.QWidget):
|
||||||
|
|
||||||
# Mode settings widget
|
# Mode settings widget
|
||||||
self.mode_settings_widget = ModeSettingsWidget(
|
self.mode_settings_widget = ModeSettingsWidget(
|
||||||
self.common, self.tab.tab_id, self.settings
|
self.common, self.tab, self.settings
|
||||||
)
|
)
|
||||||
self.mode_settings_widget.change_persistent.connect(self.change_persistent)
|
self.mode_settings_widget.change_persistent.connect(self.change_persistent)
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ class ModeSettingsWidget(QtWidgets.QWidget):
|
||||||
|
|
||||||
change_persistent = QtCore.pyqtSignal(int, bool)
|
change_persistent = QtCore.pyqtSignal(int, bool)
|
||||||
|
|
||||||
def __init__(self, common, tab_id, mode_settings):
|
def __init__(self, common, tab, mode_settings):
|
||||||
super(ModeSettingsWidget, self).__init__()
|
super(ModeSettingsWidget, self).__init__()
|
||||||
self.common = common
|
self.common = common
|
||||||
self.tab_id = tab_id
|
self.tab = tab
|
||||||
self.settings = mode_settings
|
self.settings = mode_settings
|
||||||
|
|
||||||
# Downstream Mode need to fill in this layout with its settings
|
# Downstream Mode need to fill in this layout with its settings
|
||||||
|
@ -41,24 +41,33 @@ class ModeSettingsWidget(QtWidgets.QWidget):
|
||||||
# Persistent
|
# Persistent
|
||||||
self.persistent_checkbox = QtWidgets.QCheckBox()
|
self.persistent_checkbox = QtWidgets.QCheckBox()
|
||||||
self.persistent_checkbox.clicked.connect(self.persistent_checkbox_clicked)
|
self.persistent_checkbox.clicked.connect(self.persistent_checkbox_clicked)
|
||||||
self.persistent_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
|
||||||
self.persistent_checkbox.setText(strings._("mode_settings_persistent_checkbox"))
|
self.persistent_checkbox.setText(strings._("mode_settings_persistent_checkbox"))
|
||||||
|
if self.settings.get("persistent", "enabled"):
|
||||||
|
self.persistent_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
|
else:
|
||||||
|
self.persistent_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
# Public
|
# Public
|
||||||
self.public_checkbox = QtWidgets.QCheckBox()
|
self.public_checkbox = QtWidgets.QCheckBox()
|
||||||
self.public_checkbox.clicked.connect(self.public_checkbox_clicked)
|
self.public_checkbox.clicked.connect(self.public_checkbox_clicked)
|
||||||
self.public_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
|
||||||
self.public_checkbox.setText(strings._("mode_settings_public_checkbox"))
|
self.public_checkbox.setText(strings._("mode_settings_public_checkbox"))
|
||||||
|
if self.settings.get("general", "public"):
|
||||||
|
self.public_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
|
else:
|
||||||
|
self.public_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
# Whether or not to use an auto-start timer
|
# Whether or not to use an auto-start timer
|
||||||
self.autostart_timer_checkbox = QtWidgets.QCheckBox()
|
self.autostart_timer_checkbox = QtWidgets.QCheckBox()
|
||||||
self.autostart_timer_checkbox.clicked.connect(
|
self.autostart_timer_checkbox.clicked.connect(
|
||||||
self.autostart_timer_checkbox_clicked
|
self.autostart_timer_checkbox_clicked
|
||||||
)
|
)
|
||||||
self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
|
||||||
self.autostart_timer_checkbox.setText(
|
self.autostart_timer_checkbox.setText(
|
||||||
strings._("mode_settings_autostart_timer_checkbox")
|
strings._("mode_settings_autostart_timer_checkbox")
|
||||||
)
|
)
|
||||||
|
if self.settings.get("general", "autostart_timer"):
|
||||||
|
self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
|
else:
|
||||||
|
self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
# The autostart timer widget
|
# The autostart timer widget
|
||||||
self.autostart_timer_widget = QtWidgets.QDateTimeEdit()
|
self.autostart_timer_widget = QtWidgets.QDateTimeEdit()
|
||||||
|
@ -85,10 +94,13 @@ class ModeSettingsWidget(QtWidgets.QWidget):
|
||||||
self.autostop_timer_checkbox.clicked.connect(
|
self.autostop_timer_checkbox.clicked.connect(
|
||||||
self.autostop_timer_checkbox_clicked
|
self.autostop_timer_checkbox_clicked
|
||||||
)
|
)
|
||||||
self.autostop_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
|
||||||
self.autostop_timer_checkbox.setText(
|
self.autostop_timer_checkbox.setText(
|
||||||
strings._("mode_settings_autostop_timer_checkbox")
|
strings._("mode_settings_autostop_timer_checkbox")
|
||||||
)
|
)
|
||||||
|
if self.settings.get("general", "autostop_timer"):
|
||||||
|
self.autostop_timer_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
|
else:
|
||||||
|
self.autostop_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
# The autostop timer widget
|
# The autostop timer widget
|
||||||
self.autostop_timer_widget = QtWidgets.QDateTimeEdit()
|
self.autostop_timer_widget = QtWidgets.QDateTimeEdit()
|
||||||
|
@ -114,17 +126,23 @@ class ModeSettingsWidget(QtWidgets.QWidget):
|
||||||
self.legacy_checkbox = QtWidgets.QCheckBox()
|
self.legacy_checkbox = QtWidgets.QCheckBox()
|
||||||
self.legacy_checkbox.clicked.connect(self.legacy_checkbox_clicked)
|
self.legacy_checkbox.clicked.connect(self.legacy_checkbox_clicked)
|
||||||
self.legacy_checkbox.clicked.connect(self.update_ui)
|
self.legacy_checkbox.clicked.connect(self.update_ui)
|
||||||
self.legacy_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
|
||||||
self.legacy_checkbox.setText(strings._("mode_settings_legacy_checkbox"))
|
self.legacy_checkbox.setText(strings._("mode_settings_legacy_checkbox"))
|
||||||
|
if self.settings.get("general", "legacy"):
|
||||||
|
self.legacy_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
|
else:
|
||||||
|
self.legacy_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
# Client auth
|
# Client auth
|
||||||
self.client_auth_checkbox = QtWidgets.QCheckBox()
|
self.client_auth_checkbox = QtWidgets.QCheckBox()
|
||||||
self.client_auth_checkbox.clicked.connect(self.client_auth_checkbox_clicked)
|
self.client_auth_checkbox.clicked.connect(self.client_auth_checkbox_clicked)
|
||||||
self.client_auth_checkbox.clicked.connect(self.update_ui)
|
self.client_auth_checkbox.clicked.connect(self.update_ui)
|
||||||
self.client_auth_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
|
||||||
self.client_auth_checkbox.setText(
|
self.client_auth_checkbox.setText(
|
||||||
strings._("mode_settings_client_auth_checkbox")
|
strings._("mode_settings_client_auth_checkbox")
|
||||||
)
|
)
|
||||||
|
if self.settings.get("general", "client_auth"):
|
||||||
|
self.client_auth_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
|
else:
|
||||||
|
self.client_auth_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
# Toggle advanced settings
|
# Toggle advanced settings
|
||||||
self.toggle_advanced_button = QtWidgets.QPushButton()
|
self.toggle_advanced_button = QtWidgets.QPushButton()
|
||||||
|
@ -179,8 +197,10 @@ class ModeSettingsWidget(QtWidgets.QWidget):
|
||||||
|
|
||||||
def persistent_checkbox_clicked(self):
|
def persistent_checkbox_clicked(self):
|
||||||
self.settings.set("persistent", "enabled", self.persistent_checkbox.isChecked())
|
self.settings.set("persistent", "enabled", self.persistent_checkbox.isChecked())
|
||||||
|
self.settings.set("persistent", "mode", self.tab.mode)
|
||||||
self.change_persistent.emit(self.tab_id, self.persistent_checkbox.isChecked())
|
self.change_persistent.emit(
|
||||||
|
self.tab.tab_id, self.persistent_checkbox.isChecked()
|
||||||
|
)
|
||||||
|
|
||||||
def public_checkbox_clicked(self):
|
def public_checkbox_clicked(self):
|
||||||
self.settings.set("general", "public", self.public_checkbox.isChecked())
|
self.settings.set("general", "public", self.public_checkbox.isChecked())
|
||||||
|
|
|
@ -55,10 +55,14 @@ class ShareMode(Mode):
|
||||||
self.autostop_sharing_checkbox.clicked.connect(
|
self.autostop_sharing_checkbox.clicked.connect(
|
||||||
self.autostop_sharing_checkbox_clicked
|
self.autostop_sharing_checkbox_clicked
|
||||||
)
|
)
|
||||||
self.autostop_sharing_checkbox.setCheckState(QtCore.Qt.Checked)
|
|
||||||
self.autostop_sharing_checkbox.setText(
|
self.autostop_sharing_checkbox.setText(
|
||||||
strings._("mode_settings_share_autostop_sharing_checkbox")
|
strings._("mode_settings_share_autostop_sharing_checkbox")
|
||||||
)
|
)
|
||||||
|
if self.settings.get("share", "autostop_sharing"):
|
||||||
|
self.autostop_sharing_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
|
else:
|
||||||
|
self.autostop_sharing_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
self.mode_settings_widget.mode_specific_layout.addWidget(
|
self.mode_settings_widget.mode_specific_layout.addWidget(
|
||||||
self.autostop_sharing_checkbox
|
self.autostop_sharing_checkbox
|
||||||
)
|
)
|
||||||
|
|
|
@ -55,10 +55,14 @@ class WebsiteMode(Mode):
|
||||||
# Settings
|
# Settings
|
||||||
self.disable_csp_checkbox = QtWidgets.QCheckBox()
|
self.disable_csp_checkbox = QtWidgets.QCheckBox()
|
||||||
self.disable_csp_checkbox.clicked.connect(self.disable_csp_checkbox_clicked)
|
self.disable_csp_checkbox.clicked.connect(self.disable_csp_checkbox_clicked)
|
||||||
self.disable_csp_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
|
||||||
self.disable_csp_checkbox.setText(
|
self.disable_csp_checkbox.setText(
|
||||||
strings._("mode_settings_website_disable_csp_checkbox")
|
strings._("mode_settings_website_disable_csp_checkbox")
|
||||||
)
|
)
|
||||||
|
if self.settings.get("website", "disable_csp"):
|
||||||
|
self.disable_csp_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
|
else:
|
||||||
|
self.disable_csp_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
self.mode_settings_widget.mode_specific_layout.addWidget(
|
self.mode_settings_widget.mode_specific_layout.addWidget(
|
||||||
self.disable_csp_checkbox
|
self.disable_csp_checkbox
|
||||||
)
|
)
|
||||||
|
|
|
@ -43,7 +43,15 @@ class Tab(QtWidgets.QWidget):
|
||||||
change_icon = QtCore.pyqtSignal(int, str)
|
change_icon = QtCore.pyqtSignal(int, str)
|
||||||
change_persistent = QtCore.pyqtSignal(int, bool)
|
change_persistent = QtCore.pyqtSignal(int, bool)
|
||||||
|
|
||||||
def __init__(self, common, tab_id, system_tray, status_bar, filenames=None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
common,
|
||||||
|
tab_id,
|
||||||
|
system_tray,
|
||||||
|
status_bar,
|
||||||
|
mode_settings=None,
|
||||||
|
filenames=None,
|
||||||
|
):
|
||||||
super(Tab, self).__init__()
|
super(Tab, self).__init__()
|
||||||
self.common = common
|
self.common = common
|
||||||
self.common.log("Tab", "__init__")
|
self.common.log("Tab", "__init__")
|
||||||
|
@ -130,8 +138,19 @@ class Tab(QtWidgets.QWidget):
|
||||||
)
|
)
|
||||||
self.persistent_image_label.setFixedSize(20, 20)
|
self.persistent_image_label.setFixedSize(20, 20)
|
||||||
|
|
||||||
# Settings for this tab
|
if mode_settings:
|
||||||
self.mode_settings = ModeSettings(self.common)
|
# Load this tab
|
||||||
|
self.settings = mode_settings
|
||||||
|
mode = self.settings.get("persistent", "mode")
|
||||||
|
if mode == "share":
|
||||||
|
self.share_mode_clicked()
|
||||||
|
elif mode == "receive":
|
||||||
|
self.receive_mode_clicked()
|
||||||
|
elif mode == "website":
|
||||||
|
self.website_mode_clicked()
|
||||||
|
else:
|
||||||
|
# This is a new tab
|
||||||
|
self.settings = ModeSettings(self.common)
|
||||||
|
|
||||||
def share_mode_clicked(self):
|
def share_mode_clicked(self):
|
||||||
self.common.log("Tab", "share_mode_clicked")
|
self.common.log("Tab", "share_mode_clicked")
|
||||||
|
@ -496,7 +515,7 @@ class Tab(QtWidgets.QWidget):
|
||||||
if self.mode is None:
|
if self.mode is None:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if self.mode_settings.get("persistent", "enabled"):
|
if self.settings.get("persistent", "enabled"):
|
||||||
dialog_text = strings._("gui_close_tab_warning_persistent_description")
|
dialog_text = strings._("gui_close_tab_warning_persistent_description")
|
||||||
else:
|
else:
|
||||||
server_status = self.get_mode().server_status
|
server_status = self.get_mode().server_status
|
||||||
|
|
|
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
from PyQt5 import QtCore, QtWidgets, QtGui
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||||
|
|
||||||
from onionshare import strings
|
from onionshare import strings
|
||||||
|
from onionshare.mode_settings import ModeSettings
|
||||||
|
|
||||||
from .tab import Tab
|
from .tab import Tab
|
||||||
|
|
||||||
|
@ -86,15 +87,29 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||||
self.new_tab_button.raise_()
|
self.new_tab_button.raise_()
|
||||||
|
|
||||||
def new_tab_clicked(self):
|
def new_tab_clicked(self):
|
||||||
# Create the tab
|
# Create a new tab
|
||||||
tab = Tab(self.common, self.tab_id, self.system_tray, self.status_bar)
|
tab = Tab(self.common, self.tab_id, self.system_tray, self.status_bar)
|
||||||
|
self.add_tab(tab)
|
||||||
|
|
||||||
|
def load_tab(self, mode_settings_id):
|
||||||
|
# Load the tab's mode settings
|
||||||
|
mode_settings = ModeSettings(self.common, id=mode_settings_id)
|
||||||
|
tab = Tab(
|
||||||
|
self.common,
|
||||||
|
self.tab_id,
|
||||||
|
self.system_tray,
|
||||||
|
self.status_bar,
|
||||||
|
mode_settings=mode_settings,
|
||||||
|
)
|
||||||
|
self.add_tab(tab)
|
||||||
|
|
||||||
|
def add_tab(self, tab):
|
||||||
tab.change_title.connect(self.change_title)
|
tab.change_title.connect(self.change_title)
|
||||||
tab.change_icon.connect(self.change_icon)
|
tab.change_icon.connect(self.change_icon)
|
||||||
tab.change_persistent.connect(self.change_persistent)
|
tab.change_persistent.connect(self.change_persistent)
|
||||||
self.tabs[self.tab_id] = tab
|
self.tabs[self.tab_id] = tab
|
||||||
self.tab_id += 1
|
self.tab_id += 1
|
||||||
|
|
||||||
# Add it
|
|
||||||
index = self.addTab(tab, "New Tab")
|
index = self.addTab(tab, "New Tab")
|
||||||
self.setCurrentIndex(index)
|
self.setCurrentIndex(index)
|
||||||
|
|
||||||
|
@ -121,6 +136,18 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||||
index, QtWidgets.QTabBar.LeftSide, invisible_widget
|
index, QtWidgets.QTabBar.LeftSide, invisible_widget
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.save_persistent_tabs()
|
||||||
|
|
||||||
|
def save_persistent_tabs(self):
|
||||||
|
# Figure out the order of persistent tabs to save in settings
|
||||||
|
persistent_tabs = []
|
||||||
|
for index in range(self.count()):
|
||||||
|
tab = self.widget(index)
|
||||||
|
if tab.settings.get("persistent", "enabled"):
|
||||||
|
persistent_tabs.append(tab.settings.id)
|
||||||
|
self.common.settings.set("persistent_tabs", persistent_tabs)
|
||||||
|
self.common.settings.save()
|
||||||
|
|
||||||
def close_tab(self, index):
|
def close_tab(self, index):
|
||||||
self.common.log("TabWidget", "close_tab", f"{index}")
|
self.common.log("TabWidget", "close_tab", f"{index}")
|
||||||
tab = self.widget(index)
|
tab = self.widget(index)
|
||||||
|
@ -143,6 +170,13 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def changeEvent(self, event):
|
||||||
|
# TODO: later when I have internet, figure out the right event for re-ordering tabs
|
||||||
|
|
||||||
|
# If tabs get move
|
||||||
|
super(TabWidget, self).changeEvent(event)
|
||||||
|
self.save_persistent_tabs()
|
||||||
|
|
||||||
def resizeEvent(self, event):
|
def resizeEvent(self, event):
|
||||||
# Make sure to move new tab button on each resize
|
# Make sure to move new tab button on each resize
|
||||||
super(TabWidget, self).resizeEvent(event)
|
super(TabWidget, self).resizeEvent(event)
|
||||||
|
|
Loading…
Add table
Reference in a new issue