core: Add LocalIdDetails.change_local_ids()
authorPhilip Withnall <philip@tecnocode.co.uk>
Sun, 28 Aug 2011 20:26:24 +0000 (21:26 +0100)
committerPhilip Withnall <philip@tecnocode.co.uk>
Fri, 2 Sep 2011 18:28:29 +0000 (19:28 +0100)
This allows the local IDs 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/individual.vala
folks/local-id-details.vala
po/POTFILES.in
po/POTFILES.skip

index d6ef062..a7d2eaf 100644 (file)
@@ -846,7 +846,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
     }
 
   internal async void _set_local_ids (Edsf.Persona persona,
-      Set<string> local_ids)
+      Set<string> local_ids) throws PropertyError
     {
       try
         {
@@ -856,7 +856,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
         }
       catch (GLib.Error e)
         {
-          GLib.warning ("Can't set local IDS: %s\n", e.message);
+          throw this.e_client_error_to_property_error ("local-ids", e);
         }
     }
 
index 9a3168e..da82930 100644 (file)
@@ -167,10 +167,18 @@ public class Edsf.Persona : Folks.Persona,
             }
           return this._local_ids_ro;
         }
-      set
-        {
-          ((Edsf.PersonaStore) this.store)._set_local_ids (this, value);
-        }
+      set { this.change_local_ids.begin (value); }
+    }
+
+  /**
+   * {@inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_local_ids (Set<string> local_ids)
+      throws PropertyError
+    {
+      yield ((Edsf.PersonaStore) this.store)._set_local_ids (this, local_ids);
     }
 
   /**
index f48532e..fae3377 100644 (file)
@@ -369,6 +369,7 @@ public class Trf.Persona : Folks.Persona,
   /**
    * IDs used to link {@link Trf.Persona}s.
    */
+  [CCode (notify = false)]
   public Set<string> local_ids
     {
       get
@@ -379,14 +380,23 @@ public class Trf.Persona : Folks.Persona,
             }
           return this._local_ids_ro;
         }
-      set
+      set { this.change_local_ids.begin (value); }
+    }
+
+  /**
+   * {@inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_local_ids (Set<string> local_ids)
+      throws PropertyError
+    {
+      if (local_ids.contains (this.uid) == false)
         {
-          if (value.contains (this.uid) == false)
-            {
-              value.add (this.uid);
-            }
-          ((Trf.PersonaStore) this.store)._set_local_ids (this, value);
+          local_ids.add (this.uid);
         }
+
+      yield ((Trf.PersonaStore) this.store)._set_local_ids (this, local_ids);
     }
 
   private HashMultiMap<string, WebServiceFieldDetails> _web_service_addresses =
index 40fd1a7..f70e1dc 100644 (file)
@@ -412,16 +412,11 @@ public class Folks.Individual : Object,
   /**
    * {@inheritDoc}
    */
+  [CCode (notify = false)]
   public Set<string> local_ids
     {
       get { return this._local_ids_ro; }
-      private set
-        {
-          this._local_ids.clear ();
-          foreach (var id in value)
-            this._local_ids.add (id);
-          this.notify_property ("local-ids");
-        }
+      set { this.change_local_ids.begin (value); } /* not writeable */
     }
 
   private DateTime? _birthday = null;
index fe70df1..7f4dce6 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:
  *       Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
+ *       Philip Withnall <philip@tecnocode.co.uk>
  */
 
 using Gee;
@@ -41,4 +43,24 @@ public interface Folks.LocalIdDetails : Object
    * @since 0.5.1
    */
   public abstract Set<string> local_ids { get; set; }
+
+  /**
+   * Change the contact's local IDs.
+   *
+   * It's preferred to call this rather than setting
+   * {@link LocalIdDetails.local_ids} directly, as this method gives error
+   * notification and will only return once the local IDs have been written to
+   * the relevant backing store (or the operation's failed).
+   *
+   * @param local_ids the set of local IDs
+   * @throws PropertyError if setting the local IDs failed
+   * @since UNRELEASED
+   */
+  public virtual async void change_local_ids (Set<string> local_ids)
+      throws PropertyError
+    {
+      /* Default implementation. */
+      throw new PropertyError.NOT_WRITEABLE (
+          _("Local IDs are not writeable on this contact."));
+    }
 }
index 73a083e..e7c5446 100644 (file)
@@ -16,6 +16,7 @@ folks/favourite-details.vala
 folks/gender-details.vala
 folks/im-details.vala
 folks/individual-aggregator.vala
+folks/local-id-details.vala
 folks/postal-address-details.vala
 folks/role-details.vala
 tools/import-pidgin.vala
index d0d0540..1133f89 100644 (file)
@@ -15,6 +15,7 @@ folks/favourite-details.c
 folks/gender-details.c
 folks/im-details.c
 folks/individual-aggregator.c
+folks/local-id-details.c
 folks/postal-address-details.c
 folks/role-details.c
 tools/import-pidgin.c