# -----------------------------------------------------------------------
+ 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."""
# -----------------------------------------------------------------------
+ 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."""
def get_source(self):
return self._source
+ def set_source(self, source):
+ self._source = source
+
def get_nickname(self):
return self._safe_get("nickname")
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 -----------------------
#
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)
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)
"""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())
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):
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)
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)