Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
authorAndrew Flegg <andrew@bleb.org>
Sun, 6 Jun 2010 19:48:33 +0000 (20:48 +0100)
committerAndrew Flegg <andrew@bleb.org>
Sun, 6 Jun 2010 19:48:33 +0000 (20:48 +0100)
remove Twitter from having preferences (we'll be OAuth based) and
general code tidy-up.

package/debian/hermes.postinst
package/src/org/maemo/hermes/engine/facebook/provider.py
package/src/org/maemo/hermes/engine/friend.py
package/src/org/maemo/hermes/engine/gravatar/provider.py
package/src/org/maemo/hermes/engine/gravatar/service.py
package/src/org/maemo/hermes/engine/service.py
package/src/org/maemo/hermes/engine/twitter/provider.py
package/src/org/maemo/hermes/gui/accountsdialogue.py
package/src/org/maemo/hermes/gui/gtkui.py

index aa2d4f3..69b5b56 100644 (file)
@@ -1,8 +1,11 @@
 #!/bin/sh
 
 set -e
-gconftool-2 -s /apps/maemo/hermes/key_app 5916f12942feea4b3247d42a84371112 --type string
-gconftool-2 -s /apps/maemo/hermes/key_secret 19f7538edd96b6870f2da7e84a6390a4 --type string
+gconftool-2 -s /apps/maemo/hermes/facebook_app 5916f12942feea4b3247d42a84371112 --type string
+gconftool-2 -s /apps/maemo/hermes/facebook_secret 19f7538edd96b6870f2da7e84a6390a4 --type string
+gconftool-2 -s /apps/maemo/hermes/gravatar_email TODO --type string
+gconftool-2 -s /apps/maemo/hermes/gravatar_key TODO --type string
+
 
 # Version 0.2.1 changed type of /apps/maemo/hermes/uid
 OLD_UID=`gconftool-2 -g /apps/maemo/hermes/uid`
index 56e3f17..2ecd843 100644 (file)
@@ -1,5 +1,6 @@
 from facebook import Facebook, FacebookError
 import gnome.gconf
+import gtk, hildon
 import org.maemo.hermes.engine.provider
 import org.maemo.hermes.engine.facebook.service
 
@@ -7,18 +8,51 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
     """Facebook provider for Hermes. 
 
        This requires two gconf paths to contain Facebook application keys:
-           /apps/maemo/hermes/key_app
-           /apps/maemo/hermes/key_secret
+           /apps/maemo/hermes/facebook_app
+           /apps/maemo/hermes/facebook_secret
        
        Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
        Released under the Artistic Licence."""
 
     # -----------------------------------------------------------------------
+    def __init__(self):
+        """Initialise the provider, and ensure the environment is going to work."""
+
+        self._gc = gnome.gconf.client_get_default()
+        if (self._gc.get_string('/desktop/gnome/url-handlers/http/command') == 'epiphany %s'):
+            raise Exception('Browser in gconf invalid (see NB#136012). Installation error.')
+
+        key_app    = self._gc.get_string('/apps/maemo/hermes/facebook_app')
+        key_secret = self._gc.get_string('/apps/maemo/hermes/facebook_secret')
+        if key_app is None or key_secret is None:
+            raise Exception('No Facebook application keys found. Installation error.')
+        
+        self.fb = Facebook(key_app, key_secret)
+        self.fb.desktop = True
+
+        if self.fb.session_key is None:
+            self.fb.session_key = self._gc.get_string('/apps/maemo/hermes/facebook_session_key')
+            self.fb.secret = self._gc.get_string('/apps/maemo/hermes/facebook_secret_key')
+            self.fb.uid = self._gc.get_string('/apps/maemo/hermes/facebook_uid')
+
+
+    # -----------------------------------------------------------------------
     def get_name(self):
         """Return the display name of this service. An icon, of with the lower-case,
            all-alphabetic version of this name is expected to be provided."""
            
         return 'Facebook'
+
+    
+    # -----------------------------------------------------------------------
+    def get_account_detail(self):
+        """Return the email address associated with the user, if available."""
+        
+#        if self.fb.users.getLoggedInUser() and self.fb.session_key:
+#            info = self.fb.users.getInfo([self.fb.uid], ['name'])
+#            return info['name']
+#        else:
+        return '---'
     
     
     # -----------------------------------------------------------------------
@@ -33,28 +67,41 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
     def open_preferences(self, parent):
         """Open the preferences for this provider as a child of the 'parent' widget."""
 
-        print "Err, open preferences. OK. Err, right. Hmm."
+        dialog = gtk.Dialog(self.get_name(), parent)
+        dialog.add_button(_('Clear'), gtk.RESPONSE_OK)
+        dialog.add_button(_('Disable'), gtk.RESPONSE_NO)
+        dialog.add_button(_('Enable'), gtk.RESPONSE_YES)
+        
+        dialog.vbox.add(gtk.Label(_('Note: authentication via web page')))
         
+        checkbox = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
+        checkbox.set_label(_('Create birthday-only contacts'))
+        checkbox.set_active(self._gc.get_bool('/apps/maemo/hermes/facebook_birthday_only'))
+        dialog.vbox.add(checkbox)
+        dialog.vbox.add(gtk.Label(''))
         
+        while True:
+            dialog.show_all()
+            result = dialog.run()
+            dialog.hide()
+            if result == gtk.RESPONSE_CANCEL:
+                return None
+            elif result == gtk.RESPONSE_OK:
+                self._gc.set_string('/apps/maemo/hermes/facebook_session_key', '')
+                self._gc.set_string('/apps/maemo/hermes/facebook_secret_key', '')
+                self._gc.set_string('/apps/maemo/hermes/facebook_uid', '')
+            else:
+                break
+    
+        self._gc.set_bool('/apps/maemo/hermes/facebook_birthday_only', checkbox.get_active())
+        return result == gtk.RESPONSE_YES
+        
+    
     # -----------------------------------------------------------------------
-    def prepare_service(self):
-        # -- Check the environment is going to work...
-        #
-        if (self._gc.get_string('/desktop/gnome/url-handlers/http/command') == 'epiphany %s'):
-            raise Exception('Browser in gconf invalid (see NB#136012). Installation error.')
-
-        key_app    = self._gc.get_string('/apps/maemo/hermes/key_app')
-        key_secret = self._gc.get_string('/apps/maemo/hermes/key_secret')
-        if key_app is None or key_secret is None:
-            raise Exception('No Facebook application keys found. Installation error.')
+    def service(self, gui_callback):
+        """Return a service instance."""
         
-        self.fb = Facebook(key_app, key_secret)
-        self.fb.desktop = True
-
-        if self.fb.session_key is None:
-            self.fb.session_key = self._gc.get_string('/apps/maemo/hermes/session_key')
-            self.fb.secret = self._gc.get_string('/apps/maemo/hermes/secret_key')
-            self.fb.uid = self._gc.get_string('/apps/maemo/hermes/uid')
+        self._gui = gui_callback
         
         # Check the available session is still valid...
         while True:
@@ -65,10 +112,6 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
                 pass
             self._do_fb_login()
 
-
-    
-    # -----------------------------------------------------------------------
-    def service(self, gui_callback):
         return org.maemo.hermes.engine.facebook.service.Service(self.fb)
 
 
@@ -93,6 +136,6 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
             self._gui.block_for_auth()
           
         session = self.fb.auth.getSession()
-        self._gc.set_string('/apps/maemo/hermes/session_key', session['session_key'])
-        self._gc.set_string('/apps/maemo/hermes/secret_key', session['secret'])
-        self._gc.set_string('/apps/maemo/hermes/uid', str(session['uid']))
+        self._gc.set_string('/apps/maemo/hermes/facebook_session_key', session['session_key'])
+        self._gc.set_string('/apps/maemo/hermes/facebook_secret_key', session['secret'])
+        self._gc.set_string('/apps/maemo/hermes/facebook_uid', str(session['uid']))
index 1a1f58c..fadd586 100644 (file)
@@ -1,4 +1,9 @@
 class Friend():
+    """Encapsulate the data from a remote service.
+    
+       Copyright (c) Fredrik Wendt <fredrik@wendt.se> 2010.
+       Released under the Artistic Licence."""
+
     
     def __init__(self, name, source=None):
         """ source is source service, such as LinkedIn """
index 224954d..4627c28 100644 (file)
@@ -28,20 +28,13 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
            open_preferences must NOT be called; as the behaviour is undetermined."""
            
         return False
-    
-    
-    # -----------------------------------------------------------------------
-    def open_preferences(self, parent):
-        """Open the preferences for this provider as a child of the 'parent' widget."""
-
-        print "Err, open preferences. OK. Err, right. Hmm."
 
     
     # -----------------------------------------------------------------------
     def service(self, gui_callback):
         """Return the service backend"""
 
-        self._api_email = self._gconf.get_string('/apps/maemo/hermes/gravatar_api_email')
-        self._api_key = self._gconf.get_string('/apps/maemo/hermes/gravatar_api_key')
+        api_email = self._gconf.get_string('/apps/maemo/hermes/gravatar_email')
+        api_key = self._gconf.get_string('/apps/maemo/hermes/gravatar_key')
 
-        return org.maemo.hermes.engine.gravatar.service.Service()
+        return org.maemo.hermes.engine.gravatar.service.Service(api_email, api_key)
index c7d4e80..cccc676 100644 (file)
@@ -11,10 +11,10 @@ class Service(org.maemo.hermes.engine.service.Service):
        
     # -----------------------------------------------------------------------
     def __init__(self, api_email, api_key):
-        """Initialise the Gravatar service
+        """Initialise the Gravatar service.
         
         api_email is the email address to use when talking to the backend.
-        api_key is the "secrect" key used when talking to the backend
+        api_key is the "secret" key used when talking to the backend
         """
         self._api_email = api_email
         self._api_key = api_key
index 6adcc60..2f519cd 100644 (file)
@@ -64,4 +64,4 @@ class Service:
     def _create_friend(self, name):
         """Used to create a Friend object for a contact"""
         
-        return Friend(name, self.get_name())
+        return Friend(name)
index 93a3e03..777faeb 100644 (file)
@@ -28,14 +28,7 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
         """Whether or not this provider has any preferences. If it does not,
            open_preferences must NOT be called; as the behaviour is undetermined."""
            
-        return True
-    
-    
-    # -----------------------------------------------------------------------
-    def open_preferences(self, parent):
-        """Open the preferences for this provider as a child of the 'parent' widget."""
-
-        print "Err, open preferences. OK. Err, right. Hmm."
+        return False # Going to use OAuth...
 
     
     # -----------------------------------------------------------------------
index fd52fc3..2ee2c25 100644 (file)
@@ -81,6 +81,7 @@ class AccountsDialogue:
         dialog.vbox.add(parea)
         dialog.show_all()
         dialog.run() # We actually always Save. Bad, I know.
+        dialog.hide()
 
 
     # -----------------------------------------------------------------------
index f3fcce3..c1a605c 100644 (file)
@@ -70,6 +70,11 @@ class HermesGUI(WimpWorks):
             thread.start_new_thread(self.sync, (widget, force, False))
         else:
             try:
+                services = []
+                for provider in enabled:
+                    services.append(provider.service(self))
+                    
+                print services
                 raise Exception("TODO - implement syncing")
         
             except urllib2.HTTPError, e:
@@ -153,10 +158,45 @@ class HermesGUI(WimpWorks):
                 else:
                     if fb2c.update_contact(contact, friend, False):
                         fb2c.addresses.commit_contact(contact)
+    
                         
+    # -----------------------------------------------------------------------
+    def need_auth(self, main = False):
+        """Part of the GUI callback API."""
+        
+        if main:
+            hildon.hildon_banner_show_information(self.main_window, '', _("Need to authenticate with Facebook"))
+        else:
+            gobject.idle_add(self.need_auth, True)
+      
+    
+    # -----------------------------------------------------------------------
+    def block_for_auth(self, main = False, lock = None):
+        """Part of the GUI callback API."""
+
+        if main:
+            note = gtk.Dialog(_('Facebook authorisation'), self.main_window)
+            note.add_button(_("Validate"), gtk.RESPONSE_OK)
+            note.vbox.add(gtk.Label(_("\nPress 'Validate' once Facebook has\nbeen authenticated in web browser.\n")))
+    
+            note.show_all()
+            result = note.run()
+            note.hide()
+            lock.release()
+        
+        else:
+            time.sleep(2)
+            lock = thread.allocate_lock()
+            lock.acquire()
+            gobject.idle_add(self.block_for_auth, True, lock)
+            lock.acquire()
+            lock.release()
+                      
                         
     # -----------------------------------------------------------------------
     def progress(self, i, j, main = False):
+        """Part of the GUI callback API."""
+
         if main:
             if i == 0:
                 self.progressbar = gtk.ProgressBar()

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment