[folks] core: Add PostalAddressDetails.change_postal_addresses()



commit aa87b4cb56a9466d69c1ed87439cc860e6181379
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Aug 30 20:03:00 2011 +0100

    core: Add PostalAddressDetails.change_postal_addresses()
    
    This allows the postal addresses of an implementing class to be changed
    asynchronously with proper error notification.
    
    Helps: bgo#657510

 backends/eds/lib/edsf-persona-store.vala |    7 +++----
 backends/eds/lib/edsf-persona.vala       |   17 +++++++++++++----
 backends/tracker/lib/trf-persona.vala    |   20 ++++++++++++++++----
 folks/individual.vala                    |    8 ++------
 folks/postal-address-details.vala        |   22 ++++++++++++++++++++++
 5 files changed, 56 insertions(+), 18 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 697f02b..19273bb 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -959,7 +959,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
     }
 
   internal async void _set_postal_addresses (Edsf.Persona persona,
-      Set<PostalAddressFieldDetails> postal_fds)
+      Set<PostalAddressFieldDetails> postal_fds) throws PropertyError
     {
       try
         {
@@ -968,10 +968,9 @@ public class Edsf.PersonaStore : Folks.PersonaStore
               postal_fds);
           yield this._addressbook.modify_contact (contact, null);
         }
-      catch (GLib.Error error)
+      catch (GLib.Error e)
         {
-          GLib.warning ("Can't update postal addresses: %s\n",
-              error.message);
+          throw this.e_client_error_to_property_error ("postal-addresses", e);
         }
     }
 
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index b468985..ad69a03 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -192,10 +192,19 @@ public class Edsf.Persona : Folks.Persona,
   public Set<PostalAddressFieldDetails> postal_addresses
     {
       get { return this._postal_addresses_ro; }
-      set
-        {
-          ((Edsf.PersonaStore) this.store)._set_postal_addresses (this, value);
-        }
+      set { this.change_postal_addresses.begin (value); }
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_postal_addresses (
+      Set<PostalAddressFieldDetails> postal_addresses) throws PropertyError
+    {
+      yield ((Edsf.PersonaStore) this.store)._set_postal_addresses (this,
+          postal_addresses);
     }
 
   /**
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index ac3c170..f3b947e 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -337,13 +337,23 @@ public class Trf.Persona : Folks.Persona,
   /**
    * { inheritDoc}
    */
+  [CCode (notify = false)]
   public Set<PostalAddressFieldDetails> postal_addresses
     {
       get { return this._postal_addresses_ro; }
-      public set
-        {
-          ((Trf.PersonaStore) this.store)._set_postal_addresses (this, value);
-        }
+      set { this.change_postal_addresses.begin (value); }
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_postal_addresses (
+      Set<PostalAddressFieldDetails> postal_addresses) throws PropertyError
+    {
+      yield ((Trf.PersonaStore) this.store)._set_postal_addresses (this,
+          postal_addresses);
     }
 
   private HashMap<string, HashMap<string, string>> _tracker_ids_ims =
@@ -764,6 +774,8 @@ public class Trf.Persona : Folks.Persona,
 
       this._postal_addresses = postal_addresses;
       this._postal_addresses_ro = this._postal_addresses.read_only_view;
+
+      this.notify_property ("postal-addresses");
     }
 
  private void _update_local_ids ()
diff --git a/folks/individual.vala b/folks/individual.vala
index 92ab503..e5ac6c6 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -491,15 +491,11 @@ public class Folks.Individual : Object,
   /**
    * { inheritDoc}
    */
+  [CCode (notify = false)]
   public Set<PostalAddressFieldDetails> postal_addresses
     {
       get { return this._postal_addresses_ro; }
-      private set
-        {
-          this._postal_addresses.clear ();
-          foreach (PostalAddressFieldDetails pafd in value)
-            this._postal_addresses.add (pafd);
-        }
+      set { this.change_postal_addresses.begin (value); } /* not writeable */
     }
 
   /**
diff --git a/folks/postal-address-details.vala b/folks/postal-address-details.vala
index 47e8bef..9a45d1e 100644
--- a/folks/postal-address-details.vala
+++ b/folks/postal-address-details.vala
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Collabora Ltd.
+ * Copyright (C) 2011 Philip Withnall
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -17,6 +18,7 @@
  * Authors:
  *       Marco Barisione <marco barisione collabora co uk>
  *       Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *       Philip Withnall <philip tecnocode co uk>
  */
 
 using GLib;
@@ -280,4 +282,24 @@ public interface Folks.PostalAddressDetails : Object
    * @since 0.5.1
    */
   public abstract Set<PostalAddressFieldDetails> postal_addresses { get; set; }
+
+  /**
+   * Change the contact's postal addresses.
+   *
+   * It's preferred to call this rather than setting
+   * { link PostalAddressDetails.postal_addresses} directly, as this method
+   * gives error notification and will only return once the addresses have been
+   * written to the relevant backing store (or the operation's failed).
+   *
+   * @param postal_addresses the set of postal addresses
+   * @throws PropertyError if setting the addresses failed
+   * @since UNRELEASED
+   */
+  public virtual async void change_postal_addresses (
+      Set<PostalAddressFieldDetails> postal_addresses) throws PropertyError
+    {
+      /* Default implementation. */
+      throw new PropertyError.NOT_WRITEABLE (
+          _("Postal addresses are not writeable on this contact."));
+    }
 }



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