[niepce] Created UIDataProvider for all these data that needs display Mockup of representing the label in the



commit 532707e77efd5b72c26983a20ad5c7288b7218c8
Author: Hub Figuiere <hub figuiere net>
Date:   Sat Oct 29 15:35:35 2011 -0700

    Created UIDataProvider for all these data that needs display
    Mockup of representing the label in the thumbnail view
    Defer the creation of the UI for after the LibraryClient is created.

 src/engine/db/label.hpp                        |    5 +-
 src/fwk/toolkit/uicontroller.hpp               |    4 +-
 src/libraryclient/Makefile.am                  |    4 +-
 src/libraryclient/libraryclient.cpp            |    7 +-
 src/libraryclient/libraryclient.hpp            |   20 +++--
 src/libraryclient/uidataprovider.cpp           |   91 ++++++++++++++++++++
 src/libraryclient/uidataprovider.hpp           |   60 +++++++++++++
 src/niepce/modules/darkroom/darkroommodule.hpp |    6 +-
 src/niepce/ui/dialogs/editlabels.cpp           |    5 +-
 src/niepce/ui/dialogs/editlabels.hpp           |    4 +-
 src/niepce/ui/gridviewmodule.cpp               |    7 +-
 src/niepce/ui/gridviewmodule.hpp               |    5 +
 src/niepce/ui/librarycellrenderer.cpp          |   60 +++++++++++---
 src/niepce/ui/librarycellrenderer.hpp          |   11 ++-
 src/niepce/ui/moduleshell.cpp                  |    4 +-
 src/niepce/ui/moduleshell.hpp                  |    8 +-
 src/niepce/ui/niepcewindow.cpp                 |  106 +++++++++++------------
 src/niepce/ui/niepcewindow.hpp                 |    5 +-
 src/niepce/ui/thumbstripview.cpp               |    2 +
 19 files changed, 313 insertions(+), 101 deletions(-)
---
diff --git a/src/engine/db/label.hpp b/src/engine/db/label.hpp
index d9a9d15..bde82a0 100644
--- a/src/engine/db/label.hpp
+++ b/src/engine/db/label.hpp
@@ -48,14 +48,15 @@ public:
 		
     int id() const
         { return m_id; }
-		const std::string & label() 
+    const std::string & label() 
         { return m_label; }
     void set_label(const std::string & l)
         { m_label = l; }
-    const fwk::RgbColor color() const
+    const fwk::RgbColor & color() const
         { return m_color; }
     void set_color(const fwk::RgbColor & c)
         { m_color = c; }
+
 private:
     int              m_id;
     std::string      m_label;
diff --git a/src/fwk/toolkit/uicontroller.hpp b/src/fwk/toolkit/uicontroller.hpp
index 81f11c9..75d8873 100644
--- a/src/fwk/toolkit/uicontroller.hpp
+++ b/src/fwk/toolkit/uicontroller.hpp
@@ -43,10 +43,10 @@ public:
   
     /** return the widget controlled (construct it if needed) */
     virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager) = 0;
-		Gtk::Widget * widget() const;
+    Gtk::Widget * widget() const;
 
 protected:
-		Gtk::Widget*                 m_widget;
+    Gtk::Widget*                 m_widget;
     Glib::RefPtr<Gtk::UIManager> m_uimanager;
     Gtk::UIManager::ui_merge_id  m_ui_merge_id;
 };
diff --git a/src/libraryclient/Makefile.am b/src/libraryclient/Makefile.am
index bc569de..121da4a 100644
--- a/src/libraryclient/Makefile.am
+++ b/src/libraryclient/Makefile.am
@@ -23,4 +23,6 @@ test_worker_LDADD = $(TEST_LIBS)
 
 liblibraryclient_a_SOURCES = libraryclient.hpp  libraryclient.cpp \
 	clientimpl.hpp clientimpl.cpp \
