[folks] core: Add EmailDetails.change_email_addresses()



commit b5d1fdefc24dc5d7c5b94f1332cdb4e7dce80ade
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Aug 28 19:58:21 2011 +0100

    core: Add EmailDetails.change_email_addresses()
    
    This allows the e-mail 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    |   19 +++++++++++++++----
 folks/email-details.vala                 |   22 ++++++++++++++++++++++
 folks/individual.vala                    |    8 ++------
 po/POTFILES.in                           |    1 +
 po/POTFILES.skip                         |    1 +
 7 files changed, 57 insertions(+), 18 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index f665a5c..8ddfaa3 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -927,7 +927,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
     }
 
   internal async void _set_emails (Edsf.Persona persona,
-      Set<EmailFieldDetails> emails)
+      Set<EmailFieldDetails> emails) throws PropertyError
     {
       try
         {
@@ -936,10 +936,9 @@ public class Edsf.PersonaStore : Folks.PersonaStore
               E.ContactField.EMAIL);
           yield this._addressbook.modify_contact (contact, null);
         }
-      catch (GLib.Error error)
+      catch (GLib.Error e)
         {
-          GLib.warning ("Can't update email-addresses: %s\n",
-              error.message);
+          throw this.e_client_error_to_property_error ("email-addresses", e);
         }
     }
 
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 208b2d2..1e821d4 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -214,10 +214,19 @@ public class Edsf.Persona : Folks.Persona,
   public Set<EmailFieldDetails> email_addresses
     {
       get { return this._email_addresses_ro; }
-      set
-        {
-          ((Edsf.PersonaStore) this.store)._set_emails (this, value);
-        }
+      set { this.change_email_addresses.begin (value); }
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_email_addresses (
+      Set<EmailFieldDetails> email_addresses) throws PropertyError
+    {
+      yield ((Edsf.PersonaStore) this.store)._set_emails (this,
+          email_addresses);
     }
 
   /**
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index ea009dc..26ffdbb 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -107,13 +107,22 @@ public class Trf.Persona : Folks.Persona,
   /**
    * { inheritDoc}
    */
+  [CCode (notify = false)]
   public Set<EmailFieldDetails> email_addresses
     {
       get { return this._email_addresses_ro; }
-      public set
-        {
-          ((Trf.PersonaStore) this.store)._set_emails (this, value);
-        }
+      set { this.change_email_addresses.begin (value); }
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_email_addresses (
+      Set<EmailFieldDetails> email_addresses) throws PropertyError
+    {
+      yield ((Trf.PersonaStore) this.store)._set_emails (this, email_addresses);
     }
 
   /**
@@ -1152,6 +1161,8 @@ public class Trf.Persona : Folks.Persona,
 
       this._email_addresses = email_addresses;
       this._email_addresses_ro = this._email_addresses.read_only_view;
+
+      this.notify_property ("email-addresses");
     }
 
   private void _update_urls ()
diff --git a/folks/email-details.vala b/folks/email-details.vala
index 6b56b9f..9192f4d 100644
--- a/folks/email-details.vala
+++ b/folks/email-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
@@ -16,6 +17,7 @@
  *
  * Authors:
  *       Marco Barisione <marco barisione collabora co uk>
+ *       Philip Withnall <philip tecnocode co uk>
  */
 
 using GLib;
@@ -92,4 +94,24 @@ public interface Folks.EmailDetails : Object
    * @since 0.6.0
    */
   public abstract Set<EmailFieldDetails> email_addresses { get; set; }
+
+  /**
+   * Change the contact's set of e-mail addresses.
+   *
+   * It's preferred to call this rather than setting
+   * { link EmailDetails.email_addresses} directly, as this method gives error
+   * notification and will only return once the e-mail addresses have been
+   * written to the relevant backing store (or the operation's failed).
+   *
+   * @param email_addresses the new set of e-mail addresses
+   * @throws PropertyError if setting the e-mail addresses failed
+   * @since UNRELEASED
+   */
+  public virtual async void change_email_addresses (
+      Set<EmailFieldDetails> email_addresses) throws PropertyError
+    {
+      /* Default implementation. */
+      throw new PropertyError.NOT_WRITEABLE (
+          _("E-mail addresses are not writeable on this contact."));
+    }
 }
diff --git a/folks/individual.vala b/folks/individual.vala
index a215296..9823148 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -384,15 +384,11 @@ public class Folks.Individual : Object,
   /**
    * { inheritDoc}
    */
+  [CCode (notify = false)]
   public Set<EmailFieldDetails> email_addresses
     {
       get { return this._email_addresses_ro; }
-      private set
-        {
-          this._email_addresses.clear ();
-          foreach (var email_fd in value)
-            this._email_addresses.add (email_fd);
-        }
+      set { this.change_email_addresses.begin (value); } /* not writeable */
     }
 
   private HashSet<RoleFieldDetails> _roles;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f9bf80f..72120ca 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,6 +11,7 @@ folks/alias-details.vala
 folks/avatar-details.vala
 folks/backend-store.vala
 folks/birthday-details.vala
+folks/email-details.vala
 folks/im-details.vala
 folks/individual-aggregator.vala
 folks/postal-address-details.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index fe23b1d..321fa71 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -10,6 +10,7 @@ folks/alias-details.c
 folks/avatar-details.c
 folks/backend-store.c
 folks/birthday-details.c
+folks/email-details.c
 folks/im-details.c
 folks/individual-aggregator.c
 folks/postal-address-details.c



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