[folks] e-d-s: add favourites support to EDS backend



commit 35e425903dff408fc4da4fa6577cb6f8ae4caf17
Author: Raul Gutierrez Segales <rgs collabora co uk>
Date:   Tue Oct 25 16:49:14 2011 +0100

    e-d-s: add favourites support to EDS backend
    
    Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=660908

 NEWS                                     |    2 +
 backends/eds/lib/edsf-persona-store.vala |   44 +++++++++++++++++++++++-
 backends/eds/lib/edsf-persona.vala       |   53 ++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index e3e59cd..62c1609 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Bugs fixed:
 * Bug 662285 â Error with email -> im_addresses when updating a contact
 * Bug 662433 â AbstractFieldDetails.equal() is ambiguous about checking
   parameters.
+* Bug 660908 â Add favourites support to EDS backend
 
 API changes:
 * Add AbstractFieldDetails.id to identify instances of details
@@ -11,6 +12,7 @@ API changes:
 * Deprecate NoteFieldDetails.uid in favor of AbstractFieldDetails.id
 * Deprecate Role.uid in favor of AbstractFieldDetails.id
 * Add AbstractFieldDetails.values_equal() to compare values (but not parameters)
+* Implement FavouriteDetails on Edsf.Persona
 
 Behavior changes:
 * PostalAddress.equal() now ignores PostalAddress.uid
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 6c1bca6..93f60ee 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -259,6 +259,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
    * - PersonaStore.detail_key (PersonaDetail.FULL_NAME)
    * - PersonaStore.detail_key (PersonaDetail.GENDER)
    * - PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES)
+   * - PersonaStore.detail_key (PersonaDetail.IS_FAVOURITE)
    * - PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS)
    * - PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES)
    * - PersonaStore.detail_key (PersonaDetail.ROLES)
@@ -382,6 +383,12 @@ public class Edsf.PersonaStore : Folks.PersonaStore
                 (Set<RoleFieldDetails>) v.get_object ();
               yield this._set_contact_roles (contact, roles);
             }
+          else if (k == Folks.PersonaStore.detail_key (
+                  PersonaDetail.IS_FAVOURITE))
+            {
+              bool is_fav = v.get_boolean ();
+              yield this._set_contact_is_favourite (contact, is_fav);
+            }
         }
 
       Edsf.Persona? persona = null;
@@ -647,14 +654,17 @@ public class Edsf.PersonaStore : Folks.PersonaStore
                 {
                   string[] fields = supported_fields.split (",");
 
-                  /* We always support local-ids, web-service-addresses and
-                   * gender because we use custom vCard attributes for them. */
+                  /* We always support local-ids, web-service-addresses, gender
+                   * and favourite because we use custom vCard attributes for
+                   * them. */
                   prop_set.add (Folks.PersonaStore.detail_key (
                       PersonaDetail.LOCAL_IDS));
                   prop_set.add (Folks.PersonaStore.detail_key (
                       PersonaDetail.WEB_SERVICE_ADDRESSES));
                   prop_set.add (Folks.PersonaStore.detail_key (
                       PersonaDetail.GENDER));
+                  prop_set.add (Folks.PersonaStore.detail_key (
+                      PersonaDetail.IS_FAVOURITE));
 
                   foreach (unowned string field in fields)
                     {
@@ -1220,6 +1230,36 @@ public class Edsf.PersonaStore : Folks.PersonaStore
       contact.add_attribute ((owned) new_attr);
     }
 
+  internal async void _set_is_favourite (Edsf.Persona persona,
+      bool is_favourite) throws PropertyError
+    {
+      if (!("is-favourite" in this._always_writeable_properties))
+        {
+          throw new PropertyError.NOT_WRITEABLE (
+              _("The contact cannot be marked as favourite."));
+        }
+
+      yield this._set_contact_is_favourite (persona.contact, is_favourite);
+      yield this._commit_modified_property (persona, "is-favourite");
+    }
+
+  private async void _set_contact_is_favourite (E.Contact contact,
+      bool is_favourite)
+    {
+      unowned VCardAttribute attr = contact.get_attribute ("X-FOLKS-FAVOURITE");
+      if (attr != null)
+        {
+          contact.remove_attribute (attr);
+        }
+
+      if (is_favourite)
+        {
+          var new_attr = new VCardAttribute (null, "X-FOLKS-FAVOURITE");
+          new_attr.add_value ("true");
+          contact.add_attribute ((owned) new_attr);
+        }
+    }
+
   private async void _set_contact_avatar (E.Contact contact,
       LoadableIcon? avatar) throws PropertyError
     {
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 0ec63f0..a7bcaf4 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -33,6 +33,7 @@ public class Edsf.Persona : Folks.Persona,
     AvatarDetails,
     BirthdayDetails,
     EmailDetails,
+    FavouriteDetails,
     GenderDetails,
     GroupDetails,
     ImDetails,
@@ -137,6 +138,8 @@ public class Edsf.Persona : Folks.Persona,
 
   private HashMultiMap<string, WebServiceFieldDetails> _web_service_addresses;
 
+  private bool _is_favourite;
+
   /**
    * The e-d-s contact represented by this Persona
    */
@@ -620,6 +623,34 @@ public class Edsf.Persona : Folks.Persona,
     }
 
   /**
+   * Whether this contact is a user-defined favourite.
+   *
+   * @since UNRELEASED
+   */
+  [CCode (notify = false)]
+  public bool is_favourite
+      {
+        get { return this._is_favourite; }
+        set { this.change_is_favourite.begin (value); }
+      }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since UNRELEASED
+   */
+  public async void change_is_favourite (bool is_favourite) throws PropertyError
+    {
+      if (this._is_favourite == is_favourite)
+        {
+          return;
+        }
+
+      yield ((Edsf.PersonaStore) this.store)._set_is_favourite (this,
+          is_favourite);
+    }
+
+  /**
    * Build a IID.
    *
    * @param store_id the { link PersonaStore.id}
@@ -798,6 +829,7 @@ public class Edsf.Persona : Folks.Persona,
       this._update_gender ();
       this._update_birthday ();
       this._update_roles ();
+      this._update_favourite ();
 
       this.thaw_notify ();
     }
@@ -1534,6 +1566,27 @@ public class Edsf.Persona : Folks.Persona,
         }
     }
 
+  private void _update_favourite ()
+    {
+      bool is_fav = false;
+
+      var fav = this.contact.get_attribute ("X-FOLKS-FAVOURITE");
+      if (fav != null)
+        {
+          var val = fav.get_value ();
+          if (val.down () == "true")
+            {
+              is_fav = true;
+            }
+        }
+
+      if (is_fav != this._is_favourite)
+        {
+          this._is_favourite = is_fav;
+          this.notify_property ("is-favourite");
+        }
+    }
+
   internal static void * _get_property_from_contact (E.Contact contact,
       string prop_name)
     {



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