-	locallibraryserver.hpp locallibraryserver.cpp
+	locallibraryserver.hpp locallibraryserver.cpp \
+	uidataprovider.hpp uidataprovider.cpp \
+	$(NULL)
diff --git a/src/libraryclient/libraryclient.cpp b/src/libraryclient/libraryclient.cpp
index 4b4d4ed..cd0c82a 100644
--- a/src/libraryclient/libraryclient.cpp
+++ b/src/libraryclient/libraryclient.cpp
@@ -22,6 +22,7 @@
 
 #include "libraryclient.hpp"
 #include "clientimpl.hpp"
+#include "uidataprovider.hpp"
 
 using eng::tid_t;
 
@@ -32,14 +33,16 @@ const char * s_thumbcacheDirname = "thumbcache";
 
 LibraryClient::LibraryClient(const fwk::Moniker & moniker, 
                              const fwk::NotificationCenter::Ptr & nc)
-    : m_pImpl(ClientImpl::makeClientImpl(moniker, nc)),
-      m_thumbnailCache(moniker.path() + "/" + s_thumbcacheDirname, nc)
+    : m_pImpl(ClientImpl::makeClientImpl(moniker, nc))
+    , m_thumbnailCache(moniker.path() + "/" + s_thumbcacheDirname, nc)
+    , m_uidataprovider(new UIDataProvider())
 {
 }
 
 LibraryClient::~LibraryClient()
 {
     delete m_pImpl;
+    delete m_uidataprovider;
 }
 
 tid_t LibraryClient::newTid()
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index 1a67b90..9cb79d7 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -34,7 +34,9 @@ namespace fwk {
 
 namespace libraryclient {
 
-	class ClientImpl;
+  class UIDataProvider;
+
+  class ClientImpl;
 
 	class LibraryClient
 		: public eng::Storage
@@ -85,14 +87,16 @@ namespace libraryclient {
 
 		/* sync call */
 		virtual bool fetchKeywordsForFile(int file, eng::Keyword::IdList &keywords);
-
+	  UIDataProvider *getDataProvider() const
+	  { return m_uidataprovider; }
 	private:
-		ClientImpl* m_pImpl;
-
-		eng::ThumbnailCache                    m_thumbnailCache;
-
-		LibraryClient(const LibraryClient &);
-		LibraryClient & operator=(const LibraryClient &);
+	  ClientImpl* m_pImpl;
+	  
+	  eng::ThumbnailCache                    m_thumbnailCache;
+	  UIDataProvider *m_uidataprovider;
+	  
+	  LibraryClient(const LibraryClient &);
+	  LibraryClient & operator=(const LibraryClient &);
 	};
 
 }
diff --git a/src/libraryclient/uidataprovider.cpp b/src/libraryclient/uidataprovider.cpp
new file mode 100644
index 0000000..b3840a7
--- /dev/null
+++ b/src/libraryclient/uidataprovider.cpp
@@ -0,0 +1,91 @@
+/*
+ * niepce - libraryclient/uidataprovider.cpp
+ *
+ * Copyright (C) 2011 Hub 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 <algorithm>
+#include <boost/bind.hpp>
+
+#include "fwk/base/debug.hpp"
+#include "fwk/base/color.hpp"
+#include "engine/db/label.hpp"
+#include "uidataprovider.hpp"
+
+
+namespace libraryclient {
+
+void UIDataProvider::updateLabel(const eng::Label::Ptr & l)
+{
+    // 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());
+        }
+    }
+}
+
+
+void UIDataProvider::addLabels(const eng::Label::ListPtr & l)
+{
+    for(eng::Label::List::const_iterator iter = l->begin();
+        iter != l->end(); ++iter) {
+        m_labels.push_back(eng::Label::Ptr(new eng::Label(*(iter->get()))));
+    }
+}
+
+
+void UIDataProvider::deleteLabel(int id)
+{
+    // 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;
+        }
+    }
+}
+
+const fwk::RgbColor * UIDataProvider::colorForLabel(int id) const
+{
+    for(eng::Label::List::const_iterator iter = m_labels.begin();
+        iter != m_labels.end(); ++iter) {
+        if((*iter)->id() == id) {
+            return &((*iter)->color());
+        }
+    }
+    return NULL;
+}
+
+
+}
+
+/*
+  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/libraryclient/uidataprovider.hpp b/src/libraryclient/uidataprovider.hpp
new file mode 100644
index 0000000..e9203c3
--- /dev/null
+++ b/src/libraryclient/uidataprovider.hpp
@@ -0,0 +1,60 @@
+/*
+ * niepce - libraryclient/uidataprovider.hpp
+ *
+ * Copyright (C) 2011 Hub 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 __LIBRARYCLIENT_UIDATAPROVIDER_HPP__
+#define __LIBRARYCLIENT_UIDATAPROVIDER_HPP__
+
+#include <stdint.h>
+
+#include "engine/db/label.hpp"
+
+namespace fwk {
+class RgbColor;
+}
+
+namespace libraryclient {
+
+class UIDataProvider
+{
+public:
+    // label management
+
+    void updateLabel(const eng::Label::Ptr &);
+    void addLabels(const eng::Label::ListPtr & l);
+    void deleteLabel(int id);
+    const fwk::RgbColor * colorForLabel(int id) const;
+    const eng::Label::List & getLabels() const
+        { return m_labels; }
+private:
+    eng::Label::List m_labels;
+};
+
+}
+
+#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/modules/darkroom/darkroommodule.hpp b/src/niepce/modules/darkroom/darkroommodule.hpp
index d2f32c1..672335c 100644
--- a/src/niepce/modules/darkroom/darkroommodule.hpp
+++ b/src/niepce/modules/darkroom/darkroommodule.hpp
@@ -48,10 +48,10 @@ public:
 	typedef std::tr1::shared_ptr<DarkroomModule> Ptr;
 
 	DarkroomModule(const Glib::RefPtr<Gtk::ActionGroup> & action_group,
-                   const sigc::slot<libraryclient::LibraryClient::Ptr> & getclient)
+                   const libraryclient::LibraryClient::Ptr & libclient)
         : m_actionGroup(action_group),
           m_image(new ncr::Image),
-          m_getClient(getclient)
+          m_libClient(libclient)
 		{
 		}
 
@@ -71,7 +71,7 @@ private:
     ToolboxController::Ptr       m_toolbox_ctrl;
     Glib::RefPtr<Gtk::ActionGroup> m_actionGroup;
     ncr::Image::Ptr              m_image;
-    sigc::slot<libraryclient::LibraryClient::Ptr> m_getClient;
+    libraryclient::LibraryClient::Ptr m_libClient;
     fwk::Dock                   *m_dock;
 };
 
diff --git a/src/niepce/ui/dialogs/editlabels.cpp b/src/niepce/ui/dialogs/editlabels.cpp
index 2e18b65..d106124 100644
--- a/src/niepce/ui/dialogs/editlabels.cpp
+++ b/src/niepce/ui/dialogs/editlabels.cpp
@@ -33,6 +33,7 @@
 #include "fwk/toolkit/gdkutils.hpp"
 #include "fwk/toolkit/undo.hpp"
 #include "libraryclient/libraryclient.hpp"
+#include "libraryclient/uidataprovider.hpp"
 #include "editlabels.hpp"
 
 
@@ -40,9 +41,9 @@ using libraryclient::LibraryClient;
 
 namespace ui {
 
-EditLabels::EditLabels(const eng::Label::List & labels, const LibraryClient::Ptr & libclient)
+EditLabels::EditLabels(const LibraryClient::Ptr & libclient)
     : fwk::Dialog(GLADEDIR"editlabels.ui", "editLabels")
-    , m_labels(labels)
+    , m_labels(libclient->getDataProvider()->getLabels())
     , m_lib_client(libclient)
 {
     std::fill(m_status.begin(), m_status.end(), false);
diff --git a/src/niepce/ui/dialogs/editlabels.hpp b/src/niepce/ui/dialogs/editlabels.hpp
index dd90073..a71ca1c 100644
--- a/src/niepce/ui/dialogs/editlabels.hpp
+++ b/src/niepce/ui/dialogs/editlabels.hpp
@@ -39,14 +39,14 @@ class EditLabels
 {
 public:
     typedef std::tr1::shared_ptr<EditLabels> Ptr;
-    EditLabels(const eng::Label::List &, const libraryclient::LibraryClient::Ptr &);
+    EditLabels(const libraryclient::LibraryClient::Ptr &);
 
     virtual void setup_widget();
 private:
     void label_name_changed(size_t idx);
     void label_color_changed(size_t idx);
     void update_labels(int /*response*/);
