[folks] Rebase NoteDetails.notes upon NoteFieldDetails



commit b8c144844c7012fcc1c49d46a9fc28de5a100aaf
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Mon Aug 8 16:08:36 2011 +0200

    Rebase NoteDetails.notes upon NoteFieldDetails
    
    Closes: bgo#655919 - Rebase NoteDetails.notes upon an
    AbstractFieldDetails-derived class

 NEWS                                        |    4 ++
 backends/eds/lib/edsf-persona-store.vala    |    9 ++--
 backends/eds/lib/edsf-persona.vala          |   12 +++--
 backends/tracker/lib/trf-persona-store.vala |    8 ++--
 backends/tracker/lib/trf-persona.vala       |   13 +++--
 folks/individual.vala                       |   11 ++--
 folks/note-details.vala                     |   77 +++++++++++++++------------
 tests/eds/add-persona.vala                  |   10 ++--
 tests/eds/set-notes.vala                    |    6 +-
 tests/tracker/add-persona.vala              |   12 +++--
 tests/tracker/note-details-interface.vala   |    4 +-
 tests/tracker/set-notes.vala                |   14 +++--
 tools/inspect/utils.vala                    |    3 +-
 13 files changed, 104 insertions(+), 79 deletions(-)
---
diff --git a/NEWS b/NEWS
index a5f21d8..20ec2bb 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,8 @@ Bugs fixed:
 * Bug 655917 â Rebase EmailDetails.email_addresses upon an
   AbstractFieldDetails-derived class
 * Bug 655374 â Un-break avatar tests
+* Bug 655919 â Rebase NoteDetails.notes upon an AbstractFieldDetails-derived
+  class
 
 API changes:
 * Swf.Persona retains and exposes its libsocialweb Contact
@@ -65,6 +67,8 @@ API changes:
 * Remove PostalAddress.types (obsoleted by PostalAddressFieldDetails.parameters)
 * Add and use ImFieldDetails for ImDetails.im_addresses
 * Add and use EmailFieldDetails for EmailFieldDetails.email_addresses
+* Add and use NoteFieldDetails for NoteFieldDetails.notes
+* Remove Note class (obsoleted by NoteFieldDetails)
 
 Overview of changes from libfolks 0.5.1 to libfolks 0.5.2
 =========================================================
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 09efcb0..8cb0a63 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -290,7 +290,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.NOTES))
             {
-              var notes = (Gee.HashSet<Note>) v.get_object ();
+              var notes = (Gee.HashSet<NoteFieldDetails>) v.get_object ();
               yield this._set_contact_notes (contact, notes);
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.GENDER))
@@ -923,7 +923,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
     }
 
   internal async void _set_notes (Edsf.Persona persona,
-      Set<Note> notes)
+      Set<NoteFieldDetails> notes)
     {
       try
         {
@@ -937,7 +937,8 @@ public class Edsf.PersonaStore : Folks.PersonaStore
         }
     }
 
-  private async void _set_contact_notes (E.Contact contact, Set<Note> notes)
+  private async void _set_contact_notes (E.Contact contact,
+      Set<NoteFieldDetails> notes)
     {
       string note_str = "";
       foreach (var note in notes)
@@ -946,7 +947,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
             {
               note_str += ". ";
             }
-          note_str += note.content;
+          note_str += note.value;
         }
 
       contact.set (E.Contact.field_id ("note"), note_str);
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 6163b0f..50072e7 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -117,8 +117,8 @@ public class Edsf.Persona : Folks.Persona,
   private Set<FieldDetails> _phone_numbers_ro;
   private HashSet<EmailFieldDetails> _email_addresses;
   private Set<EmailFieldDetails> _email_addresses_ro;
-  private HashSet<Note> _notes;
-  private Set<Note> _notes_ro;
+  private HashSet<NoteFieldDetails> _notes;
+  private Set<NoteFieldDetails> _notes_ro;
   private static HashTable<string, E.ContactField> _im_eds_map = null;
 
   private HashSet<PostalAddressFieldDetails> _postal_addresses;
