Fix-up manual matching to work off new friend class.
authorAndrew Flegg <andrew@bleb.org>
Wed, 9 Jun 2010 21:38:36 +0000 (22:38 +0100)
committerAndrew Flegg <andrew@bleb.org>
Wed, 9 Jun 2010 21:38:36 +0000 (22:38 +0100)
package/src/org/maemo/hermes/engine/friend.py
package/src/org/maemo/hermes/engine/hermes.py
package/src/org/maemo/hermes/gui/gtkui.py
package/src/org/maemo/hermes/gui/mapcontact.py

index a45a6bb..b6a97b6 100644 (file)
@@ -38,6 +38,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")
     
index 2cbacd6..73b9fc1 100644 (file)
@@ -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)
index 606d7d0..8936bd9 100644 (file)
@@ -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):
index 1aadff1..ca9f517 100644 (file)
@@ -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)