[folks] core: Clarify nullability of a few properties



commit 23027313a91d8ee86d43d445402628378a020739
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sat Sep 3 18:35:24 2011 +0100

    core: Clarify nullability of a few properties
    
    AliasDetails.alias, NameDetails.nickname and NameDetails.full_name must never
    be set to null. The empty string represents an unset value for these
    properties.

 backends/eds/lib/edsf-persona-store.vala      |   19 +++++++++++++++++--
 backends/eds/lib/edsf-persona.vala            |   14 +++++++++++++-
 backends/key-file/kf-persona.vala             |   14 +++++++++++++-
 backends/libsocialweb/lib/swf-persona.vala    |   14 +++++++++++++-
 backends/telepathy/lib/tpf-persona-store.vala |    6 ++++++
 backends/telepathy/lib/tpf-persona.vala       |   11 ++++++++++-
 backends/tracker/lib/trf-persona.vala         |   21 ++++++++++++++++++---
 folks/alias-details.vala                      |    2 ++
 folks/name-details.vala                       |    6 ++++++
 9 files changed, 98 insertions(+), 9 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index b046b5f..9c28f66 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -266,8 +266,13 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.FULL_NAME))
             {
-              contact.set (E.Contact.field_id ("full_name"),
-                  v.get_string ());
+              var full_name = v.get_string ();
+              if (full_name == "")
+                {
+                  full_name = null;
+                }
+
+              contact.set (E.Contact.field_id ("full_name"), full_name);
             }
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.EMAIL_ADDRESSES))
@@ -1296,6 +1301,11 @@ public class Edsf.PersonaStore : Folks.PersonaStore
   internal async void _set_full_name (Edsf.Persona persona,
       string full_name) throws PropertyError
     {
+      if (full_name == "")
+        {
+          full_name = null;
+        }
+
       if (persona.full_name == full_name)
         return;
 
@@ -1306,6 +1316,11 @@ public class Edsf.PersonaStore : Folks.PersonaStore
   internal async void _set_nickname (Edsf.Persona persona, string nickname)
       throws PropertyError
     {
+      if (nickname == "")
+        {
+          nickname = null;
+        }
+
       if (persona.nickname == nickname)
         return;
 
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 889f70b..4be8308 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -1008,6 +1008,12 @@ public class Edsf.Persona : Folks.Persona,
   private void _update_names ()
     {
       string full_name = (string) this._get_property ("full_name");
+
+      if (full_name == null)
+        {
+          full_name = "";
+        }
+
       if (this._full_name != full_name)
         {
           this._full_name = full_name;
@@ -1015,7 +1021,13 @@ public class Edsf.Persona : Folks.Persona,
         }
 
       string nickname = (string) this._get_property ("nickname");
-      if (this.nickname != nickname)
+
+      if (nickname == null)
+        {
+          nickname = "";
+        }
+
+      if (this._nickname != nickname)
         {
           this._nickname = nickname;
           this.notify_property ("nickname");
diff --git a/backends/key-file/kf-persona.vala b/backends/key-file/kf-persona.vala
index 0a70b79..28d2280 100644
--- a/backends/key-file/kf-persona.vala
+++ b/backends/key-file/kf-persona.vala
@@ -36,7 +36,7 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
   private unowned GLib.KeyFile _key_file;
   private HashMultiMap<string, ImFieldDetails> _im_addresses;
   private HashMultiMap<string, WebServiceFieldDetails> _web_service_addresses;
-  private string _alias;
+  private string _alias = ""; /* must not be null */
   private const string[] _linkable_properties =
     {
       "im-addresses",
@@ -86,6 +86,12 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
    */
   public async void change_alias (string alias) throws PropertyError
     {
+      /* Deal with badly-behaved callers. */
+      if (alias == null)
+        {
+          alias = "";
+        }
+
       if (this._alias == alias)
         {
           return;
@@ -286,6 +292,12 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
                 {
                   this._alias = this._key_file.get_string (this.display_id,
                       key);
+
+                  if (this._alias == null)
+                    {
+                      this._alias = "";
+                    }
+
                   debug ("    Loaded alias '%s'.", this._alias);
                   continue;
                 }
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index 0778a45..929ecd4 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -307,7 +307,13 @@ public class Swf.Persona : Folks.Persona,
   public void update (Contact contact)
     {
       var nickname = contact.get_value ("name");
-      if (nickname != null && this._nickname != nickname)
+
+      if (nickname == null)
+        {
+          nickname = "";
+        }
+
+      if (this._nickname != nickname)
         {
           this._nickname = nickname;
           this.notify_property ("nickname");
@@ -343,6 +349,12 @@ public class Swf.Persona : Folks.Persona,
         }
 
       var full_name = contact.get_value ("fn");
+
+      if (full_name == null)
+        {
+          full_name = "";
+        }
+
       if (this._full_name != full_name)
         {
           this._full_name = full_name;
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index b8b9848..ad0b49b 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -2086,6 +2086,12 @@ public class Tpf.PersonaStore : Folks.PersonaStore
 
   internal async void change_alias (Tpf.Persona persona, string alias)
     {
+      /* Deal with badly-behaved callers */
+      if (alias == null)
+        {
+          alias = "";
+        }
+
       debug ("Changing alias of persona %u to '%s'.", persona.contact.handle,
           alias);
       FolksTpLowlevel.connection_set_contact_alias (this._conn,
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index f80ba44..cd37b58 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -38,7 +38,7 @@ public class Tpf.Persona : Folks.Persona,
   private HashSet<string> _groups;
   private Set<string> _groups_ro;
   private bool _is_favourite;
-  private string _alias;
+  private string _alias; /* must never be null */
   private HashMultiMap<string, ImFieldDetails> _im_addresses;
   private const string[] _linkable_properties = { "im-addresses" };
   private const string[] _writeable_properties =
@@ -316,6 +316,9 @@ public class Tpf.Persona : Folks.Persona,
 
       contact.notify["alias"].connect ((s, p) =>
           {
+            /* Tp guarantees that aliases are always non-null. */
+            assert (this.contact.alias != null);
+
             if (this._alias != this.contact.alias)
               {
                 this._alias = this.contact.alias;
@@ -447,6 +450,12 @@ public class Tpf.Persona : Folks.Persona,
       this._groups_ro = this._groups.read_only_view;
 
       // Other properties
+      if (alias == null)
+        {
+          /* Deal with badly-behaved callers */
+          alias = "";
+        }
+
       this._alias = alias;
       this._is_favourite = is_favourite;
       this.is_in_contact_list = is_in_contact_list;
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 0f567e3..30ef972 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -45,7 +45,7 @@ public class Trf.Persona : Folks.Persona,
     UrlDetails,
     WebServiceDetails
 {
-  private string _nickname;
+  private string _nickname; /* must never be null */
   private bool _is_favourite;
   private const string[] _linkable_properties =
       {"im-addresses", "local-ids", "web-service-addresses"};
@@ -525,6 +525,11 @@ public class Trf.Persona : Folks.Persona,
       if (cursor != null)
         {
           fullname = cursor.get_string (Trf.Fields.FULL_NAME).dup ();
+          if (fullname == null)
+            {
+              fullname = "";
+            }
+
           var contact_urn = cursor.get_string (Trf.Fields.CONTACT_URN);
           if (contact_urn == Trf.OntologyDefs.DEFAULT_CONTACT_URN)
             {
@@ -631,7 +636,12 @@ public class Trf.Persona : Folks.Persona,
 
   internal void _update_full_name (string? fn)
     {
-      if (fn != null && this.full_name != fn)
+      if (fn == null)
+        {
+          fn = "";
+        }
+
+      if (this._full_name != fn)
         {
           this._full_name = fn;
           this.notify_property ("full-name");
@@ -640,7 +650,12 @@ public class Trf.Persona : Folks.Persona,
 
   internal void _update_nickname (string? nickname)
     {
-      if (nickname != null && this._nickname != nickname)
+      if (nickname == null)
+        {
+          nickname = "";
+        }
+
+      if (this._nickname != nickname)
         {
           this._nickname = nickname;
           this.notify_property ("nickname");
diff --git a/folks/alias-details.vala b/folks/alias-details.vala
index e7fac34..38bbdff 100644
--- a/folks/alias-details.vala
+++ b/folks/alias-details.vala
@@ -33,6 +33,8 @@ public interface Folks.AliasDetails : Object
    *
    * An alias is a user-given name, to be used in UIs as the sole way to
    * represent the contact to the user.
+   *
+   * This may not be `null`: an empty string represents an unset alias.
    */
   public abstract string alias { get; set; }
 
diff --git a/folks/name-details.vala b/folks/name-details.vala
index b1144d8..8726fac 100644
--- a/folks/name-details.vala
+++ b/folks/name-details.vala
@@ -254,6 +254,9 @@ public interface Folks.NameDetails : Object
    * The full name could or could not contain additional names (like a
    * middle name), prefixes or suffixes.
    *
+   * The full name must not be `null`: the empty string represents an unset full
+   * name.
+   *
    * @since 0.3.5
    */
   public abstract string full_name { get; set; }
@@ -289,6 +292,9 @@ public interface Folks.NameDetails : Object
    * address book when updating the information a contact has specified about
    * themselves.
    *
+   * The nickname must not be `null`: the empty string represents an unset
+   * nickname.
+   *
    * @since 0.3.5
    */
   public abstract string nickname { get; set; }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]