[folks] Support EmailDetails for the Telepathy backend.



commit c3909745b8e3308cabe44bc0a57749ca30e0ccb8
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Fri Oct 7 13:39:03 2011 -0700

    Support EmailDetails for the Telepathy backend.

 NEWS                                       |    1 +
 backends/telepathy/lib/tpf-persona.vala    |   54 ++++++++++++++++++++++++++++
 tests/lib/telepathy/contactlist/conn.c     |    7 ++++
 tests/telepathy/individual-properties.vala |   41 +++++++++++++++++++++
 4 files changed, 103 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 463327a..49dd758 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Bugs fixed:
 API changes:
 * Implement PhoneDetails on Tpf.Persona
 * Implement NameDetails on Tpf.Persona
+* Implement EmailDetails 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.vala b/backends/telepathy/lib/tpf-persona.vala
index 546f58d..074e952 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -30,6 +30,7 @@ using Folks;
 public class Tpf.Persona : Folks.Persona,
     AliasDetails,
     AvatarDetails,
+    EmailDetails,
     FavouriteDetails,
     GroupDetails,
     ImDetails,
@@ -274,6 +275,33 @@ public class Tpf.Persona : Folks.Persona,
       this.notify_property ("is-favourite");
     }
 
+  private HashSet<EmailFieldDetails> _email_addresses;
+  private Set<EmailFieldDetails> _email_addresses_ro;
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  [CCode (notify = false)]
+  public Set<EmailFieldDetails> email_addresses
+    {
+      get { return this._email_addresses_ro; }
+      set { this.change_email_addresses.begin (value); }
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_email_addresses (
+      Set<EmailFieldDetails> email_addresses) throws PropertyError
+    {
+      yield this._change_details<EmailFieldDetails> (email_addresses,
+          this._email_addresses, "email");
+    }
+
   /**
    * A mapping of IM protocol to an (unordered) set of IM addresses.
    *
@@ -502,6 +530,10 @@ public class Tpf.Persona : Folks.Persona,
       this._groups = new HashSet<string> ();
       this._groups_ro = this._groups.read_only_view;
 
+      this._email_addresses = new HashSet<EmailFieldDetails> (
+          (GLib.HashFunc) EmailFieldDetails.hash,
+          (GLib.EqualFunc) EmailFieldDetails.equal);
+      this._email_addresses_ro = this._email_addresses.read_only_view;
       this._phone_numbers = new HashSet<PhoneFieldDetails> (
           (GLib.HashFunc) PhoneFieldDetails.hash,
           (GLib.EqualFunc) PhoneFieldDetails.equal);
@@ -576,6 +608,8 @@ public class Tpf.Persona : Folks.Persona,
       var tpf_store = this.store as Tpf.PersonaStore;
       this._writeable_properties = this._always_writeable_properties;
 
+      if ("email" in tpf_store.supported_fields)
+        this._writeable_properties += "email-addresses";
       if ("fn" in tpf_store.supported_fields)
         this._writeable_properties += "full-name";
       if ("tel" in tpf_store.supported_fields)
@@ -585,6 +619,9 @@ public class Tpf.Persona : Folks.Persona,
   private void _contact_notify_contact_info ()
     {
       var new_full_name = "";
+      var new_email_addresses = new HashSet<EmailFieldDetails> (
+          (GLib.HashFunc) EmailFieldDetails.hash,
+          (GLib.EqualFunc) EmailFieldDetails.equal);
       var new_phone_numbers = new HashSet<PhoneFieldDetails> (
           (GLib.HashFunc) PhoneFieldDetails.hash,
           (GLib.EqualFunc) PhoneFieldDetails.equal);
@@ -593,6 +630,15 @@ public class Tpf.Persona : Folks.Persona,
       foreach (var info in contact_info)
         {
           if (info.field_name == "") {}
+          else if (info.field_name == "email")
+            {
+              foreach (var email_addr in info.field_value)
+                {
+                  var parameters = this._afd_params_from_strv (info.parameters);
+                  var email_fd = new EmailFieldDetails (email_addr, parameters);
+                  new_email_addresses.add (email_fd);
+                }
+            }
           else if (info.field_name == "fn")
             {
               new_full_name = info.field_value[0];
@@ -608,6 +654,14 @@ public class Tpf.Persona : Folks.Persona,
             }
         }
 
+      if (!Folks.Internal.equal_sets<EmailFieldDetails> (new_email_addresses,
+              this._email_addresses))
+        {
+          this._email_addresses = new_email_addresses;
+          this._email_addresses_ro = new_email_addresses.read_only_view;
+          this.notify_property ("email-addresses");
+        }
+
       if (new_full_name != this._full_name)
         {
           this._full_name = new_full_name;
diff --git a/tests/lib/telepathy/contactlist/conn.c b/tests/lib/telepathy/contactlist/conn.c
index dbd403e..6ee114c 100644
--- a/tests/lib/telepathy/contactlist/conn.c
+++ b/tests/lib/telepathy/contactlist/conn.c
@@ -411,6 +411,13 @@ conn_contact_info_properties_getter (GObject *object,
           supported_fields = g_ptr_array_new ();
 
           g_ptr_array_add (supported_fields, tp_value_array_build (4,
+              G_TYPE_STRING, "email",
+              G_TYPE_STRV, NULL,
+              G_TYPE_UINT, 0,
+              G_TYPE_UINT, G_MAXUINT32,
+              G_TYPE_INVALID));
+
+          g_ptr_array_add (supported_fields, tp_value_array_build (4,
               G_TYPE_STRING, "fn",
               G_TYPE_STRV, NULL,
               G_TYPE_UINT, 0,
diff --git a/tests/telepathy/individual-properties.vala b/tests/telepathy/individual-properties.vala
index f0bae52..ab63b8c 100644
--- a/tests/telepathy/individual-properties.vala
+++ b/tests/telepathy/individual-properties.vala
@@ -108,6 +108,8 @@ public class IndividualPropertiesTests : Folks.TestCase
                   assert ("groups" in tpf_persona.writeable_properties);
                   /* These are only writeable for the user contact */
                   assert (tpf_persona.is_user);
+                  assert (
+                      "email-addresses" in tpf_persona.writeable_properties);
                   assert (("full-name" in tpf_persona.writeable_properties));
                   assert (
                       ("phone-numbers" in tpf_persona.writeable_properties));
@@ -149,6 +151,8 @@ public class IndividualPropertiesTests : Folks.TestCase
                   assert ("groups" in tpf_persona.writeable_properties);
                   /* These are only writeable for the user contact */
                   assert (!tpf_persona.is_user);
+                  assert (
+                      !("email-addresses" in tpf_persona.writeable_properties));
                   assert (!("full-name" in tpf_persona.writeable_properties));
                   assert (
                       !("phone-numbers" in tpf_persona.writeable_properties));
@@ -156,6 +160,9 @@ public class IndividualPropertiesTests : Folks.TestCase
                   /* Check ContactInfo-provided properties */
                   assert (new PhoneFieldDetails ("+15142345678")
                       in i.phone_numbers);
+                  assert (i.full_name == "Olivier Crete");
+                  assert (new EmailFieldDetails ("olivier example com")
+                      in i.email_addresses);
                 }
             }
 
