mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-27 08:19:41 -05:00
Refactor ServerStatus to use mode settings
This commit is contained in:
parent
52d5a5193b
commit
ed1c3e1bc8
@ -88,7 +88,12 @@ class Mode(QtWidgets.QWidget):
|
|||||||
|
|
||||||
# Server status
|
# Server status
|
||||||
self.server_status = ServerStatus(
|
self.server_status = ServerStatus(
|
||||||
self.common, self.qtapp, self.app, None, self.common.gui.local_only
|
self.common,
|
||||||
|
self.qtapp,
|
||||||
|
self.app,
|
||||||
|
self.settings,
|
||||||
|
None,
|
||||||
|
self.common.gui.local_only,
|
||||||
)
|
)
|
||||||
self.server_status.server_started.connect(self.start_server)
|
self.server_status.server_started.connect(self.start_server)
|
||||||
self.server_status.server_stopped.connect(self.stop_server)
|
self.server_status.server_stopped.connect(self.stop_server)
|
||||||
@ -169,8 +174,8 @@ class Mode(QtWidgets.QWidget):
|
|||||||
|
|
||||||
# If the auto-stop timer has stopped, stop the server
|
# If the auto-stop timer has stopped, stop the server
|
||||||
if self.server_status.status == ServerStatus.STATUS_STARTED:
|
if self.server_status.status == ServerStatus.STATUS_STARTED:
|
||||||
if self.app.autostop_timer_thread and self.common.settings.get(
|
if self.app.autostop_timer_thread and self.settings.get(
|
||||||
"autostop_timer"
|
"general", "autostop_timer"
|
||||||
):
|
):
|
||||||
if self.autostop_timer_datetime_delta > 0:
|
if self.autostop_timer_datetime_delta > 0:
|
||||||
now = QtCore.QDateTime.currentDateTime()
|
now = QtCore.QDateTime.currentDateTime()
|
||||||
@ -217,14 +222,15 @@ class Mode(QtWidgets.QWidget):
|
|||||||
self.common.log("Mode", "start_server")
|
self.common.log("Mode", "start_server")
|
||||||
|
|
||||||
self.start_server_custom()
|
self.start_server_custom()
|
||||||
|
|
||||||
self.set_server_active.emit(True)
|
self.set_server_active.emit(True)
|
||||||
self.app.set_stealth(self.common.settings.get("use_stealth"))
|
|
||||||
|
|
||||||
# Clear the status bar
|
# Clear the status bar
|
||||||
self.status_bar.clearMessage()
|
self.status_bar.clearMessage()
|
||||||
self.server_status_label.setText("")
|
self.server_status_label.setText("")
|
||||||
|
|
||||||
|
# Hide the mode settings
|
||||||
|
self.mode_settings_widget.hide()
|
||||||
|
|
||||||
# Ensure we always get a new random port each time we might launch an OnionThread
|
# Ensure we always get a new random port each time we might launch an OnionThread
|
||||||
self.app.port = None
|
self.app.port = None
|
||||||
|
|
||||||
@ -307,7 +313,7 @@ class Mode(QtWidgets.QWidget):
|
|||||||
|
|
||||||
self.start_server_step3_custom()
|
self.start_server_step3_custom()
|
||||||
|
|
||||||
if self.common.settings.get("autostop_timer"):
|
if self.settings.get("general", "autostop_timer"):
|
||||||
# Convert the date value to seconds between now and then
|
# Convert the date value to seconds between now and then
|
||||||
now = QtCore.QDateTime.currentDateTime()
|
now = QtCore.QDateTime.currentDateTime()
|
||||||
self.autostop_timer_datetime_delta = now.secsTo(
|
self.autostop_timer_datetime_delta = now.secsTo(
|
||||||
@ -395,6 +401,9 @@ class Mode(QtWidgets.QWidget):
|
|||||||
self.set_server_active.emit(False)
|
self.set_server_active.emit(False)
|
||||||
self.stop_server_finished.emit()
|
self.stop_server_finished.emit()
|
||||||
|
|
||||||
|
# Show the mode settings
|
||||||
|
self.mode_settings_widget.show()
|
||||||
|
|
||||||
def stop_server_custom(self):
|
def stop_server_custom(self):
|
||||||
"""
|
"""
|
||||||
Add custom initialization here.
|
Add custom initialization here.
|
||||||
|
@ -43,7 +43,9 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
STATUS_WORKING = 1
|
STATUS_WORKING = 1
|
||||||
STATUS_STARTED = 2
|
STATUS_STARTED = 2
|
||||||
|
|
||||||
def __init__(self, common, qtapp, app, file_selection=None, local_only=False):
|
def __init__(
|
||||||
|
self, common, qtapp, app, mode_settings, file_selection=None, local_only=False
|
||||||
|
):
|
||||||
super(ServerStatus, self).__init__()
|
super(ServerStatus, self).__init__()
|
||||||
|
|
||||||
self.common = common
|
self.common = common
|
||||||
@ -53,6 +55,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
|
|
||||||
self.qtapp = qtapp
|
self.qtapp = qtapp
|
||||||
self.app = app
|
self.app = app
|
||||||
|
self.settings = mode_settings
|
||||||
|
|
||||||
self.web = None
|
self.web = None
|
||||||
self.autostart_timer_datetime = None
|
self.autostart_timer_datetime = None
|
||||||
@ -258,9 +261,9 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Show a Tool Tip explaining the lifecycle of this URL
|
# Show a Tool Tip explaining the lifecycle of this URL
|
||||||
if self.common.settings.get("save_private_key"):
|
if self.settings.get("persistent", "enabled"):
|
||||||
if self.mode == self.common.gui.MODE_SHARE and self.common.settings.get(
|
if self.mode == self.common.gui.MODE_SHARE and self.settings.get(
|
||||||
"close_after_first_download"
|
"share", "autostop_sharing"
|
||||||
):
|
):
|
||||||
self.url_description.setToolTip(
|
self.url_description.setToolTip(
|
||||||
strings._("gui_url_label_onetime_and_persistent")
|
strings._("gui_url_label_onetime_and_persistent")
|
||||||
@ -268,8 +271,8 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
else:
|
else:
|
||||||
self.url_description.setToolTip(strings._("gui_url_label_persistent"))
|
self.url_description.setToolTip(strings._("gui_url_label_persistent"))
|
||||||
else:
|
else:
|
||||||
if self.mode == self.common.gui.MODE_SHARE and self.common.settings.get(
|
if self.mode == self.common.gui.MODE_SHARE and self.settings.get(
|
||||||
"close_after_first_download"
|
"share", "autostop_sharing"
|
||||||
):
|
):
|
||||||
self.url_description.setToolTip(strings._("gui_url_label_onetime"))
|
self.url_description.setToolTip(strings._("gui_url_label_onetime"))
|
||||||
else:
|
else:
|
||||||
@ -279,7 +282,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
self.url.show()
|
self.url.show()
|
||||||
self.copy_url_button.show()
|
self.copy_url_button.show()
|
||||||
|
|
||||||
if self.app.stealth:
|
if self.settings.get("general", "client_auth"):
|
||||||
self.copy_hidservauth_button.show()
|
self.copy_hidservauth_button.show()
|
||||||
else:
|
else:
|
||||||
self.copy_hidservauth_button.hide()
|
self.copy_hidservauth_button.hide()
|
||||||
@ -295,15 +298,15 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
self.common.settings.load()
|
self.common.settings.load()
|
||||||
self.show_url()
|
self.show_url()
|
||||||
|
|
||||||
if self.common.settings.get("save_private_key"):
|
if self.settings.get("persistent", "enabled"):
|
||||||
if not self.common.settings.get("password"):
|
if not self.settings.get("persistent", "password"):
|
||||||
self.common.settings.set("password", self.web.password)
|
self.settings.set("persistent", "password", self.web.password)
|
||||||
self.common.settings.save()
|
self.settings.save()
|
||||||
|
|
||||||
if self.common.settings.get("autostart_timer"):
|
if self.settings.get("general", "autostart_timer"):
|
||||||
self.autostart_timer_container.hide()
|
self.autostart_timer_container.hide()
|
||||||
|
|
||||||
if self.common.settings.get("autostop_timer"):
|
if self.settings.get("general", "autostop_timer"):
|
||||||
self.autostop_timer_container.hide()
|
self.autostop_timer_container.hide()
|
||||||
else:
|
else:
|
||||||
self.url_description.hide()
|
self.url_description.hide()
|
||||||
@ -337,9 +340,9 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
else:
|
else:
|
||||||
self.server_button.setText(strings._("gui_receive_start_server"))
|
self.server_button.setText(strings._("gui_receive_start_server"))
|
||||||
self.server_button.setToolTip("")
|
self.server_button.setToolTip("")
|
||||||
if self.common.settings.get("autostart_timer"):
|
if self.settings.get("general", "autostart_timer"):
|
||||||
self.autostart_timer_container.show()
|
self.autostart_timer_container.show()
|
||||||
if self.common.settings.get("autostop_timer"):
|
if self.settings.get("general", "autostop_timer"):
|
||||||
self.autostop_timer_container.show()
|
self.autostop_timer_container.show()
|
||||||
elif self.status == self.STATUS_STARTED:
|
elif self.status == self.STATUS_STARTED:
|
||||||
self.server_button.setStyleSheet(
|
self.server_button.setStyleSheet(
|
||||||
@ -352,9 +355,9 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
self.server_button.setText(strings._("gui_share_stop_server"))
|
self.server_button.setText(strings._("gui_share_stop_server"))
|
||||||
else:
|
else:
|
||||||
self.server_button.setText(strings._("gui_receive_stop_server"))
|
self.server_button.setText(strings._("gui_receive_stop_server"))
|
||||||
if self.common.settings.get("autostart_timer"):
|
if self.settings.get("general", "autostart_timer"):
|
||||||
self.autostart_timer_container.hide()
|
self.autostart_timer_container.hide()
|
||||||
if self.common.settings.get("autostop_timer"):
|
if self.settings.get("general", "autostop_timer"):
|
||||||
self.autostop_timer_container.hide()
|
self.autostop_timer_container.hide()
|
||||||
self.server_button.setToolTip(
|
self.server_button.setToolTip(
|
||||||
strings._("gui_stop_server_autostop_timer_tooltip").format(
|
strings._("gui_stop_server_autostop_timer_tooltip").format(
|
||||||
@ -379,7 +382,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.server_button.setText(strings._("gui_please_wait"))
|
self.server_button.setText(strings._("gui_please_wait"))
|
||||||
if self.common.settings.get("autostop_timer"):
|
if self.settings.get("general", "autostop_timer"):
|
||||||
self.autostop_timer_container.hide()
|
self.autostop_timer_container.hide()
|
||||||
else:
|
else:
|
||||||
self.server_button.setStyleSheet(
|
self.server_button.setStyleSheet(
|
||||||
@ -387,7 +390,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
)
|
)
|
||||||
self.server_button.setEnabled(False)
|
self.server_button.setEnabled(False)
|
||||||
self.server_button.setText(strings._("gui_please_wait"))
|
self.server_button.setText(strings._("gui_please_wait"))
|
||||||
if self.common.settings.get("autostart_timer"):
|
if self.settings.get("general", "autostart_timer"):
|
||||||
self.autostart_timer_container.hide()
|
self.autostart_timer_container.hide()
|
||||||
self.server_button.setToolTip(
|
self.server_button.setToolTip(
|
||||||
strings._("gui_start_server_autostart_timer_tooltip").format(
|
strings._("gui_start_server_autostart_timer_tooltip").format(
|
||||||
@ -396,7 +399,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if self.common.settings.get("autostop_timer"):
|
if self.settings.get("general", "autostop_timer"):
|
||||||
self.autostop_timer_container.hide()
|
self.autostop_timer_container.hide()
|
||||||
|
|
||||||
def server_button_clicked(self):
|
def server_button_clicked(self):
|
||||||
@ -405,7 +408,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
"""
|
"""
|
||||||
if self.status == self.STATUS_STOPPED:
|
if self.status == self.STATUS_STOPPED:
|
||||||
can_start = True
|
can_start = True
|
||||||
if self.common.settings.get("autostart_timer"):
|
if self.settings.get("general", "autostart_timer"):
|
||||||
if self.local_only:
|
if self.local_only:
|
||||||
self.autostart_timer_datetime = (
|
self.autostart_timer_datetime = (
|
||||||
self.autostart_timer_widget.dateTime().toPyDateTime()
|
self.autostart_timer_widget.dateTime().toPyDateTime()
|
||||||
@ -427,7 +430,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
strings._("gui_server_autostart_timer_expired"),
|
strings._("gui_server_autostart_timer_expired"),
|
||||||
QtWidgets.QMessageBox.Warning,
|
QtWidgets.QMessageBox.Warning,
|
||||||
)
|
)
|
||||||
if self.common.settings.get("autostop_timer"):
|
if self.settings.get("general", "autostop_timer"):
|
||||||
if self.local_only:
|
if self.local_only:
|
||||||
self.autostop_timer_datetime = (
|
self.autostop_timer_datetime = (
|
||||||
self.autostop_timer_widget.dateTime().toPyDateTime()
|
self.autostop_timer_widget.dateTime().toPyDateTime()
|
||||||
@ -450,7 +453,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
strings._("gui_server_autostop_timer_expired"),
|
strings._("gui_server_autostop_timer_expired"),
|
||||||
QtWidgets.QMessageBox.Warning,
|
QtWidgets.QMessageBox.Warning,
|
||||||
)
|
)
|
||||||
if self.common.settings.get("autostart_timer"):
|
if self.settings.get("general", "autostart_timer"):
|
||||||
if self.autostop_timer_datetime <= self.autostart_timer_datetime:
|
if self.autostop_timer_datetime <= self.autostart_timer_datetime:
|
||||||
Alert(
|
Alert(
|
||||||
self.common,
|
self.common,
|
||||||
@ -537,7 +540,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
"""
|
"""
|
||||||
Returns the OnionShare URL.
|
Returns the OnionShare URL.
|
||||||
"""
|
"""
|
||||||
if self.common.settings.get("public_mode"):
|
if self.settings.get("general", "public"):
|
||||||
url = f"http://{self.app.onion_host}"
|
url = f"http://{self.app.onion_host}"
|
||||||
else:
|
else:
|
||||||
url = f"http://onionshare:{self.web.password}@{self.app.onion_host}"
|
url = f"http://onionshare:{self.web.password}@{self.app.onion_host}"
|
||||||
|
@ -111,12 +111,7 @@ class WebThread(QtCore.QThread):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.mode.common.log("WebThread", "run")
|
self.mode.common.log("WebThread", "run")
|
||||||
self.mode.web.start(
|
self.mode.web.start(self.mode.app.port)
|
||||||
self.mode.app.port,
|
|
||||||
self.mode.app.stay_open,
|
|
||||||
self.mode.common.settings.get("public_mode"),
|
|
||||||
self.mode.web.password,
|
|
||||||
)
|
|
||||||
self.success.emit()
|
self.success.emit()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user