* 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
# -----------------------------------------------------------------------
- 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:
# -- 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))
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)
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)
# -----------------------------------------------------------------------
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)
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())
# -----------------------------------------------------------------------
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:
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)
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()