[folks] core: Add GenderDetails.change_gender()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] core: Add GenderDetails.change_gender()
- Date: Fri, 2 Sep 2011 18:31:07 +0000 (UTC)
commit 55b9950994703e9f91dc6e03e961ac3c99bded28
Author: Philip Withnall <philip tecnocode co uk>
Date: Sun Aug 28 21:12:45 2011 +0100
core: Add GenderDetails.change_gender()
This allows the gender of an implementing class to be changed asynchronously
with proper error notification.
Helps: bgo#657510
backends/eds/lib/edsf-persona-store.vala | 4 ++--
backends/eds/lib/edsf-persona.vala | 15 +++++++++++----
backends/libsocialweb/lib/swf-persona.vala | 16 +++++++++++++---
backends/tracker/lib/trf-persona.vala | 16 ++++++++++++----
folks/gender-details.vala | 21 +++++++++++++++++++++
folks/individual.vala | 14 +++++++-------
po/POTFILES.in | 1 +
po/POTFILES.skip | 1 +
8 files changed, 68 insertions(+), 20 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 8ddfaa3..4153782 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -1229,7 +1229,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
}
internal async void _set_gender (Edsf.Persona persona,
- Gender gender)
+ Gender gender) throws PropertyError
{
try
{
@@ -1239,7 +1239,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
}
catch (GLib.Error e)
{
- GLib.warning ("Can't set gender: %s", e.message);
+ throw this.e_client_error_to_property_error ("gender", e);
}
}
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 1e821d4..9a3168e 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -359,10 +359,17 @@ public class Edsf.Persona : Folks.Persona,
public Gender gender
{
get { return this._gender; }
- public set
- {
- ((Edsf.PersonaStore) this.store)._set_gender (this, value);
- }
+ set { this.change_gender.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_gender (Gender gender) throws PropertyError
+ {
+ yield ((Edsf.PersonaStore) this.store)._set_gender (this, gender);
}
private HashSet<UrlFieldDetails> _urls;
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index b16ee6a..1117360 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -105,10 +105,17 @@ public class Swf.Persona : Folks.Persona,
private set {}
}
+ private Gender _gender = Gender.UNSPECIFIED;
+
/**
* { inheritDoc}
*/
- public Gender gender { get; private set; }
+ [CCode (notify = false)]
+ public Gender gender
+ {
+ get { return this._gender; }
+ set { this.change_gender.begin (value); } /* not writeable */
+ }
private HashSet<UrlFieldDetails> _urls;
private Set<UrlFieldDetails> _urls_ro;
@@ -346,7 +353,10 @@ public class Swf.Persona : Folks.Persona,
gender = Gender.FEMALE;
else
gender = Gender.UNSPECIFIED;
- if (this.gender != gender)
- this.gender = gender;
+ if (this._gender != gender)
+ {
+ this._gender = gender;
+ this.notify_property ("gender");
+ }
}
}
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 0076197..f48532e 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -198,13 +198,21 @@ public class Trf.Persona : Folks.Persona,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public Gender gender
{
get { return this._gender; }
- public set
- {
- ((Trf.PersonaStore) this.store)._set_gender (this, value);
- }
+ set { this.change_gender.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_gender (Gender gender) throws PropertyError
+ {
+ yield ((Trf.PersonaStore) this.store)._set_gender (this, gender);
}
private DateTime? _birthday = null;
diff --git a/folks/gender-details.vala b/folks/gender-details.vala
index ca61e99..6bc16ab 100644
--- a/folks/gender-details.vala
+++ b/folks/gender-details.vala
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011 Philip Withnall
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -17,6 +18,7 @@
* Authors:
* Marco Barisione <marco barisione collabora co uk>
* Travis Reitter <travis reitter collabora co uk>
+ * Philip Withnall <philip tecnocode co uk>
*/
using GLib;
@@ -55,4 +57,23 @@ public interface Folks.GenderDetails : Object
* @since 0.3.5
*/
public abstract Gender gender { get; set; }
+
+ /**
+ * Change the contact's gender.
+ *
+ * It's preferred to call this rather than setting
+ * { link GenderDetails.gender} directly, as this method gives error
+ * notification and will only return once the gender has been written to the
+ * relevant backing store (or the operation's failed).
+ *
+ * @param gender the contact's gender
+ * @throws PropertyError if setting the gender failed
+ * @since UNRELEASED
+ */
+ public virtual async void change_gender (Gender gender) throws PropertyError
+ {
+ /* Default implementation. */
+ throw new PropertyError.NOT_WRITEABLE (
+ _("Gender is not writeable on this contact."));
+ }
}
diff --git a/folks/individual.vala b/folks/individual.vala
index 850fa64..40fd1a7 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -330,18 +330,15 @@ public class Folks.Individual : Object,
}
}
- private Gender _gender;
+ private Gender _gender = Gender.UNSPECIFIED;
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public Gender gender
{
get { return this._gender; }
- private set
- {
- this._gender = value;
- this.notify_property ("gender");
- }
+ set { this.change_gender.begin (value); } /* not writeable */
}
private HashSet<UrlFieldDetails> _urls;
@@ -1389,7 +1386,10 @@ public class Folks.Individual : Object,
}
if (new_gender != this.gender)
- this.gender = new_gender;
+ {
+ this._gender = new_gender;
+ this.notify_property ("gender");
+ }
}
private void _update_urls ()
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 839882e..73a083e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -13,6 +13,7 @@ folks/backend-store.vala
folks/birthday-details.vala
folks/email-details.vala
folks/favourite-details.vala
+folks/gender-details.vala
folks/im-details.vala
folks/individual-aggregator.vala
folks/postal-address-details.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 8adfe1c..d0d0540 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -12,6 +12,7 @@ folks/backend-store.c
folks/birthday-details.c
folks/email-details.c
folks/favourite-details.c
+folks/gender-details.c
folks/im-details.c
folks/individual-aggregator.c
folks/postal-address-details.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]