[folks] Support vCard-like parameters for addresses in PostalAddressDetails.



commit ac0217fabf327e3a04701d33ca75332d1a3bfa06
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Thu Jul 14 11:38:31 2011 -0700

    Support vCard-like parameters for addresses in PostalAddressDetails.
    
    This also removes the older, less-functional, less-consistent
    PostalAddress.types.
    
    Helps: bgo#653679 - Change PostalAddressDetails.postal_addresses to
    support vCard-like arbitrary parameters

 NEWS                                               |    4 +
 backends/eds/lib/edsf-persona-store.vala           |   40 +++++----
 backends/eds/lib/edsf-persona.vala                 |   20 +++--
 backends/tracker/lib/trf-persona-store.vala        |   25 +++---
 backends/tracker/lib/trf-persona.vala              |   36 ++++----
 backends/tracker/lib/trf-util.vala                 |    2 +-
 folks/individual.vala                              |   18 ++--
 folks/postal-address-details.vala                  |   93 ++++++++++++--------
 tests/eds/add-persona.vala                         |   32 ++++---
 tests/eds/postal-address-details.vala              |   29 +++---
 tests/eds/set-postal-addresses.vala                |   30 +++---
 tests/lib/eds/backend.vala                         |    3 +-
 tests/tracker/add-persona.vala                     |   29 ++++---
 .../tracker/postal-address-details-interface.vala  |   14 ++--
 tests/tracker/set-postal-addresses.vala            |   56 ++++++------
 15 files changed, 240 insertions(+), 191 deletions(-)
---
diff --git a/NEWS b/NEWS
index 829a45e..9026590 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,8 @@ Bugs fixed:
 * Bug 652657 â Allow writing to properties of all personas
 * Bug 655008 â Tidy up error handling in eds backend
 * Bug 653619 â Add company details
+* Bug 653679 â Change PostalAddressDetails.postal_addresses to support
+  vCard-like arbitrary parameters
 
 API changes:
 * Swf.Persona retains and exposes its libsocialweb Contact
@@ -54,6 +56,8 @@ API changes:
 * Add AbstractFieldDetails.equal() and hash() for better matching on structures
   which will store derived objects.
 * Add parameters as an optional argument for the FieldDetails constructor
+* Use PostalAddressFieldDetails for PostalAddressDetails.postal_addresses
+* Remove PostalAddress.types (obsoleted by PostalAddressFieldDetails.parameters)
 
 Overview of changes from libfolks 0.5.1 to libfolks 0.5.2
 =========================================================
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index dfd7f56..7e0abae 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -264,10 +264,10 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.POSTAL_ADDRESSES))
             {
-              Set<PostalAddress> postal_addresses =
-                (Set<PostalAddress>) v.get_object ();
+              Set<PostalAddressFieldDetails> postal_fds =
+                (Set<PostalAddressFieldDetails>) v.get_object ();
                 yield this._set_contact_postal_addresses (contact,
-                    postal_addresses);
+                    postal_fds);
             }
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.STRUCTURED_NAME))
@@ -814,13 +814,13 @@ public class Edsf.PersonaStore : Folks.PersonaStore
     }
 
   internal async void _set_postal_addresses (Edsf.Persona persona,
-      Set<PostalAddress> addresses)
+      Set<PostalAddressFieldDetails> postal_fds)
     {
       try
         {
           E.Contact contact = ((Edsf.Persona) persona).contact;
           yield this._set_contact_postal_addresses (contact,
-              addresses);
+              postal_fds);
           yield this._addressbook.modify_contact (contact);
         }
       catch (GLib.Error error)
@@ -831,25 +831,29 @@ public class Edsf.PersonaStore : Folks.PersonaStore
     }
 
   private async void _set_contact_postal_addresses (E.Contact contact,
-      Set<PostalAddress> addresses)
+      Set<PostalAddressFieldDetails> postal_fds)
     {
-      foreach (var pa in addresses)
+      foreach (var fd in postal_fds)
         {
-          var address = new E.ContactAddress ();
+          if (fd == null || fd.value == null)
+            continue;
 
-          address.po = pa.po_box;
-          address.ext = pa.extension;
-          address.street = pa.street;
-          address.locality = pa.locality;
-          address.region = pa.region;
-          address.code = pa.postal_code;
-          address.country = pa.country;
-          address.address_format = pa.address_format;
+          var address = new E.ContactAddress ();
 
-          if (pa.types.size > 0)
+          address.po = fd.value.po_box;
+          address.ext = fd.value.extension;
+          address.street = fd.value.street;
+          address.locality = fd.value.locality;
+          address.region = fd.value.region;
+          address.code = fd.value.postal_code;
+          address.country = fd.value.country;
+          address.address_format = fd.value.address_format;
+
+          var types = fd.parameters.get ("type");
+          if (types.size > 0)
             {
-              var pa_type = pa.types.to_array ()[0];
-              contact.set (E.Contact.field_id (pa_type), address);
+              var type = types.to_array ()[0];
+              contact.set (E.Contact.field_id (type), address);
             }
           else
             {
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 519eced..6b58eac 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -121,8 +121,8 @@ public class Edsf.Persona : Folks.Persona,
   private Set<Note> _notes_ro;
   private static HashTable<string, E.ContactField> _im_eds_map = null;
 
-  private HashSet<PostalAddress> _postal_addresses;
-  private Set<PostalAddress> _postal_addresses_ro;
+  private HashSet<PostalAddressFieldDetails> _postal_addresses;
+  private Set<PostalAddressFieldDetails> _postal_addresses_ro;
 
   private HashSet<string> _local_ids;
   private Set<string> _local_ids_ro;
@@ -177,7 +177,7 @@ public class Edsf.Persona : Folks.Persona,
    *
    * @since 0.5.UNRELEASED
    */
-  public Set<PostalAddress> postal_addresses
+  public Set<PostalAddressFieldDetails> postal_addresses
     {
       get { return this._postal_addresses_ro; }
       set
@@ -490,7 +490,9 @@ public class Edsf.Persona : Folks.Persona,
       this._notes_ro = this._notes.read_only_view;
       this._urls = new HashSet<FieldDetails> ();
       this._urls_ro = this._urls.read_only_view;
-      this._postal_addresses = new HashSet<PostalAddress> ();
+      this._postal_addresses = new HashSet<PostalAddressFieldDetails> (
+          (GLib.HashFunc) PostalAddressFieldDetails.hash,
+          (GLib.EqualFunc) PostalAddressFieldDetails.equal);
       this._postal_addresses_ro = this._postal_addresses.read_only_view;
       this._local_ids = new HashSet<string> ();
       this._local_ids_ro = this._local_ids.read_only_view;
@@ -955,13 +957,13 @@ public class Edsf.Persona : Folks.Persona,
               var po_box = a.po;
               var region = a.region;
               var street = a.street;
-              var types = new HashSet<string> ();
-              types.add (afield);
 
-              PostalAddress pa = new PostalAddress (po_box, extension, street,
+              var pa = new PostalAddress (po_box, extension, street,
                   locality, region, postal_code, country,
-                  address_format, types, null);
-              this._postal_addresses.add (pa);
+                  address_format, null);
+              var pa_fd = new PostalAddressFieldDetails (pa);
+              pa_fd.add_parameter ("type", afield);
+              this._postal_addresses.add (pa_fd);
             }
         }
 
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 1556286..4ef6fc2 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -580,12 +580,13 @@ public class Trf.PersonaStore : Folks.PersonaStore
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.POSTAL_ADDRESSES))
             {
-              Set<PostalAddress> postal_addresses =
-                (Set<PostalAddress>) v.get_object ();
+              Set<PostalAddressFieldDetails> postal_addresses =
+                (Set<PostalAddressFieldDetails>) v.get_object ();
 
               int postal_cnt = 0;
-              foreach (var pa in postal_addresses)
+              foreach (var pafd in postal_addresses)
                 {
+                  var pa = pafd.value;
                   var postal_affl = "_:postal_affl%d".printf (postal_cnt);
                   var postal = "_:postal%d".printf (postal_cnt);
                   builder.subject (postal);
@@ -1471,8 +1472,8 @@ public class Trf.PersonaStore : Folks.PersonaStore
                     }
                 }
 
-              if (affl_info.postal_address != null)
-                p._add_postal_address (affl_info.postal_address);
+              if (affl_info.postal_address_fd != null)
+                p._add_postal_address (affl_info.postal_address_fd);
 
               if (affl_info.phone != null)
                 p._add_phone (affl_info.phone, e.object_id.to_string ());
@@ -1715,11 +1716,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
               var country = cursor.get_string
                   (Trf.AfflInfoFields.AFFL_COUNTRY).dup ();
 
-              var types = new HashSet<string> ();
-
-              affl_info.postal_address = new Folks.PostalAddress (
+              var postal_address = new Folks.PostalAddress (
                   po_box, extension, street, locality, region, postal_code,
-                  country, null, types, affl_info.affl_tracker_id);
+                  country, null, affl_info.affl_tracker_id);
+              affl_info.postal_address_fd =
+                  new Folks.PostalAddressFieldDetails (postal_address);
 
               affl_info.email = cursor.get_string
                   (Trf.AfflInfoFields.AFFL_EMAIL).dup ();
