[ekiga] Reworked the contact removal detection code in the evolution plugin



commit 19ca85e817bd88b7a0cefdef0247abe273d89e6b
Author: Julien Puydt <jpuydt gnome org>
Date:   Sat Jan 23 20:28:07 2010 +0100

    Reworked the contact removal detection code in the evolution plugin
    
    That code (which I wrote) sucked in various and entertaining different ways:
    - it was modifying the container while looping on it (iterator corruption -> crash!)
    - it didn't initialize a variable properly, so it was going out of a loop too early (this was bug #597750)
    
    This makes it work better, and fixes bug #597750.

 plugins/evolution/evolution-book.cpp |   35 ++++++++++++++++++++++++---------
 1 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/plugins/evolution/evolution-book.cpp b/plugins/evolution/evolution-book.cpp
index 1f454c0..a824905 100644
--- a/plugins/evolution/evolution-book.cpp
+++ b/plugins/evolution/evolution-book.cpp
@@ -92,35 +92,50 @@ class contacts_removed_helper
 {
 public:
 
-  contacts_removed_helper (const std::string id_): id(id_)
+  contacts_removed_helper (GList* ids_): ids(ids_)
   {}
 
+  ~contacts_removed_helper ()
+  {
+    for (std::list<Evolution::ContactPtr>::iterator iter = dead_contacts.begin ();
+	 iter != dead_contacts.end ();
+	 ++iter) {
+
+      (*iter)->removed ();
+    }
+  }
+
   bool test (Ekiga::ContactPtr contact_)
   {
     Evolution::ContactPtr contact = boost::dynamic_pointer_cast<Evolution::Contact> (contact_);
-    bool result;
+    bool result = true;
 
-    if (contact && contact->get_id () == id) {
+    if (contact) {
 
-      contact->removed ();
-      result = false;
+      for (GList* ptr = ids; ptr != NULL; ptr = g_list_next (ptr)) {
+
+	if (contact->get_id () == std::string ((gchar*)ptr->data)) {
+
+	  dead_contacts.push_front (contact);
+	  result = false;
+	}
+      }
     }
 
     return result;
   }
 
 private:
-  const std::string id;
+  GList* ids;
+  std::list<Evolution::ContactPtr> dead_contacts;
 };
 
 void
 Evolution::Book::on_view_contacts_removed (GList *ids)
 {
-  for (; ids != NULL; ids = g_list_next (ids)) {
+  contacts_removed_helper helper (ids);
 
-    contacts_removed_helper helper((gchar*)ids->data);
-    visit_contacts (boost::bind (&contacts_removed_helper::test, helper, _1));
-  }
+  visit_contacts (boost::bind (&contacts_removed_helper::test, helper, _1));
 }
 
 static void



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