Move settings into the Common object, so the settings are available to all objects (including Web, which is required for receive mode)

This commit is contained in:
Micah Lee 2018-03-13 03:28:47 -07:00
parent c2fecf8aa4
commit 76d299a6c9
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
8 changed files with 72 additions and 66 deletions

View File

@ -25,7 +25,6 @@ from .common import Common
from .web import Web from .web import Web
from .onion import * from .onion import *
from .onionshare import OnionShare from .onionshare import OnionShare
from .settings import Settings
def main(cwd=None): def main(cwd=None):
""" """
@ -71,9 +70,6 @@ def main(cwd=None):
print(strings._('no_filenames')) print(strings._('no_filenames'))
sys.exit() sys.exit()
# Debug mode?
common.debug = debug
# Validate filenames # Validate filenames
if not receive: if not receive:
valid = True valid = True
@ -88,20 +84,22 @@ def main(cwd=None):
sys.exit() sys.exit()
# Load settings # Load settings
settings = Settings(common, config) common.load_settings(config)
settings.load()
# Debug mode?
common.debug = debug
# In receive mode, validate downloads dir # In receive mode, validate downloads dir
if receive: if receive:
valid = True valid = True
if not os.path.isdir(settings.get('downloads_dir')): if not os.path.isdir(common.settings.get('downloads_dir')):
try: try:
os.mkdir(settings.get('downloads_dir'), 0o700) os.mkdir(common.settings.get('downloads_dir'), 0o700)
except: except:
print(strings._('error_cannot_create_downloads_dir').format(settings.get('downloads_dir'))) print(strings._('error_cannot_create_downloads_dir').format(common.settings.get('downloads_dir')))
valid = False valid = False
if valid and not os.access(settings.get('downloads_dir'), os.W_OK): if valid and not os.access(settings.get('downloads_dir'), os.W_OK):
print(strings._('error_downloads_dir_not_writable').format(settings.get('downloads_dir'))) print(strings._('error_downloads_dir_not_writable').format(common.settings.get('downloads_dir')))
valid = False valid = False
if not valid: if not valid:
sys.exit() sys.exit()
@ -112,7 +110,7 @@ def main(cwd=None):
# Start the Onion object # Start the Onion object
onion = Onion(common) onion = Onion(common)
try: try:
onion.connect(settings=False, config=config) onion.connect(custom_settings=False, config=config)
except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e: except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e:
sys.exit(e.args[0]) sys.exit(e.args[0])
except KeyboardInterrupt: except KeyboardInterrupt:
@ -144,7 +142,7 @@ def main(cwd=None):
print('') print('')
# Start OnionShare http service in new thread # Start OnionShare http service in new thread
t = threading.Thread(target=web.start, args=(app.port, app.stay_open, settings.get('slug'))) t = threading.Thread(target=web.start, args=(app.port, app.stay_open, common.settings.get('slug')))
t.daemon = True t.daemon = True
t.start() t.start()
@ -157,10 +155,10 @@ def main(cwd=None):
app.shutdown_timer.start() app.shutdown_timer.start()
# Save the web slug if we are using a persistent private key # Save the web slug if we are using a persistent private key
if settings.get('save_private_key'): if common.settings.get('save_private_key'):
if not settings.get('slug'): if not common.settings.get('slug'):
settings.set('slug', web.slug) common.settings.set('slug', web.slug)
settings.save() common.settings.save()
print('') print('')
if receive: if receive:

View File

@ -29,6 +29,8 @@ import tempfile
import threading import threading
import time import time
from .settings import Settings
class Common(object): class Common(object):
""" """
The Common object is shared amongst all parts of OnionShare. The Common object is shared amongst all parts of OnionShare.
@ -45,6 +47,13 @@ class Common(object):
with open(self.get_resource_path('version.txt')) as f: with open(self.get_resource_path('version.txt')) as f:
self.version = f.read().strip() self.version = f.read().strip()
def load_settings(self, config=None):
"""
Loading settings, optionally from a custom config json file.
"""
self.settings = Settings(self, config)
self.settings.load()
def log(self, module, func, msg=None): def log(self, module, func, msg=None):
""" """
If debug mode is on, log error messages to stdout If debug mode is on, log error messages to stdout

