Added autoupdate settings to Settings, and also to the settings dialog

This commit is contained in:
Micah Lee 2017-04-15 15:24:08 -07:00
parent 62cc310d0a
commit 4b11bd00c5
3 changed files with 66 additions and 11 deletions

View file

@ -42,7 +42,9 @@ class Settings(object):
'auth_type': 'no_auth', 'auth_type': 'no_auth',
'auth_password': '', 'auth_password': '',
'close_after_first_download': True, 'close_after_first_download': True,
'use_stealth': False 'use_stealth': False,
'use_autoupdate': True,
'autoupdate_timestamp': None
} }
self._settings = {} self._settings = {}
self.fill_in_defaults() self.fill_in_defaults()

View file

@ -38,6 +38,8 @@ class SettingsDialog(QtWidgets.QDialog):
self.setWindowTitle(strings._('gui_settings_window_title', True)) self.setWindowTitle(strings._('gui_settings_window_title', True))
self.setWindowIcon(QtGui.QIcon(helpers.get_resource_path('images/logo.png'))) self.setWindowIcon(QtGui.QIcon(helpers.get_resource_path('images/logo.png')))
system = platform.system()
# Sharing options # Sharing options
# Close after first download # Close after first download
@ -67,6 +69,32 @@ class SettingsDialog(QtWidgets.QDialog):
stealth_group = QtWidgets.QGroupBox(strings._("gui_settings_stealth_label", True)) stealth_group = QtWidgets.QGroupBox(strings._("gui_settings_stealth_label", True))
stealth_group.setLayout(stealth_group_layout) stealth_group.setLayout(stealth_group_layout)
# Automatic updates options
# Autoupdate
self.autoupdate_checkbox = QtWidgets.QCheckBox()
self.autoupdate_checkbox.setCheckState(QtCore.Qt.Unchecked)
self.autoupdate_checkbox.setText(strings._("gui_settings_autoupdate_option", True))
# Last update time
self.autoupdate_timestamp = QtWidgets.QLabel()
# Check for updates button
self.check_for_updates_button = QtWidgets.QPushButton(strings._('gui_settings_autoupdate_check_button', True))
self.check_for_updates_button.clicked.connect(self.check_for_updates)
# Autoupdate options layout
autoupdate_group_layout = QtWidgets.QVBoxLayout()
autoupdate_group_layout.addWidget(self.autoupdate_checkbox)
autoupdate_group_layout.addWidget(self.autoupdate_timestamp)
autoupdate_group_layout.addWidget(self.check_for_updates_button)
autoupdate_group = QtWidgets.QGroupBox(strings._("gui_settings_autoupdate_label", True))
autoupdate_group.setLayout(autoupdate_group_layout)
# Autoupdate is only available for Windows and Mac (Linux updates using package manager)
if system != 'Windows' and system != 'Darwin':
autoupdate_group.hide()
# Connection type: either automatic, control port, or socket file # Connection type: either automatic, control port, or socket file
# Bundled Tor # Bundled Tor
@ -74,8 +102,7 @@ class SettingsDialog(QtWidgets.QDialog):
self.connection_type_bundled_radio.toggled.connect(self.connection_type_bundled_toggled) self.connection_type_bundled_radio.toggled.connect(self.connection_type_bundled_toggled)
# Bundled Tor doesn't work on dev mode in Windows or Mac # Bundled Tor doesn't work on dev mode in Windows or Mac
p = platform.system() if (system == 'Windows' or system == 'Darwin') and getattr(sys, 'onionshare_dev_mode', False):
if (p == 'Windows' or p == 'Darwin') and getattr(sys, 'onionshare_dev_mode', False):
self.connection_type_bundled_radio.setEnabled(False) self.connection_type_bundled_radio.setEnabled(False)
# Automatic # Automatic
@ -140,11 +167,6 @@ class SettingsDialog(QtWidgets.QDialog):
self.authenticate_group = QtWidgets.QGroupBox(strings._("gui_settings_authenticate_label", True)) self.authenticate_group = QtWidgets.QGroupBox(strings._("gui_settings_authenticate_label", True))
self.authenticate_group.setLayout(authenticate_group_layout) self.authenticate_group.setLayout(authenticate_group_layout)
# Tor networkconnection status
self.tor_status = QtWidgets.QLabel()
self.tor_status.setStyleSheet('color: #666666; padding-top: 10px')
self.tor_status.hide()
# Test tor settings button # Test tor settings button
self.connection_type_test_button = QtWidgets.QPushButton(strings._('gui_settings_connection_type_test_button', True)) self.connection_type_test_button = QtWidgets.QPushButton(strings._('gui_settings_connection_type_test_button', True))
self.connection_type_test_button.clicked.connect(self.test_tor_clicked) self.connection_type_test_button.clicked.connect(self.test_tor_clicked)
@ -158,7 +180,6 @@ class SettingsDialog(QtWidgets.QDialog):
connection_type_group_layout.addWidget(self.connection_type_control_port_extras) connection_type_group_layout.addWidget(self.connection_type_control_port_extras)
connection_type_group_layout.addWidget(self.connection_type_socket_file_extras) connection_type_group_layout.addWidget(self.connection_type_socket_file_extras)
connection_type_group_layout.addWidget(self.authenticate_group) connection_type_group_layout.addWidget(self.authenticate_group)
connection_type_group_layout.addWidget(self.tor_status)
connection_type_group_layout.addWidget(self.connection_type_test_button) connection_type_group_layout.addWidget(self.connection_type_test_button)
connection_type_group = QtWidgets.QGroupBox(strings._("gui_settings_connection_type_label", True)) connection_type_group = QtWidgets.QGroupBox(strings._("gui_settings_connection_type_label", True))
connection_type_group.setLayout(connection_type_group_layout) connection_type_group.setLayout(connection_type_group_layout)
@ -172,15 +193,22 @@ class SettingsDialog(QtWidgets.QDialog):
buttons_layout.addWidget(self.save_button) buttons_layout.addWidget(self.save_button)
buttons_layout.addWidget(self.cancel_button) buttons_layout.addWidget(self.cancel_button)
# Tor network connection status
self.tor_status = QtWidgets.QLabel()
self.tor_status.setStyleSheet('background-color: #ffffff; color: #000000; padding: 10px')
self.tor_status.hide()
# Layout # Layout
layout = QtWidgets.QVBoxLayout() layout = QtWidgets.QVBoxLayout()
layout.addWidget(sharing_group) layout.addWidget(sharing_group)
layout.addWidget(stealth_group) layout.addWidget(stealth_group)
layout.addWidget(autoupdate_group)
layout.addWidget(connection_type_group) layout.addWidget(connection_type_group)
layout.addStretch() layout.addStretch()
layout.addLayout(buttons_layout) layout.addLayout(buttons_layout)
layout.addWidget(self.tor_status)
self.setLayout(layout) self.setLayout(layout)
self.cancel_button.setFocus()
# Load settings, and fill them in # Load settings, and fill them in
settings = Settings() settings = Settings()
@ -198,6 +226,20 @@ class SettingsDialog(QtWidgets.QDialog):
else: else:
self.stealth_checkbox.setCheckState(QtCore.Qt.Unchecked) self.stealth_checkbox.setCheckState(QtCore.Qt.Unchecked)
use_autoupdate = settings.get('use_autoupdate')
if use_autoupdate:
self.autoupdate_checkbox.setCheckState(QtCore.Qt.Checked)
else:
self.autoupdate_checkbox.setCheckState(QtCore.Qt.Unchecked)
autoupdate_timestamp = settings.get('autoupdate_timestamp')
if autoupdate_timestamp:
dt = datetime.datetime.fromtimestamp(autoupdate_timestamp)
last_checked = dt.strftime('%B %d, %Y %H:%M')
else:
last_checked = strings._('gui_settings_autoupdate_timestamp_never', True)
self.autoupdate_timestamp.setText(strings._('gui_settings_autoupdate_timestamp', True).format(last_checked))
connection_type = settings.get('connection_type') connection_type = settings.get('connection_type')
if connection_type == 'bundled': if connection_type == 'bundled':
if self.connection_type_bundled_radio.isEnabled(): if self.connection_type_bundled_radio.isEnabled():
@ -279,7 +321,7 @@ class SettingsDialog(QtWidgets.QDialog):
def test_tor_clicked(self): def test_tor_clicked(self):
""" """
Test Settings button clicked. With the given settings, see if we can Test Tor Settings button clicked. With the given settings, see if we can
successfully connect and authenticate to Tor. successfully connect and authenticate to Tor.
""" """
settings = self.settings_from_fields() settings = self.settings_from_fields()
@ -321,6 +363,12 @@ class SettingsDialog(QtWidgets.QDialog):
if settings.get('connection_type') == 'bundled': if settings.get('connection_type') == 'bundled':
bundled_cleanup() bundled_cleanup()
def check_for_updates(self):
"""
Check for Updates button clicked. Manually force an update check.
"""
pass
def save_clicked(self): def save_clicked(self):
""" """
Save button clicked. Save current settings to disk. Save button clicked. Save current settings to disk.

