[niepce] * Refactor NotificationCenter to not have to decode



commit 3ec3826604b58d41e5c515e2162010bd5c4cfec3
Author: Hubert Figuiere <hub figuiere net>
Date:   Sun May 10 21:29:50 2009 -0400

    	* Refactor NotificationCenter to not have to decode
    	the notification every time.
---
 ChangeLog                                   |    9 ++
 src/fwk/toolkit/notificationcenter.cpp      |   84 +++++++++--------
 src/fwk/toolkit/notificationcenter.hpp      |    6 +-
 src/niepce/Makefile.am                      |    1 +
 src/niepce/notificationcenter.cpp           |   62 ++++++++++++
 src/niepce/notificationcenter.hpp           |   51 ++++++++++
 src/niepce/notifications.hpp                |    3 +-
 src/niepce/ui/imageliststore.cpp            |  129 +++++++++++--------------
 src/niepce/ui/imageliststore.hpp            |    7 +-
 src/niepce/ui/librarymainviewcontroller.cpp |   48 +++++-----
 src/niepce/ui/librarymainviewcontroller.hpp |    3 +-
 src/niepce/ui/niepcewindow.cpp              |  136 +++++++++++++--------------
 src/niepce/ui/niepcewindow.hpp              |    8 +-
 src/niepce/ui/workspacecontroller.cpp       |   99 +++++++++----------
 src/niepce/ui/workspacecontroller.hpp       |    4 +-
 15 files changed, 378 insertions(+), 272 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 87ae067..6792836 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-05-10  Hubert Figuiere  <hub figuiere net>
+
+	* Refactor NotificationCenter to not have to decode
+	the notification every time.
+
+	* collapse db:: and library:: to eng::
+
+	* replace the utils namespace by the fwk namespace
+
 2009-05-08  Hubert Figuiere  <hub figuiere net>
 
 	* Refactor init to fwk::utils::init()
diff --git a/src/fwk/toolkit/notificationcenter.cpp b/src/fwk/toolkit/notificationcenter.cpp
index 341fe43..d396c46 100644
--- a/src/fwk/toolkit/notificationcenter.cpp
+++ b/src/fwk/toolkit/notificationcenter.cpp
@@ -1,7 +1,7 @@
 /*
- * niepce - fwk/notification.h
+ * niepce - fwk/toolkit/notification.h
  *
- * Copyright (C) 2007 Hubert Figuiere
+ * Copyright (C) 2007-2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,10 +21,6 @@
 #include <map>
 #include <functional>
 
-#include <boost/bind.hpp>
-#include <boost/bind/apply.hpp>
-#include <boost/function_equal.hpp>
-
 #include <glibmm/dispatcher.h>
 
 #include "fwk/utils/mtqueue.hpp"
@@ -32,57 +28,65 @@
 
 namespace fwk {
 
-	class NotificationCenter::Priv
-	{
-	public:
-		typedef std::list< subscriber_t > SubscriberList;
+class NotificationCenter::Priv
+{
+public:
 		Glib::Dispatcher                     m_dispatcher;
-		sigc::connection                     m_dispatchConn;
 		fwk::MtQueue< Notification::Ptr >    m_notificationQueue;
-		std::map< int, SubscriberList >      m_subscribers;
-	};
+		std::map< int, subscription_t >      m_subscribers;
+};
 
 
-	NotificationCenter::NotificationCenter()
+NotificationCenter::NotificationCenter()
 		: p( new Priv )
-	{
-		p->m_dispatchConn = p->m_dispatcher.connect(
-			sigc::mem_fun(this, &NotificationCenter::_dispatch));
-	}
-
-	NotificationCenter::~NotificationCenter()
-	{
-		p->m_dispatchConn.disconnect();
+{
+		p->m_dispatcher.connect(
+        sigc::mem_fun(this, &NotificationCenter::_dispatch));
+}
+
+NotificationCenter::~NotificationCenter()
+{
 		delete p;
-	}
+}
 
 
-	void NotificationCenter::subscribe(int type, const subscriber_t & s)
-	{
-		
+void NotificationCenter::subscribe(int type, const subscriber_t & s)
+{
 		// TODO make sure it is not yet subscribed
-		p->m_subscribers[type].push_back(s);
-	}
+		p->m_subscribers[type].connect(s);
+}
 
-	void NotificationCenter::unsubscribe(int /*type*/, const subscriber_t & /*s*/)
-	{
+void NotificationCenter::unsubscribe(int /*type*/, const subscriber_t & /*s*/)
+{
 //		m_subscribers.remove_if(boost::bind(&boost::function_equal, _1, s));
-	}
+}
 