View File

@ -148,15 +148,14 @@ class Onion(object):
# Start out not connected to Tor # Start out not connected to Tor
self.connected_to_tor = False self.connected_to_tor = False
def connect(self, settings=False, config=False, tor_status_update_func=None): def connect(self, custom_settings=False, config=False, tor_status_update_func=None):
self.common.log('Onion', 'connect') self.common.log('Onion', 'connect')
# Either use settings that are passed in, or load them from disk # Either use settings that are passed in, or use them from common
if settings: if custom_settings:
self.settings = settings self.settings = custom_settings
else: else:
self.settings = Settings(self.common, config) self.settings = self.common.settings
self.settings.load()
# The Tor controller # The Tor controller
self.c = None self.c = None

View File

@ -27,7 +27,6 @@ from onionshare.common import Common
from onionshare.web import Web from onionshare.web import Web
from onionshare.onion import Onion from onionshare.onion import Onion
from onionshare.onionshare import OnionShare from onionshare.onionshare import OnionShare
from onionshare.settings import Settings
from .onionshare_gui import OnionShareGui from .onionshare_gui import OnionShareGui

View File

@ -25,7 +25,6 @@ from PyQt5 import QtCore, QtWidgets, QtGui
from onionshare import strings, common from onionshare import strings, common
from onionshare.common import Common, ShutdownTimer from onionshare.common import Common, ShutdownTimer
from onionshare.settings import Settings
from onionshare.onion import * from onionshare.onion import *
from .tor_connection_dialog import TorConnectionDialog from .tor_connection_dialog import TorConnectionDialog
@ -66,8 +65,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
# Load settings # Load settings
self.config = config self.config = config
self.settings = Settings(self.common, self.config) self.common.load_settings(self.config)
self.settings.load()
# File selection # File selection
self.file_selection = FileSelection(self.common) self.file_selection = FileSelection(self.common)
@ -76,7 +74,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.file_selection.file_list.add_file(filename) self.file_selection.file_list.add_file(filename)
# Server status # Server status
self.server_status = ServerStatus(self.common, self.qtapp, self.app, self.web, self.file_selection, self.settings) self.server_status = ServerStatus(self.common, self.qtapp, self.app, self.web, self.file_selection)
self.server_status.server_started.connect(self.file_selection.server_started) self.server_status.server_started.connect(self.file_selection.server_started)
self.server_status.server_started.connect(self.start_server) self.server_status.server_started.connect(self.start_server)
self.server_status.server_started.connect(self.update_server_status_indicator) self.server_status.server_started.connect(self.update_server_status_indicator)
@ -222,7 +220,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.timer.timeout.connect(self.check_for_requests) self.timer.timeout.connect(self.check_for_requests)
# Start the "Connecting to Tor" dialog, which calls onion.connect() # Start the "Connecting to Tor" dialog, which calls onion.connect()
tor_con = TorConnectionDialog(self.common, self.qtapp, self.settings, self.onion) tor_con = TorConnectionDialog(self.common, self.qtapp, 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() tor_con.start()
@ -339,7 +337,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
def reload_settings(): def reload_settings():
self.common.log('OnionShareGui', 'open_settings', 'settings have changed, reloading') self.common.log('OnionShareGui', 'open_settings', 'settings have changed, reloading')
self.settings.load() self.common.settings.load()
# 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.
@ -352,7 +350,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.server_status.server_button.setEnabled(True) self.server_status.server_button.setEnabled(True)
self.status_bar.clearMessage() 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.common.settings.get('shutdown_timeout'):
self.server_status.shutdown_timeout_container.hide() self.server_status.shutdown_timeout_container.hide()
d = SettingsDialog(self.common, self.onion, self.qtapp, self.config) d = SettingsDialog(self.common, self.onion, self.qtapp, self.config)
@ -371,7 +369,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.set_server_active(True) self.set_server_active(True)
self.app.set_stealth(self.settings.get('use_stealth')) self.app.set_stealth(self.common.settings.get('use_stealth'))
# Hide and reset the downloads if we have previously shared # Hide and reset the downloads if we have previously shared
self.downloads_container.hide() self.downloads_container.hide()
@ -395,10 +393,10 @@ class OnionShareGui(QtWidgets.QMainWindow):
return return
self.app.stay_open = not self.settings.get('close_after_first_download') self.app.stay_open = not self.common.settings.get('close_after_first_download')
# start onionshare http service in new thread # start onionshare http service in new thread
t = threading.Thread(target=self.web.start, args=(self.app.port, self.app.stay_open, self.settings.get('slug'))) t = threading.Thread(target=self.web.start, args=(self.app.port, self.app.stay_open, self.common.settings.get('slug')))
t.daemon = True t.daemon = True
t.start() t.start()
# wait for modules in thread to load, preventing a thread-related cx_Freeze crash # wait for modules in thread to load, preventing a thread-related cx_Freeze crash
@ -462,7 +460,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.filesize_warning.setText(strings._("large_filesize", True)) self.filesize_warning.setText(strings._("large_filesize", True))
self.filesize_warning.show() self.filesize_warning.show()
if self.settings.get('shutdown_timeout'): if self.common.settings.get('shutdown_timeout'):
# Convert the date value to seconds between now and then # Convert the date value to seconds between now and then
now = QtCore.QDateTime.currentDateTime() now = QtCore.QDateTime.currentDateTime()
self.timeout = now.secsTo(self.server_status.timeout) self.timeout = now.secsTo(self.server_status.timeout)
@ -527,7 +525,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
Check for updates in a new thread, if enabled. Check for updates in a new thread, if enabled.
""" """
if self.common.platform == 'Windows' or self.common.platform == 'Darwin': if self.common.platform == 'Windows' or self.common.platform == 'Darwin':
if self.settings.get('use_autoupdate'): if self.common.settings.get('use_autoupdate'):
def update_available(update_url, installed_version, latest_version): def update_available(update_url, installed_version, latest_version):
Alert(self.common, strings._("update_available", True).format(update_url, installed_version, latest_version)) Alert(self.common, strings._("update_available", True).format(update_url, installed_version, latest_version))
@ -558,7 +556,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.server_status.stop_server() self.server_status.stop_server()
self.server_status.server_button.setEnabled(False) self.server_status.server_button.setEnabled(False)
self.status_bar.showMessage(strings._('gui_tor_connection_lost', True)) self.status_bar.showMessage(strings._('gui_tor_connection_lost', True))
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): if self.systemTray.supportsMessages() and self.common.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True)) 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
@ -587,7 +585,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.new_download = True self.new_download = True
self.downloads_in_progress += 1 self.downloads_in_progress += 1
self.update_downloads_in_progress(self.downloads_in_progress) self.update_downloads_in_progress(self.downloads_in_progress)
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): if self.systemTray.supportsMessages() and self.common.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('systray_download_started_title', True), strings._('systray_download_started_message', True)) self.systemTray.showMessage(strings._('systray_download_started_title', True), strings._('systray_download_started_message', True))
elif event["type"] == self.web.REQUEST_RATE_LIMIT: elif event["type"] == self.web.REQUEST_RATE_LIMIT:
@ -599,7 +597,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
# is the download complete? # is the download complete?
if event["data"]["bytes"] == self.web.zip_filesize: if event["data"]["bytes"] == self.web.zip_filesize:
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): if self.systemTray.supportsMessages() and self.common.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('systray_download_completed_title', True), strings._('systray_download_completed_message', True)) self.systemTray.showMessage(strings._('systray_download_completed_title', True), strings._('systray_download_completed_message', True))
# Update the total 'completed downloads' info # Update the total 'completed downloads' info
self.downloads_completed += 1 self.downloads_completed += 1
@ -625,7 +623,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
# Update the 'in progress downloads' info # Update the 'in progress downloads' info
self.downloads_in_progress -= 1 self.downloads_in_progress -= 1
self.update_downloads_in_progress(self.downloads_in_progress) self.update_downloads_in_progress(self.downloads_in_progress)
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): if self.systemTray.supportsMessages() and self.common.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('systray_download_canceled_title', True), strings._('systray_download_canceled_message', True)) self.systemTray.showMessage(strings._('systray_download_canceled_title', True), strings._('systray_download_canceled_message', True))
elif event["path"] != '/favicon.ico': elif event["path"] != '/favicon.ico':
@ -633,7 +631,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
# If the auto-shutdown timer has stopped, stop the server # If the auto-shutdown timer has stopped, stop the server
if self.server_status.status == self.server_status.STATUS_STARTED: if self.server_status.status == self.server_status.STATUS_STARTED:
if self.app.shutdown_timer and self.settings.get('shutdown_timeout'): if self.app.shutdown_timer and self.common.settings.get('shutdown_timeout'):
if self.timeout > 0: if self.timeout > 0:
now = QtCore.QDateTime.currentDateTime() now = QtCore.QDateTime.currentDateTime()
seconds_remaining = now.secsTo(self.server_status.timeout) seconds_remaining = now.secsTo(self.server_status.timeout)
@ -654,7 +652,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
When the URL gets copied to the clipboard, display this in the status bar. When the URL gets copied to the clipboard, display this in the status bar.
""" """
self.common.log('OnionShareGui', 'copy_url') self.common.log('OnionShareGui', 'copy_url')
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): if self.systemTray.supportsMessages() and self.common.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('gui_copied_url_title', True), strings._('gui_copied_url', True)) self.systemTray.showMessage(strings._('gui_copied_url_title', True), strings._('gui_copied_url', True))
def copy_hidservauth(self): def copy_hidservauth(self):
@ -662,7 +660,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
When the stealth onion service HidServAuth gets copied to the clipboard, display this in the status bar. When the stealth onion service HidServAuth gets copied to the clipboard, display this in the status bar.
""" """
self.common.log('OnionShareGui', 'copy_hidservauth') self.common.log('OnionShareGui', 'copy_hidservauth')
if self.systemTray.supportsMessages() and self.settings.get('systray_notifications'): if self.systemTray.supportsMessages() and self.common.settings.get('systray_notifications'):
self.systemTray.showMessage(strings._('gui_copied_hidservauth_title', True), strings._('gui_copied_hidservauth', True)) self.systemTray.showMessage(strings._('gui_copied_hidservauth_title', True), strings._('gui_copied_hidservauth', True))
def clear_message(self): def clear_message(self):

