[folks] Add RoleOwner interface for contacts that belong to an Organisation



commit a292acae512f76932e2ae95cd143df89e3e27ecd
Author: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
Date:   Tue Mar 1 19:09:14 2011 +0000

    Add RoleOwner interface for contacts that belong to an Organisation

 folks/Makefile.am     |    1 +
 folks/individual.vala |   47 ++++++++++++++++++++
 folks/role-owner.vala |  112 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+), 0 deletions(-)
---
diff --git a/folks/Makefile.am b/folks/Makefile.am
index 6e533ed..b7e3ee9 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -33,6 +33,7 @@ libfolks_la_SOURCES = \
 	types.vala \
 	urlable.vala \
 	debug.vala \
+	role-owner.vala \
 	$(NULL)
 
 libfolks_la_VALAFLAGS = \
diff --git a/folks/individual.vala b/folks/individual.vala
index 7f6ddb3..fe39fad 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -73,6 +73,7 @@ public class Folks.Individual : Object,
     NameOwner,
     PresenceOwner,
     Phoneable,
+    RoleOwner,
     Urlable
 {
   private bool _is_favourite;
@@ -296,6 +297,20 @@ public class Folks.Individual : Object,
         }
     }
 
+  private HashSet<Role> _roles;
+  /**
+   * { inheritDoc}
+   */
+  public HashSet<Role> roles
+    {
+      get { return this._roles; }
+      private set
+        {
+          this._roles = value;
+          this.notify_property ("roles");
+        }
+    }
+
   /**
    * Whether this Individual is a user-defined favourite.
    *
@@ -436,6 +451,11 @@ public class Folks.Individual : Object,
       this._update_email_addresses ();
     }
 
+  private void _notify_roles_cb ()
+    {
+      this._update_roles ();
+    }
+
   /**
    * Add or remove the Individual from the specified group.
    *
@@ -572,6 +592,7 @@ public class Folks.Individual : Object,
       this._update_urls ();
       this._update_phone_numbers ();
       this._update_email_addresses ();
+      this._update_roles ();
     }
 
   private void _update_groups ()
@@ -853,6 +874,7 @@ public class Folks.Individual : Object,
       persona.notify["phone-numbers"].connect (this._notify_phone_numbers_cb);
       persona.notify["email-addresses"].connect (
           this._notify_email_addresses_cb);
+      persona.notify["roles"].connect (this._notify_roles_cb);
 
       if (persona is Groupable)
         {
@@ -942,6 +964,7 @@ public class Folks.Individual : Object,
           this._notify_phone_numbers_cb);
       persona.notify["email-addresses"].disconnect (
           this._notify_email_addresses_cb);
+      persona.notify["roles"].disconnect (this._notify_roles_cb);
 
       if (persona is Groupable)
         {
@@ -1058,6 +1081,30 @@ public class Folks.Individual : Object,
       this.notify_property ("email-addresses");
     }
 
+  private void _update_roles ()
+    {
+      HashSet<Role> roles = new HashSet<Role>
+          ((GLib.HashFunc) Role.hash, (GLib.EqualFunc) Role.equal);
+
+      foreach (var persona in this._persona_list)
+        {
+          var role_owner = persona as RoleOwner;
+          if (role_owner != null)
+            {
+              foreach (var r in role_owner.roles)
+                {
+                  if (roles.contains (r) == false)
+                    {
+                      roles.add (r);
+                    }
+                }
+            }
+        }
+
+      this._roles = (owned) roles;
+      this.notify_property ("roles");
+    }
+
   private void _set_personas (GLib.List<Persona>? persona_list,
       Individual? replacement_individual)
     {
diff --git a/folks/role-owner.vala b/folks/role-owner.vala
new file mode 100644
index 0000000..f58b07c
--- /dev/null
+++ b/folks/role-owner.vala
@@ -0,0 +1,112 @@
+/*
+ * 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;
+
+/**
+ * This interface represents the role a { link Persona} and { link Individual}
+ * have in a given Organisation.
+ *
+ * @since 0.3.UNRELEASED
+ */
+public class Folks.Role : Object
+{
+  /**
+   * The name of the organisation in which the role is held.
+   */
+  public string organisation_name { get; set; }
+
+  /**
+   * The name of the position held.
+   */
+  public string title { get; set; }
+
+  /**
+   * The UID that distinguishes this role.
+   */
+  public string uid { get; set; }
+
+  /**
+   * Default constructor.
+   *
+   * @param title title of the position
+   * @param organisation_name organisation where the role is hold
+   * @param uid a Unique ID associated to this Role
+   * @return a new Role
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public Role (string? title = null,
+      string? organisation_name = null, string? uid = null)
+    {
+      if (title == null)
+        {
+          title = "";
+        }
+
+      if (organisation_name == null)
+        {
+          organisation_name = "";
+        }
+
+      if (uid == null)
+        {
+          uid = "";
+        }
+
+      Object (uid:                  uid,
+              title:                title,
+              organisation_name:    organisation_name);
+    }
+
+  /**
+   * Compare if 2 roles are equal
+   */
+  public static bool equal (Role a, Role b)
+    {
+      return (a.title == b.title) &&
+          (a.organisation_name == b.organisation_name);
+    }
+
+  /**
+   * Hash function for the class.
+   */
+  public static uint hash (Role r)
+    {
+      return r.organisation_name.hash () + r.title.hash ();
+    }
+}
+
+/**
+ * This interfaces represents the list of roles a { link Persona} and
+ * { link Individual} might have.
+ *
+ * @since 0.3.UNRELEASED
+ */
+public interface Folks.RoleOwner : Object
+{
+  /**
+   * The roles of the contact.
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public abstract HashSet<Role> roles { get; set; }
+}



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