Completely refactor common to make a Common class, and pass that class down into all parts of the program

This commit is contained in:
Micah Lee 2018-03-08 10:18:31 -08:00
parent 49e352d131
commit 50409167d4
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
17 changed files with 458 additions and 444 deletions

View file

@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from PyQt5 import QtCore, QtWidgets, QtGui
from onionshare import strings, common
from onionshare import strings
from onionshare.onion import *
from .alert import Alert
@ -30,16 +30,19 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
"""
open_settings = QtCore.pyqtSignal()
def __init__(self, qtapp, settings, onion):
def __init__(self, common, qtapp, settings, onion):
super(TorConnectionDialog, self).__init__(None)
common.log('TorConnectionDialog', '__init__')
self.common = common
self.common.log('TorConnectionDialog', '__init__')
self.qtapp = qtapp
self.settings = settings
self.onion = onion
self.setWindowTitle("OnionShare")
self.setWindowIcon(QtGui.QIcon(common.get_resource_path('images/logo.png')))
self.setWindowIcon(QtGui.QIcon(self.common.get_resource_path('images/logo.png')))
self.setModal(True)
self.setFixedSize(400, 150)
@ -55,9 +58,9 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
self._tor_status_update(0, '')
def start(self):
common.log('TorConnectionDialog', 'start')
self.common.log('TorConnectionDialog', 'start')
t = TorConnectionThread(self, self.settings, self.onion)
t = TorConnectionThread(self.common, self, self.settings, self.onion)
t.tor_status_update.connect(self._tor_status_update)
t.connected_to_tor.connect(self._connected_to_tor)
t.canceled_connecting_to_tor.connect(self._canceled_connecting_to_tor)
@ -77,14 +80,14 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
self.setLabelText("<strong>{}</strong><br>{}".format(strings._('connecting_to_tor', True), summary))
def _connected_to_tor(self):
common.log('TorConnectionDialog', '_connected_to_tor')
self.common.log('TorConnectionDialog', '_connected_to_tor')
self.active = False
# Close the dialog after connecting
self.setValue(self.maximum())
def _canceled_connecting_to_tor(self):
common.log('TorConnectionDialog', '_canceled_connecting_to_tor')
self.common.log('TorConnectionDialog', '_canceled_connecting_to_tor')
self.active = False
self.onion.cleanup()
@ -92,12 +95,12 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
QtCore.QTimer.singleShot(1, self.cancel)
def _error_connecting_to_tor(self, msg):
common.log('TorConnectionDialog', '_error_connecting_to_tor')
self.common.log('TorConnectionDialog', '_error_connecting_to_tor')
self.active = False
def alert_and_open_settings():
# Display the exception in an alert box
Alert("{}\n\n{}".format(msg, strings._('gui_tor_connection_error_settings', True)), QtWidgets.QMessageBox.Warning)
Alert(self.common, "{}\n\n{}".format(msg, strings._('gui_tor_connection_error_settings', True)), QtWidgets.QMessageBox.Warning)
# Open settings
self.open_settings.emit()
@ -113,16 +116,19 @@ class TorConnectionThread(QtCore.QThread):
canceled_connecting_to_tor = QtCore.pyqtSignal()
error_connecting_to_tor = QtCore.pyqtSignal(str)
def __init__(self, dialog, settings, onion):
def __init__(self, common, dialog, settings, onion):
super(TorConnectionThread, self).__init__()
common.log('TorConnectionThread', '__init__')
self.common = common
self.common.log('TorConnectionThread', '__init__')
self.dialog = dialog
self.settings = settings
self.onion = onion
def run(self):
common.log('TorConnectionThread', 'run')
self.common.log('TorConnectionThread', 'run')
# Connect to the Onion
try:
@ -133,11 +139,11 @@ class TorConnectionThread(QtCore.QThread):
self.canceled_connecting_to_tor.emit()
except BundledTorCanceled as e:
common.log('TorConnectionThread', 'run', 'caught exception: BundledTorCanceled')
self.common.log('TorConnectionThread', 'run', 'caught exception: BundledTorCanceled')
self.canceled_connecting_to_tor.emit()
except Exception as e:
common.log('TorConnectionThread', 'run', 'caught exception: {}'.format(e.args[0]))
self.common.log('TorConnectionThread', 'run', 'caught exception: {}'.format(e.args[0]))
self.error_connecting_to_tor.emit(str(e.args[0]))
def _tor_status_update(self, progress, summary):