def _update_account(self): try: with qui_utils.notify_busy(self._errorLog, "Updating Account"): accountData = yield (self._backend[0].refresh_account_info, (), {}) except Exception, e: _moduleLogger.exception("Reporting error to user") self.error.emit(str(e)) return
def _update_history(self, historyType): try: assert self.state == self.LOGGEDIN_STATE, "History requires being logged in (currently %s" % self.state with qui_utils.notify_busy(self._errorLog, "Updating '%s' History" % historyType): self._history = yield (self._backend[0].get_call_history, (historyType,), {}) except Exception, e: _moduleLogger.exception("Reporting error to user") self.error.emit(str(e)) return
def _update_messages(self, messageType): try: assert self.state == self.LOGGEDIN_STATE, "Messages requires being logged in (currently %s" % self.state with qui_utils.notify_busy(self._errorLog, "Updating %s Messages" % messageType): self._messages = yield (self._backend[0].get_messages, (messageType,), {}) except Exception, e: _moduleLogger.exception("Reporting error to user") self.error.emit(str(e)) return
def _cancel(self): self.cancelling.emit() try: with qui_utils.notify_busy(self._errorLog, "Cancelling"): yield (self._backend[0].cancel, (), {}) self.cancelled.emit() except Exception, e: _moduleLogger.exception("Reporting error to user") self.error.emit(str(e))
def _set_dnd(self, dnd): oldDnd = self._dnd try: assert self.state == self.LOGGEDIN_STATE, "DND requires being logged in (currently %s" % self.state with qui_utils.notify_busy(self._errorLog, "Setting DND Status"): yield (self._backend[0].set_dnd, (dnd,), {}) except Exception, e: _moduleLogger.exception("Reporting error to user") self.error.emit(str(e)) return
def _refresh_authentication(self): try: with qui_utils.notify_busy(self._errorLog, "Updating Account"): accountData = yield (self._backend[0].refresh_account_info, (), {}) accountData = None except Exception, e: _moduleLogger.exception("Passing to user") self.error.emit(str(e)) # refresh_account_info does not normally throw, so it is fine if we # just quit early because something seriously wrong is going on return
def _call(self, number): self.calling.emit() try: with self._busy("Calling"): with qui_utils.notify_busy(self._errorLog, "Calling"): yield (self._backend[0].call, (number,), {}) self.called.emit() self._clear() except Exception, e: _moduleLogger.exception("Reporting error to user") self.error.emit(str(e))
def _send(self, numbers, text): self.sendingMessage.emit() try: with self._busy("Sending Text"): with qui_utils.notify_busy(self._errorLog, "Sending Text"): yield (self._backend[0].send_sms, (numbers, text), {}) self.sentMessage.emit() self._clear() except Exception, e: _moduleLogger.exception("Reporting error to user") self.error.emit(str(e))
def _update_dnd(self): with qui_utils.notify_busy(self._errorLog, "Updating Do-Not-Disturb Status"): oldDnd = self._dnd try: assert self.state == self.LOGGEDIN_STATE, "DND requires being logged in (currently %s" % self.state self._dnd = yield (self._backend[0].is_dnd, (), {}) except Exception, e: _moduleLogger.exception("Reporting error to user") self.error.emit(str(e)) return if oldDnd != self._dnd: self.dndStateChange(self._dnd)
def _download_voicemail(self, messageId): actualPath = os.path.join(self._voicemailCachePath, "%s.mp3" % messageId) targetPath = "%s.%s.part" % (actualPath, time.time()) if os.path.exists(actualPath): self.voicemailAvailable.emit(messageId, actualPath) return with qui_utils.notify_busy(self._errorLog, "Downloading Voicemail"): try: yield (self._backend[0].download, (messageId, targetPath), {}) except Exception, e: _moduleLogger.exception("Passing to user") self.error.emit(str(e)) return
def _login(self, username, password): with qui_utils.notify_busy(self._errorLog, "Logging In"): self._loggedInTime = self._LOGGINGIN_TIME self.stateChange.emit(self.LOGGINGIN_STATE) finalState = self.LOGGEDOUT_STATE accountData = None try: if accountData is None and self._backend[0].is_quick_login_possible(): accountData = yield (self._backend[0].refresh_account_info, (), {}) if accountData is not None: _moduleLogger.info("Logged in through cookies") else: # Force a clearing of the cookies yield (self._backend[0].logout, (), {}) if accountData is None: accountData = yield (self._backend[0].login, (username, password), {}) if accountData is not None: _moduleLogger.info("Logged in through credentials") if accountData is not None: self._loggedInTime = int(time.time()) oldUsername = self._username self._username = username self._password = password finalState = self.LOGGEDIN_STATE if oldUsername != self._username: needOps = not self._load() else: needOps = True self._voicemailCachePath = os.path.join(self._cachePath, "%s.voicemail.cache" % self._username) try: os.makedirs(self._voicemailCachePath) except OSError, e: if e.errno != 17: raise self.loggedIn.emit() self.stateChange.emit(finalState) finalState = None # Mark it as already set self._process_account_data(accountData) if needOps: loginOps = self._loginOps[:] else: loginOps = [] del self._loginOps[:] for asyncOp, args, kwds in loginOps: asyncOp.start(*args, **kwds) else: