[niepce] rust+ui: Port more ImageListStore to Rust



commit fcf4274ab385a1011940a28bd87f14a1c4db24ee
Author: Hubert Figuière <hub figuiere net>
Date:   Tue Feb 4 22:58:21 2020 -0500

    rust+ui: Port more ImageListStore to Rust

 crates/npc-engine/src/library/notification.rs   |  58 ------
 crates/npc-engine/src/library/queriedcontent.rs |  19 +-
 crates/npc-fwk/src/toolkit/thumbnail.rs         |   2 +-
 src/niepce/ui/image_list_store.rs               | 249 ++++++++++++++++++------
 src/niepce/ui/imageliststore.cpp                | 172 ++--------------
 src/niepce/ui/imageliststore.hpp                |  27 ---
 6 files changed, 218 insertions(+), 309 deletions(-)
---
diff --git a/crates/npc-engine/src/library/notification.rs b/crates/npc-engine/src/library/notification.rs
index 4da84b0..b72383f 100644
--- a/crates/npc-engine/src/library/notification.rs
+++ b/crates/npc-engine/src/library/notification.rs
@@ -17,10 +17,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-use gdk_pixbuf;
-use gdk_pixbuf_sys;
-use glib::translate::*;
-
 use super::queriedcontent::QueriedContent;
 use crate::db::libfile::FileStatus;
 use crate::db::{Keyword, Label, LibFolder, LibMetadata, LibraryId};
@@ -230,26 +226,6 @@ pub unsafe extern "C" fn engine_library_notification_get_label(
     }
 }
 
-#[no_mangle]
-pub unsafe extern "C" fn engine_library_notification_get_filemoved(
-    n: *const LibNotification,
-) -> *const FileMove {
-    match n.as_ref() {
-        Some(&LibNotification::FileMoved(ref m)) => m,
-        _ => unreachable!(),
-    }
-}
-
-#[no_mangle]
-pub unsafe extern "C" fn engine_library_notification_get_filestatus(
-    n: *const LibNotification,
-) -> FileStatus {
-    match n.as_ref() {
-        Some(&LibNotification::FileStatusChanged(ref s)) => s.status,
-        _ => unreachable!(),
-    }
-}
-
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_get_libmetadata(
     n: *const LibNotification,
@@ -273,16 +249,6 @@ pub unsafe extern "C" fn engine_library_notification_get_count(
     }
 }
 
-#[no_mangle]
-pub unsafe extern "C" fn engine_library_notification_get_metadatachange(
-    n: *const LibNotification,
-) -> *const MetadataChange {
-    match n.as_ref() {
-        Some(&LibNotification::MetadataChanged(ref c)) => c,
-        _ => unreachable!(),
-    }
-}
-
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_get_libfolder(
     n: *const LibNotification,
@@ -302,27 +268,3 @@ pub unsafe extern "C" fn engine_library_notification_get_keyword(
         _ => unreachable!(),
     }
 }
-
-#[no_mangle]
-pub unsafe extern "C" fn engine_library_notification_get_content(
-    n: *const LibNotification,
-) -> *const QueriedContent {
-    match n.as_ref() {
-        Some(&LibNotification::FolderContentQueried(ref c))
-        | Some(&LibNotification::KeywordContentQueried(ref c)) => c,
-        _ => unreachable!(),
-    }
-}
-
-#[no_mangle]
-pub unsafe extern "C" fn engine_library_notification_get_pixbuf(
-    n: *const LibNotification,
-) -> *mut gdk_pixbuf_sys::GdkPixbuf {
-    match n.as_ref() {
-        Some(&LibNotification::ThumbnailLoaded(ref thumbnail)) => {
-            let pixbuf: gdk_pixbuf::Pixbuf = thumbnail.pix.clone().into();
-            pixbuf.to_glib_full()
-        }
-        _ => unreachable!(),
-    }
-}
diff --git a/crates/npc-engine/src/library/queriedcontent.rs b/crates/npc-engine/src/library/queriedcontent.rs
index 6a84430..2bc3c24 100644
--- a/crates/npc-engine/src/library/queriedcontent.rs
+++ b/crates/npc-engine/src/library/queriedcontent.rs
@@ -23,8 +23,8 @@ use crate::db::LibraryId;
 /// Queried content to pass a list of LibFile and the id of the container.
 #[derive(Clone)]
 pub struct QueriedContent {
-    id: LibraryId,
-    content: Vec<LibFile>,
+    pub id: LibraryId,
+    pub content: Vec<LibFile>,
 }
 
 impl QueriedContent {
@@ -43,18 +43,3 @@ impl QueriedContent {
         &self.content
     }
 }
