Commit 35e42590 authored by Raul Gutierrez Segales's avatar Raul Gutierrez Segales
Browse files

e-d-s: add favourites support to EDS backend

Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=660908
parent c832a3a0
......@@ -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
......
......@@ -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
{
......
......@@ -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
*/
......@@ -619,6 +622,34 @@ public class Edsf.Persona : Folks.Persona,
yield ((Edsf.PersonaStore) this.store)._set_roles (this, roles);
}
/**
* 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.
*
......@@ -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)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment