[niepce] Change the namespace for the darkroom module to dr Define a IModuleShell interface to callback from



commit ca8152d5148e76388d3c260e4c3b52774b8f059c
Author: Hub Figuiere <hub figuiere net>
Date:   Thu Nov 10 19:40:20 2011 -0800

    Change the namespace for the darkroom module to dr
    Define a IModuleShell interface to callback from the module
    Allow the DarkroomModule to know about the selection change.

 src/niepce/modules/darkroom/darkroommodule.cpp    |   42 ++++++++++++++--
 src/niepce/modules/darkroom/darkroommodule.hpp    |   37 ++++++++------
 src/niepce/modules/darkroom/dritemwidget.cpp      |    2 +-
 src/niepce/modules/darkroom/dritemwidget.hpp      |    2 +-
 src/niepce/modules/darkroom/imagecanvas.cpp       |    4 +-
 src/niepce/modules/darkroom/imagecanvas.hpp       |    2 +-
 src/niepce/modules/darkroom/toolboxcontroller.cpp |    2 +-
 src/niepce/modules/darkroom/toolboxcontroller.hpp |    2 +-
 src/niepce/ui/Makefile.am                         |    2 +-
 src/niepce/ui/gridviewmodule.cpp                  |   12 +++--
 src/niepce/ui/gridviewmodule.hpp                  |    6 ++-
 src/niepce/ui/ilibrarymodule.hpp                  |    5 ++
 src/niepce/ui/imoduleshell.hpp                    |   46 +++++++++++++++++
 src/niepce/ui/moduleshell.cpp                     |   24 ++++++---
 src/niepce/ui/moduleshell.hpp                     |   21 +++++---
 src/niepce/ui/moduleshellwidget.cpp               |   55 +++++++++++----------
 src/niepce/ui/moduleshellwidget.hpp               |   45 +++++++++++------
 src/niepce/ui/selectioncontroller.cpp             |   10 +++-
 src/niepce/ui/selectioncontroller.hpp             |    7 ++-
 19 files changed, 226 insertions(+), 100 deletions(-)
---
diff --git a/src/niepce/modules/darkroom/darkroommodule.cpp b/src/niepce/modules/darkroom/darkroommodule.cpp
index 526da9d..a85ff27 100644
--- a/src/niepce/modules/darkroom/darkroommodule.cpp
+++ b/src/niepce/modules/darkroom/darkroommodule.cpp
@@ -28,15 +28,29 @@
 #include "ncr/init.hpp"
 #include "darkroommodule.hpp"
 
