8 from org.bleb.wimpworks import WimpWorks
9 from org.maemo.hermes.gui.contactview import ContactView
10 from org.maemo.hermes.gui.mapcontact import MapContact
11 from org.maemo.hermes.gui.accountsdialogue import AccountsDialogue
12 from org.bleb.wimpworks import HildonMainScreenLayout
13 from org.maemo.hermes.engine.syncjob import SyncJob
14 #from hermes import Hermes ### FIXME This needs to be new
16 class HermesGUI(WimpWorks):
17 """Provides the GUI for Hermes, allowing the syncing of Facebook and
18 Twitter friends' information with the Evolution contacts' database.
20 Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
21 Released under the Artistic Licence."""
24 # -----------------------------------------------------------------------
25 def __init__(self, providers = None):
26 gettext.install('hermes','/opt/hermes/share/locale/')
27 WimpWorks.__init__(self, 'Hermes', version = '0.9.0', dbus_name = 'org.maemo.hermes')
28 self.set_background('background.png')
30 layout = HildonMainScreenLayout(offset = 0.8, container = self)
31 layout.add_button('Retrieve', _("Get contacts' missing info"))
32 layout.add_button('Refresh', _("Update contacts' info"))
34 self.add_menu_action("Accounts")
37 self.providers = providers
38 self.progressnote = None
41 # -----------------------------------------------------------------------
42 def do_retrieve(self, widget):
43 self.sync(widget, False)
46 # -----------------------------------------------------------------------
47 def do_refresh(self, widget):
48 self.sync(widget, True)
51 # -----------------------------------------------------------------------
52 def do_accounts(self, widget = None):
53 dialog = AccountsDialogue(self.main_window, self.providers)
57 # -----------------------------------------------------------------------
58 def sync(self, widget, force, main = True):
60 for provider in self.providers:
61 if self.gconf.get_bool('/apps/maemo/hermes/use_%s' % (provider.get_id())):
62 enabled.append(provider)
64 if main and len(enabled) == 0:
65 saved = self.do_accounts()
66 if saved == gtk.RESPONSE_DELETE_EVENT:
70 self.main_window.set_property('sensitive', False)
71 thread.start_new_thread(self.sync, (widget, force, False))
75 for provider in enabled:
76 services.append(provider.service(self))
81 return "Fredrik Wendt"
83 return ["fredrik@wendt.se","maemohermes@wendt.se"]
84 self._sync_job = SyncJob(services, [FakeContact()], self.progress)
86 self._sync_job.get_unmatched_friends()
87 self._sync_job.get_updated_contacts()
88 self._sync_job.get_matched_contacts()
89 raise Exception("TODO - implement syncing")
91 except urllib2.HTTPError, e:
94 gobject.idle_add(self.report_error, _('Authentication problem. Check credentials.'), True)
96 gobject.idle_add(self.report_error, _('Network connection error. Check connectivity.'))
98 except urllib2.URLError, e:
100 gobject.idle_add(self.report_error, _('Network connection error. Check connectivity.'))
103 traceback.print_exc()
104 gobject.idle_add(self.report_error, _('Something went wrong: ') + e.message)
107 # -----------------------------------------------------------------------
108 def open_summary(self, fb2c):
109 gobject.idle_add(self.main_window.set_property, 'sensitive', True)
111 dialog = gtk.Dialog(_('Summary'), self.main_window)
112 dialog.add_button(_('Done'), gtk.RESPONSE_OK)
114 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
115 title = _('Updated %d contacts') % (len(fb2c.updated)))
116 button.connect('clicked', self.show_contacts, fb2c, fb2c.updated)
117 button.set_property('sensitive', len(fb2c.updated) > 0)
118 dialog.vbox.add(button)
120 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
121 title = _('Matched %d contacts') % (len(fb2c.matched)))
122 button.connect('clicked', self.show_contacts, fb2c, fb2c.matched)
123 button.set_property('sensitive', len(fb2c.matched) > 0)
124 dialog.vbox.add(button)
126 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
127 title = _('%d contacts unmatched') % (len(fb2c.unmatched)))
128 button.connect('clicked', self.show_contacts, fb2c, fb2c.unmatched)
129 button.set_property('sensitive', len(fb2c.unmatched) > 0)
130 dialog.vbox.add(button)
137 # -----------------------------------------------------------------------
138 def show_contacts(self, widget, fb2c, contacts):
139 view = ContactView(contacts)
141 dialog = gtk.Dialog(_('Contacts'), self.main_window)
142 view.connect('contact-activated', self.map_contact, fb2c)
143 dialog.vbox.add(view)
150 # -----------------------------------------------------------------------
151 def map_contact(self, widget, contact, fb2c):
152 view = MapContact(fb2c.friends, contact)
154 dialog = gtk.Dialog(contact.get_name(), self.main_window)
155 dialog.add_button(_('Update'), gtk.RESPONSE_OK)
156 dialog.vbox.add(view)
159 result = dialog.run()
161 if result == gtk.RESPONSE_OK:
162 friend = view.get_selected_friend()
164 if 'contact' in friend and friend['contact'] == contact:
165 hildon.hildon_banner_show_information(self.main_window, '', _("Removing existing mappings is not yet supported"))
166 elif view.contact_mapped:
167 if fb2c.update_contact(contact, friend, True):
168 fb2c.addresses.commit_contact(contact)
170 if fb2c.update_contact(contact, friend, False):
171 fb2c.addresses.commit_contact(contact)
174 # -----------------------------------------------------------------------
175 def need_auth(self, main = False):
176 """Part of the GUI callback API."""
179 hildon.hildon_banner_show_information(self.main_window, '', _("Need to authenticate via browser"))
181 gobject.idle_add(self.need_auth, True)
184 # -----------------------------------------------------------------------
185 def block_for_auth(self, prompt = False, main = False, lock = None):
186 """Part of the GUI callback API."""
189 note = gtk.Dialog(_('Service authorisation'), self.main_window)
190 note.add_button(_("Validate"), gtk.RESPONSE_OK)
192 input = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
193 input.set_placeholder(_("Verification code from web browser"))
194 input.set_property('is-focus', False)
197 note.vbox.add(gtk.Label(_("\nPress 'Validate' once account has\nbeen authorised in web browser.\n")))
203 if prompt and result == gtk.RESPONSE_OK:
204 return input.get_text()
210 lock = thread.allocate_lock()
212 gobject.idle_add(self.block_for_auth, prompt, True, lock)
217 # -----------------------------------------------------------------------
218 def progress(self, i, j, main = False):
219 """Part of the GUI callback API."""
223 self.progressbar = gtk.ProgressBar()
224 self.progressnote = gtk.Dialog(_("Fetching friends' info"), self.main_window)
225 self.progressnote.vbox.add(self.progressbar)
226 hildon.hildon_gtk_window_set_progress_indicator(self.progressnote, 1)
228 self.progressnote.show_all()
232 self.progressnote.set_title(_("Updating contacts"))
233 hildon.hildon_gtk_window_set_progress_indicator(self.progressnote, 0)
235 self.progressbar.set_fraction(float(i) / float(j))
238 self.progressnote.destroy()
242 gobject.idle_add(self.progress, i, j, True)
245 # -----------------------------------------------------------------------
246 def report_error(self, e, prefs = False):
247 if self.progressnote:
248 self.main_window.set_property('sensitive', True)
249 self.progressnote.destroy()
251 hildon.hildon_banner_show_information(self.main_window, '', e)