View File

@ -38,7 +38,7 @@ class ServerStatus(QtWidgets.QWidget):
STATUS_WORKING = 1 STATUS_WORKING = 1
STATUS_STARTED = 2 STATUS_STARTED = 2
def __init__(self, common, qtapp, app, web, file_selection, settings): def __init__(self, common, qtapp, app, web, file_selection):
super(ServerStatus, self).__init__() super(ServerStatus, self).__init__()
self.common = common self.common = common
@ -50,8 +50,6 @@ class ServerStatus(QtWidgets.QWidget):
self.web = web self.web = web
self.file_selection = file_selection self.file_selection = file_selection
self.settings = settings
# Shutdown timeout layout # Shutdown timeout layout
self.shutdown_timeout_label = QtWidgets.QLabel(strings._('gui_settings_shutdown_timeout', True)) self.shutdown_timeout_label = QtWidgets.QLabel(strings._('gui_settings_shutdown_timeout', True))
self.shutdown_timeout = QtWidgets.QDateTimeEdit() self.shutdown_timeout = QtWidgets.QDateTimeEdit()
@ -135,13 +133,13 @@ class ServerStatus(QtWidgets.QWidget):
info_image = self.common.get_resource_path('images/info.png') info_image = self.common.get_resource_path('images/info.png')
self.url_description.setText(strings._('gui_url_description', True).format(info_image)) self.url_description.setText(strings._('gui_url_description', True).format(info_image))
# Show a Tool Tip explaining the lifecycle of this URL # Show a Tool Tip explaining the lifecycle of this URL
if self.settings.get('save_private_key'): if self.common.settings.get('save_private_key'):
if self.settings.get('close_after_first_download'): if self.common.settings.get('close_after_first_download'):
self.url_description.setToolTip(strings._('gui_url_label_onetime_and_persistent', True)) self.url_description.setToolTip(strings._('gui_url_label_onetime_and_persistent', True))
else: else:
self.url_description.setToolTip(strings._('gui_url_label_persistent', True)) self.url_description.setToolTip(strings._('gui_url_label_persistent', True))
else: else:
if self.settings.get('close_after_first_download'): if self.common.settings.get('close_after_first_download'):
self.url_description.setToolTip(strings._('gui_url_label_onetime', True)) self.url_description.setToolTip(strings._('gui_url_label_onetime', True))
else: else:
self.url_description.setToolTip(strings._('gui_url_label_stay_open', True)) self.url_description.setToolTip(strings._('gui_url_label_stay_open', True))
@ -151,12 +149,12 @@ class ServerStatus(QtWidgets.QWidget):
self.copy_url_button.show() self.copy_url_button.show()
if self.settings.get('save_private_key'): if self.common.settings.get('save_private_key'):
if not self.settings.get('slug'): if not self.common.settings.get('slug'):
self.settings.set('slug', self.web.slug) self.common.settings.set('slug', self.web.slug)
self.settings.save() self.common.settings.save()
if self.settings.get('shutdown_timeout'): if self.common.settings.get('shutdown_timeout'):
self.shutdown_timeout_container.hide() self.shutdown_timeout_container.hide()
if self.app.stealth: if self.app.stealth:
@ -183,26 +181,26 @@ class ServerStatus(QtWidgets.QWidget):
self.server_button.setEnabled(True) self.server_button.setEnabled(True)
self.server_button.setText(strings._('gui_start_server', True)) self.server_button.setText(strings._('gui_start_server', True))
self.server_button.setToolTip('') self.server_button.setToolTip('')
if self.settings.get('shutdown_timeout'): if self.common.settings.get('shutdown_timeout'):
self.shutdown_timeout_container.show() self.shutdown_timeout_container.show()
elif self.status == self.STATUS_STARTED: elif self.status == self.STATUS_STARTED:
self.server_button.setStyleSheet(button_started_style) self.server_button.setStyleSheet(button_started_style)
self.server_button.setEnabled(True) self.server_button.setEnabled(True)
self.server_button.setText(strings._('gui_stop_server', True)) self.server_button.setText(strings._('gui_stop_server', True))
if self.settings.get('shutdown_timeout'): if self.common.settings.get('shutdown_timeout'):
self.shutdown_timeout_container.hide() self.shutdown_timeout_container.hide()
self.server_button.setToolTip(strings._('gui_stop_server_shutdown_timeout_tooltip', True).format(self.timeout)) self.server_button.setToolTip(strings._('gui_stop_server_shutdown_timeout_tooltip', True).format(self.timeout))
elif self.status == self.STATUS_WORKING: elif self.status == self.STATUS_WORKING:
self.server_button.setStyleSheet(button_working_style) self.server_button.setStyleSheet(button_working_style)
self.server_button.setEnabled(True) self.server_button.setEnabled(True)
self.server_button.setText(strings._('gui_please_wait')) self.server_button.setText(strings._('gui_please_wait'))
if self.settings.get('shutdown_timeout'): if self.common.settings.get('shutdown_timeout'):
self.shutdown_timeout_container.hide() self.shutdown_timeout_container.hide()
else: else:
self.server_button.setStyleSheet(button_working_style) self.server_button.setStyleSheet(button_working_style)
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.settings.get('shutdown_timeout'): if self.common.settings.get('shutdown_timeout'):
self.shutdown_timeout_container.hide() self.shutdown_timeout_container.hide()
def server_button_clicked(self): def server_button_clicked(self):
@ -210,7 +208,7 @@ class ServerStatus(QtWidgets.QWidget):
Toggle starting or stopping the server. Toggle starting or stopping the server.
""" """
if self.status == self.STATUS_STOPPED: if self.status == self.STATUS_STOPPED:
if self.settings.get('shutdown_timeout'): if self.common.settings.get('shutdown_timeout'):
# Get the timeout chosen, stripped of its seconds. This prevents confusion if the share stops at (say) 37 seconds past the minute chosen # Get the timeout chosen, stripped of its seconds. This prevents confusion if the share stops at (say) 37 seconds past the minute chosen
self.timeout = self.shutdown_timeout.dateTime().toPyDateTime().replace(second=0, microsecond=0) self.timeout = self.shutdown_timeout.dateTime().toPyDateTime().replace(second=0, microsecond=0)
# If the timeout has actually passed already before the user hit Start, refuse to start the server. # If the timeout has actually passed already before the user hit Start, refuse to start the server.

View File

@ -599,8 +599,8 @@ class SettingsDialog(QtWidgets.QDialog):
else: else:
tor_status_update_func = None tor_status_update_func = None
onion = Onion() onion = Onion(self.common)
onion.connect(settings=settings, config=self.config, tor_status_update_func=tor_status_update_func) onion.connect(custom_settings=settings, config=self.config, tor_status_update_func=tor_status_update_func)
# If an exception hasn't been raised yet, the Tor settings work # If an exception hasn't been raised yet, the Tor settings work
Alert(self.common, strings._('settings_test_success', True).format(onion.tor_version, onion.supports_ephemeral, onion.supports_stealth)) Alert(self.common, strings._('settings_test_success', True).format(onion.tor_version, onion.supports_ephemeral, onion.supports_stealth))
@ -707,7 +707,7 @@ class SettingsDialog(QtWidgets.QDialog):
self.common.log('SettingsDialog', 'save_clicked', 'rebooting the Onion') self.common.log('SettingsDialog', 'save_clicked', 'rebooting the Onion')
self.onion.cleanup() self.onion.cleanup()
tor_con = TorConnectionDialog(self.common, self.qtapp, settings, self.onion) tor_con = TorConnectionDialog(self.common, self.qtapp, self.onion, settings)
tor_con.start() tor_con.start()
self.common.log('SettingsDialog', 'save_clicked', 'Onion done rebooting, connected to Tor: {}'.format(self.onion.connected_to_tor)) self.common.log('SettingsDialog', 'save_clicked', 'Onion done rebooting, connected to Tor: {}'.format(self.onion.connected_to_tor))

