summaryrefslogtreecommitdiff
path: root/src/leap/baseapp
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/baseapp')
-rw-r--r--src/leap/baseapp/eip.py2
-rw-r--r--src/leap/baseapp/mainwindow.py27
-rw-r--r--src/leap/baseapp/network.py40
-rw-r--r--src/leap/baseapp/systray.py7
4 files changed, 73 insertions, 3 deletions
diff --git a/src/leap/baseapp/eip.py b/src/leap/baseapp/eip.py
index 8007d2b7..e291de34 100644
--- a/src/leap/baseapp/eip.py
+++ b/src/leap/baseapp/eip.py
@@ -230,9 +230,11 @@ class EIPConductorAppMixin(object):
# we could bring Timer Init to this Mixin
# or to its own Mixin.
self.timer.start(constants.TIMER_MILLISECONDS)
+ self.network_checker.start()
return
if self.eip_service_started is True:
+ self.network_checker.stop()
self.conductor.disconnect()
if self.debugmode:
self.startStopButton.setText('&Connect')
diff --git a/src/leap/baseapp/mainwindow.py b/src/leap/baseapp/mainwindow.py
index 1accac30..09e0c0bb 100644
--- a/src/leap/baseapp/mainwindow.py
+++ b/src/leap/baseapp/mainwindow.py
@@ -8,7 +8,9 @@ from PyQt4 import QtGui
from leap.baseapp.eip import EIPConductorAppMixin
from leap.baseapp.log import LogPaneMixin
from leap.baseapp.systray import StatusAwareTrayIconMixin
+from leap.baseapp.network import NetworkCheckerAppMixin
from leap.baseapp.leap_app import MainWindowMixin
+from leap.baseapp import dialogs
logger = logging.getLogger(name=__name__)
@@ -16,6 +18,7 @@ logger = logging.getLogger(name=__name__)
class LeapWindow(QtGui.QMainWindow,
MainWindowMixin, EIPConductorAppMixin,
StatusAwareTrayIconMixin,
+ NetworkCheckerAppMixin,
LogPaneMixin):
"""
main window for the leap app.
@@ -28,6 +31,7 @@ class LeapWindow(QtGui.QMainWindow,
statusChange = QtCore.pyqtSignal([object])
mainappReady = QtCore.pyqtSignal([])
initReady = QtCore.pyqtSignal([])
+ networkError = QtCore.pyqtSignal([object])
def __init__(self, opts):
logger.debug('init leap window')
@@ -38,6 +42,7 @@ class LeapWindow(QtGui.QMainWindow,
EIPConductorAppMixin.__init__(self, opts=opts)
StatusAwareTrayIconMixin.__init__(self)
+ NetworkCheckerAppMixin.__init__(self)
MainWindowMixin.__init__(self)
settings = QtCore.QSettings()
@@ -58,6 +63,8 @@ class LeapWindow(QtGui.QMainWindow,
lambda status: self.onStatusChange(status))
self.timer.timeout.connect(
lambda: self.onTimerTick())
+ self.networkError.connect(
+ lambda exc: self.onNetworkError(exc))
# do frwizard and init signals
self.mainappReady.connect(self.do_first_run_wizard_check)
@@ -93,5 +100,25 @@ class InitChecksThread(QtCore.QThread):
def run(self):
self.fun()
+#<<<<<<< HEAD
def begin(self):
self.start()
+#=======
+ # could send "ready" signal instead
+ # eipapp should catch that
+ #if self.conductor.autostart:
+ #self.start_or_stopVPN()
+#
+ #TODO: Put all Dialogs in one place
+ #@QtCore.pyqtSlot()
+ #def raise_Network_Error(self, exc):
+ #message = exc.message
+#
+ # XXX
+ # check headless = False before
+ # launching dialog.
+ # (so Qt tests can assert stuff)
+#
+ #dialog = dialogs.ErrorDialog()
+ #dialog.warningMessage(message, 'error')
+#>>>>>>> feature/network_check
diff --git a/src/leap/baseapp/network.py b/src/leap/baseapp/network.py
new file mode 100644
index 00000000..077d5164
--- /dev/null
+++ b/src/leap/baseapp/network.py
@@ -0,0 +1,40 @@
+from __future__ import print_function
+
+import logging
+
+logger = logging.getLogger(name=__name__)
+
+from PyQt4 import QtCore
+
+from leap.baseapp.dialogs import ErrorDialog
+from leap.base.network import NetworkCheckerThread
+
+
+class NetworkCheckerAppMixin(object):
+ """
+ initialize an instance of the Network Checker,
+ which gathers error and passes them on.
+ """
+
+ def __init__(self, *args, **kwargs):
+ self.network_checker = NetworkCheckerThread(
+ error_cb=self.networkError.emit,
+ debug=self.debugmode)
+
+ # XXX move run_checks to slot
+ self.network_checker.run_checks()
+
+ @QtCore.pyqtSlot(object)
+ def onNetworkError(self, exc):
+ """
+ slot that receives a network exceptions
+ and raises a user error message
+ """
+ logger.debug('handling network exception')
+ logger.error(exc.message)
+ dialog = ErrorDialog(parent=self)
+
+ if exc.critical:
+ dialog.criticalMessage(exc.usermessage, "network error")
+ else:
+ dialog.warningMessage(exc.usermessage, "network error")
diff --git a/src/leap/baseapp/systray.py b/src/leap/baseapp/systray.py
index 0ab37f7f..1939bc09 100644
--- a/src/leap/baseapp/systray.py
+++ b/src/leap/baseapp/systray.py
@@ -163,9 +163,10 @@ class StatusAwareTrayIconMixin(object):
oldlayout.itemAt(new).widget().show()
def setIcon(self, name):
- icon = self.Icons.get(name)(self)
- self.trayIcon.setIcon(icon)
- #self.setWindowIcon(icon)
+ icon_fun = self.Icons.get(name)
+ if icon_fun and callable(icon_fun):
+ icon = icon_fun(self)
+ self.trayIcon.setIcon(icon)
def getIcon(self, icon_name):
return self.states.get(icon_name, None)