Freeze break request: Deskbar Applet



Hi Release team,

A request to break UI freeze from the Deskbar team.

Case in point: Our new identi.ca module does not support OpenId
(regretably) and users try to enter OpenIds into the standard
credentials dialog.

Solution: Add a note in the credentials dialog. This breaks UI and
adds two new strings.

Tracker bug: http://bugzilla.gnome.org/show_bug.cgi?id=550297

Approvals: sebp (maintainer) and i18n

-- 
Cheers,
Mikkel
Index: deskbar/handlers/twitter.py
===================================================================
--- deskbar/handlers/twitter.py	(revision 2377)
+++ deskbar/handlers/twitter.py	(working copy)
@@ -51,13 +51,21 @@
     """
     A factory to help instantiating C{TwitterClient}s.
     """
-    def __init__ (self, domain="twitter.com", update_url=TWITTER_UPDATE_URL, realm="Twitter API"):
+    def __init__ (self,
+                  domain="twitter.com",
+                  update_url=TWITTER_UPDATE_URL,
+                  realm="Twitter API",
+                  extra_widget_factory=None):
         self._domain = domain
         self._update_url = update_url
         self._realm = realm
+        self._extra_widget_factory = extra_widget_factory
     
     def create_client (self):
-        return TwitterClient(domain=self._domain, update_url=self._update_url, realm=self._realm)
+        return TwitterClient(domain=self._domain,
+                             update_url=self._update_url,
+                             realm=self._realm,
+                             extra_widget_factory=self._extra_widget_factory)
         
 class TwitterClient :
     """
@@ -68,9 +76,14 @@
                      use the TwitterClientFactory and create a new TwitterClient
                      instance each time you need it
     """
-    def __init__ (self, domain="twitter.com", update_url=TWITTER_UPDATE_URL, realm="Twitter API"):
+    def __init__ (self,
+                  domain="twitter.com",
+                  update_url=TWITTER_UPDATE_URL,
+                  realm="Twitter API",
+                  extra_widget_factory=None):
         self._account = Account (domain, realm)
-        self._opener = GnomeURLopener (self._account)
+        self._opener = GnomeURLopener (self._account,
+                                       extra_widget_factory=extra_widget_factory)
         self._thread = None
         self._update_url = update_url
         self._domain = domain
@@ -200,7 +213,13 @@
              'description': _("Post updates to your Twitter account"),
              'version': VERSION}
     
-    def __init__(self, domain="twitter.com", service="Twitter", pixbuf=None, update_url=TWITTER_UPDATE_URL, realm="Twitter API"):
+    def __init__(self,
+                 domain="twitter.com",
+                 service="Twitter",
+                 pixbuf=None,
+                 update_url=TWITTER_UPDATE_URL,
+                 realm="Twitter API",
+                 extra_widget_factory=None):
         global _twitter_pixbuf
         
         deskbar.interfaces.Module.__init__(self)
@@ -214,7 +233,8 @@
         
         self._client_factory = TwitterClientFactory(domain=self._domain,
                                                     update_url=update_url,
-                                                    realm=self._realm)
+                                                    realm=self._realm,
+                                                    extra_widget_factory=self.get_extra_account_dialog_widget)
     
     def query(self, qstring):
         if len (qstring) <= MIN_MESSAGE_LEN and \
@@ -234,6 +254,12 @@
         account = Account (self._domain, self._realm)
         LOGGER.debug ("Showing config")
         login_dialog = AccountDialog(account, dialog_parent=parent)
+        
+        # Pack optional widget if appropriate
+        extra_widget = self.get_extra_account_dialog_widget ()
+        if extra_widget != None:
+            login_dialog.vbox.pack_start (extra_widget)
+        
         login_dialog.show_all()
         login_dialog.run()            
         login_dialog.destroy()
@@ -241,6 +267,16 @@
     def get_domain (self):
         return self._domain
     
