From: Fredrik Wendt Date: Wed, 9 Jun 2010 22:08:30 +0000 (+0100) Subject: Merge branch 'master' of git@wendt.se:hermes X-Git-Tag: 0.8.0~11^2~2 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=c5b55a77ae13ec909fa20d00decf3c2a1d02fa33;hp=dc60ee5cac324d5e4fb3da18a97ace44da3964cf;p=hermes Merge branch 'master' of git@wendt.se:hermes --- diff --git a/package/src/org/maemo/hermes/engine/contact.py b/package/src/org/maemo/hermes/engine/contact.py index b9a49d2..8281d18 100644 --- a/package/src/org/maemo/hermes/engine/contact.py +++ b/package/src/org/maemo/hermes/engine/contact.py @@ -162,6 +162,12 @@ class Contact: # ----------------------------------------------------------------------- + def get_birthday(self): + photo = self._contact.get_property('birth-date') + return cast(c_void_p(hash(photo)), POINTER(EContactDate)) + + + # ----------------------------------------------------------------------- def set_nickname(self, nickname): """Set the nickname for this contact to the given nickname.""" @@ -171,6 +177,13 @@ class Contact: # ----------------------------------------------------------------------- + def get_nickname(self): + """Get the nickname for this contact.""" + + return self._contact.get_property('nickname') + + + # ----------------------------------------------------------------------- def get_emails(self): """Return the email addresses associated with this contact.""" diff --git a/package/src/org/maemo/hermes/engine/friend.py b/package/src/org/maemo/hermes/engine/friend.py index 4278541..4f90ae9 100644 --- a/package/src/org/maemo/hermes/engine/friend.py +++ b/package/src/org/maemo/hermes/engine/friend.py @@ -41,6 +41,9 @@ class Friend(): def get_source(self): return self._source + def set_source(self, source): + self._source = source + def get_nickname(self): return self._safe_get("nickname") @@ -88,22 +91,24 @@ class Friend(): self._add(key, value) def update_contact(self, contact, overwrite=False): - """ - Updates the contact with information from this object, - without overwriting unless overwrite is set to True. - """ + """Updates the contact with information from this object, + without overwriting unless overwrite is set to True. + Returns flag indicating if anything *was* changed.""" - # FIXME: currently we overwrite everything - self._if_defined('photo-url', contact.set_photo) - self._if_defined('nickname', contact.set_nickname) - if self._multi_attributes.has_key('url'): - for url in self._multi_attributes['url']: - contact.add_url(url) - def fixme(arg): pass #print "FIXME - birthday date needs to be parsed/fixed %s before calling contact.set_birthday" % arg - self._if_defined('bday', fixme) + + updated = False + if overwrite or contact.get_photo() is None: updated += self._if_defined('photo-url', contact.set_photo) + if overwrite or contact.get_nickname() is None: updated += self._if_defined('nickname', contact.set_nickname) + if overwrite or contact.get_birthday() is None: updated += self._if_defined('bday', fixme) + if self._multi_attributes.has_key('url'): + for url in self._multi_attributes['url']: + updated += contact.add_url(url) + + return updated + # private helpers ----------------------- # @@ -122,8 +127,7 @@ class Friend(): return False def _if_defined(self, key, callback): - if self._attributes.has_key(key): - callback(self._attributes[key]) + return self._attributes.has_key(key) and callback(self._attributes[key]) or False def _has(self, key): return self._attributes.has_key(key) or self._multi_attributes.has_key(key) diff --git a/package/src/org/maemo/hermes/engine/hermes.py b/package/src/org/maemo/hermes/engine/hermes.py index 9a00bfd..9197b52 100644 --- a/package/src/org/maemo/hermes/engine/hermes.py +++ b/package/src/org/maemo/hermes/engine/hermes.py @@ -101,7 +101,10 @@ class Hermes: self._progress("Finalising...", current_tick, total_ticks) current_tick += len(contacts) service.finalise(self.updated, overwrite_existing_fields) - self.friends[service.get_id] = service.get_unmatched_friends() + for friend in service.get_unmatched_friends(): + friend.set_source(service.get_id()) + key = unicode(friend['name']).encode('trans') + "_" + service.get_id() + self.friends[key] = friend # commit changes tick_increment = total_contacts / (len(self.updated) or 1) @@ -120,7 +123,9 @@ class Hermes: """Update the given contact with information from the given friend.""" print "updating contact ", contact, " with friend ", friend - self.updated.append(contact) + if friend.update_contact(contact, resync): + self.updated.append(contact) + self.matched.append(contact) if friend.get_source() is not None: contact.add_mapping(friend.get_source()) diff --git a/package/src/org/maemo/hermes/gui/gtkui.py b/package/src/org/maemo/hermes/gui/gtkui.py index 606d7d0..8936bd9 100644 --- a/package/src/org/maemo/hermes/gui/gtkui.py +++ b/package/src/org/maemo/hermes/gui/gtkui.py @@ -155,7 +155,7 @@ class HermesGUI(WimpWorks): if result == gtk.RESPONSE_OK: friend = view.get_selected_friend() if friend: - if 'contact' in friend and friend['contact'] == contact: + if friend.get_contact() == contact: hildon.hildon_banner_show_information(self.main_window, '', _("Removing existing mappings is not yet supported")) elif view.contact_mapped: if fb2c.update_contact(contact, friend, True): diff --git a/package/src/org/maemo/hermes/gui/mapcontact.py b/package/src/org/maemo/hermes/gui/mapcontact.py index 1aadff1..ca9f517 100644 --- a/package/src/org/maemo/hermes/gui/mapcontact.py +++ b/package/src/org/maemo/hermes/gui/mapcontact.py @@ -21,28 +21,29 @@ class MapContact(hildon.PannableArea): self.treestore = gtk.ListStore(gtk.gdk.Pixbuf, str, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT) accounts = {} - _facebook = gtk.gdk.pixbuf_new_from_file('/opt/hermes/share/account-facebook.png') - _twitter = gtk.gdk.pixbuf_new_from_file('/opt/hermes/share/account-twitter.png') - _tick = gtk.icon_theme_get_default().load_icon('widgets_tickmark_list', 48, 0) + _tick = gtk.icon_theme_get_default().load_icon('widgets_tickmark_list', 48, 0) self.contact_mapped = False mapped_iter = None for key in sorted(self.friends.keys(), cmp = lambda a, b: cmp(a.lower(), b.lower())): friend = self.friends[key] - if friend['account'] not in accounts: - accounts[friend['account']] = gtk.gdk.pixbuf_new_from_file("/opt/hermes/share/account-%s.png" % (friend['account'])) + if friend.get_source() not in accounts: + try: + accounts[friend.get_source()] = gtk.gdk.pixbuf_new_from_file("/opt/hermes/share/account-%s.png" % (friend.get_source())) + except glib.GError, e: + accounts[friend.get_source()] = None + print "Couldn't find icon:", e.message - photo = friend['pic'] pixbuf = None - if 'contact' in friend: - if friend['contact'] == contact: + if friend.get_contact() is not None: + if friend.get_contact() == contact: pixbuf = _tick self.contact_mapped = True - mapped_iter = self.treestore.append([accounts[friend['account']], friend['name'], pixbuf, friend]) + mapped_iter = self.treestore.append([accounts[friend.get_source()], friend.get_name(), pixbuf, friend]) else: continue else: - self.treestore.append([accounts[friend['account']], friend['name'], pixbuf, friend]) + self.treestore.append([accounts[friend.get_source()], friend.get_name(), pixbuf, friend]) self.treeview = gtk.TreeView(self.treestore) hildon.hildon_gtk_tree_view_set_ui_mode(self.treeview, gtk.HILDON_UI_MODE_EDIT) @@ -58,6 +59,8 @@ class MapContact(hildon.PannableArea): path = self.treestore.get_path(mapped_iter) self.treeview.get_selection().select_path(path) self.treeview.scroll_to_cell(path) + else: + self.treeview.get_selection().unselect_all() self.add(self.treeview) self.set_size_request_policy(hildon.SIZE_REQUEST_CHILDREN)