#662 Allow local-only mode in GUI

This commit is contained in:
Miguel Jacq 2018-03-07 16:13:22 +11:00
parent b16c654e77
commit 46a9a2a0a1
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
3 changed files with 68 additions and 58 deletions

View File

@ -108,7 +108,7 @@ def main():
app = OnionShare(onion, local_only, stay_open, shutdown_timeout) app = OnionShare(onion, local_only, stay_open, shutdown_timeout)
# Launch the gui # Launch the gui
gui = OnionShareGui(onion, qtapp, app, filenames, config) gui = OnionShareGui(onion, qtapp, app, filenames, config, local_only)
# Clean up when app quits # Clean up when app quits
def shutdown(): def shutdown():

View File

@ -43,7 +43,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
starting_server_step3 = QtCore.pyqtSignal() starting_server_step3 = QtCore.pyqtSignal()
starting_server_error = QtCore.pyqtSignal(str) starting_server_error = QtCore.pyqtSignal(str)
def __init__(self, onion, qtapp, app, filenames, config=False): def __init__(self, onion, qtapp, app, filenames, config=False, local_only=False):
super(OnionShareGui, self).__init__() super(OnionShareGui, self).__init__()
self._initSystemTray() self._initSystemTray()
@ -53,6 +53,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.onion = onion self.onion = onion
self.qtapp = qtapp self.qtapp = qtapp
self.app = app self.app = app
self.local_only = local_only
self.setWindowTitle('OnionShare') self.setWindowTitle('OnionShare')
self.setWindowIcon(QtGui.QIcon(common.get_resource_path('images/logo.png'))) self.setWindowIcon(QtGui.QIcon(common.get_resource_path('images/logo.png')))
@ -219,7 +220,8 @@ class OnionShareGui(QtWidgets.QMainWindow):
tor_con = TorConnectionDialog(self.qtapp, self.settings, self.onion) tor_con = TorConnectionDialog(self.qtapp, self.settings, self.onion)
tor_con.canceled.connect(self._tor_connection_canceled) tor_con.canceled.connect(self._tor_connection_canceled)
tor_con.open_settings.connect(self._tor_connection_open_settings) tor_con.open_settings.connect(self._tor_connection_open_settings)
tor_con.start() if not self.local_only:
tor_con.start()
# Start the timer # Start the timer
self.timer.start(500) self.timer.start(500)
@ -339,19 +341,20 @@ class OnionShareGui(QtWidgets.QMainWindow):
# We might've stopped the main requests timer if a Tor connection failed. # We might've stopped the main requests timer if a Tor connection failed.
# If we've reloaded settings, we probably succeeded in obtaining a new # If we've reloaded settings, we probably succeeded in obtaining a new
# connection. If so, restart the timer. # connection. If so, restart the timer.
if self.onion.is_authenticated(): if not self.local_only:
if not self.timer.isActive(): if self.onion.is_authenticated():
self.timer.start(500) if not self.timer.isActive():
# If there were some files listed for sharing, we should be ok to self.timer.start(500)
# re-enable the 'Start Sharing' button now. # If there were some files listed for sharing, we should be ok to
if self.server_status.file_selection.get_num_files() > 0: # re-enable the 'Start Sharing' button now.
self.server_status.server_button.setEnabled(True) if self.server_status.file_selection.get_num_files() > 0:
self.status_bar.clearMessage() self.server_status.server_button.setEnabled(True)
self.status_bar.clearMessage()
# If we switched off the shutdown timeout setting, ensure the widget is hidden. # If we switched off the shutdown timeout setting, ensure the widget is hidden.
if not self.settings.get('shutdown_timeout'): if not self.settings.get('shutdown_timeout'):
self.server_status.shutdown_timeout_container.hide() self.server_status.shutdown_timeout_container.hide()
d = SettingsDialog(self.onion, self.qtapp, self.config) d = SettingsDialog(self.onion, self.qtapp, self.config, self.local_only)
d.settings_saved.connect(reload_settings) d.settings_saved.connect(reload_settings)
d.exec_() d.exec_()
@ -549,15 +552,16 @@ class OnionShareGui(QtWidgets.QMainWindow):
""" """
self.update() self.update()
# Have we lost connection to Tor somehow? if not self.local_only:
if not self.onion.is_authenticated(): # Have we lost connection to Tor somehow?
self.timer.stop() if not self.onion.is_authenticated():
if self.server_status.status != self.server_status.STATUS_STOPPED: self.timer.stop()
self.server_status.stop_server() if self.server_status.status != self.server_status.STATUS_STOPPED:
self.server_status.server_button.setEnabled(False) self.server_status.stop_server()
self.status_bar.showMessage(strings._('gui_tor_connection_lost', True)) self.server_status.server_button.setEnabled(False)
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): self.status_bar.showMessage(strings._('gui_tor_connection_lost', True))
self.systemTray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True)) if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True))
# scroll to the bottom of the dl progress bar log pane # scroll to the bottom of the dl progress bar log pane
# if a new download has been added # if a new download has been added

View File

