[niepce] Implement virtual folders Create a Trash Folder Show the trash icon in the workspace. Split the LibF



commit 25fca1d17a1ea0ef5af5560b9619f3ac7ee9767d
Author: Hub Figuiere <hub figuiere net>
Date:   Fri Oct 28 23:02:32 2011 -0700

    Implement virtual folders
    Create a Trash Folder
    Show the trash icon in the workspace.
    Split the LibFolder database persistance out of the library

 doc/database.txt                      |    3 +
 src/engine/db/Makefile.am             |    2 +-
 src/engine/db/libfolder.cpp           |   44 +++++++++++++++++++
 src/engine/db/libfolder.hpp           |   76 ++++++++++++++++++++++++---------
 src/engine/db/library.cpp             |   34 ++++++++------
 src/engine/db/library.hpp             |    2 +-
 src/niepce/ui/workspacecontroller.cpp |   18 ++++++--
 src/niepce/ui/workspacecontroller.hpp |    1 +
 8 files changed, 138 insertions(+), 42 deletions(-)
---
diff --git a/doc/database.txt b/doc/database.txt
index 5fa3ccc..ab54955 100644
--- a/doc/database.txt
+++ b/doc/database.txt
@@ -43,6 +43,9 @@ folders         id             Unique ID in the database
 		path           The absolute path of the folder
 		name 	       The display name
 		vault_id       The vault ID (unused) 0 = no vault (= vaults.id)
+		locked         Can't be deleted if non 0. For special folders.
+		virtual        Type of virtual item. 0 = regular. 
+                               See libfolder.hpp
 		parent_id      The ID of the parent (= folders.id). 0 = top level
 
 Keywords are defined in on table, and linked to files in the other
diff --git a/src/engine/db/Makefile.am b/src/engine/db/Makefile.am
index 5c28029..21ae897 100644
--- a/src/engine/db/Makefile.am
+++ b/src/engine/db/Makefile.am
@@ -28,7 +28,7 @@ noinst_LIBRARIES = libniepcedb.a
 
 libniepcedb_a_SOURCES = library.hpp library.cpp \
 	libfile.hpp libfile.cpp \
-	libfolder.hpp \
+	libfolder.hpp libfolder.cpp \
 	label.hpp \
 	libmetadata.hpp libmetadata.cpp \
 	keyword.hpp keyword.cpp \
diff --git a/src/engine/db/libfolder.cpp b/src/engine/db/libfolder.cpp
new file mode 100644
index 0000000..9ed78c2
--- /dev/null
+++ b/src/engine/db/libfolder.cpp
@@ -0,0 +1,44 @@
+/*
+ * niepce - eng/db/libfolder.cpp
+ *
+ * Copyright (C) 2011 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
+ * 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 "libfolder.hpp"
+
+namespace eng {
+
+const char* LibFolder::read_db_columns()
+{
+  return "id,name,virtual,locked";
+}
+
+LibFolder::Ptr LibFolder::read_from(const db::IConnectionDriver::Ptr & db)
+{
+  int32_t id;
+  std::string name;
+  int32_t virt_type, locked;
+  db->get_column_content(0, id);
+  db->get_column_content(1, name);
+  db->get_column_content(2, virt_type);
+  db->get_column_content(3, locked);
+  LibFolder::Ptr f(new LibFolder(id, name));
+  f->set_virtual_type((VirtualType)virt_type);
+  f->set_is_locked(locked);
+  return f;
+}
+
+}
diff --git a/src/engine/db/libfolder.hpp b/src/engine/db/libfolder.hpp
index c4ce9b8..9ae1886 100644
--- a/src/engine/db/libfolder.hpp
+++ b/src/engine/db/libfolder.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - eng/db/libfolder.hpp
  *
- * Copyright (C) 2007 Hubert Figuiere
+ * Copyright (C) 2007, 2011 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
@@ -26,27 +26,63 @@
 #include <list>
 #include <tr1/memory>
 
+#include "fwk/utils/db/iconnectiondriver.hpp"
+
 namespace eng {
 
-	class LibFolder
-	{
-	public:
-		typedef std::tr1::shared_ptr< LibFolder > Ptr;
-		typedef std::list< Ptr > List;
-		typedef std::tr1::shared_ptr< List > ListPtr;
-
-		LibFolder(int _id, std::string _name)
-			: m_id(_id), m_name(_name)
-			{
-			}
-		int id() const
-			{ return m_id; }
-		const std::string & name() const
-			{ return m_name; }
-	private:
-		int         m_id;
-		std::string m_name;
-	};
+class LibFolder
+{
+public:
+    typedef std::tr1::shared_ptr< LibFolder > Ptr;
+    typedef std::list< Ptr > List;
+    typedef std::tr1::shared_ptr< List > ListPtr;
+    typedef enum {
+        VIRTUAL_NONE = 0,
+        VIRTUAL_TRASH = 1,
+
+        _VIRTUAL_LAST
+    } VirtualType;
+
+    LibFolder(int _id, std::string _name)
+        : m_id(_id), m_name(_name)
+        , m_locked(false)
+        , m_virtual(VIRTUAL_NONE)
+        {
+        }
+    int id() const
+        { return m_id; }
+    const std::string & name() const
+        { return m_name; }
+
+    bool is_locked() const
+        { return m_locked; }
+    void set_is_locked(bool _locked)
+        { m_locked = _locked; }
+    VirtualType virtual_type() const
+        { return m_virtual; }
+    void set_virtual_type(VirtualType _virtual)
+        { m_virtual = _virtual; }
+
+    /** database persistance */
+    static const char * read_db_columns();
+    static Ptr read_from(const db::IConnectionDriver::Ptr & db);
+private:
+    int         m_id;
+    std::string m_name;
+    bool m_locked;
+    VirtualType m_virtual;
+};
+
 }
 
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0))
+  indent-tabs-mode:nil
+  fill-column:80
+  End:
+*/
+
 #endif
