Update contactview to show photo, name and then the set of icons
authorAndrew Flegg <andrew@bleb.org>
Tue, 8 Jun 2010 08:36:55 +0000 (09:36 +0100)
committerAndrew Flegg <andrew@bleb.org>
Tue, 8 Jun 2010 08:36:55 +0000 (09:36 +0100)
corrersponding to the services which matched.

package/src/org/maemo/hermes/engine/contact.py
package/src/org/maemo/hermes/engine/facebook/provider.py
package/src/org/maemo/hermes/engine/facebook/service.py
package/src/org/maemo/hermes/engine/hermes.py
package/src/org/maemo/hermes/engine/service.py
package/src/org/maemo/hermes/gui/contactview.py
package/src/org/maemo/hermes/gui/mapcontact.py

index 9fee7b2..4cb4128 100644 (file)
@@ -27,13 +27,14 @@ class Contact:
 
        
     # -----------------------------------------------------------------------
-    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([])
         
         
     # -----------------------------------------------------------------------
@@ -72,6 +73,29 @@ class Contact:
            
         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):
index f9aafd7..a6a0554 100644 (file)
@@ -106,7 +106,7 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
                 pass
             self._do_fb_login()
 
-        return org.maemo.hermes.engine.facebook.service.Service(self.fb)
+        return org.maemo.hermes.engine.facebook.service.Service(self.fb, self._gc.get_bool('/apps/maemo/hermes/facebook_birthday_only'))
 
 
     # -----------------------------------------------------------------------
index ac8915d..9b9e6ec 100644 (file)
@@ -14,7 +14,7 @@ class Service(org.maemo.hermes.engine.service.Service):
 
 
     # -----------------------------------------------------------------------
-    def __init__(self, facebook):
+    def __init__(self, facebook, create_birthday_only = False):
         """Initialise the Facebook service, finding Facebook API keys in gconf and
            having a gui_callback available."""
         
index a37a9a8..8f8c571 100644 (file)
@@ -47,6 +47,8 @@ class Hermes:
                 return ["fredrik@wendt.se","maemohermes@wendt.se"]
             def get_photo(self):
                 return None
+            def get_mapped_to(self):
+                return set(["facebook", "gravatar"])
         self.matched = [FakeContact()]
  
 #        self._sync_job = SyncJob(services, [FakeContact()], self.progress)
@@ -61,7 +63,7 @@ class Hermes:
     def update_contact(self, contact, friend, resync = False):
         """Update the given contact with information from the given friend."""
         
-        pass
+        friend.update_contact(contact, resync)
     
 """        
  friends = ()
index 2f519cd..de6d87e 100644 (file)
@@ -61,6 +61,7 @@ class Service:
 
 
     # -----------------------------------------------------------------------
+    ###DEPRECATED
     def _create_friend(self, name):
         """Used to create a Friend object for a contact"""
         
index 7c7def3..d9c50e5 100644 (file)
@@ -1,4 +1,4 @@
-import gtk
+import gtk, glib
 import hildon
 import gobject
 import evolution
@@ -18,7 +18,33 @@ class ContactView(hildon.PannableArea):
         
         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
@@ -38,22 +64,30 @@ class ContactView(hildon.PannableArea):
             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):
@@ -61,7 +95,7 @@ class ContactView(hildon.PannableArea):
            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)
 
 
index ca668cd..1aadff1 100644 (file)
@@ -60,7 +60,8 @@ class MapContact(hildon.PannableArea):
             self.treeview.scroll_to_cell(path)
           
         self.add(self.treeview)
-        self.set_size_request(600, 320)
+        self.set_size_request_policy(hildon.SIZE_REQUEST_CHILDREN)
+
       
     # -----------------------------------------------------------------------
     def get_selected_friend(self):