Migrate PostalAddressDetails to using AbstractFieldDetails.id
authorTravis Reitter <travis.reitter@collabora.co.uk>
Thu, 20 Oct 2011 17:23:08 +0000 (10:23 -0700)
committerTravis Reitter <travis.reitter@collabora.co.uk>
Mon, 24 Oct 2011 18:39:23 +0000 (11:39 -0700)
Deprecate PostalAddress.uid in favor of AbstractFieldDetails.id

PostalAddress.equal() now ignores PostalAddress.uid

Helps: bgo#662433 - AbstractFieldDetails.equal() is ambiguous about
checking parameters.

NEWS
backends/tracker/lib/trf-persona.vala
folks/postal-address-details.vala
tests/eds/add-persona.vala
tests/eds/postal-address-details.vala
tests/eds/set-postal-addresses.vala
tests/eds/set-properties-race.vala
tests/tracker/add-persona.vala
tests/tracker/postal-address-details-interface.vala
tests/tracker/set-postal-addresses.vala

diff --git a/NEWS b/NEWS
index 5b95fcc..24e5d8d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,10 @@ Bugs fixed:
 
 API changes:
 * Add AbstractFieldDetails.id to identify instances of details
+* Deprecate PostalAddress.uid in favor of AbstractFieldDetails.id
+
+Behavior changes:
+* PostalAddress.equal() now ignores PostalAddress.uid
 
 Overview of changes from libfolks 0.6.4 to libfolks 0.6.4.1
 =============================================================
index 8639bc7..8867684 100644 (file)
@@ -806,8 +806,9 @@ public class Trf.Persona : Folks.Persona,
               a_info[Trf.PostalAddressFields.POSTALCODE],
               a_info[Trf.PostalAddressFields.COUNTRY],
               null,
-              a_info[Trf.PostalAddressFields.TRACKER_ID]);
+              null);
           var pafd = new PostalAddressFieldDetails (pa);
+          pafd.id = a_info[Trf.PostalAddressFields.TRACKER_ID];
 
           postal_addresses.add (pafd);
         }