@ -34,13 +34,14 @@ class SettingsDialog(QtWidgets.QDialog):
""" """
settings_saved = QtCore.pyqtSignal() settings_saved = QtCore.pyqtSignal()
def __init__(self, onion, qtapp, config=False): def __init__(self, onion, qtapp, config=False, local_only=False):
super(SettingsDialog, self).__init__() super(SettingsDialog, self).__init__()
common.log('SettingsDialog', '__init__') common.log('SettingsDialog', '__init__')
self.onion = onion self.onion = onion
self.qtapp = qtapp self.qtapp = qtapp
self.config = config self.config = config
self.local_only = local_only
self.setModal(True) self.setModal(True)
self.setWindowTitle(strings._('gui_settings_window_title', True)) self.setWindowTitle(strings._('gui_settings_window_title', True))
@ -671,48 +672,52 @@ class SettingsDialog(QtWidgets.QDialog):
# If Tor isn't connected, or if Tor settings have changed, Reinitialize # If Tor isn't connected, or if Tor settings have changed, Reinitialize
# the Onion object # the Onion object
reboot_onion = False reboot_onion = False
if self.onion.is_authenticated(): if not self.local_only:
common.log('SettingsDialog', 'save_clicked', 'Connected to Tor') if self.onion.is_authenticated():
def changed(s1, s2, keys): common.log('SettingsDialog', 'save_clicked', 'Connected to Tor')
""" def changed(s1, s2, keys):
Compare the Settings objects s1 and s2 and return true if any values """
have changed for the given keys. Compare the Settings objects s1 and s2 and return true if any values
""" have changed for the given keys.
for key in keys: """
if s1.get(key) != s2.get(key): for key in keys:
return True if s1.get(key) != s2.get(key):
return False return True
return False
if changed(settings, self.old_settings, [ if changed(settings, self.old_settings, [
'connection_type', 'control_port_address', 'connection_type', 'control_port_address',
'control_port_port', 'socks_address', 'socks_port', 'control_port_port', 'socks_address', 'socks_port',
'socket_file_path', 'auth_type', 'auth_password', 'socket_file_path', 'auth_type', 'auth_password',
'no_bridges', 'tor_bridges_use_obfs4', 'no_bridges', 'tor_bridges_use_obfs4',
'tor_bridges_use_meek_lite_amazon', 'tor_bridges_use_meek_lite_azure', 'tor_bridges_use_meek_lite_amazon', 'tor_bridges_use_meek_lite_azure',
'tor_bridges_use_custom_bridges']): 'tor_bridges_use_custom_bridges']):
reboot_onion = True
else:
common.log('SettingsDialog', 'save_clicked', 'Not connected to Tor')
# Tor isn't connected, so try connecting
reboot_onion = True reboot_onion = True
else: # Do we need to reinitialize Tor?
common.log('SettingsDialog', 'save_clicked', 'Not connected to Tor') if reboot_onion:
# Tor isn't connected, so try connecting # Reinitialize the Onion object
reboot_onion = True common.log('SettingsDialog', 'save_clicked', 'rebooting the Onion')
self.onion.cleanup()
# Do we need to reinitialize Tor? tor_con = TorConnectionDialog(self.qtapp, settings, self.onion)
if reboot_onion: tor_con.start()
# Reinitialize the Onion object
common.log('SettingsDialog', 'save_clicked', 'rebooting the Onion')
self.onion.cleanup()
tor_con = TorConnectionDialog(self.qtapp, settings, self.onion) common.log('SettingsDialog', 'save_clicked', 'Onion done rebooting, connected to Tor: {}'.format(self.onion.connected_to_tor))
tor_con.start()
common.log('SettingsDialog', 'save_clicked', 'Onion done rebooting, connected to Tor: {}'.format(self.onion.connected_to_tor)) if self.onion.is_authenticated() and not tor_con.wasCanceled():
self.settings_saved.emit()
self.close()
if self.onion.is_authenticated() and not tor_con.wasCanceled(): else:
self.settings_saved.emit() self.settings_saved.emit()
self.close() self.close()
else: else:
self.settings_saved.emit() self.settings_saved.emit()
self.close() self.close()
@ -856,11 +861,12 @@ class SettingsDialog(QtWidgets.QDialog):
common.log('SettingsDialog', 'closeEvent') common.log('SettingsDialog', 'closeEvent')
# On close, if Tor isn't connected, then quit OnionShare altogether # On close, if Tor isn't connected, then quit OnionShare altogether
if not self.onion.is_authenticated(): if not self.local_only:
common.log('SettingsDialog', 'closeEvent', 'Closing while not connected to Tor') if not self.onion.is_authenticated():
common.log('SettingsDialog', 'closeEvent', 'Closing while not connected to Tor')
# Wait 1ms for the event loop to finish, then quit # Wait 1ms for the event loop to finish, then quit
QtCore.QTimer.singleShot(1, self.qtapp.quit) QtCore.QTimer.singleShot(1, self.qtapp.quit)
def _update_autoupdate_timestamp(self, autoupdate_timestamp): def _update_autoupdate_timestamp(self, autoupdate_timestamp):
common.log('SettingsDialog', '_update_autoupdate_timestamp') common.log('SettingsDialog', '_update_autoupdate_timestamp')