summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaul Gutierrez Segales <rgs@collabora.co.uk>2011-10-25 15:49:14 (GMT)
committerRaul Gutierrez Segales <rgs@collabora.co.uk>2011-10-25 19:56:38 (GMT)
commitfa1c224d776759a4f421899f2324a2d132a59de3 (patch)
tree13e6bb394b95ddefea949123329a5faf3b576888
parentc832a3a0c787c534a792a8ffb511b72fdc51dc3a (diff)
downloadfolks-fa1c224d776759a4f421899f2324a2d132a59de3.tar.gz
folks-fa1c224d776759a4f421899f2324a2d132a59de3.tar.xz
e-d-s: add favourites support to EDS backend
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=660908
-rw-r--r--NEWS3
-rw-r--r--backends/eds/lib/edsf-persona-store.vala44
-rw-r--r--backends/eds/lib/edsf-persona.vala53
3 files changed, 98 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index e3e59cd..8ab5905 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,8 @@ 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)
+* Add is_favourite to Edsf.Persona
+* Add change_is_favourite to 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..92518bb 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 (
+ _("Is favourite is not writeable on this contact."));
+ }
+
+ 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)
{