Standardise all startup_timer, scheduled_start attributes as 'autostart_timer'

This commit is contained in:
Miguel Jacq 2019-03-25 15:28:31 +11:00
parent c411e8d61a
commit ee3a14a025
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
16 changed files with 121 additions and 121 deletions

View File

@ -138,7 +138,7 @@ def main(cwd=None):
if autostart_timer > 0: if autostart_timer > 0:
# Can't set a schedule that is later than the auto-stop timer # Can't set a schedule that is later than the auto-stop timer
if app.autostop_timer > 0 and app.autostop_timer < autostart_timer: if app.autostop_timer > 0 and app.autostop_timer < autostart_timer:
print(strings._('gui_autostop_timer_cant_be_earlier_than_startup')) print(strings._('gui_autostop_timer_cant_be_earlier_than_autostart_timer'))
sys.exit() sys.exit()
app.start_onion_service(False, True) app.start_onion_service(False, True)

View File

@ -85,7 +85,7 @@ class Settings(object):
'auth_password': '', 'auth_password': '',
'close_after_first_download': True, 'close_after_first_download': True,
'autostop_timer': False, 'autostop_timer': False,
'startup_timer': False, 'autostart_timer': False,
'use_stealth': False, 'use_stealth': False,
'use_autoupdate': True, 'use_autoupdate': True,
'autoupdate_timestamp': None, 'autoupdate_timestamp': None,

View File

@ -24,7 +24,7 @@ from onionshare.common import AutoStopTimer
from ..server_status import ServerStatus from ..server_status import ServerStatus
from ..threads import OnionThread from ..threads import OnionThread
from ..threads import StartupTimer from ..threads import AutoStartTimer
from ..widgets import Alert from ..widgets import Alert
class Mode(QtWidgets.QWidget): 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 this is a scheduled share, display the countdown til the share starts
if self.server_status.status == ServerStatus.STATUS_WORKING: 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() now = QtCore.QDateTime.currentDateTime()
if self.server_status.local_only: 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: 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 # Update the server button
if seconds_remaining > 0: if seconds_remaining > 0:
self.server_status.server_button.setText(strings._('gui_waiting_to_start').format(self.human_friendly_time(seconds_remaining))) 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, # 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 # the OnionThread will start and exit 'early' to obtain the port, slug
# and onion address, but it will not start the WebThread yet. # 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) self.start_onion_thread(obtain_onion_early=True)
else: else:
self.start_onion_thread() self.start_onion_thread()
# If scheduling a share, delay starting the real share # If scheduling a share, delay starting the real share
if self.server_status.scheduled_start: if self.server_status.autostart_timer_datetime:
self.common.log('Mode', 'start_server', 'Starting startup timer') self.common.log('Mode', 'start_server', 'Starting auto-start timer')
self.startup_thread = StartupTimer(self) self.startup_thread = AutoStartTimer(self)
# Once the timer has finished, start the real share, with a WebThread # Once the timer has finished, start the real share, with a WebThread
self.startup_thread.success.connect(self.start_scheduled_service) self.startup_thread.success.connect(self.start_scheduled_service)
self.startup_thread.error.connect(self.start_server_error) self.startup_thread.error.connect(self.start_server_error)

View File

