diff options
author | kali <kali@leap.se> | 2012-10-08 09:32:34 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2012-10-08 09:32:34 +0900 |
commit | 479710e977327774b9ba9e1839f75b4a38b51e5f (patch) | |
tree | 120019de26461534c32c39f19777ed3be5084082 /src | |
parent | bf8c6b19b05e73a6e59b8884e1d26a730df6188b (diff) |
add leap-status to main window in non-debug mode
not very DRY but just to have it ready for rc cut.
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/baseapp/eip.py | 1 | ||||
-rw-r--r-- | src/leap/baseapp/leap_app.py | 42 | ||||
-rw-r--r-- | src/leap/baseapp/mainwindow.py | 37 | ||||
-rw-r--r-- | src/leap/baseapp/systray.py | 41 | ||||
-rw-r--r-- | src/leap/eip/eipconnection.py | 26 |
5 files changed, 91 insertions, 56 deletions
diff --git a/src/leap/baseapp/eip.py b/src/leap/baseapp/eip.py index e291de34..311470f2 100644 --- a/src/leap/baseapp/eip.py +++ b/src/leap/baseapp/eip.py @@ -36,6 +36,7 @@ class EIPConductorAppMixin(object): self.conductor = EIPConnection( watcher_cb=self.newLogLine.emit, config_file=config_file, + checker_signals=(self.changeLeapStatus.emit, ), status_signals=(self.statusChange.emit, ), debug=self.debugmode, ovpn_verbosity=opts.openvpn_verb) diff --git a/src/leap/baseapp/leap_app.py b/src/leap/baseapp/leap_app.py index 460d1269..f9eb3bb1 100644 --- a/src/leap/baseapp/leap_app.py +++ b/src/leap/baseapp/leap_app.py @@ -31,6 +31,8 @@ class MainWindowMixin(object): # add widgets to layout #self.createWindowHeader() #mainLayout.addWidget(self.headerBox) + + # created in systray mainLayout.addWidget(self.statusIconBox) if self.debugmode: mainLayout.addWidget(self.statusBox) @@ -87,26 +89,26 @@ class MainWindowMixin(object): icon = QtGui.QIcon(APP_LOGO) self.setWindowIcon(icon) - def createWindowHeader(self): - """ - description lines for main window - """ - self.headerBox = QtGui.QGroupBox() - self.headerLabel = QtGui.QLabel( - "<font size=40>LEAP Encryption Access Project</font>") - self.headerLabelSub = QtGui.QLabel( - "<br><i>your internet encryption toolkit</i>") - - pixmap = QtGui.QPixmap(APP_LOGO) - leap_lbl = QtGui.QLabel() - leap_lbl.setPixmap(pixmap) - - headerLayout = QtGui.QHBoxLayout() - headerLayout.addWidget(leap_lbl) - headerLayout.addWidget(self.headerLabel) - headerLayout.addWidget(self.headerLabelSub) - headerLayout.addStretch() - self.headerBox.setLayout(headerLayout) + #def createWindowHeader(self): + #""" + #description lines for main window + #""" + #self.headerBox = QtGui.QGroupBox() + #self.headerLabel = QtGui.QLabel( + #"<font size=40>LEAP Encryption Access Project</font>") + #self.headerLabelSub = QtGui.QLabel( + #"<br><i>your internet encryption toolkit</i>") +# + #pixmap = QtGui.QPixmap(APP_LOGO) + #leap_lbl = QtGui.QLabel() + #leap_lbl.setPixmap(pixmap) +# + #headerLayout = QtGui.QHBoxLayout() + #headerLayout.addWidget(leap_lbl) + #headerLayout.addWidget(self.headerLabel) + #headerLayout.addWidget(self.headerLabelSub) + #headerLayout.addStretch() + #self.headerBox.setLayout(headerLayout) def set_statusbarMessage(self, msg): self.statusBar().showMessage(msg) diff --git a/src/leap/baseapp/mainwindow.py b/src/leap/baseapp/mainwindow.py index 09e0c0bb..bf42f0e7 100644 --- a/src/leap/baseapp/mainwindow.py +++ b/src/leap/baseapp/mainwindow.py @@ -10,7 +10,6 @@ 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__) @@ -28,11 +27,16 @@ class LeapWindow(QtGui.QMainWindow, """ newLogLine = QtCore.pyqtSignal([str]) - statusChange = QtCore.pyqtSignal([object]) mainappReady = QtCore.pyqtSignal([]) initReady = QtCore.pyqtSignal([]) networkError = QtCore.pyqtSignal([object]) + # XXX fix nomenclature here + # this is eip status change got from vpn management + statusChange = QtCore.pyqtSignal([object]) + # this is global leap status + changeLeapStatus = QtCore.pyqtSignal([str]) + def __init__(self, opts): logger.debug('init leap window') self.debugmode = getattr(opts, 'debug', False) @@ -59,13 +63,18 @@ class LeapWindow(QtGui.QMainWindow, self.trayIcon.activated.connect(self.iconActivated) self.newLogLine.connect( lambda line: self.onLoggerNewLine(line)) - self.statusChange.connect( - lambda status: self.onStatusChange(status)) self.timer.timeout.connect( lambda: self.onTimerTick()) self.networkError.connect( lambda exc: self.onNetworkError(exc)) + # status change. + # TODO unify + self.statusChange.connect( + lambda status: self.onStatusChange(status)) + self.changeLeapStatus.connect( + lambda newstatus: self.onChangeLeapConnStatus(newstatus)) + # do frwizard and init signals self.mainappReady.connect(self.do_first_run_wizard_check) self.initReady.connect(self.runchecks_and_eipconnect) @@ -100,25 +109,5 @@ 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/systray.py b/src/leap/baseapp/systray.py index 1939bc09..d5d44f61 100644 --- a/src/leap/baseapp/systray.py +++ b/src/leap/baseapp/systray.py @@ -41,7 +41,7 @@ class StatusAwareTrayIconMixin(object): self.createIconGroupBox() self.createActions() self.createTrayIcon() - logger.debug('showing tray icon................') + #logger.debug('showing tray icon................') self.trayIcon.show() # not sure if this really belongs here, but... @@ -75,6 +75,10 @@ class StatusAwareTrayIconMixin(object): statusIconLayout.addWidget(self.ConnectionWidgets['connected']) statusIconLayout.itemAt(1).widget().hide() statusIconLayout.itemAt(2).widget().hide() + + self.leapConnStatus = QtGui.QLabel("<b>disconnected</b>") + statusIconLayout.addWidget(self.leapConnStatus) + self.statusIconBox.setLayout(statusIconLayout) def createTrayIcon(self): @@ -84,9 +88,6 @@ class StatusAwareTrayIconMixin(object): self.trayIconMenu = QtGui.QMenu(self) self.trayIconMenu.addAction(self.connAct) - #self.trayIconMenu.addAction(self.minimizeAction) - #self.trayIconMenu.addAction(self.maximizeAction) - #self.trayIconMenu.addAction(self.restoreAction) self.trayIconMenu.addSeparator() self.trayIconMenu.addAction(self.detailsAct) self.trayIconMenu.addSeparator() @@ -113,12 +114,6 @@ class StatusAwareTrayIconMixin(object): self.detailsAct = QtGui.QAction("&Details...", self, triggered=self.detailsWin) - #self.minimizeAction = QtGui.QAction("Mi&nimize", self, - #triggered=self.hide) - #self.maximizeAction = QtGui.QAction("Ma&ximize", self, - #triggered=self.showMaximized) - #self.restoreAction = QtGui.QAction("&Restore", self, - #triggered=self.showNormal) self.aboutAct = QtGui.QAction("&About", self, triggered=self.about) self.aboutQtAct = QtGui.QAction("About Q&t", self, @@ -197,10 +192,32 @@ class StatusAwareTrayIconMixin(object): @QtCore.pyqtSlot(object) def onStatusChange(self, status): """ - slot for status changes. triggers new signals for - updating icon, status bar, etc. + updates icon """ icon_name = self.conductor.get_icon_name() + + # XXX refactor. Use QStateMachine + + if icon_name in ("disconnected", "connected"): + self.changeLeapStatus.emit(icon_name) + + if icon_name in ("connecting"): + # let's see how it matches + leap_status_name = self.conductor.get_leap_status() + self.changeLeapStatus.emit(leap_status_name) + self.setIcon(icon_name) # change connection pixmap widget self.setConnWidget(icon_name) + + @QtCore.pyqtSlot(str) + def onChangeLeapConnStatus(self, newstatus): + """ + slot for LEAP status changes + not to be confused with onStatusChange. + this only updates the non-debug LEAP Status line + next to the connection icon. + """ + # XXX move bold to style sheet + self.leapConnStatus.setText( + "<b>%s</b>" % newstatus) diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index f0a98d8c..a5b59892 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -35,6 +35,9 @@ class EIPConnection(OpenVPNConnection): status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) + checker_signals = kwargs.pop('checker_signals', None) + self.checker_signals = checker_signals + self.provider_cert_checker = provider_cert_checker() self.config_checker = config_checker() @@ -59,10 +62,14 @@ class EIPConnection(OpenVPNConnection): try: # network (1) + for signal in self.checker_signals: + signal('checking encryption keys') self.provider_cert_checker.run_all(skip_verify=skip_verify) except Exception as exc: push_err(exc) try: + for signal in self.checker_signals: + signal('checking provider config') self.config_checker.run_all(skip_download=skip_download) except Exception as exc: push_err(exc) @@ -125,6 +132,9 @@ class EIPConnection(OpenVPNConnection): """ return self.status.get_state_icon() + def get_leap_status(self): + return self.status.get_leap_status() + # # private methods # @@ -231,6 +241,22 @@ class EIPConnectionStatus(object): } return human_status[self.current] + def get_leap_status(self): + # XXX improve nomenclature + leap_status = { + 1: 'connecting to gateway', + 2: 'connecting to gateway', + 3: 'authenticating', + 4: 'establishing network encryption', + 5: 'establishing network encryption', + 6: 'establishing network encryption', + 7: 'connected', + 8: 'reconnecting', + 9: 'exiting', + 11: 'unrecoverable error', + } + return leap_status[self.current] + def get_state_icon(self): """ returns the high level icon |