[folks] Support nickname writability in the EDS backend.



commit b01fae00ac721b89c4cce6e3eb353b8f0bbe98b8
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Tue Jul 19 09:03:59 2011 -0700

    Support nickname writability in the EDS backend.
    
    Helps: bgo#652048 â Make Individual.nickname writeable

 backends/eds/lib/edsf-persona-store.vala         |   14 ++++
 backends/eds/lib/edsf-persona.vala               |   14 +++-
 tests/eds/Makefile.am                            |   10 +-
 tests/eds/{set-full-name.vala => set-names.vala} |   88 ++++++++++++++++------
 4 files changed, 98 insertions(+), 28 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 35caad7..67fef06 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -695,6 +695,20 @@ public class Edsf.PersonaStore : Folks.PersonaStore
         }
     }
 
+  internal async void _set_nickname (Edsf.Persona persona, string nickname)
+    {
+      try
+        {
+          E.Contact contact = ((Edsf.Persona) persona).contact;
+          contact.set (E.Contact.field_id ("nickname"), nickname);
+          yield this._addressbook.modify_contact (contact);
+        }
+      catch (GLib.Error error)
+        {
+          GLib.warning ("Can't update nickname: %s\n", error.message);
+        }
+    }
+
   internal async void _set_notes (Edsf.Persona persona,
       Set<Note> notes)
     {
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 36b6e41..d06928c 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -250,7 +250,19 @@ public class Edsf.Persona : Folks.Persona,
    *
    * @since 0.5.UNRELEASED
    */
-  public string nickname { get { return this._nickname; } }
+  public string nickname
+    {
+      get { return this._nickname; }
+
+      set
+        {
+          if (this._nickname == value)
+            return;
+          this._nickname = value;
+          this.notify_property ("nickname");
+          ((Edsf.PersonaStore) this.store)._set_nickname (this, value);
+        }
+    }
 
   /**
    * { inheritDoc}
diff --git a/tests/eds/Makefile.am b/tests/eds/Makefile.am
index 6fc1645..a6d00ec 100644
--- a/tests/eds/Makefile.am
+++ b/tests/eds/Makefile.am
@@ -58,7 +58,7 @@ noinst_PROGRAMS = \
 	set-avatar \
 	set-emails \
 	set-im-addresses \
-	set-full-name \
+	set-names \
 	set-structured-name \
 	set-phones \
 	set-postal-addresses \
@@ -142,8 +142,8 @@ set_im_addresses_SOURCES = \
 	set-im-addresses.vala \
 	$(NULL)
 
-set_full_name_SOURCES = \
-	set-full-name.vala \
+set_names_SOURCES = \
+	set-names.vala \
 	$(NULL)
 
 set_structured_name_SOURCES = \
@@ -193,7 +193,7 @@ MAINTAINERCLEANFILES = \
         set_avatar_vala.stamp \
         set_emails_vala.stamp \
         set_im_addresses_vala.stamp \
-        set_full_name_vala.stamp \
+        set_names_vala.stamp \
         set_structured_name_vala.stamp \
         set_phones_vala.stamp \
         set_postal_addresses_vala.stamp \
@@ -208,4 +208,4 @@ EXTRA_DIST = \
 	$(NULL)
 
 -include $(top_srcdir)/git.mk
--include $(top_srcdir)/check.mk
\ No newline at end of file
+-include $(top_srcdir)/check.mk
diff --git a/tests/eds/set-full-name.vala b/tests/eds/set-names.vala
similarity index 56%
rename from tests/eds/set-full-name.vala
rename to tests/eds/set-names.vala
index 8578bc7..92007f3 100644
--- a/tests/eds/set-full-name.vala
+++ b/tests/eds/set-names.vala
@@ -22,22 +22,24 @@ using EdsTest;
 using Folks;
 using Gee;
 
-public class SetFullNameTests : Folks.TestCase
+public class SetNamesTests : Folks.TestCase
 {
   private EdsTest.Backend _eds_backend;
   private IndividualAggregator _aggregator;
   private GLib.MainLoop _main_loop;
-  private bool _found_before_update;
-  private bool _found_after_update;
+  private bool _full_name_found_before_update;
+  private bool _full_name_found_after_update;
+  private bool _nickname_found_before_update;
+  private bool _nickname_found_after_update;
 
-  public SetFullNameTests ()
+  public SetNamesTests ()
     {
-      base ("SetFullName");
+      base ("SetNames");
 
       this._eds_backend = new EdsTest.Backend ();
 
       this.add_test ("setting full name on e-d-s persona",
-          this.test_set_full_name);
+          this.test_set_names);
     }
 
   public override void set_up ()
@@ -50,23 +52,28 @@ public class SetFullNameTests : Folks.TestCase
       this._eds_backend.tear_down ();
     }
 
-  void test_set_full_name ()
+  void test_set_names ()
     {
       Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
       this._main_loop = new GLib.MainLoop (null, false);
       Value? v;
 
-      this._found_before_update = false;
-      this._found_after_update = false;
+      this._full_name_found_before_update = false;
+      this._full_name_found_after_update = false;
+      this._nickname_found_before_update = false;
+      this._nickname_found_after_update = false;
 
       this._eds_backend.reset ();
 
       v = Value (typeof (string));
       v.set_string ("bernie h. innocenti");
       c1.set ("full_name", (owned) v);
+      v = Value (typeof (string));
+      v.set_string ("foo bar");
+      c1.set ("nickname", (owned) v);
       this._eds_backend.add_contact (c1);
 
-      this._test_set_full_name_async ();
+      this._test_set_names_async ();
 
       Timeout.add_seconds (5, () => {
             this._main_loop.quit ();
@@ -75,19 +82,21 @@ public class SetFullNameTests : Folks.TestCase
 
       this._main_loop.run ();
 
-      assert (this._found_before_update);
-      assert (this._found_after_update);
+      assert (this._full_name_found_before_update);
+      assert (this._full_name_found_after_update);
+      assert (this._nickname_found_before_update);
+      assert (this._nickname_found_after_update);
     }
 
-  private async void _test_set_full_name_async ()
+  private async void _test_set_names_async ()
     {
       yield this._eds_backend.commit_contacts_to_addressbook ();
 
       var store = BackendStore.dup ();
       yield store.prepare ();
       this._aggregator = new IndividualAggregator ();
-      this._aggregator.individuals_changed.connect
-          (this._individuals_changed_cb);
+      this._aggregator.individuals_changed.connect (
+          this._set_names_individuals_changed_cb);
       try
         {
           yield this._aggregator.prepare ();
@@ -98,7 +107,7 @@ public class SetFullNameTests : Folks.TestCase
         }
     }
 
-  private void _individuals_changed_cb
+  private void _set_names_individuals_changed_cb
       (Set<Individual> added,
        Set<Individual> removed,
        string? message,
@@ -111,26 +120,61 @@ public class SetFullNameTests : Folks.TestCase
 
           if (name.full_name == "bernie h. innocenti")
             {
-              i.notify["full-name"].connect (this._notify_full_name_cb);
-              this._found_before_update = true;
-
+              i.notify["full-name"].connect (
+                  this._set_names_notify_full_name_cb);
+              this._full_name_found_before_update = true;
               foreach (var p in i.personas)
                 {
                   ((NameDetails) p).full_name = "bernie";
                 }
             }
+
+          if (name.nickname == "foo bar")
+            {
+              i.notify["nickname"].connect (
+                  this._set_names_notify_nickname_cb);
+              this._nickname_found_before_update = true;
+              foreach (var p in i.personas)
+                {
+                  ((NameDetails) p).nickname = "bar baz";
+                }
+            }
         }
 
       assert (removed.size == 0);
     }
 
-  private void _notify_full_name_cb (Object individual_obj, ParamSpec ps)
+  private void _set_names_notify_full_name_cb (
+      Object individual_obj,
+      ParamSpec ps)
     {
       Folks.Individual i = (Folks.Individual) individual_obj;
       var name = (Folks.NameDetails) i;
       if (name.full_name == "bernie")
         {
-          this._found_after_update = true;
+          this._full_name_found_after_update = true;
+          this._quit_if_complete ();
+        }
+    }
+
+  private void _set_names_notify_nickname_cb (
+      Object individual_obj,
+      ParamSpec ps)
+    {
+      Folks.Individual i = (Folks.Individual) individual_obj;
+      var name = (Folks.NameDetails) i;
+      if (name.nickname == "bar baz")
+        {
+          this._nickname_found_after_update = true;
+          this._quit_if_complete ();
+        }
+    }
+
+  private void _quit_if_complete ()
+    {
+      if (this._full_name_found_after_update &&
+          this._nickname_found_after_update)
+        {
           this._main_loop.quit ();
         }
     }
@@ -141,7 +185,7 @@ public int main (string[] args)
   Test.init (ref args);
 
   TestSuite root = TestSuite.get_root ();
-  root.add_suite (new SetFullNameTests ().get_suite ());
+  root.add_suite (new SetNamesTests ().get_suite ());
 
   Test.run ();
 



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