@ -228,7 +228,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.server_status_label.setText(strings._('gui_status_indicator_share_stopped')) self.server_status_label.setText(strings._('gui_status_indicator_share_stopped'))
elif self.share_mode.server_status.status == ServerStatus.STATUS_WORKING: elif self.share_mode.server_status.status == ServerStatus.STATUS_WORKING:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_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')) self.server_status_label.setText(strings._('gui_status_indicator_share_scheduled'))
else: else:
self.server_status_label.setText(strings._('gui_status_indicator_share_working')) 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')) self.server_status_label.setText(strings._('gui_status_indicator_receive_stopped'))
elif self.receive_mode.server_status.status == ServerStatus.STATUS_WORKING: elif self.receive_mode.server_status.status == ServerStatus.STATUS_WORKING:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_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')) self.server_status_label.setText(strings._('gui_status_indicator_receive_scheduled'))
else: else:
self.server_status_label.setText(strings._('gui_status_indicator_receive_working')) 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'): if not self.common.settings.get('autostop_timer'):
self.share_mode.server_status.autostop_timer_container.hide() self.share_mode.server_status.autostop_timer_container.hide()
self.receive_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 we switched off the auto-start timer setting, ensure the widget is hidden.
if not self.common.settings.get('startup_timer'): if not self.common.settings.get('autostart_timer'):
self.share_mode.server_status.scheduled_start = None self.share_mode.server_status.autostart_timer_datetime = None
self.receive_mode.server_status.scheduled_start = None self.receive_mode.server_status.autostart_timer_datetime = None
self.share_mode.server_status.startup_timer_container.hide() self.share_mode.server_status.autostart_timer_container.hide()
self.receive_mode.server_status.startup_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 = SettingsDialog(self.common, self.onion, self.qtapp, self.config, self.local_only)
d.settings_saved.connect(reload_settings) d.settings_saved.connect(reload_settings)

View File