-    eng::Label::List                  m_labels;
+    const eng::Label::List            & m_labels;
     std::tr1::array<Gtk::ColorButton*, 5> m_colors;
     std::tr1::array<Gtk::Entry*, 5>   m_entries;
     std::tr1::array<bool, 5>          m_status;
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index d89c656..01457c9 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -38,7 +38,10 @@ GridViewModule::GridViewModule(ModuleShell* shell,
                                const Glib::RefPtr<ImageListStore> & store)
   : m_shell(shell)
   , m_model(store)
+  , m_uidataprovider(NULL)
 {
+    m_uidataprovider = m_shell->getLibraryClient()->getDataProvider();
+    DBG_ASSERT(m_uidataprovider, "provider is NULL");
 }
 
 void 
@@ -89,7 +92,7 @@ Gtk::Widget * GridViewModule::buildWidget(const Glib::RefPtr<Gtk::UIManager> & m
   m_librarylistview.property_margin() = 0;
 
   // the main cell
-  LibraryCellRenderer * libcell = Gtk::manage(new LibraryCellRenderer());
+  LibraryCellRenderer * libcell = Gtk::manage(new LibraryCellRenderer(m_uidataprovider));
   libcell->signal_rating_changed.connect(sigc::mem_fun(*this, &GridViewModule::on_rating_changed));
 
   GtkCellLayout *cl = GTK_CELL_LAYOUT(m_librarylistview.gobj());
@@ -164,7 +167,7 @@ void GridViewModule::select_image(int id)
     }
 }
 
