core: Add EmailDetails.change_email_addresses()
authorPhilip Withnall <philip@tecnocode.co.uk>
Sun, 28 Aug 2011 18:58:21 +0000 (19:58 +0100)
committerPhilip Withnall <philip@tecnocode.co.uk>
Fri, 2 Sep 2011 18:28:28 +0000 (19:28 +0100)
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
backends/eds/lib/edsf-persona.vala
backends/tracker/lib/trf-persona.vala
folks/email-details.vala
folks/individual.vala
po/POTFILES.in
po/POTFILES.skip

index f665a5c..8ddfaa3 100644 (file)
@@ -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);
         }
     }
 
index 208b2d2..1e821d4 100644 (file)
@@ -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);
     }
 
   /**
index ea009dc..26ffdbb 100644 (file)
@@ -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 ()
index 6b56b9f..9192f4d 100644 (file)
@@ -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."));
+    }
 }
index a215296..9823148 100644 (file)
@@ -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;
index f9bf80f..72120ca 100644 (file)
@@ -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
index fe23b1d..321fa71 100644 (file)
@@ -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