3 import org.maemo.hermes.engine.provider
4 import org.maemo.hermes.engine.twitter.service
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 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 # TODO Connect change signal: if blank, disable "Enable"
52 username.set_text(self._gconf.get_string("/apps/maemo/hermes/twitter_user") or '')
54 hbox.pack_start(username)
60 hbox.pack_start(gtk.Label(_("Password")))
62 password = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
63 password.set_property('hildon-input-mode', gtk.HILDON_GTK_INPUT_MODE_FULL | gtk.HILDON_GTK_INPUT_MODE_INVISIBLE)
64 # TODO Connect change signal: if blank, disable "Enable"
65 password.set_text(self._gconf.get_string("/apps/maemo/hermes/twitter_pwd") or '')
66 hbox.pack_start(password)
69 # -- Run the dialogue...
74 if result == gtk.RESPONSE_CANCEL or result == gtk.RESPONSE_DELETE_EVENT:
77 self._gconf.set_string("/apps/maemo/hermes/twitter_user", username.get_text())
78 self._gconf.set_string("/apps/maemo/hermes/twitter_pwd", password.get_text())
79 return result == gtk.RESPONSE_YES
82 # -----------------------------------------------------------------------
83 def get_account_detail(self):
84 """Return the Twitter username."""
86 return self._gconf.get_string("/apps/maemo/hermes/twitter_user")
89 # -----------------------------------------------------------------------
90 def service(self, gui_callback):
91 """Return the service backend. This must be a class which implements the
97 See Service for more details."""
99 username = self._gconf.get_string("/apps/maemo/hermes/twitter_user") or ''
100 password = self._gconf.get_string("/apps/maemo/hermes/twitter_pwd") or ''
102 api = twitter.Api(username=username, password=password)
104 return org.maemo.hermes.engine.twitter.service.Service(username, password, gui_callback)