import time
import logging
-import backend
import addressbook
import conversations
import state_machine
defaults[key] = (state_machine.UpdateStateMachine.INFINITE_PERIOD, unit)
self._username = None
self._password = None
+ self._cookiePath = cookiePath
+
+ self._lastDndCheck = 0
+ self._cachedIsDnd = False
self._asyncPool = gobject_utils.AsyncPool()
- self._backend = backend.GVoiceBackend(cookiePath)
+ import backend
+ self._backend = backend.GVoiceBackend(self._cookiePath)
if defaults["contacts"][0] == state_machine.UpdateStateMachine.INFINITE_PERIOD:
contactsPeriodInSeconds = state_machine.UpdateStateMachine.INFINITE_PERIOD
self._masterStateMachine.append_machine(self._voicemailsStateMachine)
self._masterStateMachine.append_machine(self._textsStateMachine)
- self._lastDndCheck = 0
- self._cachedIsDnd = False
-
def load(self, path):
self._texts.load(os.sep.join((path, "texts.cache")))
self._voicemails.load(os.sep.join((path, "voicemails.cache")))
def _login(self, username, password, on_success, on_error):
self._username = username
self._password = password
- try:
- isLoggedIn = yield (
- self._backend.login,
- (self._username, self._password),
- {},
- )
- except Exception, e:
- on_error(e)
- return
+
+ isLoggedIn = False
+
+ if not isLoggedIn and self._backend.is_quick_login_possible():
+ try:
+ isLoggedIn = yield (
+ self._backend.is_authed,
+ (),
+ {},
+ )
+ except Exception, e:
+ on_error(e)
+ return
+ if isLoggedIn:
+ _moduleLogger.info("Logged in through cookies")
+
+ if not isLoggedIn:
+ try:
+ isLoggedIn = yield (
+ self._backend.login,
+ (self._username, self._password),
+ {},
+ )
+ except Exception, e:
+ on_error(e)
+ return
+ if isLoggedIn:
+ _moduleLogger.info("Logged in through credentials")
self._masterStateMachine.start()
on_success(isLoggedIn)
+ def shutdown(self):
+ self._asyncPool.stop()
+ self._masterStateMachine.stop()
+ self._backend.shutdown()
+
+ self._username = None
+ self._password = None
+
def logout(self):
self._asyncPool.stop()
self._masterStateMachine.stop()
return isLoggedIn
def set_dnd(self, doNotDisturb):
- self._backend.set_dnd(doNotDisturb)
- self._cachedIsDnd = doNotDisturb
+ if self._cachedIsDnd != doNotDisturb:
+ self._backend.set_dnd(doNotDisturb)
+ self._cachedIsDnd = doNotDisturb
def is_dnd(self):
# To throttle checking with the server, use a 30s cache