Fixing the lists on fremantle
[gc-dialer] / src / dc_glade.py
index ff6123c..6923606 100755 (executable)
@@ -40,6 +40,7 @@ import gtk_toolbox
 
 
 _moduleLogger = logging.getLogger("dc_glade")
+PROFILE_STARTUP = False
 
 
 def getmtime_nothrow(path):
@@ -73,6 +74,7 @@ class Dialcentral(object):
        ACCOUNT_TAB = 4
 
        NULL_BACKEND = 0
+       # 1 Was GrandCentral support so the gap was maintained for compatibility
        GV_BACKEND = 2
        BACKENDS = (NULL_BACKEND, GV_BACKEND)
 
@@ -171,9 +173,12 @@ class Dialcentral(object):
                        )
                )
 
-               backgroundSetup = threading.Thread(target=self._idle_setup)
-               backgroundSetup.setDaemon(True)
-               backgroundSetup.start()
+               if not PROFILE_STARTUP:
+                       backgroundSetup = threading.Thread(target=self._idle_setup)
+                       backgroundSetup.setDaemon(True)
+                       backgroundSetup.start()
+               else:
+                       self._idle_setup()
 
        def _idle_setup(self):
                """
@@ -217,13 +222,17 @@ class Dialcentral(object):
 
                        try:
                                import alarm_handler
-                               self._alarmHandler = alarm_handler.AlarmHandler()
+                               if alarm_handler.AlarmHandler is not alarm_handler._NoneAlarmHandler:
+                                       self._alarmHandler = alarm_handler.AlarmHandler()
+                               else:
+                                       self._alarmHandler = None
                        except (ImportError, OSError):
                                alarm_handler = None
                        except Exception:
                                with gtk_toolbox.gtk_lock():
                                        self._errorDisplay.push_exception()
                                alarm_handler = None
+                       if alarm_handler is None:
                                _moduleLogger.warning("No notification support")
                        if hildonize.IS_HILDON_SUPPORTED:
                                try:
@@ -343,22 +352,21 @@ class Dialcentral(object):
                        with gtk_toolbox.gtk_lock():
                                self._errorDisplay.push_exception()
                finally:
-                       self._spawn_attempt_login(2)
+                       self._spawn_attempt_login()
 
        def _spawn_attempt_login(self, *args):
                self._loginSink.send(args)
 
-       def _attempt_login(self, numOfAttempts = 10, force = False):
+       def _attempt_login(self, force = False):
                """
                @note This must be run outside of the UI lock
                """
                try:
-                       assert 0 <= numOfAttempts, "That was pointless having 0 or less login attempts"
                        assert self._initDone, "Attempting login before app is fully loaded"
 
                        serviceId = self.NULL_BACKEND
                        loggedIn = False
-                       if not force:
+                       if not force and self._defaultBackendId != self.NULL_BACKEND:
                                with gtk_toolbox.gtk_lock():
                                        banner = hildonize.show_busy_banner_start(self._window, "Logging In...")
                                try:
@@ -372,7 +380,7 @@ class Dialcentral(object):
                                                hildonize.show_busy_banner_end(banner)
 
                        if not loggedIn:
-                               loggedIn, serviceId = self._login_by_user(numOfAttempts)
+                               loggedIn, serviceId = self._login_by_user()
 
                        with gtk_toolbox.gtk_lock():
                                self._change_loggedin_status(serviceId)
@@ -413,30 +421,19 @@ class Dialcentral(object):
                @note Thread agnostic
                """
                username, password = self._credentials
-               try:
-                       loggedIn = self._phoneBackends[self._defaultBackendId].login(username, password)
-               except Exception:
-                       # Retry in case the redirect failed
-                       # luckily is_authed does everything we need for a retry
-                       loggedIn = self._phoneBackends[self._defaultBackendId].is_authed(True)
-                       if not loggedIn:
-                               raise
-                       _moduleLogger.info("Redirection failed on initial login attempt, auto-corrected for this")
+               loggedIn = self._phoneBackends[self._defaultBackendId].login(username, password)
                if loggedIn:
                        self._credentials = username, password
                        _moduleLogger.info("Logged into %r through settings" % self._phoneBackends[self._defaultBackendId])
                return loggedIn
 