diff --git a/src/engine/db/library.cpp b/src/engine/db/library.cpp
index b62dc89..ee17475 100644
--- a/src/engine/db/library.cpp
+++ b/src/engine/db/library.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - engine/db/library.cpp
  *
- * Copyright (C) 2007-2009 Hubert Figuiere
+ * Copyright (C) 2007-2009,2011 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
@@ -25,6 +25,8 @@
 #include <boost/format.hpp>
 #include <boost/bind.hpp>
 
+#include <glibmm/i18n.h>
+
 #include "fwk/base/color.hpp"
 #include "niepce/notifications.hpp"
 #include "library.hpp"
@@ -125,7 +127,14 @@ bool Library::_initDb()
                             " path TEXT)");
     SQLStatement folderTable("CREATE TABLE folders (id INTEGER PRIMARY KEY,"
                              " path TEXT, name TEXT, vault_id INTEGER, "
+                             " locked INTEGER, virtual INTEGER,"
                              " parent_id INTEGER)");
+
+    SQLStatement initialFolders(
+        boost::format("insert into folders (name, locked, virtual, parent_id) "
+                      " values ('%1%', 1, %2%, 0)") 
+        % _("Trash") 
+        % int(LibFolder::VIRTUAL_TRASH));
     SQLStatement fileTable("CREATE TABLE files (id INTEGER PRIMARY KEY,"
                            " main_file INTEGER, name TEXT, parent_id INTEGER,"
                            " orientation INTEGER, file_type INTEGER, "
@@ -164,6 +173,7 @@ bool Library::_initDb()
     m_dbdrv->execute_statement(adminVersion);
     m_dbdrv->execute_statement(vaultTable);
     m_dbdrv->execute_statement(folderTable);
+    m_dbdrv->execute_statement(initialFolders);
     m_dbdrv->execute_statement(fileTable);
     m_dbdrv->execute_statement(fsFileTable);
     m_dbdrv->execute_statement(keywordTable);
@@ -395,18 +405,14 @@ bool Library::addJpegFileToBundle(int file_id, int fsfile_id)
 LibFolder::Ptr Library::getFolder(const std::string & folder)
 {
     LibFolder::Ptr f;
-    SQLStatement sql(boost::format("SELECT id,name "
-                                   "FROM folders WHERE path='%1%'") 
-                     % folder);
+    SQLStatement sql(boost::format("SELECT %1% "
+                                   "FROM folders WHERE path='%2%'") 
+                     % LibFolder::read_db_columns() % folder);
 		
     try {
         if(m_dbdrv->execute_statement(sql)) {
             if(m_dbdrv->read_next_row()) {
-                int32_t id;
-                std::string name;
-                m_dbdrv->get_column_content(0, id);
-                m_dbdrv->get_column_content(1, name);
-                f = LibFolder::Ptr(new LibFolder(id, name));
+                f = LibFolder::read_from(m_dbdrv);
             }
         }
     }
@@ -443,15 +449,13 @@ LibFolder::Ptr Library::addFolder(const std::string & folder)
 
 void Library::getAllFolders(const LibFolder::ListPtr & l)
 {
-    SQLStatement sql("SELECT id,name FROM folders");
+    SQLStatement sql(boost::format("SELECT %1% FROM folders")
+                     % LibFolder::read_db_columns());
     try {
         if(m_dbdrv->execute_statement(sql)) {
             while(m_dbdrv->read_next_row()) {
-                int32_t id;
-                std::string name;
-                m_dbdrv->get_column_content(0, id);
-                m_dbdrv->get_column_content(1, name);
-                l->push_back(LibFolder::Ptr(new LibFolder(id, name)));
+                LibFolder::Ptr f = LibFolder::read_from(m_dbdrv);
+                l->push_back(f);
             }
         }
     }
diff --git a/src/engine/db/library.hpp b/src/engine/db/library.hpp
index 11e3732..9cae447 100644
--- a/src/engine/db/library.hpp
+++ b/src/engine/db/library.hpp
@@ -39,7 +39,7 @@
 
 // The database schema version. Increase at each change.
 // Some will be persistent and have a conversion TBD.
-#define DB_SCHEMA_VERSION 3
+#define DB_SCHEMA_VERSION 4
 
 namespace fwk {
 class RgbColor;
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index 9922fc2..cac79dc 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -50,6 +50,9 @@ namespace ui {
 			m_icons[ICON_ROLL] = icon_theme->load_icon(
 				Glib::ustring("emblem-photos"), 16,
 				Gtk::ICON_LOOKUP_USE_BUILTIN);
+			m_icons[ICON_TRASH] = icon_theme->load_icon(
+				Glib::ustring("user-trash"), 16,
+				Gtk::ICON_LOOKUP_USE_BUILTIN);
 			// FIXME use an icon that make more sense.
 			m_icons[ICON_KEYWORD] = icon_theme->load_icon(
 				Glib::ustring("application-certificate"), 16, 
@@ -154,11 +157,16 @@ namespace ui {
 
 	void WorkspaceController::add_folder_item(const eng::LibFolder::Ptr & f)
 	{
-		Gtk::TreeModel::iterator iter(add_item(m_treestore, m_folderNode->children(), 
-											   m_icons[ICON_ROLL], 
-											   f->name(), f->id(), FOLDER_ITEM));
-		getLibraryClient()->countFolder(f->id());
-		m_folderidmap[f->id()] = iter;
+	  int icon_idx = ICON_ROLL;
+	  if(f->virtual_type() == eng::LibFolder::VIRTUAL_TRASH) {
+	    icon_idx = ICON_TRASH;
+	  }
+	  Gtk::TreeModel::iterator iter(add_item(m_treestore, 
+						 m_folderNode->children(), 
+						 m_icons[icon_idx], 
+						 f->name(), f->id(), FOLDER_ITEM));
+	  getLibraryClient()->countFolder(f->id());
+	  m_folderidmap[f->id()] = iter;
 	}
 
 	Gtk::TreeModel::iterator
diff --git a/src/niepce/ui/workspacecontroller.hpp b/src/niepce/ui/workspacecontroller.hpp
index e48493f..8e69179 100644
--- a/src/niepce/ui/workspacecontroller.hpp
+++ b/src/niepce/ui/workspacecontroller.hpp
@@ -108,6 +108,7 @@ namespace ui {
 			ICON_FOLDER = 0,
 			ICON_PROJECT,
 			ICON_ROLL,
+			ICON_TRASH,
 			ICON_KEYWORD,
 			_ICON_SIZE
 		};



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