[folks] Allow NameDetails.nickname to be writeable
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Allow NameDetails.nickname to be writeable
- Date: Tue, 19 Jul 2011 16:52:26 +0000 (UTC)
commit d3b636b525dbfd9c50a8fcbab0f82777042e3aa0
Author: Philip Withnall <philip withnall collabora co uk>
Date: Sat Jun 25 10:11:39 2011 +0100
Allow NameDetails.nickname to be writeable
Helps: bgo#652048 â Make Individual.nickname writeable
NEWS | 1 +
backends/libsocialweb/lib/swf-persona.vala | 6 +++-
folks/individual.vala | 53 ++++++++++++++++++++++++++--
folks/name-details.vala | 6 +++-
folks/persona-store.vala | 6 +++-
5 files changed, 66 insertions(+), 6 deletions(-)
---
diff --git a/NEWS b/NEWS
index 0e889d4..23c9eea 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,7 @@ Bugs fixed:
API changes:
* Swf.Persona retains and exposes its libsocialweb Contact
* Add a PresenceDetails.presence_status property
+* Make NameDetails.nickname settable
Overview of changes from libfolks 0.5.1 to libfolks 0.5.2
=========================================================
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index c65897b..89d75aa 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -72,7 +72,11 @@ public class Swf.Persona : Folks.Persona,
/**
* { inheritDoc}
*/
- public string nickname { get { return this._nickname; } }
+ public string nickname
+ {
+ get { return this._nickname; }
+ private set {}
+ }
/**
* { inheritDoc}
diff --git a/folks/individual.vala b/folks/individual.vala
index 4dd2439..ccfc456 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -98,6 +98,7 @@ public class Folks.Individual : Object,
private uint _persona_user_count = 0;
private HashMultiMap<string, string> _im_addresses;
private HashMultiMap<string, string> _web_service_addresses;
+ private string _nickname = "";
/**
* The trust level of the Individual.
@@ -248,11 +249,57 @@ public class Folks.Individual : Object,
*/
public string full_name { get; private set; }
- private string _nickname;
/**
* { inheritDoc}
*/
- public string nickname { get { return this._nickname; } }
+ public string nickname
+ {
+ get { return this._nickname; }
+
+ set
+ {
+ // Normalise null values to the empty string
+ if (value == null)
+ value = "";
+
+ if (this._nickname == value)
+ return;
+
+ this._nickname = value;
+
+ debug ("Setting nickname of individual '%s' to '%s'â", this.id,
+ value);
+
+ /* First, try to write it to only the writeable Personasâ */
+ var nickname_changed = false;
+ foreach (var p in this._persona_set)
+ {
+ if (p is NameDetails &&
+ ((Persona) p).store.is_writeable == true)
+ {
+ debug (" written to writeable persona '%s'",
+ ((Persona) p).uid);
+ ((NameDetails) p).nickname = value;
+ nickname_changed = true;
+ }
+ }
+
+ /* âbut if there are no writeable Personas, we have to fall back to
+ * writing it to every Persona. */
+ if (nickname_changed == false)
+ {
+ foreach (var p in this._persona_set)
+ {
+ if (p is NameDetails)
+ {
+ debug (" written to non-writeable persona '%s'",
+ ((Persona) p).uid);
+ ((NameDetails) p).nickname = value;
+ }
+ }
+ }
+ }
+ }
private Gender _gender;
/**
@@ -1154,7 +1201,7 @@ public class Folks.Individual : Object,
private void _update_nickname ()
{
- string? new_nickname = null;
+ string new_nickname = "";
foreach (var persona in this._persona_set)
{
diff --git a/folks/name-details.vala b/folks/name-details.vala
index ed808cc..d4779b8 100644
--- a/folks/name-details.vala
+++ b/folks/name-details.vala
@@ -242,7 +242,11 @@ public interface Folks.NameDetails : Object
* different from { link AliasDetails.alias} as aliases can be chosen by
* the user and not by the contacts themselves.
*
+ * Consequently, setting the nickname only makes sense in the context of an
+ * address book when updating the information a contact has specified about
+ * themselves.
+ *
* @since 0.3.5
*/
- public abstract string nickname { get; }
+ public abstract string nickname { get; set; }
}
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index f65f9f3..3bbf8b9 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -107,6 +107,8 @@ public errordomain Folks.PersonaStoreError
*
* @since 0.5.0
*/
+/* NOTE: Must be kept in sync with
+ * { link Folks.PersonaStore._PERSONA_DETAIL}. */
public enum Folks.PersonaDetail
{
ALIAS,
@@ -118,6 +120,7 @@ public enum Folks.PersonaDetail
IM_ADDRESSES,
IS_FAVOURITE,
LOCAL_IDS,
+ NICKNAME,
NOTES,
PHONE_NUMBERS,
POSTAL_ADDRESSES,
@@ -147,7 +150,7 @@ public abstract class Folks.PersonaStore : Object
* allowed to support keys beyond the ones defined here
* which might be specific to the backend in question.
*
- * Should be kept in sync with { link Folks.PersonaDetail}.
+ * NOTE: MUST be kept in sync with { link Folks.PersonaDetail}.
*
* @since 0.5.0
*/
@@ -161,6 +164,7 @@ public abstract class Folks.PersonaStore : Object
"im-addresses",
"is-favourite",
"local-ids",
+ "nickname",
"notes",
"phone-numbers",
"postal-addresses",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]