Stop hildonizing widgets that don't exist, now and in the future
[gc-dialer] / src / dc_glade.py
index 9e85078..33ad67a 100755 (executable)
@@ -39,6 +39,9 @@ import hildonize
 import gtk_toolbox
 
 
+_moduleLogger = logging.getLogger("dc_glade")
+
+
 def getmtime_nothrow(path):
        try:
                return os.path.getmtime(path)
@@ -111,21 +114,38 @@ class Dialcentral(object):
                self._window = hildonize.hildonize_window(self._app, self._window)
                hildonize.hildonize_text_entry(self._widgetTree.get_widget("usernameentry"))
                hildonize.hildonize_password_entry(self._widgetTree.get_widget("passwordentry"))
-               hildonize.hildonize_combo_entry(self._widgetTree.get_widget("callbackcombo").get_child())
 
-               for scrollingWidget in (
+               for scrollingWidgetName in (
                        'recent_scrolledwindow',
                        'message_scrolledwindow',
                        'contacts_scrolledwindow',
-                       "phoneSelectionMessages_scrolledwindow",
                        "smsMessages_scrolledwindow",
                ):
-                       hildonize.hildonize_scrollwindow(self._widgetTree.get_widget(scrollingWidget))
-               for scrollingWidget in (
-                       "phonetypes_scrolledwindow",
+                       scrollingWidget = self._widgetTree.get_widget(scrollingWidgetName)
+                       assert scrollingWidget is not None, scrollingWidgetName
+                       hildonize.hildonize_scrollwindow(scrollingWidget)
+               for scrollingWidgetName in (
                        "smsMessage_scrolledEntry",
                ):
-                       hildonize.hildonize_scrollwindow_with_viewport(self._widgetTree.get_widget(scrollingWidget))
+                       scrollingWidget = self._widgetTree.get_widget(scrollingWidgetName)
+                       assert scrollingWidget is not None, scrollingWidgetName
+                       hildonize.hildonize_scrollwindow_with_viewport(scrollingWidget)
+
+               for buttonName in (
+                       "back",
+                       "addressbookSelectButton",
+                       "sendSmsButton",
+                       "dialButton",
+                       "selectButton",
+                       "cancelSmsButton",
+                       "callbackSelectButton",
+                       "minutesEntryButton",
+                       "clearcookies",
+                       "phoneTypeSelection",
+               ):
+                       button = self._widgetTree.get_widget(buttonName)
+                       assert button is not None, buttonName
+                       hildonize.set_button_thumb_selectable(button)
 
                replacementButtons = [gtk.Button("Test")]
                menu = hildonize.hildonize_menu(
@@ -137,7 +157,7 @@ class Dialcentral(object):
                self._window.connect("key-press-event", self._on_key_press)
                self._window.connect("window-state-event", self._on_window_state_change)
                if not hildonize.IS_HILDON_SUPPORTED:
-                       logging.warning("No hildonization support")
+                       _moduleLogger.warning("No hildonization support")
 
                hildonize.set_application_title(self._window, "%s" % constants.__pretty_app_name__)
 
@@ -194,7 +214,7 @@ class Dialcentral(object):
                                device = osso.DeviceState(self._osso)
                                device.set_device_state_callback(self._on_device_state_change, 0)
                        else:
-                               logging.warning("No device state support")
+                               _moduleLogger.warning("No device state support")
 
                        try:
                                import alarm_handler
@@ -205,13 +225,13 @@ class Dialcentral(object):
                                with gtk_toolbox.gtk_lock():
                                        self._errorDisplay.push_exception()
                                alarm_handler = None
-                               logging.warning("No notification support")
+                               _moduleLogger.warning("No notification support")
                        if hildonize.IS_HILDON_SUPPORTED:
                                try:
                                        import led_handler
                                        self._ledHandler = led_handler.LedHandler()
                                except Exception, e:
-                                       logging.exception('LED Handling failed: "%s"' % str(e))
+                                       _moduleLogger.exception('LED Handling failed: "%s"' % str(e))
                                        self._ledHandler = None
                        else:
                                self._ledHandler = None
@@ -226,7 +246,7 @@ class Dialcentral(object):
                                self._connection.connect("connection-event", self._on_connection_change, constants.__app_magic__)
                                self._connection.request_connection(conic.CONNECT_FLAG_NONE)
                        else:
-                               logging.warning("No connection support")
+                               _moduleLogger.warning("No connection support")
                except Exception, e:
                        with gtk_toolbox.gtk_lock():
                                self._errorDisplay.push_exception()
@@ -340,12 +360,17 @@ class Dialcentral(object):
                        serviceId = self.NULL_BACKEND
                        loggedIn = False
                        if not force:
+                               with gtk_toolbox.gtk_lock():
+                                       banner = hildonize.show_busy_banner_start(self._window, "Logging In...")
                                try:
                                        self.refresh_session()
                                        serviceId = self._defaultBackendId
                                        loggedIn = True
                                except Exception, e:
-                                       logging.exception('Session refresh failed with the following message "%s"' % str(e))
+                                       _moduleLogger.exception('Session refresh failed with the following message "%s"' % str(e))
+                               finally:
+                                       with gtk_toolbox.gtk_lock():
+                                               hildonize.show_busy_banner_end(banner)
 
                        if not loggedIn:
                                loggedIn, serviceId = self._login_by_user(numOfAttempts)
@@ -354,6 +379,8 @@ class Dialcentral(object):
                                self._change_loggedin_status(serviceId)
                                if loggedIn:
                                        hildonize.show_information_banner(self._window, "Logged In")
+                               else:
+                                       hildonize.show_information_banner(self._window, "Login Failed")
                except Exception, e:
                        with gtk_toolbox.gtk_lock():
                                self._errorDisplay.push_exception()
@@ -379,7 +406,7 @@ class Dialcentral(object):
                """
                loggedIn = self._phoneBackends[self._defaultBackendId].is_authed()
                if loggedIn:
-                       logging.info("Logged into %r through cookies" % self._phoneBackends[self._defaultBackendId])
+                       _moduleLogger.info("Logged into %r through cookies" % self._phoneBackends[self._defaultBackendId])
                return loggedIn
 
        def _login_by_settings(self):
@@ -390,7 +417,7 @@ class Dialcentral(object):
                loggedIn = self._phoneBackends[self._defaultBackendId].login(username, password)
                if loggedIn:
                        self._credentials = username, password
-                       logging.info("Logged into %r through settings" % self._phoneBackends[self._defaultBackendId])
+                       _moduleLogger.info("Logged into %r through settings" % self._phoneBackends[self._defaultBackendId])
                return loggedIn
 
        def _login_by_user(self, numOfAttempts):
@@ -409,13 +436,18 @@ 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)
-                       username, password = credentials
-                       loggedIn = self._phoneBackends[tmpServiceId].login(username, password)
+                               banner = hildonize.show_busy_banner_start(self._window, "Logging In...")
+                       try:
+                               username, password = credentials
+                               loggedIn = self._phoneBackends[tmpServiceId].login(username, password)
+                       finally:
+                               with gtk_toolbox.gtk_lock():
+                                       hildonize.show_busy_banner_end(banner)
 
                if loggedIn:
                        serviceId = tmpServiceId
                        self._credentials = username, password
-                       logging.info("Logged into %r through user request" % self._phoneBackends[serviceId])
+                       _moduleLogger.info("Logged into %r through user request" % self._phoneBackends[serviceId])
                else:
                        serviceId = self.NULL_BACKEND
                        self._notebook.set_current_page(self.ACCOUNT_TAB)
@@ -478,14 +510,14 @@ class Dialcentral(object):
                        if self._alarmHandler is not None:
                                self._alarmHandler.load_settings(config, "alarm")
                except ConfigParser.NoOptionError, e:
-                       logging.exception(
+                       _moduleLogger.exception(
                                "Settings file %s is missing section %s" % (
                                        constants._user_settings_,
                                        e.section,
                                ),
                        )
                except ConfigParser.NoSectionError, e:
-                       logging.exception(
+                       _moduleLogger.exception(
                                "Settings file %s is missing section %s" % (
                                        constants._user_settings_,
                                        e.section,
@@ -503,14 +535,14 @@ class Dialcentral(object):
                        try:
                                view.load_settings(config, sectionName)
                        except ConfigParser.NoOptionError, e:
-                               logging.exception(
+                               _moduleLogger.exception(
                                        "Settings file %s is missing section %s" % (
                                                constants._user_settings_,
                                                e.section,
                                        ),
                                )
                        except ConfigParser.NoSectionError, e:
-                               logging.exception(
+                               _moduleLogger.exception(
                                        "Settings file %s is missing section %s" % (
                                                constants._user_settings_,
                                                e.section,
@@ -524,14 +556,14 @@ class Dialcentral(object):
                        elif previousOrientation == gtk.ORIENTATION_VERTICAL:
                                hildonize.window_to_portrait(self._window)
                except ConfigParser.NoOptionError, e:
-                       logging.exception(
+                       _moduleLogger.exception(
                                "Settings file %s is missing section %s" % (
                                        constants._user_settings_,
                                        e.section,
                                ),
                        )
                except ConfigParser.NoSectionError, e:
-                       logging.exception(
+                       _moduleLogger.exception(
                                "Settings file %s is missing section %s" % (
                                        constants._user_settings_,
                                        e.section,
@@ -652,10 +684,11 @@ class Dialcentral(object):
                """
                @note Hildon specific
                """
+               RETURN_TYPES = (gtk.keysyms.Return, gtk.keysyms.ISO_Enter, gtk.keysyms.KP_Enter)
                try:
                        if (
                                event.keyval == gtk.keysyms.F6 or
-                               event.keyval == gtk.keysyms.Return and event.get_state() & gtk.gdk.CONTROL_MASK
+                               event.keyval in RETURN_TYPES and event.get_state() & gtk.gdk.CONTROL_MASK
                        ):
                                if self._isFullScreen:
                                        self._window.unfullscreen()