core: Make NameDetails.structured_name nullable
authorPhilip Withnall <philip@tecnocode.co.uk>
Sun, 28 Aug 2011 20:41:02 +0000 (21:41 +0100)
committerPhilip Withnall <philip@tecnocode.co.uk>
Fri, 2 Sep 2011 18:28:29 +0000 (19:28 +0100)
It effectively was before; now it's official.

backends/eds/lib/edsf-persona.vala
backends/libsocialweb/lib/swf-persona.vala
backends/tracker/lib/trf-persona-store.vala
backends/tracker/lib/trf-persona.vala
folks/individual.vala
folks/name-details.vala

index da82930..cff1ea5 100644 (file)
@@ -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
index 1117360..16c9a87 100644 (file)
@@ -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}
index 9c3a7de..3d44425 100644 (file)
@@ -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");
     }
 
index fae3377..5c15217 100644 (file)
@@ -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");
         }
     }
index f70e1dc..d4cc203 100644 (file)
@@ -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}
index 34c9df9..22f9f2c 100644 (file)
@@ -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.