@@ -2021,7 +2022,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
     }
 
   internal async void _set_postal_addresses (Folks.Persona persona,
-      Set<PostalAddress> postal_addresses)
+      Set<PostalAddressFieldDetails> postal_addresses)
     {
        yield this._set_attrib_set (persona, postal_addresses,
           Trf.Attrib.POSTAL_ADDRESSES);
@@ -2349,6 +2350,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
       foreach (var p in attribs)
         {
           AbstractFieldDetails fd = null;
+          PostalAddressFieldDetails pafd = null;
           PostalAddress pa = null;
 
           string affl = "_:a%d".printf (i);
@@ -2357,7 +2359,8 @@ public class Trf.PersonaStore : Folks.PersonaStore
           switch (what)
             {
               case Trf.Attrib.POSTAL_ADDRESSES:
-                pa = (PostalAddress) p;
+                pafd = (PostalAddressFieldDetails) p;
+                pa = pafd.value;
                 attr = "_:p%d".printf (i);
                 builder.subject (attr);
                 builder.predicate ("a");
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 338d63f..e69fc12 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -259,13 +259,13 @@ public class Trf.Persona : Folks.Persona,
         }
     }
 
-  private HashSet<PostalAddress> _postal_addresses;
-  private Set<PostalAddress> _postal_addresses_ro;
+  private HashSet<PostalAddressFieldDetails> _postal_addresses;
+  private Set<PostalAddressFieldDetails> _postal_addresses_ro;
 
   /**
    * { inheritDoc}
    */
-  public Set<PostalAddress> postal_addresses
+  public Set<PostalAddressFieldDetails> postal_addresses
     {
       get { return this._postal_addresses_ro; }
       public set
@@ -421,7 +421,9 @@ public class Trf.Persona : Folks.Persona,
       this._urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
           (GLib.EqualFunc) FieldDetails.equal);
       this._urls_ro = this._urls.read_only_view;
-      this._postal_addresses = new HashSet<PostalAddress> ();
+      this._postal_addresses = new HashSet<PostalAddressFieldDetails> (
+          (GLib.HashFunc) PostalAddressFieldDetails.hash,
+          (GLib.EqualFunc) PostalAddressFieldDetails.equal);
       this._postal_addresses_ro = this._postal_addresses.read_only_view;
       this._local_ids = new HashSet<string> ();
       this._local_ids_ro = this._local_ids.read_only_view;
@@ -574,7 +576,9 @@ public class Trf.Persona : Folks.Persona,
           return;
         }
 
-      var postal_addresses = new HashSet<PostalAddress> ();
+      var postal_addresses = new HashSet<PostalAddressFieldDetails> (
+          (GLib.HashFunc) PostalAddressFieldDetails.hash,
+          (GLib.EqualFunc) PostalAddressFieldDetails.equal);
 
       string[] addresses_a = postal_field.split ("\n");
 
@@ -594,8 +598,6 @@ public class Trf.Persona : Folks.Persona,
           if (address_empty)
             continue;
 
-          var types = new HashSet<string> ();
-
           var pa = new PostalAddress (a_info[Trf.PostalAddressFields.POBOX],
               a_info[Trf.PostalAddressFields.EXTENDED_ADDRESS],
               a_info[Trf.PostalAddressFields.STREET_ADDRESS],
@@ -603,10 +605,11 @@ public class Trf.Persona : Folks.Persona,
               a_info[Trf.PostalAddressFields.REGION],
               a_info[Trf.PostalAddressFields.POSTALCODE],
               a_info[Trf.PostalAddressFields.COUNTRY],
-              null, types,
+              null,
               a_info[Trf.PostalAddressFields.TRACKER_ID]);
+          var pafd = new PostalAddressFieldDetails (pa);
 
-          postal_addresses.add (pa);
+          postal_addresses.add (pafd);
         }
 
       this._postal_addresses = postal_addresses;
@@ -626,28 +629,29 @@ public class Trf.Persona : Folks.Persona,
       this._set_local_ids (local_ids);
     }
 
-  internal bool _add_postal_address (PostalAddress postal_address)
+  internal bool _add_postal_address (
+      PostalAddressFieldDetails postal_address_fd)
     {
-      foreach (var pa in this._postal_addresses)
+      foreach (var pafd_cur in this._postal_addresses)
         {
-          if (postal_address.equal (pa))
+          if (postal_address_fd.value.equal (pafd_cur.value))
             {
               return false;
             }
         }
 
-      this._postal_addresses.add (postal_address);
+      this._postal_addresses.add (postal_address_fd);
       this.notify_property ("postal-addresses");
       return true;
     }
 
   internal bool _remove_postal_address (string tracker_id)
     {
-      foreach (var pa in this._postal_addresses)
+      foreach (var pafd in this._postal_addresses)
         {
-          if (pa.uid == tracker_id)
+          if (pafd.value.uid == tracker_id)
             {
-              this._postal_addresses.remove (pa);
+              this._postal_addresses.remove (pafd);
               this.notify_property ("postal-addresses");
               return true;
             }
diff --git a/backends/tracker/lib/trf-util.vala b/backends/tracker/lib/trf-util.vala
index 1270b5f..5f4849a 100644
--- a/backends/tracker/lib/trf-util.vala
+++ b/backends/tracker/lib/trf-util.vala
@@ -56,7 +56,7 @@ internal class Trf.AfflInfo : Object
 
   public string role { get; set; }
 
-  public Folks.PostalAddress postal_address;
+  public Folks.PostalAddressFieldDetails postal_address_fd;
 
   public string email { get; set; }
 
diff --git a/folks/individual.vala b/folks/individual.vala
index 6b1782d..d4f8595 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -426,20 +426,20 @@ public class Folks.Individual : Object,
         }
     }
 
-  private HashSet<PostalAddress> _postal_addresses;
-  private Set<PostalAddress> _postal_addresses_ro;
+  private HashSet<PostalAddressFieldDetails> _postal_addresses;
+  private Set<PostalAddressFieldDetails> _postal_addresses_ro;
 
   /**
    * { inheritDoc}
    */
-  public Set<PostalAddress> postal_addresses
+  public Set<PostalAddressFieldDetails> postal_addresses
     {
       get { return this._postal_addresses_ro; }
       private set
         {
           this._postal_addresses.clear ();
-          foreach (PostalAddress pa in value)
-            this._postal_addresses.add (pa);
+          foreach (PostalAddressFieldDetails pafd in value)
+            this._postal_addresses.add (pafd);
         }
     }
 
@@ -710,7 +710,9 @@ public class Folks.Individual : Object,
       this._roles_ro = this._roles.read_only_view;
       this._local_ids = new HashSet<string> ();
       this._local_ids_ro = this._local_ids.read_only_view;
-      this._postal_addresses = new HashSet<PostalAddress> ();
+      this._postal_addresses = new HashSet<PostalAddressFieldDetails> (
+          (GLib.HashFunc) PostalAddressFieldDetails.hash,
+          (GLib.EqualFunc) PostalAddressFieldDetails.equal);
       this._postal_addresses_ro = this._postal_addresses.read_only_view;
       this._notes = new HashSet<Note>
           ((GLib.HashFunc) Note.hash, (GLib.EqualFunc) Note.equal);
@@ -1458,8 +1460,8 @@ public class Folks.Individual : Object,
           var address_details = persona as PostalAddressDetails;
           if (address_details != null)
             {
-              foreach (var pa in address_details.postal_addresses)
-                this._postal_addresses.add (pa);
+              foreach (var pafd in address_details.postal_addresses)
+                this._postal_addresses.add (pafd);
             }
         }
 
diff --git a/folks/postal-address-details.vala b/folks/postal-address-details.vala
index ebcc065..6b50eef 100644
--- a/folks/postal-address-details.vala
+++ b/folks/postal-address-details.vala
@@ -128,30 +128,6 @@ public class Folks.PostalAddress : Object
       construct set { _address_format = (value != null ? value : ""); }
     }
 
-  private HashSet<string> _types;
-  private Set<string> _types_ro;
-
-  /**
-   * The types of the address.
-   *
-   * The types of address, for instance an address can be a home or work
-   * address.
-   */
-  public Set<string> types
-    {
-      get { return this._types_ro; }
-      construct set
-        {
-          this._types = new HashSet<string> ();
-          if (value != null)
-            {
-              this._types_ro = this._types.read_only_view;
-              foreach (var type in value)
-                this._types.add (type);
-            }
-        }
-    }
-
   private string _uid = "";
   /**
    * The UID of the Postal Address (if any).
@@ -181,7 +157,7 @@ public class Folks.PostalAddress : Object
    */
   public PostalAddress (string? po_box, string? extension, string? street,
       string? locality, string? region, string? postal_code, string? country,
-      string? address_format, Set<string>? types, string? uid)
+      string? address_format, string? uid)
     {
       Object (po_box:         po_box,
               extension:      extension,
@@ -191,7 +167,6 @@ public class Folks.PostalAddress : Object
               postal_code:    postal_code,
               country:        country,
               address_format: address_format,
-              types:          types,
               uid:            uid);
     }
 
@@ -213,18 +188,9 @@ public class Folks.PostalAddress : Object
           this.postal_code != with.postal_code ||
           this.country != with.country ||
           this.address_format != with.address_format ||
-          this.types.size != with.types.size ||
           this.uid != with.uid)
         return false;
 
-      foreach (var type in this.types)
-        {
-          if (with.types.contains (type) == false)
-            {
-              return false;
-            }
-        }
-
       return true;
     }
 
