Twitter and LinkedIn providers can only be enabled if suitable
authorAndrew Flegg <andrew@bleb.org>
Tue, 8 Jun 2010 23:20:19 +0000 (00:20 +0100)
committerAndrew Flegg <andrew@bleb.org>
Tue, 8 Jun 2010 23:20:19 +0000 (00:20 +0100)
information is provided. Make sure the UI reflects that.

package/src/org/maemo/hermes/engine/linkedin/provider.py
package/src/org/maemo/hermes/engine/twitter/provider.py

index a25db8b..382a04e 100644 (file)
@@ -50,12 +50,12 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
         api = LinkedInApi(gconf = self._gc) 
         dialog = gtk.Dialog(self.get_name(), parent)
         dialog.add_button(_('Disable'), gtk.RESPONSE_NO)
-        dialog.add_button(_('Enable'), gtk.RESPONSE_YES)
+        enable = dialog.add_button(_('Enable'), gtk.RESPONSE_YES)
     
         button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
                                hildon.BUTTON_ARRANGEMENT_VERTICAL)
-        self._handle_button(None, api, button)
-        button.connect('clicked', self._handle_button, api, button)
+        self._handle_button(None, api, button, enable)
+        button.connect('clicked', self._handle_button, api, button, enable)
             
         dialog.vbox.add(gtk.Label(""))
         dialog.vbox.add(button)
@@ -71,7 +71,7 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
 
 
     # -----------------------------------------------------------------------
-    def _handle_button(self, e, api, button):
+    def _handle_button(self, e, api, button, enable):
         """Ensure the button state is correct."""
         
         authenticated = api.get_access_token_from_gconf() is not None
@@ -84,6 +84,7 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
             authenticated = api.get_access_token_from_gconf() is not None
         
         button.set_title(authenticated and _("Clear authorisation") or _("Authorise"))
+        enable.set_sensitive(authenticated)
 
         
     # -----------------------------------------------------------------------
index 3f2bfab..58386e0 100644 (file)
@@ -38,7 +38,7 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
            
         dialog = gtk.Dialog(self.get_name(), parent)
         dialog.add_button(_('Disable'), gtk.RESPONSE_NO)
-        dialog.add_button(_('Enable'), gtk.RESPONSE_YES)
+        enable = dialog.add_button(_('Enable'), gtk.RESPONSE_YES)
 
         # -- Username...
         #
@@ -48,7 +48,6 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
         username = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
         username.set_property('is-focus', True)
         username.set_property('hildon-input-mode', gtk.HILDON_GTK_INPUT_MODE_FULL)
-        # TODO Connect change signal: if blank, disable "Enable"
         username.set_text(self._gconf.get_string("/apps/maemo/hermes/twitter_user") or '')
 
         hbox.pack_start(username)
@@ -61,11 +60,18 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
         
         password = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
         password.set_property('hildon-input-mode', gtk.HILDON_GTK_INPUT_MODE_FULL | gtk.HILDON_GTK_INPUT_MODE_INVISIBLE)
-        # TODO Connect change signal: if blank, disable "Enable"
         password.set_text(self._gconf.get_string("/apps/maemo/hermes/twitter_pwd") or '')
         hbox.pack_start(password)
         dialog.vbox.add(hbox)
 
+        # -- Enable is only available if both populated...
+        #
+        def _check_fields(e, p):
+            enable.set_sensitive(e.get_text() != '' and p.get_text() != '')
+        username.connect('changed', _check_fields, password)
+        password.connect('changed', _check_fields, username)
+        _check_fields(username, password)
+
         # -- Run the dialogue...
         #
         dialog.show_all()