[folks] Add GenderOwner interface for specifying contact gender



commit 281a329984c46c07ac40cc2d74da1aa9305faf30
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Tue Jan 18 13:57:44 2011 -0800

    Add GenderOwner interface for specifying contact gender

 folks/Makefile.am       |    1 +
 folks/gender-owner.vala |   58 ++++++++++++++++++++++++++++++
 folks/individual.vala   |   90 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 149 insertions(+), 0 deletions(-)
---
diff --git a/folks/Makefile.am b/folks/Makefile.am
index 412e94b..1ad1cca 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -17,6 +17,7 @@ libfolks_la_SOURCES = \
 	backend-store.vala \
 	favouritable.vala \
 	field-details.vala \
+	gender-owner.vala \
 	groupable.vala \
 	avatar-owner.vala \
 	presence-owner.vala \
diff --git a/folks/gender-owner.vala b/folks/gender-owner.vala
new file mode 100644
index 0000000..5d3b25a
--- /dev/null
+++ b/folks/gender-owner.vala
@@ -0,0 +1,58 @@
+/*
+ * 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:
+ *       Marco Barisione <marco barisione collabora co uk>
+ *       Travis Reitter <travis reitter collabora co uk>
+ */
+
+using GLib;
+
+/**
+ * The gender of a contact
+ *
+ * @since 0.3.UNRELEASED
+ */
+public enum Folks.Gender
+{
+  /**
+   * The gender of the contact is unknown or the contact didn't specify it.
+   */
+  UNSPECIFIED,
+  /**
+   * The contact is male.
+   */
+  MALE,
+  /**
+   * The contact is female.
+   */
+  FEMALE
+}
+
+/**
+ * Interface for specifying the gender of a contact.
+ *
+ * @since 0.3.UNRELEASED
+ */
+public interface Folks.GenderOwner : Object
+{
+  /**
+   * The gender of the contact.
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public abstract Gender gender { get; set; }
+}
diff --git a/folks/individual.vala b/folks/individual.vala
index 932f89f..ae6c745 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -65,6 +65,7 @@ public enum Folks.TrustLevel
 public class Folks.Individual : Object,
     Aliasable,
     Favouritable,
+    GenderOwner,
     Groupable,
     AvatarOwner,
     PresenceOwner,
@@ -231,6 +232,68 @@ public class Folks.Individual : Object,
    */
   public string nickname { get { return this._nickname; } }
 
+  private Gender _gender;
+  /**
+   * { inheritDoc}
+   */
+  public Gender gender
+    {
+      get { return this._gender; }
+      private set
+        {
+          this._gender = value;
+          this.notify_property ("gender");
+        }
+    }
+
+  private GLib.List<FieldDetails> _urls;
+  /**
+   * { inheritDoc}
+   */
+  public GLib.List<FieldDetails> urls
+    {
+      get { return this._urls; }
+      private set
+        {
+          this._urls = new GLib.List<FieldDetails> ();
+          foreach (unowned FieldDetails ps in value)
+            this._urls.prepend (ps);
+          this._urls.reverse ();
+        }
+    }
+
+  private GLib.List<FieldDetails> _phone_numbers;
+  /**
+   * { inheritDoc}
+   */
+  public GLib.List<FieldDetails> phone_numbers
+    {
+      get { return this._phone_numbers; }
+      private set
+        {
+          this._phone_numbers = new GLib.List<FieldDetails> ();
+          foreach (unowned FieldDetails fd in value)
+            this._phone_numbers.prepend (fd);
+          this._phone_numbers.reverse ();
+        }
+    }
+
+  private GLib.List<FieldDetails> _email_addresses;
+  /**
+   * { inheritDoc}
+   */
+  public GLib.List<FieldDetails> email_addresses
+    {
+      get { return this._email_addresses; }
+      private set
+        {
+          this._email_addresses = new GLib.List<FieldDetails> ();
+          foreach (unowned FieldDetails fd in value)
+            this._email_addresses.prepend (fd);
+          this._email_addresses.reverse ();
+        }
+    }
+
   /**
    * Whether this Individual is a user-defined favourite.
    *
@@ -351,6 +414,11 @@ public class Folks.Individual : Object,
       this._update_groups ();
     }
 
+  private void _notify_gender_cb ()
+    {
+      this._update_gender ();
+    }
+
   private void _notify_urls_cb ()
     {
       this._update_urls ();
@@ -413,6 +481,7 @@ public class Folks.Individual : Object,
           new HashTable<string, LinkedHashSet<string>> (str_hash, str_equal);
       this._persona_set = new HashSet<Persona> (null, null);
       this._stores = new HashMap<PersonaStore, uint> (null, null);
+      this._gender = Gender.UNSPECIFIED;
       this.personas = personas;
     }
 
@@ -487,6 +556,7 @@ public class Folks.Individual : Object,
       this._update_structured_name ();
       this._update_full_name ();
       this._update_nickname ();
+      this._update_gender ();
       this._update_urls ();
     }
 
@@ -764,6 +834,7 @@ public class Folks.Individual : Object,
           this._notify_structured_name_cb);
       persona.notify["full-name"].connect (this._notify_full_name_cb);
       persona.notify["nickname"].connect (this._notify_nickname_cb);
+      persona.notify["gender"].connect (this._notify_gender_cb);
       persona.notify["urls"].connect (this._notify_urls_cb);
 
       if (persona is Groupable)
@@ -848,6 +919,7 @@ public class Folks.Individual : Object,
           this._notify_structured_name_cb);
       persona.notify["full-name"].disconnect (this._notify_full_name_cb);
       persona.notify["nickname"].disconnect (this._notify_nickname_cb);
+      persona.notify["gender"].disconnect (this._notify_gender_cb);
       persona.notify["urls"].disconnect (this._notify_urls_cb);
 
       if (persona is Groupable)
@@ -857,6 +929,24 @@ public class Folks.Individual : Object,
         }
     }
 
+  private void _update_gender ()
+    {
+      foreach (var persona in this._persona_list)
+        {
+          var gender_owner = persona as GenderOwner;
+          if (gender_owner != null)
+            {
+              var new_value = gender_owner.gender;
+              if (new_value != Gender.UNSPECIFIED)
+                {
+                  if (new_value != this.gender)
+                    this.gender = new_value;
+                  break;
+                }
+            }
+        }
+    }
+
   private void _update_urls ()
     {
       /* Populate the URLs as the union of our Personas' URLs.



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