Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
authorAndrew Flegg <andrew@bleb.org>
Tue, 8 Jun 2010 21:53:09 +0000 (22:53 +0100)
committerAndrew Flegg <andrew@bleb.org>
Tue, 8 Jun 2010 21:53:09 +0000 (22:53 +0100)
checking doesn't seem to work, although it's currently hardcoded.

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

index e456bce..ca61849 100644 (file)
@@ -10,8 +10,8 @@ class LinkedInApi():
        Copyright (c) Fredrik Wendt <fredrik@wendt.se> 2010.
        Released under the Artistic Licence."""
        
-    GCONF_API_KEY = '/apps/maemo/hermes/linkedin_api_key'
-    GCONF_API_SECRET = '/apps/maemo/hermes/linkedin_key_secret'
+    GCONF_API_KEY = '/apps/maemo/hermes/linkedin_key'
+    GCONF_API_SECRET = '/apps/maemo/hermes/linkedin_secret'
     GCONF_ACCESS_TOKEN = '/apps/maemo/hermes/linkedin_access_token'
     
     LI_SERVER = "api.linkedin.com"
@@ -38,7 +38,7 @@ class LinkedInApi():
         if api_key is None or secret_key is None:
             raise Exception('No LinkedIn application keys found. Installation error.')
 
-        self.access_token = self._get_access_token_from_gconf()
+        self.access_token = self.get_access_token_from_gconf()
 
         self.consumer = oauth.OAuthConsumer(api_key, secret_key)
         self.sig_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
@@ -211,7 +211,7 @@ class LinkedInApi():
 
         
     # -----------------------------------------------------------------------
-    def _get_access_token_from_gconf(self):
+    def get_access_token_from_gconf(self):
         """Returns an oauth.OAuthToken, or None if the gconf value is empty"""
         
         token_str = self._gc.get_string(LinkedInApi.GCONF_ACCESS_TOKEN)
@@ -222,4 +222,9 @@ class LinkedInApi():
             raise Exception("Authorization failure - access token reported OAuth problem")
         return oauth.OAuthToken.from_string(token_str)
 
-    
+
+    # -----------------------------------------------------------------------
+    def remove_access_token_from_gconf(self):
+        """Remove the oauth.OAuthToken, if any."""
+        
+        self._gc.unset(LinkedInAPI.GCONF_ACCESS_TOKEN)
index 40058ee..f4f871a 100644 (file)
@@ -1,11 +1,22 @@
+import gnome.gconf
+import gobject, gtk, hildon
+import time, thread
 import org.maemo.hermes.engine.provider
 import org.maemo.hermes.engine.linkedin.service
+from org.maemo.hermes.engine.linkedin.api import LinkedInApi
 
 class Provider(org.maemo.hermes.engine.provider.Provider):
     """LinkedIn provider for Hermes. 
 
        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()
+
 
     # -----------------------------------------------------------------------
     def get_name(self):
@@ -27,12 +38,73 @@ 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."
+        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)
+    
+        authenticated = api.get_access_token_from_gconf() is not None 
+        title = authenticated and _("Clear authorisation") or _("Authorise")
+        button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
+                               hildon.BUTTON_ARRANGEMENT_VERTICAL,
+                               title = title)
+        if authenticated:
+            button.connect('clicked', lambda e: api.remove_access_token_from_gconf)
+        else:
+            button.connect('clicked', lambda e: api.authenticate(lambda: None, self.block_for_auth))
+            
+        dialog.vbox.add(gtk.Label(""))
+        dialog.vbox.add(button)
+        dialog.vbox.add(gtk.Label(""))
+        
+        dialog.show_all()
+        result = dialog.run()
+        dialog.hide()
+        if result == gtk.RESPONSE_CANCEL or result == gtk.RESPONSE_DELETE_EVENT:
+            return None
+    
+        return result == gtk.RESPONSE_YES
         # FIXME: do auth:
         # get request token
         # get auth token
         # open browser to have user allow data access
         # user inputs the 5 char  
+        
+        
+    # -----------------------------------------------------------------------
+    def block_for_auth(self, prompt = True, main = False, lock = None):
+        """Part of the GUI callback API."""
+
+        print "Get input:", prompt, main, lock
+        return "12345"
+#        if main:
+#            note = gtk.Dialog(_('Service authorisation'), self.main_window)
+#            note.add_button(_("Validate"), gtk.RESPONSE_OK)
+#            if prompt:
+#                input = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
+#                input.set_property('is-focus', False)
+#                note.set_title(_("Verification code from web browser"))
+#                note.vbox.add(input)
+#            else:
+#                note.vbox.add(gtk.Label(_("\nPress 'Validate' once account has\nbeen authorised in web browser.\n")))
+#    
+#            note.show_all()
+#            result = note.run()
+#            note.hide()
+#            lock.release()
+#            if prompt and result == gtk.RESPONSE_OK:
+#                print input.get_text()
+#                return input.get_text()
+#            else:
+#                return None
+#        
+#        else:
+#            time.sleep(2)
+#            lock = thread.allocate_lock()
+#            lock.acquire()
+#            gobject.idle_add(self.block_for_auth, prompt, True, lock)
+#            lock.acquire()
+#            lock.release()
 
     
     # -----------------------------------------------------------------------

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment