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()
20 self._api = LinkedInApi(gconf = self._gc)
23 # -----------------------------------------------------------------------
25 """Return the display name of this service. An icon, of with the lower-case,
26 all-alphabetic version of this name is expected to be provided."""
31 # -----------------------------------------------------------------------
32 def get_account_detail(self):
33 """Return the name of the linked LinkedIn account."""
35 return self._gc.get_string(LinkedInApi.GCONF_USER)
38 # -----------------------------------------------------------------------
39 def has_preferences(self):
40 """Whether or not this provider has any preferences. If it does not,
41 open_preferences must NOT be called; as the behaviour is undetermined."""
46 # -----------------------------------------------------------------------
47 def open_preferences(self, parent):
48 """Open the preferences for this provider as a child of the 'parent' widget."""
50 self.main_window = parent
51 dialog = gtk.Dialog(self.get_name(), parent)
52 dialog.add_button(_('Disable'), gtk.RESPONSE_NO)
53 enable = 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, button, enable)
58 button.connect('clicked', self._handle_button, button, enable)
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, button, enable):
75 """Ensure the button state is correct."""
77 authenticated = self._api.get_access_token_from_gconf() is not None
80 self._api.remove_access_token_from_gconf()
82 self._api.authenticate(lambda: None, self.block_for_auth)
84 authenticated = self._api.get_access_token_from_gconf() is not None
86 button.set_title(authenticated and _("Clear authorisation") or _("Authorise"))
87 enable.set_sensitive(authenticated)
90 # -----------------------------------------------------------------------
91 def block_for_auth(self, url):
92 """Part of the GUI callback API."""
96 note = gtk.Dialog(_('Service authorisation'), self.main_window)
97 note.add_button(_("Validate"), gtk.RESPONSE_OK)
98 input = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
99 input.set_property('is-focus', False)
100 input.set_property('hildon-input-mode', gtk.HILDON_GTK_INPUT_MODE_NUMERIC)
101 note.set_title(_("Verification code from web browser"))
107 if result == gtk.RESPONSE_OK:
108 return input.get_text()
113 # -----------------------------------------------------------------------
114 def service(self, gui_callback):
115 """Return the service backend."""
117 return org.maemo.hermes.engine.linkedin.service.Service(self.get_id(), self._api)