2 import gobject, gtk, hildon
5 import org.maemo.hermes.engine.provider
6 import org.maemo.hermes.engine.linkedin.service
7 from org.maemo.hermes.engine.linkedin.api import LinkedInApi
9 class Provider(org.maemo.hermes.engine.provider.Provider):
10 """LinkedIn provider for Hermes.
12 Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
13 Released under the Artistic Licence."""
15 # -----------------------------------------------------------------------
17 """Initialise the provider, and ensure the environment is going to work."""
19 self._gc = gnome.gconf.client_get_default()
22 # -----------------------------------------------------------------------
24 """Return the display name of this service. An icon, of with the lower-case,
25 all-alphabetic version of this name is expected to be provided."""
30 # -----------------------------------------------------------------------
31 def get_account_detail(self):
32 """Return the name of the linked LinkedIn account."""
34 return self._gc.get_string(LinkedInApi.GCONF_USER)
37 # -----------------------------------------------------------------------
38 def has_preferences(self):
39 """Whether or not this provider has any preferences. If it does not,
40 open_preferences must NOT be called; as the behaviour is undetermined."""
45 # -----------------------------------------------------------------------
46 def open_preferences(self, parent):
47 """Open the preferences for this provider as a child of the 'parent' widget."""
49 self.main_window = parent
50 api = LinkedInApi(gconf = self._gc)
51 dialog = gtk.Dialog(self.get_name(), parent)
52 dialog.add_button(_('Disable'), gtk.RESPONSE_NO)
53 dialog.add_button(_('Enable'), gtk.RESPONSE_YES)
55 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
56 hildon.BUTTON_ARRANGEMENT_VERTICAL)
57 self._handle_button(None, api, button)
58 button.connect('clicked', self._handle_button, api, button)
60 dialog.vbox.add(gtk.Label(""))
61 dialog.vbox.add(button)
62 dialog.vbox.add(gtk.Label(""))
67 if result == gtk.RESPONSE_CANCEL or result == gtk.RESPONSE_DELETE_EVENT:
70 return result == gtk.RESPONSE_YES
73 # -----------------------------------------------------------------------
74 def _handle_button(self, e, api, button):
75 """Ensure the button state is correct."""
77 authenticated = api.get_access_token_from_gconf() is not None
80 api.remove_access_token_from_gconf()
82 api.authenticate(lambda: None, self.block_for_auth)
84 authenticated = api.get_access_token_from_gconf() is not None
86 button.set_title(authenticated and _("Clear authorisation") or _("Authorise"))
89 # -----------------------------------------------------------------------
90 def block_for_auth(self, url):
91 """Part of the GUI callback API."""
95 note = gtk.Dialog(_('Service authorisation'), self.main_window)
96 note.add_button(_("Validate"), gtk.RESPONSE_OK)
97 input = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
98 input.set_property('is-focus', False)
99 note.set_title(_("Verification code from web browser"))
105 if result == gtk.RESPONSE_OK:
106 return input.get_text()
111 # -----------------------------------------------------------------------
112 def service(self, gui_callback):
113 """Return the service backend."""
115 return org.maemo.hermes.engine.linkedin.service.Service()