Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
1 import gnome.gconf
2 import gtk, hildon
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     # -----------------------------------------------------------------------
15     def __init__(self):
16         self._gconf  = gnome.gconf.client_get_default()
19     # -----------------------------------------------------------------------
20     def get_name(self):
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."""
23            
24         return 'Twitter'
25     
26     
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."""
31            
32         return True
33     
34     
35     # -----------------------------------------------------------------------
36     def open_preferences(self, parent):
37         """Show the username/password dialogue."""
38            
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)
43         # -- Username...
44         #
45         hbox = gtk.HBox()
46         hbox.pack_start(gtk.Label(_("Username")))
47         
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)
54         dialog.vbox.add(hbox)
55         
56         # -- Password...
57         #
58         hbox = gtk.HBox()
59         hbox.pack_start(gtk.Label(_("Password")))
60         
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)
65         dialog.vbox.add(hbox)
67         # -- Enable is only available if both populated...
68         #
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...
76         #
77         dialog.show_all()
78         result = dialog.run()
79         dialog.hide()
80         if result == gtk.RESPONSE_CANCEL or result == gtk.RESPONSE_DELETE_EVENT:
81             return None
82  
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."""
91         
92         return self._gconf.get_string("/apps/maemo/hermes/twitter_user")
93     
94     
95     # -----------------------------------------------------------------------
96     def service(self, gui_callback):
97         """Return the service backend. This must be a class which implements the
98            following methods:
99                * get_friends
100                * process_contact
101                * finalise
102         
103            See Service for more details."""
104     
105         username = self._gconf.get_string("/apps/maemo/hermes/twitter_user") or ''
106         password = self._gconf.get_string("/apps/maemo/hermes/twitter_pwd") or ''
107         
108         api = TwitterApi(username, password)
110         return org.maemo.hermes.engine.twitter.service.Service(self.get_id(), api)

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment