summaryrefslogtreecommitdiff
path: root/onionshare_gui
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2019-03-25 15:28:31 +1100
committerMiguel Jacq <mig@mig5.net>2019-03-25 15:28:31 +1100
commitee3a14a0253b409ad58c289cea788333cda93d37 (patch)
tree6e9b8bfea44846914b9bdc96aea15eb9be77dcdb /onionshare_gui
parentc411e8d61a952faca758673a5c59133986fd9623 (diff)
downloadonionshare-ee3a14a0253b409ad58c289cea788333cda93d37.tar.gz
onionshare-ee3a14a0253b409ad58c289cea788333cda93d37.zip
Standardise all startup_timer, scheduled_start attributes as 'autostart_timer'
Diffstat (limited to 'onionshare_gui')
-rw-r--r--onionshare_gui/mode/__init__.py16
-rw-r--r--onionshare_gui/onionshare_gui.py16
-rw-r--r--onionshare_gui/server_status.py94
-rw-r--r--onionshare_gui/settings_dialog.py44
-rw-r--r--onionshare_gui/threads.py12
5 files changed, 91 insertions, 91 deletions
diff --git a/onionshare_gui/mode/__init__.py b/onionshare_gui/mode/__init__.py
index 954bcc4d..8f5ff32b 100644
--- a/onionshare_gui/mode/__init__.py
+++ b/onionshare_gui/mode/__init__.py
@@ -24,7 +24,7 @@ from onionshare.common import AutoStopTimer
from ..server_status import ServerStatus
from ..threads import OnionThread
-from ..threads import StartupTimer
+from ..threads import AutoStartTimer
from ..widgets import Alert
class Mode(QtWidgets.QWidget):
@@ -115,12 +115,12 @@ class Mode(QtWidgets.QWidget):
"""
# If this is a scheduled share, display the countdown til the share starts
if self.server_status.status == ServerStatus.STATUS_WORKING:
- if self.server_status.scheduled_start:
+ if self.server_status.autostart_timer_datetime:
now = QtCore.QDateTime.currentDateTime()
if self.server_status.local_only:
- seconds_remaining = now.secsTo(self.server_status.startup_timer.dateTime())
+ seconds_remaining = now.secsTo(self.server_status.autostart_timer_widget.dateTime())
else:
- seconds_remaining = now.secsTo(self.server_status.scheduled_start.replace(second=0, microsecond=0))
+ seconds_remaining = now.secsTo(self.server_status.autostart_timer_datetime.replace(second=0, microsecond=0))
# Update the server button
if seconds_remaining > 0:
self.server_status.server_button.setText(strings._('gui_waiting_to_start').format(self.human_friendly_time(seconds_remaining)))
@@ -183,15 +183,15 @@ class Mode(QtWidgets.QWidget):
# Start the onion thread. If this share was scheduled for a future date,
# the OnionThread will start and exit 'early' to obtain the port, slug
# and onion address, but it will not start the WebThread yet.
- if self.server_status.scheduled_start:
+ if self.server_status.autostart_timer_datetime:
self.start_onion_thread(obtain_onion_early=True)
else:
self.start_onion_thread()
# If scheduling a share, delay starting the real share
- if self.server_status.scheduled_start:
- self.common.log('Mode', 'start_server', 'Starting startup timer')
- self.startup_thread = StartupTimer(self)
+ if self.server_status.autostart_timer_datetime:
+ self.common.log('Mode', 'start_server', 'Starting auto-start timer')
+ self.startup_thread = AutoStartTimer(self)
# Once the timer has finished, start the real share, with a WebThread
self.startup_thread.success.connect(self.start_scheduled_service)
self.startup_thread.error.connect(self.start_server_error)
diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py
index 0627d205..88c0052e 100644
--- a/onionshare_gui/onionshare_gui.py
+++ b/onionshare_gui/onionshare_gui.py
@@ -228,7 +228,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.server_status_label.setText(strings._('gui_status_indicator_share_stopped'))
elif self.share_mode.server_status.status == ServerStatus.STATUS_WORKING:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working))
- if self.share_mode.server_status.scheduled_start:
+ if self.share_mode.server_status.autostart_timer_datetime:
self.server_status_label.setText(strings._('gui_status_indicator_share_scheduled'))
else:
self.server_status_label.setText(strings._('gui_status_indicator_share_working'))
@@ -242,7 +242,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.server_status_label.setText(strings._('gui_status_indicator_receive_stopped'))
elif self.receive_mode.server_status.status == ServerStatus.STATUS_WORKING:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working))
- if self.receive_mode.server_status.scheduled_start:
+ if self.receive_mode.server_status.autostart_timer_datetime:
self.server_status_label.setText(strings._('gui_status_indicator_receive_scheduled'))
else:
self.server_status_label.setText(strings._('gui_status_indicator_receive_working'))
@@ -319,12 +319,12 @@ class OnionShareGui(QtWidgets.QMainWindow):
if not self.common.settings.get('autostop_timer'):
self.share_mode.server_status.autostop_timer_container.hide()
self.receive_mode.server_status.autostop_timer_container.hide()
- # If we switched off the startup timer setting, ensure the widget is hidden.
- if not self.common.settings.get('startup_timer'):
- self.share_mode.server_status.scheduled_start = None
- self.receive_mode.server_status.scheduled_start = None
- self.share_mode.server_status.startup_timer_container.hide()
- self.receive_mode.server_status.startup_timer_container.hide()
+ # If we switched off the auto-start timer setting, ensure the widget is hidden.
+ if not self.common.settings.get('autostart_timer'):
+ self.share_mode.server_status.autostart_timer_datetime = None
+ self.receive_mode.server_status.autostart_timer_datetime = None
+ self.share_mode.server_status.autostart_timer_container.hide()
+ self.receive_mode.server_status.autostart_timer_container.hide()
d = SettingsDialog(self.common, self.onion, self.qtapp, self.config, self.local_only)
d.settings_saved.connect(reload_settings)
diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py
index d05c8251..9f5b095d 100644
--- a/onionshare_gui/server_status.py
+++ b/onionshare_gui/server_status.py
@@ -56,35 +56,35 @@ class ServerStatus(QtWidgets.QWidget):
self.app = app
self.web = None
- self.scheduled_start = None
+ self.autostart_timer_datetime = None
self.local_only = local_only
self.resizeEvent(None)
- # Startup timer layout
- self.startup_timer_label = QtWidgets.QLabel(strings._('gui_settings_startup_timer'))
- self.startup_timer = QtWidgets.QDateTimeEdit()
- self.startup_timer.setDisplayFormat("hh:mm A MMM d, yy")
+ # Auto-start timer layout
+ self.autostart_timer_label = QtWidgets.QLabel(strings._('gui_settings_autostart_timer'))
+ self.autostart_timer_widget = QtWidgets.QDateTimeEdit()
+ self.autostart_timer_widget.setDisplayFormat("hh:mm A MMM d, yy")
if self.local_only:
# For testing
- self.startup_timer.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(15))
- self.startup_timer.setMinimumDateTime(QtCore.QDateTime.currentDateTime())
+ self.autostart_timer_widget.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(15))
+ self.autostart_timer_widget.setMinimumDateTime(QtCore.QDateTime.currentDateTime())
else:
# Set proposed timer to be 5 minutes into the future
- self.startup_timer.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
+ self.autostart_timer_widget.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 60s from now
- self.startup_timer.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
- self.startup_timer.setCurrentSection(QtWidgets.QDateTimeEdit.MinuteSection)
- startup_timer_layout = QtWidgets.QHBoxLayout()
- startup_timer_layout.addWidget(self.startup_timer_label)
- startup_timer_layout.addWidget(self.startup_timer)
-
- # Startup timer container, so it can all be hidden and shown as a group
- startup_timer_container_layout = QtWidgets.QVBoxLayout()
- startup_timer_container_layout.addLayout(startup_timer_layout)
- self.startup_timer_container = QtWidgets.QWidget()
- self.startup_timer_container.setLayout(startup_timer_container_layout)
- self.startup_timer_container.hide()
+ self.autostart_timer_widget.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
+ self.autostart_timer_widget.setCurrentSection(QtWidgets.QDateTimeEdit.MinuteSection)
+ autostart_timer_layout = QtWidgets.QHBoxLayout()
+ autostart_timer_layout.addWidget(self.autostart_timer_label)
+ autostart_timer_layout.addWidget(self.autostart_timer_widget)
+
+ # Auto-start timer container, so it can all be hidden and shown as a group
+ autostart_timer_container_layout = QtWidgets.QVBoxLayout()
+ autostart_timer_container_layout.addLayout(autostart_timer_layout)
+ self.autostart_timer_container = QtWidgets.QWidget()
+ self.autostart_timer_container.setLayout(autostart_timer_container_layout)
+ self.autostart_timer_container.hide()
# Auto-stop timer layout
self.autostop_timer_label = QtWidgets.QLabel(strings._('gui_settings_autostop_timer'))
@@ -149,7 +149,7 @@ class ServerStatus(QtWidgets.QWidget):
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.server_button)
layout.addLayout(url_layout)
- layout.addWidget(self.startup_timer_container)
+ layout.addWidget(self.autostart_timer_container)
layout.addWidget(self.autostop_timer_container)
self.setLayout(layout)
@@ -181,13 +181,13 @@ class ServerStatus(QtWidgets.QWidget):
except:
pass
- def startup_timer_reset(self):
+ def autostart_timer_reset(self):
"""
- Reset the timer in the UI after stopping a share
+ Reset the auto-start timer in the UI after stopping a share
"""
- self.startup_timer.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
+ self.autostart_timer_widget.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
if not self.local_only:
- self.startup_timer.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
+ self.autostart_timer_widget.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
def autostop_timer_reset(self):
"""
@@ -244,8 +244,8 @@ class ServerStatus(QtWidgets.QWidget):
self.common.settings.set('slug', self.web.slug)
self.common.settings.save()
- if self.common.settings.get('startup_timer'):
- self.startup_timer_container.hide()
+ if self.common.settings.get('autostart_timer'):
+ self.autostart_timer_container.hide()
if self.common.settings.get('autostop_timer'):
self.autostop_timer_container.hide()
@@ -269,8 +269,8 @@ class ServerStatus(QtWidgets.QWidget):
else:
self.server_button.setText(strings._('gui_receive_start_server'))
self.server_button.setToolTip('')
- if self.common.settings.get('startup_timer'):
- self.startup_timer_container.show()
+ if self.common.settings.get('autostart_timer'):
+ self.autostart_timer_container.show()
if self.common.settings.get('autostop_timer'):
self.autostop_timer_container.show()
elif self.status == self.STATUS_STARTED:
@@ -280,17 +280,17 @@ class ServerStatus(QtWidgets.QWidget):
self.server_button.setText(strings._('gui_share_stop_server'))
else:
self.server_button.setText(strings._('gui_receive_stop_server'))
- if self.common.settings.get('startup_timer'):
- self.startup_timer_container.hide()
+ if self.common.settings.get('autostart_timer'):
+ self.autostart_timer_container.hide()
if self.common.settings.get('autostop_timer'):
self.autostop_timer_container.hide()
self.server_button.setToolTip(strings._('gui_stop_server_autostop_timer_tooltip').format(self.autostop_timer_widget.dateTime().toString("H:mmAP, MMM dd, yy")))
elif self.status == self.STATUS_WORKING:
self.server_button.setStyleSheet(self.common.css['server_status_button_working'])
self.server_button.setEnabled(True)
- if self.scheduled_start:
- self.startup_timer_container.hide()
- self.server_button.setToolTip(strings._('gui_start_server_startup_timer_tooltip').format(self.startup_timer.dateTime().toString("H:mmAP, MMM dd, yy")))
+ if self.autostart_timer_datetime:
+ self.autostart_timer_container.hide()
+ self.server_button.setToolTip(strings._('gui_start_server_autostart_timer_tooltip').format(self.autostart_timer_widget.dateTime().toString("H:mmAP, MMM dd, yy")))
else:
self.server_button.setText(strings._('gui_please_wait'))
if self.common.settings.get('autostop_timer'):
@@ -299,9 +299,9 @@ class ServerStatus(QtWidgets.QWidget):
self.server_button.setStyleSheet(self.common.css['server_status_button_working'])
self.server_button.setEnabled(False)
self.server_button.setText(strings._('gui_please_wait'))
- if self.common.settings.get('startup_timer'):
- self.startup_timer_container.hide()
- self.server_button.setToolTip(strings._('gui_start_server_startup_timer_tooltip').format(self.startup_timer.dateTime().toString("H:mmAP, MMM dd, yy")))
+ if self.common.settings.get('autostart_timer'):
+ self.autostart_timer_container.hide()
+ self.server_button.setToolTip(strings._('gui_start_server_autostart_timer_tooltip').format(self.autostart_timer_widget.dateTime().toString("H:mmAP, MMM dd, yy")))
if self.common.settings.get('autostop_timer'):
self.autostop_timer_container.hide()
@@ -311,15 +311,15 @@ class ServerStatus(QtWidgets.QWidget):
"""
if self.status == self.STATUS_STOPPED:
can_start = True
- if self.common.settings.get('startup_timer'):
+ if self.common.settings.get('autostart_timer'):
if self.local_only:
- self.scheduled_start = self.startup_timer.dateTime().toPyDateTime()
+ self.autostart_timer_datetime = self.autostart_timer_widget.dateTime().toPyDateTime()
else:
- self.scheduled_start = self.startup_timer.dateTime().toPyDateTime().replace(second=0, microsecond=0)
+ self.autostart_timer_datetime = self.autostart_timer_widget.dateTime().toPyDateTime().replace(second=0, microsecond=0)
# If the timer has actually passed already before the user hit Start, refuse to start the server.
- if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.scheduled_start:
+ if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.autostart_timer_datetime:
can_start = False
- Alert(self.common, strings._('gui_server_startup_timer_expired'), QtWidgets.QMessageBox.Warning)
+ Alert(self.common, strings._('gui_server_autostart_timer_expired'), QtWidgets.QMessageBox.Warning)
if self.common.settings.get('autostop_timer'):
if self.local_only:
self.autostop_timer_datetime = self.autostop_timer_widget.dateTime().toPyDateTime()
@@ -330,9 +330,9 @@ class ServerStatus(QtWidgets.QWidget):
if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.autostop_timer_datetime:
can_start = False
Alert(self.common, strings._('gui_server_autostop_timer_expired'), QtWidgets.QMessageBox.Warning)
- if self.common.settings.get('startup_timer'):
- if self.autostop_timer_datetime <= self.scheduled_start:
- Alert(self.common, strings._('gui_autostop_timer_cant_be_earlier_than_startup'), QtWidgets.QMessageBox.Warning)
+ if self.common.settings.get('autostart_timer'):
+ if self.autostop_timer_datetime <= self.autostart_timer_datetime:
+ Alert(self.common, strings._('gui_autostop_timer_cant_be_earlier_than_autostart_timer'), QtWidgets.QMessageBox.Warning)
can_start = False
if can_start:
self.start_server()
@@ -364,7 +364,7 @@ class ServerStatus(QtWidgets.QWidget):
Stop the server.
"""
self.status = self.STATUS_WORKING
- self.startup_timer_reset()
+ self.autostart_timer_reset()
self.autostop_timer_reset()
self.update()
self.server_stopped.emit()
@@ -375,7 +375,7 @@ class ServerStatus(QtWidgets.QWidget):
"""
self.common.log('ServerStatus', 'cancel_server', 'Canceling the server mid-startup')
self.status = self.STATUS_WORKING
- self.startup_timer_reset()
+ self.autostart_timer_reset()
self.autostop_timer_reset()
self.update()
self.server_canceled.emit()
diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py
index f5d9c85a..2419723d 100644
--- a/onionshare_gui/settings_dialog.py
+++ b/onionshare_gui/settings_dialog.py
@@ -71,22 +71,22 @@ class SettingsDialog(QtWidgets.QDialog):
self.public_mode_widget = QtWidgets.QWidget()
self.public_mode_widget.setLayout(public_mode_layout)
- # Whether or not to use a startup ('auto-start') timer
- self.startup_timer_checkbox = QtWidgets.QCheckBox()
- self.startup_timer_checkbox.setCheckState(QtCore.Qt.Checked)
- self.startup_timer_checkbox.setText(strings._("gui_settings_startup_timer_checkbox"))
- startup_timer_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Using-the-Startup-Timer"))
- startup_timer_label.setStyleSheet(self.common.css['settings_whats_this'])
- startup_timer_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
- startup_timer_label.setOpenExternalLinks(True)
- startup_timer_label.setMinimumSize(public_mode_label.sizeHint())
- startup_timer_layout = QtWidgets.QHBoxLayout()
- startup_timer_layout.addWidget(self.startup_timer_checkbox)
- startup_timer_layout.addWidget(startup_timer_label)
- startup_timer_layout.addStretch()
- startup_timer_layout.setContentsMargins(0,0,0,0)
- self.startup_timer_widget = QtWidgets.QWidget()
- self.startup_timer_widget.setLayout(startup_timer_layout)
+ # Whether or not to use an auto-start timer
+ self.autostart_timer_checkbox = QtWidgets.QCheckBox()
+ self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Checked)
+ self.autostart_timer_checkbox.setText(strings._("gui_settings_autostart_timer_checkbox"))
+ autostart_timer_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Using-the-Startup-Timer"))
+ autostart_timer_label.setStyleSheet(self.common.css['settings_whats_this'])
+ autostart_timer_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
+ autostart_timer_label.setOpenExternalLinks(True)
+ autostart_timer_label.setMinimumSize(public_mode_label.sizeHint())
+ autostart_timer_layout = QtWidgets.QHBoxLayout()
+ autostart_timer_layout.addWidget(self.autostart_timer_checkbox)
+ autostart_timer_layout.addWidget(autostart_timer_label)
+ autostart_timer_layout.addStretch()
+ autostart_timer_layout.setContentsMargins(0,0,0,0)
+ self.autostart_timer_widget = QtWidgets.QWidget()
+ self.autostart_timer_widget.setLayout(autostart_timer_layout)
# Whether or not to use an auto-stop timer
self.autostop_timer_checkbox = QtWidgets.QCheckBox()
@@ -108,7 +108,7 @@ class SettingsDialog(QtWidgets.QDialog):
# General settings layout
general_group_layout = QtWidgets.QVBoxLayout()
general_group_layout.addWidget(self.public_mode_widget)
- general_group_layout.addWidget(self.startup_timer_widget)
+ general_group_layout.addWidget(self.autostart_timer_widget)
general_group_layout.addWidget(self.autostop_timer_widget)
general_group = QtWidgets.QGroupBox(strings._("gui_settings_general_label"))
general_group.setLayout(general_group_layout)
@@ -506,11 +506,11 @@ class SettingsDialog(QtWidgets.QDialog):
else:
self.close_after_first_download_checkbox.setCheckState(QtCore.Qt.Unchecked)
- startup_timer = self.old_settings.get('startup_timer')
- if startup_timer:
- self.startup_timer_checkbox.setCheckState(QtCore.Qt.Checked)
+ autostart_timer = self.old_settings.get('autostart_timer')
+ if autostart_timer:
+ self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Checked)
else:
- self.startup_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
+ self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
autostop_timer = self.old_settings.get('autostop_timer')
if autostop_timer:
@@ -956,7 +956,7 @@ class SettingsDialog(QtWidgets.QDialog):
settings.load() # To get the last update timestamp
settings.set('close_after_first_download', self.close_after_first_download_checkbox.isChecked())
- settings.set('startup_timer', self.startup_timer_checkbox.isChecked())
+ settings.set('autostart_timer', self.autostart_timer_checkbox.isChecked())
settings.set('autostop_timer', self.autostop_timer_checkbox.isChecked())
# Complicated logic here to force v2 onion mode on or off depending on other settings
diff --git a/onionshare_gui/threads.py b/onionshare_gui/threads.py
index cb7447b5..26a9ee6b 100644
--- a/onionshare_gui/threads.py
+++ b/onionshare_gui/threads.py
@@ -90,30 +90,30 @@ class WebThread(QtCore.QThread):
self.success.emit()
-class StartupTimer(QtCore.QThread):
+class AutoStartTimer(QtCore.QThread):
"""
Waits for a prescribed time before allowing a share to start
"""
success = QtCore.pyqtSignal()
error = QtCore.pyqtSignal(str)
def __init__(self, mode, canceled=False):
- super(StartupTimer, self).__init__()
+ super(AutoStartTimer, self).__init__()
self.mode = mode
self.canceled = canceled
- self.mode.common.log('StartupTimer', '__init__')
+ self.mode.common.log('AutoStartTimer', '__init__')
# allow this thread to be terminated
self.setTerminationEnabled()
def run(self):
now = QtCore.QDateTime.currentDateTime()
- scheduled_start = now.secsTo(self.mode.server_status.scheduled_start)
+ autostart_timer_datetime_delta = now.secsTo(self.mode.server_status.autostart_timer_datetime)
try:
# Sleep until scheduled time
- while scheduled_start > 0 and self.canceled == False:
+ while autostart_timer_datetime_delta > 0 and self.canceled == False:
time.sleep(0.1)
now = QtCore.QDateTime.currentDateTime()
- scheduled_start = now.secsTo(self.mode.server_status.scheduled_start)
+ autostart_timer_datetime_delta = now.secsTo(self.mode.server_status.autostart_timer_datetime)
# Timer has now finished
if self.canceled == False:
self.mode.server_status.server_button.setText(strings._('gui_please_wait'))