[ekiga/ds-fix-boost-leaks: 6/7] Evolution: Migrated to the new framework.



commit 3ddcaff16a69a31f4c2095747bde0b28d91e4074
Author: Damien Sandras <dsandras seconix com>
Date:   Mon May 25 17:43:07 2015 +0200

    Evolution: Migrated to the new framework.

 plugins/evolution/evolution-book.cpp    |   31 +++++++++-----
 plugins/evolution/evolution-book.h      |   10 +++-
 plugins/evolution/evolution-contact.cpp |   72 +++++++++++++++++++------------
 plugins/evolution/evolution-contact.h   |   13 ++++--
 plugins/evolution/evolution-main.cpp    |    7 ++-
 plugins/evolution/evolution-source.cpp  |   56 +++++++++++++++---------
 plugins/evolution/evolution-source.h    |    8 +++-
 7 files changed, 125 insertions(+), 72 deletions(-)
---
diff --git a/plugins/evolution/evolution-book.cpp b/plugins/evolution/evolution-book.cpp
index 9c2a0cf..065b268 100644
--- a/plugins/evolution/evolution-book.cpp
+++ b/plugins/evolution/evolution-book.cpp
@@ -64,15 +64,13 @@ Evolution::Book::on_view_contacts_added (GList *econtacts)
 
     if (e_contact_get_const (econtact, E_CONTACT_FULL_NAME) != NULL) {
 
-      ContactPtr contact(new Evolution::Contact (services, book,
-                                                econtact));
-
+      ContactPtr contact = Evolution::Contact::create (services, book, econtact);
       add_contact (contact);
       nbr++;
     }
   }
 
-  updated ();
+  updated (this->shared_from_this ());
 }
 
 static void
@@ -96,7 +94,7 @@ public:
         iter != dead_contacts.end ();
         ++iter) {
 
-      (*iter)->removed ();
+      (*iter)->removed (*iter);
     }
   }
 
@@ -213,8 +211,9 @@ Evolution::Book::on_book_view_obtained (EBookStatus _status,
                      G_CALLBACK (on_view_contacts_changed_c), this);
 
     e_book_view_start (view);
-  } else
-    removed ();
+  }
+  else
+    removed (this->shared_from_this ());
 }
 
 static void
@@ -248,18 +247,27 @@ Evolution::Book::on_book_opened (EBookStatus _status)
   else {
 
     book = NULL;
-    removed ();
+    removed (this->shared_from_this ());
   }
 }
 
