3 import org.maemo.hermes.engine.provider
4 import org.maemo.hermes.engine.twitter.service
5 from org.maemo.hermes.engine.twitter.api import TwitterApi
7 class Provider(org.maemo.hermes.engine.provider.Provider):
8 """Twitter provider for Hermes.
10 Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
11 Released under the Artistic Licence."""
14 # -----------------------------------------------------------------------
16 self._gconf = gnome.gconf.client_get_default()
19 # -----------------------------------------------------------------------
21 """Return the display name of this service. An icon, of with the lower-case,
22 all-alphabetic version of this name is expected to be provided."""
27 # -----------------------------------------------------------------------
28 def has_preferences(self):
29 """Whether or not this provider has any preferences. If it does not,
30 open_preferences must NOT be called; as the behaviour is undetermined."""
35 # -----------------------------------------------------------------------
36 def open_preferences(self, parent):
37 """Show the username/password dialogue."""
39 dialog = gtk.Dialog(self.get_name(), parent)
40 dialog.add_button(_('Disable'), gtk.RESPONSE_NO)
41 enable = dialog.add_button(_('Enable'), gtk.RESPONSE_YES)
46 hbox.pack_start(gtk.Label(_("Username")))
48 username = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
49 username.set_property('is-focus', True)
50 username.set_property('hildon-input-mode', gtk.HILDON_GTK_INPUT_MODE_FULL)
51 username.set_text(self._gconf.get_string("/apps/maemo/hermes/twitter_user") or '')
53 hbox.pack_start(username)
59 hbox.pack_start(gtk.Label(_("Password")))
61 password = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
62 password.set_property('hildon-input-mode', gtk.HILDON_GTK_INPUT_MODE_FULL | gtk.HILDON_GTK_INPUT_MODE_INVISIBLE)
63 password.set_text(self._gconf.get_string("/apps/maemo/hermes/twitter_pwd") or '')
64 hbox.pack_start(password)
67 # -- Enable is only available if both populated...
69 def _check_fields(e, p):
70 enable.set_sensitive(e.get_text() != '' and p.get_text() != '')
71 username.connect('changed', _check_fields, password)
72 password.connect('changed', _check_fields, username)
73 _check_fields(username, password)
75 # -- Run the dialogue...
80 if result == gtk.RESPONSE_CANCEL or result == gtk.RESPONSE_DELETE_EVENT:
83 self._gconf.set_string("/apps/maemo/hermes/twitter_user", username.get_text())
84 self._gconf.set_string("/apps/maemo/hermes/twitter_pwd", password.get_text())
85 return result == gtk.RESPONSE_YES
88 # -----------------------------------------------------------------------
89 def get_account_detail(self):
90 """Return the Twitter username."""
92 return self._gconf.get_string("/apps/maemo/hermes/twitter_user")
95 # -----------------------------------------------------------------------
96 def service(self, gui_callback):
97 """Return the service backend. This must be a class which implements the
103 See Service for more details."""
105 username = self._gconf.get_string("/apps/maemo/hermes/twitter_user") or ''
106 password = self._gconf.get_string("/apps/maemo/hermes/twitter_pwd") or ''
108 api = TwitterApi(username, password)
110 return org.maemo.hermes.engine.twitter.service.Service(self.get_id(), api)