@ -56,35 +56,35 @@ class ServerStatus(QtWidgets.QWidget):
self.app = app self.app = app
self.web = None self.web = None
self.scheduled_start = None self.autostart_timer_datetime = None
self.local_only = local_only self.local_only = local_only
self.resizeEvent(None) self.resizeEvent(None)
# Startup timer layout # Auto-start timer layout
self.startup_timer_label = QtWidgets.QLabel(strings._('gui_settings_startup_timer')) self.autostart_timer_label = QtWidgets.QLabel(strings._('gui_settings_autostart_timer'))
self.startup_timer = QtWidgets.QDateTimeEdit() self.autostart_timer_widget = QtWidgets.QDateTimeEdit()
self.startup_timer.setDisplayFormat("hh:mm A MMM d, yy") self.autostart_timer_widget.setDisplayFormat("hh:mm A MMM d, yy")
if self.local_only: if self.local_only:
# For testing # For testing
self.startup_timer.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(15)) self.autostart_timer_widget.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(15))
self.startup_timer.setMinimumDateTime(QtCore.QDateTime.currentDateTime()) self.autostart_timer_widget.setMinimumDateTime(QtCore.QDateTime.currentDateTime())
else: else:
# Set proposed timer to be 5 minutes into the future # 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 # 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.autostart_timer_widget.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
self.startup_timer.setCurrentSection(QtWidgets.QDateTimeEdit.MinuteSection) self.autostart_timer_widget.setCurrentSection(QtWidgets.QDateTimeEdit.MinuteSection)
startup_timer_layout = QtWidgets.QHBoxLayout() autostart_timer_layout = QtWidgets.QHBoxLayout()
startup_timer_layout.addWidget(self.startup_timer_label) autostart_timer_layout.addWidget(self.autostart_timer_label)
startup_timer_layout.addWidget(self.startup_timer) autostart_timer_layout.addWidget(self.autostart_timer_widget)
# Startup timer container, so it can all be hidden and shown as a group # Auto-start timer container, so it can all be hidden and shown as a group
startup_timer_container_layout = QtWidgets.QVBoxLayout() autostart_timer_container_layout = QtWidgets.QVBoxLayout()
startup_timer_container_layout.addLayout(startup_timer_layout) autostart_timer_container_layout.addLayout(autostart_timer_layout)
self.startup_timer_container = QtWidgets.QWidget() self.autostart_timer_container = QtWidgets.QWidget()
self.startup_timer_container.setLayout(startup_timer_container_layout) self.autostart_timer_container.setLayout(autostart_timer_container_layout)
self.startup_timer_container.hide() self.autostart_timer_container.hide()
# Auto-stop timer layout # Auto-stop timer layout
self.autostop_timer_label = QtWidgets.QLabel(strings._('gui_settings_autostop_timer')) self.autostop_timer_label = QtWidgets.QLabel(strings._('gui_settings_autostop_timer'))
@ -149,7 +149,7 @@ class ServerStatus(QtWidgets.QWidget):
layout = QtWidgets.QVBoxLayout() layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.server_button) layout.addWidget(self.server_button)
layout.addLayout(url_layout) layout.addLayout(url_layout)
layout.addWidget(self.startup_timer_container) layout.addWidget(self.autostart_timer_container)
layout.addWidget(self.autostop_timer_container) layout.addWidget(self.autostop_timer_container)
self.setLayout(layout) self.setLayout(layout)
@ -181,13 +181,13 @@ class ServerStatus(QtWidgets.QWidget):
except: except:
pass 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: 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): def autostop_timer_reset(self):
""" """
@ -244,8 +244,8 @@ class ServerStatus(QtWidgets.QWidget):
self.common.settings.set('slug', self.web.slug) self.common.settings.set('slug', self.web.slug)
self.common.settings.save() self.common.settings.save()
if self.common.settings.get('startup_timer'): if self.common.settings.get('autostart_timer'):
self.startup_timer_container.hide() self.autostart_timer_container.hide()
if self.common.settings.get('autostop_timer'): if self.common.settings.get('autostop_timer'):
self.autostop_timer_container.hide() self.autostop_timer_container.hide()
@ -269,8 +269,8 @@ 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('startup_timer'): if self.common.settings.get('autostart_timer'):
self.startup_timer_container.show() self.autostart_timer_container.show()
if self.common.settings.get('autostop_timer'): if self.common.settings.get('autostop_timer'):
self.autostop_timer_container.show() self.autostop_timer_container.show()
elif self.status == self.STATUS_STARTED: elif self.status == self.STATUS_STARTED:
@ -280,17 +280,17 @@ 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('startup_timer'): if self.common.settings.get('autostart_timer'):
self.startup_timer_container.hide() self.autostart_timer_container.hide()
if self.common.settings.get('autostop_timer'): if self.common.settings.get('autostop_timer'):
self.autostop_timer_container.hide() 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"))) 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: elif self.status == self.STATUS_WORKING:
self.server_button.setStyleSheet(self.common.css['server_status_button_working']) self.server_button.setStyleSheet(self.common.css['server_status_button_working'])
self.server_button.setEnabled(True) self.server_button.setEnabled(True)
if self.scheduled_start: if self.autostart_timer_datetime:
self.startup_timer_container.hide() self.autostart_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"))) self.server_button.setToolTip(strings._('gui_start_server_autostart_timer_tooltip').format(self.autostart_timer_widget.dateTime().toString("H:mmAP, MMM dd, yy")))
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.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.setStyleSheet(self.common.css['server_status_button_working'])
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('startup_timer'): if self.common.settings.get('autostart_timer'):
self.startup_timer_container.hide() self.autostart_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"))) 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'): if self.common.settings.get('autostop_timer'):
self.autostop_timer_container.hide() self.autostop_timer_container.hide()
@ -311,15 +311,15 @@ 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('startup_timer'): if self.common.settings.get('autostart_timer'):
if self.local_only: if self.local_only:
self.scheduled_start = self.startup_timer.dateTime().toPyDateTime() self.autostart_timer_datetime = self.autostart_timer_widget.dateTime().toPyDateTime()
else: 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 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 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.common.settings.get('autostop_timer'):
if self.local_only: if self.local_only:
self.autostop_timer_datetime = self.autostop_timer_widget.dateTime().toPyDateTime() 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: if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.autostop_timer_datetime:
can_start = False can_start = False
Alert(self.common, strings._('gui_server_autostop_timer_expired'), QtWidgets.QMessageBox.Warning) Alert(self.common, strings._('gui_server_autostop_timer_expired'), QtWidgets.QMessageBox.Warning)
if self.common.settings.get('startup_timer'): if self.common.settings.get('autostart_timer'):
if self.autostop_timer_datetime <= self.scheduled_start: if self.autostop_timer_datetime <= self.autostart_timer_datetime:
Alert(self.common, strings._('gui_autostop_timer_cant_be_earlier_than_startup'), QtWidgets.QMessageBox.Warning) Alert(self.common, strings._('gui_autostop_timer_cant_be_earlier_than_autostart_timer'), QtWidgets.QMessageBox.Warning)
can_start = False can_start = False
if can_start: if can_start:
self.start_server() self.start_server()
@ -364,7 +364,7 @@ class ServerStatus(QtWidgets.QWidget):
Stop the server. Stop the server.
""" """
self.status = self.STATUS_WORKING self.status = self.STATUS_WORKING
self.startup_timer_reset() self.autostart_timer_reset()
self.autostop_timer_reset() self.autostop_timer_reset()
self.update() self.update()
self.server_stopped.emit() self.server_stopped.emit()
@ -375,7 +375,7 @@ class ServerStatus(QtWidgets.QWidget):
""" """
self.common.log('ServerStatus', 'cancel_server', 'Canceling the server mid-startup') self.common.log('ServerStatus', 'cancel_server', 'Canceling the server mid-startup')
self.status = self.STATUS_WORKING self.status = self.STATUS_WORKING
self.startup_timer_reset() self.autostart_timer_reset()
self.autostop_timer_reset() self.autostop_timer_reset()
self.update() self.update()
self.server_canceled.emit() self.server_canceled.emit()

