Fix manual mapping, and scroll to the best place in the friends list that can be...
authorAndrew Flegg <andrew@bleb.org>
Thu, 10 Jun 2010 11:35:11 +0000 (12:35 +0100)
committerAndrew Flegg <andrew@bleb.org>
Thu, 10 Jun 2010 11:35:11 +0000 (12:35 +0100)
package/debian/changelog
package/src/org/maemo/hermes/engine/hermes.py
package/src/org/maemo/hermes/gui/contactview.py
package/src/org/maemo/hermes/gui/gtkui.py
package/src/org/maemo/hermes/gui/mapcontact.py

index 7a899a8..9ccf618 100644 (file)
@@ -2,6 +2,7 @@ hermes (0.8.1) unstable; urgency=low
 
   * Make LinkedIn verification box numbers only.
   * Localise main buttons (provided by Todor Tsankov). MB#9412
+  * Fix manual mapping, and scroll to the best place recognised.
   * ...
 
  -- Andrew Flegg <andrew@bleb.org>  Thu, 10 Jun 2010 11:25:21 +0100
index a2cd2c3..7b50935 100644 (file)
@@ -120,12 +120,14 @@ class Hermes:
         
 
     # -----------------------------------------------------------------------
-    def update_contact(self, contact, friend, resync=False):
+    def update_contact(self, contact, friend, resync=False, commit=False):
         """Update the given contact with information from the given friend."""
         
         print "updating contact ", contact, " with friend ", friend
         if friend.update_contact(contact, resync):
             self.updated.append(contact)
+            if commit:
+                self.address_book.commit_contact(contact.get_econtact())
 
         self.matched.append(contact)
         if friend.get_source() is not None:
index 0728d50..98f8ef1 100644 (file)
@@ -27,17 +27,17 @@ class ContactView(hildon.PannableArea):
 
         # -- Work out which services need to be shown...
         #
-        icons    = {}
-        services = set([])
+        self._icons    = {}
+        self._services = set([])
         for contact in self.contacts:
-            services |= contact.get_mappings()
+            self._services |= contact.get_mappings()
 
-        for service in sorted(services):
+        for service in sorted(self._services):
             columns.append(gtk.gdk.Pixbuf)
             try:
-                icons[service] = gtk.gdk.pixbuf_new_from_file('/opt/hermes/share/account-%s.png' % (service))
+                self._icons[service] = gtk.gdk.pixbuf_new_from_file('/opt/hermes/share/account-%s.png' % (service))
             except glib.GError, e:
-                icons[service] = None
+                self._icons[service] = None
                 
         columns.append(gobject.TYPE_PYOBJECT)
         self.treestore = gtk.ListStore(*tuple(columns))
@@ -66,8 +66,8 @@ class ContactView(hildon.PannableArea):
                 pixbuf = pixbuf.subpixbuf(0, 0, size, size).scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR)
                 
             row = [pixbuf, contact.get_name(), ]
-            for service in services:
-                row.append(service in contact.get_mappings() and icons[service] or None)
+            for service in self._services:
+                row.append(service in contact.get_mappings() and self._icons[service] or None)
                 
             row.append(contact)
             self.treestore.append(row)
@@ -80,22 +80,35 @@ class ContactView(hildon.PannableArea):
         self.treeview.append_column(tvcolumn)
 
         i = 2
-        for service in services:
+        for service in self._services:
             self.treeview.append_column(gtk.TreeViewColumn('Service', gtk.CellRendererPixbuf(), pixbuf = i))
-            i = i + 1
+            i += 1
         
         self.treeview.connect('row-activated', self._activated)
         self.add(self.treeview)
         self.set_size_request_policy(hildon.SIZE_REQUEST_CHILDREN)
 
+
+    # -----------------------------------------------------------------------
+    def add_mapping(self, service_id):
+        """Used to emit the `contact-activated' signal once a row has been
+           selected."""
+
+        if self._selected_iter:
+            i = 2
+            for service in self._services:
+                if service == service_id:
+                    self.treeview.get_model().set_value(self._selected_iter, i, self._icons[service])
+                i += 1
       
+
     # -----------------------------------------------------------------------
     def _activated(self, treeview, path, column):
         """Used to emit the `contact-activated' signal once a row has been
            selected."""
         
-        iter    = treeview.get_model().get_iter(path)
-        contact = treeview.get_model().get_value(iter, self._contact_index)
+        self._selected_iter = treeview.get_model().get_iter(path)
+        contact = treeview.get_model().get_value(self._selected_iter, self._contact_index)
         self.emit('contact-activated', contact)
 
 
index 33dc4da..fa72817 100644 (file)
@@ -147,7 +147,7 @@ class HermesGUI(WimpWorks):
     # -----------------------------------------------------------------------
     def map_contact(self, widget, contact, fb2c):
         view = MapContact(fb2c.friends, contact)
-    
+
         dialog = gtk.Dialog(contact.get_name(), self.main_window)
         dialog.add_button(_('Update'), gtk.RESPONSE_OK)
         dialog.vbox.add(view)
@@ -161,11 +161,11 @@ class HermesGUI(WimpWorks):
                 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):
-                        fb2c.addresses.commit_contact(contact)
+                    fb2c.update_contact(contact, friend, True, True)
+                    widget.add_mapping(friend.get_source())
                 else:
-                    if fb2c.update_contact(contact, friend, False):
-                        fb2c.addresses.commit_contact(contact)
+                    fb2c.update_contact(contact, friend, False, True)
+                    widget.add_mapping(friend.get_source())
     
                         
     # -----------------------------------------------------------------------
index ca9f517..aa60ea9 100644 (file)
@@ -25,6 +25,8 @@ class MapContact(hildon.PannableArea):
         
         self.contact_mapped = False
         mapped_iter = None
+        best_iter   = None
+        last_name   = '' # Keep track for when we switch name positions and focus there
         for key in sorted(self.friends.keys(), cmp = lambda a, b: cmp(a.lower(), b.lower())):
             friend = self.friends[key]
             if friend.get_source() not in accounts:
@@ -43,7 +45,11 @@ class MapContact(hildon.PannableArea):
                 else:
                     continue
             else:
-                self.treestore.append([accounts[friend.get_source()], friend.get_name(), pixbuf, friend])
+                position = self.treestore.append([accounts[friend.get_source()], friend.get_name(), pixbuf, friend])
+                if cmp(last_name, contact.get_name()) != cmp(friend.get_name(), contact.get_name()):
+                    best_iter = position
+
+                last_name = friend.get_name()
         
         self.treeview = gtk.TreeView(self.treestore)
         hildon.hildon_gtk_tree_view_set_ui_mode(self.treeview, gtk.HILDON_UI_MODE_EDIT)
@@ -59,6 +65,10 @@ class MapContact(hildon.PannableArea):
             path = self.treestore.get_path(mapped_iter)
             self.treeview.get_selection().select_path(path)
             self.treeview.scroll_to_cell(path)
+        elif best_iter:
+            path = self.treestore.get_path(best_iter)
+            self.treeview.get_selection().unselect_all()
+            self.treeview.scroll_to_cell(path)
         else:
             self.treeview.get_selection().unselect_all()