mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Move auto-stop timer into settings, so its UI does not show up unless the user specifically enables that feature
This commit is contained in:
parent
23668baa09
commit
05633673fc
@ -58,6 +58,7 @@ class Settings(object):
|
||||
'auth_password': '',
|
||||
'close_after_first_download': True,
|
||||
'systray_notifications': True,
|
||||
'shutdown_timeout': False,
|
||||
'use_stealth': False,
|
||||
'use_autoupdate': True,
|
||||
'autoupdate_timestamp': None,
|
||||
|
@ -297,6 +297,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
d.settings_saved.connect(reload_settings)
|
||||
d.exec_()
|
||||
|
||||
# When settings close, refresh the server status UI
|
||||
self.server_status.update()
|
||||
|
||||
def start_server(self):
|
||||
"""
|
||||
Start the onionshare server. This uses multiple threads to start the Tor onion
|
||||
|
@ -51,31 +51,22 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.timer_enabled = False
|
||||
|
||||
# Shutdown timeout layout
|
||||
self.server_shutdown_timeout_checkbox = QtWidgets.QCheckBox()
|
||||
self.server_shutdown_timeout_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.server_shutdown_timeout_checkbox.toggled.connect(self.shutdown_timeout_toggled)
|
||||
self.server_shutdown_timeout_checkbox.setText(strings._("gui_settings_shutdown_timeout_choice", True))
|
||||
self.server_shutdown_timeout_label = QtWidgets.QLabel(strings._('gui_settings_shutdown_timeout', True))
|
||||
self.server_shutdown_timeout = QtWidgets.QDateTimeEdit()
|
||||
|
||||
self.shutdown_timeout_label = QtWidgets.QLabel(strings._('gui_settings_shutdown_timeout', True))
|
||||
self.shutdown_timeout = QtWidgets.QDateTimeEdit()
|
||||
# Set proposed timeout to be 5 minutes into the future
|
||||
self.server_shutdown_timeout.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
|
||||
self.shutdown_timeout.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
# Onion services can take a little while to start, so reduce the risk of it expiring too soon by setting the minimum to 2 min from now
|
||||
self.server_shutdown_timeout.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(120))
|
||||
self.server_shutdown_timeout.setCurrentSectionIndex(4)
|
||||
self.server_shutdown_timeout_label.hide()
|
||||
self.server_shutdown_timeout.hide()
|
||||
self.shutdown_timeout.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(120))
|
||||
self.shutdown_timeout.setCurrentSectionIndex(4)
|
||||
shutdown_timeout_layout = QtWidgets.QHBoxLayout()
|
||||
shutdown_timeout_layout.addWidget(self.server_shutdown_timeout_label)
|
||||
shutdown_timeout_layout.addWidget(self.server_shutdown_timeout)
|
||||
shutdown_timeout_layout.addWidget(self.shutdown_timeout_label)
|
||||
shutdown_timeout_layout.addWidget(self.shutdown_timeout)
|
||||
|
||||
# Shutdown timeout container, so it can all be hidden and shown as a group
|
||||
shutdown_timeout_container_layout = QtWidgets.QVBoxLayout()
|
||||
shutdown_timeout_container_layout.addWidget(self.server_shutdown_timeout_checkbox)
|
||||
shutdown_timeout_container_layout.addLayout(shutdown_timeout_layout)
|
||||
self.server_shutdown_timeout_container = QtWidgets.QWidget()
|
||||
self.server_shutdown_timeout_container.setLayout(shutdown_timeout_container_layout)
|
||||
self.shutdown_timeout_container = QtWidgets.QWidget()
|
||||
self.shutdown_timeout_container.setLayout(shutdown_timeout_container_layout)
|
||||
|
||||
# Server layout
|
||||
self.server_button = QtWidgets.QPushButton()
|
||||
@ -118,7 +109,7 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
layout.addWidget(self.server_button)
|
||||
layout.addLayout(url_layout)
|
||||
layout.addWidget(self.server_shutdown_timeout_container)
|
||||
layout.addWidget(self.shutdown_timeout_container)
|
||||
self.setLayout(layout)
|
||||
|
||||
self.update()
|
||||
@ -130,22 +121,21 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
if checked:
|
||||
self.timer_enabled = True
|
||||
# Hide the checkbox, show the options
|
||||
self.server_shutdown_timeout_label.show()
|
||||
self.shutdown_timeout_label.show()
|
||||
# Reset the default timer to 5 minutes into the future after toggling the option on
|
||||
self.server_shutdown_timeout.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
self.server_shutdown_timeout.show()
|
||||
self.shutdown_timeout.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
self.shutdown_timeout.show()
|
||||
else:
|
||||
self.timer_enabled = False
|
||||
self.server_shutdown_timeout_label.hide()
|
||||
self.server_shutdown_timeout.hide()
|
||||
self.shutdown_timeout_label.hide()
|
||||
self.shutdown_timeout.hide()
|
||||
|
||||
def shutdown_timeout_reset(self):
|
||||
"""
|
||||
Reset the timeout in the UI after stopping a share
|
||||
"""
|
||||
self.server_shutdown_timeout_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.server_shutdown_timeout.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
self.server_shutdown_timeout.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(120))
|
||||
self.shutdown_timeout.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
self.shutdown_timeout.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(120))
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
@ -191,40 +181,31 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
else:
|
||||
self.server_button.show()
|
||||
|
||||
if self.status == self.STATUS_STOPPED:
|
||||
self.server_shutdown_timeout_checkbox.show()
|
||||
self.server_shutdown_timeout_container.show()
|
||||
if self.settings.get('shutdown_timeout'):
|
||||
self.shutdown_timeout_container.show()
|
||||
else:
|
||||
self.server_shutdown_timeout_checkbox.hide()
|
||||
if self.server_shutdown_timeout_checkbox.isChecked():
|
||||
self.server_shutdown_timeout_container.show()
|
||||
else:
|
||||
self.server_shutdown_timeout_container.hide()
|
||||
self.shutdown_timeout_container.hide()
|
||||
|
||||
if self.status == self.STATUS_STOPPED:
|
||||
self.server_button.setStyleSheet(button_stopped_style)
|
||||
self.server_button.setEnabled(True)
|
||||
self.server_button.setText(strings._('gui_start_server', True))
|
||||
self.server_shutdown_timeout.setEnabled(True)
|
||||
self.server_shutdown_timeout_checkbox.setEnabled(True)
|
||||
self.shutdown_timeout.setEnabled(True)
|
||||
elif self.status == self.STATUS_STARTED:
|
||||
self.server_button.setStyleSheet(button_started_style)
|
||||
self.server_button.setEnabled(True)
|
||||
self.server_button.setText(strings._('gui_stop_server', True))
|
||||
self.server_shutdown_timeout.setEnabled(False)
|
||||
self.server_shutdown_timeout_checkbox.setEnabled(False)
|
||||
self.shutdown_timeout.setEnabled(False)
|
||||
elif self.status == self.STATUS_WORKING:
|
||||
self.server_button.setStyleSheet(button_working_style)
|
||||
self.server_button.setEnabled(False)
|
||||
self.server_button.setText(strings._('gui_please_wait'))
|
||||
self.server_shutdown_timeout.setEnabled(False)
|
||||
self.server_shutdown_timeout_checkbox.setEnabled(False)
|
||||
self.shutdown_timeout.setEnabled(False)
|
||||
else:
|
||||
self.server_button.setStyleSheet(button_working_style)
|
||||
self.server_button.setEnabled(False)
|
||||
self.server_button.setText(strings._('gui_please_wait'))
|
||||
self.server_shutdown_timeout.setEnabled(False)
|
||||
self.server_shutdown_timeout_checkbox.setEnabled(False)
|
||||
self.shutdown_timeout.setEnabled(False)
|
||||
|
||||
def server_button_clicked(self):
|
||||
"""
|
||||
@ -233,7 +214,7 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
if self.status == self.STATUS_STOPPED:
|
||||
if self.timer_enabled:
|
||||
# Get the timeout chosen, stripped of its seconds. This prevents confusion if the share stops at (say) 37 seconds past the minute chosen
|
||||
self.timeout = self.server_shutdown_timeout.dateTime().toPyDateTime().replace(second=0, microsecond=0)
|
||||
self.timeout = self.shutdown_timeout.dateTime().toPyDateTime().replace(second=0, microsecond=0)
|
||||
# If the timeout has actually passed already before the user hit Start, refuse to start the server.
|
||||
if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.timeout:
|
||||
Alert(strings._('gui_server_timeout_expired', QtWidgets.QMessageBox.Warning))
|
||||
|
@ -60,6 +60,11 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
self.systray_notifications_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
self.systray_notifications_checkbox.setText(strings._("gui_settings_systray_notifications", True))
|
||||
|
||||
# Whether or not to use a shutdown timer
|
||||
self.shutdown_timeout_checkbox = QtWidgets.QCheckBox()
|
||||
self.shutdown_timeout_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
self.shutdown_timeout_checkbox.setText(strings._("gui_settings_shutdown_timeout_checkbox", True))
|
||||
|
||||
# Whether or not to save the Onion private key for reuse
|
||||
self.save_private_key_checkbox = QtWidgets.QCheckBox()
|
||||
self.save_private_key_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
@ -69,6 +74,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
sharing_group_layout = QtWidgets.QVBoxLayout()
|
||||
sharing_group_layout.addWidget(self.close_after_first_download_checkbox)
|
||||
sharing_group_layout.addWidget(self.systray_notifications_checkbox)
|
||||
sharing_group_layout.addWidget(self.shutdown_timeout_checkbox)
|
||||
sharing_group_layout.addWidget(self.save_private_key_checkbox)
|
||||
sharing_group = QtWidgets.QGroupBox(strings._("gui_settings_sharing_label", True))
|
||||
sharing_group.setLayout(sharing_group_layout)
|
||||
@ -352,6 +358,12 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
else:
|
||||
self.systray_notifications_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
|
||||
shutdown_timeout = self.old_settings.get('shutdown_timeout')
|
||||
if shutdown_timeout:
|
||||
self.shutdown_timeout_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
else:
|
||||
self.shutdown_timeout_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
|
||||
save_private_key = self.old_settings.get('save_private_key')
|
||||
if save_private_key:
|
||||
self.save_private_key_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
@ -684,6 +696,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
|
||||
settings.set('close_after_first_download', self.close_after_first_download_checkbox.isChecked())
|
||||
settings.set('systray_notifications', self.systray_notifications_checkbox.isChecked())
|
||||
settings.set('shutdown_timeout', self.shutdown_timeout_checkbox.isChecked())
|
||||
if self.save_private_key_checkbox.isChecked():
|
||||
settings.set('save_private_key', True)
|
||||
settings.set('private_key', self.old_settings.get('private_key'))
|
||||
|
@ -102,7 +102,7 @@
|
||||
"gui_settings_button_save": "Save",
|
||||
"gui_settings_button_cancel": "Cancel",
|
||||
"gui_settings_button_help": "Help",
|
||||
"gui_settings_shutdown_timeout_choice": "Set auto-stop timer?",
|
||||
"gui_settings_shutdown_timeout_checkbox": "Use auto-stop timer",
|
||||
"gui_settings_shutdown_timeout": "Stop the share at:",
|
||||
"settings_saved": "Settings saved to {}",
|
||||
"settings_error_unknown": "Can't connect to Tor controller because the settings don't make sense.",
|
||||
|
Loading…
Reference in New Issue
Block a user