[niepce] library: properly update the view when deleting an image (move to trash)



commit e5b203814a096d54f4b0865d75e5e9e5c5b32e96
Author: Hubert Figuière <hub figuiere net>
Date:   Wed May 31 22:09:05 2017 -0400

    library: properly update the view when deleting an image (move to trash)
    
    - also remove warning cause by not needed notification handling.

 src/niepce/ui/gridviewmodule.cpp      |    7 ------
 src/niepce/ui/imageliststore.cpp      |   36 +++++++++++++++++++++++++++++---
 src/niepce/ui/imageliststore.hpp      |    2 +
 src/niepce/ui/workspacecontroller.cpp |    6 -----
 4 files changed, 34 insertions(+), 17 deletions(-)
---
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index df1643a..009284d 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -72,13 +72,6 @@ GridViewModule::on_lib_notification(const eng::LibNotification &ln)
         }
         break;
     }
-    case eng::LibNotification::Type::FILE_MOVED:
-    {
-        auto moved = ln.get<eng::LibNotification::Type::FILE_MOVED>();
-// XXX check that the file that was moved still match the content
-
-        break;
-    }
     default:
         break;
     }
diff --git a/src/niepce/ui/imageliststore.cpp b/src/niepce/ui/imageliststore.cpp
index de449a4..c5c1c28 100644
--- a/src/niepce/ui/imageliststore.cpp
+++ b/src/niepce/ui/imageliststore.cpp
@@ -61,8 +61,10 @@ Glib::RefPtr<ImageListStore> ImageListStore::create()
 }
 
 ImageListStore::ImageListStore(const Columns& _columns)
-    : Gtk::ListStore(_columns),
-      m_columns(_columns)
+    : Gtk::ListStore(_columns)
+    , m_columns(_columns)
+    , m_current_folder(0)
+    , m_current_keyword(0)
 {
 }
 
@@ -88,11 +90,19 @@ Gtk::TreePath ImageListStore::get_path_from_id(eng::library_id_t id)
 
 void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
 {
-    switch(ln.type) {
+    switch (ln.type) {
     case eng::LibNotification::Type::FOLDER_CONTENT_QUERIED:
     case eng::LibNotification::Type::KEYWORD_CONTENT_QUERIED:
     {
-        auto l = ln.get<eng::LibNotification::Type::FOLDER_CONTENT_QUERIED>().files;
+        auto param = ln.get<eng::LibNotification::Type::FOLDER_CONTENT_QUERIED>();
+        auto l = param.files;
+        if (ln.type == eng::LibNotification::Type::FOLDER_CONTENT_QUERIED) {
+            m_current_folder = param.container;
+            m_current_keyword = 0;
+        } else if (ln.type == eng::LibNotification::Type::KEYWORD_CONTENT_QUERIED) {
+            m_current_folder = 0;
+            m_current_keyword = param.container;
+        }
         DBG_OUT("received folder content file # %lu", l->size());
         // clear the map before the list.
         m_idmap.clear();
@@ -113,6 +123,24 @@ void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
         getLibraryClient()->thumbnailCache().request(l);
         break;
     }
+    case eng::LibNotification::Type::FILE_MOVED:
+    {
+        DBG_OUT("File moved. Current folder %ld", m_current_folder);
+        auto param = ln.get<eng::LibNotification::Type::FILE_MOVED>();
+        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 = erase(iter);
+            }
+        } else if (param.to == m_current_folder) {
+            // XXX add to list. but this isn't likely to happen atm.
+        }
+    }
     case eng::LibNotification::Type::METADATA_CHANGED:
     {
         auto m = ln.get<eng::LibNotification::Type::METADATA_CHANGED>();
diff --git a/src/niepce/ui/imageliststore.hpp b/src/niepce/ui/imageliststore.hpp
index 6cc4be7..45c8984 100644
--- a/src/niepce/ui/imageliststore.hpp
+++ b/src/niepce/ui/imageliststore.hpp
@@ -81,6 +81,8 @@ private:
     static bool is_property_interesting(fwk::PropertyIndex idx);
 
     const Columns           & m_columns;
+    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;
 };
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index f3aef8f..d07a5d1 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -140,12 +140,6 @@ void WorkspaceController::on_lib_notification(const eng::LibNotification &ln)
 
         break;
     }
-    case eng::LibNotification::Type::FILE_MOVED:
-    {
-        auto moved = ln.get<eng::LibNotification::Type::FILE_MOVED>();
-
-        break;
-    }
     default:
         break;
     }


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