View File

@ -71,22 +71,22 @@ class SettingsDialog(QtWidgets.QDialog):
self.public_mode_widget = QtWidgets.QWidget() self.public_mode_widget = QtWidgets.QWidget()
self.public_mode_widget.setLayout(public_mode_layout) self.public_mode_widget.setLayout(public_mode_layout)
# Whether or not to use a startup ('auto-start') timer # Whether or not to use an auto-start timer
self.startup_timer_checkbox = QtWidgets.QCheckBox() self.autostart_timer_checkbox = QtWidgets.QCheckBox()
self.startup_timer_checkbox.setCheckState(QtCore.Qt.Checked) self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Checked)
self.startup_timer_checkbox.setText(strings._("gui_settings_startup_timer_checkbox")) self.autostart_timer_checkbox.setText(strings._("gui_settings_autostart_timer_checkbox"))
startup_timer_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Using-the-Startup-Timer")) autostart_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']) autostart_timer_label.setStyleSheet(self.common.css['settings_whats_this'])
startup_timer_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) autostart_timer_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
startup_timer_label.setOpenExternalLinks(True) autostart_timer_label.setOpenExternalLinks(True)
startup_timer_label.setMinimumSize(public_mode_label.sizeHint()) autostart_timer_label.setMinimumSize(public_mode_label.sizeHint())
startup_timer_layout = QtWidgets.QHBoxLayout() autostart_timer_layout = QtWidgets.QHBoxLayout()
startup_timer_layout.addWidget(self.startup_timer_checkbox) autostart_timer_layout.addWidget(self.autostart_timer_checkbox)
startup_timer_layout.addWidget(startup_timer_label) autostart_timer_layout.addWidget(autostart_timer_label)
startup_timer_layout.addStretch() autostart_timer_layout.addStretch()
startup_timer_layout.setContentsMargins(0,0,0,0) autostart_timer_layout.setContentsMargins(0,0,0,0)
self.startup_timer_widget = QtWidgets.QWidget() self.autostart_timer_widget = QtWidgets.QWidget()
self.startup_timer_widget.setLayout(startup_timer_layout) self.autostart_timer_widget.setLayout(autostart_timer_layout)
# Whether or not to use an auto-stop timer # Whether or not to use an auto-stop timer
self.autostop_timer_checkbox = QtWidgets.QCheckBox() self.autostop_timer_checkbox = QtWidgets.QCheckBox()
@ -108,7 +108,7 @@ class SettingsDialog(QtWidgets.QDialog):
# General settings layout # General settings layout
general_group_layout = QtWidgets.QVBoxLayout() general_group_layout = QtWidgets.QVBoxLayout()
general_group_layout.addWidget(self.public_mode_widget) 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_layout.addWidget(self.autostop_timer_widget)
general_group = QtWidgets.QGroupBox(strings._("gui_settings_general_label")) general_group = QtWidgets.QGroupBox(strings._("gui_settings_general_label"))
general_group.setLayout(general_group_layout) general_group.setLayout(general_group_layout)
@ -506,11 +506,11 @@ class SettingsDialog(QtWidgets.QDialog):
else: else:
self.close_after_first_download_checkbox.setCheckState(QtCore.Qt.Unchecked) self.close_after_first_download_checkbox.setCheckState(QtCore.Qt.Unchecked)
startup_timer = self.old_settings.get('startup_timer') autostart_timer = self.old_settings.get('autostart_timer')
if startup_timer: if autostart_timer:
self.startup_timer_checkbox.setCheckState(QtCore.Qt.Checked) self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Checked)
else: 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') autostop_timer = self.old_settings.get('autostop_timer')
if autostop_timer: if autostop_timer:
@ -956,7 +956,7 @@ class SettingsDialog(QtWidgets.QDialog):
settings.load() # To get the last update timestamp settings.load() # To get the last update timestamp
settings.set('close_after_first_download', self.close_after_first_download_checkbox.isChecked()) 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()) settings.set('autostop_timer', self.autostop_timer_checkbox.isChecked())
# Complicated logic here to force v2 onion mode on or off depending on other settings # Complicated logic here to force v2 onion mode on or off depending on other settings

