[folks] e-d-s: implement BirthdayDetails
- From: Raul Gutierrez Segales <raulgs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] e-d-s: implement BirthdayDetails
- Date: Sat, 3 Sep 2011 14:36:40 +0000 (UTC)
commit f7bbe3723cde7ba6a7ac91735a082366c9f52e70
Author: Raul Gutierrez Segales <rgs collabora co uk>
Date: Sat Sep 3 13:37:50 2011 +0100
e-d-s: implement BirthdayDetails
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=657971
backends/eds/lib/edsf-persona-store.vala | 39 ++++++++++++++++
backends/eds/lib/edsf-persona.vala | 70 ++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+), 0 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 3ff8aee..ba1eb85 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -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
{
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index a5c17de..f2d0e7c 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -31,6 +31,7 @@ using Xml;
*/
public class Edsf.Persona : Folks.Persona,
AvatarDetails,
+ BirthdayDetails,
EmailDetails,
GenderDetails,
GroupDetails,
@@ -548,6 +549,45 @@ public class Edsf.Persona : Folks.Persona,
}
/**
+ * { 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.
*
* @param store_id the { link PersonaStore.id}
@@ -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 ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]