From d4398c52acc54fb27a4b8bba2735a41f55b8f402 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 17 Oct 2013 12:04:12 -0300 Subject: Mail State Machine refactor. Closes: #4059 --- src/leap/bitmask/gui/mail_status.py | 105 +++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 43 deletions(-) (limited to 'src/leap/bitmask/gui/mail_status.py') diff --git a/src/leap/bitmask/gui/mail_status.py b/src/leap/bitmask/gui/mail_status.py index 83533666..c2c06dbb 100644 --- a/src/leap/bitmask/gui/mail_status.py +++ b/src/leap/bitmask/gui/mail_status.py @@ -50,6 +50,8 @@ class MailStatusWidget(QtGui.QWidget): QtGui.QWidget.__init__(self, parent) self._systray = None + self._disabled = True + self._started = False self.ui = Ui_MailStatusWidget() self.ui.setupUi(self) @@ -98,29 +100,16 @@ class MailStatusWidget(QtGui.QWidget): callback=self._mail_handle_soledad_events, reqcbk=lambda req, resp: None) - register(signal=proto.SMTP_SERVICE_STARTED, - callback=self._mail_handle_smtp_events, - reqcbk=lambda req, resp: None) - - register(signal=proto.SMTP_SERVICE_FAILED_TO_START, - callback=self._mail_handle_smtp_events, - reqcbk=lambda req, resp: None) - - register(signal=proto.IMAP_SERVICE_STARTED, + register(signal=proto.IMAP_UNREAD_MAIL, callback=self._mail_handle_imap_events, reqcbk=lambda req, resp: None) - - register(signal=proto.IMAP_SERVICE_FAILED_TO_START, + register(signal=proto.IMAP_SERVICE_STARTED, callback=self._mail_handle_imap_events, reqcbk=lambda req, resp: None) - - register(signal=proto.IMAP_UNREAD_MAIL, + register(signal=proto.SMTP_SERVICE_STARTED, callback=self._mail_handle_imap_events, reqcbk=lambda req, resp: None) - self._smtp_started = False - self._imap_started = False - self._soledad_event.connect( self._mail_handle_soledad_events_slot) self._imap_event.connect( @@ -176,6 +165,9 @@ class MailStatusWidget(QtGui.QWidget): """ # TODO: Figure out how to handle this with the two status in different # classes + # XXX right now we could connect the state transition signals of the + # two connection machines (EIP/Mail) to a class that keeps track of the + # state -- kali # status = self.tr("Encrypted Internet: {0}").format(self._eip_status) # status += '\n' # status += self.tr("Mail is {0}").format(self._mx_status) @@ -292,11 +284,9 @@ class MailStatusWidget(QtGui.QWidget): """ # We want to ignore this kind of events once everything has # started - if self._smtp_started and self._imap_started: + if self._started: return - self._set_mail_status(self.tr("Starting..."), ready=1) - ext_status = "" if req.event == proto.KEYMANAGER_LOOKING_FOR_KEY: @@ -340,14 +330,9 @@ class MailStatusWidget(QtGui.QWidget): ext_status = "" if req.event == proto.SMTP_SERVICE_STARTED: - ext_status = self.tr("SMTP has started...") self._smtp_started = True - if self._smtp_started and self._imap_started: - self._set_mail_status(self.tr("ON"), ready=2) - ext_status = "" elif req.event == proto.SMTP_SERVICE_FAILED_TO_START: ext_status = self.tr("SMTP failed to start, check the logs.") - self._set_mail_status(self.tr("Failed")) else: leap_assert(False, "Don't know how to handle this state: %s" @@ -355,6 +340,8 @@ class MailStatusWidget(QtGui.QWidget): self._set_mail_status(ext_status, ready=2) + # ----- XXX deprecate (move to mail conductor) + def _mail_handle_imap_events(self, req): """ Callback for the IMAP events @@ -376,27 +363,17 @@ class MailStatusWidget(QtGui.QWidget): """ ext_status = None - if req.event == proto.IMAP_SERVICE_STARTED: - ext_status = self.tr("IMAP has started...") - self._imap_started = True - if self._smtp_started and self._imap_started: - self._set_mail_status(self.tr("ON"), ready=2) - ext_status = "" - elif req.event == proto.IMAP_SERVICE_FAILED_TO_START: - ext_status = self.tr("IMAP failed to start, check the logs.") - self._set_mail_status(self.tr("Failed")) - elif req.event == proto.IMAP_UNREAD_MAIL: - if self._smtp_started and self._imap_started: + if req.event == proto.IMAP_UNREAD_MAIL: + + if self._started: + print "printing foo" if req.content != "0": self._set_mail_status(self.tr("%s Unread Emails") % (req.content,), ready=2) else: self._set_mail_status("", ready=2) - else: - leap_assert(False, # XXX ??? - "Don't know how to handle this state: %s" - % (req.event)) - + elif req.event == proto.IMAP_SERVICE_STARTED: + self._imap_started = True if ext_status is not None: self._set_mail_status(ext_status, ready=1) @@ -414,8 +391,50 @@ class MailStatusWidget(QtGui.QWidget): """ self._set_mail_status(self.tr("Disabled"), -1) - def stopped_mail(self): + # statuses + + # XXX make the signal emit the label and state. + + @QtCore.Slot() + def mail_state_disconnected(self): + """ + Displays the correct UI for the disconnected state. + """ + # XXX this should handle the disabled state better. + self._started = False + if self._disabled: + self.mail_state_disabled() + else: + self._set_mail_status(self.tr("OFF"), -1) + + @QtCore.Slot() + def mail_state_connecting(self): + """ + Displays the correct UI for the connecting state. + """ + self._disabled = False + self._started = True + self._set_mail_status(self.tr("Starting..."), 1) + + @QtCore.Slot() + def mail_state_disconnecting(self): + """ + Displays the correct UI for the connecting state. + """ + self._set_mail_status(self.tr("Disconnecting..."), 1) + + @QtCore.Slot() + def mail_state_connected(self): + """ + Displays the correct UI for the connected state. + """ + self._set_mail_status(self.tr("ON"), 2) + + @QtCore.Slot() + def mail_state_disabled(self): """ - Displayes the correct UI for the stopped state. + Displays the correct UI for the disabled state. """ - self._set_mail_status(self.tr("OFF")) + self._disabled = True + self._set_mail_status( + self.tr("You must be logged in to use encrypted email."), -1) -- cgit v1.2.3 From 71f53e07adfa77e1f9f2832334e90b1ffadda73a Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 1 Nov 2013 00:04:17 -0200 Subject: remove print --- src/leap/bitmask/gui/mail_status.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/leap/bitmask/gui/mail_status.py') diff --git a/src/leap/bitmask/gui/mail_status.py b/src/leap/bitmask/gui/mail_status.py index c2c06dbb..c1e82d4d 100644 --- a/src/leap/bitmask/gui/mail_status.py +++ b/src/leap/bitmask/gui/mail_status.py @@ -364,9 +364,7 @@ class MailStatusWidget(QtGui.QWidget): ext_status = None if req.event == proto.IMAP_UNREAD_MAIL: - if self._started: - print "printing foo" if req.content != "0": self._set_mail_status(self.tr("%s Unread Emails") % (req.content,), ready=2) -- cgit v1.2.3