-void GridViewModule::on_rating_changed(int id, int rating)
+void GridViewModule::on_rating_changed(int /*id*/, int rating)
 {
     m_shell->get_selection_controller()->set_rating(rating);
 }
diff --git a/src/niepce/ui/gridviewmodule.hpp b/src/niepce/ui/gridviewmodule.hpp
index 3be50e7..5379d93 100644
--- a/src/niepce/ui/gridviewmodule.hpp
+++ b/src/niepce/ui/gridviewmodule.hpp
@@ -37,6 +37,10 @@ namespace fwk {
 class Dock;
 }
 
+namespace libraryclient {
+class UIDataProvider;
+}
+
 namespace ui {
 
 class ModuleShell;
@@ -72,6 +76,7 @@ private:
 
   ModuleShell                 *m_shell;
   Glib::RefPtr<ImageListStore> m_model;
+  libraryclient::UIDataProvider *m_uidataprovider;
 
   // library split view
   Gtk::IconView                m_librarylistview;
diff --git a/src/niepce/ui/librarycellrenderer.cpp b/src/niepce/ui/librarycellrenderer.cpp
index 01f127e..f9f7719 100644
--- a/src/niepce/ui/librarycellrenderer.cpp
+++ b/src/niepce/ui/librarycellrenderer.cpp
@@ -18,8 +18,13 @@
  */
 
 
+#include <stdint.h>
+
 #include "fwk/base/debug.hpp"
 #include "fwk/toolkit/widgets/ratinglabel.hpp"
+#include "fwk/toolkit/gdkutils.hpp"
+#include "engine/db/label.hpp"
+#include "libraryclient/uidataprovider.hpp"
 #include "librarycellrenderer.hpp"
 
 #include <gdkmm/general.h>
@@ -32,7 +37,7 @@
 
 namespace ui {
 
-LibraryCellRenderer::LibraryCellRenderer()
+LibraryCellRenderer::LibraryCellRenderer(libraryclient::UIDataProvider *provider)
     : Glib::ObjectBase(typeid(LibraryCellRenderer)),
       Gtk::CellRendererPixbuf(),
       m_size(160),
@@ -40,6 +45,8 @@ LibraryCellRenderer::LibraryCellRenderer()
       m_drawborder(true),
       m_drawemblem(true),
       m_drawrating(true),
+      m_drawlabel(true),
+      m_uiDataProvider(provider),
       m_libfileproperty(*this, "libfile")
 {
     property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
@@ -98,23 +105,42 @@ void LibraryCellRenderer::_drawThumbnail(const Cairo::RefPtr<Cairo::Context> & c
 
 namespace {
 
-void drawFormatEmblem(const Cairo::RefPtr<Cairo::Context> & cr, 
+int drawFormatEmblem(const Cairo::RefPtr<Cairo::Context> & cr, 
                       const Cairo::RefPtr<Cairo::ImageSurface> & emblem,
-                      const GdkRectangle & r)
-		
+                      const GdkRectangle & r)		
 {	
+    int left = 0;
     if(emblem) {
         int w, h;
         w = emblem->get_width();
         h = emblem->get_height();
         double x, y;
-        x = r.x + r.width - CELL_PADDING - w;
+        left = CELL_PADDING + w;
+        x = r.x + r.width - left;
         y = r.y + r.height - CELL_PADDING - h;
         cr->set_source(emblem, x, y);
         cr->paint();
     }
+    return left;
 }
 
+void drawLabel(const Cairo::RefPtr<Cairo::Context> & cr, 
+               int right, const fwk::RgbColor * color,
+               const GdkRectangle & r)
+{
+    DBG_ASSERT(color, "color is NULL");
+    const int label_size = 15;
+    double x, y;
+    x = r.x + r.width - CELL_PADDING - right - CELL_PADDING - label_size;
+    y = r.y + r.height - CELL_PADDING - label_size;
+    
+    cr->rectangle(x, y, label_size, label_size);
+    cr->set_source_rgb(1.0, 1.0, 1.0);
+    cr->stroke();
+    cr->rectangle(x, y, label_size, label_size);
+    Gdk::Cairo::set_source_color(cr, fwk::rgbcolor_to_gdkcolor(*color));
+    cr->fill();
+}
 
 }
 
@@ -218,17 +244,27 @@ LibraryCellRenderer::render_vfunc(const Glib::RefPtr<Gdk::Drawable>& window,
             break;
         }
         
-        drawFormatEmblem(cr, emblem, r);
+        int left = drawFormatEmblem(cr, emblem, r);
+        if(m_drawlabel) {
+            DBG_ASSERT(m_uiDataProvider, "no UIDataProvider");
+            uint32_t label_index = file->label();
+            const fwk::RgbColor * label_color = m_uiDataProvider->colorForLabel(label_index);
+            DBG_ASSERT(label_color, "color not found");
+            if(label_color) {
+                drawLabel(cr, left, label_color, r);
+            }
+        }
     }
 }
 
 
-bool LibraryCellRenderer::activate_vfunc(GdkEvent *event,
-                                         Gtk::Widget & widget,
-                                         const Glib::ustring &	path,
-                                         const Gdk::Rectangle&	background_area,
-                                         const Gdk::Rectangle&	cell_area,
-                                         Gtk::CellRendererState	flags)
+bool
+LibraryCellRenderer::activate_vfunc(GdkEvent *event,
+                                    Gtk::Widget & /*widget*/,
+                                    const Glib::ustring & /*path*/,
+                                    const Gdk::Rectangle& /*background_area*/,
+                                    const Gdk::Rectangle& cell_area,
+                                    Gtk::CellRendererState /*flags*/)
 {
     DBG_OUT("activated. Event type of %d", event->type);
     if(event->type == GDK_BUTTON_PRESS) {
diff --git a/src/niepce/ui/librarycellrenderer.hpp b/src/niepce/ui/librarycellrenderer.hpp
index cc37954..c6955ab 100644
--- a/src/niepce/ui/librarycellrenderer.hpp
+++ b/src/niepce/ui/librarycellrenderer.hpp
@@ -26,6 +26,11 @@
 #include <cairomm/surface.h>
 
 #include "engine/db/libfile.hpp"
+#include "engine/db/label.hpp"
+
+namespace libraryclient {
+class UIDataProvider;
+}
 
 namespace ui {
 
@@ -33,7 +38,7 @@ class LibraryCellRenderer
 	: public Gtk::CellRendererPixbuf
 {
 public:
-    LibraryCellRenderer();
+    LibraryCellRenderer(libraryclient::UIDataProvider *provider);
     
     virtual void get_size_vfunc(Gtk::Widget& widget, 
                                 const Gdk::Rectangle* cell_area, 
@@ -66,6 +71,8 @@ public:
         { m_drawemblem = val; }
     void set_drawrating(bool val)
         { m_drawrating = val; }
+    void set_drawlabel(bool val)
+        { m_drawlabel = val; }
 
     Glib::PropertyProxy_ReadOnly<eng::LibFile::Ptr> property_libfile() const;
     Glib::PropertyProxy<eng::LibFile::Ptr>          property_libfile();
@@ -82,6 +89,8 @@ private:
     bool                                m_drawborder;
     bool                                m_drawemblem;
     bool                                m_drawrating;
+    bool                                m_drawlabel;
+    libraryclient::UIDataProvider      *m_uiDataProvider;
     Glib::Property<eng::LibFile::Ptr>   m_libfileproperty;
     
     Cairo::RefPtr<Cairo::ImageSurface>  m_raw_format_emblem;
diff --git a/src/niepce/ui/moduleshell.cpp b/src/niepce/ui/moduleshell.cpp
index dea1e5c..b8391c6 100644
--- a/src/niepce/ui/moduleshell.cpp
+++ b/src/niepce/ui/moduleshell.cpp
@@ -180,7 +180,7 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
 
 
     m_darkroom = darkroom::DarkroomModule::Ptr(
-        new darkroom::DarkroomModule(m_actionGroup, m_getclient));
+        new darkroom::DarkroomModule(m_actionGroup, m_libraryclient));
     add_library_module(m_darkroom, _("Darkroom"));
 
     // TODO PrintModuleController
@@ -208,7 +208,7 @@ void ModuleShell::on_selected(int id)
 {
     DBG_OUT("selected callback %d", id);
     if(id > 0) {
-        m_getclient()->requestMetadata(id);
+        m_libraryclient->requestMetadata(id);
     }		
     else  {
         m_gridview->display_none();
diff --git a/src/niepce/ui/moduleshell.hpp b/src/niepce/ui/moduleshell.hpp
index ded9f76..f1ccae0 100644
--- a/src/niepce/ui/moduleshell.hpp
+++ b/src/niepce/ui/moduleshell.hpp
@@ -44,8 +44,8 @@ public:
     typedef std::tr1::shared_ptr<ModuleShell> Ptr;
     typedef std::tr1::weak_ptr<ModuleShell> WeakPtr;
     
-    ModuleShell(const sigc::slot<libraryclient::LibraryClient::Ptr> get_client)
-        : m_getclient(get_client)
+    ModuleShell(const libraryclient::LibraryClient::Ptr & libclient)
+        : m_libraryclient(libclient)
         , m_actionGroup(Gtk::ActionGroup::create("ModuleShell"))
         {
         }
@@ -65,7 +65,7 @@ public:
         }
     libraryclient::LibraryClient::Ptr getLibraryClient() const
         {
-            return m_getclient();
+            return m_libraryclient;
         }
 
     /** called when somehing is selected by the shared selection */
@@ -78,7 +78,7 @@ protected:
                                     const std::string & label);
     virtual void on_ready();
 private:
-    sigc::slot<libraryclient::LibraryClient::Ptr> m_getclient;
+    libraryclient::LibraryClient::Ptr m_libraryclient;
     Glib::RefPtr<Gtk::ActionGroup> m_actionGroup;
     
     // managed widgets...
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index e77880b..58dd392 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -40,6 +40,7 @@
 #include "fwk/toolkit/configdatabinder.hpp"
 #include "fwk/toolkit/undo.hpp"
 #include "engine/db/library.hpp"
+#include "libraryclient/uidataprovider.hpp"
 
 #include "thumbstripview.hpp"
 #include "niepcewindow.hpp"
@@ -68,36 +69,19 @@ NiepceWindow::~NiepceWindow()
     pApp->uiManager()->remove_action_group(m_refActionGroup);
 }
 
-Gtk::Widget * 
-NiepceWindow::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager)
+void 
+NiepceWindow::_createModuleShell()
 {
-    DBG_ASSERT(manager, "manager is NULL");
-    if(m_widget) {
-        return m_widget;
-    }
-    Gtk::Window & win(gtkWindow());
-
-    m_widget = &win;
-
-    init_actions(manager);
-    init_ui(manager);
-
-    m_notifcenter.reset(new niepce::NotificationCenter());
-
-    Glib::ustring name("camera");
-    set_icon_from_theme(name);		
-
-
-    m_notifcenter->signal_lib_notification.connect(
-        sigc::mem_fun(*this, &NiepceWindow::on_lib_notification));
-
+    DBG_ASSERT(m_uimanager, "UI manager NULL");
+    DBG_ASSERT(m_libClient, "libclient not initialized");
+    DBG_ASSERT(m_widget, "widget not built");
 
+    DBG_OUT("creating module shell");
 
     // main view
     m_moduleshell = ModuleShell::Ptr(
-        new ModuleShell(sigc::mem_fun(
-                            *this, &NiepceWindow::getLibraryClient)));
-    m_moduleshell->buildWidget(manager);
+        new ModuleShell(getLibraryClient()));
+    m_moduleshell->buildWidget(m_uimanager);
 
     add(m_moduleshell);
 
@@ -124,15 +108,15 @@ NiepceWindow::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager)
     add(m_workspacectrl);
 
     m_hbox.set_border_width(4);
-    m_hbox.pack1(*(m_workspacectrl->buildWidget(manager)), Gtk::EXPAND);
-    m_hbox.pack2(*(m_moduleshell->buildWidget(manager)), Gtk::EXPAND);
+    m_hbox.pack1(*(m_workspacectrl->buildWidget(m_uimanager)), Gtk::EXPAND);
+    m_hbox.pack2(*(m_moduleshell->buildWidget(m_uimanager)), Gtk::EXPAND);
     m_databinders.add_binder(new fwk::ConfigDataBinder<int>(m_hbox.property_position(),
                                                                   Application::app()->config(),
                                                                   "workspace_splitter"));
 
-    win.add(m_vbox);
+    static_cast<Gtk::Window*>(m_widget)->add(m_vbox);
 
-    Gtk::Widget* pMenuBar = manager->get_widget("/MenuBar");
+    Gtk::Widget* pMenuBar = m_uimanager->get_widget("/MenuBar");
     m_vbox.pack_start(*pMenuBar, Gtk::PACK_SHRINK);
     m_vbox.pack_start(m_hbox);
 
@@ -141,7 +125,7 @@ NiepceWindow::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager)
     m_filmstrip = FilmStripController::Ptr(new FilmStripController(m_moduleshell->get_list_store()));
     add(m_filmstrip);
 
-    m_vbox.pack_start(*(m_filmstrip->buildWidget(manager)), Gtk::PACK_SHRINK);
+    m_vbox.pack_start(*(m_filmstrip->buildWidget(m_uimanager)), Gtk::PACK_SHRINK);
 
     // status bar
     m_vbox.pack_start(m_statusBar, Gtk::PACK_SHRINK);
@@ -149,6 +133,36 @@ NiepceWindow::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager)
 
     selection_controller->add_selectable(m_filmstrip.get());
 
+    m_vbox.show_all_children();
+    m_vbox.show();
+}
+
+
+Gtk::Widget * 
+NiepceWindow::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager)
+{
+    DBG_ASSERT(manager, "manager is NULL");
+
+    if(m_widget) {
+        return m_widget;
+    }
+    m_uimanager = manager;
+    Gtk::Window & win(gtkWindow());
+
+    m_widget = &win;
+
+    init_actions(manager);
+    init_ui(manager);
+
+    m_notifcenter.reset(new niepce::NotificationCenter());
+
+    Glib::ustring name("camera");
+    set_icon_from_theme(name);		
+
+
+    m_notifcenter->signal_lib_notification.connect(
+        sigc::mem_fun(*this, &NiepceWindow::on_lib_notification));
+
     win.set_size_request(600, 400);
     win.show_all_children();
     on_open_library();
@@ -395,41 +409,20 @@ void NiepceWindow::on_lib_notification(const eng::LibNotification & ln)
     {
         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);
-        }
+        m_libClient->getDataProvider()->addLabels(l);
         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());