+boost::shared_ptr<Evolution::Book>
+Evolution::Book::create (Ekiga::ServiceCore &_services,
+                         EBook *_book)
+{
+  boost::shared_ptr<Evolution::Book> book = boost::shared_ptr<Evolution::Book> (new Evolution::Book 
(_services, _book));
+  book->refresh ();
+
+  return book;
+}
+
+
 Evolution::Book::Book (Ekiga::ServiceCore &_services,
                       EBook *_book)
   : services(_services), book(_book), view(NULL)
 {
   g_object_ref (book);
 
-  refresh ();
-
   /* Actor stuff */
   add_action (Ekiga::ActionPtr (new Ekiga::Action ("add-contact", _("A_dd Contact"),
                                                    boost::bind (&Evolution::Book::new_contact_action, 
this))));
@@ -269,6 +277,7 @@ Evolution::Book::~Book ()
 {
   if (book != NULL)
     g_object_unref (book);
+
 #if DEBUG
   std::cout << "Evolution::Book: Destructor invoked" << std::endl;
 #endif
@@ -327,7 +336,7 @@ Evolution::Book::get_status () const
 void
 Evolution::Book::refresh ()
 {
-  remove_all_objects ();
+  contacts.remove_all_objects ();
 
   /* we go */
   if (e_book_is_opened (book))
diff --git a/plugins/evolution/evolution-book.h b/plugins/evolution/evolution-book.h
index 906816c..2024380 100644
--- a/plugins/evolution/evolution-book.h
+++ b/plugins/evolution/evolution-book.h
@@ -49,6 +49,7 @@
 #include "book-impl.h"
 
 #include "evolution-contact.h"
+#include "dynamic-object.h"
 
 namespace Evolution
 {
@@ -61,12 +62,13 @@ namespace Evolution
 
   class Book:
     public virtual Ekiga::Filterable,
-    public Ekiga::BookImpl<Contact>
+    public Ekiga::BookImpl<Contact>,
+    public Ekiga::DynamicObject<Book>
   {
   public:
 
-    Book (Ekiga::ServiceCore &_services,
-         EBook *_book);
+    static boost::shared_ptr<Book> create (Ekiga::ServiceCore &_services,
+                                           EBook *_book);
 
     ~Book ();
 
@@ -96,6 +98,8 @@ namespace Evolution
     void on_view_contacts_changed (GList *econtacts);
 
   private:
+    Book (Ekiga::ServiceCore &_services,
+         EBook *_book);
 
     void new_contact_action ();
     void set_econtact_attribute_value (EContact *contact,
diff --git a/plugins/evolution/evolution-contact.cpp b/plugins/evolution/evolution-contact.cpp
index d819216..5b74440 100644
--- a/plugins/evolution/evolution-contact.cpp
+++ b/plugins/evolution/evolution-contact.cpp
@@ -40,6 +40,8 @@
 #include "form-request-simple.h"
 #include "menu-builder-tools.h"
 
+#define DEBUG 1
+
 /* at one point we will return a smart pointer on this... and if we don't use
  * a false smart pointer, we will crash : the reference count isn't embedded!
  */
@@ -50,43 +52,46 @@ struct null_deleter
     }
 };
 
+
+boost::shared_ptr<Evolution::Contact>
+Evolution::Contact::create (Ekiga::ServiceCore &_services,
+                            EBook *ebook,
+                            EContact *econtact)
+{
+  boost::shared_ptr<Evolution::Contact> contact = boost::shared_ptr<Evolution::Contact> (new 
Evolution::Contact (_services, ebook));
+
+  if (E_IS_CONTACT (econtact))
+    contact->update_econtact (econtact);
+
+  return contact;
+}
+
 Evolution::Contact::Contact (Ekiga::ServiceCore &_services,
-                            EBook *ebook,
-                            EContact *_econtact) : services(_services),
-                                                   book(ebook),
-                                                   econtact(NULL)
+                            EBook *ebook) : services(_services),
+                                             book(ebook),
+                                             econtact(NULL)
 {
   for (unsigned int ii = 0;
        ii < ATTR_NUMBER;
        ii++)
     attributes[ii] = NULL;
 
-  if (E_IS_CONTACT (_econtact))
-    update_econtact (_econtact);
 
   /* Actor stuff */
   add_action (Ekiga::ActionPtr (new Ekiga::Action ("edit-contact", _("_Edit"),
                                                    boost::bind (&Evolution::Contact::edit_action, this))));
   add_action (Ekiga::ActionPtr (new Ekiga::Action ("remove-contact", _("_Remove"),
                                                    boost::bind (&Evolution::Contact::remove_action, this))));
-
-  /* Pull actions */
-  boost::shared_ptr<Ekiga::ContactCore> core = services.get<Ekiga::ContactCore> ("contact-core");
-  if (core) {
-    for (unsigned int attr_type = 0; attr_type < ATTR_NUMBER; attr_type++) {
-
-      std::string attr_value = get_attribute_value (attr_type);
-      if (!attr_value.empty ()) {
-        core->pull_actions (*this, get_name (), attr_value);
-      }
-    }
-  }
 }
 
 Evolution::Contact::~Contact ()
 {
   if (E_IS_CONTACT (econtact))
     g_object_unref (econtact);
+
+#if DEBUG
+  std::cout << __FUNCTION__ << " invoked in " << __FILE__ << std::endl << std::flush;
+#endif
 }
 
 const std::string
@@ -124,6 +129,7 @@ void
 Evolution::Contact::update_econtact (EContact *_econtact)
 {
   GList *attrs = NULL;
+  unsigned int attr_type = 0;
 
   if (E_IS_CONTACT (econtact))
     g_object_unref (econtact);
@@ -138,6 +144,8 @@ Evolution::Contact::update_econtact (EContact *_econtact)
 
   attrs = e_vcard_get_attributes (E_VCARD (econtact));
 
+  boost::shared_ptr<Ekiga::ContactCore> core = services.get<Ekiga::ContactCore> ("contact-core");
+
   for (GList *attribute_ptr = attrs ;
        attribute_ptr != NULL;
        attribute_ptr = g_list_next (attribute_ptr)) {
@@ -180,30 +188,37 @@ Evolution::Contact::update_econtact (EContact *_econtact)
            if (type_name == "HOME") {
 
              attributes[ATTR_HOME] = attribute;
-             break;
-           } else if (type_name == "CELL") {
+              attr_type = ATTR_HOME;
+           }
+            else if (type_name == "CELL") {
 
              attributes[ATTR_CELL] = attribute;
-             break;
-           } else if (type_name == "WORK") {
+              attr_type = ATTR_CELL;
+           }
+            else if (type_name == "WORK") {
 
              attributes[ATTR_WORK] = attribute;
-             break;
-           } else if (type_name == "PAGER") {
+              attr_type = ATTR_WORK;
+           }
+            else if (type_name == "PAGER") {
 
              attributes[ATTR_PAGER] = attribute;
-             break;
-           } else if (type_name == "VIDEO") {
+              attr_type = ATTR_PAGER;
+           }
+            else if (type_name == "VIDEO") {
 
              attributes[ATTR_VIDEO] = attribute;
-             break;
+              attr_type = ATTR_VIDEO;
            }
+            if (core)
+              core->pull_actions (*this, get_name (), get_attribute_value (attr_type));
          }
        }
       }
     }
   }