@@ -851,7 +852,7 @@ public class Trf.Persona : Folks.Persona,
     {
       foreach (var pafd in this._postal_addresses)
         {
-          if (pafd.value.uid == tracker_id)
+          if (pafd.id == tracker_id)
             {
               this._postal_addresses.remove (pafd);
               this.notify_property ("postal-addresses");
index e77d83f..2781b2b 100644 (file)
@@ -134,6 +134,7 @@ public class Folks.PostalAddress : Object
   /**
    * The UID of the Postal Address (if any).
    */
+  [Deprecated (since = "UNRELEASED", replacement = "AbstractFieldDetails.id")]
   public string uid
     {
       get { return _uid; }
@@ -177,6 +178,8 @@ public class Folks.PostalAddress : Object
    * components are equal (where `null` compares equal only with `null`) and
    * they have the same set of types (or both have no types).
    *
+   * This does not factor in the {@link PostalAddress.uid}.
+   *
    * @param with another postal address to compare with
    * @return `true` if the addresses are equal, `false` otherwise
    */
@@ -189,8 +192,7 @@ public class Folks.PostalAddress : Object
           this.region != with.region ||
           this.postal_code != with.postal_code ||
           this.country != with.country ||
-          this.address_format != with.address_format ||
-          this.uid != with.uid)
+          this.address_format != with.address_format)
         return false;
 
       return true;
@@ -224,6 +226,23 @@ public class Folks.PostalAddress : Object
 public class Folks.PostalAddressFieldDetails :
     AbstractFieldDetails<PostalAddress>
 {
+  private string _id;
+  /**
+   * {@inheritDoc}
+   */
+  public override string id
+    {
+      get { return this._id; }
+      set
+        {
+          this._id = (value != null ? value : "");
+
+          /* Keep the PostalAddress.uid sync'd from our id */
+          if (this._id != this.value.uid)
+            this.value.uid = this._id;
+        }
+    }
+
   /**
    * Create a new PostalAddressFieldDetails.
    *
@@ -243,6 +262,16 @@ public class Folks.PostalAddressFieldDetails :
       this.value = value;
       if (parameters != null)
         this.parameters = parameters;
+
+      /* We keep these sync'd both directions */
+      this.id = this.value.uid;
+
+      /* Keep the PostalAddress.uid sync'd to our id */
+      this.value.notify["uid"].connect ((s, p) =>
+        {
+          if (this.id != this.value.uid)
+            this.id = this.value.uid;
+        });
     }
 
   /**
index fa751e7..9b2ed02 100644 (file)
@@ -411,7 +411,7 @@ public class AddPersonaTests : Folks.TestCase
 
       foreach (var pa_fd in i.postal_addresses)
         {
-          this._address.value.uid = pa_fd.value.uid;
+          this._address.id = pa_fd.id;
           if (pa_fd.equal (this._address))
             this._properties_found.replace ("postal-address-1", true);
         }
index 807fa3f..216b950 100644 (file)
@@ -153,7 +153,7 @@ public class PostalAddressDetailsTests : Folks.TestCase
                  * Although we could get it from the 1st
                  * personas iid; there is no real need.
                  */
-                this._postal_address.value.uid = pa_fd.value.uid;
+                this._postal_address.id = pa_fd.id;
 
                 if (pa_fd.equal (this._postal_address))
                   {
index d0ffc8d..ef65ca9 100644 (file)
@@ -151,7 +151,7 @@ public class SetPostalAddressesTests : Folks.TestCase
       Folks.Individual i = (Folks.Individual) individual_obj;
       foreach (var pa_fd in i.postal_addresses)
         {
-          pa_fd.value.uid = this._pa_fd.value.uid;
+          pa_fd.id = this._pa_fd.id;
           if (pa_fd.equal (this._pa_fd))
             {
               this._found_after_update = true;
index 348af71..8179e5d 100644 (file)
@@ -159,7 +159,7 @@ public class SetPropertiesRaceTests : Folks.TestCase
           assert (pa_fd is PostalAddressFieldDetails);
           assert (pa_fd.value is PostalAddress);
 
-          pa_fd.value.uid = this._pa_fd.value.uid;
+          pa_fd.id = this._pa_fd.id;
           if (pa_fd.equal (this._pa_fd))
             {
               this._found_after_update = true;
index 4d3f928..e1d63b2 100644 (file)
@@ -482,8 +482,8 @@ public class AddPersonaTests : Folks.TestCase
 
       foreach (var pafd in i.postal_addresses)
         {
-          this._postal_address_fd.value.uid = pafd.value.uid;
-          if (pafd.value.equal (this._postal_address_fd.value))
+          this._postal_address_fd.id = pafd.id;
+          if (pafd.equal (this._postal_address_fd))
             this._properties_found.replace ("postal-address-1", true);
         }
 
index 83409ee..2166e53 100644 (file)
@@ -149,10 +149,27 @@ public class PostalAddressDetailsInterfaceTests : Folks.TestCase
                  * Although we could get it from the 1st
                  * personas iid; there is no real need.
                  */
-                this._postal_address_fd.value.uid = pafd.value.uid;
+                this._postal_address_fd.id = pafd.id;
 
                 if (pafd.value.equal (this._postal_address_fd.value))
                   {
+                    /* Ensure that setting the postal address uid directly
+                     * (which is deprecated) is equivalent to setting the id on
+                     * a PostalAddressFieldDetails directly */
+                    var pa_2 = new PostalAddress (
+                        this._postal_address_fd.value.po_box,
+                        this._postal_address_fd.value.extension,
+                        this._postal_address_fd.value.street,
+                        this._postal_address_fd.value.locality,
+                        this._postal_address_fd.value.region,
+                        this._postal_address_fd.value.postal_code,
+                        this._postal_address_fd.value.country,
+                        null,
+                        pafd.id);
+                    var pa_fd_2 = new PostalAddressFieldDetails (pa_2);
+                    assert (pafd.equal (pa_fd_2));
+                    assert (pafd.id == pa_fd_2.id);
+
                     this._found_postal_address = true;
                     this._main_loop.quit ();
                   }
index 7183f54..9c80f75 100644 (file)
@@ -159,7 +159,7 @@ public class SetPostalAddressesTests : Folks.TestCase
           foreach (var pafd in i.postal_addresses)
             {
               /* we don't care if UIDs differ for this test */
-              this._postal_address_fd.value.uid = pafd.value.uid;
+              this._postal_address_fd.id = pafd.id;
               if (pafd.value.equal (this._postal_address_fd.value))
                 {
                   this._postal_address_found = true;