[folks] Add NoteOwner interface



commit a41ee9f96eb9e7fdea67d8bf884670797eb24521
Author: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
Date:   Thu Mar 3 01:17:38 2011 +0000

    Add NoteOwner interface
    
    Fixes: bgo#642501 - Folks needs API for attaching notes to a Contact

 NEWS                  |    1 +
 folks/Makefile.am     |    1 +
 folks/individual.vala |   45 ++++++++++++++++++++++++
 folks/note-owner.vala |   92 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 42e6a51..7c0ecb9 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ Bugs fixed:
 * Bug 642861 â?? FolksLinkedHashSet still alive when exiting Empathy
 * Bug 642493 â?? Folks needs API for specifying a contact's organisation
 * Bug 642500 â?? Folks needs API for specifying a contact's birthday
+* Bug 642501 â?? Folks needs API for attaching notes to a Contact
 
 Overview of changes from libfolks 0.3.5 to libfolks 0.3.6
 =========================================================
diff --git a/folks/Makefile.am b/folks/Makefile.am
index 3712f3c..26fb27e 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -35,6 +35,7 @@ libfolks_la_SOURCES = \
 	debug.vala \
 	role-owner.vala \
 	birthday-owner.vala \
+	note-owner.vala \
 	$(NULL)
 
 libfolks_la_VALAFLAGS = \
diff --git a/folks/individual.vala b/folks/individual.vala
index c9ebd5e..259787b 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -72,6 +72,7 @@ public class Folks.Individual : Object,
     Groupable,
     IMable,
     NameOwner,
+    NoteOwner,
     PresenceOwner,
     Phoneable,
     RoleOwner,
@@ -316,6 +317,20 @@ public class Folks.Individual : Object,
 
   public string calendar_event_id { get; set; }
 
+  private HashSet<Note> _notes;
+  /**
+   * { inheritDoc}
+   */
+  public HashSet<Note> notes
+    {
+      get { return this._notes; }
+      private set
+        {
+          this._notes = value;
+          this.notify_property ("notes");
+        }
+    }
+
   /**
    * Whether this Individual is a user-defined favourite.
    *
@@ -466,6 +481,11 @@ public class Folks.Individual : Object,
       this._update_birthday ();
     }
 
+  private void _notify_notes_cb ()
+    {
+      this._update_notes ();
+    }
+
   /**
    * Add or remove the Individual from the specified group.
    *
@@ -525,6 +545,8 @@ public class Folks.Individual : Object,
       this._stores = new HashMap<PersonaStore, uint> (null, null);
       this._gender = Gender.UNSPECIFIED;
       this.personas = personas;
+      this._notes = new HashSet<Note>
+          ((GLib.HashFunc) Note.hash, (GLib.EqualFunc) Note.equal);
     }
 
   private void _store_removed_cb (PersonaStore store)
@@ -886,6 +908,7 @@ public class Folks.Individual : Object,
           this._notify_email_addresses_cb);
       persona.notify["roles"].connect (this._notify_roles_cb);
       persona.notify["birthday"].connect (this._notify_birthday_cb);
+      persona.notify["notes"].connect (this._notify_notes_cb);
 
       if (persona is Groupable)
         {
@@ -977,6 +1000,7 @@ public class Folks.Individual : Object,
           this._notify_email_addresses_cb);
       persona.notify["roles"].disconnect (this._notify_roles_cb);
       persona.notify["birthday"].disconnect (this._notify_birthday_cb);
+      persona.notify["notes"].disconnect (this._notify_notes_cb);
 
       if (persona is Groupable)
         {
@@ -1152,6 +1176,27 @@ public class Folks.Individual : Object,
         }
     }
 
+  private void _update_notes ()
+    {
+      HashSet<Note> notes = new HashSet<Note>
+          ((GLib.HashFunc) Note.hash, (GLib.EqualFunc) Note.equal);
+
+      foreach (var persona in this._persona_list)
+        {
+          var note_owner = persona as NoteOwner;
+          if (note_owner != null)
+            {
+              foreach (var n in note_owner.notes)
+                {
+                  notes.add (n);
+                }
+            }
+        }
+
+      this._notes = (owned) notes;
+      this.notify_property ("notes");
+    }
+
   private void _set_personas (GLib.List<Persona>? persona_list,
       Individual? replacement_individual)
     {
diff --git a/folks/note-owner.vala b/folks/note-owner.vala
new file mode 100644
index 0000000..93ea6fc
--- /dev/null
+++ b/folks/note-owner.vala
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *       Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ */
+
+using Gee;
+using GLib;
+
+/**
+ * Representation of a Note that might be attached to a { link Persona}.
+ *
+ * @since 0.3.UNRELEASED
+ */
+public class Folks.Note : Object
+{
+  /**
+   * The note's content.
+   */
+  public string content { get; set; }
+
+  /**
+   * The UID of the note (if any).
+   */
+  public string uid { get; set; }
+
+  /**
+   * Default constructor.
+   *
+   * @param content the note's content
+   * @param uid the note's UID (may be null)
+   * @return a new Note
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public Note (string content, string? uid = null)
+    {
+      if (uid == null)
+        {
+          uid = "";
+        }
+
+      Object (uid:                  uid,
+              content:              content);
+    }
+
+  /**
+   * Compare if 2 notes are equal
+   */
+  public static bool equal (Note a, Note b)
+    {
+      return (a.content == b.content);
+    }
+
+  /**
+   * Hash function for the class.
+   */
+  public static uint hash (Note r)
+    {
+      return r.uid.hash () + r.content.hash ();
+    }
+}
+
+/**
+ * This interface represents the list of notes associated
+ * to a { link Persona} and { link Individual}.
+ *
+ * @since 0.3.UNRELEASED
+ */
+public interface Folks.NoteOwner : Object
+{
+  /**
+   * The notes about the contact.
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public abstract HashSet<Note> notes { get; set; }
+}



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