-  updated ();
+
+  updated (this->shared_from_this ());
 }
 
 void
@@ -375,5 +390,6 @@ Evolution::Contact::on_remove_form_submitted (bool submitted,
   if (!submitted)
     return false;
 
+  remove ();
   return true;
 }
diff --git a/plugins/evolution/evolution-contact.h b/plugins/evolution/evolution-contact.h
index eb4adf7..346ad1c 100644
--- a/plugins/evolution/evolution-contact.h
+++ b/plugins/evolution/evolution-contact.h
@@ -47,6 +47,7 @@
 #endif
 #include "contact-core.h"
 #include "form.h"
+#include "dynamic-object.h"
 
 namespace Evolution
 {
@@ -57,13 +58,15 @@ namespace Evolution
  * @{
  */
 
-  class Contact: public Ekiga::Contact
+  class Contact:
+      public Ekiga::Contact,
+      public Ekiga::DynamicObject<Contact>
   {
   public:
 
-    Contact (Ekiga::ServiceCore &_services,
-            EBook *ebook = NULL,
-            EContact *econtact = NULL);
+    static boost::shared_ptr<Contact> create (Ekiga::ServiceCore &_services,
+                                              EBook *ebook = NULL,
+                                              EContact *econtact = NULL);
 
     ~Contact ();
 
@@ -78,6 +81,8 @@ namespace Evolution
     void remove ();
 
   private:
+    Contact (Ekiga::ServiceCore &_services,
+            EBook *ebook = NULL);
 
     // attributes of interest to that code :
     enum {
diff --git a/plugins/evolution/evolution-main.cpp b/plugins/evolution/evolution-main.cpp
index d06e06e..d06fa14 100644
--- a/plugins/evolution/evolution-main.cpp
+++ b/plugins/evolution/evolution-main.cpp
@@ -38,6 +38,7 @@
 #include "contact-core.h"
 
 #include "evolution-main.h"
+
 #include "evolution-source.h"
 
 struct EVOSpark: public Ekiga::Spark
@@ -46,15 +47,15 @@ struct EVOSpark: public Ekiga::Spark
   {}
 
   bool try_initialize_more (Ekiga::ServiceCore &services,
-                           int */*argc*/,
-                           char **/*argv*/[])
+                           G_GNUC_UNUSED int *argc,
+                           G_GNUC_UNUSED char **argv[])
   {
     boost::shared_ptr<Ekiga::ContactCore> core = services.get<Ekiga::ContactCore> ("contact-core");
     Ekiga::ServicePtr service = services.get ("evolution-source");
 
     if (core && !service) {
 
-      boost::shared_ptr<Evolution::Source> source (new Evolution::Source (services));
+      boost::shared_ptr<Evolution::Source> source = Evolution::Source::create (services);
       services.add (source);
       core->add_source (source);
       result = true;
diff --git a/plugins/evolution/evolution-source.cpp b/plugins/evolution/evolution-source.cpp
index c4f0704..e124efe 100644
--- a/plugins/evolution/evolution-source.cpp
+++ b/plugins/evolution/evolution-source.cpp
@@ -78,7 +78,7 @@ Evolution::Source::add_source (ESource *source)
 {
   EBook *ebook = NULL;
   ebook = e_book_new (source, NULL);
-  BookPtr book (new Evolution::Book (services, ebook));
+  BookPtr book = Evolution::Book::create (services, ebook);
   g_object_unref (ebook);
   add_book (book);
 }
@@ -171,7 +171,7 @@ public :
 
       if (book_group == group) {
 #endif
-        book->removed ();
+        book->removed (book);
         found = true;
       }
     }
@@ -210,9 +210,42 @@ Evolution::Source::remove_group (ESourceGroup *group)
   } while (helper.has_found ());
 }
 
+boost::shared_ptr<Evolution::Source>
+Evolution::Source::create (Ekiga::ServiceCore &_services)
+{
+  boost::shared_ptr<Evolution::Source> source = boost::shared_ptr<Evolution::Source> (new Evolution::Source 
(_services));
+  source->load ();
+
+  return source;
+}
+
 Evolution::Source::Source (Ekiga::ServiceCore &_services)
   : services(_services)
 {
+}
+
+Evolution::Source::~Source ()
+{
+#if EDS_CHECK_VERSION(3,5,3)
+  g_object_unref (registry);
+#else
+  g_object_unref (source_list);
+#endif
+#if DEBUG
+  std::cout << "Evolution::Source: Destructor invoked" << std::endl;
+#endif
+}
+
+bool
+Evolution::Source::populate_menu (Ekiga::MenuBuilder &/*builder*/)
+{
+  /* FIXME: add back creating a new addressbook later */
+  return false;
+}
+
+void
+Evolution::Source::load ()
+{
 #if EDS_CHECK_VERSION(3,5,3)
   GList *list, *link;
   const gchar *extension_name;
@@ -262,22 +295,3 @@ Evolution::Source::Source (Ekiga::ServiceCore &_services)
                    G_CALLBACK (on_source_list_group_removed_c), this);
 #endif
 }
-
-Evolution::Source::~Source ()
-{
-#if EDS_CHECK_VERSION(3,5,3)
-  g_object_unref (registry);
-#else
-  g_object_unref (source_list);
-#endif
-#if DEBUG
-  std::cout << "Evolution::Source: Destructor invoked" << std::endl;
-#endif
-}
-
-bool
-Evolution::Source::populate_menu (Ekiga::MenuBuilder &/*builder*/)
-{
-  /* FIXME: add back creating a new addressbook later */
-  return false;
-}
diff --git a/plugins/evolution/evolution-source.h b/plugins/evolution/evolution-source.h
index 31baaea..8b172b1 100644
--- a/plugins/evolution/evolution-source.h
+++ b/plugins/evolution/evolution-source.h
@@ -48,6 +48,7 @@
 #include "source-impl.h"
 
 #include "evolution-book.h"
+#include "dynamic-object.h"
 
 namespace Evolution
 {
@@ -60,11 +61,12 @@ namespace Evolution
 
   class Source:
     public Ekiga::Service,
-    public Ekiga::SourceImpl<Book>
+    public Ekiga::SourceImpl<Book>,
+    public Ekiga::DynamicObject<Source>
   {
   public:
 
-    Source (Ekiga::ServiceCore &_services);
+    static boost::shared_ptr<Source> create (Ekiga::ServiceCore &_services);
 
     ~Source ();
 
@@ -88,6 +90,8 @@ namespace Evolution
 #endif
 
   private:
+    void load ();
+    Source (Ekiga::ServiceCore &_services);
 
     Ekiga::ServiceCore &services;
 #if EDS_CHECK_VERSION(3,5,3)


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