-            }
-        }
+        m_libClient->getDataProvider()->updateLabel(l);
         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;
-            }
-        }
+        m_libClient->getDataProvider()->deleteLabel(id);
         break;
     }
     default:
@@ -444,13 +437,16 @@ void NiepceWindow::open_library(const std::string & libMoniker)
                                                        m_notifcenter));
     set_title(libMoniker);
     m_libClient->getAllLabels();
+    if(!m_moduleshell) {
+        _createModuleShell();
+    }
 }
 
 void NiepceWindow::on_action_edit_labels()
 {
     DBG_OUT("edit labels");
     // get the labels.
-    EditLabels::Ptr dlg(new EditLabels(get_labels(), getLibraryClient()));
+    EditLabels::Ptr dlg(new EditLabels(getLibraryClient()));
     dlg->run_modal(shared_frame_ptr());
 }
 
diff --git a/src/niepce/ui/niepcewindow.hpp b/src/niepce/ui/niepcewindow.hpp
index e10b763..6fe7fc8 100644
--- a/src/niepce/ui/niepcewindow.hpp
+++ b/src/niepce/ui/niepcewindow.hpp
@@ -78,8 +78,8 @@ private:
     void init_actions(const Glib::RefPtr<Gtk::UIManager> & manager);
 
     void open_library(const std::string & libMoniker);
-    eng::Label::List &   get_labels()
-        { return m_labels; }
+
+    void _createModuleShell();
 		
     niepce::NotificationCenter::Ptr m_notifcenter;
 
@@ -91,7 +91,6 @@ private:
     Gtk::Statusbar                 m_statusBar;
     Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
     libraryclient::LibraryClient::Ptr m_libClient;
-    eng::Label::List               m_labels;
 };
 
 }
diff --git a/src/niepce/ui/thumbstripview.cpp b/src/niepce/ui/thumbstripview.cpp
index 9274e18..12504b4 100644
--- a/src/niepce/ui/thumbstripview.cpp
+++ b/src/niepce/ui/thumbstripview.cpp
@@ -64,12 +64,14 @@ public:
 
 ThumbStripCell::ThumbStripCell()
     : Glib::ObjectBase(typeid(ThumbStripCell))
+    , LibraryCellRenderer(NULL)
 {
     set_pad(0);
     set_size(100);
     set_drawborder(false);
     set_drawemblem(false);
     set_drawrating(false);
+    set_drawlabel(false);
 }
 
 



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