[folks] Create a new function set_string_afd_equal.
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Create a new function set_string_afd_equal.
- Date: Fri, 20 Jun 2014 13:23:46 +0000 (UTC)
commit 47776e621dda8041a3329986f663cb83e8a4a4fa
Author: Renato Araujo Oliveira Filho <renato filho canonical com>
Date: Thu Jun 19 18:53:24 2014 -0300
Create a new function set_string_afd_equal.
This is necessary to avoid problems with phone numbers that has a special values_equal function to try
match phone numbers in different formats.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=731175
NEWS | 2 +
backends/bluez/bluez-persona.vala | 2 +-
backends/dummy/lib/dummy-full-persona.vala | 2 +-
backends/eds/lib/edsf-persona-store.vala | 2 +-
backends/eds/lib/edsf-persona.vala | 6 ++-
backends/telepathy/lib/tpf-persona.vala | 2 +-
folks/individual.vala | 2 +-
folks/utils.vala | 55 ++++++++++++++++++++++++++++
8 files changed, 66 insertions(+), 7 deletions(-)
---
diff --git a/NEWS b/NEWS
index 9511744..91e65e0 100644
--- a/NEWS
+++ b/NEWS
@@ -26,12 +26,14 @@ Bugs fixed:
from _edsf_persona_update
• Bug 731325 — Fails to build with srcdir != builddir
• Bug 731464 — Fail to run EDS tests
+ • Bug 731175 — Modifying contact phone number get a timeout
API changes:
• Add Individual.display_name
• Add StructuredName.to_string_with_format()
• Add libfolks-dummy.la and all its symbols
• Add IndividualAggregator.backend_store
+ • Add Utils.set_string_afd_equal
Overview of changes from libfolks 0.9.5 to libfolks 0.9.6
=========================================================
diff --git a/backends/bluez/bluez-persona.vala b/backends/bluez/bluez-persona.vala
index ac6e2d5..5db3034 100644
--- a/backends/bluez/bluez-persona.vala
+++ b/backends/bluez/bluez-persona.vala
@@ -367,7 +367,7 @@ public class Folks.Backends.BlueZ.Persona : Folks.Persona,
this.freeze_notify ();
/* Phone numbers. */
- if (!Folks.Internal.equal_sets<PhoneFieldDetails> (this._phone_numbers,
+ if (!Utils.set_string_afd_equal (this._phone_numbers,
new_phone_numbers))
{
this._phone_numbers = new_phone_numbers;
diff --git a/backends/dummy/lib/dummy-full-persona.vala b/backends/dummy/lib/dummy-full-persona.vala
index f998664..6d69524 100644
--- a/backends/dummy/lib/dummy-full-persona.vala
+++ b/backends/dummy/lib/dummy-full-persona.vala
@@ -1052,7 +1052,7 @@ public class FolksDummy.FullPersona : FolksDummy.Persona,
*/
public void update_phone_numbers (Set<PhoneFieldDetails> phone_numbers)
{
- if (!Folks.Internal.equal_sets<PhoneFieldDetails> (phone_numbers,
+ if (!Utils.set_string_afd_equal (phone_numbers,
this._phone_numbers))
{
this._phone_numbers =
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 0a427d0..c92fc08 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -1606,7 +1606,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
_("Phone numbers are not writeable on this contact."));
}
- if (Folks.Internal.equal_sets<PhoneFieldDetails> (phones,
+ if (Utils.set_string_afd_equal (phones,
persona.phone_numbers))
return;
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 718fe82..a69f45a 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -2000,8 +2000,10 @@ public class Edsf.Persona : Folks.Persona,
new_phone_numbers.add (phone_fd);
}
- if (!Folks.Internal.equal_sets<PhoneFieldDetails> (new_phone_numbers,
- this._phone_numbers))
+ // Does not use phone comparation because this will try to match only
+ // numbers and will remove the prefix, and that could cause a wrong result
+ // since the the phone number is stored as string
+ if (!Utils.set_string_afd_equal (this._phone_numbers, new_phone_numbers))
{
this._phone_numbers = new_phone_numbers;
this._phone_numbers_ro = new_phone_numbers.read_only_view;
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index f336877..fee2f2b 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -1090,7 +1090,7 @@ public class Tpf.Persona : Folks.Persona,
changed = true;
}
- if (!Folks.Internal.equal_sets<PhoneFieldDetails> (new_phone_numbers,
+ if (!Utils.set_string_afd_equal (new_phone_numbers,
this._phone_numbers))
{
this._phone_numbers = new_phone_numbers;
diff --git a/folks/individual.vala b/folks/individual.vala
index 5ff00b2..f60f31e 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -2433,7 +2433,7 @@ public class Folks.Individual : Object,
}
}
- if (!Utils.set_afd_equal (new_phone_numbers, this._phone_numbers))
+ if (!Utils.set_string_afd_equal (new_phone_numbers, this._phone_numbers))
{
this._phone_numbers = new_phone_numbers;
this._phone_numbers_ro = new_phone_numbers.read_only_view;
diff --git a/folks/utils.vala b/folks/utils.vala
index 4225a05..7e99810 100644
--- a/folks/utils.vala
+++ b/folks/utils.vala
@@ -217,4 +217,59 @@ public class Folks.Utils : Object
return true;
}
+
+ /**
+ * Check whether a set of AbstractFieldDetails with string values are equal.
+ *
+ * This performs a deep check for equality, checking whether both sets are of
+ * the same size, and that each set has the same values using string compation
+ * instead of AbstractFieldDetails equal function
+ *
+ * @param a a set to compare
+ * @param b another set to compare
+ * @return ``true`` if the sets are equal, ``false`` otherwise
+ *
+ * @since UNRELEASED
+ */
+ public static bool set_string_afd_equal (
+ Set<AbstractFieldDetails<string> > a,
+ Set<AbstractFieldDetails<string> > b)
+ {
+ if (a == b)
+ return true;
+
+ var a_size = a.size;
+ var b_size = b.size;
+
+ if (a_size == 0 && b_size == 0)
+ {
+ /* fast path: avoid creating the iterator, which is a GObject */
+ return true;
+ }
+ else if (a_size == b_size)
+ {
+ foreach (var a_val in a)
+ {
+ bool found = false;
+ foreach (var b_val in b)
+ {
+ if (a_val.parameters_equal (b_val) &&
+ str_equal(a_val.value, b_val.value))
+ {
+ found = true;
+ }
+ }
+ if (!found)
+ {
+ return false;
+ }
+ }
+ }
+ else
+ {
+ return false;
+ }
+
+ return true;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]