# -----------------------------------------------------------------------
- def __init__(self, book, contact):
+ def __init__(self, book, econtact):
"""Create a new contact store for modifying contacts in the given
EBook."""
self._book = book
- self._contact = contact
+ self._econtact = econtact
self._identifiers = self._find_ids()
+ self._mapped_to = set([])
# -----------------------------------------------------------------------
return self._identifiers
+
+ # -----------------------------------------------------------------------
+ def get_econtact(self):
+ """Return the EContact which backs this contact."""
+
+ return self._econtact
+
+
+ # -----------------------------------------------------------------------
+ def add_mapping(self, id):
+ """Record the fact that this contact is mapped against a provider.
+ 'id' MUST match the string returned by Provider.get_id()."""
+
+ self._mapped_to.add(id)
+
+
+ # ----------------------------------------------------------------------
+ def get_mappings(self):
+ """Return the set of IDs of providers which are mapped to this contact.
+ The data can only be relied upon after services have run."""
+
+ return self._mapped_to
+
# -----------------------------------------------------------------------
def get_photo(self):
-import gtk
+import gtk, glib
import hildon
import gobject
import evolution
hildon.PannableArea.__init__(self)
self.contacts = contacts
- self.treestore = gtk.ListStore(str, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT)
+
+ columns = [gtk.gdk.Pixbuf, # 0. Photo
+ str, # 1. Name
+ # ... # x. Services
+ # gobject.TYPE_PYOBJECT # y. Actual contact
+ ]
+
+ # -- Work out which services need to be shown...
+ #
+ icons = {}
+ services = set([])
+ for contact in self.contacts:
+ services |= contact.get_mapped_to()
+
+ for service in sorted(services):
+ columns.append(gtk.gdk.Pixbuf)
+ try:
+ icons[service] = gtk.gdk.pixbuf_new_from_file('/opt/hermes/share/account-%s.png' % (service))
+ except glib.GError, e:
+ icons[service] = None
+
+ columns.append(gobject.TYPE_PYOBJECT)
+ self.treestore = gtk.ListStore(*tuple(columns))
+ self._contact_index = len(columns) -1
+
+ # -- Build the tree model...
+ #
for contact in self.contacts:
if not contact.get_name():
continue
if pixbuf:
size = min(pixbuf.get_width(), pixbuf.get_height())
pixbuf = pixbuf.subpixbuf(0, 0, size, size).scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR)
- self.treestore.append(row = [contact.get_name(), pixbuf, contact])
+
+ row = [pixbuf, contact.get_name(), ]
+ for service in services:
+ row.append(service in contact.get_mapped_to() and icons[service] or None)
+
+ row.append(contact)
+ self.treestore.append(row)
self.treeview = gtk.TreeView(self.treestore)
- tvcolumn = gtk.TreeViewColumn('Name', gtk.CellRendererText(), text = 0)
- self.treeview.append_column(tvcolumn)
-
- cell = gtk.CellRendererPixbuf()
- cell.set_property('xalign', 1.0)
- tvcolumn = gtk.TreeViewColumn('Picture', cell, pixbuf = 1)
+ self.treeview.append_column(gtk.TreeViewColumn('Picture', gtk.CellRendererPixbuf(), pixbuf = 0))
+
+ tvcolumn = gtk.TreeViewColumn('Name', gtk.CellRendererText(), text = 1)
+ tvcolumn.set_expand(True)
self.treeview.append_column(tvcolumn)
+
+ i = 2
+ for service in services:
+ self.treeview.append_column(gtk.TreeViewColumn('Service', gtk.CellRendererPixbuf(), pixbuf = i))
+ i = i + 1
- self.treeview.set_search_column(0)
self.treeview.connect('row-activated', self._activated)
self.add(self.treeview)
- self.set_size_request(600, 380)
-
+ self.set_size_request_policy(hildon.SIZE_REQUEST_CHILDREN)
+
# -----------------------------------------------------------------------
def _activated(self, treeview, path, column):
selected."""
iter = treeview.get_model().get_iter(path)
- contact = treeview.get_model().get_value(iter, 2)
+ contact = treeview.get_model().get_value(iter, self._contact_index)
self.emit('contact-activated', contact)