View File

@ -90,30 +90,30 @@ class WebThread(QtCore.QThread):
self.success.emit() self.success.emit()
class StartupTimer(QtCore.QThread): class AutoStartTimer(QtCore.QThread):
""" """
Waits for a prescribed time before allowing a share to start Waits for a prescribed time before allowing a share to start
""" """
success = QtCore.pyqtSignal() success = QtCore.pyqtSignal()
error = QtCore.pyqtSignal(str) error = QtCore.pyqtSignal(str)
def __init__(self, mode, canceled=False): def __init__(self, mode, canceled=False):
super(StartupTimer, self).__init__() super(AutoStartTimer, self).__init__()
self.mode = mode self.mode = mode
self.canceled = canceled self.canceled = canceled
self.mode.common.log('StartupTimer', '__init__') self.mode.common.log('AutoStartTimer', '__init__')
# allow this thread to be terminated # allow this thread to be terminated
self.setTerminationEnabled() self.setTerminationEnabled()
def run(self): def run(self):
now = QtCore.QDateTime.currentDateTime() 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: try:
# Sleep until scheduled time # 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) time.sleep(0.1)
now = QtCore.QDateTime.currentDateTime() 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 # Timer has now finished
if self.canceled == False: if self.canceled == False:
self.mode.server_status.server_button.setText(strings._('gui_please_wait')) self.mode.server_status.server_button.setText(strings._('gui_please_wait'))

View File

