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 hermes import Hermes ### FIXME This needs to be new
15 class HermesGUI(WimpWorks):
16 """Provides the GUI for Hermes, allowing the syncing of Facebook and
17 Twitter friends' information with the Evolution contacts' database.
19 Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
20 Released under the Artistic Licence."""
23 # -----------------------------------------------------------------------
24 def __init__(self, providers = None):
25 gettext.install('hermes','/opt/hermes/share/locale/')
26 WimpWorks.__init__(self, 'Hermes', version = '0.9.0', dbus_name = 'org.maemo.hermes')
27 self.set_background('background.png')
29 layout = HildonMainScreenLayout(offset = 0.8, container = self)
30 layout.add_button('Retrieve', _("Get contacts' missing info"))
31 layout.add_button('Refresh', _("Update contacts' info"))
33 self.add_menu_action("Accounts")
36 self.providers = providers
37 self.progressnote = None
40 # -----------------------------------------------------------------------
41 def do_retrieve(self, widget):
42 self.sync(widget, False)
45 # -----------------------------------------------------------------------
46 def do_refresh(self, widget):
47 self.sync(widget, True)
50 # -----------------------------------------------------------------------
51 def do_accounts(self, widget = None):
52 dialog = AccountsDialogue(self.main_window, self.providers)
56 # -----------------------------------------------------------------------
57 def sync(self, widget, force, main = True):
59 for provider in self.providers:
60 if self.gconf.get_bool('/apps/maemo/hermes/use_%s' % (provider.get_id())):
61 enabled.append(provider)
63 if main and len(enabled) == 0:
64 saved = self.do_accounts()
65 if saved == gtk.RESPONSE_DELETE_EVENT:
69 self.main_window.set_property('sensitive', False)
70 thread.start_new_thread(self.sync, (widget, force, False))
73 raise Exception("TODO - implement syncing")
75 except urllib2.HTTPError, e:
78 gobject.idle_add(self.report_error, _('Authentication problem. Check credentials.'), True)
80 gobject.idle_add(self.report_error, _('Network connection error. Check connectivity.'))
82 except urllib2.URLError, e:
84 gobject.idle_add(self.report_error, _('Network connection error. Check connectivity.'))
88 gobject.idle_add(self.report_error, _('Something went wrong: ') + e.message)
91 # -----------------------------------------------------------------------
92 def open_summary(self, fb2c):
93 gobject.idle_add(self.main_window.set_property, 'sensitive', True)
95 dialog = gtk.Dialog(_('Summary'), self.main_window)
96 dialog.add_button(_('Done'), gtk.RESPONSE_OK)
98 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
99 title = _('Updated %d contacts') % (len(fb2c.updated)))
100 button.connect('clicked', self.show_contacts, fb2c, fb2c.updated)
101 button.set_property('sensitive', len(fb2c.updated) > 0)
102 dialog.vbox.add(button)
104 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
105 title = _('Matched %d contacts') % (len(fb2c.matched)))
106 button.connect('clicked', self.show_contacts, fb2c, fb2c.matched)
107 button.set_property('sensitive', len(fb2c.matched) > 0)
108 dialog.vbox.add(button)
110 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
111 title = _('%d contacts unmatched') % (len(fb2c.unmatched)))
112 button.connect('clicked', self.show_contacts, fb2c, fb2c.unmatched)
113 button.set_property('sensitive', len(fb2c.unmatched) > 0)
114 dialog.vbox.add(button)
121 # -----------------------------------------------------------------------
122 def show_contacts(self, widget, fb2c, contacts):
123 view = ContactView(contacts)
125 dialog = gtk.Dialog(_('Contacts'), self.main_window)
126 view.connect('contact-activated', self.map_contact, fb2c)
127 dialog.vbox.add(view)
134 # -----------------------------------------------------------------------
135 def map_contact(self, widget, contact, fb2c):
136 view = MapContact(fb2c.friends, contact)
138 dialog = gtk.Dialog(contact.get_name(), self.main_window)
139 dialog.add_button(_('Update'), gtk.RESPONSE_OK)
140 dialog.vbox.add(view)
143 result = dialog.run()
145 if result == gtk.RESPONSE_OK:
146 friend = view.get_selected_friend()
148 if 'contact' in friend and friend['contact'] == contact:
149 hildon.hildon_banner_show_information(self.main_window, '', _("Removing existing mappings is not yet supported"))
150 elif view.contact_mapped:
151 if fb2c.update_contact(contact, friend, True):
152 fb2c.addresses.commit_contact(contact)
154 if fb2c.update_contact(contact, friend, False):
155 fb2c.addresses.commit_contact(contact)
158 # -----------------------------------------------------------------------
159 def progress(self, i, j, main = False):
162 self.progressbar = gtk.ProgressBar()
163 self.progressnote = gtk.Dialog(_("Fetching friends' info"), self.main_window)
164 self.progressnote.vbox.add(self.progressbar)
165 hildon.hildon_gtk_window_set_progress_indicator(self.progressnote, 1)
167 self.progressnote.show_all()
171 self.progressnote.set_title(_("Updating contacts"))
172 hildon.hildon_gtk_window_set_progress_indicator(self.progressnote, 0)
174 self.progressbar.set_fraction(float(i) / float(j))
177 self.progressnote.destroy()
181 gobject.idle_add(self.progress, i, j, True)
184 # -----------------------------------------------------------------------
185 def report_error(self, e, prefs = False):
186 if self.progressnote:
187 self.main_window.set_property('sensitive', True)
188 self.progressnote.destroy()
190 hildon.hildon_banner_show_information(self.main_window, '', e)