@@ -245,6 +211,61 @@ public class Folks.PostalAddress : Object
 }
 
 /**
+ * Object representing a PostalAddress value that can have some parameters
+ * associated with it.
+ *
+ * See { link Folks.AbstractFieldDetails}.
+ *
+ * @since UNRELEASED
+ */
+public class Folks.PostalAddressFieldDetails :
+    AbstractFieldDetails<PostalAddress>
+{
+  /**
+   * Create a new PostalAddressFieldDetails.
+   *
+   * @param value the value of the field
+   * @param parameters initial parameters. See
+   * { link AbstractFieldDetails.parameters}. A `null` value is equivalent to an
+   * empty map of parameters.
+   *
+   *
+   * @return a new PostalAddressFieldDetails
+   *
+   * @since UNRELEASED
+   */
+  public PostalAddressFieldDetails (PostalAddress value,
+      MultiMap<string, string>? parameters = null)
+    {
+      this.value = value;
+      if (parameters != null)
+        this.parameters = parameters;
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public override bool equal (AbstractFieldDetails<PostalAddress> that)
+    {
+      /* This is fairly-dumb but smart matching is an i10n nightmare. */
+      return this.value.to_string () == that.value.to_string ();
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public override uint hash ()
+    {
+      /* This is basic because smart matching is very hard (see equal()). */
+      return str_hash (this.value.to_string ());
+    }
+}
+
+/**
  * Interface for classes that can provide postal addresses, such as
  * { link Persona} and { link Individual}.
  */
@@ -257,5 +278,5 @@ public interface Folks.PostalAddressDetails : Object
    *
    * @since 0.5.1
    */
-  public abstract Set<PostalAddress> postal_addresses { get; set; }
+  public abstract Set<PostalAddressFieldDetails> postal_addresses { get; set; }
 }
diff --git a/tests/eds/add-persona.vala b/tests/eds/add-persona.vala
index f4fc660..c2f98a5 100644
--- a/tests/eds/add-persona.vala
+++ b/tests/eds/add-persona.vala
@@ -36,7 +36,7 @@ public class AddPersonaTests : Folks.TestCase
   private string _im_addr_2;
   private string _phone_1;
   private string _phone_2;
-  private PostalAddress _address;
+  private PostalAddressFieldDetails _address;
   private string _po_box = "12345";
   private string _locality = "locality";
   private string _postal_code = "code";
@@ -80,11 +80,11 @@ public class AddPersonaTests : Folks.TestCase
       this._family_name = "family";
       this._given_name = "given";
 
-      var types =  new HashSet<string> ();
-      types.add (Edsf.Persona.address_fields[0]);
-      this._address = new PostalAddress (this._po_box,
+      var pa = new PostalAddress (this._po_box,
           this._extension, this._street, this._locality, this._region,
-          this._postal_code, this._country, null, types, null);
+          this._postal_code, this._country, null, null);
+      this._address = new PostalAddressFieldDetails (pa);
+      this._address.add_parameter ("type", Edsf.Persona.address_fields[0]);
 
       this._properties_found = new HashTable<string, bool>
           (str_hash, str_equal);
@@ -192,15 +192,17 @@ public class AddPersonaTests : Folks.TestCase
           (owned) v5);
 
       Value? v6 = Value (typeof (Set<PostalAddress>));
-      var postal_addresses = new HashSet<PostalAddress> ();
+      var pa_fds = new HashSet<PostalAddressFieldDetails> (
+          (GLib.HashFunc) PostalAddressFieldDetails.hash,
+          (GLib.EqualFunc) PostalAddressFieldDetails.equal);
 
-      var types =  new HashSet<string> ();
-      types.add (Edsf.Persona.address_fields[0]);
-      PostalAddress postal_a = new PostalAddress (this._po_box,
+      PostalAddress pa_a = new PostalAddress (this._po_box,
           this._extension, this._street, this._locality, this._region,
-          this._postal_code, this._country, null, types, null);
-      postal_addresses.add (postal_a);
-      v6.set_object (postal_addresses);
+          this._postal_code, this._country, null, null);
+      var pa_fd_a = new PostalAddressFieldDetails (pa_a);
+      pa_fd_a.add_parameter ("types", Edsf.Persona.address_fields[0]);
+      pa_fds.add (pa_fd_a);
+      v6.set_object (pa_fds);
       details.insert (
           Folks.PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES),
           (owned) v6);
@@ -332,10 +334,10 @@ public class AddPersonaTests : Folks.TestCase
             }
         }
 
-      foreach (var pa in i.postal_addresses)
+      foreach (var pa_fd in i.postal_addresses)
         {
-          this._address.uid = pa.uid;
-          if (pa.equal (this._address))
+          this._address.value.uid = pa_fd.value.uid;
+          if (pa_fd.equal (this._address))
             this._properties_found.replace ("postal-address-1", true);
         }
 
diff --git a/tests/eds/postal-address-details.vala b/tests/eds/postal-address-details.vala
index b322425..55b2597 100644
--- a/tests/eds/postal-address-details.vala
+++ b/tests/eds/postal-address-details.vala
@@ -33,7 +33,7 @@ public class PostalAddressDetailsTests : Folks.TestCase
   private string _extended = "example extended address";
   private string _country = "example country";
   private string _region = "example region";
-  private PostalAddress _postal_address;
+  private PostalAddressFieldDetails _postal_address;
   private bool _found_postal_address;
   private string _fullname;
 
@@ -64,9 +64,7 @@ public class PostalAddressDetailsTests : Folks.TestCase
       this._fullname = "persona #1";
       Value? v;
 