+    def get_extra_account_dialog_widget (self):
+        """
+        This method should return a C{gtk.Widget} or C{None}. If it returns
+        a widget that widget will be packed into the L{AccountDialog} spawned
+        by the underlying url opener.
+        
+        The default implementation simply returns C{None}
+        """
+        return None
+    
 class IdenticaModule(TwitterModule):
     
     INFOS = {'icon': _identica_pixbuf,
@@ -255,4 +291,14 @@
                                pixbuf=_identica_pixbuf,
                                update_url=IDENTICA_UPDATE_URL,
                                realm="Laconica API")
-
+    
+    def get_extra_account_dialog_widget (self):
+        vbox = gtk.VBox()
+        label = gtk.Label()
+        label.set_markup (_("Please note that Deskbar Applet does not support authentication via OpenId. You must configure a username and password on the <i>identi.ca</i> website if you haven't already."))
+        label.set_line_wrap(True)
+        button = gtk.LinkButton ("http://identi.ca";, _("Visit identi.ca website"))
+        vbox.pack_start (label)
+        vbox.pack_start (button)
+        return vbox
+    
Index: deskbar/core/Utils.py
===================================================================
--- deskbar/core/Utils.py	(revision 2377)
+++ deskbar/core/Utils.py	(working copy)
@@ -228,6 +228,9 @@
         if resp == gtk.RESPONSE_CLOSE:
             message_dialog.destroy()
 
+# Make gtk.LinkButtons call url_show()
+gtk.link_button_set_uri_hook (lambda button, url : url_show(url))
+
 def get_proxy():
     # TODO: Very dirty, should use CoreImpl class
     deskbarapplet = GconfStore.get_instance()
Index: deskbar/core/Web.py
===================================================================
--- deskbar/core/Web.py	(revision 2377)
+++ deskbar/core/Web.py	(working copy)
@@ -223,7 +223,16 @@
         "done" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
     }
     
-    def __init__ (self, account):
+    def __init__ (self, account, extra_widget_factory=None):
+        """
+        @param account: The L{Account} object to request credentials from
+        @param extra_widget_factory: This optional parameter may point to a
+                                     C{callable} returning a C{gtk.Widget} which
+                                     will be packed into the L{AccountDialog}
+                                     when it is spawned. The callable may also
+                                     return C{None} if no widgets should be
+                                     added.
+        """
         proxies = get_proxy()
         urllib.FancyURLopener.__init__ (self, proxies)
         gobject.GObject.__init__ (self)
@@ -231,6 +240,7 @@
         self._thread = None
         self._authentication_retries = 0
         self._success = True
+        self._extra_widget_factory = extra_widget_factory
         
         LOGGER.debug ("Using proxies: %s" % proxies)
         
@@ -253,6 +263,9 @@
                                          dialog_type=gtk.MESSAGE_WARNING)
             login_dialog.set_markup (_("<big><b>Login to %s rejected</b></big>") % self._account.get_host())
             login_dialog.format_secondary_markup (_("Please verify your credentials for <b>%s</b>") % self._account.get_host())
+            
+            self._install_extra_widget (login_dialog)
+            
             login_dialog.show_all()
             login_dialog.run()            
             login_dialog.destroy()
@@ -267,6 +280,9 @@
             LOGGER.debug ("No credentials for %s in keyring. Asking for them..." %
                           self._account.get_host())
             login_dialog = AccountDialog(self._account)
+            
+            self._install_extra_widget (login_dialog)
+            
             login_dialog.show_all()
             login_dialog.run()            
             login_dialog.destroy()
@@ -281,6 +297,20 @@
         
         return creds
     
+    def _install_extra_widget (self, login_dialog):
+        """
+        Install the extra widget returned by the extra_widget_factory into
+        login_dialog, if applicable
+        """
+        if callable(self._extra_widget_factory):
+                widget = self._extra_widget_factory()
+                if widget != None:
+                    if isinstance (widget, gtk.Widget):
+                        login_dialog.vbox.pack_start (widget)
+                    else:
+                        # The factory returned a non-None non-widget object
+                        LOGGER.error ("%s returned a non-gtk.Widget instance: %s" % (self._extra_widget_factory, type(widget)))
+    
     def open_async (self, url, payload=None):
         """
         Open a URL asynchronously. When the request has been completed the


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]