@@ -219,7 +219,7 @@ public class Edsf.Persona : Folks.Persona,
    *
    * @since 0.5.UNRELEASED
    */
-  public Set<Note> notes
+  public Set<NoteFieldDetails> notes
     {
       get { return this._notes_ro; }
       set
@@ -490,7 +490,9 @@ public class Edsf.Persona : Folks.Persona,
           (GLib.HashFunc) EmailFieldDetails.hash,
           (GLib.EqualFunc) EmailFieldDetails.equal);
       this._email_addresses_ro = this._email_addresses.read_only_view;
-      this._notes = new HashSet<Note> ();
+      this._notes = new HashSet<NoteFieldDetails> (
+          (GLib.HashFunc) NoteFieldDetails.hash,
+          (GLib.EqualFunc) NoteFieldDetails.equal);
       this._notes_ro = this._notes.read_only_view;
       this._urls = new HashSet<FieldDetails> ();
       this._urls_ro = this._urls.read_only_view;
@@ -652,7 +654,7 @@ public class Edsf.Persona : Folks.Persona,
       string n = (string) this._get_property ("note");
       if (n != null && n != "")
         {
-          var note = new Note (n);
+          var note = new NoteFieldDetails (n);
           this._notes.add (note);
         }
 
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 1afb8ef..e1b5c06 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -536,12 +536,12 @@ public class Trf.PersonaStore : Folks.PersonaStore
             }
           else if (k == Folks.PersonaStore.detail_key (PersonaDetail.NOTES))
             {
-              var notes = (Gee.HashSet<Note>) v.get_object ();
+              var notes = (Gee.HashSet<NoteFieldDetails>) v.get_object ();
               foreach (var n in notes)
                 {
                   builder.subject ("_:p");
                   builder.predicate (Trf.OntologyDefs.NCO_NOTE);
-                  builder.object_string (n.content);
+                  builder.object_string (n.value);
                 }
             }
           else if (k == Folks.PersonaStore.detail_key (
@@ -2078,7 +2078,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
    }
 
   internal async void _set_notes (Folks.Persona persona,
-      Set<Note> notes)
+      Set<NoteFieldDetails> notes)
     {
       const string del_t = "DELETE { " +
         "?p " + Trf.OntologyDefs.NCO_NOTE  + " ?n " +
@@ -2099,7 +2099,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
         {
           builder.subject ("?contact");
           builder.predicate (Trf.OntologyDefs.NCO_NOTE);
-          builder.object_string (n.content);
+          builder.object_string (n.value);
         }
 
       builder.insert_close ();
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index b90c426..a3efb02 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -229,13 +229,13 @@ public class Trf.Persona : Folks.Persona,
         }
     }
 
-  private HashSet<Note> _notes;
-  private Set<Note> _notes_ro;
+  private HashSet<NoteFieldDetails> _notes;
+  private Set<NoteFieldDetails> _notes_ro;
 
   /**
    * { inheritDoc}
    */
-  public Set<Note> notes
+  public Set<NoteFieldDetails> notes
     {
       get { return this._notes_ro; }
       set
@@ -417,8 +417,9 @@ public class Trf.Persona : Folks.Persona,
       this._roles = new HashSet<Role> ((GLib.HashFunc) Role.hash,
           (GLib.EqualFunc) Role.equal);
       this._roles_ro = this._roles.read_only_view;
-      this._notes = new HashSet<Note> ((GLib.HashFunc) Note.hash,
-          (GLib.EqualFunc) Note.equal);
+      this._notes = new HashSet<NoteFieldDetails> (
+          (GLib.HashFunc) NoteFieldDetails.hash,
+          (GLib.EqualFunc) NoteFieldDetails.equal);
       this._notes_ro = this._notes.read_only_view;
       this._urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
           (GLib.EqualFunc) FieldDetails.equal);