-      var types = new HashSet<string> ();
-      types.add (Edsf.Persona.address_fields[0]);
-      this._postal_address = new PostalAddress (
+      var pa = new PostalAddress (
            this._pobox,
            this._extended,
            this._street,
@@ -74,14 +72,15 @@ public class PostalAddressDetailsTests : Folks.TestCase
            this._region,
            this._postalcode,
            this._country,
-           null, types, "eds_id");
+           null, "eds_id");
+      this._postal_address = new PostalAddressFieldDetails (pa);
+      this._postal_address.add_parameter ("type",
+          Edsf.Persona.address_fields[0]);
 
       v = Value (typeof (string));
       v.set_string (this._fullname);
       c1.set ("full_name", (owned) v);
-      var types1 = new HashSet<string> ();
-      types1.add (Edsf.Persona.address_fields[0]);
-      var postal_address_copy = new PostalAddress (
+      var pa_copy = new PostalAddress (
            this._pobox,
            this._extended,
            this._street,
@@ -89,9 +88,11 @@ public class PostalAddressDetailsTests : Folks.TestCase
            this._region,
            this._postalcode,
            this._country,
-           null, types1, "eds_id");
-      v = Value (typeof (PostalAddress));
-      v.set_object (postal_address_copy);
+           null, "eds_id");
+      var pa_fd_copy = new PostalAddressFieldDetails (pa_copy);
+      pa_fd_copy.add_parameter ("type", Edsf.Persona.address_fields[0]);
+      v = Value (typeof (PostalAddressFieldDetails));
+      v.set_object (pa_fd_copy);
       c1.set (Edsf.Persona.address_fields[0], (owned) v);
 
       this._eds_backend.add_contact (c1);
