[folks] Add BirthdayOwner interface



commit f30fc9be93996d99b8700f8d8cad85a6ff901e32
Author: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
Date:   Wed Mar 2 18:44:37 2011 +0000

    Add BirthdayOwner interface
    
    Fixes: bgo#642500 - Folks needs API for specifying a contact's birthday

 NEWS                      |    1 +
 folks/Makefile.am         |    1 +
 folks/birthday-owner.vala |   45 +++++++++++++++++++++++++++++++++++++++++++
 folks/individual.vala     |   47 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 871b721..42e6a51 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Bugs fixed:
 * Bug 642866 â?? tp-lowlevel leaks TpChannel
 * 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
 
 Overview of changes from libfolks 0.3.5 to libfolks 0.3.6
 =========================================================
diff --git a/folks/Makefile.am b/folks/Makefile.am
index b7e3ee9..3712f3c 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -34,6 +34,7 @@ libfolks_la_SOURCES = \
 	urlable.vala \
 	debug.vala \
 	role-owner.vala \
+	birthday-owner.vala \
 	$(NULL)
 
 libfolks_la_VALAFLAGS = \
diff --git a/folks/birthday-owner.vala b/folks/birthday-owner.vala
new file mode 100644
index 0000000..c0d3212
--- /dev/null
+++ b/folks/birthday-owner.vala
@@ -0,0 +1,45 @@
+/*
+ * 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 GLib;
+
+/**
+ * This interface contains the birth date of a { link Persona} and
+ * { link Individual}
+ *
+ * @since 0.3.UNRELEASED
+ */
+public interface Folks.BirthdayOwner : Object
+{
+  /**
+   * The birthday of the { link Persona} and
+   * { link Individual}
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public abstract DateTime birthday { get; set; }
+
+  /**
+   * The event id from the source calenar
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public abstract string calendar_event_id { get; set; }
+}
diff --git a/folks/individual.vala b/folks/individual.vala
index fe39fad..c9ebd5e 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -65,6 +65,7 @@ public enum Folks.TrustLevel
 public class Folks.Individual : Object,
     Aliasable,
     AvatarOwner,
+    BirthdayOwner,
     Emailable,
     Favouritable,
     GenderOwner,
@@ -311,6 +312,10 @@ public class Folks.Individual : Object,
         }
     }
 
+  public DateTime birthday { get; set; }
+
+  public string calendar_event_id { get; set; }
+
   /**
    * Whether this Individual is a user-defined favourite.
    *
@@ -456,6 +461,11 @@ public class Folks.Individual : Object,
       this._update_roles ();
     }
 
+  private void _notify_birthday_cb ()
+    {
+      this._update_birthday ();
+    }
+
   /**
    * Add or remove the Individual from the specified group.
    *
@@ -875,6 +885,7 @@ public class Folks.Individual : Object,
       persona.notify["email-addresses"].connect (
           this._notify_email_addresses_cb);
       persona.notify["roles"].connect (this._notify_roles_cb);
+      persona.notify["birthday"].connect (this._notify_birthday_cb);
 
       if (persona is Groupable)
         {
@@ -965,6 +976,7 @@ public class Folks.Individual : Object,
       persona.notify["email-addresses"].disconnect (
           this._notify_email_addresses_cb);
       persona.notify["roles"].disconnect (this._notify_roles_cb);
+      persona.notify["birthday"].disconnect (this._notify_birthday_cb);
 
       if (persona is Groupable)
         {
@@ -1105,6 +1117,41 @@ public class Folks.Individual : Object,
       this.notify_property ("roles");
     }
 
+  private void _update_birthday ()
+    {
+      unowned DateTime bday = null;
+      unowned string calendar_event_id = "";
+
+      foreach (var persona in this._persona_list)
+        {
+          var bday_owner = persona as BirthdayOwner;
+          if (bday_owner != null)
+            {
+              if (bday_owner.birthday != null)
+                {
+                  if (this.birthday == null ||
+                      bday_owner.birthday.compare (this.birthday) != 0)
+                    {
+                      bday = bday_owner.birthday;
+                      calendar_event_id = bday_owner.calendar_event_id;
+                      break;
+                    }
+                }
+            }
+        }
+
+      if (this.birthday != null && bday == null)
+        {
+          this.birthday = null;
+          this.calendar_event_id = null;
+        }
+      else if (bday != null)
+        {
+          this.birthday = bday;
+          this.calendar_event_id = calendar_event_id;
+        }
+    }
+
   private void _set_personas (GLib.List<Persona>? persona_list,
       Individual? replacement_individual)
     {



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