[folks/wip/arbitrary-field-interface] Implement ExtendedInfo in Individual
- From: Rodrigo Moya <rodrigo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks/wip/arbitrary-field-interface] Implement ExtendedInfo in Individual
- Date: Fri, 5 Jul 2013 12:16:38 +0000 (UTC)
commit 06216414dca6fd68beadda28a44e42ba99d8b193
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Fri Jul 5 14:09:22 2013 +0200
Implement ExtendedInfo in Individual
folks/extended-info.vala | 4 +-
folks/individual.vala | 77 ++++++++++++++++++++++++++++++++++++++++++++++
folks/persona-store.vala | 7 ++++
3 files changed, 86 insertions(+), 2 deletions(-)
---
diff --git a/folks/extended-info.vala b/folks/extended-info.vala
index af04ef5..14b9585 100644
--- a/folks/extended-info.vala
+++ b/folks/extended-info.vala
@@ -45,7 +45,7 @@ public class Folks.ExtendedFieldDetails : AbstractFieldDetails<string>
* @since 0.9.4
*/
public ExtendedFieldDetails (string value,
- MultiMap<string, string>? parameters = null)
+ MultiMap<string, string>? parameters = null)
{
if (value == "")
{
@@ -111,4 +111,4 @@ public interface Folks.ExtendedInfo : Object
throw new PropertyError.NOT_WRITEABLE (
_("Extended fields are not writeable on this contact."));
}
-}
\ No newline at end of file
+}
diff --git a/folks/individual.vala b/folks/individual.vala
index b94bb15..fd1315a 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -86,6 +86,7 @@ public class Folks.Individual : Object,
AvatarDetails,
BirthdayDetails,
EmailDetails,
+ ExtendedInfo,
FavouriteDetails,
GenderDetails,
GroupDetails,
@@ -958,6 +959,82 @@ public class Folks.Individual : Object,
}
/**
+ * { inheritDoc}
+ *
+ * @since 0.9.4
+ */
+ public ExtendedFieldDetails get_extended_field (string name)
+ {
+ debug ("Getting extended field '%s' on '%s'ā¦", name, this.id);
+
+ /* Try to get it from the writeable Personas which have "extended_info"
+ * as a writeable property. */
+ foreach (var p in this._persona_set)
+ {
+ if ("extended_info" in p.writeable_properties)
+ {
+ var e = p as ExtendedInfo;
+ return e.get_extended_field (name);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since 0.9.4
+ */
+ public async void change_extended_field (
+ string name, ExtendedFieldDetails value) throws PropertyError
+ {
+ debug ("Setting extended field '%s' on '%s'ā¦", name, this.id);
+
+ PropertyError? persona_error = null;
+ var prop_changed = false;
+
+ /* Try to write it to only the writeable Personas which have "extended_info"
+ * as a writeable property. */
+ foreach (var p in this._persona_set)
+ {
+ if ("extended_info" in p.writeable_properties)
+ {
+ var e = p as ExtendedInfo;
+ try
+ {
+ yield e.change_extended_field (name, value);
+ debug (" written to writeable persona '%s'", p.uid);
+ prop_changed = true;
+ }
+ catch (PropertyError e)
+ {
+ /* Store the first error so we can throw it if setting the
+ * nickname fails on every other persona. */
+ if (persona_error == null)
+ {
+ persona_error = e;
+ }
+ }
+ }
+ }
+
+ /* Failure? Changing the property failed on every suitable persona found
+ * (and potentially zero suitable personas were found). */
+ if (prop_changed == false)
+ {
+ if (persona_error == null)
+ {
+ persona_error = new PropertyError.NOT_WRITEABLE (
+ _("Failed to change property ā%sā: No suitable personas were found."),
+ "extended_info");
+ }
+
+ throw persona_error;
+ }
+ }
+
+ /**
* The set of { link Persona}s encapsulated by this Individual.
*
* There must always be at least one Persona in this set.
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index 4d6359d..bad4537 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -309,6 +309,13 @@ public enum Folks.PersonaDetail
* @since 0.7.3
*/
ANTI_LINKS,
+
+ /**
+ * Field for { link ExtendedFieldDetails}.
+ *
+ * @since 0.9.4
+ */
+ EXTENDED_INFO,
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]