-	void NotificationCenter::post(const Notification::Ptr & n)
-	{ 
+void NotificationCenter::post(const Notification::Ptr & n)
+{
+    /* called out of thread */
+    /* MUST be thread safe */
 		p->m_notificationQueue.add(n);
 		p->m_dispatcher.emit();
-	}
+}
 	
-	void NotificationCenter::_dispatch(void)
-	{
+void NotificationCenter::_dispatch(void)
+{
+    /* this is not pop() like in STL. */
 		Notification::Ptr notif( p->m_notificationQueue.pop() );
 
 		Notification::mutex_t::Lock lock(notif->mutex());
-		const Priv::SubscriberList & subscriber_list(p->m_subscribers[notif->type()]);
-		std::for_each(subscriber_list.begin(), subscriber_list.end(), 
-					  bind(boost::apply<void>(), _1, boost::ref(notif)));
-	}
+    p->m_subscribers[notif->type()](notif);
 }
 
+
+}
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0))
+  indent-tabs-mode:nil
+  fill-column:80
+  End:
+*/
diff --git a/src/fwk/toolkit/notificationcenter.hpp b/src/fwk/toolkit/notificationcenter.hpp
index 0a03336..3b2ba28 100644
--- a/src/fwk/toolkit/notificationcenter.hpp
+++ b/src/fwk/toolkit/notificationcenter.hpp
@@ -23,7 +23,6 @@
 #ifndef __FWK_NOTIFICATIONCENTER_H__
 #define __FWK_NOTIFICATIONCENTER_H__
 
-#include <boost/function.hpp>
 #include <tr1/memory>
 
 #include "fwk/toolkit/notification.hpp"