@ -38,7 +38,7 @@
"gui_share_stop_server": "Stop sharing", "gui_share_stop_server": "Stop sharing",
"gui_share_stop_server_autostop_timer": "Stop Sharing ({})", "gui_share_stop_server_autostop_timer": "Stop Sharing ({})",
"gui_stop_server_autostop_timer_tooltip": "Auto-stop timer ends at {}", "gui_stop_server_autostop_timer_tooltip": "Auto-stop timer ends at {}",
"gui_start_server_startup_timer_tooltip": "Auto-start timer ends at {}", "gui_start_server_autostart_timer_tooltip": "Auto-start timer ends at {}",
"gui_receive_start_server": "Start Receive Mode", "gui_receive_start_server": "Start Receive Mode",
"gui_receive_stop_server": "Stop Receive Mode", "gui_receive_stop_server": "Stop Receive Mode",
"gui_receive_stop_server_autostop_timer": "Stop Receive Mode ({}s remaining)", "gui_receive_stop_server_autostop_timer": "Stop Receive Mode ({}s remaining)",
@ -102,8 +102,8 @@
"gui_settings_button_help": "Help", "gui_settings_button_help": "Help",
"gui_settings_autostop_timer_checkbox": "Use auto-stop timer", "gui_settings_autostop_timer_checkbox": "Use auto-stop timer",
"gui_settings_autostop_timer": "Stop the share at:", "gui_settings_autostop_timer": "Stop the share at:",
"gui_settings_startup_timer_checkbox": "Use auto-start timer", "gui_settings_autostart_timer_checkbox": "Use auto-start timer",
"gui_settings_startup_timer": "Start the share at:", "gui_settings_autostart_timer": "Start the share at:",
"settings_error_unknown": "Can't connect to Tor controller because your settings don't make sense.", "settings_error_unknown": "Can't connect to Tor controller because your settings don't make sense.",
"settings_error_automatic": "Could not connect to the Tor controller. Is Tor Browser (available from torproject.org) running in the background?", "settings_error_automatic": "Could not connect to the Tor controller. Is Tor Browser (available from torproject.org) running in the background?",
"settings_error_socket_port": "Can't connect to the Tor controller at {}:{}.", "settings_error_socket_port": "Can't connect to the Tor controller at {}:{}.",
@ -131,8 +131,8 @@
"gui_tor_connection_lost": "Disconnected from Tor.", "gui_tor_connection_lost": "Disconnected from Tor.",
"gui_server_started_after_autostop_timer": "The auto-stop timer ran out before the server started. Please make a new share.", "gui_server_started_after_autostop_timer": "The auto-stop timer ran out before the server started. Please make a new share.",
"gui_server_autostop_timer_expired": "The auto-stop timer already ran out. Please update it to start sharing.", "gui_server_autostop_timer_expired": "The auto-stop timer already ran out. Please update it to start sharing.",
"gui_server_startup_timer_expired": "The scheduled time has already passed. Please update it to start sharing.", "gui_server_autostart_timer_expired": "The scheduled time has already passed. Please update it to start sharing.",
"gui_autostop_timer_cant_be_earlier_than_startup": "The auto-stop time can't be the same or earlier than the start-up time. Please update it to start sharing.", "gui_autostop_timer_cant_be_earlier_than_autostart_timer": "The auto-stop time can't be the same or earlier than the auto-start time. Please update it to start sharing.",
"share_via_onionshare": "OnionShare it", "share_via_onionshare": "OnionShare it",
"gui_connect_to_tor_for_onion_settings": "Connect to Tor to see onion service settings", "gui_connect_to_tor_for_onion_settings": "Connect to Tor to see onion service settings",
"gui_use_legacy_v2_onions_checkbox": "Use legacy addresses", "gui_use_legacy_v2_onions_checkbox": "Use legacy addresses",

View File