View file

@ -59,6 +59,11 @@
"gui_settings_stealth_label": "Stealth (advanced)", "gui_settings_stealth_label": "Stealth (advanced)",
"gui_settings_stealth_option": "Create stealth onion services", "gui_settings_stealth_option": "Create stealth onion services",
"gui_settings_stealth_option_details": "This makes OnionShare more secure, but also more difficult for the recipient to connect to it.<br><a href=\"https://github.com/micahflee/onionshare/wiki/Stealth-Onion-Services\">More information</a>.", "gui_settings_stealth_option_details": "This makes OnionShare more secure, but also more difficult for the recipient to connect to it.<br><a href=\"https://github.com/micahflee/onionshare/wiki/Stealth-Onion-Services\">More information</a>.",
"gui_settings_autoupdate_label": "Automatic updates",
"gui_settings_autoupdate_option": "Notify me when updates are available",
"gui_settings_autoupdate_timestamp": "Last checked: {}",
"gui_settings_autoupdate_timestamp_never": "Never",
"gui_settings_autoupdate_check_button": "Check For Updates",
"gui_settings_sharing_label": "Sharing options", "gui_settings_sharing_label": "Sharing options",
"gui_settings_close_after_first_download_option": "Stop sharing after first download", "gui_settings_close_after_first_download_option": "Stop sharing after first download",
"gui_settings_connection_type_label": "How should OnionShare connect to Tor?", "gui_settings_connection_type_label": "How should OnionShare connect to Tor?",