@@ -31,10 +30,11 @@
 namespace fwk {
 
 	class NotificationCenter
+    : public sigc::trackable
 	{
 	public:
 		typedef std::tr1::shared_ptr< NotificationCenter > Ptr;
-		typedef boost::function< void (Notification::Ptr) > subscriber_t;
+    typedef sigc::slot<void, Notification::Ptr> subscriber_t;
 
 		NotificationCenter();
 		~NotificationCenter();
@@ -47,6 +47,8 @@ namespace fwk {
 		void unsubscribe(int type, const subscriber_t & );
 		
 	private:
+		typedef sigc::signal<void, Notification::Ptr> subscription_t;
+
 		void _dispatch(void);
 
 		class Priv;
diff --git a/src/niepce/Makefile.am b/src/niepce/Makefile.am
index ef494b5..ba31ade 100644
--- a/src/niepce/Makefile.am
+++ b/src/niepce/Makefile.am
@@ -34,5 +34,6 @@ niepce_LDADD = \
 
 niepce_SOURCES = xmp.cpp \
 	stock.hpp stock.cpp \
+	notificationcenter.hpp notificationcenter.cpp \
         notifications.hpp xmp.hpp \
 	main.cpp
diff --git a/src/niepce/notificationcenter.cpp b/src/niepce/notificationcenter.cpp
new file mode 100644
index 0000000..b0c1ec9
--- /dev/null
+++ b/src/niepce/notificationcenter.cpp
@@ -0,0 +1,62 @@
+/*
+ * niepce - niepce/notificationcenter.hpp
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <boost/any.hpp>
+
+#include "fwk/base/debug.hpp"
+#include "niepce/notifications.hpp"
+#include "niepce/notificationcenter.hpp"
+
+namespace niepce {
+
+
+NotificationCenter::NotificationCenter()
+{
+  subscribe(NOTIFICATION_LIB, 
+            sigc::mem_fun(*this, &NotificationCenter::dispatch_notification));
+  subscribe(NOTIFICATION_THUMBNAIL, 
+            sigc::mem_fun(*this, &NotificationCenter::dispatch_notification));
+}
+
+
+void NotificationCenter::dispatch_notification(const fwk::Notification::Ptr &n)
+{
+    switch(n->type()) {
+
+    case NOTIFICATION_LIB:
+    {
+        eng::LibNotification ln 
+          = boost::any_cast<eng::LibNotification>(n->data());
+        signal_lib_notification (ln);
+        break;
+    }
+    case NOTIFICATION_THUMBNAIL:
+    {
+        eng::ThumbnailNotification tn
+          = boost::any_cast<eng::ThumbnailNotification>(n->data());
+        signal_thumbnail_notification (tn);
+        break;
+    }
+    default:
+      break;
+    }
+}
+
+
+}
diff --git a/src/niepce/notificationcenter.hpp b/src/niepce/notificationcenter.hpp
new file mode 100644
index 0000000..3fee7ec
--- /dev/null
+++ b/src/niepce/notificationcenter.hpp
@@ -0,0 +1,51 @@
+/*
+ * niepce - niepce/notificationcenter.hpp
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __NIEPCE_NOTIFICATIONCENTER_HPP_
+#define __NIEPCE_NOTIFICATIONCENTER_HPP_
+
+#include <tr1/memory>
+#include <sigc++/signal.h>
+
+#include "fwk/toolkit/notificationcenter.hpp"
+#include "engine/db/library.hpp"
+#include "engine/library/thumbnailnotification.hpp"
+
+
+namespace niepce {
+
+
+class NotificationCenter
+  : public fwk::NotificationCenter
+{
+public:
+  typedef std::tr1::shared_ptr<NotificationCenter> Ptr;
+  NotificationCenter();
+
+  sigc::signal<void, const eng::LibNotification &> signal_lib_notification;
+  sigc::signal<void, const eng::ThumbnailNotification &> signal_thumbnail_notification;
+
+private:
+  void dispatch_notification(const fwk::Notification::Ptr &n);
+};
+
+}
+
+#endif
diff --git a/src/niepce/notifications.hpp b/src/niepce/notifications.hpp
index fd32d54..60053aa 100644
--- a/src/niepce/notifications.hpp
+++ b/src/niepce/notifications.hpp
@@ -25,8 +25,7 @@ namespace niepce {
 
 	enum {
 		NOTIFICATION_LIB = 0,
-		NOTIFICATION_THUMBNAIL,
-		NOTIFICATION_COUNT                    /**< Notification a counted items */
+		NOTIFICATION_THUMBNAIL
 	};
 
 }
diff --git a/src/niepce/ui/imageliststore.cpp b/src/niepce/ui/imageliststore.cpp
index 749aca3..a2cae2d 100644
--- a/src/niepce/ui/imageliststore.cpp
+++ b/src/niepce/ui/imageliststore.cpp
@@ -24,8 +24,6 @@
 #include "fwk/toolkit/application.hpp"
 #include "fwk/toolkit/gdkutils.hpp"
 #include "niepce/notifications.hpp"
-#include "engine/db/library.hpp"
-#include "engine/library/thumbnailnotification.hpp"
 #include "niepcewindow.hpp"
 
 namespace ui {
@@ -64,83 +62,72 @@ Gtk::TreePath ImageListStore::get_path_from_id(int id)
 }
 
 
-void ImageListStore::on_lib_notification(const fwk::Notification::Ptr &n)
+void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
 {
-    DBG_ASSERT(n->type() == niepce::NOTIFICATION_LIB, 
-               "wrong notification type");
-    if(n->type() == niepce::NOTIFICATION_LIB) {
-        eng::LibNotification ln = boost::any_cast<eng::LibNotification>(n->data());
-        switch(ln.type) {
-        case eng::Library::NOTIFY_FOLDER_CONTENT_QUERIED:
-        case eng::Library::NOTIFY_KEYWORD_CONTENT_QUERIED:
+    switch(ln.type) {
+    case eng::Library::NOTIFY_FOLDER_CONTENT_QUERIED:
+    case eng::Library::NOTIFY_KEYWORD_CONTENT_QUERIED:
+    {
+        eng::LibFile::ListPtr l 
+            = boost::any_cast<eng::LibFile::ListPtr>(ln.param);
+        DBG_OUT("received folder content file # %d", l->size());
+        Glib::RefPtr< Gtk::IconTheme > icon_theme(fwk::Application::app()->getIconTheme());
+        clear();
+        m_idmap.clear();
+        eng::LibFile::List::const_iterator iter = l->begin();
+        for( ; iter != l->end(); iter++ )
         {
-            eng::LibFile::ListPtr l 
-                = boost::any_cast<eng::LibFile::ListPtr>(ln.param);
-            DBG_OUT("received folder content file # %d", l->size());
-            Glib::RefPtr< Gtk::IconTheme > icon_theme(fwk::Application::app()->getIconTheme());
-            clear();
-            m_idmap.clear();
-            eng::LibFile::List::const_iterator iter = l->begin();
-            for( ; iter != l->end(); iter++ )
-            {
-                Gtk::TreeModel::iterator riter = append();
-                Gtk::TreeRow row = *riter;
-                // locate it in local cache...
-                row[m_columns.m_pix] = icon_theme->load_icon(
-                    Glib::ustring("image-loading"), 32,
-                    Gtk::ICON_LOOKUP_USE_BUILTIN);
-                row[m_columns.m_libfile] = *iter;
-                row[m_columns.m_strip_thumb] = fwk::gdkpixbuf_scale_to_fit(row[m_columns.m_pix], 100);
-                m_idmap[(*iter)->id()] = riter;
-            }
-            // at that point clear the cache because the icon view is populated.
-            getLibraryClient()->thumbnailCache().request(l);
-            break;
+            Gtk::TreeModel::iterator riter = append();
+            Gtk::TreeRow row = *riter;
+            // locate it in local cache...
+            row[m_columns.m_pix] = icon_theme->load_icon(
+                Glib::ustring("image-loading"), 32,
+                Gtk::ICON_LOOKUP_USE_BUILTIN);
+            row[m_columns.m_libfile] = *iter;
+            row[m_columns.m_strip_thumb] = fwk::gdkpixbuf_scale_to_fit(row[m_columns.m_pix], 100);
+            m_idmap[(*iter)->id()] = riter;
         }
-        case eng::Library::NOTIFY_METADATA_CHANGED:
-        {
-            std::tr1::array<int, 3> m = boost::any_cast<std::tr1::array<int, 3> >(ln.param);
-            DBG_OUT("metadata changed");
-            Gtk::TreeRow row;
-            std::map<int, Gtk::TreeIter>::const_iterator iter = m_idmap.find(m[0]);
-            if(iter != m_idmap.end()) {
-                row = *(iter->second);
-                //
-                eng::LibFile::Ptr file = row[m_columns.m_libfile];
-                file->setMetaData(m[1], m[2]);
-                row[m_columns.m_libfile] = file;
-            }
-            break;
-        }
-        case eng::Library::NOTIFY_XMP_NEEDS_UPDATE:
-        {
-            getLibraryClient()->processXmpUpdateQueue();
-            break;
-        }
-        default:
-            break;
+        // at that point clear the cache because the icon view is populated.
+        getLibraryClient()->thumbnailCache().request(l);
+        break;
+    }
+    case eng::Library::NOTIFY_METADATA_CHANGED:
+    {
+        std::tr1::array<int, 3> m = boost::any_cast<std::tr1::array<int, 3> >(ln.param);
+        DBG_OUT("metadata changed");
+        Gtk::TreeRow row;
+        std::map<int, Gtk::TreeIter>::const_iterator iter = m_idmap.find(m[0]);
+        if(iter != m_idmap.end()) {
+            row = *(iter->second);
+            //
+            eng::LibFile::Ptr file = row[m_columns.m_libfile];
+            file->setMetaData(m[1], m[2]);
+            row[m_columns.m_libfile] = file;
         }
+        break;
+    }
+    case eng::Library::NOTIFY_XMP_NEEDS_UPDATE:
+    {
+        getLibraryClient()->processXmpUpdateQueue();
+        break;
+    }
+    default:
+        break;
     }
 }
 
-void ImageListStore::on_tnail_notification(const fwk::Notification::Ptr &n)
+void ImageListStore::on_tnail_notification(const eng::ThumbnailNotification &tn)
 {
-    DBG_ASSERT(n->type() == niepce::NOTIFICATION_THUMBNAIL, 
-               "wrong notification type");
-    if(n->type() == niepce::NOTIFICATION_THUMBNAIL) {
-        eng::ThumbnailNotification tn 
-            = boost::any_cast<eng::ThumbnailNotification>(n->data());
-        std::map<int, Gtk::TreeIter>::iterator iter
-            = m_idmap.find( tn.id );
-        if(iter != m_idmap.end()) {
-            // found the icon view item
-            Gtk::TreeRow row = *(iter->second);
-            row[m_columns.m_pix] = tn.pixmap;
-            row[m_columns.m_strip_thumb] = fwk::gdkpixbuf_scale_to_fit(tn.pixmap, 100);
-        }
-        else {
-            DBG_OUT("row %d not found", tn.id);
-        }
+    std::map<int, Gtk::TreeIter>::iterator iter
+        = m_idmap.find( tn.id );
+    if(iter != m_idmap.end()) {
+        // found the icon view item
+        Gtk::TreeRow row = *(iter->second);
+        row[m_columns.m_pix] = tn.pixmap;
+        row[m_columns.m_strip_thumb] = fwk::gdkpixbuf_scale_to_fit(tn.pixmap, 100);
+    }
+    else {
+        DBG_OUT("row %d not found", tn.id);
     }
 }
 
diff --git a/src/niepce/ui/imageliststore.hpp b/src/niepce/ui/imageliststore.hpp
index 86ead88..a9a2393 100644
--- a/src/niepce/ui/imageliststore.hpp
+++ b/src/niepce/ui/imageliststore.hpp
@@ -26,9 +26,10 @@
 #include <gdkmm/pixbuf.h>
 #include <gtkmm/liststore.h>
 
-#include "fwk/toolkit/notification.hpp"
 #include "fwk/toolkit/controller.hpp"
 #include "engine/db/libfile.hpp"
+#include "engine/db/library.hpp"
+#include "engine/library/thumbnailnotification.hpp"
 #include "libraryclient/libraryclient.hpp"
 
 namespace ui {
@@ -68,8 +69,8 @@ public:
     void set_parent_controller(const fwk::Controller::WeakPtr & ctrl)
         { m_controller = ctrl; }
 
-    void on_lib_notification(const fwk::Notification::Ptr &n);
-    void on_tnail_notification(const fwk::Notification::Ptr &n);
+    void on_lib_notification(const eng::LibNotification &n);
+    void on_tnail_notification(const eng::ThumbnailNotification &n);
 protected:
     ImageListStore(const Columns& columns);
 private:
diff --git a/src/niepce/ui/librarymainviewcontroller.cpp b/src/niepce/ui/librarymainviewcontroller.cpp
index 71cc9e5..fc7c36f 100644
--- a/src/niepce/ui/librarymainviewcontroller.cpp
+++ b/src/niepce/ui/librarymainviewcontroller.cpp
@@ -38,34 +38,30 @@
 
 namespace ui {
 
-void LibraryMainViewController::on_lib_notification(const fwk::Notification::Ptr &n)
+void 
+LibraryMainViewController::on_lib_notification(const eng::LibNotification &ln)
 {
-    DBG_ASSERT(n->type() == niepce::NOTIFICATION_LIB, 
-               "wrong notification type");
-    if(n->type() == niepce::NOTIFICATION_LIB) {
-        eng::LibNotification ln = boost::any_cast<eng::LibNotification>(n->data());
-        switch(ln.type) {
-        case eng::Library::NOTIFY_METADATA_QUERIED:
-        {
-            eng::LibMetadata::Ptr lm
-                = boost::any_cast<eng::LibMetadata::Ptr>(ln.param);
-            DBG_OUT("received metadata");
-            m_metapanecontroller->display(lm->id(), lm.get());
-            break;
-        }
-        case eng::Library::NOTIFY_METADATA_CHANGED:
-        {
-            DBG_OUT("metadata changed");
-            std::tr1::array<int, 3> m = boost::any_cast<std::tr1::array<int, 3> >(ln.param);
-            if(m[0] == m_metapanecontroller->displayed_file()) {
-                // FIXME: actually just update the metadata
-                getLibraryClient()->requestMetadata(m[0]);
-            }
-            break;
-        }
-        default:
-            break;
+    switch(ln.type) {
+    case eng::Library::NOTIFY_METADATA_QUERIED:
+    {
+        eng::LibMetadata::Ptr lm
+            = boost::any_cast<eng::LibMetadata::Ptr>(ln.param);
+        DBG_OUT("received metadata");
+        m_metapanecontroller->display(lm->id(), lm.get());
+        break;
+    }
+    case eng::Library::NOTIFY_METADATA_CHANGED:
+    {
+        DBG_OUT("metadata changed");
+        std::tr1::array<int, 3> m = boost::any_cast<std::tr1::array<int, 3> >(ln.param);
+        if(m[0] == m_metapanecontroller->displayed_file()) {
+            // FIXME: actually just update the metadata
+            getLibraryClient()->requestMetadata(m[0]);
         }
+        break;
+    }
+    default:
+        break;
     }
 }
 
diff --git a/src/niepce/ui/librarymainviewcontroller.hpp b/src/niepce/ui/librarymainviewcontroller.hpp
index 0f621b6..ae9f4c0 100644
--- a/src/niepce/ui/librarymainviewcontroller.hpp
+++ b/src/niepce/ui/librarymainviewcontroller.hpp
@@ -30,6 +30,7 @@
 
 #include "librarymainview.hpp"
 #include "engine/db/libfile.hpp"
+#include "engine/db/library.hpp"
 #include "libraryclient/libraryclient.hpp"
 #include "fwk/toolkit/controller.hpp"
 #include "fwk/toolkit/notification.hpp"
@@ -62,7 +63,7 @@ public:
         {
         }
 
-		void on_lib_notification(const fwk::Notification::Ptr &);
+		void on_lib_notification(const eng::LibNotification &);
 
 		/** called when somehing is selected by the shared selection */
 		void on_selected(int id);
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 352443a..76c0662 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -30,6 +30,7 @@
 #include <gtkmm/filechooserdialog.h>
 
 #include "niepce/notifications.hpp"
+#include "niepce/notificationcenter.hpp"
 #include "niepce/stock.hpp"
 #include "fwk/base/debug.hpp"
 #include "fwk/base/moniker.hpp"
@@ -51,7 +52,6 @@
 using libraryclient::LibraryClient;
 using fwk::Application;
 using fwk::Configuration;
-using fwk::NotificationCenter;
 using fwk::UndoHistory;
 
 namespace ui {
@@ -82,38 +82,41 @@ NiepceWindow::buildWidget()
     init_actions();
     init_ui();
 
-    m_lib_notifcenter.reset(new NotificationCenter());
+    m_notifcenter.reset(new niepce::NotificationCenter());
 
     Glib::ustring name("camera");
     set_icon_from_theme(name);		
 
-    m_lib_notifcenter->subscribe(niepce::NOTIFICATION_LIB,
-                                 boost::bind(&NiepceWindow::on_lib_notification, 
-                                             this, _1));
-    m_lib_notifcenter->subscribe(niepce::NOTIFICATION_LIB,
-                                 boost::bind(&ImageListStore::on_lib_notification, 
-                                             m_selection_controller->list_store(), _1));
-    m_lib_notifcenter->subscribe(niepce::NOTIFICATION_THUMBNAIL,
-                                 boost::bind(&ImageListStore::on_tnail_notification, 
-                                             m_selection_controller->list_store(), _1));
+
+    m_notifcenter->signal_lib_notification.connect(
+        sigc::mem_fun(*this, &NiepceWindow::on_lib_notification));
+
+
+    m_notifcenter->signal_lib_notification
+        .connect(sigc::mem_fun(
+                     *get_pointer(m_selection_controller->list_store()),
+                     &ImageListStore::on_lib_notification));
+    m_notifcenter->signal_thumbnail_notification
+        .connect(sigc::mem_fun(
+                     *get_pointer(m_selection_controller->list_store()), 
+                     &ImageListStore::on_tnail_notification));
 
     // main view
     m_mainviewctrl = LibraryMainViewController::Ptr(
         new LibraryMainViewController(m_refActionGroup,
                                       m_selection_controller->list_store()));
-    m_lib_notifcenter->subscribe(niepce::NOTIFICATION_LIB,
-                                 boost::bind(&LibraryMainViewController::on_lib_notification, 
-                                             BIND_SHARED_PTR(LibraryMainViewController, m_mainviewctrl)
-                                             , _1));
+    m_notifcenter->signal_lib_notification
+        .connect(sigc::mem_fun(
+                     *m_mainviewctrl,
+                     &LibraryMainViewController::on_lib_notification));
+
     add(m_mainviewctrl);
     // workspace treeview
     m_workspacectrl = WorkspaceController::Ptr( new WorkspaceController() );
-    m_lib_notifcenter->subscribe(niepce::NOTIFICATION_LIB,
-                                 boost::bind(&WorkspaceController::on_lib_notification, 
-                                             m_workspacectrl, _1));
-    m_lib_notifcenter->subscribe(niepce::NOTIFICATION_COUNT,
-                                 boost::bind(&WorkspaceController::on_count_notification,
-                                             m_workspacectrl, _1));
+
+    m_notifcenter->signal_lib_notification
+        .connect(sigc::mem_fun(*m_workspacectrl,
+                               &WorkspaceController::on_lib_notification));
     add(m_workspacectrl);
 
     m_hbox.set_border_width(4);
@@ -503,60 +506,55 @@ void NiepceWindow::create_initial_labels()
 }
 
 
-void NiepceWindow::on_lib_notification(const fwk::Notification::Ptr &n)
+void NiepceWindow::on_lib_notification(const eng::LibNotification & ln)
 {
-    DBG_ASSERT(n->type() == niepce::NOTIFICATION_LIB, 
-               "wrong notification type");
-    if(n->type() == niepce::NOTIFICATION_LIB) {
-        eng::LibNotification ln = boost::any_cast<eng::LibNotification>(n->data());
-        switch(ln.type) {
-        case eng::Library::NOTIFY_NEW_LIBRARY_CREATED:
-            create_initial_labels();
-            break;
-        case eng::Library::NOTIFY_ADDED_LABELS:
-        {
-            eng::Label::ListPtr l 
-                = boost::any_cast<eng::Label::ListPtr>(ln.param);
-            for(eng::Label::List::const_iterator iter = l->begin();
-                iter != l->end(); ++iter) {
+    switch(ln.type) {
+    case eng::Library::NOTIFY_NEW_LIBRARY_CREATED:
+        create_initial_labels();
+        break;
+    case eng::Library::NOTIFY_ADDED_LABELS:
+    {
+        eng::Label::ListPtr l 
+            = boost::any_cast<eng::Label::ListPtr>(ln.param);
+        for(eng::Label::List::const_iterator iter = l->begin();
+            iter != l->end(); ++iter) {
                 
-                m_labels.push_back(*iter);
-            }
-            break;
+            m_labels.push_back(*iter);
         }
-        case eng::Library::NOTIFY_LABEL_CHANGED:
-        {
-            eng::Label::Ptr & l 
-                = boost::any_cast<eng::Label::Ptr &>(ln.param);
-            // TODO: will work as long as we have 5 labels or something.
-            for(eng::Label::List::iterator iter = m_labels.begin();
-                iter != m_labels.end(); ++iter) {
-
-                if((*iter)->id() == l->id()) {
-                    (*iter)->set_label(l->label());
-                    (*iter)->set_color(l->color());
-                }
+        break;
+    }
+    case eng::Library::NOTIFY_LABEL_CHANGED:
+    {
+        const eng::Label::Ptr & l 
+            = boost::any_cast<const eng::Label::Ptr &>(ln.param);
+        // TODO: will work as long as we have 5 labels or something.
+        for(eng::Label::List::iterator iter = m_labels.begin();
+            iter != m_labels.end(); ++iter) {
+
+            if((*iter)->id() == l->id()) {
+                (*iter)->set_label(l->label());
+                (*iter)->set_color(l->color());
             }
-            break;
         }
-        case eng::Library::NOTIFY_LABEL_DELETED:
-        {
-            int id = boost::any_cast<int>(ln.param);
-            // TODO: will work as long as we have 5 labels or something.
-            for(eng::Label::List::iterator iter = m_labels.begin();
-                iter != m_labels.end(); ++iter) {
-
-                if((*iter)->id() == id) {
-                    DBG_OUT("remove label %d", id);
-                    iter = m_labels.erase(iter);
-                    break;
-                }
+        break;
+    }
+    case eng::Library::NOTIFY_LABEL_DELETED:
+    {
+        int id = boost::any_cast<int>(ln.param);
+        // TODO: will work as long as we have 5 labels or something.
+        for(eng::Label::List::iterator iter = m_labels.begin();
+            iter != m_labels.end(); ++iter) {
+
+            if((*iter)->id() == id) {
+                DBG_OUT("remove label %d", id);
+                iter = m_labels.erase(iter);
+                break;
             }
-            break;
-        }
-        default:
-            break;
         }
+        break;
+    }
+    default:
+        break;
     }
 }
 
@@ -564,7 +562,7 @@ void NiepceWindow::on_lib_notification(const fwk::Notification::Ptr &n)
 void NiepceWindow::open_library(const std::string & libMoniker)
 {
     m_libClient = LibraryClient::Ptr(new LibraryClient(fwk::Moniker(libMoniker),
-                                                       m_lib_notifcenter));
+                                                       m_notifcenter));
     set_title(libMoniker);
     m_libClient->getAllLabels();
 }
diff --git a/src/niepce/ui/niepcewindow.hpp b/src/niepce/ui/niepcewindow.hpp
index 90ebaaa..3861ffe 100644
--- a/src/niepce/ui/niepcewindow.hpp
+++ b/src/niepce/ui/niepcewindow.hpp
@@ -29,7 +29,6 @@
 #include <gtkmm/paned.h>
 
 #include "fwk/toolkit/frame.hpp"
-#include "fwk/toolkit/notificationcenter.hpp"
 #include "fwk/toolkit/configdatabinder.hpp"
 #include "engine/db/label.hpp"
 #include "libraryclient/libraryclient.hpp"
@@ -37,6 +36,7 @@
 #include "ui/workspacecontroller.hpp"
 #include "ui/selectioncontroller.hpp"
 #include "ui/filmstripcontroller.hpp"
+#include "notificationcenter.hpp"
 
 namespace fwk {
 	class NotificatioCenter;
@@ -56,9 +56,9 @@ public:
 
     libraryclient::LibraryClient::Ptr getLibraryClient()
         { return m_libClient; }
+
 protected:
     virtual Gtk::Widget * buildWidget();
-
 private:
     void undo_state();
     void redo_state();
@@ -75,7 +75,7 @@ private:
     void on_preferences();
 
     void create_initial_labels();
-    void on_lib_notification(const fwk::Notification::Ptr &n);
+    void on_lib_notification(const eng::LibNotification & n);
 
     void init_ui();
     void init_actions();
@@ -84,7 +84,7 @@ private:
     eng::Label::List &   get_labels()
         { return m_labels; }
 		
-    fwk::NotificationCenter::Ptr  m_lib_notifcenter;
+    niepce::NotificationCenter::Ptr m_notifcenter;
 
     Gtk::VBox                      m_vbox;
     Gtk::HPaned                    m_hbox;
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index d6c477a..4466956 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -68,64 +68,59 @@ namespace ui {
 	}
 
 
-	void WorkspaceController::on_lib_notification(const fwk::Notification::Ptr &n)
+	void WorkspaceController::on_lib_notification(const eng::LibNotification &ln)
 	{
 		DBG_OUT("notification for workspace");
-		if(n->type() == niepce::NOTIFICATION_LIB) {
-			eng::LibNotification ln = boost::any_cast<eng::LibNotification>(n->data());
-			switch(ln.type) {
-			case eng::Library::NOTIFY_ADDED_FOLDERS:
-			{
-				eng::LibFolder::ListPtr l 
-					= boost::any_cast<eng::LibFolder::ListPtr>(ln.param);
-				DBG_OUT("received added folders # %d", l->size());
-				for_each(l->begin(), l->end(), 
-						 boost::bind(&WorkspaceController::add_folder_item, 
-									 this, _1));
-				break;
-			}
-			case eng::Library::NOTIFY_ADDED_KEYWORD:
-			{
-				eng::Keyword::Ptr k
-					= boost::any_cast<eng::Keyword::Ptr>(ln.param);
-				DBG_ASSERT(k, "keyword must not be NULL");
-				add_keyword_item(k);
-				break;
-			}
-			case eng::Library::NOTIFY_ADDED_KEYWORDS:
-			{
-				eng::Keyword::ListPtr l
-					= boost::any_cast<eng::Keyword::ListPtr>(ln.param);
-				DBG_ASSERT(l, "keyword list must not be NULL");
-				for_each(l->begin(), l->end(), 
-						 boost::bind(&WorkspaceController::add_keyword_item, 
-									 this, _1));
-				break;
-			}
-			case eng::Library::NOTIFY_FOLDER_COUNTED:
-			{
-				std::pair<int,int> count(boost::any_cast<std::pair<int,int> >(ln.param));
-				DBG_OUT("count for folder %d is %d", count.first, count.second);
-				std::map<int, Gtk::TreeIter>::iterator iter
-					= m_folderidmap.find( count.first );
-				if(iter != m_folderidmap.end()) {
-					Gtk::TreeRow row = *(iter->second);
-					row[m_librarycolumns.m_count] = boost::lexical_cast<Glib::ustring>(count.second);
-				}
-
-				break;
-			}
-			default:
-				break;
-			}
-		}
+    switch(ln.type) {
+    case eng::Library::NOTIFY_ADDED_FOLDERS:
+    {
+      eng::LibFolder::ListPtr l 
+        = boost::any_cast<eng::LibFolder::ListPtr>(ln.param);
+      DBG_OUT("received added folders # %d", l->size());
+      for_each(l->begin(), l->end(), 
+               boost::bind(&WorkspaceController::add_folder_item, 
+                           this, _1));
+      break;
+    }
+    case eng::Library::NOTIFY_ADDED_KEYWORD:
+    {
+      eng::Keyword::Ptr k
+        = boost::any_cast<eng::Keyword::Ptr>(ln.param);
+      DBG_ASSERT(k, "keyword must not be NULL");
+      add_keyword_item(k);
+      break;
+    }
+    case eng::Library::NOTIFY_ADDED_KEYWORDS:
+    {
+      eng::Keyword::ListPtr l
+        = boost::any_cast<eng::Keyword::ListPtr>(ln.param);
+      DBG_ASSERT(l, "keyword list must not be NULL");
+      for_each(l->begin(), l->end(), 
+               boost::bind(&WorkspaceController::add_keyword_item, 
+                           this, _1));
+      break;
+    }
+    case eng::Library::NOTIFY_FOLDER_COUNTED:
+    {
+      std::pair<int,int> count(boost::any_cast<std::pair<int,int> >(ln.param));
+      DBG_OUT("count for folder %d is %d", count.first, count.second);
+      std::map<int, Gtk::TreeIter>::iterator iter
+        = m_folderidmap.find( count.first );
+      if(iter != m_folderidmap.end()) {
+        Gtk::TreeRow row = *(iter->second);
+        row[m_librarycolumns.m_count] = boost::lexical_cast<Glib::ustring>(count.second);
+      }
+
+      break;
+    }
+    default:
+      break;
+    }
 	}
 
-	void WorkspaceController::on_count_notification(const fwk::Notification::Ptr &n)
+	void WorkspaceController::on_count_notification(int)
 	{
-		if(n->type() == niepce::NOTIFICATION_COUNT) {
-			DBG_OUT("received NOTIFICATION_COUNT");
-		}
+    DBG_OUT("received NOTIFICATION_COUNT");
 	}
 
 
diff --git a/src/niepce/ui/workspacecontroller.hpp b/src/niepce/ui/workspacecontroller.hpp
index 7c920c5..90f486c 100644
--- a/src/niepce/ui/workspacecontroller.hpp
+++ b/src/niepce/ui/workspacecontroller.hpp
@@ -78,8 +78,8 @@ namespace ui {
 
 		virtual void on_ready();
 
-		void on_lib_notification(const fwk::Notification::Ptr &);
-		void on_count_notification(const fwk::Notification::Ptr &);
+		void on_lib_notification(const eng::LibNotification &);
+		void on_count_notification(int);
 		void on_libtree_selection();
 
 	protected:



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