View File

@ -30,15 +30,19 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
""" """
open_settings = QtCore.pyqtSignal() open_settings = QtCore.pyqtSignal()
def __init__(self, common, qtapp, settings, onion): def __init__(self, common, qtapp, onion, custom_settings=False):
super(TorConnectionDialog, self).__init__(None) super(TorConnectionDialog, self).__init__(None)
self.common = common self.common = common
if custom_settings:
self.settings = custom_settings
else:
self.settings = self.common.settings
self.common.log('TorConnectionDialog', '__init__') self.common.log('TorConnectionDialog', '__init__')
self.qtapp = qtapp self.qtapp = qtapp
self.settings = settings
self.onion = onion self.onion = onion
self.setWindowTitle("OnionShare") self.setWindowTitle("OnionShare")
@ -60,7 +64,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
def start(self): def start(self):
self.common.log('TorConnectionDialog', 'start') self.common.log('TorConnectionDialog', 'start')
t = TorConnectionThread(self.common, self, self.settings, self.onion) t = TorConnectionThread(self.common, self.settings, self, self.onion)
t.tor_status_update.connect(self._tor_status_update) t.tor_status_update.connect(self._tor_status_update)
t.connected_to_tor.connect(self._connected_to_tor) t.connected_to_tor.connect(self._connected_to_tor)
t.canceled_connecting_to_tor.connect(self._canceled_connecting_to_tor) t.canceled_connecting_to_tor.connect(self._canceled_connecting_to_tor)
@ -116,15 +120,16 @@ class TorConnectionThread(QtCore.QThread):
canceled_connecting_to_tor = QtCore.pyqtSignal() canceled_connecting_to_tor = QtCore.pyqtSignal()
error_connecting_to_tor = QtCore.pyqtSignal(str) error_connecting_to_tor = QtCore.pyqtSignal(str)
def __init__(self, common, dialog, settings, onion): def __init__(self, common, settings, dialog, onion):
super(TorConnectionThread, self).__init__() super(TorConnectionThread, self).__init__()
self.common = common self.common = common
self.common.log('TorConnectionThread', '__init__') self.common.log('TorConnectionThread', '__init__')
self.dialog = dialog
self.settings = settings self.settings = settings
self.dialog = dialog
self.onion = onion self.onion = onion
def run(self): def run(self):