mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-14 13:41:25 -05:00
Make a new ModeSettings class in onionshare, and use this instead of tab_settings
This commit is contained in:
parent
c42c11648c
commit
61dc04a105
54
onionshare/mode_settings.py
Normal file
54
onionshare/mode_settings.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
OnionShare | https://onionshare.org/
|
||||||
|
|
||||||
|
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class ModeSettings:
|
||||||
|
"""
|
||||||
|
This stores the settings for a single instance of an OnionShare mode. In CLI there
|
||||||
|
is only one TabSettings, and in the GUI there is a separate TabSettings for each tab
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, common):
|
||||||
|
self.common = common
|
||||||
|
|
||||||
|
self.settings = {
|
||||||
|
"persistent": {
|
||||||
|
"enabled": False,
|
||||||
|
"private_key": None,
|
||||||
|
"hidservauth": None,
|
||||||
|
"password": None,
|
||||||
|
},
|
||||||
|
"general": {
|
||||||
|
"public": False,
|
||||||
|
"autostart_timer": False,
|
||||||
|
"autostop_timer": False,
|
||||||
|
"legacy": False,
|
||||||
|
"client_auth": False,
|
||||||
|
},
|
||||||
|
"share": {"autostop_sharing": True},
|
||||||
|
"receive": {"data_dir": self.common.settings.build_default_data_dir()},
|
||||||
|
"website": {"disable_csp": False},
|
||||||
|
}
|
||||||
|
|
||||||
|
def get(self, group, key):
|
||||||
|
return self.settings[group][key]
|
||||||
|
|
||||||
|
def set(self, group, key, val):
|
||||||
|
self.settings[group][key] = val
|
@ -60,10 +60,19 @@ class Web:
|
|||||||
REQUEST_OTHER = 13
|
REQUEST_OTHER = 13
|
||||||
REQUEST_INVALID_PASSWORD = 14
|
REQUEST_INVALID_PASSWORD = 14
|
||||||
|
|
||||||
def __init__(self, common, is_gui, mode="share"):
|
def __init__(
|
||||||
|
self, common, is_gui, tab_settings_get=None, tab_settings_set=None, mode="share"
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
tab_settings_get and tab_settings_set are getter and setter functions for tab settings
|
||||||
|
"""
|
||||||
|
|
||||||
self.common = common
|
self.common = common
|
||||||
self.common.log("Web", "__init__", f"is_gui={is_gui}, mode={mode}")
|
self.common.log("Web", "__init__", f"is_gui={is_gui}, mode={mode}")
|
||||||
|
|
||||||
|
self.settings_get = tab_settings_get
|
||||||
|
self.settings_set = tab_settings_set
|
||||||
|
|
||||||
# The flask app
|
# The flask app
|
||||||
self.app = Flask(
|
self.app = Flask(
|
||||||
__name__,
|
__name__,
|
||||||
|
@ -23,7 +23,7 @@ from onionshare import strings
|
|||||||
from onionshare.common import AutoStopTimer
|
from onionshare.common import AutoStopTimer
|
||||||
|
|
||||||
from .history import IndividualFileHistoryItem
|
from .history import IndividualFileHistoryItem
|
||||||
from .mode_settings import ModeSettings
|
from .mode_settings_widget import ModeSettingsWidget
|
||||||
|
|
||||||
from ..server_status import ServerStatus
|
from ..server_status import ServerStatus
|
||||||
from ...threads import OnionThread, AutoStartTimer
|
from ...threads import OnionThread, AutoStartTimer
|
||||||
@ -47,6 +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.common = tab.common
|
self.common = tab.common
|
||||||
self.qtapp = self.common.gui.qtapp
|
self.qtapp = self.common.gui.qtapp
|
||||||
@ -72,7 +73,9 @@ class Mode(QtWidgets.QWidget):
|
|||||||
self.header_label.setStyleSheet(self.common.gui.css["mode_header_label"])
|
self.header_label.setStyleSheet(self.common.gui.css["mode_header_label"])
|
||||||
self.header_label.setAlignment(QtCore.Qt.AlignHCenter)
|
self.header_label.setAlignment(QtCore.Qt.AlignHCenter)
|
||||||
|
|
||||||
self.mode_settings = ModeSettings(self.common, self.tab)
|
self.mode_settings = ModeSettingsWidget(
|
||||||
|
self.common, self.tab.tab_id, self.tab.mode_settings
|
||||||
|
)
|
||||||
self.mode_settings.change_persistent.connect(self.change_persistent)
|
self.mode_settings.change_persistent.connect(self.change_persistent)
|
||||||
|
|
||||||
header_layout = QtWidgets.QVBoxLayout()
|
header_layout = QtWidgets.QVBoxLayout()
|
||||||
|
@ -22,17 +22,18 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
|||||||
from onionshare import strings
|
from onionshare import strings
|
||||||
|
|
||||||
|
|
||||||
class ModeSettings(QtWidgets.QWidget):
|
class ModeSettingsWidget(QtWidgets.QWidget):
|
||||||
"""
|
"""
|
||||||
All of the common settings for each mode are in this widget
|
All of the common settings for each mode are in this widget
|
||||||
"""
|
"""
|
||||||
|
|
||||||
change_persistent = QtCore.pyqtSignal(int, bool)
|
change_persistent = QtCore.pyqtSignal(int, bool)
|
||||||
|
|
||||||
def __init__(self, common, tab):
|
def __init__(self, common, tab_id, mode_settings):
|
||||||
super(ModeSettings, self).__init__()
|
super(ModeSettingsWidget, self).__init__()
|
||||||
self.common = common
|
self.common = common
|
||||||
self.tab = tab
|
self.tab_id = tab_id
|
||||||
|
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
|
||||||
self.mode_specific_layout = QtWidgets.QVBoxLayout()
|
self.mode_specific_layout = QtWidgets.QVBoxLayout()
|
||||||
@ -137,32 +138,28 @@ class ModeSettings(QtWidgets.QWidget):
|
|||||||
self.client_auth_checkbox.hide()
|
self.client_auth_checkbox.hide()
|
||||||
|
|
||||||
def persistent_checkbox_clicked(self):
|
def persistent_checkbox_clicked(self):
|
||||||
self.tab.set_tab_setting(
|
self.settings.set("persistent", "enabled", self.persistent_checkbox.isChecked())
|
||||||
"persistent", "enabled", self.persistent_checkbox.isChecked()
|
|
||||||
)
|
|
||||||
|
|
||||||
self.change_persistent.emit(
|
self.change_persistent.emit(self.tab_id, self.persistent_checkbox.isChecked())
|
||||||
self.tab.tab_id, self.persistent_checkbox.isChecked()
|
|
||||||
)
|
|
||||||
|
|
||||||
def public_checkbox_clicked(self):
|
def public_checkbox_clicked(self):
|
||||||
self.tab.set_tab_setting("general", "public", self.public_checkbox.isChecked())
|
self.settings.set("general", "public", self.public_checkbox.isChecked())
|
||||||
|
|
||||||
def autostart_timer_checkbox_clicked(self):
|
def autostart_timer_checkbox_clicked(self):
|
||||||
self.tab.set_tab_setting(
|
self.settings.set(
|
||||||
"general", "autostart_timer", self.autostart_timer_checkbox.isChecked()
|
"general", "autostart_timer", self.autostart_timer_checkbox.isChecked()
|
||||||
)
|
)
|
||||||
|
|
||||||
def autostop_timer_checkbox_clicked(self):
|
def autostop_timer_checkbox_clicked(self):
|
||||||
self.tab.set_tab_setting(
|
self.settings.set(
|
||||||
"general", "autostop_timer", self.autostop_timer_checkbox.isChecked()
|
"general", "autostop_timer", self.autostop_timer_checkbox.isChecked()
|
||||||
)
|
)
|
||||||
|
|
||||||
def legacy_checkbox_clicked(self):
|
def legacy_checkbox_clicked(self):
|
||||||
self.tab.set_tab_setting("general", "legacy", self.legacy_checkbox.isChecked())
|
self.settings.set("general", "legacy", self.legacy_checkbox.isChecked())
|
||||||
|
|
||||||
def client_auth_checkbox_clicked(self):
|
def client_auth_checkbox_clicked(self):
|
||||||
self.tab.set_tab_setting(
|
self.settings.set(
|
||||||
"general", "client_auth", self.client_auth_checkbox.isChecked()
|
"general", "client_auth", self.client_auth_checkbox.isChecked()
|
||||||
)
|
)
|
||||||
|
|
@ -47,7 +47,7 @@ class ReceiveMode(Mode):
|
|||||||
)
|
)
|
||||||
self.data_dir_lineedit = QtWidgets.QLineEdit()
|
self.data_dir_lineedit = QtWidgets.QLineEdit()
|
||||||
self.data_dir_lineedit.setReadOnly(True)
|
self.data_dir_lineedit.setReadOnly(True)
|
||||||
self.data_dir_lineedit.setText(self.tab.tab_settings["receive"]["data_dir"])
|
self.data_dir_lineedit.setText(self.settings.get("receive", "data_dir"))
|
||||||
data_dir_button = QtWidgets.QPushButton(
|
data_dir_button = QtWidgets.QPushButton(
|
||||||
strings._("mode_settings_receive_data_dir_browse_button")
|
strings._("mode_settings_receive_data_dir_browse_button")
|
||||||
)
|
)
|
||||||
@ -140,7 +140,7 @@ class ReceiveMode(Mode):
|
|||||||
f"selected dir: {selected_dir}",
|
f"selected dir: {selected_dir}",
|
||||||
)
|
)
|
||||||
self.data_dir_lineedit.setText(selected_dir)
|
self.data_dir_lineedit.setText(selected_dir)
|
||||||
self.tab.set_tab_setting("receive", "data_dir", data_dir)
|
self.settings.set("receive", "data_dir", data_dir)
|
||||||
|
|
||||||
def get_stop_server_autostop_timer_text(self):
|
def get_stop_server_autostop_timer_text(self):
|
||||||
"""
|
"""
|
||||||
|
@ -157,7 +157,7 @@ class ShareMode(Mode):
|
|||||||
"""
|
"""
|
||||||
Save autostop sharing setting to the tab settings
|
Save autostop sharing setting to the tab settings
|
||||||
"""
|
"""
|
||||||
self.tab.set_tab_setting(
|
self.settings.set(
|
||||||
"share", "autostop_sharing", self.autostop_sharing_checkbox.isChecked()
|
"share", "autostop_sharing", self.autostop_sharing_checkbox.isChecked()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -309,7 +309,7 @@ class ShareMode(Mode):
|
|||||||
self.history.update_in_progress()
|
self.history.update_in_progress()
|
||||||
|
|
||||||
# Close on finish?
|
# Close on finish?
|
||||||
if self.tab.tab_settings["share"]["autostop_sharing"]:
|
if self.settings.get("share", "autostop_sharing"):
|
||||||
self.server_status.stop_server()
|
self.server_status.stop_server()
|
||||||
self.status_bar.clearMessage()
|
self.status_bar.clearMessage()
|
||||||
self.server_status_label.setText(strings._("closing_automatically"))
|
self.server_status_label.setText(strings._("closing_automatically"))
|
||||||
|
@ -155,7 +155,7 @@ class WebsiteMode(Mode):
|
|||||||
"""
|
"""
|
||||||
Save disable CSP setting to the tab settings
|
Save disable CSP setting to the tab settings
|
||||||
"""
|
"""
|
||||||
self.tab.set_tab_setting(
|
self.settings.set(
|
||||||
"website", "disable_csp", self.disable_csp_checkbox.isChecked()
|
"website", "disable_csp", self.disable_csp_checkbox.isChecked()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
|||||||
from onionshare import strings
|
from onionshare import strings
|
||||||
from onionshare.onionshare import OnionShare
|
from onionshare.onionshare import OnionShare
|
||||||
from onionshare.web import Web
|
from onionshare.web import Web
|
||||||
|
from onionshare.mode_settings import ModeSettings
|
||||||
|
|
||||||
from .mode.share_mode import ShareMode
|
from .mode.share_mode import ShareMode
|
||||||
from .mode.receive_mode import ReceiveMode
|
from .mode.receive_mode import ReceiveMode
|
||||||
@ -130,30 +131,7 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self.persistent_image_label.setFixedSize(30, 30)
|
self.persistent_image_label.setFixedSize(30, 30)
|
||||||
|
|
||||||
# Settings for this tab
|
# Settings for this tab
|
||||||
self.tab_settings = {
|
self.mode_settings = ModeSettings(self.common)
|
||||||
"persistent": {
|
|
||||||
"enabled": False,
|
|
||||||
"private_key": None,
|
|
||||||
"hidservauth": None,
|
|
||||||
"password": None,
|
|
||||||
},
|
|
||||||
"general": {
|
|
||||||
"public": False,
|
|
||||||
"autostart_timer": False,
|
|
||||||
"autostop_timer": False,
|
|
||||||
"legacy": False,
|
|
||||||
"client_auth": False,
|
|
||||||
},
|
|
||||||
"share": {"autostop_sharing": True},
|
|
||||||
"receive": {"data_dir": self.common.settings.build_default_data_dir()},
|
|
||||||
"website": {"disable_csp": False},
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_tab_setting(self, group, key):
|
|
||||||
return self.tab_settings[group][key]
|
|
||||||
|
|
||||||
def set_tab_setting(self, group, key, val):
|
|
||||||
self.tab_settings[group][key] = val
|
|
||||||
|
|
||||||
def share_mode_clicked(self):
|
def share_mode_clicked(self):
|
||||||
self.common.log("Tab", "share_mode_clicked")
|
self.common.log("Tab", "share_mode_clicked")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user