-       def _login_by_user(self, numOfAttempts):
+       def _login_by_user(self):
                """
                @note This must be run outside of the UI lock
                """
                loggedIn, (username, password) = False, self._credentials
                tmpServiceId = self.GV_BACKEND
-               for attemptCount in xrange(numOfAttempts):
-                       if loggedIn:
-                               break
-
+               while not loggedIn:
                        with gtk_toolbox.gtk_lock():
                                credentials = self._credentialsDialog.request_credentials(
                                        defaultCredentials = self._credentials
@@ -444,19 +441,11 @@ class Dialcentral(object):
                                if not self._phoneBackends[tmpServiceId].get_callback_number():
                                        # subtle reminder to the users to configure things
                                        self._notebook.set_current_page(self.ACCOUNT_TAB)
-                               banner = hildonize.show_busy_banner_start(self._window, "Logging In...")
 
+                               banner = hildonize.show_busy_banner_start(self._window, "Logging In...")
                        try:
                                username, password = credentials
-                               try:
-                                       loggedIn = self._phoneBackends[tmpServiceId].login(username, password)
-                               except Exception:
-                                       # Retry in case the redirect failed
-                                       # luckily is_authed does everything we need for a retry
-                                       loggedIn = self._phoneBackends[tmpServiceId].is_authed(True)
-                                       if not loggedIn:
-                                               raise
-                                       _moduleLogger.info("Redirection failed on initial login attempt, auto-corrected for this")
+                               loggedIn = self._phoneBackends[tmpServiceId].login(username, password)
                        finally:
                                with gtk_toolbox.gtk_lock():
                                        hildonize.show_busy_banner_end(banner)
@@ -466,6 +455,7 @@ class Dialcentral(object):
                        self._credentials = username, password
                        _moduleLogger.info("Logged into %r through user request" % self._phoneBackends[serviceId])
                else:
+                       # Hint to the user that they are not logged in
                        serviceId = self.NULL_BACKEND
                        self._notebook.set_current_page(self.ACCOUNT_TAB)
 
@@ -510,7 +500,10 @@ class Dialcentral(object):
                @note UI Thread
                """
                try:
-                       self._defaultBackendId = config.getint(constants.__pretty_app_name__, "active")
+                       if not PROFILE_STARTUP:
+                               self._defaultBackendId = config.getint(constants.__pretty_app_name__, "active")
+                       else:
+                               self._defaultBackendId = self.NULL_BACKEND
                        blobs = (
                                config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
                                for i in xrange(len(self._credentials))
@@ -588,8 +581,15 @@ class Dialcentral(object):
                """
                @note Thread Agnostic
                """
+               # Because we now only support GVoice, if there are user credentials,
+               # always assume its using the GVoice backend
+               if self._credentials[0] and self._credentials[1]:
+                       backend = self.GV_BACKEND
+               else:
+                       backend = self.NULL_BACKEND
+
                config.add_section(constants.__pretty_app_name__)
-               config.set(constants.__pretty_app_name__, "active", str(self._selectedBackendId))
+               config.set(constants.__pretty_app_name__, "active", str(backend))
                config.set(constants.__pretty_app_name__, "orientation", str(int(gtk_toolbox.get_screen_orientation())))
                for i, value in enumerate(self._credentials):
                        blob = base64.b64encode(value)
@@ -674,7 +674,7 @@ class Dialcentral(object):
 
                        if status == conic.STATUS_CONNECTED:
                                if self._initDone:
-                                       self._spawn_attempt_login(2)
+                                       self._spawn_attempt_login()
                        elif status == conic.STATUS_DISCONNECTED:
                                if self._initDone:
                                        self._defaultBackendId = self._selectedBackendId
@@ -720,7 +720,7 @@ class Dialcentral(object):
                        self._contactsViews[self._selectedBackendId].clear()
                        self._change_loggedin_status(self.NULL_BACKEND)
 
-                       self._spawn_attempt_login(2, True)
+                       self._spawn_attempt_login(True)
                except Exception, e:
                        self._errorDisplay.push_exception()
 
@@ -880,7 +880,8 @@ def run_dialpad():
        if hildonize.IS_HILDON_SUPPORTED:
                gtk.set_application_name(constants.__pretty_app_name__)
        handle = Dialcentral()
-       gtk.main()
+       if not PROFILE_STARTUP:
+               gtk.main()
 
 
 class DummyOptions(object):