@@ -143,15 +144,15 @@ public class PostalAddressDetailsTests : Folks.TestCase
         {
           if (i.full_name == this._fullname)
             {
-              foreach (var p in i.postal_addresses)
+              foreach (var pa_fd in i.postal_addresses)
               {
                 /* We copy the uid - we don't know it.
                  * Although we could get it from the 1st
                  * personas iid; there is no real need.
                  */
-                this._postal_address.uid = p.uid;
+                this._postal_address.value.uid = pa_fd.value.uid;
 
-                if (p.equal (this._postal_address))
+                if (pa_fd.equal (this._postal_address))
                   {
                     this._found_postal_address = true;
                     this._main_loop.quit ();
diff --git a/tests/eds/set-postal-addresses.vala b/tests/eds/set-postal-addresses.vala
index dc9356c..4dbd648 100644
--- a/tests/eds/set-postal-addresses.vala
+++ b/tests/eds/set-postal-addresses.vala
@@ -29,7 +29,7 @@ public class SetPostalAddressesTests : Folks.TestCase
   private GLib.MainLoop _main_loop;
   private bool _found_before_update;
   private bool _found_after_update;
-  private PostalAddress _postal;
+  private PostalAddressFieldDetails _pa_fd;
 
   public SetPostalAddressesTests ()
     {
@@ -56,11 +56,11 @@ public class SetPostalAddressesTests : Folks.TestCase
       Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
       this._main_loop = new GLib.MainLoop (null, false);
       Value? v;
-      var types = new HashSet<string> ();
-      types.add ("address_other");
-      this._postal = new PostalAddress ("123", "extension", "street",
+      var pa = new PostalAddress ("123", "extension", "street",
           "locality", "region", "postal code", "country", "",
-          types, "123");
+          "123");
+      this._pa_fd = new PostalAddressFieldDetails (pa);
+      this._pa_fd.add_parameter ("type", "address_other");
 
       this._found_before_update = false;
       this._found_after_update = false;
@@ -123,14 +123,14 @@ public class SetPostalAddressesTests : Folks.TestCase
 
               foreach (var p in i.personas)
                 {
-                  var addresses = new HashSet<PostalAddress> ();
-                  var types = new HashSet<string> ();
-                  types.add ("address_other");
-                  var addr1 = new PostalAddress ("123", "extension", "street",
+                  var pa_fds = new HashSet<PostalAddressFieldDetails> ();
+                  var pa_1 = new PostalAddress ("123", "extension", "street",
                       "locality", "region", "postal code", "country", "format",
-                      types, "123");
-                  addresses.add (addr1);
-                  ((PostalAddressDetails) p).postal_addresses = addresses;
+                      "123");
+                  var pa_fd_1 = new PostalAddressFieldDetails (pa_1);
+                  pa_fd_1.add_parameter ("type", "address_other");
+                  pa_fds.add (pa_fd_1);
+                  ((PostalAddressDetails) p).postal_addresses = pa_fds;
                 }
             }
         }
@@ -141,10 +141,10 @@ public class SetPostalAddressesTests : Folks.TestCase
   private void _notify_postal_addresses_cb (Object individual_obj, ParamSpec ps)
     {
       Folks.Individual i = (Folks.Individual) individual_obj;
-      foreach (var p in i.postal_addresses)
+      foreach (var pa_fd in i.postal_addresses)
         {
-          p.uid = this._postal.uid;
-          if (p.equal (this._postal))
+          pa_fd.value.uid = this._pa_fd.value.uid;
+          if (pa_fd.equal (this._pa_fd))
             {
               this._found_after_update = true;
               this._main_loop.quit ();
diff --git a/tests/lib/eds/backend.vala b/tests/lib/eds/backend.vala
index fe4902c..90de27f 100644
--- a/tests/lib/eds/backend.vala
+++ b/tests/lib/eds/backend.vala
@@ -225,7 +225,8 @@ public class EdsTest.Backend
             }
           else if (k == Edsf.Persona.address_fields[0])
             {
-              var pa = (PostalAddress) c.get (k).get_object ();
+              var pa_fd = (PostalAddressFieldDetails) c.get (k).get_object ();
+              var pa = (PostalAddress) pa_fd.value;
               var address = new E.ContactAddress ();
               address.po = pa.po_box;
               address.ext = pa.extension;
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index 7a0df3b..56efcc2 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -48,7 +48,7 @@ public class AddPersonaTests : Folks.TestCase
   private string _title_1;
   private string _organisation_1;
   private string _role_1;
-  private PostalAddress _address;
+  private PostalAddressFieldDetails _postal_address_fd;
   private string _po_box = "12345";
   private string _locality = "locality";
   private string _postal_code = "code";
@@ -100,10 +100,10 @@ public class AddPersonaTests : Folks.TestCase
       this._organisation_1 = "Example Inc.";
       this._role_1 = "Role";
 
-      var types =  new HashSet<string> ();
-      this._address = new PostalAddress (this._po_box,
+      var address = new PostalAddress (this._po_box,
           this._extension, this._street, this._locality, this._region,
-          this._postal_code, this._country, null, types, null);
+          this._postal_code, this._country, null, null);
+      this._postal_address_fd = new PostalAddressFieldDetails (address);
 
       TimeVal t = TimeVal ();
       t.from_iso8601 (this._birthday);
@@ -273,14 +273,17 @@ public class AddPersonaTests : Folks.TestCase
       details.insert (Folks.PersonaStore.detail_key (PersonaDetail.ROLES),
           (owned) v12);
 
-      Value? v13 = Value (typeof (Set<PostalAddress>));
-      var postal_addresses = new HashSet<PostalAddress> ();
+      Value? v13 = Value (typeof (Set<PostalAddressFieldDetails>));
+      var postal_addresses = new HashSet<PostalAddressFieldDetails> (
+          (GLib.HashFunc) PostalAddressFieldDetails.hash,
+          (GLib.EqualFunc) PostalAddressFieldDetails.equal);
 
-      var types =  new HashSet<string> ();
-      PostalAddress postal_a = new PostalAddress (this._po_box,
+
+      var postal_a = new PostalAddress (this._po_box,
           this._extension, this._street, this._locality, this._region,
-          this._postal_code, this._country, null, types, null);
-      postal_addresses.add (postal_a);
+          this._postal_code, this._country, null, null);
+      var postal_a_fd = new PostalAddressFieldDetails (postal_a);
+      postal_addresses.add (postal_a_fd);
       v13.set_object (postal_addresses);
       details.insert (
           Folks.PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES),
@@ -474,10 +477,10 @@ public class AddPersonaTests : Folks.TestCase
             }
         }
 
-      foreach (var pa in i.postal_addresses)
+      foreach (var pafd in i.postal_addresses)
         {
-          this._address.uid = pa.uid;
-          if (pa.equal (this._address))
+          this._postal_address_fd.value.uid = pafd.value.uid;
+          if (pafd.value.equal (this._postal_address_fd.value))
             this._properties_found.replace ("postal-address-1", true);
         }
 
diff --git a/tests/tracker/postal-address-details-interface.vala b/tests/tracker/postal-address-details-interface.vala
index e35138c..1dddf50 100644
--- a/tests/tracker/postal-address-details-interface.vala
+++ b/tests/tracker/postal-address-details-interface.vala
@@ -38,7 +38,7 @@ public class PostalAddressDetailsInterfaceTests : Folks.TestCase
   private string _extended = "example extended address";
   private string _country = "example country";
   private string _region = "example region";
-  private PostalAddress _postal_address;
+  private PostalAddressFieldDetails _postal_address_fd;
   private bool _found_postal_address;
   private string _fullname;
 
@@ -67,8 +67,7 @@ public class PostalAddressDetailsInterfaceTests : Folks.TestCase
       this._fullname = "persona #1";
       c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname);
 
-      var types = new HashSet<string> ();
-      this._postal_address = new PostalAddress (
+      var pa = new PostalAddress (
            this._pobox,
            this._extended,
            this._street,
@@ -76,7 +75,8 @@ public class PostalAddressDetailsInterfaceTests : Folks.TestCase
            this._region,
            this._postalcode,
            this._country,
-           null, types, "tracker_id");
+           null, "tracker_id");
+      this._postal_address_fd = new PostalAddressFieldDetails (pa);
 
       // nco:pobox, nco:district, nco:county, nco:locality, nco:postalcode,
       // nco:streetAddress
@@ -142,15 +142,15 @@ public class PostalAddressDetailsInterfaceTests : Folks.TestCase
         {
           if (i.full_name == this._fullname)
             {
-              foreach (var p in i.postal_addresses)
+              foreach (var pafd in i.postal_addresses)
               {
                 /* We copy the tracker_id - we don't know it.
                  * Although we could get it from the 1st
                  * personas iid; there is no real need.
                  */
-                this._postal_address.uid = p.uid;
+                this._postal_address_fd.value.uid = pafd.value.uid;
 
-                if (p.equal (this._postal_address))
+                if (pafd.value.equal (this._postal_address_fd.value))
                   {
                     this._found_postal_address = true;
                     this._main_loop.quit ();
diff --git a/tests/tracker/set-postal-addresses.vala b/tests/tracker/set-postal-addresses.vala
index 7e36e6c..1943679 100644
--- a/tests/tracker/set-postal-addresses.vala
+++ b/tests/tracker/set-postal-addresses.vala
@@ -30,7 +30,7 @@ public class SetPostalAddressesTests : Folks.TestCase
   private IndividualAggregator _aggregator;
   private string _persona_fullname;
   private bool _postal_address_found;
-  private PostalAddress _address;
+  private PostalAddressFieldDetails _postal_address_fd;
 
   public SetPostalAddressesTests ()
     {
@@ -59,16 +59,16 @@ public class SetPostalAddressesTests : Folks.TestCase
       c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
       this._tracker_backend.add_contact (c1);
 
-      var types =  new HashSet<string> ();
-      this._address = new PostalAddress (null, null, null, null, null,
-          null, null, null, types, null);
-      this._address.po_box = "12345";
-      this._address.locality = "locality";
-      this._address.postal_code = "code";
-      this._address.street = "some street";
-      this._address.extension = "some extension";
-      this._address.country = "some country";
-      this._address.region = "some region";
+      var pa = new PostalAddress (null, null, null, null, null,
+          null, null, null, null);
+      pa.po_box = "12345";
+      pa.locality = "locality";
+      pa.postal_code = "code";
+      pa.street = "some street";
+      pa.extension = "some extension";
+      pa.country = "some country";
+      pa.region = "some region";
+      this._postal_address_fd = new PostalAddressFieldDetails (pa);
 
       this._tracker_backend.set_up ();
 
@@ -119,19 +119,21 @@ public class SetPostalAddressesTests : Folks.TestCase
             {
               i.notify["postal-addresses"].connect (this._notify_postal_cb);
 
-              var types =  new HashSet<string> ();
-              var addresses = new HashSet<PostalAddress> ();
-              var pa = new Folks.PostalAddress (null, null, null, null, null,
-                null, null, null, types, null);
-              pa.po_box = this._address.po_box;
-              pa.locality = this._address.locality;
-              pa.postal_code =this._address.postal_code;
-              pa.street = this._address.street;
-              pa.extension = this._address.extension;
-              pa.country = this._address.country;
-              pa.region  = this._address.region;
-
-              addresses.add (pa);
+              var addresses = new HashSet<PostalAddressFieldDetails> (
+                  (GLib.HashFunc) PostalAddressFieldDetails.hash,
+                  (GLib.EqualFunc) PostalAddressFieldDetails.equal);
+              var pa = new PostalAddress (null, null, null, null, null,
+                null, null, null, null);
+              pa.po_box = this._postal_address_fd.value.po_box;
+              pa.locality = this._postal_address_fd.value.locality;
+              pa.postal_code =this._postal_address_fd.value.postal_code;
+              pa.street = this._postal_address_fd.value.street;
+              pa.extension = this._postal_address_fd.value.extension;
+              pa.country = this._postal_address_fd.value.country;
+              pa.region  = this._postal_address_fd.value.region;
+              var pafd = new PostalAddressFieldDetails (pa);
+
+              addresses.add (pafd);
 
               foreach (var p in i.personas)
                 {
@@ -148,11 +150,11 @@ public class SetPostalAddressesTests : Folks.TestCase
       Folks.Individual i = (Folks.Individual) individual_obj;
       if (i.full_name == this._persona_fullname)
         {
-          foreach (var p in i.postal_addresses)
+          foreach (var pafd in i.postal_addresses)
             {
               /* we don't care if UIDs differ for this test */
-              this._address.uid = p.uid;
-              if (p.equal (this._address))
+              this._postal_address_fd.value.uid = pafd.value.uid;
+              if (pafd.value.equal (this._postal_address_fd.value))
                 {
                   this._postal_address_found = true;
                   this._main_loop.quit ();



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