[folks] core: Make NameDetails.structured_name nullable



commit e80b364c31817f4b2d3e3876ec5112d64ef90c80
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Aug 28 21:41:02 2011 +0100

    core: Make NameDetails.structured_name nullable
    
    It effectively was before; now it's official.

 backends/eds/lib/edsf-persona.vala          |    4 +-
 backends/libsocialweb/lib/swf-persona.vala  |    2 +-
 backends/tracker/lib/trf-persona-store.vala |   18 +++++---
 backends/tracker/lib/trf-persona.vala       |   61 +++++++++++++++++++++++----
 folks/individual.vala                       |    2 +-
 folks/name-details.vala                     |    2 +-
 6 files changed, 70 insertions(+), 19 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index da82930..cff1ea5 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -301,14 +301,14 @@ public class Edsf.Persona : Folks.Persona,
         }
     }
 
-  private StructuredName _structured_name;
+  private StructuredName? _structured_name = null;
   /**
    * { inheritDoc}
    *
    * @since 0.6.0
    */
   [CCode (notify = false)]
-  public StructuredName structured_name
+  public StructuredName? structured_name
     {
       get { return this._structured_name; }
       set
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index 1117360..16c9a87 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -88,7 +88,7 @@ public class Swf.Persona : Folks.Persona,
   /**
    * { inheritDoc}
    */
-  public StructuredName structured_name { get; private set; }
+  public StructuredName? structured_name { get; private set; }
 
   /**
    * { inheritDoc}
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 9c3a7de..3d44425 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -2280,9 +2280,9 @@ public class Trf.PersonaStore : Folks.PersonaStore
     }
 
   internal async void _set_structured_name (Folks.Persona persona,
-      StructuredName sname)
+      StructuredName? sname)
     {
-      const string query_t = "DELETE { " +
+      const string query_d = "DELETE { " +
         " ?p " + Trf.OntologyDefs.NCO_FAMILY + " ?family . " +
         " ?p " + Trf.OntologyDefs.NCO_GIVEN + " ?given . " +
         " ?p " + Trf.OntologyDefs.NCO_ADDITIONAL + " ?adi . " +
@@ -2297,8 +2297,8 @@ public class Trf.PersonaStore : Folks.PersonaStore
         " OPTIONAL { ?p " + Trf.OntologyDefs.NCO_PREFIX + " ?prefix } . " +
         " OPTIONAL { ?p " + Trf.OntologyDefs.NCO_SUFFIX + " ?suffix } . " +
         " FILTER (tracker:id(?p) = %s) " +
-        "} " +
-        "INSERT { " +
+        "} ";
+      const string query_i = "INSERT { " +
         " ?p " + Trf.OntologyDefs.NCO_FAMILY + " '%s'; " +
         " " + Trf.OntologyDefs.NCO_GIVEN + " '%s'; " +
         " " + Trf.OntologyDefs.NCO_ADDITIONAL + " '%s'; " +
@@ -2311,8 +2311,14 @@ public class Trf.PersonaStore : Folks.PersonaStore
         "} ";
 
       var p_id = ((Trf.Persona) persona).tracker_id ();
-      string query = query_t.printf (p_id, sname.family_name, sname.given_name,
-          sname.additional_names, sname.prefixes, sname.suffixes, p_id);
+
+      string query = query_d.printf (p_id);
+      if (sname != null)
+        {
+          query = query_i.printf (sname.family_name, sname.given_name,
+              sname.additional_names, sname.prefixes, sname.suffixes, p_id);
+        }
+
       yield this._tracker_update (query, "_set_structured_name");
     }
 
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index fae3377..5c15217 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -168,11 +168,11 @@ public class Trf.Persona : Folks.Persona,
       yield ((Trf.PersonaStore) this.store)._set_avatar (this, avatar);
     }
 
-  private StructuredName _structured_name;
+  private StructuredName? _structured_name = null;
   /**
    * { inheritDoc}
    */
-  public StructuredName structured_name
+  public StructuredName? structured_name
     {
       get { return this._structured_name; }
       public set
@@ -466,7 +466,7 @@ public class Trf.Persona : Folks.Persona,
       this._gender = Gender.UNSPECIFIED;
       this._full_name = fullname;
       this._tracker_id = tracker_id;
-      this._structured_name = new StructuredName (null, null, null, null, null);
+      this._structured_name = null;
       this._phone_numbers = new HashSet<PhoneFieldDetails> (
           (GLib.HashFunc) PhoneFieldDetails.hash,
           (GLib.EqualFunc) PhoneFieldDetails.equal);
@@ -574,7 +574,16 @@ public class Trf.Persona : Folks.Persona,
     {
       if (family_name != null)
         {
-          this._structured_name.family_name = family_name;
+          if (this._structured_name == null)
+            {
+              this._structured_name =
+                  new StructuredName (family_name, null, null, null, null);
+            }
+          else
+            {
+              this._structured_name.family_name = family_name;
+            }
+
           this.notify_property ("structured-name");
         }
     }
@@ -583,7 +592,16 @@ public class Trf.Persona : Folks.Persona,
     {
       if (given_name != null)
         {
-          this._structured_name.given_name = given_name;
+          if (this._structured_name == null)
+            {
+              this._structured_name =
+                  new StructuredName (null, given_name, null, null, null);
+            }
+          else
+            {
+              this._structured_name.given_name = given_name;
+            }
+
           this.notify_property ("structured-name");
         }
     }
@@ -592,7 +610,16 @@ public class Trf.Persona : Folks.Persona,
     {
       if (additional_names != null)
         {
-          this._structured_name.additional_names = additional_names;
+          if (this._structured_name == null)
+            {
+              this._structured_name =
+                  new StructuredName (null, null, additional_names, null, null);
+            }
+          else
+            {
+              this._structured_name.additional_names = additional_names;
+            }
+
           this.notify_property ("structured-name");
         }
     }
@@ -601,7 +628,16 @@ public class Trf.Persona : Folks.Persona,
     {
       if (prefixes != null)
         {
-          this._structured_name.prefixes = prefixes;
+          if (this._structured_name == null)
+            {
+              this._structured_name =
+                  new StructuredName (null, null, null, prefixes, null);
+            }
+          else
+            {
+              this._structured_name.prefixes = prefixes;
+            }
+
           this.notify_property ("structured-name");
         }
     }
@@ -610,7 +646,16 @@ public class Trf.Persona : Folks.Persona,
     {
       if (suffixes != null)
         {
-          this._structured_name.suffixes = suffixes;
+          if (this._structured_name == null)
+            {
+              this._structured_name =
+                  new StructuredName (null, null, null, null, suffixes);
+            }
+          else
+            {
+              this._structured_name.suffixes = suffixes;
+            }
+
           this.notify_property ("structured-name");
         }
     }
diff --git a/folks/individual.vala b/folks/individual.vala
index f70e1dc..d4cc203 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -271,7 +271,7 @@ public class Folks.Individual : Object,
   /**
    * { inheritDoc}
    */
-  public StructuredName structured_name { get; private set; }
+  public StructuredName? structured_name { get; private set; }
 
   /**
    * { inheritDoc}
diff --git a/folks/name-details.vala b/folks/name-details.vala
index 34c9df9..22f9f2c 100644
--- a/folks/name-details.vala
+++ b/folks/name-details.vala
@@ -220,7 +220,7 @@ public interface Folks.NameDetails : Object
    *
    * @since 0.3.5
    */
-  public abstract StructuredName structured_name { get; set; }
+  public abstract StructuredName? structured_name { get; set; }
 
   /**
    * The full name of the contact.



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