[folks] core: Add LocalIdDetails.change_local_ids()



commit 825694c474ae97ef05434a812c5830364270c08f
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Aug 28 21:26:24 2011 +0100

    core: Add LocalIdDetails.change_local_ids()
    
    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 |    4 ++--
 backends/eds/lib/edsf-persona.vala       |   16 ++++++++++++----
 backends/tracker/lib/trf-persona.vala    |   22 ++++++++++++++++------
 folks/individual.vala                    |    9 ++-------
 folks/local-id-details.vala              |   22 ++++++++++++++++++++++
 po/POTFILES.in                           |    1 +
 po/POTFILES.skip                         |    1 +
 7 files changed, 56 insertions(+), 19 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index d6ef062..a7d2eaf 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -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);
         }
     }
 
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 9a3168e..da82930 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -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);
     }
 
   /**
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index f48532e..fae3377 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -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 =
diff --git a/folks/individual.vala b/folks/individual.vala
index 40fd1a7..f70e1dc 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -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;
diff --git a/folks/local-id-details.vala b/folks/local-id-details.vala
index fe70df1..7f4dce6 100644
--- a/folks/local-id-details.vala
+++ b/folks/local-id-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:
  *       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."));
+    }
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 73a083e..e7c5446 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -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
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index d0d0540..1133f89 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -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



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