[niepce] ui: don't pass the shell to the filmstrip controller.



commit e3d83bcf5d9ad67fb46f2565f80cefc43c8e3971
Author: Hubert Figuière <hub figuiere net>
Date:   Thu Jan 9 21:19:23 2020 -0500

    ui: don't pass the shell to the filmstrip controller.
    
    - all we need is to get label colours from UIDataProvider

 src/libraryclient/libraryclient.hpp   |  9 ++++-----
 src/libraryclient/uidataprovider.hpp  | 11 ++++++-----
 src/niepce/ui/filmstripcontroller.cpp |  9 +++++----
 src/niepce/ui/filmstripcontroller.hpp | 31 ++++++++++++++++++-------------
 src/niepce/ui/gridviewmodule.cpp      | 16 ++++++++++++++--
 src/niepce/ui/imoduleshell.hpp        |  9 +++------
 src/niepce/ui/librarycellrenderer.cpp |  8 ++++----
 src/niepce/ui/librarycellrenderer.hpp | 12 ++++++------
 src/niepce/ui/moduleshell.hpp         | 12 ++++--------
 src/niepce/ui/niepcewindow.cpp        |  4 +++-
 src/niepce/ui/thumbstripview.cpp      | 22 ++++++++++++++++------
 src/niepce/ui/thumbstripview.hpp      |  6 +++---
 12 files changed, 86 insertions(+), 63 deletions(-)
---
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index 4ca1252..6a6b2df 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - libraryclient/libraryclient.hpp
  *
- * Copyright (C) 2007-2019 Hubert Figuière
+ * Copyright (C) 2007-2020 Hubert Figuière
  *
  * 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
@@ -23,6 +23,7 @@
 #include <memory>
 
 #include "engine/library/thumbnailcache.hpp"
+#include "uidataprovider.hpp"
 
 #include "rust_bindings.hpp"
 
@@ -32,8 +33,6 @@ class Moniker;
 
 namespace libraryclient {
 
-class UIDataProvider;
-
 class LibraryClient
 {
 public:
@@ -47,7 +46,7 @@ public:
     eng::ThumbnailCache & thumbnailCache()
         { return m_thumbnailCache; }
 
-    const std::unique_ptr<UIDataProvider>& getDataProvider() const
+    const UIDataProviderPtr& getDataProvider() const
         { return m_uidataprovider; }
 
     ffi::LibraryClientWrapper* client() const {
@@ -57,7 +56,7 @@ private:
     std::shared_ptr<ffi::LibraryClientWrapper> m_client;
 
     eng::ThumbnailCache m_thumbnailCache;
-    std::unique_ptr<UIDataProvider> m_uidataprovider;
+    UIDataProviderPtr m_uidataprovider;
 };
 
 typedef std::shared_ptr<LibraryClient> LibraryClientPtr;
diff --git a/src/libraryclient/uidataprovider.hpp b/src/libraryclient/uidataprovider.hpp
index 19f479d..f57981d 100644
--- a/src/libraryclient/uidataprovider.hpp
+++ b/src/libraryclient/uidataprovider.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - libraryclient/uidataprovider.hpp
  *
- * Copyright (C) 2011-2017 Hubert Figuière
+ * Copyright (C) 2011-2020 Hubert Figuière
  *
  * 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
@@ -17,10 +17,10 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __LIBRARYCLIENT_UIDATAPROVIDER_HPP__
-#define __LIBRARYCLIENT_UIDATAPROVIDER_HPP__
+#pragma once
 
 #include <stdint.h>
+#include <memory>
 
 #include "fwk/base/option.hpp"
 #include "fwk/base/colour.hpp"
@@ -43,9 +43,10 @@ private:
     eng::LabelList m_labels;
 };
 
-}
+typedef std::shared_ptr<UIDataProvider> UIDataProviderPtr;
+typedef std::weak_ptr<UIDataProvider> UIDataProviderWeakPtr;
 