@@ -707,7 +708,7 @@ public class Trf.Persona : Folks.Persona,
     {
       if (note_content != null)
         {
-          var note = new Note (note_content);
+          var note = new NoteFieldDetails (note_content);
           this._notes.add ((owned) note);
         }
       else
diff --git a/folks/individual.vala b/folks/individual.vala
index 5c7861c..4453dc2 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -408,13 +408,13 @@ public class Folks.Individual : Object,
 
   public string? calendar_event_id { get; set; }
 
-  private HashSet<Note> _notes;
-  private Set<Note> _notes_ro;
+  private HashSet<NoteFieldDetails> _notes;
+  private Set<NoteFieldDetails> _notes_ro;
 
   /**
    * { inheritDoc}
    */
-  public Set<Note> notes
+  public Set<NoteFieldDetails> notes
     {
       get { return this._notes_ro; }
       private set
@@ -715,8 +715,9 @@ public class Folks.Individual : Object,
           (GLib.HashFunc) PostalAddressFieldDetails.hash,
           (GLib.EqualFunc) PostalAddressFieldDetails.equal);
       this._postal_addresses_ro = this._postal_addresses.read_only_view;
-      this._notes = new HashSet<Note>
-          ((GLib.HashFunc) Note.hash, (GLib.EqualFunc) Note.equal);
+      this._notes = new HashSet<NoteFieldDetails> (
+          (GLib.HashFunc) NoteFieldDetails.hash,
+          (GLib.EqualFunc) NoteFieldDetails.equal);
       this._notes_ro = this._notes.read_only_view;
 
       this.personas = personas;
diff --git a/folks/note-details.vala b/folks/note-details.vala
index 7c16025..03e6d10 100644
--- a/folks/note-details.vala
+++ b/folks/note-details.vala
@@ -22,64 +22,73 @@ using Gee;
 using GLib;
 
 /**
- * Representation of a Note that might be attached to a { link Persona}.
+ * Object representing a note that can have some parameters associated with it.
  *
- * @since 0.4.0
+ * See { link Folks.AbstractFieldDetails} for details on common parameter names
+ * and values.
+ *
+ * @since UNRELEASED
  */
-public class Folks.Note : Object
+public class Folks.NoteFieldDetails : AbstractFieldDetails<string>
 {
   /**
-   * The note's content.
-   */
-  public string content { get; set; }
-
-  /**
    * The UID of the note (if any).
    */
   public string uid { get; set; }
 
   /**
-   * Default constructor.
+   * Create a new NoteFieldDetails.
+   *
+   * @param value the value of the field
+   * @param parameters initial parameters. See
+   * { link AbstractFieldDetails.parameters}. A `null` value is equivalent to a
+   * empty map of parameters.
    *
-   * @param content the note's content
-   * @param uid the note's UID (may be null)
-   * @return a new Note
+   * @return a new NoteFieldDetails
    *
-   * @since 0.4.0
+   * @since UNRELEASED
    */
-  public Note (string content, string? uid = null)
+  public NoteFieldDetails (string value,
+      MultiMap<string, string>? parameters = null,
+      string? uid = null)
     {
-      if (uid == null)
-        {
-          uid = "";
-        }
-
-      Object (uid:                  uid,
-              content:              content);
+      this.value = value;
+      if (parameters != null)
+        this.parameters = parameters;
+      this.uid = uid;
     }
 
   /**
-   * Compare if 2 notes are equal. This compares both their { link Note.content}
-   * and { link Note.uid} (if set).
+   * { inheritDoc}
    *
-   * @param a a note to compare
-   * @param b another note to compare
-   * @return `true` if the notes are equal, `false` otherwise
+   * @since UNRELEASED
    */
-  public static bool equal (Note a, Note b)
+  public override bool equal (AbstractFieldDetails<string> that)
     {
-      return (a.uid == b.uid && a.content == b.content);
+      var that_nfd = that as NoteFieldDetails;
+
+      if (that_nfd == null)
+        return false;
+
+      return (this.uid == that_nfd.uid && this.value == that_nfd.value);
     }
 
   /**
-   * Hash function for the class. Suitable for use as a hash table key.
+   * { inheritDoc}
    *
-   * @param r a note to hash
-   * @return hash value for the note instance
+   * @since UNRELEASED
    */
-  public static uint hash (Note r)
+  public override uint hash ()
     {
-      return r.uid.hash () + r.content.hash ();
+      uint retval = 0;
+
+      if (this.value != null)
+        retval += this.value.hash ();
+
+      if (this.uid != null)
+        retval += this.uid.hash ();
+
+      return retval;
     }
 }
 
@@ -96,5 +105,5 @@ public interface Folks.NoteDetails : Object
    *
    * @since 0.5.1
    */
-  public abstract Set<Note> notes { get; set; }
+  public abstract Set<NoteFieldDetails> notes { get; set; }
 }
