[folks] Add Phoneable interface for contacts with phone numbers



commit 9ea499303e6dceb462b34b930e2065c7668ac753
Author: Marco Barisione <marco barisione org>
Date:   Mon Dec 20 12:37:50 2010 +0000

    Add Phoneable interface for contacts with phone numbers

 folks/Makefile.am     |    1 +
 folks/individual.vala |   55 ++++++++++++++++++++++++++++++++++--------------
 folks/phoneable.vala  |   39 ++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 16 deletions(-)
---
diff --git a/folks/Makefile.am b/folks/Makefile.am
index 1ad1cca..17460e2 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -28,6 +28,7 @@ libfolks_la_SOURCES = \
 	name-owner.vala \
 	persona.vala \
 	persona-store.vala \
+	phoneable.vala \
 	types.vala \
 	urlable.vala \
 	debug.vala \
diff --git a/folks/individual.vala b/folks/individual.vala
index ae6c745..60b86e2 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -71,6 +71,7 @@ public class Folks.Individual : Object,
     PresenceOwner,
     IMable,
     NameOwner,
+    Phoneable,
     URLable
 {
   private bool _is_favourite;
@@ -278,22 +279,6 @@ public class Folks.Individual : Object,
         }
     }
 
-  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.
    *
@@ -424,6 +409,11 @@ public class Folks.Individual : Object,
       this._update_urls ();
     }
 
+  private void _notify_phone_numbers_cb ()
+    {
+      this._update_phone_numbers ();
+    }
+
   /**
    * Add or remove the Individual from the specified group.
    *
@@ -558,6 +548,7 @@ public class Folks.Individual : Object,
       this._update_nickname ();
       this._update_gender ();
       this._update_urls ();
+      this._update_phone_numbers ();
     }
 
   private void _update_groups ()
@@ -836,6 +827,7 @@ public class Folks.Individual : Object,
       persona.notify["nickname"].connect (this._notify_nickname_cb);
       persona.notify["gender"].connect (this._notify_gender_cb);
       persona.notify["urls"].connect (this._notify_urls_cb);
+      persona.notify["phone-numbers"].connect (this._notify_phone_numbers_cb);
 
       if (persona is Groupable)
         {
@@ -921,6 +913,8 @@ public class Folks.Individual : Object,
       persona.notify["nickname"].disconnect (this._notify_nickname_cb);
       persona.notify["gender"].disconnect (this._notify_gender_cb);
       persona.notify["urls"].disconnect (this._notify_urls_cb);
+      persona.notify["phone-numbers"].disconnect (
+          this._notify_phone_numbers_cb);
 
       if (persona is Groupable)
         {
@@ -974,6 +968,35 @@ public class Folks.Individual : Object,
       this.notify_property ("urls");
     }
 
+  private void _update_phone_numbers ()
+    {
+      /* Populate the phone numberss as the union of our Personas' numbers
+       * If the same number exist multiple times we merge the parameters. */
+      /* FIXME: We should handle phone numbers better, just string comparison
+         doesn't work. */
+      var phone_numbers_set =
+          new HashTable<unowned string, unowned FieldDetails> (
+              str_hash, str_equal);
+      foreach (var persona in this._persona_list)
+        {
+          var phoneable = persona as Phoneable;
+          if (phoneable != null)
+            {
+              foreach (unowned FieldDetails fd in phoneable.phone_numbers)
+                {
+                  var existing = phone_numbers_set.lookup (fd.value);
+                  if (existing != null)
+                    existing.extend_parameters (fd.parameters);
+                  else
+                    phone_numbers_set.insert (fd.value, fd);
+                }
+            }
+        }
+      this._phone_numbers = phone_numbers_set.get_values ();
+
+      this.notify_property ("phone-numbers");
+    }
+
   private void _set_personas (GLib.List<Persona>? persona_list,
       Individual? replacement_individual)
     {
diff --git a/folks/phoneable.vala b/folks/phoneable.vala
new file mode 100644
index 0000000..b4d9cbe
--- /dev/null
+++ b/folks/phoneable.vala
@@ -0,0 +1,39 @@
+/*
+ * 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>
+ */
+
+using GLib;
+
+/**
+ * Interface for classes that can provide a phone number, such as
+ * { link Persona} and { link Individual}.
+ *
+ * @since 0.3.UNRELEASED
+ */
+public interface Folks.Phoneable : Object
+{
+  /**
+   * The phone numbers of the contact.
+   *
+   * A list of phone numbers associated to the contact.
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public abstract List<FieldDetails> phone_numbers { get; set; }
+}



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