[folks] Ensure that all modifications of Individual.personas happen in _set_personas()



commit 21b750e58f6ba3c00fdb550a56669dd6395ea824
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Jul 3 20:18:33 2011 +0100

    Ensure that all modifications of Individual.personas happen in _set_personas()
    
    This ensures that signals are handled consistently, and the overall internal
    state of the Individual is kept consistent. This probably also fixes the
    implementation of store_removed signal handling for Individuals, which looked
    rather broken.

 folks/individual.vala |   50 ++++++++++++++++--------------------------------
 1 files changed, 17 insertions(+), 33 deletions(-)
---
diff --git a/folks/individual.vala b/folks/individual.vala
index ccfc456..79630e3 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -738,29 +738,19 @@ public class Folks.Individual : Object,
 
   private void _store_removed_cb (PersonaStore store)
     {
-      var removed_personas = new HashSet<Persona> ();
-      var iter = this._persona_set.iterator ();
-      while (iter.next ())
-        {
-          var persona = iter.get ();
-
-          removed_personas.add (persona);
-          iter.remove ();
-        }
-
-      if (removed_personas != null)
-        this._emit_personas_changed (null, removed_personas);
+      var remaining_personas = new HashSet<Persona> ();
 
-      if (store != null)
-        this._stores.unset (store);
-
-      if (this._persona_set.size < 1)
+      /* Build a set of the remaining personas (those which weren't in the
+       * removed store. */
+      foreach (var persona in this._persona_set)
         {
-          this.removed (null);
-          return;
+          if (persona.store != store)
+            {
+              remaining_personas.add (persona);
+            }
         }
 
-      this._update_fields ();
+      this._set_personas (remaining_personas, null);
     }
 
   private void _store_personas_changed_cb (PersonaStore store,
@@ -770,25 +760,19 @@ public class Folks.Individual : Object,
       Persona? actor,
       GroupDetails.ChangeReason reason)
     {
-      var removed_personas = new HashSet<Persona> ();
-      foreach (var p in removed)
+      var remaining_personas = new HashSet<Persona> ();
+
+      /* Build a set of the remaining personas (those which aren't in the
+       * set of removed personas). */
+      foreach (var persona in this._persona_set)
         {
-          if (this._persona_set.remove (p))
+          if (!removed.contains (persona))
             {
-              removed_personas.add (p);
+              remaining_personas.add (persona);
             }
         }
 
-      if (removed_personas != null)
-        this._emit_personas_changed (null, removed_personas);
-
-      if (this._persona_set.size < 1)
-        {
-          this.removed (null);
-          return;
-        }
-
-      this._update_fields ();
+      this._set_personas (remaining_personas, null);
     }
 
   private void _update_fields ()



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