-#endif
+}
 /*
   Local Variables:
   mode:c++
diff --git a/src/niepce/ui/filmstripcontroller.cpp b/src/niepce/ui/filmstripcontroller.cpp
index 259f7a4..e22584d 100644
--- a/src/niepce/ui/filmstripcontroller.cpp
+++ b/src/niepce/ui/filmstripcontroller.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - niepce/ui/filmstripcontroller.cpp
  *
- * Copyright (C) 2008-2009 Hubert Figuiere
+ * Copyright (C) 2008-2020 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
@@ -31,8 +31,8 @@
 namespace ui {
 
 FilmStripController::FilmStripController(const Glib::RefPtr<ImageListStore> & store,
-                                         const IModuleShell& shell)
-    : m_shell(shell)
+                                         const libraryclient::UIDataProviderWeakPtr& ui_data_provider)
+    : m_ui_data_provider(ui_data_provider)
     , m_store(store)
 {
 }
@@ -43,7 +43,7 @@ Gtk::Widget * FilmStripController::buildWidget()
         return m_widget;
     }
     DBG_ASSERT(static_cast<bool>(m_store), "m_store NULL");
-    m_thumbview = manage(new ThumbStripView(m_store, m_shell));
+    m_thumbview = manage(new ThumbStripView(m_store, m_ui_data_provider));
     GtkWidget *thn = eog_thumb_nav_new(m_thumbview,
                                        EogThumbNavMode::ONE_ROW, true);
     m_thumbview->set_selection_mode(Gtk::SELECTION_SINGLE);
@@ -100,6 +100,7 @@ void FilmStripController::select_image(eng::library_id_t id)
 /*
   Local Variables:
   mode:c++
+  c-basic-offset:4
   c-file-style:"stroustrup"
   c-file-offsets:((innamespace . 0))
   indent-tabs-mode:nil
diff --git a/src/niepce/ui/filmstripcontroller.hpp b/src/niepce/ui/filmstripcontroller.hpp
index 1b4e746..d46775d 100644
--- a/src/niepce/ui/filmstripcontroller.hpp
+++ b/src/niepce/ui/filmstripcontroller.hpp
@@ -1,7 +1,7 @@
 /*
- * niepce - niepce/ui/filmstripcontroller.h
+ * niepce - niepce/ui/filmstripcontroller.hpp
  *
- * Copyright (C) 2008-2013 Hubert Figuiere
+ * Copyright (C) 2008-2020 Hubert Figuière
  *
  * 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
@@ -17,10 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
-
-#ifndef __UI_FILMSTRIPCONTROLLER_H_
-#define __UI_FILMSTRIPCONTROLLER_H_
+#pragma once
 
 #include "fwk/toolkit/uicontroller.hpp"
 #include "fwk/toolkit/notificationcenter.hpp"
@@ -32,8 +29,6 @@ namespace Gtk {
 
 namespace ui {
 
-class IModuleShell;
-
 class FilmStripController
        : public fwk::UiController,
          public IImageSelectable
@@ -42,8 +37,9 @@ public:
        typedef std::shared_ptr<FilmStripController> Ptr;
        typedef std::weak_ptr<FilmStripController> WeakPtr;
 
-       FilmStripController(const Glib::RefPtr<ImageListStore>& store,
-                           const IModuleShell& shell);
+       FilmStripController(
+          const Glib::RefPtr<ImageListStore>& store,
+          const libraryclient::UIDataProviderWeakPtr& ui_data_provider);
 
        virtual Gtk::IconView * image_list() override;
        virtual eng::library_id_t get_selected() override;
@@ -52,12 +48,21 @@ public:
        virtual Gtk::Widget * buildWidget() override;
 
 private:
-       const IModuleShell& m_shell;
+       libraryclient::UIDataProviderWeakPtr m_ui_data_provider;
        Gtk::IconView * m_thumbview;
        Glib::RefPtr<ImageListStore> m_store;
 };
 
 
 }
-
-#endif
+/*
+  Local Variables:
+  mode:c++
+  c-basic-offset:4
+  tab-width:4
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0))
+  indent-tabs-mode:t
+  fill-column:99
+  End:
+*/
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index c18b9da..eb57c8d 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/gridviewmodule.cpp
  *
