5 class ContactView(hildon.PannableArea):
6 """Widget which shows a list of contacts in a pannable area.
8 Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
9 Released under the Artistic Licence."""
12 # -----------------------------------------------------------------------
13 def __init__(self, contacts):
14 """Constructor. Passed a list of EContacts."""
16 hildon.PannableArea.__init__(self)
17 self.contacts = contacts
18 self.treestore = gtk.ListStore(str, gtk.gdk.Pixbuf)
19 for contact in self.contacts:
20 if not contact.get_name():
23 photo = contact.get_property('photo')
24 pi = cast(c_void_p(hash(photo)), POINTER(EContactPhoto))
26 if pi.contents.data.uri.startswith("image/"):
27 data = string_at(pi.contents.data.inlined.data, pi.contents.data.inlined.length)
28 pixbuf_loader = gtk.gdk.PixbufLoader()
29 pixbuf_loader.write(data)
31 pixbuf = pixbuf_loader.get_pixbuf()
32 elif pi.contents.data.uri.startswith("file://"):
33 filename = pi.contents.data.uri[7:]
34 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
37 size = min(pixbuf.get_width(), pixbuf.get_height())
38 pixbuf = pixbuf.subpixbuf(0, 0, size, size).scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR)
39 self.treestore.append(row = [contact.get_name(), pixbuf])
41 self.treeview = gtk.TreeView(self.treestore)
42 tvcolumn = gtk.TreeViewColumn('Name', gtk.CellRendererText(), text = 0)
43 self.treeview.append_column(tvcolumn)
45 cell = gtk.CellRendererPixbuf()
46 cell.set_property('xalign', 1.0)
47 tvcolumn = gtk.TreeViewColumn('Picture', cell, pixbuf = 1)
48 self.treeview.append_column(tvcolumn)
50 self.add(self.treeview)
51 self.set_size_request(600, 380)
54 class EContactPhoto_inlined(Structure):
55 _fields_ = [('mime_type', c_char_p),
59 class EContactPhoto_data(Union):
60 _fields_ = [('inlined', EContactPhoto_inlined),
63 class EContactPhoto(Structure):
64 _fields_ = [('type', c_int),
65 ('data', EContactPhoto_data)]