Commit f7bbe372 authored by Raul Gutierrez Segales's avatar Raul Gutierrez Segales
Browse files

e-d-s: implement BirthdayDetails

Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=657971
parent 0aa6c481
......@@ -248,6 +248,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
*
* Accepted keys for `details` are:
* - PersonaStore.detail_key (PersonaDetail.AVATAR)
* - PersonaStore.detail_key (PersonaDetail.BIRTHDAY)
* - PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES)
* - PersonaStore.detail_key (PersonaDetail.FULL_NAME)
* - PersonaStore.detail_key (PersonaDetail.GENDER)
......@@ -358,6 +359,11 @@ public class Edsf.PersonaStore : Folks.PersonaStore
Set<UrlFieldDetails> urls = (Set<UrlFieldDetails>) v.get_object ();
yield this._set_contact_urls (contact, urls);
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.BIRTHDAY))
{
var birthday = (DateTime?) v.get_boxed ();
yield this._set_contact_birthday (contact, birthday);
}
}
Edsf.Persona? persona = null;
......@@ -1115,6 +1121,39 @@ public class Edsf.PersonaStore : Folks.PersonaStore
contact.set (E.Contact.field_id ("note"), note_str);
}
internal async void _set_birthday (Edsf.Persona persona,
DateTime? bday) throws PropertyError
{
if (persona.birthday != null &&
bday != null &&
persona.birthday.equal (bday))
return;
/* Maybe the current and new b-day are unset */
if (persona.birthday == null &&
bday == null)
return;
yield this._set_contact_birthday (persona.contact, bday);
yield this._commit_modified_property (persona, "birthday");
}
private async void _set_contact_birthday (E.Contact contact,
DateTime? bday)
{
E.ContactDate? contact_bday = null;
if (bday != null)
{
contact_bday = new E.ContactDate ();
contact_bday.year = (uint) bday.get_year ();
contact_bday.month = (uint) bday.get_month ();
contact_bday.day = (uint) bday.get_day_of_month ();
}
contact.set (E.Contact.field_id ("birth_date"), contact_bday);
}
internal async void _set_structured_name (Edsf.Persona persona,
StructuredName? sname) throws PropertyError
{
......
......@@ -31,6 +31,7 @@ using Xml;
*/
public class Edsf.Persona : Folks.Persona,
AvatarDetails,
BirthdayDetails,
EmailDetails,
GenderDetails,
GroupDetails,
......@@ -547,6 +548,45 @@ public class Edsf.Persona : Folks.Persona,
yield ((Edsf.PersonaStore) this.store)._set_groups (this, groups);
}
/**
* {@inheritDoc}
*
* e-d-s has no equivalent field, so this is unsupported.
*
* @since UNRELEASED
*/
[CCode (notify = false)]
public string? calendar_event_id
{
get { return null; } /* unsupported */
set { this.change_calendar_event_id.begin (value); } /* not writeable */
}
private DateTime? _birthday = null;
/**
* {@inheritDoc}
*
* @since UNRELEASED
*/
[CCode (notify = false)]
public DateTime? birthday
{
get { return this._birthday; }
set { this.change_birthday.begin (value); }
}
/**
* {@inheritDoc}
*
* @since UNRELEASED
*/
public async void change_birthday (DateTime? bday)
throws PropertyError
{
yield ((Edsf.PersonaStore) this.store)._set_birthday (this,
bday);
}
/**
* Build a IID.
*
......@@ -712,6 +752,7 @@ public class Edsf.Persona : Folks.Persona,
this._update_local_ids ();
this._update_web_services_addresses ();
this._update_gender ();
this._update_birthday ();
}
private void _update_params (AbstractFieldDetails details,
......@@ -754,6 +795,35 @@ public class Edsf.Persona : Folks.Persona,
}
}
private void _update_birthday ()
{
E.ContactDate? bday = (E.ContactDate?) this._get_property ("birth_date");
if (bday != null)
{
/* Since e-d-s stores birthdays as a plain date, we take the
* given date in local time and convert it to UTC as mandated
* by the BirthdayDetails interface */
var d = new DateTime.local ((int) bday.year, (int) bday.month,
(int) bday.day, 0, 0, 0.0);
if (this._birthday == null ||
(this._birthday != null &&
!this._birthday.equal (d.to_utc ())))
{
this._birthday = d.to_utc ();
this.notify_property ("birthday");
}
}
else
{
if (this._birthday != null)
{
this._birthday = null;
this.notify_property ("birthday");
}
}
}
private void _update_web_services_addresses ()
{
this._web_service_addresses.clear ();
......
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