- * Copyright (C) 2009-2019 Hubert Figuière
+ * Copyright (C) 2009-2020 Hubert Figuière
  *
  * 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
@@ -30,6 +30,7 @@
 #include "fwk/toolkit/application.hpp"
 #include "fwk/toolkit/configdatabinder.hpp"
 #include "fwk/toolkit/widgets/dock.hpp"
+#include "libraryclient/uidataprovider.hpp"
 #include "gridviewmodule.hpp"
 #include "moduleshell.hpp"
 #include "librarycellrenderer.hpp"
@@ -110,7 +111,18 @@ Gtk::Widget * GridViewModule::buildWidget()
       .connect(sigc::mem_fun(*this, &GridViewModule::on_popup_menu));
 
   // the main cell
-  LibraryCellRenderer* libcell = Gtk::manage(new LibraryCellRenderer(m_shell));
+  libraryclient::UIDataProviderWeakPtr ui_data_provider(m_shell.get_ui_data_provider());
+  LibraryCellRenderer* libcell = Gtk::manage(
+      new LibraryCellRenderer(
+          [ui_data_provider] (int label) {
+              auto provider = ui_data_provider.lock();
+              if (provider) {
+                  return provider->colourForLabel(label);
+              }
+              ERR_OUT("couldn't lock UI provider");
+              return fwk::Option<fwk::RgbColourPtr>();
+          })
+      );
   libcell->signal_rating_changed.connect(
       sigc::mem_fun(*this, &GridViewModule::on_rating_changed));
 
diff --git a/src/niepce/ui/imoduleshell.hpp b/src/niepce/ui/imoduleshell.hpp
index 75aa876..93495ae 100644
--- a/src/niepce/ui/imoduleshell.hpp
+++ b/src/niepce/ui/imoduleshell.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/imoduleshell.hpp
  *
- * Copyright (C) 2011-2019 Hubert Figuière
+ * Copyright (C) 2011-2020 Hubert Figuière
  *
  * 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
@@ -22,10 +22,7 @@
 #include <memory>
 #include <giomm/menu.h>
 #include "niepce/ui/selectioncontroller.hpp"
-
-namespace libraryclient {
-class UIDataProvider;
-}
+#include "libraryclient/uidataprovider.hpp"
 
 namespace ui {
 
@@ -35,7 +32,7 @@ public:
     virtual ~IModuleShell() {}
     virtual const ui::SelectionController::Ptr & get_selection_controller() const = 0;
     virtual libraryclient::LibraryClientPtr getLibraryClient() const = 0;
-    virtual const std::unique_ptr<libraryclient::UIDataProvider>& get_ui_data_provider() const = 0;
+    virtual const libraryclient::UIDataProviderPtr& get_ui_data_provider() const = 0;
     virtual Glib::RefPtr<Gio::Menu> getMenu() const = 0;
 };
 
diff --git a/src/niepce/ui/librarycellrenderer.cpp b/src/niepce/ui/librarycellrenderer.cpp
index 18ee3a8..3df57a3 100644
--- a/src/niepce/ui/librarycellrenderer.cpp
+++ b/src/niepce/ui/librarycellrenderer.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/librarycellrenderer.cpp
  *
- * Copyright (C) 2008-2018 Hubert Figuière
+ * Copyright (C) 2008-2020 Hubert Figuière
  *
  * 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
@@ -32,10 +32,10 @@
 
 namespace ui {
 
-LibraryCellRenderer::LibraryCellRenderer(const IModuleShell& shell)
+LibraryCellRenderer::LibraryCellRenderer(const GetColourFunc& get_colour)
     : Glib::ObjectBase(typeid(LibraryCellRenderer))
     , Gtk::CellRendererPixbuf()
-    , m_shell(shell)
+    , m_get_colour(get_colour)
     , m_size(160)
     , m_pad(16)
     , m_drawborder(true)
@@ -287,7 +287,7 @@ LibraryCellRenderer::render_vfunc(const Cairo::RefPtr<Cairo::Context>& cr,
         if (m_drawlabel) {
             uint32_t label_id = engine_db_libfile_label(file.get());
             if (label_id != 0) {
-                auto result = m_shell.get_ui_data_provider()->colourForLabel(label_id);
+                auto result = m_get_colour(label_id);
                 DBG_ASSERT(!result.empty(), "colour not found");
                 if (!result.empty()) {
                     drawLabel(cr, left, *result.unwrap(), r);
diff --git a/src/niepce/ui/librarycellrenderer.hpp b/src/niepce/ui/librarycellrenderer.hpp
index 28198b6..8e83d05 100644
--- a/src/niepce/ui/librarycellrenderer.hpp
+++ b/src/niepce/ui/librarycellrenderer.hpp
@@ -1,7 +1,7 @@
 /*
- * niepce - ui/librarycellrenderer.h
+ * niepce - niepce/ui/librarycellrenderer.hpp
  *
- * Copyright (C) 2008-2019 Hubert Figuière
+ * Copyright (C) 2008-2020 Hubert Figuière
  *
  * 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
@@ -24,18 +24,18 @@
 #include <cairomm/surface.h>
 
 #include "engine/db/libfile.hpp"
+#include "fwk/base/colour.hpp"
 #include "fwk/toolkit/widgets/imagegridview.hpp"
 
 namespace ui {
 
-class IModuleShell;
-
 class LibraryCellRenderer
     : public Gtk::CellRendererPixbuf
     , public fwk::ClickableCellRenderer
 {
 public:
-    LibraryCellRenderer(const IModuleShell& shell);
+    typedef std::function<fwk::Option<fwk::RgbColourPtr>(int)> GetColourFunc;
+    LibraryCellRenderer(const GetColourFunc& get_colour);
 
     virtual void get_preferred_width_vfunc(Gtk::Widget& widget, int& minimum_width, int& natural_width) 
const override;
     virtual void get_preferred_height_vfunc(Gtk::Widget& widget, int& minimum_height, int& natural_height) 
const override;
@@ -83,7 +83,7 @@ protected:
                      eng::FileStatus status, const GdkRectangle& r) const;
 
 private:
-    const IModuleShell& m_shell;
+    GetColourFunc m_get_colour;
     int                                 m_size;
     int                                 m_pad;
     bool                                m_drawborder;
diff --git a/src/niepce/ui/moduleshell.hpp b/src/niepce/ui/moduleshell.hpp
index 44dde51..a61d545 100644
--- a/src/niepce/ui/moduleshell.hpp
+++ b/src/niepce/ui/moduleshell.hpp
@@ -1,7 +1,7 @@
 /*
- * niepce - ui/moduleshell.hpp
+ * niepce - niepce/ui/moduleshell.hpp
  *
- * Copyright (C) 2007-2018 Hubert Figuière
+ * Copyright (C) 2007-2020 Hubert Figuière
  *
  * 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
@@ -17,9 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
-#ifndef __UI_MODULESHELL_HPP__
-#define __UI_MODULESHELL_HPP__
+#pragma once
 
 #include <vector>
 
@@ -76,7 +74,7 @@ public:
         {
             return m_libraryclient;
         }
-    virtual const std::unique_ptr<libraryclient::UIDataProvider>& get_ui_data_provider() const override
+    virtual const libraryclient::UIDataProviderPtr& get_ui_data_provider() const override
         {
             return m_libraryclient->getDataProvider();
         }
@@ -131,5 +129,3 @@ private:
   fill-column:80
   End:
 */
-
-#endif
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 91d4d5e..0a972f0 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -161,7 +161,9 @@ NiepceWindow::_createModuleShell()
 
     SelectionController::Ptr selection_controller = m_moduleshell->get_selection_controller();
     m_filmstrip = FilmStripController::Ptr(
-        new FilmStripController(m_moduleshell->get_list_store(), *m_moduleshell));
+        new FilmStripController(
+            m_moduleshell->get_list_store(),
+            libraryclient::UIDataProviderWeakPtr(m_moduleshell->get_ui_data_provider())));
     add(m_filmstrip);
 
     m_vbox.pack_start(*(m_filmstrip->buildWidget()), Gtk::PACK_SHRINK);
diff --git a/src/niepce/ui/thumbstripview.cpp b/src/niepce/ui/thumbstripview.cpp
index f936840..35bea95 100644
--- a/src/niepce/ui/thumbstripview.cpp
+++ b/src/niepce/ui/thumbstripview.cpp
@@ -1,7 +1,7 @@
 /* Eye Of Gnome - Thumbnail View
  *
  * Copyright (C) 2006 The Free Software Foundation
- * Copyright (C) 2007-2018 Hubert Figuière
+ * Copyright (C) 2007-2020 Hubert Figuière
  *
  * C++-ization: Hubert Figuiere <hub figuiere net>
  * Original Author: Claudio Saavedra <csaavedra alumnos utalca cl>
@@ -59,12 +59,12 @@ class ThumbStripCell
     : public LibraryCellRenderer
 {
 public:
-    ThumbStripCell(const IModuleShell& shell);
+    ThumbStripCell(const GetColourFunc& get_colour);
 };
 
-ThumbStripCell::ThumbStripCell(const IModuleShell& shell)
+ThumbStripCell::ThumbStripCell(const GetColourFunc& get_colour)
     : Glib::ObjectBase(typeid(ThumbStripCell))
-    , LibraryCellRenderer(shell)
+    , LibraryCellRenderer(get_colour)
 {
     set_pad(0);
     set_size(100);
@@ -76,14 +76,24 @@ ThumbStripCell::ThumbStripCell(const IModuleShell& shell)
 }
 
 ThumbStripView::ThumbStripView(const Glib::RefPtr<ui::ImageListStore> & store,
-                               const IModuleShell& shell)
+                               const libraryclient::UIDataProviderWeakPtr& ui_data_provider)
     : Glib::ObjectBase(typeid(ThumbStripView))
     , Gtk::IconView(Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(store))
     , property_item_height(*this, "item-height", 100)
     , m_store(store)
     , m_model_item_count(0)
 {
-    m_renderer = manage(new ThumbStripCell(shell));
+    m_renderer = manage(
+        new ThumbStripCell(
+            [ui_data_provider] (int label) {
+                auto provider = ui_data_provider.lock();
+                if (provider) {
+                    return provider->colourForLabel(label);
+                }
+                ERR_OUT("couldn't lock UI provider");
+                return fwk::Option<fwk::RgbColourPtr>();
+            })
+        );
 
     pack_start(*m_renderer, FALSE);
     connect_property_changed("item-height",
diff --git a/src/niepce/ui/thumbstripview.hpp b/src/niepce/ui/thumbstripview.hpp
index 30e8b27..0149927 100644
--- a/src/niepce/ui/thumbstripview.hpp
+++ b/src/niepce/ui/thumbstripview.hpp
@@ -26,17 +26,17 @@
 #include <gtkmm/orientable.h>
 #include <gtkmm/cellrendererpixbuf.h>
 
+#include "libraryclient/uidataprovider.hpp"
 #include "niepce/ui/imageliststore.hpp"
 
 namespace ui {
 
-class IModuleShell;
-
 class ThumbStripView
   : public Gtk::IconView
 {
 public:
-    ThumbStripView(const Glib::RefPtr<ui::ImageListStore>& store, const IModuleShell& shell);
+    ThumbStripView(const Glib::RefPtr<ui::ImageListStore>& store,
+                   const libraryclient::UIDataProviderWeakPtr& ui_data_provider);
 
     void set_model(const Glib::RefPtr<ui::ImageListStore> & store);
     const Glib::RefPtr<ui::ImageListStore> & get_model() const;


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