-
-#[no_mangle]
-pub extern "C" fn engine_queried_content_id(obj: &QueriedContent) -> LibraryId {
-    obj.id
-}
-
-#[no_mangle]
-pub extern "C" fn engine_queried_content_size(obj: &QueriedContent) -> u64 {
-    obj.content.len() as u64
-}
-
-#[no_mangle]
-pub extern "C" fn engine_queried_content_get(obj: &QueriedContent, idx: usize) -> *mut LibFile {
-    Box::into_raw(Box::new(obj.content[idx].clone()))
-}
diff --git a/crates/npc-fwk/src/toolkit/thumbnail.rs b/crates/npc-fwk/src/toolkit/thumbnail.rs
index 9b2a6af..91306cc 100644
--- a/crates/npc-fwk/src/toolkit/thumbnail.rs
+++ b/crates/npc-fwk/src/toolkit/thumbnail.rs
@@ -75,7 +75,7 @@ impl Thumbnail {
     }
 
     /// Make a gdk_pixbuf::Pixbuf out of the Thumbnail
-    fn make_pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
+    pub fn make_pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
         if self.ok() {
             // XXX figure out the allocation here.
             // Ideally we should have this shared
diff --git a/src/niepce/ui/image_list_store.rs b/src/niepce/ui/image_list_store.rs
index 2b612b8..8e64ae2 100644
--- a/src/niepce/ui/image_list_store.rs
+++ b/src/niepce/ui/image_list_store.rs
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+use std::collections::BTreeMap;
 use std::ptr;
 
 use gdk_pixbuf;
@@ -27,9 +28,15 @@ use gtk::prelude::*;
 use gtk::subclass::prelude::*;
 use gtk_sys;
 
+use once_cell::unsync::OnceCell;
+
 use npc_engine::db::libfile::{FileStatus, LibFile};
 use npc_engine::db::LibraryId;
-use npc_engine::library::notification::MetadataChange;
+use npc_engine::library::notification::{LibNotification, MetadataChange};
+use npc_engine::library::thumbnail_cache::ThumbnailCache;
+use npc_engine::root::eng;
+use npc_fwk::base::PropertyIndex;
+use npc_fwk::toolkit::gdk_utils;
 use npc_fwk::PropertyValue;
 
 /// Wrap a libfile into something that can be in a glib::Value
@@ -51,8 +58,14 @@ pub enum ColIndex {
     FileStatus = 3,
 }
 
+/// The Image list store.
+/// It wraps the tree model/store.
 pub struct ImageListStore {
     store: gtk::ListStore,
+    current_folder: LibraryId,
+    current_keyword: LibraryId,
+    idmap: BTreeMap<LibraryId, gtk::TreeIter>,
+    image_loading_icon: OnceCell<Option<gdk_pixbuf::Pixbuf>>,
 }
 
 impl ImageListStore {
@@ -66,7 +79,148 @@ impl ImageListStore {
 
         let store = gtk::ListStore::new(&col_types);
 
-        Self { store }
+        Self {
+            store,
+            current_folder: 0,
+            current_keyword: 0,
+            idmap: BTreeMap::new(),
+            image_loading_icon: OnceCell::new(),
+        }
+    }
+
+    fn get_loading_icon(&self) -> Option<&gdk_pixbuf::Pixbuf> {
+        self.image_loading_icon
+            .get_or_init(|| {
+                if let Some(theme) = gtk::IconTheme::get_default() {
+                    if let Ok(icon) =
+                        theme.load_icon("image-loading", 32, gtk::IconLookupFlags::USE_BUILTIN)
+                    {
+                        icon
+                    } else {
+                        None
+                    }
+                } else {
+                    None
+                }
+            })
+            .as_ref()
+    }
+
+    fn is_property_interesting(idx: PropertyIndex) -> bool {
+        return (idx == eng::NpXmpRatingProp)
+            || (idx == eng::NpXmpLabelProp)
+            || (idx == eng::NpTiffOrientationProp)
+            || (idx == eng::NpNiepceFlagProp);
+    }
+
+    fn get_iter_from_id(&self, id: LibraryId) -> Option<&gtk::TreeIter> {
+        self.idmap.get(&id)
+    }
+
+    fn clear_content(&mut self) {
+        // clear the map before the list.
+        self.idmap.clear();
+        self.store.clear();
+    }
+
+    fn add_libfile(&mut self, f: &LibFile) {
+        let icon = self.get_loading_icon().map(|v| v.clone());
+        let iter = self.add_row(
+            icon.clone().as_ref(),
+            f,
+            gdk_utils::gdkpixbuf_scale_to_fit(icon.as_ref(), 100).as_ref(),
+            FileStatus::Ok,
+        );
+        self.idmap.insert(f.id(), iter);
+    }
+
+    fn add_libfiles(&mut self, content: &Vec<LibFile>) {
+        for f in content.iter() {
+            self.add_libfile(f);
+        }
+    }
+
+    /// Process the notification.
+    /// Returns false if it hasn't been
+    pub fn on_lib_notification(
+        &mut self,
+        notification: &LibNotification,
+        thumbnail_cache: &ThumbnailCache,
+    ) -> bool {
+        use self::LibNotification::*;
+
+        match *notification {
+            FolderContentQueried(ref c) | KeywordContentQueried(ref c) => {
+                match *notification {
+                    FolderContentQueried(_) => {
+                        self.current_folder = c.id;
+                        self.current_keyword = 0;
+                    }
+                    KeywordContentQueried(_) => {
+                        self.current_folder = 0;
+                        self.current_keyword = c.id;
+                    }
+                    _ => {}
+                }
+                self.clear_content();
+                dbg_out!("received folder content file # {}", c.content.len());
+                self.add_libfiles(&c.content);
+                // request thumbnails c.content
+                thumbnail_cache.request(&c.content);
+                true
+            }
+            FileMoved(ref param) => {
+                dbg_out!("File moved. Current folder {}", self.current_folder);
+                if self.current_folder != 0 {
+                    if param.from == self.current_folder {
+                        // remove from list
+                        dbg_out!("from this folder");
+                        if let Some(iter) = self.get_iter_from_id(param.file) {
+                            self.store.remove(iter);
+                            self.idmap.remove(&param.file);
+                        }
+                    } else if param.to == self.current_folder {
+                        // XXX add to list. but this isn't likely to happen atm.
+                    }
+                }
+                true
+            }
+            FileStatusChanged(ref status) => {
+                if let Some(iter) = self.idmap.get(&status.id) {
+                    self.store.set_value(
+                        iter,
+                        ColIndex::FileStatus as u32,
+                        &(status.status as i32).to_value(),
+                    );
+                }
+                true
+            }
+            MetadataChanged(ref m) => {
+                dbg_out!("metadata changed {}", m.meta);
+                // only interested in a few props
+                if Self::is_property_interesting(m.meta) {
+                    if let Some(iter) = self.idmap.get(&m.id) {
+                        self.set_property(iter, m);
+                    }
+                }
+                true
+            }
+            ThumbnailLoaded(ref t) => {
+                if let Some(iter) = self.get_iter_from_id(t.id) {
+                    let pixbuf = t.pix.make_pixbuf();
+                    self.store.set(
+                        iter,
+                        &[ColIndex::Thumb as u32, ColIndex::StripThumb as u32],
+                        &[
+                            &pixbuf,
+                            &gdk_utils::gdkpixbuf_scale_to_fit(pixbuf.as_ref(), 100),
+                        ],
+                    );
+                }
+                true
+            }
+            _ => false,
+        }
     }
 
     pub fn get_file_id_at_path(&self, path: &gtk::TreePath) -> LibraryId {
@@ -82,22 +236,24 @@ impl ImageListStore {
         0
     }
 
-    pub fn get_file(&self, iter: &gtk::TreeIter) -> Option<LibFile> {
-        if let Ok(libfile) = self
-            .store
-            .get_value(&iter, ColIndex::File as i32)
-            .get_some::<&StoreLibFile>()
-        {
-            return Some(libfile.0.clone());
+    pub fn get_file(&self, id: LibraryId) -> Option<LibFile> {
+        if let Some(iter) = self.idmap.get(&id) {
+            if let Ok(libfile) = self
+                .store
+                .get_value(&iter, ColIndex::File as i32)
+                .get_some::<&StoreLibFile>()
+            {
+                return Some(libfile.0.clone());
+            }
         }
         None
     }
 
     pub fn add_row(
         &mut self,
-        thumb: &gdk_pixbuf::Pixbuf,
+        thumb: Option<&gdk_pixbuf::Pixbuf>,
         file: &LibFile,
-        strip_thumb: &gdk_pixbuf::Pixbuf,
+        strip_thumb: Option<&gdk_pixbuf::Pixbuf>,
         status: FileStatus,
     ) -> gtk::TreeIter {
         let iter = self.store.append();
@@ -108,26 +264,21 @@ impl ImageListStore {
             ColIndex::StripThumb as u32,
             ColIndex::FileStatus as u32,
         ];
-        assert!(thumb.ref_count() > 0);
-        assert!(strip_thumb.ref_count() > 0);
         self.store.set(
             &iter,
             &indices,
-            &[thumb, &store_libfile, strip_thumb, &(status as i32)],
+            &[&thumb, &store_libfile, &strip_thumb, &(status as i32)],
         );
         iter
     }
 
-    pub fn set_thumbnail(
-        &mut self,
-        iter: &gtk::TreeIter,
-        thumb: &gdk_pixbuf::Pixbuf,
-        strip_thumb: &gdk_pixbuf::Pixbuf,
-    ) {
-        let indices: [u32; 2] = [ColIndex::Thumb as u32, ColIndex::StripThumb as u32];
-        assert!(thumb.ref_count() > 0);
-        assert!(strip_thumb.ref_count() > 0);
-        self.store.set(iter, &indices, &[thumb, strip_thumb]);
+    pub fn set_thumbnail(&mut self, id: LibraryId, thumb: &gdk_pixbuf::Pixbuf) {
+        if let Some(iter) = self.idmap.get(&id) {
+            let strip_thumb = gdk_utils::gdkpixbuf_scale_to_fit(Some(thumb), 100);
+            let indices: [u32; 2] = [ColIndex::Thumb as u32, ColIndex::StripThumb as u32];
+            assert!(thumb.ref_count() > 0);
+            self.store.set(iter, &indices, &[thumb, &strip_thumb]);
+        }
     }
 
     pub fn set_property(&self, iter: &gtk::TreeIter, change: &MetadataChange) {
@@ -188,43 +339,28 @@ pub unsafe extern "C" fn npc_image_list_store_add_row(
     strip_thumb: *mut gdk_pixbuf_sys::GdkPixbuf,
     status: FileStatus,
 ) -> gtk_sys::GtkTreeIter {
-    assert!(!thumb.is_null());
-    assert!(!strip_thumb.is_null());
+    let thumb: Option<gdk_pixbuf::Pixbuf> = from_glib_none(thumb);
+    let strip_thumb: Option<gdk_pixbuf::Pixbuf> = from_glib_none(strip_thumb);
     *self_
-        .add_row(
-            &from_glib_borrow(thumb),
-            &*file,
-            &from_glib_borrow(strip_thumb),
-            status,
-        )
+        .add_row(thumb.as_ref(), &*file, strip_thumb.as_ref(), status)
         .to_glib_none()
         .0
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn npc_image_list_store_set_tnail(
+pub unsafe extern "C" fn npc_image_list_store_get_iter_from_id(
     self_: &mut ImageListStore,
-    iter: *mut gtk_sys::GtkTreeIter,
-    thumb: *mut gdk_pixbuf_sys::GdkPixbuf,
-    strip_thumb: *mut gdk_pixbuf_sys::GdkPixbuf,
-) {
-    assert!(!iter.is_null());
-    assert!(!thumb.is_null());
-    assert!(!strip_thumb.is_null());
-    self_.set_thumbnail(
-        &from_glib_borrow(iter),
-        &from_glib_borrow(thumb),
-        &from_glib_borrow(strip_thumb),
-    )
+    id: LibraryId,
+) -> *const gtk_sys::GtkTreeIter {
+    self_.idmap.get(&id).to_glib_none().0
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn npc_image_list_store_get_file(
     self_: &mut ImageListStore,
-    iter: *mut gtk_sys::GtkTreeIter,
+    id: LibraryId,
 ) -> *mut LibFile {
-    assert!(!iter.is_null());
-    if let Some(libfile) = self_.get_file(&from_glib_borrow(iter)) {
+    if let Some(libfile) = self_.get_file(id) {
         Box::into_raw(Box::new(libfile))
     } else {
         ptr::null_mut()
@@ -232,12 +368,15 @@ pub unsafe extern "C" fn npc_image_list_store_get_file(
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn npc_image_list_store_set_property(
+pub unsafe extern "C" fn npc_image_list_store_on_lib_notification(
     self_: &mut ImageListStore,
-    iter: *const gtk_sys::GtkTreeIter,
-    change: *const MetadataChange,
-) {
-    assert!(!iter.is_null());
-    assert!(!change.is_null());
-    self_.set_property(&from_glib_borrow(mut_override(iter)), &*change);
+    notification: &LibNotification,
+    thumbnail_cache: &ThumbnailCache,
+) -> bool {
+    self_.on_lib_notification(notification, thumbnail_cache)
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn npc_image_list_store_clear_content(self_: &mut ImageListStore) {
+    self_.clear_content()
 }
diff --git a/src/niepce/ui/imageliststore.cpp b/src/niepce/ui/imageliststore.cpp
index 678a8f6..bbfd421 100644
--- a/src/niepce/ui/imageliststore.cpp
+++ b/src/niepce/ui/imageliststore.cpp
@@ -17,44 +17,15 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <mutex>
-
-#include <gtkmm/icontheme.h>
-
 #include "imageliststore.hpp"
-#include "engine/db/properties.hpp"
 #include "fwk/base/debug.hpp"
 #include "fwk/toolkit/application.hpp"
-#include "fwk/toolkit/gdkutils.hpp"
 #include "niepcewindow.hpp"
 
 #include "rust_bindings.hpp"
 
 namespace ui {
 
-Glib::RefPtr<Gdk::Pixbuf> ImageListStore::get_loading_icon()
-{
-    static Glib::RefPtr<Gdk::Pixbuf> icon;
-    if (!icon) {
-        static std::mutex m;
-        m.lock();
-        if (!icon) {
-            auto icon_theme(fwk::Application::app()->getIconTheme());
-            try {
-                icon = icon_theme->load_icon(
-                    Glib::ustring("image-loading"), 32,
-                    Gtk::ICON_LOOKUP_USE_BUILTIN);
-            }
-            catch(const Gtk::IconThemeError & e)
-            {
-                ERR_OUT("Exception %s.", e.what().c_str());
-            }
-        }
-        m.unlock();
-    }
-    return icon;
-}
-
 ImageListStorePtr ImageListStore::create()
 {
     return std::make_shared<ImageListStore>(ffi::npc_image_list_store_new());
@@ -63,8 +34,6 @@ ImageListStorePtr ImageListStore::create()
 ImageListStore::ImageListStore(ffi::ImageListStore* store)
     : m_store(store)
     , m_store_wrap(Glib::wrap(GTK_LIST_STORE(ffi::npc_image_list_store_gobj(store)), true))
-    , m_current_folder(0)
-    , m_current_keyword(0)
 {
 }
 
@@ -76,18 +45,23 @@ ImageListStore::~ImageListStore()
 
 Gtk::TreeIter ImageListStore::get_iter_from_id(eng::library_id_t id) const
 {
-    auto iter = m_idmap.find(id);
-    if(iter != m_idmap.end()) {
-        return iter->second;
+    if (m_store == nullptr) {
+        return Gtk::TreeIter();
+    }
+    auto iter = ffi::npc_image_list_store_get_iter_from_id(m_store, id);
+    if (!iter) {
+        return Gtk::TreeIter();
     }
-    return Gtk::TreeIter();
+    return Gtk::TreeIter(GTK_TREE_MODEL(m_store_wrap->gobj()), iter);
 }
 
 Gtk::TreePath ImageListStore::get_path_from_id(eng::library_id_t id) const
 {
-    Gtk::TreeIter iter = get_iter_from_id(id);
-    if(iter) {
-        return m_store_wrap->get_path(iter);
+    if (m_store) {
+        Gtk::TreeIter iter = get_iter_from_id(id);
+        if (iter) {
+            return m_store_wrap->get_path(iter);
+        }
     }
     return Gtk::TreePath();
 }
@@ -99,107 +73,27 @@ eng::library_id_t ImageListStore::get_libfile_id_at_path(const Gtk::TreePath &pa
 
 eng::LibFilePtr ImageListStore::get_file(eng::library_id_t id) const
 {
-    auto iter = get_iter_from_id(id);
-    if (iter) {
-        auto f = ffi::npc_image_list_store_get_file(m_store, iter.gobj());
-        if (f) {
-            return eng::libfile_wrap(f);
-        }
+    auto f = ffi::npc_image_list_store_get_file(m_store, id);
+    if (f) {
+        return eng::libfile_wrap(f);
     }
     return eng::LibFilePtr();
 }
 
-void ImageListStore::add_libfile(const eng::LibFilePtr & f)
-{
-    Glib::RefPtr<Gdk::Pixbuf> icon = get_loading_icon();
-    DBG_ASSERT(static_cast<bool>(f), "f can't be null");
-    auto iter = ffi::npc_image_list_store_add_row(m_store,
-        icon->gobj(), f.get(), fwk::gdkpixbuf_scale_to_fit(icon, 100)->gobj(),
-        eng::FileStatus::Ok);
-
-    m_idmap[engine_db_libfile_id(f.get())] = Gtk::TreeIter(
-        GTK_TREE_MODEL(m_store_wrap->gobj()), &iter);
-}
-
 void ImageListStore::clear_content()
 {
-    // clear the map before the list.
-    m_idmap.clear();
-    m_store_wrap->clear();
+    ffi::npc_image_list_store_clear_content(m_store);
 }
 
 void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
 {
+    if (ffi::npc_image_list_store_on_lib_notification(
+            m_store, &ln, getLibraryClient()->thumbnailCache())) {
+        return;
+    }
+
     auto type = engine_library_notification_type(&ln);
     switch (type) {
-    case eng::NotificationType::FOLDER_CONTENT_QUERIED:
-    case eng::NotificationType::KEYWORD_CONTENT_QUERIED:
-    {
-        auto content = ffi::engine_library_notification_get_content(&ln);
-        if (type == eng::NotificationType::FOLDER_CONTENT_QUERIED) {
-            m_current_folder = ffi::engine_queried_content_id(content);
-            m_current_keyword = 0;
-        } else if (type == eng::NotificationType::KEYWORD_CONTENT_QUERIED) {
-            m_current_folder = 0;
-            m_current_keyword = ffi::engine_queried_content_id(content);
-        }
-        clear_content();
-        DBG_OUT("received folder content file # %lu", engine_queried_content_size(content));
-        eng::LibFileListPtr l(new eng::LibFileList);
-        for (uint64_t i = 0; i < engine_queried_content_size(content); i++) {
-            auto f = eng::libfile_wrap(engine_queried_content_get(content, i));
-            add_libfile(f);
-            l->push_back(f);
-        }
-        // at that point clear the cache because the icon view is populated.
-        ffi::engine_library_thumbnail_cache_request(getLibraryClient()->thumbnailCache(), content);
-        break;
-    }
-    case eng::NotificationType::FILE_MOVED:
-    {
-        DBG_OUT("File moved. Current folder %ld", m_current_folder);
-        auto param = engine_library_notification_get_filemoved(&ln);
-        if (m_current_folder == 0) {
-            return;
-        }
-        if (param->from == m_current_folder) {
-            // remove from list
-            DBG_OUT("from this folder");
-            auto iter = get_iter_from_id(param->file);
-            if (iter) {
-                iter = m_store_wrap->erase(iter);
-            }
-        } else if (param->to == m_current_folder) {
-            // XXX add to list. but this isn't likely to happen atm.
-        }
-        break;
-    }
-    case eng::NotificationType::FILE_STATUS_CHANGED:
-    {
-        auto status = engine_library_notification_get_filestatus(&ln);
-        auto id = engine_library_notification_get_id(&ln);
-        auto iter = m_idmap.find(id);
-        if (iter != m_idmap.end()) {
-            Gtk::TreeRow row = *(iter->second);
-            row[m_columns.m_file_status] = static_cast<gint>(status);
-        }
-        break;
-    }
-    case eng::NotificationType::METADATA_CHANGED:
-    {
-        auto m = engine_library_notification_get_metadatachange(&ln);
-        const fwk::PropertyIndex& prop = ffi::metadatachange_get_meta(m);
-        DBG_OUT("metadata changed %s", eng::_propertyName(prop));
-        // only interested in a few props
-        if(is_property_interesting(prop)) {
-            std::map<eng::library_id_t, Gtk::TreeIter>::const_iterator iter =
-                m_idmap.find(ffi::metadatachange_get_id(m));
-            if (iter != m_idmap.end()) {
-                ffi::npc_image_list_store_set_property(m_store, iter->second.gobj(), m);
-            }
-        }
-        break;
-    }
     case eng::NotificationType::XMP_NEEDS_UPDATE:
     {
         fwk::Configuration & cfg = fwk::Application::app()->config();
@@ -217,23 +111,6 @@ void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
         ffi::libraryclient_process_xmp_update_queue(getLibraryClient()->client(), write_xmp);
         break;
     }
-    case eng::NotificationType::ThumbnailLoaded:
-    {
-        auto id = engine_library_notification_get_id(&ln);
-        auto iter = m_idmap.find(id);
-        if(iter != m_idmap.end()) {
-            // found the icon view item
-            auto pixbuf = engine_library_notification_get_pixbuf(&ln);
-            // About the ownership:
-            // The Glib::wrap below will claim it.
-            ffi::npc_image_list_store_set_tnail(
-                m_store, iter->second.gobj(), pixbuf,
-                fwk::gdkpixbuf_scale_to_fit(Glib::wrap(pixbuf), 100)->gobj());
-        }
-        else {
-            DBG_OUT("row %Ld not found", (long long)id);
-        }
-    }
     default:
         break;
     }
@@ -246,13 +123,6 @@ libraryclient::LibraryClientPtr ImageListStore::getLibraryClient()
     return shell->getLibraryClient();
 }
 
-
-bool ImageListStore::is_property_interesting(fwk::PropertyIndex idx)
-{
-    return (idx == eng::NpXmpRatingProp) || (idx == eng::NpXmpLabelProp)
-        || (idx == eng::NpTiffOrientationProp) || (idx == eng::NpNiepceFlagProp);
-}
-
 }
 
 
diff --git a/src/niepce/ui/imageliststore.hpp b/src/niepce/ui/imageliststore.hpp
index 1c51b87..6d0bd91 100644
--- a/src/niepce/ui/imageliststore.hpp
+++ b/src/niepce/ui/imageliststore.hpp
@@ -19,7 +19,6 @@
 
 #pragma once
 
-#include <gdkmm/pixbuf.h>
 #include <gtkmm/liststore.h>
 
 #include "fwk/base/propertybag.hpp"
@@ -37,23 +36,6 @@ typedef std::shared_ptr<ImageListStore> ImageListStorePtr;
 class ImageListStore
 {
 public:
-    class Columns
-        : public Gtk::TreeModelColumnRecord
-    {
-    public:
-        Columns()
-            {
-                add(m_pix);
-                add(m_libfile_do_not_use);
-                add(m_strip_thumb);
-                add(m_file_status);
-            }
-        Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > m_pix;
-        Gtk::TreeModelColumn<eng::LibFilePtr> m_libfile_do_not_use;
-        Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > m_strip_thumb;
-        Gtk::TreeModelColumn<gint> m_file_status;
-    };
-
     ImageListStore(ffi::ImageListStore*);
     ~ImageListStore();
     Glib::RefPtr<Gtk::ListStore> gobjmm() const
@@ -75,19 +57,10 @@ public:
     void on_lib_notification(const eng::LibNotification &n);
 
 private:
-    /// Add the LibFile to the model
-    void add_libfile(const eng::LibFilePtr & f);
-
-    static Glib::RefPtr<Gdk::Pixbuf> get_loading_icon();
     libraryclient::LibraryClientPtr getLibraryClient();
-    static bool is_property_interesting(fwk::PropertyIndex idx);
 
-    Columns m_columns;
     ffi::ImageListStore* m_store;
     Glib::RefPtr<Gtk::ListStore> m_store_wrap;
-    eng::library_id_t m_current_folder;
-    eng::library_id_t m_current_keyword;
-    std::map<eng::library_id_t, Gtk::TreeIter> m_idmap;
     fwk::Controller::WeakPtr m_controller;
 };
 


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