[folks] Telepathy: implement PhoneDetails for Tpf.Persona



commit 87e04d0b796c48fe3fdd2c0e46704ca2f02a97fb
Author: Raul Gutierrez Segales <rgs collabora co uk>
Date:   Mon Sep 19 18:24:34 2011 +0100

    Telepathy: implement PhoneDetails for Tpf.Persona
    
    Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=657602

 NEWS                                          |    6 ++
 backends/telepathy/lib/tpf-persona-store.vala |    3 +-
 backends/telepathy/lib/tpf-persona.vala       |   77 +++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index adc888c..463327a 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,12 @@ Overview of changes from libfolks 0.6.3.2 to libfolks 0.6.4
 Bugs fixed:
 * Bug 660217 â folks-0.6.3.2 requires tracker-0.12, but configure.ac calls
   VALA_CHECK_PACKAGES([tracker-sparql-0.12])
+* Bug 657602 â Telepathy backend fails to set Personas' phone numbers from
+  ContactInfo
+
+API changes:
+* Implement PhoneDetails on Tpf.Persona
+* Implement NameDetails on Tpf.Persona
 
 Overview of changes from libfolks 0.6.3.1 to libfolks 0.6.3.2
 =============================================================
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index 6b6f930..14b07a4 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -58,7 +58,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
         ContactFeature.AVATAR_TOKEN,
         ContactFeature.CAPABILITIES,
         ContactFeature.CLIENT_TYPES,
-        ContactFeature.PRESENCE
+        ContactFeature.PRESENCE,
+        ContactFeature.CONTACT_INFO
       };
 
   private const string[] _always_writeable_properties =
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index 848813f..8e05a34 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -33,6 +33,7 @@ public class Tpf.Persona : Folks.Persona,
     FavouriteDetails,
     GroupDetails,
     ImDetails,
+    PhoneDetails,
     PresenceDetails
 {
   private HashSet<string> _groups;
@@ -286,6 +287,21 @@ public class Tpf.Persona : Folks.Persona,
    */
   public Contact? contact { get; construct; }
 
+  private HashSet<PhoneFieldDetails> _phone_numbers;
+  private Set<PhoneFieldDetails> _phone_numbers_ro;
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  [CCode (notify = false)]
+  public Set<PhoneFieldDetails> phone_numbers
+    {
+      get { return this._phone_numbers_ro; }
+      set { this.change_phone_numbers.begin (value); }
+    }
+
   /**
    * Create a new persona.
    *
@@ -353,6 +369,11 @@ public class Tpf.Persona : Folks.Persona,
       this._groups = new HashSet<string> ();
       this._groups_ro = this._groups.read_only_view;
 
+      this._phone_numbers = new HashSet<PhoneFieldDetails> (
+          (GLib.HashFunc) PhoneFieldDetails.hash,
+          (GLib.EqualFunc) PhoneFieldDetails.equal);
+      this._phone_numbers_ro = this._phone_numbers.read_only_view;
+
       contact.notify["avatar-file"].connect ((s, p) =>
         {
           this._contact_notify_avatar ();
@@ -375,6 +396,12 @@ public class Tpf.Persona : Folks.Persona,
       this._contact_notify_presence_type ();
       this._contact_notify_presence_status ();
 
+      contact.notify["contact-info"].connect ((s, p) =>
+        {
+          this._contact_notify_phones ();
+        });
+      this._contact_notify_phones ();
+
       ((Tpf.PersonaStore) this.store).group_members_changed.connect (
           (s, group, added, removed) =>
             {
@@ -401,6 +428,56 @@ public class Tpf.Persona : Folks.Persona,
             });
     }
 
+  private void _contact_notify_phones ()
+    {
+      var new_phone_numbers = new HashSet<PhoneFieldDetails> (
+          (GLib.HashFunc) PhoneFieldDetails.hash,
+          (GLib.EqualFunc) PhoneFieldDetails.equal);
+
+      var contact_info = this.contact.get_contact_info ();
+      foreach (var info in contact_info)
+        {
+          if (info.field_name != "tel")
+            continue;
+
+          foreach (var phone_num in info.field_value)
+            {
+              var parameters = this._afd_params_from_strv (info.parameters);
+              var phone_fd = new PhoneFieldDetails (phone_num, parameters);
+              new_phone_numbers.add (phone_fd);
+            }
+        }
+
+      if (!Folks.PersonaStore.equal_sets<PhoneFieldDetails> (new_phone_numbers,
+              this._phone_numbers))
+        {
+          this._phone_numbers = new_phone_numbers;
+          this._phone_numbers_ro = new_phone_numbers.read_only_view;
+          this.notify_property ("phone-numbers");
+        }
+    }
+
+  private MultiMap<string, string> _afd_params_from_strv (string[] parameters)
+    {
+      var retval = new HashMultiMap<string, string> ();
+
+      foreach (var entry in parameters)
+        {
+          var tokens = entry.split ("=", 2);
+          if (tokens.length == 2)
+            {
+              retval.set (tokens[0], tokens[1]);
+            }
+          else
+            {
+              warning ("Failed to parse vCard parameter from string '%s'",
+                  entry);
+            }
+        }
+
+      return retval;
+    }
+
   /**
    * Create a new persona for the { link PersonaStore} `store`, representing
    * a cached contact for which we currently have no Telepathy contact.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]