[folks] core: Add PhoneDetails.change_phone_numbers()



commit 22866a6481fdd49d4aa8731da302d6cf6c8e4d17
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Aug 30 19:55:32 2011 +0100

    core: Add PhoneDetails.change_phone_numbers()
    
    This allows the phone numbers of an implementing class to be changed
    asynchronously with proper error notification.
    
    Helps: bgo#657510

 backends/eds/lib/edsf-persona-store.vala |    6 +++---
 backends/eds/lib/edsf-persona.vala       |   16 ++++++++++++----
 backends/tracker/lib/trf-persona.vala    |   19 +++++++++++++++----
 folks/individual.vala                    |    8 ++------
 folks/phone-details.vala                 |   22 ++++++++++++++++++++++
 po/POTFILES.in                           |    1 +
 po/POTFILES.skip                         |    1 +
 7 files changed, 56 insertions(+), 17 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 2017035..697f02b 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -943,7 +943,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
     }
 
   internal async void _set_phones (Edsf.Persona persona,
-      Set<PhoneFieldDetails> phones)
+      Set<PhoneFieldDetails> phones) throws PropertyError
     {
       try
         {
@@ -952,9 +952,9 @@ public class Edsf.PersonaStore : Folks.PersonaStore
               E.ContactField.TEL);
           yield this._addressbook.modify_contact (contact, null);
         }
-      catch (GLib.Error error)
+      catch (GLib.Error e)
         {
-          GLib.warning ("Can't update phones: %s\n", error.message);
+          throw this.e_client_error_to_property_error ("phone-numbers", e);
         }
     }
 
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 9efbc5b..b468985 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -207,10 +207,18 @@ public class Edsf.Persona : Folks.Persona,
   public Set<PhoneFieldDetails> phone_numbers
     {
       get { return this._phone_numbers_ro; }
-      set
-        {
-          ((Edsf.PersonaStore) this.store)._set_phones (this, value);
-        }
+      set { this.change_phone_numbers.begin (value); }
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_phone_numbers (
+      Set<PhoneFieldDetails> phone_numbers) throws PropertyError
+    {
+      yield ((Edsf.PersonaStore) this.store)._set_phones (this, phone_numbers);
     }
 
   /**
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 2da08f3..ac3c170 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -98,13 +98,22 @@ public class Trf.Persona : Folks.Persona,
   /**
    * { inheritDoc}
    */
+  [CCode (notify = false)]
   public Set<PhoneFieldDetails> phone_numbers
     {
       get { return this._phone_numbers_ro; }
-      public set
-        {
-          ((Trf.PersonaStore) this.store)._set_phones (this, value);
-        }
+      set { this.change_phone_numbers.begin (value); }
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_phone_numbers (Set<PhoneFieldDetails> phone_numbers)
+      throws PropertyError
+    {
+      yield ((Trf.PersonaStore) this.store)._set_phones (this, phone_numbers);
     }
 
   /**
@@ -1136,6 +1145,8 @@ public class Trf.Persona : Folks.Persona,
 
       this._phone_numbers = phones;
       this._phone_numbers_ro = this._phone_numbers.read_only_view;
+
+      this.notify_property ("phone-numbers");
     }
 
   internal bool _add_phone (string phone, string tracker_id)
diff --git a/folks/individual.vala b/folks/individual.vala
index 9c00e43..92ab503 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -397,15 +397,11 @@ public class Folks.Individual : Object,
   /**
    * { inheritDoc}
    */
+  [CCode (notify = false)]
   public Set<PhoneFieldDetails> phone_numbers
     {
       get { return this._phone_numbers_ro; }
-      private set
-        {
-          this._phone_numbers.clear ();
-          foreach (var phone_fd in value)
-            this._phone_numbers.add (phone_fd);
-        }
+      set { this.change_phone_numbers.begin (value); } /* not writeable */
     }
 
   private HashSet<EmailFieldDetails> _email_addresses;
diff --git a/folks/phone-details.vala b/folks/phone-details.vala
index 521c1fa..41aaa50 100644
--- a/folks/phone-details.vala
+++ b/folks/phone-details.vala
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 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;
@@ -183,4 +185,24 @@ public interface Folks.PhoneDetails : Object
    * @since 0.6.0
    */
   public abstract Set<PhoneFieldDetails> phone_numbers { get; set; }
+
+  /**
+   * Change the contact's phone numbers.
+   *
+   * It's preferred to call this rather than setting
+   * { link PhoneDetails.phone_numbers} directly, as this method gives error
+   * notification and will only return once the phone numbers have been written
+   * to the relevant backing store (or the operation's failed).
+   *
+   * @param phone_numbers the set of phone numbers
+   * @throws PropertyError if setting the phone numbers failed
+   * @since UNRELEASED
+   */
+  public virtual async void change_phone_numbers (
+      Set<PhoneFieldDetails> phone_numbers) throws PropertyError
+    {
+      /* Default implementation. */
+      throw new PropertyError.NOT_WRITEABLE (
+          _("Phone numbers are not writeable on this contact."));
+    }
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e4801ce..b50a2ab 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -19,6 +19,7 @@ folks/individual-aggregator.vala
 folks/local-id-details.vala
 folks/name-details.vala
 folks/note-details.vala
+folks/phone-details.vala
 folks/postal-address-details.vala
 folks/role-details.vala
 tools/import-pidgin.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index b66348d..a467645 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -18,6 +18,7 @@ folks/individual-aggregator.c
 folks/local-id-details.c
 folks/name-details.c
 folks/note-details.c
+folks/phone-details.c
 folks/postal-address-details.c
 folks/role-details.c
 tools/import-pidgin.c



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