mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-28 08:49:30 -05:00
Human-friendly autostart/autostop countdown timers on server button, tooltips
This commit is contained in:
parent
281af5fc1a
commit
539be2ded3
@ -92,10 +92,35 @@ class Mode(QtWidgets.QWidget):
|
||||
"""
|
||||
pass
|
||||
|
||||
def human_friendly_time(self, secs):
|
||||
"""
|
||||
Returns a human-friendly time delta from given seconds.
|
||||
"""
|
||||
days = secs//86400
|
||||
hours = (secs - days*86400)//3600
|
||||
minutes = (secs - days*86400 - hours*3600)//60
|
||||
seconds = secs - days*86400 - hours*3600 - minutes*60
|
||||
if not seconds:
|
||||
seconds = '0'
|
||||
result = ("{0}{1}, ".format(days, strings._('days_first_letter')) if days else "") + \
|
||||
("{0}{1}, ".format(hours, strings._('hours_first_letter')) if hours else "") + \
|
||||
("{0}{1}, ".format(minutes, strings._('minutes_first_letter')) if minutes else "") + \
|
||||
"{0}{1}".format(seconds, strings._('seconds_first_letter'))
|
||||
|
||||
return result
|
||||
|
||||
def timer_callback(self):
|
||||
"""
|
||||
This method is called regularly on a timer.
|
||||
"""
|
||||
# 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:
|
||||
now = QtCore.QDateTime.currentDateTime()
|
||||
seconds_remaining = now.secsTo(self.server_status.startup_timer.dateTime())
|
||||
# Update the server button
|
||||
self.server_status.server_button.setText(strings._('gui_waiting_to_start').format(self.human_friendly_time(seconds_remaining)))
|
||||
|
||||
# If the auto-shutdown timer has stopped, stop the server
|
||||
if self.server_status.status == ServerStatus.STATUS_STARTED:
|
||||
if self.app.shutdown_timer and self.common.settings.get('shutdown_timeout'):
|
||||
@ -105,7 +130,7 @@ class Mode(QtWidgets.QWidget):
|
||||
|
||||
# Update the server button
|
||||
server_button_text = self.get_stop_server_shutdown_timeout_text()
|
||||
self.server_status.server_button.setText(server_button_text.format(seconds_remaining))
|
||||
self.server_status.server_button.setText(server_button_text.format(self.human_friendly_time(seconds_remaining)))
|
||||
|
||||
self.status_bar.clearMessage()
|
||||
if not self.app.shutdown_timer.is_alive():
|
||||
|
@ -284,17 +284,13 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.startup_timer_container.hide()
|
||||
if self.common.settings.get('shutdown_timeout'):
|
||||
self.shutdown_timeout_container.hide()
|
||||
if self.mode == ServerStatus.MODE_SHARE:
|
||||
self.server_button.setToolTip(strings._('gui_share_stop_server_shutdown_timeout_tooltip').format(self.timeout))
|
||||
else:
|
||||
self.server_button.setToolTip(strings._('gui_receive_stop_server_shutdown_timeout_tooltip').format(self.timeout))
|
||||
self.server_button.setToolTip(strings._('gui_stop_server_shutdown_timeout_tooltip').format(self.shutdown_timeout.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:
|
||||
scheduled_friendly_time = self.startup_timer.dateTime().toString("MMM dd, H:mmAP")
|
||||
self.server_button.setText(strings._('gui_waiting_to_start').format(scheduled_friendly_time))
|
||||
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")))
|
||||
else:
|
||||
self.server_button.setText(strings._('gui_please_wait'))
|
||||
if self.common.settings.get('shutdown_timeout'):
|
||||
@ -305,6 +301,7 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
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('shutdown_timeout'):
|
||||
self.shutdown_timeout_container.hide()
|
||||
|
||||
|
@ -35,12 +35,12 @@
|
||||
"gui_choose_items": "Choose",
|
||||
"gui_share_start_server": "Start sharing",
|
||||
"gui_share_stop_server": "Stop sharing",
|
||||
"gui_share_stop_server_shutdown_timeout": "Stop Sharing ({}s remaining)",
|
||||
"gui_share_stop_server_shutdown_timeout_tooltip": "Auto-stop timer ends at {}",
|
||||
"gui_share_stop_server_shutdown_timeout": "Stop Sharing ({})",
|
||||
"gui_stop_server_shutdown_timeout_tooltip": "Auto-stop timer ends at {}",
|
||||
"gui_start_server_startup_timer_tooltip": "Auto-start timer ends at {}",
|
||||
"gui_receive_start_server": "Start Receive Mode",
|
||||
"gui_receive_stop_server": "Stop Receive Mode",
|
||||
"gui_receive_stop_server_shutdown_timeout": "Stop Receive Mode ({}s remaining)",
|
||||
"gui_receive_stop_server_shutdown_timeout_tooltip": "Auto-stop timer ends at {}",
|
||||
"gui_copy_url": "Copy Address",
|
||||
"gui_copy_hidservauth": "Copy HidServAuth",
|
||||
"gui_canceled": "Canceled",
|
||||
@ -48,7 +48,7 @@
|
||||
"gui_copied_url": "OnionShare address copied to clipboard",
|
||||
"gui_copied_hidservauth_title": "Copied HidServAuth",
|
||||
"gui_copied_hidservauth": "HidServAuth line copied to clipboard",
|
||||
"gui_waiting_to_start": "Scheduled for {}. Click to cancel.",
|
||||
"gui_waiting_to_start": "Scheduled to start in {}. Click to cancel.",
|
||||
"gui_please_wait": "Starting… Click to cancel.",
|
||||
"version_string": "OnionShare {0:s} | https://onionshare.org/",
|
||||
"gui_quit_title": "Not so fast",
|
||||
@ -194,5 +194,9 @@
|
||||
"gui_share_mode_timeout_waiting": "Waiting to finish sending",
|
||||
"gui_receive_mode_no_files": "No Files Received Yet",
|
||||
"gui_receive_mode_timeout_waiting": "Waiting to finish receiving",
|
||||
"waiting_for_scheduled_time": "Waiting for the scheduled time before starting..."
|
||||
"waiting_for_scheduled_time": "Waiting for the scheduled time before starting...",
|
||||
"days_first_letter": "d",
|
||||
"hours_first_letter": "h",
|
||||
"minutes_first_letter": "m",
|
||||
"seconds_first_letter": "s"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user