diff --git a/tests/eds/add-persona.vala b/tests/eds/add-persona.vala
index 26418c3..dc8ebca 100644
--- a/tests/eds/add-persona.vala
+++ b/tests/eds/add-persona.vala
@@ -217,9 +217,11 @@ public class AddPersonaTests : Folks.TestCase
           Folks.PersonaStore.detail_key (PersonaDetail.STRUCTURED_NAME),
           (owned) v7);
 
-      Value? v8 = Value (typeof (Set<Note>));
-      var notes = new HashSet<Note> ();
-      var note = new Note(this._note);
+      Value? v8 = Value (typeof (Set<NoteFieldDetails>));
+      var notes = new HashSet<NoteFieldDetails> (
+          (GLib.HashFunc) NoteFieldDetails.hash,
+          (GLib.EqualFunc) NoteFieldDetails.equal);
+      var note = new NoteFieldDetails (this._note);
       notes.add (note);
       v8.set_object (notes);
       details.insert (
@@ -350,7 +352,7 @@ public class AddPersonaTests : Folks.TestCase
 
       foreach (var note in i.notes)
         {
-          if (note.content == this._note)
+          if (note.equal (new NoteFieldDetails (this._note)))
             {
               this._properties_found.replace ("note", true);
               break;
diff --git a/tests/eds/set-notes.vala b/tests/eds/set-notes.vala
index 43cad5c..0ce96a9 100644
--- a/tests/eds/set-notes.vala
+++ b/tests/eds/set-notes.vala
@@ -117,8 +117,8 @@ public class SetNotesTests : Folks.TestCase
 
               foreach (var p in i.personas)
                 {
-                  var notes = new HashSet<Note> ();
-                  var note = new Note(this._note);
+                  var notes = new HashSet<NoteFieldDetails> ();
+                  var note = new NoteFieldDetails (this._note);
                   notes.add (note);
                   ((NoteDetails) p).notes = notes;
                 }
@@ -133,7 +133,7 @@ public class SetNotesTests : Folks.TestCase
       Folks.Individual i = (Folks.Individual) individual_obj;
       foreach (var note in i.notes)
         {
-          if (note.content == this._note)
+          if (note.equal (new NoteFieldDetails (this._note)))
             {
               this._found_after_update = true;
               this._main_loop.quit ();
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index 54a8d78..a334066 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -247,10 +247,12 @@ public class AddPersonaTests : Folks.TestCase
       details.insert (
           Folks.PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES), v9);
 
-      Value? v10 = Value (typeof (Set<Note>));
-      var notes = new HashSet<Note> ();
-      Note n1 = new Note (this._note_1);
-      notes.add (n1);
+      Value? v10 = Value (typeof (Set<NoteFieldDetails>));
+      var notes = new HashSet<NoteFieldDetails> (
+          (GLib.HashFunc) NoteFieldDetails.hash,
+          (GLib.EqualFunc) NoteFieldDetails.equal);
+      NoteFieldDetails note_fd_1 = new NoteFieldDetails (this._note_1);
+      notes.add (note_fd_1);
       v10.set_object (notes);
       details.insert (Folks.PersonaStore.detail_key (PersonaDetail.NOTES),
           (owned) v10);
@@ -452,7 +454,7 @@ public class AddPersonaTests : Folks.TestCase
 
       foreach (var n in i.notes)
         {
-          if (n.content == this._note_1)
+          if (n.equal (new NoteFieldDetails (this._note_1)))
             {
               this._properties_found.replace ("note-1", true);
             }
diff --git a/tests/tracker/note-details-interface.vala b/tests/tracker/note-details-interface.vala
index 8ce0882..74d8c1e 100644
--- a/tests/tracker/note-details-interface.vala
+++ b/tests/tracker/note-details-interface.vala
@@ -112,7 +112,7 @@ public class NoteDetailsInterfaceTests : Folks.TestCase
               i.notify["notes"].connect (this._notify_note_cb);
               foreach (var n in i.notes)
                 {
-                  if (n.content == this._note)
+                  if (n.equal (new NoteFieldDetails (this._note)))
                     {
                       this._found_note = true;
                       this._main_loop.quit ();
@@ -129,7 +129,7 @@ public class NoteDetailsInterfaceTests : Folks.TestCase
       Folks.Individual individual = (Folks.Individual) individual_obj;
       foreach (var n in individual.notes)
         {
-          if (n.content == this._note)
+          if (n.equal (new NoteFieldDetails (this._note)))
             {
               this._found_note = true;
               this._main_loop.quit ();
diff --git a/tests/tracker/set-notes.vala b/tests/tracker/set-notes.vala
index 2d6930c..5633875 100644
--- a/tests/tracker/set-notes.vala
+++ b/tests/tracker/set-notes.vala
@@ -30,7 +30,7 @@ public class SetNotesTests : Folks.TestCase
   private IndividualAggregator _aggregator;
   private string _persona_fullname;
   private bool _note_found;
-  private Note _note;
+  private NoteFieldDetails _note;
 
   public SetNotesTests ()
     {
@@ -59,7 +59,7 @@ public class SetNotesTests : Folks.TestCase
       c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
       this._tracker_backend.add_contact (c1);
 
-      this._note = new Note ("some note");
+      this._note = new NoteFieldDetails ("some note");
 
       this._tracker_backend.set_up ();
 
@@ -110,9 +110,11 @@ public class SetNotesTests : Folks.TestCase
             {
               i.notify["notes"].connect (this._notify_notes_cb);
 
-              Gee.HashSet<Note> notes = new HashSet<Note>
-                  ((GLib.HashFunc) Note.hash, (GLib.EqualFunc) Note.equal);
-              var n = new Note ("some note");
+              Gee.HashSet<NoteFieldDetails> notes =
+                  new HashSet<NoteFieldDetails> (
+                          (GLib.HashFunc) NoteFieldDetails.hash,
+                          (GLib.EqualFunc) NoteFieldDetails.equal);
+              var n = new NoteFieldDetails ("some note");
               notes.add ((owned) n);
 
               foreach (var p in i.personas)
@@ -132,7 +134,7 @@ public class SetNotesTests : Folks.TestCase
         {
           foreach (var n in i.notes)
             {
-              if (Note.equal (n, this._note))
+              if (n.equal (this._note))
                 {
                   this._note_found = true;
                   this._main_loop.quit ();
diff --git a/tools/inspect/utils.vala b/tools/inspect/utils.vala
index a190fa9..66c9f29 100644
--- a/tools/inspect/utils.vala
+++ b/tools/inspect/utils.vala
@@ -392,7 +392,8 @@ private class Folks.Inspect.Utils
         }
       else if (prop_name == "notes")
         {
-          Set<Note> notes = (Set<Note>) prop_value.get_object ();
+          Set<NoteFieldDetails> notes =
+              prop_value.get_object () as Set<NoteFieldDetails>;
 
           output_string = "{ ";
           bool first = true;



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