[folks] core: Add BirthdayDetails.change_birthday() and .change_calendar_event_id()



commit a5517e657d92d95e295714bb2be97a93261a9d1a
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Aug 28 19:46:58 2011 +0100

    core: Add BirthdayDetails.change_birthday() and .change_calendar_event_id()
    
    These allows the birthday (and its calendar event) of an implementing class
    to be changed asynchronously with proper error notification.
    
    Helps: bgo#657510

 backends/tracker/lib/trf-persona.vala |   19 +++++++++---
 folks/birthday-details.vala           |   42 ++++++++++++++++++++++++++++
 folks/individual.vala                 |   48 ++++++++++++++++++++++++++------
 po/POTFILES.in                        |    1 +
 po/POTFILES.skip                      |    1 +
 5 files changed, 97 insertions(+), 14 deletions(-)
---
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 6035016..ea009dc 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -202,23 +202,32 @@ public class Trf.Persona : Folks.Persona,
   /**
    * { inheritDoc}
    */
+  [CCode (notify = false)]
   public DateTime? birthday
     {
       get { return this._birthday; }
-      public set
-        {
-          ((Trf.PersonaStore) this.store)._set_birthday (this, value);
-        }
+      set { this.change_birthday.begin (value); }
     }
 
   /**
    * { inheritDoc}
+   *
+   * @since UNRELEASED
    */
+  public async void change_birthday (DateTime? birthday) throws PropertyError
+    {
+      yield ((Trf.PersonaStore) this.store)._set_birthday (this, birthday);
+    }
+
+  /**
+   * { inheritDoc}
+   */
+  [CCode (notify = false)]
   public string? calendar_event_id
     {
       /* Unsupported */
       get { return null; }
-      private set {}
+      set { this.change_calendar_event_id.begin (value); } /* not writeable */
     }
 
   private HashSet<RoleFieldDetails> _roles;
diff --git a/folks/birthday-details.vala b/folks/birthday-details.vala
index d6ee9e0..69d23b0 100644
--- a/folks/birthday-details.vala
+++ b/folks/birthday-details.vala
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011 Philip Withnall
  *
  * 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
@@ -16,6 +17,7 @@
  *
  * Authors:
  *       Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *       Philip Withnall <philip tecnocode co uk>
  */
 
 using GLib;
@@ -38,6 +40,26 @@ public interface Folks.BirthdayDetails : Object
   public abstract DateTime? birthday { get; set; }
 
   /**
+   * Change the contact's birthday.
+   *
+   * It's preferred to call this rather than setting
+   * { link BirthdayDetails.birthday} directly, as this method gives error
+   * notification and will only return once the birthday has been written to the
+   * relevant backing store (or the operation's failed).
+   *
+   * @param birthday the new birthday (or `null` to unset the birthday)
+   * @throws PropertyError if setting the birthday failed
+   * @since UNRELEASED
+   */
+  public virtual async void change_birthday (DateTime? birthday)
+      throws PropertyError
+    {
+      /* Default implementation. */
+      throw new PropertyError.NOT_WRITEABLE (
+          _("Birthday is not writeable on this contact."));
+    }
+
+  /**
    * The event ID of the birthday event from the source calendar.
    *
    * If this is `null`, the birthday event is unknown.
@@ -45,4 +67,24 @@ public interface Folks.BirthdayDetails : Object
    * @since 0.4.0
    */
   public abstract string? calendar_event_id { get; set; }
+
+  /**
+   * Change the contact's birthday event ID.
+   *
+   * It's preferred to call this rather than setting
+   * { link BirthdayDetails.calendar_event_id} directly, as this method gives
+   * error notification and will only return once the event has been written to
+   * the relevant backing store (or the operation's failed).
+   *
+   * @param event_id the new birthday event ID (or `null` to unset the event ID)
+   * @throws PropertyError if setting the birthday event ID failed
+   * @since UNRELEASED
+   */
+  public virtual async void change_calendar_event_id (string? event_id)
+      throws PropertyError
+    {
+      /* Default implementation. */
+      throw new PropertyError.NOT_WRITEABLE (
+          _("Birthday event ID is not writeable on this contact."));
+    }
 }
diff --git a/folks/individual.vala b/folks/individual.vala
index f22075d..a215296 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -431,9 +431,29 @@ public class Folks.Individual : Object,
         }
     }
 
-  public DateTime? birthday { get; private set; }
+  private DateTime? _birthday = null;
 
-  public string? calendar_event_id { get; set; }
+  /**
+   * { inheritDoc}
+   */
+  [CCode (notify = false)]
+  public DateTime? birthday
+    {
+      get { return this._birthday; }
+      set { this.change_birthday.begin (value); } /* not writeable */
+    }
+
+  private string? _calendar_event_id = null;
+
+  /**
+   * { inheritDoc}
+   */
+  [CCode (notify = false)]
+  public string? calendar_event_id
+    {
+      get { return this._calendar_event_id; }
+      set { this.change_calendar_event_id.begin (value); } /* not writeable */
+    }
 
   private HashSet<NoteFieldDetails> _notes;
   private Set<NoteFieldDetails> _notes_ro;
@@ -1514,8 +1534,8 @@ public class Folks.Individual : Object,
             {
               if (bday_owner.birthday != null)
                 {
-                  if (this.birthday == null ||
-                      bday_owner.birthday.compare (this.birthday) != 0)
+                  if (this._birthday == null ||
+                      bday_owner.birthday.compare (this._birthday) != 0)
                     {
                       bday = bday_owner.birthday;
                       calendar_event_id = bday_owner.calendar_event_id;
@@ -1525,15 +1545,25 @@ public class Folks.Individual : Object,
             }
         }
 
-      if (this.birthday != null && bday == null)
+      if (this._birthday != null && bday == null)
         {
-          this.birthday = null;
-          this.calendar_event_id = null;
+          this._birthday = null;
+          this._calendar_event_id = null;
+
+          this.freeze_notify ();
+          this.notify_property ("birthday");
+          this.notify_property ("calendar-event-id");
+          this.thaw_notify ();
         }
       else if (bday != null)
         {
-          this.birthday = bday;
-          this.calendar_event_id = calendar_event_id;
+          this._birthday = bday;
+          this._calendar_event_id = calendar_event_id;
+
+          this.freeze_notify ();
+          this.notify_property ("birthday");
+          this.notify_property ("calendar-event-id");
+          this.thaw_notify ();
         }
     }
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 640e25a..f9bf80f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -10,6 +10,7 @@ backends/tracker/lib/trf-persona-store.vala
 folks/alias-details.vala
 folks/avatar-details.vala
 folks/backend-store.vala
+folks/birthday-details.vala
 folks/im-details.vala
 folks/individual-aggregator.vala
 folks/postal-address-details.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 898acd8..fe23b1d 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -9,6 +9,7 @@ docs/gtk-doc/folks-telepathy/ccomments/tp-lowlevel.c
 folks/alias-details.c
 folks/avatar-details.c
 folks/backend-store.c
+folks/birthday-details.c
 folks/im-details.c
 folks/individual-aggregator.c
 folks/postal-address-details.c



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