@ -308,16 +308,16 @@ class GuiBaseTest(object):
# We should have timed out now # We should have timed out now
self.assertEqual(mode.server_status.status, 0) self.assertEqual(mode.server_status.status, 0)
# Startup timer tests # Auto-start timer tests
def set_startup_timer(self, mode, timer): def set_autostart_timer(self, mode, timer):
'''Test that the timer can be set''' '''Test that the timer can be set'''
schedule = QtCore.QDateTime.currentDateTime().addSecs(timer) schedule = QtCore.QDateTime.currentDateTime().addSecs(timer)
mode.server_status.startup_timer.setDateTime(schedule) mode.server_status.autostart_timer_widget.setDateTime(schedule)
self.assertTrue(mode.server_status.startup_timer.dateTime(), schedule) self.assertTrue(mode.server_status.autostart_timer_widget.dateTime(), schedule)
def startup_timer_widget_hidden(self, mode): def autostart_timer_widget_hidden(self, mode):
'''Test that the startup timer widget is hidden when share has started''' '''Test that the auto-start timer widget is hidden when share has started'''
self.assertFalse(mode.server_status.startup_timer_container.isVisible()) self.assertFalse(mode.server_status.autostart_timer_container.isVisible())
def scheduled_service_started(self, mode, wait): def scheduled_service_started(self, mode, wait):
'''Test that the server has timed out after the timer ran out''' '''Test that the server has timed out after the timer ran out'''
@ -331,7 +331,7 @@ class GuiBaseTest(object):
self.server_status_indicator_says_scheduled(mode) self.server_status_indicator_says_scheduled(mode)
self.add_delete_buttons_hidden() self.add_delete_buttons_hidden()
self.settings_button_is_hidden() self.settings_button_is_hidden()
self.set_startup_timer(mode, 10) self.set_autostart_timer(mode, 10)
QtTest.QTest.mousePress(mode.server_status.server_button, QtCore.Qt.LeftButton) QtTest.QTest.mousePress(mode.server_status.server_button, QtCore.Qt.LeftButton)
QtTest.QTest.qWait(2000) QtTest.QTest.qWait(2000)
QtTest.QTest.mouseRelease(mode.server_status.server_button, QtCore.Qt.LeftButton) QtTest.QTest.mouseRelease(mode.server_status.server_button, QtCore.Qt.LeftButton)

View File

@ -195,12 +195,12 @@ class GuiShareTest(GuiBaseTest):
self.server_timed_out(self.gui.share_mode, 10000) self.server_timed_out(self.gui.share_mode, 10000)
self.web_server_is_stopped() self.web_server_is_stopped()
def run_all_share_mode_startup_timer_tests(self, public_mode): def run_all_share_mode_autostart_timer_tests(self, public_mode):
"""Auto-stop timer tests in share mode""" """Auto-start timer tests in share mode"""
self.run_all_share_mode_setup_tests() self.run_all_share_mode_setup_tests()
self.set_startup_timer(self.gui.share_mode, 5) self.set_autostart_timer(self.gui.share_mode, 5)
self.server_working_on_start_button_pressed(self.gui.share_mode) self.server_working_on_start_button_pressed(self.gui.share_mode)
self.startup_timer_widget_hidden(self.gui.share_mode) self.autostart_timer_widget_hidden(self.gui.share_mode)
self.server_status_indicator_says_scheduled(self.gui.share_mode) self.server_status_indicator_says_scheduled(self.gui.share_mode)
self.web_server_is_stopped() self.web_server_is_stopped()
self.scheduled_service_started(self.gui.share_mode, 7000) self.scheduled_service_started(self.gui.share_mode, 7000)
@ -209,7 +209,7 @@ class GuiShareTest(GuiBaseTest):
def run_all_share_mode_autostop_autostart_mismatch_tests(self, public_mode): def run_all_share_mode_autostop_autostart_mismatch_tests(self, public_mode):
"""Auto-stop timer tests in share mode""" """Auto-stop timer tests in share mode"""
self.run_all_share_mode_setup_tests() self.run_all_share_mode_setup_tests()
self.set_startup_timer(self.gui.share_mode, 15) self.set_autostart_timer(self.gui.share_mode, 15)
self.set_timeout(self.gui.share_mode, 5) self.set_timeout(self.gui.share_mode, 5)
QtCore.QTimer.singleShot(4000, self.accept_dialog) QtCore.QTimer.singleShot(4000, self.accept_dialog)
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton) QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)

View File

