[gnome-contacts] New method to pick best replacement on join
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] New method to pick best replacement on join
- Date: Fri, 9 Sep 2011 12:19:18 +0000 (UTC)
commit cb48efa20d8717b7eef57819c6c9e91e27663823
Author: Alexander Larsson <alexl redhat com>
Date: Fri Sep 9 14:17:25 2011 +0200
New method to pick best replacement on join
src/contacts-linking.vala | 7 +++++--
src/contacts-store.vala | 44 ++++++++++++++++++++++++++++++++++----------
2 files changed, 39 insertions(+), 12 deletions(-)
---
diff --git a/src/contacts-linking.vala b/src/contacts-linking.vala
index d42563d..00a5120 100644
--- a/src/contacts-linking.vala
+++ b/src/contacts-linking.vala
@@ -406,7 +406,8 @@ namespace Contacts {
public async void link_contacts (Contact main, Contact other) {
// This should not be used as being replaced with the new individual
// instead we should always pick this contact to keep around
- other.individual.set_data ("contacts-not-replaced", true);
+ var contact_persona = main.individual.personas.to_array()[0];
+ contact_persona.set_data ("contacts-master-at-join", true);
var main_linkables = get_linkable_attributes_for_individual (main.individual);
var other_linkables = get_linkable_attributes_for_individual (other.individual);
@@ -416,7 +417,6 @@ namespace Contacts {
main_linkables.remove_all (other_linkables);
other_linkables.remove_all (main_linkables);
-
Persona? write_persona = null;
foreach (var p1 in main.individual.personas) {
if (persona_can_link_to (p1, other_linkables)) {
@@ -449,12 +449,15 @@ namespace Contacts {
linkables.add_all (other_linkables);
yield (write_persona as NameDetails).change_full_name (main.display_name);
} catch (GLib.Error e) {
+ contact_persona.set_data ("contacts-master-at-join", false);
warning ("Unable to create new persona when linking: %s\n", e.message);
return;
}
}
yield persona_apply_attributes (write_persona, linkables, null);
+
+ contact_persona.set_data ("contacts-master-at-join", false);
}
public async void unlink_persona (Contact contact, Persona persona_to_unlink) {
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index f8bed35..7d232a1 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -38,10 +38,25 @@ public class Contacts.Store : GLib.Object {
}
}
- public bool is_quiescent
- {
- get { return this.aggregator.is_quiescent; }
+ public bool is_quiescent {
+ get { return this.aggregator.is_quiescent; }
+ }
+
+ private bool individual_can_replace_at_split (Individual new_individual) {
+ foreach (var p in new_individual.personas) {
+ if (p.get_data<bool> ("contacts-new-contact"))
+ return false;
+ }
+ return true;
+ }
+
+ private bool individual_should_replace_at_join (Individual new_individual) {
+ foreach (var p in new_individual.personas) {
+ if (p.get_data<bool> ("contacts-master-at-join"))
+ return true;
}
+ return false;
+ }
public Store () {
contacts = new Gee.ArrayList<Contact>();
@@ -58,18 +73,27 @@ public class Contacts.Store : GLib.Object {
// Note: Apparently the current implementation doesn't necessarily pick
// up unlinked individual as replacements.
- // Keep track of which individuals we've replaced, as the same individual
- // can appear multiple times in the values (when linking multiple individuals
- // into one).
- var replaced_individuals = new HashSet<Individual> ();
+ var replaced_individuals = new HashMap<Individual?, Individual?> ();
+
+ // Pick best replacements at joins
+ foreach (var old_individual in changes.get_keys ()) {
+ if (old_individual == null)
+ continue;
+ foreach (var new_individual in changes.get (old_individual)) {
+ if (new_individual == null)
+ continue;
+ if (!replaced_individuals.has_key (new_individual) ||
+ individual_should_replace_at_join (old_individual)) {
+ replaced_individuals.set (new_individual, old_individual);
+ }
+ }
+ }
foreach (var old_individual in changes.get_keys ()) {
HashSet<Individual>? replacements = null;
foreach (var new_individual in changes.get (old_individual)) {
if (old_individual != null && new_individual != null &&
- !old_individual.get_data<bool> ("contacts-not-replaced") &&
- !(new_individual in replaced_individuals)) {
- replaced_individuals.add (new_individual);
+ replaced_individuals.get (new_individual) == old_individual) {
if (replacements == null)
replacements = new HashSet<Individual> ();
replacements.add (new_individual);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]