[niepce] Change some ids to the real type Store the trash folder id in the library client state Use the trash



commit 6585507035ffa933711b445b1e813d0cc1e7f567
Author: Hub Figuiere <hub figuiere net>
Date:   Wed Nov 16 22:28:57 2011 -0800

    Change some ids to the real type
    Store the trash folder id in the library client state
    Use the trash folder id from the library client

 src/libraryclient/libraryclient.cpp   |    1 +
 src/libraryclient/libraryclient.hpp   |  138 ++++++++++++++-----------
 src/niepce/ui/selectioncontroller.cpp |    2 +-
 src/niepce/ui/workspacecontroller.cpp |    9 +-
 src/niepce/ui/workspacecontroller.hpp |  182 +++++++++++++++++----------------
 5 files changed, 181 insertions(+), 151 deletions(-)
---
diff --git a/src/libraryclient/libraryclient.cpp b/src/libraryclient/libraryclient.cpp
index 54f6a71..3ba0c40 100644
--- a/src/libraryclient/libraryclient.cpp
+++ b/src/libraryclient/libraryclient.cpp
@@ -36,6 +36,7 @@ LibraryClient::LibraryClient(const fwk::Moniker & moniker,
     : m_pImpl(ClientImpl::makeClientImpl(moniker, nc))
     , m_thumbnailCache(moniker.path() + "/" + s_thumbcacheDirname, nc)
     , m_uidataprovider(new UIDataProvider())
+    , m_trash_id(0)
 {
 }
 
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index f33dd3a..01f9dc1 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -30,79 +30,99 @@
 #include "engine/db/storage.hpp"
 
 namespace fwk {
-	class Moniker;
-	class NotificationCenter;
+class Moniker;
+class NotificationCenter;
 }
 
 namespace libraryclient {
 
-  class UIDataProvider;
-
-  class ClientImpl;
-
-	class LibraryClient
-		: public eng::Storage
-	{
-	public:
-		typedef std::tr1::shared_ptr< LibraryClient > Ptr;
-
-		LibraryClient(const fwk::Moniker & moniker, const fwk::NotificationCenter::Ptr & nc);
-		virtual ~LibraryClient();
-
-		static eng::tid_t newTid();
-		/** get all the keywords 
-		 * @return transaction ID
-		 */
-		eng::tid_t getAllKeywords();
-		/** get all the folder
-		 * @return transaction ID
-		 */
-		eng::tid_t getAllFolders();
-
-		eng::tid_t queryFolderContent(eng::library_id_t id);
-		eng::tid_t queryKeywordContent(eng::library_id_t id);
-		eng::tid_t countFolder(eng::library_id_t id);
-		eng::tid_t requestMetadata(eng::library_id_t id);
-
+class UIDataProvider;
+
+class ClientImpl;
+
+class LibraryClient
+    : public eng::Storage
+{
+public:
+    typedef std::tr1::shared_ptr< LibraryClient > Ptr;
+    
+    LibraryClient(const fwk::Moniker & moniker, const fwk::NotificationCenter::Ptr & nc);
+    virtual ~LibraryClient();
+    
+    static eng::tid_t newTid();
+    /** get all the keywords 
+     * @return transaction ID
+     */
+    eng::tid_t getAllKeywords();
+    /** get all the folder
+     * @return transaction ID
+     */
+    eng::tid_t getAllFolders();
+    
+    eng::tid_t queryFolderContent(eng::library_id_t id);
+    eng::tid_t queryKeywordContent(eng::library_id_t id);
+    eng::tid_t countFolder(eng::library_id_t id);
+    eng::tid_t requestMetadata(eng::library_id_t id);
+    
     /** set the metadata */
-	  eng::tid_t setMetadata(eng::library_id_t id, fwk::PropertyIndex meta, const fwk::PropertyValue & value);
-	  eng::tid_t moveFileToFolder(eng::library_id_t file_id, eng::library_id_t from_folder,
-				      eng::library_id_t to_folder);
-
+    eng::tid_t setMetadata(eng::library_id_t id, fwk::PropertyIndex meta, const fwk::PropertyValue & value);
+    eng::tid_t moveFileToFolder(eng::library_id_t file_id, eng::library_id_t from_folder,
+                                eng::library_id_t to_folder);
+    
     /** get all the labels */
     eng::tid_t getAllLabels();
     eng::tid_t createLabel(const std::string & s, const std::string & color);
     eng::tid_t deleteLabel(int id);
     /** update a label */
     eng::tid_t updateLabel(eng::library_id_t id, const std::string & new_name, 
-                               const std::string & new_color);
-
+                           const std::string & new_color);
+    
     /** tell to process the Xmp update Queue */
     eng::tid_t processXmpUpdateQueue();
-
-		/** Import files from a directory
-		 * @param dir the directory
-		 * @param manage true if imports have to be managed
-		 */
-		void importFromDirectory(const std::string & dir, bool manage);
-		
-		eng::ThumbnailCache & thumbnailCache()
-			{ return m_thumbnailCache; }
-
-		/* 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;
-	  UIDataProvider *m_uidataprovider;
-	  
-	  LibraryClient(const LibraryClient &);
-	  LibraryClient & operator=(const LibraryClient &);
-	};
+    
+    /** Import files from a directory
+     * @param dir the directory
+     * @param manage true if imports have to be managed
+     */
+    void importFromDirectory(const std::string & dir, bool manage);
+    
+    eng::ThumbnailCache & thumbnailCache()
+        { return m_thumbnailCache; }
+    
+    /* sync call */
+    virtual bool fetchKeywordsForFile(int file, eng::Keyword::IdList &keywords);
+    UIDataProvider *getDataProvider() const
+        { return m_uidataprovider; }
+    
+    // state
+    eng::library_id_t trash_id() const
+        {
+	    return m_trash_id;
+        }
+    void set_trash_id(eng::library_id_t id) 
+        {
+	    m_trash_id = id;
+        }
+private:
+    ClientImpl* m_pImpl;
+    
+    eng::ThumbnailCache                    m_thumbnailCache;
+    UIDataProvider *m_uidataprovider;
+    eng::library_id_t m_trash_id;
+    
+    LibraryClient(const LibraryClient &);
+    LibraryClient & operator=(const LibraryClient &);
+};
 
 }
 
 #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 5b638ff..79a2709 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -280,7 +280,7 @@ void SelectionController::set_properties(const fwk::PropertyBag & props,
 
 void SelectionController::move_to_trash()
 {
-    eng::library_id_t trash_folder = 1; // FIXME get the actual ID.
+    eng::library_id_t trash_folder = getLibraryClient()->trash_id();
     eng::library_id_t selection = get_selection();
     if(selection >= 0) {
         Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index c18a033..aa76bd3 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -111,7 +111,7 @@ void WorkspaceController::on_lib_notification(const eng::LibNotification &ln)
     {
         std::pair<eng::library_id_t,int> count(boost::any_cast<std::pair<eng::library_id_t,int> >(ln.param));
         DBG_OUT("count for folder %Ld is %d", count.first, count.second);
-        std::map<int, Gtk::TreeIter>::iterator iter
+        std::map<eng::library_id_t, Gtk::TreeIter>::iterator iter
             = m_folderidmap.find( count.first );
         if(iter != m_folderidmap.end()) {
             Gtk::TreeRow row = *(iter->second);
@@ -125,7 +125,7 @@ void WorkspaceController::on_lib_notification(const eng::LibNotification &ln)
     {
         std::pair<eng::library_id_t,int> count(boost::any_cast<std::pair<eng::library_id_t,int> >(ln.param));
         DBG_OUT("count change for folder %Ld is %d", count.first, count.second);
-        std::map<int, Gtk::TreeIter>::iterator iter
+        std::map<eng::library_id_t, Gtk::TreeIter>::iterator iter
             = m_folderidmap.find( count.first );
         if(iter != m_folderidmap.end()) {
             Gtk::TreeRow row = *(iter->second);
@@ -163,12 +163,12 @@ void WorkspaceController::on_libtree_selection()
     Gtk::TreeModel::iterator selected = selection->get_selected();
     if((*selected)[m_librarycolumns.m_type] == FOLDER_ITEM)
     {
-        int id = (*selected)[m_librarycolumns.m_id];
+        eng::library_id_t id = (*selected)[m_librarycolumns.m_id];
         getLibraryClient()->queryFolderContent(id);
     }
     else if((*selected)[m_librarycolumns.m_type] == KEYWORD_ITEM)
     {
-        int id = (*selected)[m_librarycolumns.m_id];
+        eng::library_id_t id = (*selected)[m_librarycolumns.m_id];
         getLibraryClient()->queryKeywordContent(id);			
     }
     else 
@@ -191,6 +191,7 @@ void WorkspaceController::add_folder_item(const eng::LibFolder::Ptr & f)
     int icon_idx = ICON_ROLL;
     if(f->virtual_type() == eng::LibFolder::VIRTUAL_TRASH) {
         icon_idx = ICON_TRASH;
+        getLibraryClient()->set_trash_id(f->id());
     }
     Gtk::TreeModel::iterator iter(add_item(m_treestore, 
                                            m_folderNode->children(), 
diff --git a/src/niepce/ui/workspacecontroller.hpp b/src/niepce/ui/workspacecontroller.hpp
index 08879e4..8c0cbcb 100644
--- a/src/niepce/ui/workspacecontroller.hpp
+++ b/src/niepce/ui/workspacecontroller.hpp
@@ -40,95 +40,103 @@ namespace Gtk {
 
 namespace ui {
 
-	class WorkspaceController
-		: public fwk::UiController
-	{
-	public:
-		typedef std::tr1::shared_ptr<WorkspaceController> Ptr;
-
-		enum {
-			FOLDERS_ITEM,
-			PROJECTS_ITEM,
-			KEYWORDS_ITEM,
-			FOLDER_ITEM,
-			PROJECT_ITEM,
-			KEYWORD_ITEM
-		};
-
-		WorkspaceController();
-		class WorkspaceTreeColumns 
-			: public Gtk::TreeModelColumnRecord
-		{
-		public:
-			
-			WorkspaceTreeColumns()
-				{ 
-					add(m_icon);
-					add(m_id);
-					add(m_label);  
-					add(m_type);
-					add(m_count);
-					add(m_count_n);
-				}
-			Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > m_icon;
-			Gtk::TreeModelColumn<int> m_id;
-			Gtk::TreeModelColumn<Glib::ustring> m_label;
-			Gtk::TreeModelColumn<int> m_type;
-			Gtk::TreeModelColumn<Glib::ustring> m_count;
-			Gtk::TreeModelColumn<int> m_count_n;
-		};
-
-		virtual void on_ready();
-
-		void on_lib_notification(const eng::LibNotification &);
-		void on_count_notification(int);
-		void on_libtree_selection();
-
-		virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> &);
-
-	private:
-		libraryclient::LibraryClient::Ptr getLibraryClient();
-
-		/** add a folder item to the treeview */
-		void add_folder_item(const eng::LibFolder::Ptr & f);
-		/** add a keyword item to the treeview */
-		void add_keyword_item(const eng::Keyword::Ptr & k);
-		/** add a tree item in the treeview 
-		 * @param treestore the treestore to add to
-		 * @param childrens the children subtree to add to
-		 * @param icon the icon for the item
-		 * @param label the item label
-		 * @param id the item id (in the database)
-		 * @paran type the type of node
-		 */
-		Gtk::TreeModel::iterator add_item(const Glib::RefPtr<Gtk::TreeStore> & treestore, 
-										  const Gtk::TreeNodeChildren & childrens,
-										  const Glib::RefPtr<Gdk::Pixbuf> & icon,
-										  const Glib::ustring & label, 
-										  eng::library_id_t id, int type) const;
-		enum {
-			ICON_FOLDER = 0,
-			ICON_PROJECT,
-			ICON_ROLL,
-			ICON_TRASH,
-			ICON_KEYWORD,
-			_ICON_SIZE
-		};
-		std::tr1::array< Glib::RefPtr<Gdk::Pixbuf>, _ICON_SIZE > m_icons;
-		WorkspaceTreeColumns           m_librarycolumns;
-		Gtk::VBox                      m_vbox;
-		Gtk::Label                     m_label;
-		Gtk::TreeView                  m_librarytree;
-		Gtk::TreeModel::iterator       m_folderNode;  /**< the folder node */
-		Gtk::TreeModel::iterator       m_projectNode; /**< the project node */
-		Gtk::TreeModel::iterator       m_keywordsNode; /**< the keywords node */
-		Glib::RefPtr<Gtk::TreeStore>   m_treestore;   /**< the treestore */
-		std::map<int, Gtk::TreeIter>   m_folderidmap;
-		std::map<int, Gtk::TreeIter>   m_projectidmap;
-		std::map<int, Gtk::TreeIter>   m_keywordsidmap;
-	};
+class WorkspaceController
+    : public fwk::UiController
+{
+public:
+    typedef std::tr1::shared_ptr<WorkspaceController> Ptr;
+    
+    enum {
+        FOLDERS_ITEM,
+        PROJECTS_ITEM,
+        KEYWORDS_ITEM,
+        FOLDER_ITEM,
+        PROJECT_ITEM,
+        KEYWORD_ITEM
+    };
+    
+    WorkspaceController();
+    class WorkspaceTreeColumns 
+        : public Gtk::TreeModelColumnRecord
+    {
+    public:
+        
+        WorkspaceTreeColumns()
+            { 
+                add(m_icon);
+                add(m_id);
+                add(m_label);  
+                add(m_type);
+                add(m_count);
+                add(m_count_n);
+            }
+        Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > m_icon;
+        Gtk::TreeModelColumn<eng::library_id_t> m_id;
+        Gtk::TreeModelColumn<Glib::ustring> m_label;
+        Gtk::TreeModelColumn<int> m_type;
+        Gtk::TreeModelColumn<Glib::ustring> m_count;
+        Gtk::TreeModelColumn<int> m_count_n;
+    };
+    
+    virtual void on_ready();
+    
+    void on_lib_notification(const eng::LibNotification &);
+    void on_count_notification(int);
+    void on_libtree_selection();
+    
+    virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> &);
+private:
+    libraryclient::LibraryClient::Ptr getLibraryClient();
+    
+    /** add a folder item to the treeview */
+    void add_folder_item(const eng::LibFolder::Ptr & f);
+    /** add a keyword item to the treeview */
+    void add_keyword_item(const eng::Keyword::Ptr & k);
+    /** add a tree item in the treeview 
+     * @param treestore the treestore to add to
+     * @param childrens the children subtree to add to
+     * @param icon the icon for the item
+     * @param label the item label
+     * @param id the item id (in the database)
+     * @paran type the type of node
+     */
+    Gtk::TreeModel::iterator add_item(const Glib::RefPtr<Gtk::TreeStore> & treestore, 
+                                      const Gtk::TreeNodeChildren & childrens,
+                                      const Glib::RefPtr<Gdk::Pixbuf> & icon,
+                                      const Glib::ustring & label, 
+                                      eng::library_id_t id, int type) const;
+    enum {
+        ICON_FOLDER = 0,
+        ICON_PROJECT,
+        ICON_ROLL,
+        ICON_TRASH,
+        ICON_KEYWORD,
+        _ICON_SIZE
+    };
+    std::tr1::array< Glib::RefPtr<Gdk::Pixbuf>, _ICON_SIZE > m_icons;
+    WorkspaceTreeColumns           m_librarycolumns;
+    Gtk::VBox                      m_vbox;
+    Gtk::Label                     m_label;
+    Gtk::TreeView                  m_librarytree;
+    Gtk::TreeModel::iterator       m_folderNode;  /**< the folder node */
+    Gtk::TreeModel::iterator       m_projectNode; /**< the project node */
+    Gtk::TreeModel::iterator       m_keywordsNode; /**< the keywords node */
+    Glib::RefPtr<Gtk::TreeStore>   m_treestore;   /**< the treestore */
+    std::map<eng::library_id_t, Gtk::TreeIter>   m_folderidmap;
+    std::map<eng::library_id_t, Gtk::TreeIter>   m_projectidmap;
+    std::map<eng::library_id_t, Gtk::TreeIter>   m_keywordsidmap;
+};
 
 
 }
 
 #endif
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0))
+  indent-tabs-mode:nil
+  fill-column:80
+  End:
+*/



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