@ -4,12 +4,12 @@ import unittest
from .GuiShareTest import GuiShareTest from .GuiShareTest import GuiShareTest
class LocalShareModeStartupTimerTest(unittest.TestCase, GuiShareTest): class LocalShareModeAutoStartTimerTest(unittest.TestCase, GuiShareTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
test_settings = { test_settings = {
"public_mode": False, "public_mode": False,
"startup_timer": True, "autostart_timer": True,
"autostop_timer": True, "autostop_timer": True,
} }
cls.gui = GuiShareTest.set_up(test_settings) cls.gui = GuiShareTest.set_up(test_settings)

View File

@ -4,12 +4,12 @@ import unittest
from .GuiShareTest import GuiShareTest from .GuiShareTest import GuiShareTest
class LocalShareModeStartupTimerTest(unittest.TestCase, GuiShareTest): class LocalShareModeAutoStartTimerTest(unittest.TestCase, GuiShareTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
test_settings = { test_settings = {
"public_mode": False, "public_mode": False,
"startup_timer": True, "autostart_timer": True,
} }
cls.gui = GuiShareTest.set_up(test_settings) cls.gui = GuiShareTest.set_up(test_settings)
@ -20,7 +20,7 @@ class LocalShareModeStartupTimerTest(unittest.TestCase, GuiShareTest):
@pytest.mark.gui @pytest.mark.gui
def test_gui(self): def test_gui(self):
self.run_all_common_setup_tests() self.run_all_common_setup_tests()
self.run_all_share_mode_startup_timer_tests(False) self.run_all_share_mode_autostart_timer_tests(False)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

View File

@ -5,12 +5,12 @@ from PyQt5 import QtCore, QtTest
from .GuiShareTest import GuiShareTest from .GuiShareTest import GuiShareTest
class LocalShareModeStartupTimerTooShortTest(unittest.TestCase, GuiShareTest): class LocalShareModeAutoStartTimerTooShortTest(unittest.TestCase, GuiShareTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
test_settings = { test_settings = {
"public_mode": False, "public_mode": False,
"startup_timer": True, "autostart_timer": True,
} }
cls.gui = GuiShareTest.set_up(test_settings) cls.gui = GuiShareTest.set_up(test_settings)
@ -23,7 +23,7 @@ class LocalShareModeStartupTimerTooShortTest(unittest.TestCase, GuiShareTest):
self.run_all_common_setup_tests() self.run_all_common_setup_tests()
self.run_all_share_mode_setup_tests() self.run_all_share_mode_setup_tests()
# Set a low timeout # Set a low timeout
self.set_startup_timer(self.gui.share_mode, 2) self.set_autostart_timer(self.gui.share_mode, 2)
QtTest.QTest.qWait(3000) QtTest.QTest.qWait(3000)
QtCore.QTimer.singleShot(4000, self.accept_dialog) QtCore.QTimer.singleShot(4000, self.accept_dialog)
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton) QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)

View File

@ -8,7 +8,7 @@ class LocalShareModeCancelTest(unittest.TestCase, GuiShareTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
test_settings = { test_settings = {
"startup_timer": True, "autostart_timer": True,
} }
cls.gui = GuiShareTest.set_up(test_settings) cls.gui = GuiShareTest.set_up(test_settings)

View File

@ -8,7 +8,7 @@ class ShareModeCancelTest(unittest.TestCase, TorGuiShareTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
test_settings = { test_settings = {
"startup_timer": True, "autostart_timer": True,
} }
cls.gui = TorGuiShareTest.set_up(test_settings) cls.gui = TorGuiShareTest.set_up(test_settings)

View File

@ -52,7 +52,7 @@ class TestSettings:
'auth_password': '', 'auth_password': '',
'close_after_first_download': True, 'close_after_first_download': True,
'autostop_timer': False, 'autostop_timer': False,
'startup_timer': False, 'autostart_timer': False,
'use_stealth': False, 'use_stealth': False,
'use_autoupdate': True, 'use_autoupdate': True,
'autoupdate_timestamp': None, 'autoupdate_timestamp': None,