[gnome-contacts] Try to detect when a individual is replaces with another and reuse the contact
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Try to detect when a individual is replaces with another and reuse the contact
- Date: Wed, 24 Aug 2011 21:04:58 +0000 (UTC)
commit 3d4361509be514133b083a72f9264cae3d5ab583
Author: Alexander Larsson <alexl redhat com>
Date: Wed Aug 24 15:51:29 2011 +0200
Try to detect when a individual is replaces with another and reuse the contact
src/contacts-contact.vala | 12 ++++++++++++
src/contacts-store.vala | 40 +++++++++++++++++++++++++++++++++++++---
2 files changed, 49 insertions(+), 3 deletions(-)
---
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index b8c5708..9d62608 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -293,6 +293,18 @@ public class Contacts.Contact : GLib.Object {
individual.notify.connect(notify_cb);
}
+ public void replace_individual (Individual new_individual) {
+ foreach (var p in individual.personas) {
+ disconnect_persona (p);
+ }
+ individual = new_individual;
+ individual.set_data ("contact", this);
+ foreach (var p in individual.personas) {
+ connect_persona (p);
+ }
+ queue_changed ();
+ }
+
public void remove () {
unqueue_changed ();
foreach (var p in individual.personas) {
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index cdb7498..232a8ae 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -34,12 +34,46 @@ public class Contacts.Store : GLib.Object {
aggregator = new IndividualAggregator ();
aggregator.individuals_changed.connect ((added, removed, m, a, r) => {
+ var old_individuals = new HashMap<Persona, Individual>();
+ var replaced_individuals = new HashSet<Individual>();
+
+ /* Try to reverse engineer which added individuals just replaces
+ old individuals */
+
foreach (Individual i in removed) {
- this.remove (Contact.from_individual (i));
+ foreach (var p in i.personas) {
+ old_individuals.set (p, i);
+ }
}
+
foreach (Individual i in added) {
- var c = new Contact (this, i);
- this.add (c);
+ Individual? old_individual = null;
+ foreach (var p in i.personas) {
+ var o_i = old_individuals.get (p);
+ if (o_i != null) {
+ if (old_individual == null)
+ old_individual = o_i;
+ else if (o_i != old_individual) {
+ old_individual = null;
+ break;
+ }
+ }
+ }
+ if (old_individual != null &&
+ !replaced_individuals.contains (old_individual)) {
+ replaced_individuals.add (old_individual);
+ var c = Contact.from_individual (old_individual);
+ c.replace_individual (i);
+ } else {
+ var c = new Contact (this, i);
+ this.add (c);
+ }
+ }
+
+ foreach (Individual i in removed) {
+ if (!replaced_individuals.contains (i)) {
+ this.remove (Contact.from_individual (i));
+ }
}
});
aggregator.prepare ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]