-namespace darkroom {
+namespace dr {
+
+DarkroomModule::DarkroomModule(const ui::IModuleShell & shell, 
+                               const Glib::RefPtr<Gtk::ActionGroup> & action_group)
+    : m_shell(shell)
+    , m_actionGroup(action_group)
+    , m_image(new ncr::Image)
+{
+    m_shell.get_selection_controller()->signal_selected.connect(
+        sigc::mem_fun(*this, &DarkroomModule::on_selected));
+}
 
 
 void DarkroomModule::set_image(const eng::LibFile::Ptr & file)
 {
-    m_image->reload(file->path(), 
-                    file->fileType() == eng::LibFile::FILE_TYPE_RAW,
-                    file->orientation());
-
+    if(file) {
+        m_image->reload(file->path(), 
+                        file->fileType() == eng::LibFile::FILE_TYPE_RAW,
+                        file->orientation());
+    }
+    else {
+        // clear out
+    }
 }
 
 void DarkroomModule::dispatch_action(const std::string & /*action_name*/)
@@ -44,6 +58,19 @@ void DarkroomModule::dispatch_action(const std::string & /*action_name*/)
 }
 
 
+void DarkroomModule::set_active(bool active)
+{
+    m_active = active;
+    if(active) {
+        // if activated, force the refresh of the image.
+        ui::SelectionController::Ptr sel = m_shell.get_selection_controller();
+        eng::library_id_t id = sel->get_selection();
+        eng::LibFile::Ptr file = sel->get_file(id);
+        set_image(file);
+    }
+}
+
+
 Gtk::Widget * DarkroomModule::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager)
 {
     if(m_widget) {
@@ -96,6 +123,11 @@ Gtk::Widget * DarkroomModule::buildWidget(const Glib::RefPtr<Gtk::UIManager> & m
     return m_widget;
 }
 
+void DarkroomModule::on_selected(eng::library_id_t id)
+{
+    eng::LibFile::Ptr file = m_shell.get_selection_controller()->get_file(id);
+    set_image(file);
+}
 
 }
 
diff --git a/src/niepce/modules/darkroom/darkroommodule.hpp b/src/niepce/modules/darkroom/darkroommodule.hpp
index 672335c..f500cf9 100644
--- a/src/niepce/modules/darkroom/darkroommodule.hpp
+++ b/src/niepce/modules/darkroom/darkroommodule.hpp
@@ -32,6 +32,7 @@
 #include "libraryclient/libraryclient.hpp"
 #include "ncr/image.hpp"
 #include "niepce/ui/ilibrarymodule.hpp"
+#include "niepce/ui/imoduleshell.hpp"
 #include "modules/darkroom/imagecanvas.hpp"
 #include "modules/darkroom/toolboxcontroller.hpp"
 	
@@ -39,30 +40,30 @@ namespace fwk {
 class Dock;
 }
 
-namespace darkroom {
+namespace dr {
 
 class DarkroomModule
     : public ui::ILibraryModule
 {
 public:
-	typedef std::tr1::shared_ptr<DarkroomModule> Ptr;
-
-	DarkroomModule(const Glib::RefPtr<Gtk::ActionGroup> & action_group,
-                   const libraryclient::LibraryClient::Ptr & libclient)
-        : m_actionGroup(action_group),
-          m_image(new ncr::Image),
-          m_libClient(libclient)
-		{
-		}
-
-	void set_image(const eng::LibFile::Ptr & file);
-
-  virtual void dispatch_action(const std::string & action_name);
+    typedef std::tr1::shared_ptr<DarkroomModule> Ptr;
+    
+    DarkroomModule(const ui::IModuleShell & shell, 
+                   const Glib::RefPtr<Gtk::ActionGroup> & action_group);
+    
+    void set_image(const eng::LibFile::Ptr & file);
+    
+    virtual void dispatch_action(const std::string & action_name);
 
+    virtual void set_active(bool active);
+    
 protected:
-	virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> &);
-
+    virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> &);
+    
 private:
+    void on_selected(eng::library_id_t id);
+
+    const ui::IModuleShell &     m_shell;
     // darkroom split view
     Gtk::HPaned                  m_dr_splitview;
     Gtk::VBox                    m_vbox;
@@ -71,8 +72,10 @@ private:
     ToolboxController::Ptr       m_toolbox_ctrl;
     Glib::RefPtr<Gtk::ActionGroup> m_actionGroup;
     ncr::Image::Ptr              m_image;
-    libraryclient::LibraryClient::Ptr m_libClient;
     fwk::Dock                   *m_dock;
+
+    // state
+    bool                         m_active;
 };
 
 
diff --git a/src/niepce/modules/darkroom/dritemwidget.cpp b/src/niepce/modules/darkroom/dritemwidget.cpp
index ffe231b..13daae4 100644
--- a/src/niepce/modules/darkroom/dritemwidget.cpp
+++ b/src/niepce/modules/darkroom/dritemwidget.cpp
@@ -21,7 +21,7 @@
 
 #include "dritemwidget.hpp"
 
-namespace darkroom {
+namespace dr {
 
 DrItemWidget::DrItemWidget(const Glib::ustring & title)
     : fwk::ToolboxItemWidget(title)
diff --git a/src/niepce/modules/darkroom/dritemwidget.hpp b/src/niepce/modules/darkroom/dritemwidget.hpp
index 90e0b68..c1ee9b8 100644
--- a/src/niepce/modules/darkroom/dritemwidget.hpp
+++ b/src/niepce/modules/darkroom/dritemwidget.hpp
@@ -26,7 +26,7 @@
 
 #include "fwk/toolkit/widgets/toolboxitemwidget.hpp"
 
-namespace darkroom {
+namespace dr {
 
 /** Generic Darkroom item for the toolbox. */
 class DrItemWidget
diff --git a/src/niepce/modules/darkroom/imagecanvas.cpp b/src/niepce/modules/darkroom/imagecanvas.cpp
index b7fe986..e0d644a 100644
--- a/src/niepce/modules/darkroom/imagecanvas.cpp
+++ b/src/niepce/modules/darkroom/imagecanvas.cpp
@@ -27,9 +27,7 @@
 
 #include <gdkmm/general.h>
 
-namespace darkroom {
-
-
+namespace dr {
 
 #define IMAGE_INSET 6
 #define SHADOW_OFFSET 3
diff --git a/src/niepce/modules/darkroom/imagecanvas.hpp b/src/niepce/modules/darkroom/imagecanvas.hpp
index edc9dc2..107dba2 100644
--- a/src/niepce/modules/darkroom/imagecanvas.hpp
+++ b/src/niepce/modules/darkroom/imagecanvas.hpp
@@ -26,7 +26,7 @@
 
 #include "ncr/image.hpp"
 
-namespace darkroom {
+namespace dr {
 
 class ImageCanvas
     : public Gtk::DrawingArea
diff --git a/src/niepce/modules/darkroom/toolboxcontroller.cpp b/src/niepce/modules/darkroom/toolboxcontroller.cpp
index 404adfc..70958ac 100644
--- a/src/niepce/modules/darkroom/toolboxcontroller.cpp
+++ b/src/niepce/modules/darkroom/toolboxcontroller.cpp
@@ -33,7 +33,7 @@
 #error DATADIR is not defined
 #endif
 
-namespace darkroom {
+namespace dr {
 
 ToolboxController::ToolboxController()
     : Dockable("tools", _("Develop"), Gtk::Stock::APPLY.id)
diff --git a/src/niepce/modules/darkroom/toolboxcontroller.hpp b/src/niepce/modules/darkroom/toolboxcontroller.hpp
index 3e77885..be8c89f 100644
--- a/src/niepce/modules/darkroom/toolboxcontroller.hpp
+++ b/src/niepce/modules/darkroom/toolboxcontroller.hpp
@@ -23,7 +23,7 @@
 
 #include "fwk/toolkit/dockable.hpp"
 
-namespace darkroom {
+namespace dr {
 
 class ToolboxController
     : public fwk::Dockable
diff --git a/src/niepce/ui/Makefile.am b/src/niepce/ui/Makefile.am
index 93547ba..0c8b50a 100644
--- a/src/niepce/ui/Makefile.am
+++ b/src/niepce/ui/Makefile.am
@@ -23,7 +23,7 @@ EXTRA_DIST = $(gladefiles)
 
 noinst_LIBRARIES = libniepceui.a
 
-PUBLICHEADERS = ilibrarymodule.hpp
+PUBLICHEADERS = ilibrarymodule.hpp imoduleshell.hpp
 
 libniepceui_a_CPPFLAGS = 
 libniepceui_a_SOURCES = \
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index 1b88952..d473a77 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -34,13 +34,13 @@
 namespace ui {
 
 
-GridViewModule::GridViewModule(ModuleShell* shell,
+GridViewModule::GridViewModule(const IModuleShell & shell,
                                const Glib::RefPtr<ImageListStore> & store)
   : m_shell(shell)
   , m_model(store)
   , m_uidataprovider(NULL)
 {
-    m_uidataprovider = m_shell->getLibraryClient()->getDataProvider();
+    m_uidataprovider = m_shell.getLibraryClient()->getDataProvider();
     DBG_ASSERT(m_uidataprovider, "provider is NULL");
 }
 
@@ -62,7 +62,7 @@ GridViewModule::on_lib_notification(const eng::LibNotification &ln)
 		eng::metadata_desc_t m = boost::any_cast<eng::metadata_desc_t>(ln.param);
         if(m.id == m_metapanecontroller->displayed_file()) {
             // FIXME: actually just update the metadata
-          m_shell->getLibraryClient()->requestMetadata(m.id);
+          m_shell.getLibraryClient()->requestMetadata(m.id);
         }
         break;
     }
@@ -127,6 +127,10 @@ void GridViewModule::dispatch_action(const std::string & /*action_name*/)
 {
 }
 
+void GridViewModule::set_active(bool /*active*/)
+{
+}
+
 
 Gtk::IconView * GridViewModule::image_list()
 { 
@@ -169,7 +173,7 @@ void GridViewModule::select_image(eng::library_id_t id)
 
 void GridViewModule::on_rating_changed(int /*id*/, int rating)
 {
-    m_shell->get_selection_controller()->set_rating(rating);
+    m_shell.get_selection_controller()->set_rating(rating);
 }
 
 }
diff --git a/src/niepce/ui/gridviewmodule.hpp b/src/niepce/ui/gridviewmodule.hpp
index 8cc3fc5..665c57b 100644
--- a/src/niepce/ui/gridviewmodule.hpp
+++ b/src/niepce/ui/gridviewmodule.hpp
@@ -30,6 +30,7 @@
 
 #include "engine/db/library.hpp"
 #include "niepce/ui/ilibrarymodule.hpp"
+#include "niepce/ui/imoduleshell.hpp"
 #include "niepce/ui/metadatapanecontroller.hpp"
 #include "niepce/ui/selectioncontroller.hpp"
 
@@ -52,7 +53,7 @@ class GridViewModule
 public:
   typedef std::tr1::shared_ptr<GridViewModule> Ptr;
 
-  GridViewModule(ModuleShell *shell,
+  GridViewModule(const IModuleShell & shell,
                  const Glib::RefPtr<ImageListStore> & store);
 
 
@@ -61,6 +62,7 @@ public:
 
   /* ILibraryModule */
   virtual void dispatch_action(const std::string & action_name);
+  virtual void set_active(bool active);
 
   /* IImageSelectable */
   virtual Gtk::IconView * image_list();
@@ -74,7 +76,7 @@ protected:
 private:
   void on_rating_changed(int id, int rating);
 
-  ModuleShell                 *m_shell;
+  const IModuleShell &               m_shell;
   Glib::RefPtr<ImageListStore> m_model;
   libraryclient::UIDataProvider *m_uidataprovider;
 
diff --git a/src/niepce/ui/ilibrarymodule.hpp b/src/niepce/ui/ilibrarymodule.hpp
index 8ff2ab5..5fc64fe 100644
--- a/src/niepce/ui/ilibrarymodule.hpp
+++ b/src/niepce/ui/ilibrarymodule.hpp
@@ -37,6 +37,11 @@ public:
 
   /** dispatch action by name to the controller */
   virtual void dispatch_action(const std::string & action_name) = 0;
+
+  /** called when the module is set activate or unactive 
+      @param active true if brought to the front, false if defocused.
+   */
+  virtual void set_active(bool active) = 0;
 };
 
 
diff --git a/src/niepce/ui/imoduleshell.hpp b/src/niepce/ui/imoduleshell.hpp
new file mode 100644
index 0000000..1abe4e9
--- /dev/null
+++ b/src/niepce/ui/imoduleshell.hpp
@@ -0,0 +1,46 @@
+/*
+ * niepce - ui/imoduleshell.hpp
+ *
+ * Copyright (C) 2011 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 _UI_IMODULESHELL_HPP__
+#define _UI_IMODULESHELL_HPP__
+
+#include "niepce/ui/selectioncontroller.hpp"
+
+namespace ui {
+
+class IModuleShell
+{
+public:
+    virtual const ui::SelectionController::Ptr & get_selection_controller() const = 0;
+    virtual libraryclient::LibraryClient::Ptr getLibraryClient() const = 0;
+};
+
+}
+
+#endif
+/*
+  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/niepce/ui/moduleshell.cpp b/src/niepce/ui/moduleshell.cpp
index 27cc7bd..edbdf81 100644
--- a/src/niepce/ui/moduleshell.cpp
+++ b/src/niepce/ui/moduleshell.cpp
@@ -191,8 +191,7 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
     DBG_ASSERT(m_ui_merge_id, "merge failed");
 
     m_gridview = GridViewModule::Ptr(
-        new GridViewModule(this,
-                           m_selection_controller->get_list_store()));
+        new GridViewModule(*this, m_selection_controller->get_list_store()));
     add_library_module(m_gridview, _("Library"));
 
     m_selection_controller->add_selectable(m_gridview.get());
@@ -201,11 +200,11 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
     m_selection_controller->signal_activated
         .connect(sigc::mem_fun(*this, &ModuleShell::on_image_activated));
 
-
-    m_darkroom = darkroom::DarkroomModule::Ptr(
-        new darkroom::DarkroomModule(m_actionGroup, m_libraryclient));
+    m_darkroom = dr::DarkroomModule::Ptr(new dr::DarkroomModule(*this, m_actionGroup));
     add_library_module(m_darkroom, _("Darkroom"));
 
+    m_shell.signal_activated.connect(sigc::mem_fun(*this, &ModuleShell::on_module_activated));
+
     // TODO PrintModuleController
     // add_library_module(, _("Print"));
     return m_widget;
@@ -219,6 +218,7 @@ void ModuleShell::add_library_module(const ILibraryModule::Ptr & module,
     if(w) {
         add(module);
         m_shell.append_page(*w, label);
+        m_modules.push_back(module);
     }
 }
 
@@ -227,9 +227,9 @@ void ModuleShell::on_ready()
 }
 
 
-void ModuleShell::on_selected(int id)
+void ModuleShell::on_selected(eng::library_id_t id)
 {
-    DBG_OUT("selected callback %d", id);
+    DBG_OUT("selected callback %Ld", id);
     if(id > 0) {
         m_libraryclient->requestMetadata(id);
     }		
@@ -238,9 +238,9 @@ void ModuleShell::on_selected(int id)
     }
 }
 
-void ModuleShell::on_image_activated(int id)
+void ModuleShell::on_image_activated(eng::library_id_t id)
 {
-    DBG_OUT("on image activated %d", id);
+    DBG_OUT("on image activated %Ld", id);
     Glib::RefPtr<ImageListStore> store = m_selection_controller->get_list_store();
     Gtk::TreeIter iter = store->get_iter_from_id(id);
     if(iter) {
@@ -250,6 +250,12 @@ void ModuleShell::on_image_activated(int id)
     }
 }
 
+void ModuleShell::on_module_activated(int idx)
+{
+    DBG_ASSERT(idx < m_modules.size(), "wrong module index");
+    m_modules[idx]->set_active(true);
+}
+
 
 }
 
diff --git a/src/niepce/ui/moduleshell.hpp b/src/niepce/ui/moduleshell.hpp
index f1ccae0..de1162a 100644
--- a/src/niepce/ui/moduleshell.hpp
+++ b/src/niepce/ui/moduleshell.hpp
@@ -21,7 +21,7 @@
 #ifndef __UI_MODULESHELL_HPP__
 #define __UI_MODULESHELL_HPP__
 
-
+#include <vector>
 
 #include "moduleshellwidget.hpp"
 #include "libraryclient/libraryclient.hpp"
@@ -30,15 +30,17 @@
 #include "niepce/ui/gridviewmodule.hpp"
 #include "modules/darkroom/darkroommodule.hpp"
 #include "imageliststore.hpp"
+#include "imoduleshell.hpp"
 
 namespace Gtk {
-	class Widget;
+class Widget;
 }
 
 namespace ui {
 
 class ModuleShell
     : public fwk::UiController
+    , public IModuleShell
 {
 public:
     typedef std::tr1::shared_ptr<ModuleShell> Ptr;
@@ -59,24 +61,25 @@ public:
         { 
             return m_selection_controller->get_list_store(); 
         }
-    const SelectionController::Ptr & get_selection_controller() const
+    virtual const SelectionController::Ptr & get_selection_controller() const
         {
             return m_selection_controller;
         }
-    libraryclient::LibraryClient::Ptr getLibraryClient() const
+    virtual libraryclient::LibraryClient::Ptr getLibraryClient() const
         {
             return m_libraryclient;
         }
 
-    /** called when somehing is selected by the shared selection */
-    void on_selected(int id);
-    void on_image_activated(int id);
+    /** called when something is selected by the shared selection */
+    void on_selected(eng::library_id_t id);
+    void on_image_activated(eng::library_id_t id);
     
     virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager);
 protected:
     virtual void add_library_module(const ILibraryModule::Ptr & module,
                                     const std::string & label);
     virtual void on_ready();
+    void on_module_activated(int idx);
 private:
     libraryclient::LibraryClient::Ptr m_libraryclient;
     Glib::RefPtr<Gtk::ActionGroup> m_actionGroup;
@@ -86,8 +89,10 @@ private:
     Glib::RefPtr<Gtk::UIManager>  m_ui_manager;
     
     ui::SelectionController::Ptr  m_selection_controller;
+    std::vector<ILibraryModule::Ptr> m_modules;
+    // these should be dynamic
     GridViewModule::Ptr           m_gridview;
-    darkroom::DarkroomModule::Ptr m_darkroom;
+    dr::DarkroomModule::Ptr       m_darkroom;
 };
 
 }
diff --git a/src/niepce/ui/moduleshellwidget.cpp b/src/niepce/ui/moduleshellwidget.cpp
index 4f46a97..dffa9af 100644
--- a/src/niepce/ui/moduleshellwidget.cpp
+++ b/src/niepce/ui/moduleshellwidget.cpp
@@ -25,44 +25,44 @@
 namespace ui {
 
 ModuleShellWidget::ModuleShellWidget()
-		: Gtk::VBox(),
-		  m_currentpage(-1)
+    : Gtk::VBox(),
+      m_currentpage(-1)
 {
-		set_spacing(4);
-		m_mainbar.set_layout(Gtk::BUTTONBOX_START);
-		m_mainbar.set_spacing(4);
-		m_notebook.set_show_tabs(false);
-		pack_start(m_mainbar, Gtk::PACK_SHRINK);
-		pack_start(m_notebook);
+    set_spacing(4);
+    m_mainbar.set_layout(Gtk::BUTTONBOX_START);
+    m_mainbar.set_spacing(4);
+    m_notebook.set_show_tabs(false);
+    pack_start(m_mainbar, Gtk::PACK_SHRINK);
+    pack_start(m_notebook);
 }
 
 int
 ModuleShellWidget::append_page(Gtk::Widget & w, const Glib::ustring & label)
 {
-		int idx;
-		
-		Gtk::ToggleButton* button = Gtk::manage(new Gtk::ToggleButton(label));
-		m_mainbar.pack_start(*button);
-		idx = m_notebook.append_page(w, label);
-		sigc::connection conn = button->signal_toggled().connect(
+    int idx;
+    
+    Gtk::ToggleButton* button = Gtk::manage(new Gtk::ToggleButton(label));
+    m_mainbar.pack_start(*button);
+    idx = m_notebook.append_page(w, label);
+    sigc::connection conn = button->signal_toggled().connect(
         sigc::bind(sigc::mem_fun(this, &ModuleShellWidget::set_current_page),
                    idx, button));
-		if(m_currentpage == -1) {
+    if(m_currentpage == -1) {
         set_current_page(idx, button);
-		}
-		if((int)m_buttons.size() < idx + 1) {
+    }
+    if((int)m_buttons.size() < idx + 1) {
         m_buttons.resize(idx + 1);
-		}
-		m_buttons[idx] = std::make_pair(button, conn);
-		return idx;
+    }
+    m_buttons[idx] = std::make_pair(button, conn);
+    return idx;
 }
 	
 void ModuleShellWidget::activate_page(int idx)
 {
-		if(m_currentpage != idx) {
+    if(m_currentpage != idx) {
         Gtk::ToggleButton * btn = m_buttons[idx].first;
         set_current_page(idx, btn);
-		}
+    }
 }
 
 
@@ -76,14 +76,15 @@ void ModuleShellWidget::set_current_page(int idx, Gtk::ToggleButton * btn)
         m_buttons[m_currentpage].second.unblock();
         return;
     }
-		m_notebook.set_current_page(idx);
-		if(m_currentpage >= 0) {
+    m_notebook.set_current_page(idx);
+    if(m_currentpage >= 0) {
         m_buttons[m_currentpage].second.block();
         m_buttons[m_currentpage].first->set_active(false);
         m_buttons[m_currentpage].second.unblock();
-		}
-		btn->set_active(true);
-		m_currentpage = idx;
+    }
+    btn->set_active(true);
+    m_currentpage = idx;
+    signal_activated(idx);
 }
 
 }
diff --git a/src/niepce/ui/moduleshellwidget.hpp b/src/niepce/ui/moduleshellwidget.hpp
index 6dd7428..492f255 100644
--- a/src/niepce/ui/moduleshellwidget.hpp
+++ b/src/niepce/ui/moduleshellwidget.hpp
@@ -34,25 +34,36 @@ namespace Gtk {
 namespace ui {
 
 
-	class ModuleShellWidget
-		: public Gtk::VBox
-	{
-	public:
-		ModuleShellWidget();
-
-		int append_page(Gtk::Widget & w, const Glib::ustring & label);
-		void activate_page(int);
-	protected:
-		
-		void set_current_page(int, Gtk::ToggleButton *);
-	private:
-		Gtk::HButtonBox         m_mainbar;
-		Gtk::Notebook           m_notebook;
-		int                     m_currentpage;
-		std::vector<std::pair<Gtk::ToggleButton*, sigc::connection> > m_buttons;
-	};
+class ModuleShellWidget
+    : public Gtk::VBox
+{
+public:
+    ModuleShellWidget();
+    
+    int append_page(Gtk::Widget & w, const Glib::ustring & label);
+    void activate_page(int);
+
+    sigc::signal<void, int> signal_activated;
+protected:
+    
+    void set_current_page(int, Gtk::ToggleButton *);
+private:
+    Gtk::HButtonBox         m_mainbar;
+    Gtk::Notebook           m_notebook;
+    int                     m_currentpage;
+    std::vector<std::pair<Gtk::ToggleButton*, sigc::connection> > m_buttons;
+};
 
 }
 
 
 #endif
+/*
+  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/niepce/ui/selectioncontroller.cpp b/src/niepce/ui/selectioncontroller.cpp
index 197707a..38fd780 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -103,12 +103,20 @@ libraryclient::LibraryClient::Ptr SelectionController::getLibraryClient()
     return	shell->getLibraryClient();
 }
 
-inline eng::library_id_t SelectionController::get_selection()
+eng::library_id_t SelectionController::get_selection() const
 {
     DBG_ASSERT(!m_selectables.empty(), "selectables list can't be empty");
     return m_selectables[0]->get_selected();
 }
 
+eng::LibFile::Ptr SelectionController::get_file(eng::library_id_t id) const
+{
+    Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(id);
+    if(iter) {
+        return (*iter)[m_imageliststore->columns().m_libfile];
+    }
+    return eng::LibFile::Ptr();
+}
 
 void SelectionController::_selection_move(bool backwards)
 {
diff --git a/src/niepce/ui/selectioncontroller.hpp b/src/niepce/ui/selectioncontroller.hpp
index f453f32..bbaeb25 100644
--- a/src/niepce/ui/selectioncontroller.hpp
+++ b/src/niepce/ui/selectioncontroller.hpp
@@ -89,10 +89,15 @@ public:
     void set_label(int label);
     /** set flag */
     void set_flag(int flag);
+
+    /** get the current selection 
+     *  todo: change it to support multiple
+     */
+    eng::library_id_t get_selection() const;
+    eng::LibFile::Ptr get_file(eng::library_id_t id) const;
 protected:
     virtual void _added();
 private:
-	eng::library_id_t get_selection();
     libraryclient::LibraryClient::Ptr getLibraryClient();
 
     bool _set_metadata(const std::string & undo_label, 



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