@@ -345,6 +352,7 @@ public class IndividualPropertiesTests : Folks.TestCase
   public void test_individual_properties_change_contact_info ()
     {
       var main_loop = new GLib.MainLoop (null, false);
+      this._changes_pending.add ("email-addresses");
       this._changes_pending.add ("phone-numbers");
       this._changes_pending.add ("full-name");
 
@@ -380,6 +388,9 @@ public class IndividualPropertiesTests : Folks.TestCase
       var added = changes.get_values ();
       var removed = changes.get_keys ();
 
+      var new_email_fd = new EmailFieldDetails ("cave aperturescience com");
+      new_email_fd.set_parameter (AbstractFieldDetails.PARAM_TYPE,
+          AbstractFieldDetails.PARAM_TYPE_WORK);
       var new_phone_fd = new PhoneFieldDetails ("+112233445566");
       new_phone_fd.set_parameter (AbstractFieldDetails.PARAM_TYPE,
           AbstractFieldDetails.PARAM_TYPE_HOME);
@@ -390,9 +401,21 @@ public class IndividualPropertiesTests : Folks.TestCase
           assert (i != null);
 
           /* Check properties */
+          assert (!(new_email_fd in i.email_addresses));
           assert (new_full_name != i.full_name);
           assert (!(new_phone_fd in i.phone_numbers));
 
+          i.notify["email-addresses"].connect ((s, p) =>
+              {
+                /* we can't re-use i here due to Vala's implementation */
+                var ind = (Individual) s;
+
+                if (new_email_fd in ind.email_addresses)
+                  {
+                    this._changes_pending.remove ("email-addresses");
+                  }
+              });
+
           i.notify["full-name"].connect ((s, p) =>
               {
                 /* we can't re-use i here due to Vala's implementation */
@@ -423,6 +446,10 @@ public class IndividualPropertiesTests : Folks.TestCase
             }
           assert (persona is Tpf.Persona);
 
+          var emails = new HashSet<EmailFieldDetails> (
+              (GLib.HashFunc) EmailFieldDetails.hash,
+              (GLib.EqualFunc) EmailFieldDetails.equal);
+          emails.add (new_email_fd);
           var phones = new HashSet<PhoneFieldDetails> (
               (GLib.HashFunc) PhoneFieldDetails.hash,
               (GLib.EqualFunc) PhoneFieldDetails.equal);
@@ -440,6 +467,20 @@ public class IndividualPropertiesTests : Folks.TestCase
             uncaught_errors++;
           try
             {
+              yield ((Tpf.Persona) persona).change_email_addresses (emails);
+            }
+          catch (PropertyError e0)
+            {
+              /* setting the extended info on a non-user is invalid for the
+               * Telepathy backend */
+              if (!i.is_user)
+                uncaught_errors--;
+            }
+
+          if (!i.is_user)
+            uncaught_errors++;
+          try
+            {
               yield ((Tpf.Persona) persona).change_full_name (new_full_name);
             }
           catch (PropertyError e1)



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