Bug 645549 — Add a way to get the individual from a persona
authorPhilip Withnall <philip@tecnocode.co.uk>
Sun, 3 Jul 2011 19:38:29 +0000 (20:38 +0100)
committerPhilip Withnall <philip@tecnocode.co.uk>
Wed, 20 Jul 2011 21:14:42 +0000 (22:14 +0100)
Add a Persona.individual property which is updated by
Individual._connect_to_persona() and ._disconnect_from_persona() as
appropriate, so should remain in lock-step with the Individual whose persona
set the Persona instance is currently in.

Closes: bgo#645549

NEWS
folks/individual.vala
folks/persona.vala

diff --git a/NEWS b/NEWS
index e2853fb..fc737c8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ Bugs fixed:
 * Bug 654509 — Folks master not building
 * Bug 652048 — Make nickname writable
 * Bug 652425 — Failure codes for removing personas needed in PersonaStoreError
+* Bug 645549 — Add a way to get the individual from a persona
 
 API changes:
 * Swf.Persona retains and exposes its libsocialweb Contact
@@ -27,6 +28,7 @@ API changes:
 * Add PersonaStoreError.PERMISSION_DENIED and PersonaStoreError.REMOVE_FAILED
 * Change the error domain of PersonaStore.remove_persona() from GLib.Error to
   Folks.PersonaStoreError
+* Add a Persona.individual property
 
 Overview of changes from libfolks 0.5.1 to libfolks 0.5.2
 =========================================================
index 79630e3..8cdb9dd 100644 (file)
@@ -1101,6 +1101,8 @@ public class Folks.Individual : Object,
 
   private void _connect_to_persona (Persona persona)
     {
+      persona.individual = this;
+
       persona.notify["alias"].connect (this._notify_alias_cb);
       persona.notify["avatar"].connect (this._notify_avatar_cb);
       persona.notify["presence-message"].connect (this._notify_presence_cb);
@@ -1208,7 +1210,8 @@ public class Folks.Individual : Object,
         }
     }
 
-  private void _disconnect_from_persona (Persona persona)
+  private void _disconnect_from_persona (Persona persona,
+      Individual? replacement_individual)
     {
       persona.notify["alias"].disconnect (this._notify_alias_cb);
       persona.notify["avatar"].disconnect (this._notify_avatar_cb);
@@ -1244,6 +1247,8 @@ public class Folks.Individual : Object,
           ((GroupDetails) persona).group_changed.disconnect (
               this._persona_group_changed_cb);
         }
+
+      persona.individual = replacement_individual;
     }
 
   private void _update_gender ()
@@ -1558,7 +1563,7 @@ public class Folks.Individual : Object,
                   this._stores.unset (store);
                 }
 
-              this._disconnect_from_persona (p);
+              this._disconnect_from_persona (p, replacement_individual);
               iter.remove ();
             }
         }
index 8f36b81..a49805b 100644 (file)
@@ -30,6 +30,8 @@ using GLib;
  */
 public abstract class Folks.Persona : Object
 {
+  private weak Individual _individual;
+
   /**
    * The internal ID used to represent the Persona for linking.
    *
@@ -105,6 +107,33 @@ public abstract class Folks.Persona : Object
   public weak PersonaStore store { get; construct; }
 
   /**
+   * The {@link Individual} which contains this Persona.
+   *
+   * This may be `null`, but should only ever be so when the Persona has just
+   * been created, when its {@link PersonaStore} is being destroyed, or when
+   * it's moving between {@link Individual}s.
+   *
+   * @since UNRELEASED
+   */
+  public weak Individual? individual
+    {
+      get
+        {
+          assert (this._individual == null ||
+              this._individual.personas.contains (this));
+
+          return this._individual;
+        }
+
+      internal set
+        {
+          assert (value == null || value.personas.contains (this));
+
+          this._individual = value;
+        }
+    }
+
+  /**
    * The names of the properties of this Persona which are linkable.
    *
    * If a property name is in this list, and the Persona is from a