]> Creatis software - creaImageIO.git/commitdiff
Added Timestamp database to avoid repetition of files on addition.
authorcaballero <caballero>
Fri, 17 Apr 2009 16:51:09 +0000 (16:51 +0000)
committercaballero <caballero>
Fri, 17 Apr 2009 16:51:09 +0000 (16:51 +0000)
17 files changed:
src2/CMakeLists.txt
src2/creaImageIOGimmick.cpp
src2/creaImageIOGimmick.h
src2/creaImageIOGimmickView.cpp
src2/creaImageIOGimmickView.h
src2/creaImageIOSQLiteTreeHandler.cpp
src2/creaImageIOSQLiteTreeHandler.h
src2/creaImageIOTimestampDatabaseHandler.cpp [new file with mode: 0644]
src2/creaImageIOTimestampDatabaseHandler.h [new file with mode: 0644]
src2/creaImageIOTreeHandlerImageAdder.cpp
src2/creaImageIOTreeHandlerImageAdder.h
src2/creaImageIOTreeView.cpp
src2/creaImageIOTreeView.h
src2/creaImageIOWxGimmickView.cpp
src2/creaImageIOWxGimmickView.h
src2/creaImageIOWxTreeView.cpp
src2/creaImageIOWxTreeView.h

index 83bab4a5091cd2639a5c05ae964530eba64a694b..18228ce069b3ac854ce9d51ff57be6d69c9c2ea7 100644 (file)
@@ -34,6 +34,7 @@ SET( SRCS
   # 
   creaImageIOGimmick
   creaImageIOSynchronizer
+  creaImageIOTimestampDatabaseHandler
 
   # Abstract views
   creaImageIOGimmickView
index 8d1583ccac4ddd4fd75b62d39535e32e8cd05e8f..5ae843801e4952e9d89ca7e6d7b81497fe9a1959 100644 (file)
@@ -35,11 +35,11 @@ namespace creaImageIO
     // Sets the current directory to the home dir
     mCurrentDirectory =  GetHomeDirectory();
        mSynchronizer=0;
+
     // Create local database handler
     mLocalDatabase = new SQLiteTreeHandler(GetLocalDatabasePath());
     // Add it to the TreeHandlerMap
     mTreeHandlerMap["Local database"] = mLocalDatabase;
-
     // Create or open local database
     if (! boost::filesystem::exists( GetLocalDatabasePath() ) )
       {
@@ -69,6 +69,37 @@ namespace creaImageIO
          }
        
       }
+
+
+       // Creates files and directories database
+    mTimestampDatabase = new TimestampDatabaseHandler(GetTimestampDatabasePath());
+    // Create or open local database
+    if (! boost::filesystem::exists( GetTimestampDatabasePath() ) )
+      {
+       std::string mess = "Timestamp database '";
+       mess += GetTimestampDatabasePath();
+       mess += "' does not exist : creating it";
+       GimmickMessage(1,mess<<std::endl);
+       
+       if ( ! mTimestampDatabase->Create() )
+         {
+           GimmickError("ERROR CREATING '"<<GetTimestampDatabasePath()<<"'");
+         }
+       
+     }
+    else 
+      {
+       /// Open and test it
+       GimmickMessage(1,"Opening Timestamp database '"
+                      <<GetTimestampDatabasePath()<<"' "
+                      <<std::endl);
+       if ( ! mTimestampDatabase->Open() )
+         {
+           GimmickError("ERROR OPENING '"<<GetTimestampDatabasePath()<<"'");
+         }
+       
+      }
+
   }
   //================================================================
 
@@ -77,6 +108,7 @@ namespace creaImageIO
   void Gimmick::Finalize()
   {
     delete mLocalDatabase;
+       delete mTimestampDatabase;
   }
   //==============================================================
 
@@ -132,6 +164,22 @@ namespace creaImageIO
       }
     return mLocalDatabasePath;    
   }
+
+  //================================================================
+
+  //================================================================
+  const std::string& Gimmick::GetTimestampDatabasePath()
+  {
+    if (mTimestampDatabasePath.size()==0) 
+      {
+       mTimestampDatabasePath = GetUserSettingsDirectory();
+       mTimestampDatabasePath += "timestamp_database.sqlite3";
+       boost::algorithm::replace_all( mTimestampDatabasePath,
+                                      INVALID_FILE_SEPARATOR , 
+                                      VALID_FILE_SEPARATOR);
+      }
+    return mTimestampDatabasePath;    
+  }
   //========================================================================
 
   //========================================================================
@@ -168,7 +216,7 @@ namespace creaImageIO
   //========================================================================
 
   //========================================================================
-  /// Add a file to the local database
+  /// Returns the tree handler with the given name
   TreeHandler* Gimmick::GetTreeHandler(const std::string& name) const 
   {  
     TreeHandlerMapType::const_iterator i;
@@ -180,6 +228,13 @@ namespace creaImageIO
     return i->second;
   }
 
+  //========================================================================
+  ///Returns the timestamp database handler
+  TimestampDatabaseHandler* Gimmick::GetTimestampDatabase() const 
+  {  
+    return mTimestampDatabase;
+  }
+
 
   //========================================================================
   /// Add the files to the tree handler
@@ -189,6 +244,7 @@ namespace creaImageIO
     GimmickMessage(2,"Adding files to '"<<d<<"'"<<std::endl);
  
     mImageAdder.SetTreeHandler(GetTreeHandler(d));
+       mImageAdder.SetTimestampHandler(mTimestampDatabase);
     mImageAdder.AddFiles(filenames);
 
   }
@@ -204,6 +260,7 @@ namespace creaImageIO
 
        TreeHandler * handler=GetTreeHandler(d);
     mImageAdder.SetTreeHandler(handler);
+       mImageAdder.SetTimestampHandler(mTimestampDatabase);
     mImageAdder.AddDirectory(f,recurse);
        //Synchronize(true, handler);
     
index 93d982a99c10a12d940665891ec4c957f1596f35..5b6606ce679a18acfb36eb829c49281748e57f61 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <creaImageIOSQLiteTreeHandler.h>
 #include <creaImageIOTreeHandlerImageAdder.h>
+#include <creaImageIOTimestampDatabaseHandler.h>
 #include <creaImageIOSynchronizer.h>
 
 namespace creaImageIO
@@ -100,6 +101,9 @@ namespace creaImageIO
 
     /// Returns the TreeHandler with a given name
     TreeHandler* GetTreeHandler(const std::string& name) const;
+
+       /// Returns the TimestampDatabase
+       TimestampDatabaseHandler* GetTimestampDatabase() const;
     /// 
     SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
 
@@ -113,11 +117,13 @@ namespace creaImageIO
     const std::string& GetUserSettingsDirectory();
     void CreateUserSettingsDirectory();
     const std::string& GetLocalDatabasePath();
+       const std::string& GetTimestampDatabasePath();
 
 
     //=============================================
   private:
     SQLiteTreeHandler* mLocalDatabase;
+       TimestampDatabaseHandler* mTimestampDatabase;
     TreeHandlerMapType mTreeHandlerMap;
        Synchronizer* mSynchronizer;
 
@@ -125,6 +131,7 @@ namespace creaImageIO
     std::string mHomeDirectory;
     std::string mUserSettingsDirectory;
     std::string mLocalDatabasePath;
+       std::string mTimestampDatabasePath;
 
     TreeHandlerImageAdder mImageAdder;
   };
index e076ef71ea4d5d1b685b304db6ba2b1118c484b8..2c2507f2ed90388baeab450522f415e5992a8c7b 100644 (file)
@@ -109,7 +109,7 @@ namespace creaImageIO
         i!= mGimmick->GetTreeHandlerMap().end();
         ++i)
       {
-       this->CreateTreeView(i->second);
+       this->CreateTreeView(i->second, mGimmick->GetTimestampDatabase());
       }
   }
   //======================================================================
index 83b74078d5dc10887b81e8bb39d71343b59b468a..1e9968bf2e612890c424cc5a6405046100218487 100644 (file)
@@ -101,7 +101,7 @@ namespace creaImageIO
       void CreateTreeViews();
 
       /// Create the tree view for TreeHandler provided
-      virtual void CreateTreeView( TreeHandler*) 
+      virtual void CreateTreeView( TreeHandler*, TimestampDatabaseHandler* 
       { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
 
       /// Updates the TreeView of given name from level l to bottom
index 52042a21a097d8564bbae4950d2ed4ec8890dea8..6af107d7c27fc023b17de9f0403edf5c2140754b 100644 (file)
@@ -915,13 +915,56 @@ namespace creaImageIO
                            <<"' in level "<< GetTree().GetLevelDescriptor(node->GetLevel()).GetName()
                            <<std::endl);
 
-    Node::ChildrenListType::iterator i;
-    for (i  = node->GetChildrenList().begin();
-        i != node->GetChildrenList().end();
-        i++)
-      {
-       DBRecursiveRemoveNode((*i));
-      }
+
+       if(node->GetNumberOfChildren()!=0)
+       {
+               Node::ChildrenListType::iterator i;
+               for (i  = node->GetChildrenList().begin();
+               i != node->GetChildrenList().end();
+               i++)
+               {
+               DBRecursiveRemoveNode((*i));
+               }
+       }
+       else if(node->GetLevel()<GetTree().GetNumberOfLevels()-1)
+       {
+               DBRecursiveRemoveNode(node->GetLevel()+1,node->GetAttribute("ID"));
+    }
+  }
+
+  //=====================================================================
+  void SQLiteTreeHandler::DBRecursiveRemoveNode(int level, std::string parentId)
+  {
+    std::stringstream out;
+       std::stringstream result;
+       out<<"SELECT ID FROM "<<GetTree().GetLevelDescriptor(level).GetName()<<" WHERE PARENT_ID='"<<parentId<<"'";
+               
+       CppSQLite3Query q;
+       QUERYDB(out.str(),q);
+       
+       while (!q.eof())
+         {
+           for (int fld = 0; fld < q.numFields(); fld++)
+             {
+                         result<<q.getStringField(fld)<<"#";
+             }
+           q.nextRow();
+         }
+         std::string res=result.str();
+         size_t ini=0;
+         size_t fin=0;
+         while(fin<res.size()-1)
+         {
+          fin=res.find('#',ini);
+          DBDelete(GetTree().GetLevelDescriptor(level).GetName(),"ID",res.substr(ini,fin-ini));
+         if(level<GetTree().GetNumberOfLevels()-1)
+         {
+               DBRecursiveRemoveNode(level+1,res.substr(ini,fin-ini));
+         } 
+          ini=fin+1;
+         }
+         
+    
   }
 
   //=====================================================================
index 0f45f7093503360e45ff9d0300c6b9dc79019e9e..1c35aac5c6f1c7757ae58c7c05b40c272c9be2a9 100644 (file)
@@ -193,9 +193,15 @@ namespace creaImageIO
        void DBDelete(std::string levelDescriptor, std::string key, std::string value);
     //======================================================================
 
+       //======================================================================
 
        /// Recursively Removes the nodes whose parent is given as a parameter
     void DBRecursiveRemoveNode(tree::Node* node);
+       /// Recursively Removes the nodes found in the given level with the given parent id
+       void DBRecursiveRemoveNode(int level, std::string parentId);
+       //======================================================================
+
     /*
     /// 
     int DBQueryNumberOfChildren(tree::Node* n);
diff --git a/src2/creaImageIOTimestampDatabaseHandler.cpp b/src2/creaImageIOTimestampDatabaseHandler.cpp
new file mode 100644 (file)
index 0000000..0e1176e
--- /dev/null
@@ -0,0 +1,417 @@
+#include <creaImageIOTimestampDatabaseHandler.h>
+#include <creaImageIOSystem.h>
+
+#include "CppSQLite3.h"
+
+#include <sys/stat.h>
+
+#include <deque>
+
+#include "wx/wx.h"
+#include <wx/dir.h>
+#include <wx/filename.h>
+
+#include <creaWx.h>
+using namespace crea;
+
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string/replace.hpp>
+
+namespace creaImageIO
+{
+       using namespace tree;
+  //=============================================================
+  TimestampDatabaseHandler::TimestampDatabaseHandler(const std::string& filename)
+    : mFileName(filename)
+  {
+    mDB = new CppSQLite3DB;
+    GimmickMessage(1,"SQLite version : "
+                  <<std::string(mDB->SQLiteVersion())<< std::endl);
+  }
+  //=============================================================
+
+  //=============================================================
+  TimestampDatabaseHandler::~TimestampDatabaseHandler()
+  {
+    delete mDB;
+  }
+  //=============================================================
+  //=====================================================================
+  bool TimestampDatabaseHandler::Open()
+  {
+    return DBOpen();
+  }
+
+  //=====================================================================
+  bool TimestampDatabaseHandler::Create()
+  {
+    return DBCreate();
+  }
+  //=====================================================================
+
+
+  //=====================================================================
+  bool TimestampDatabaseHandler::Close()
+  {
+    return true;
+  }
+  //=====================================================================
+
+
+  //=====================================================================
+  bool TimestampDatabaseHandler::Destroy()
+  {
+    return false;
+  }
+
+
+
+
+
+
+  //=====================================================================
+  // SQLite DB specific methods
+  //=====================================================================
+  //=====================================================================
+#define QUERYTIMESTAMPDB(QUER,RES)                                             \
+    try                                                                        \
+      {                                                                        \
+       GimmickMessage(2,"SQL query: '"<<QUER<<"'"<<std::endl);         \
+       RES = mDB->execQuery(QUER.c_str());                             \
+      }                                                                        \
+    catch (CppSQLite3Exception& e)                                     \
+      {                                                                        \
+       GimmickError("SQLite query '"<<QUER<<"' : "                     \
+                    << e.errorCode() << ":"                            \
+                    << e.errorMessage() );                             \
+      }                                                                        \
+  //=====================================================================
+#define UPDATETIMESTAMPDB(UP)                                                  \
+  try                                                                  \
+    {                                                                  \
+      GimmickMessage(2,"SQL update: '"<<UP<<"'"<<std::endl);           \
+      mDB->execDML(UP.c_str());                                                \
+    }                                                                  \
+  catch (CppSQLite3Exception& e)                                       \
+    {                                                                  \
+      GimmickError("SQLite update '"<<UP<<"' Error : "                 \
+                  << e.errorCode() << ":"                              \
+                  << e.errorMessage() );                               \
+    }                                                                  
+  //=====================================================================
+
+
+   //=====================================================================
+  bool TimestampDatabaseHandler::DBOpen()
+  {
+    GimmickMessage(1,"Opening SQLite database '"<<GetFileName()
+                  <<"' ... "<<std::endl);
+    // OPENING FILE
+    if (!boost::filesystem::exists(GetFileName())) 
+      {
+       return false;
+      }
+
+    try
+      {
+       mDB->open(GetFileName().c_str());
+      }
+    catch (CppSQLite3Exception& e)
+      {
+       GimmickError("Opening '"<<GetFileName()<<"' : "
+                    << e.errorCode() << ":" 
+                    << e.errorMessage());
+       return false;
+      }
+
+    GimmickDebugMessage(1,"Opening SQLite database '"<<GetFileName()
+                  <<"' ... OK"<<std::endl);
+    return true;
+  }
+  //=====================================================================
+
+  //=====================================================================
+  bool TimestampDatabaseHandler::DBCreate()
+  {
+    GimmickMessage(1,"Creating SQLite database '"<<GetFileName()
+                  <<"' ... "<<std::endl);
+
+    if (boost::filesystem::exists(GetFileName())) 
+      {
+       GimmickError(GetFileName()<<"' : "
+                    << "file already exists");
+       return false;
+      }
+    
+    // OPENING
+    try
+      {
+       mDB->open(GetFileName().c_str());
+      }
+    catch (CppSQLite3Exception& e)
+      {
+       GimmickError(e.errorCode() << ":" 
+                    << e.errorMessage() <<std::endl);
+       return false;
+      }
+    
+     
+    // CREATING TABLES
+    
+    std::string command;
+  
+    
+           command = "CREATE TABLE ";
+           command += "FILES";
+           command += "\n(\nID INTEGER PRIMARY KEY";
+               command += ",\nPARENT_ID int not null"; 
+           command += ",\nPATH text";
+               command += ",\nLastModified datetext";
+               command += ",\nLastRead datetext";
+               command += ",\nconstraint FK_PARENT foreign key (PARENT_ID) references ";
+               command += "FILES";
+               command += "(ID) on delete restrict on update restrict";
+             
+           command += "\n)";
+           UPDATETIMESTAMPDB(command);
+           
+    return true;
+  }
+
+
+
+  //=====================================================================
+  void TimestampDatabaseHandler::CleanName(std::string& str) const
+  {
+        size_t pos;
+        do
+     {
+         pos = str.find('\\');
+         if (pos!=-1)  
+                {
+                        str.replace(pos, 1, "/");
+                }
+     }
+     while (pos!=-1);
+  }
+
+
+  //=====================================================================
+
+  bool TimestampDatabaseHandler::AddDirectory(const std::string& parent,
+                                                                                  const std::string& path, 
+                                                                                  const time_t lastModif, 
+                                                                                  const time_t lastRead)
+  {
+        bool valid=false;
+        std::string par=parent.c_str();
+        std::string pat=path.c_str();
+        CleanName(par);
+        CleanName(pat);
+
+        std::string pathId=IsIndexed(pat);
+        //Case: It is a root parent
+        if(parent.compare("")==0)
+        {
+                if(pathId.compare("")==0)
+                {
+                       AddFile(pat,lastModif,lastRead);
+                       valid=true;
+                }
+                else
+                {
+                        valid=CheckTimestamp(pathId, lastModif);
+                }
+        }
+        else 
+        {
+                std::string parentId=IsIndexed(par);
+                //Case: Parent is not in database
+                if(parentId.compare("")==0)
+               {
+                       AddFile(par,lastModif,lastRead);
+                       parentId=IsIndexed(par);
+               }
+
+               //Case path is not in database
+               if(pathId.compare("")==0)
+               {
+                   AddFile(parentId,pat,lastModif,lastRead);
+                       valid=true;
+               }
+               //Parent and path are in the database
+               else
+               {
+                       SetAttribute("PARENT_ID",parentId,"ID", pathId);
+                       valid=CheckTimestamp(pathId, lastModif);
+               }
+        }
+        return valid;
+       
+  }
+
+  //=====================================================================
+
+  void TimestampDatabaseHandler::AddFile(const std::string& path, const time_t lastModif, const time_t lastRead)
+  {
+       std::stringstream out;
+       out<<"INSERT INTO FILES (PARENT_ID,PATH,LastModified,LastRead) VALUES(0,'"<<path<<"',";
+       out<<lastModif<<","<<lastRead<<");";
+    UPDATETIMESTAMPDB(out.str());
+       
+  }
+
+   //=====================================================================
+
+  void TimestampDatabaseHandler::AddFile(const std::string& parentId, 
+                                                                                const std::string& path, 
+                                                                                const time_t lastModif, 
+                                                                                const time_t lastRead)
+  {
+       std::stringstream out;
+       out<<"INSERT INTO FILES (PARENT_ID,PATH,LastModified,LastRead) VALUES("<<parentId<<",'"<<path<<"',";
+       out<<lastModif<<","<<lastRead<<");";
+    UPDATETIMESTAMPDB(out.str());
+  }
+
+  //=====================================================================
+  std::string TimestampDatabaseHandler::IsIndexed(const std::string& path)
+  {
+       std::stringstream out;
+       std::stringstream result;
+       out<<"SELECT ID FROM FILES WHERE PATH='"<<path<<"'";
+               
+       CppSQLite3Query q;
+       QUERYTIMESTAMPDB(out.str(),q);
+       
+       
+       while (!q.eof())
+         {
+           for (int fld = 0; fld < q.numFields(); fld++)
+             {
+                         result<<q.getStringField(fld);
+             }
+           q.nextRow();
+         }
+
+         return result.str();
+  }
+
+  //=====================================================================
+  void TimestampDatabaseHandler::SetAttribute(const std::string& attName, 
+                                                                                       const std::string& attValue,
+                                                                                       const std::string& searchParam,
+                                                                                       const std::string& searchValue)
+  {
+       std::string sql = "UPDATE FILES SET ";
+    sql += attName;
+    sql += " = '";
+    sql += attValue;
+    sql += "' WHERE ";
+       sql += searchParam;
+       sql += " = '";
+    sql += searchValue;
+       sql += "'";
+    UPDATETIMESTAMPDB(sql);
+  }
+  //=====================================================================
+  void TimestampDatabaseHandler::RemoveNode(const std::string& searchAtt, tree::Node* node)
+  {
+         int n=node->GetNumberOfChildren();
+         if(n>0)
+         {
+                 std::vector<tree::Node*> children=node->GetChildrenList();
+                 std::vector<tree::Node*>::iterator it;
+                 for(it=children.begin();it!=children.end();++it)
+                 {
+                         RemoveNode(searchAtt,(*it));
+                 }
+         }
+         else if(node->GetLevel()==3)
+         {
+                 RemoveFile(searchAtt,node->GetAttribute("FullFileName"));
+         }
+
+
+  }
+  //=====================================================================
+  void TimestampDatabaseHandler::RemoveFile(const std::string& searchAtt, const std::string& searchVal)
+  {
+         
+         std::stringstream result;
+         std::string sel="SELECT PARENT_ID FROM FILES WHERE "+searchAtt+"='"+searchVal+"'";
+               
+         CppSQLite3Query q;
+         QUERYTIMESTAMPDB(sel,q);
+       
+         while (!q.eof())
+         {
+           for (int fld = 0; fld < q.numFields(); fld++)
+             {
+                         result<<q.getStringField(fld);
+             }
+           q.nextRow();
+         }
+         DBRemove(searchAtt,searchVal);
+         
+                 int nChildren=0;
+                 sel="SELECT ID FROM FILES WHERE PARENT_ID='"+result.str()+"'";
+                 CppSQLite3Query q2;
+                 QUERYTIMESTAMPDB(sel,q2);
+                 while (!q2.eof())
+                       {
+                               nChildren++;
+                               q2.nextRow();
+                       }
+                       if(nChildren<1)
+                       {
+                               if(!result.str().compare("0"))
+                               {
+                               RemoveFile("ID",result.str());
+                               }
+                               else
+                               {
+                               DBRemove("ID",result.str());
+                               }
+                       }
+  }
+
+  //=====================================================================
+  void TimestampDatabaseHandler::DBRemove(const std::string& searchAtt, const std::string& searchVal)
+  {
+       
+    std::string query = "DELETE FROM FILES WHERE "+searchAtt+"='"+ searchVal + "';";
+    UPDATETIMESTAMPDB(query);
+  }
+
+   //=====================================================================
+  bool TimestampDatabaseHandler::CheckTimestamp(const std::string pathId, const time_t lastModif)
+  {
+       std::string sel="SELECT LastModified FROM FILES WHERE ID='"+pathId+"';";
+       CppSQLite3Query q;
+       QUERYTIMESTAMPDB(sel,q);
+       double timestamp;
+       
+       while (!q.eof())
+         {
+           for (int fld = 0; fld < q.numFields(); fld++)
+             {
+                         timestamp=q.getFloatField(fld);
+             }
+           q.nextRow();
+         }
+
+         
+         std::stringstream lm;
+         lm<<lastModif;
+         double modif=atof((lm.str()).c_str());
+         if(timestamp<modif)
+         {
+                 SetAttribute("LastModified",lm.str(),"ID",pathId);
+                 return true;
+         }
+         return false;  
+  }
+
+}// namespace creaImageIO
\ No newline at end of file
diff --git a/src2/creaImageIOTimestampDatabaseHandler.h b/src2/creaImageIOTimestampDatabaseHandler.h
new file mode 100644 (file)
index 0000000..ce01556
--- /dev/null
@@ -0,0 +1,105 @@
+#ifndef __creaImageIOTimestampDatabaseHandler_h_INCLUDED__
+#define __creaImageIOTimestampDatabaseHandler_h_INCLUDED__
+#include <vector>
+#include <map>
+#include <creaImageIOTree.h>
+class CppSQLite3DB;
+
+namespace creaImageIO
+{
+       using namespace std;
+//=======================================================================
+  /// Concrete TreeHandler which manages a Tree stored in a sqlite database
+  class TimestampDatabaseHandler 
+  {
+  public:
+    //====================================================================
+    /// Ctor with database file name 
+    TimestampDatabaseHandler(const std::string& filename);
+    /// Dtor
+    virtual ~TimestampDatabaseHandler();
+    //====================================================================
+
+    //====================================================================
+    /// Returns the sqlite db file name 
+    const std::string& GetFileName() const { return mFileName; }
+    //====================================================================
+    //====================================================================
+    // INITIALIZATION / FINALIZATION
+    //====================================================================
+
+    //====================================================================
+    /// Opens an existing 'source' 
+     bool Open();
+    /// Closes the 'source'
+    bool Close();
+    /// Creates a new 'source' 
+    bool Create();
+    /// Destroys the 'source'
+    bool Destroy();
+    //====================================================================
+
+       //====================================================================
+    // READ / WRITE
+    //====================================================================
+       //====================================================================
+       ///Returns the id of the path if it's indexed, blank otherwise
+       std::string IsIndexed(const std::string& path);
+    ///Sets the current path's parent
+       bool AddDirectory(const std::string& parent,
+                                  const std::string& path, 
+                                  const time_t lastModif, 
+                                  const time_t lastRead);
+       ///Adds a new file to the database without a parent
+       void AddFile(const std::string& path, const time_t lastModif, const time_t lastRead);
+       ///Adds a new file to the database with a parent
+       void AddFile(const std::string& parentId,const std::string& path, const time_t lastModif, const time_t lastRead);
+       ///Sets the attribute to the value passed as parameter where the searchParameter is searchValue
+       void SetAttribute(const std::string& attName, 
+                                       const std::string& attValue,
+                                       const std::string& searchParam,
+                                       const std::string& searchValue);
+       ///Removes the given node
+       void RemoveNode(const std::string& searchAtt, tree::Node* node);
+       ///Removes the filename with the given pathname
+       void RemoveFile(const std::string& searchAtt, const std::string& searchVal);
+       ///Cleans the path name
+       void CleanName(std::string& str) const;
+       ///Checks the timestamp in the database and compares it with the given one. 
+       //If there is a difference, it will return false, otherwise it will return true.
+       bool CheckTimestamp(const std::string pathId, const time_t lastModif);
+
+       //====================================================================
+
+
+  protected:
+    //======================================================================
+    /// Open the database
+    bool DBOpen();
+    //======================================================================
+    //======================================================================
+    // Creation
+    /// Creates a new database on disk and the tables
+    bool DBCreate();
+    //======================================================================
+       //======================================================================
+    // Removes a file from the database
+       void DBRemove(const std::string& searchAtt, const std::string& searchVal);
+  private:
+    /// The DB
+    CppSQLite3DB* mDB;
+   /// The physical location associated to the DicomDatabase (directory, db file...)
+    std::string mFileName;
+  
+  };
+  // EO class
+  //=======================================================================
+
+
+} // EO namespace creaImageIO
+
+// EOF
+#endif  
+
index 800a8b8f08ae65223edc8a4b0ebc4e02eaa87f64..f5424b63ca63d920e39ea9d7258b41afb4aaddd4 100644 (file)
@@ -1,8 +1,15 @@
 #include <creaImageIOTreeHandlerImageAdder.h>
 #include <creaImageIOSystem.h>
 #include "boost/filesystem.hpp"
+#include <boost/filesystem/operations.hpp>
+#include <boost/utility.hpp>
+
 
 namespace fs = boost::filesystem;
+using boost::filesystem::path;
+using boost::next;
+using boost::prior;
+
 
 //using namespace crea;
 
@@ -90,7 +97,8 @@ namespace creaImageIO
     mProgress.IncNumberScannedDirs();
 
     if ( !fs::exists( dirpath ) ) return;
-    
+       time_t lastModif=fs::last_write_time(dirpath);
+
     fs::directory_iterator end_itr; // default construction yields past-the-end
     for ( fs::directory_iterator itr( dirpath );
          itr != end_itr;
@@ -99,24 +107,32 @@ namespace creaImageIO
        // If is directory & recurse : do recurse
        if ( fs::is_directory(itr->status()) )
          {
-           if (recursive) AddDirectoryRecursor( itr->string(), recursive);
+           if (recursive) 
+               {
+                       AddDirectoryRecursor( itr->string(), recursive);
+               }
          }
        else 
          {
-           mProgress.IncNumberScannedFiles();
-           if (IsHandledFile(itr->string()))
-             {
-               mProgress.IncNumberHandledFiles();
-               AddFile( itr->string() );
-             }
-           mProgressSignal(mProgress);
-           if (mProgress.GetStop()) 
-             {
-               //itr = end_itr;
-               break;
-             }
+               bool valid=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0));
+               if(valid)
+               {
+                       mProgress.IncNumberScannedFiles();
+                       if (IsHandledFile(itr->string()))
+                       {
+                       mProgress.IncNumberHandledFiles();
+                       AddFile( itr->string() );
+                       }
+                       mProgressSignal(mProgress);
+                       if (mProgress.GetStop()) 
+                       {
+                       //itr = end_itr;
+                       break;
+                       }
+               }
          }
       }
+       
   }
   //=======================================================================
 
index bcb74c0c2514b080fdfce842b49dc83890cc6270..e490509100a1469e2837639ae6f42f29a06c6646 100644 (file)
@@ -2,6 +2,7 @@
 #define __creaImageIOTreeHandlerImageAdder_h_INCLUDED__
 
 #include <creaImageIOTreeHandler.h>
+#include <creaImageIOTimestampDatabaseHandler.h>
 #include <creaImageIOImageReader.h>
 #include <wx/wx.h>
 #include <wx/progdlg.h>
@@ -29,6 +30,8 @@ namespace creaImageIO
     ~TreeHandlerImageAdder();
     /// Sets the TreeHandler
     void SetTreeHandler(TreeHandler* tree) { mTreeHandler = tree;}
+       /// Sets the TimestampDatabaseHandler
+    void SetTimestampHandler(TimestampDatabaseHandler* tdh) { mTimestampHandler = tdh;}
     //====================================================================
 
     //====================================================================
@@ -113,6 +116,7 @@ namespace creaImageIO
                               bool recurse );
 
     TreeHandler* mTreeHandler;
+       TimestampDatabaseHandler* mTimestampHandler;
     ImageReader mReader;
     
     Progress mProgress;
index a34f0c6fc6008fb9f5267597d139465e72dbdbf0..42d4fd3b6ca309b19a5ad5427e2db89958a2808e 100644 (file)
@@ -4,8 +4,9 @@
 namespace creaImageIO
 {
   // CTor
-  TreeView::TreeView(TreeHandler* handler,  GimmickView* gimmick )
+  TreeView::TreeView(TreeHandler* handler, TimestampDatabaseHandler* tdh, GimmickView* gimmick )
     : mTreeHandler(handler),
+         mTimestampDatabaseHandler (tdh),
       mGimmickView(gimmick)
   {
     GimmickDebugMessage(1,"TreeView::TreeView"
index 886fc38590111ffdeecb3b48ee3195f61a557410..c5fab53309688d504ffe3ba338885ed793a6234e 100644 (file)
@@ -2,6 +2,7 @@
 #define __creaImageIOTreeView_h_INCLUDED__
 
 #include <creaImageIOTreeHandler.h>
+#include <creaImageIOTimestampDatabaseHandler.h>
 #include <creaImageIOSystem.h>
 #include <vtkImageData.h>
 
@@ -22,7 +23,7 @@ namespace creaImageIO
     {
     public:
       /// Ctor
-      TreeView(TreeHandler*,GimmickView*);
+      TreeView(TreeHandler*,TimestampDatabaseHandler*,GimmickView*);
       /// Virtual destructor
       virtual ~TreeView();
 
@@ -52,11 +53,14 @@ namespace creaImageIO
 
     protected:
       TreeHandler* GetTreeHandler() { return mTreeHandler; }
+         TimestampDatabaseHandler* GetTimestampDatabaseHandler() { return mTimestampDatabaseHandler; }
       GimmickView* GetGimmickView() { return mGimmickView; }
         
     private:
       /// The TreeHandler with which it corresponds
       TreeHandler* mTreeHandler;
+          /// The Timestamp handler with which it corresponds
+         TimestampDatabaseHandler* mTimestampDatabaseHandler;
       /// The GimmickView which holds the TreeView
       GimmickView* mGimmickView;  
 
index dd8745ff2c15ea342889fa70940caba9b956a272..6bcf489dbcc3029ed8053ef5759502bafe2ad6ff 100644 (file)
@@ -206,13 +206,13 @@ namespace creaImageIO
  
   //======================================================================
   /// Create the tree view for TreeHandler provided
-  void WxGimmickView::CreateTreeView( TreeHandler* h)
+  void WxGimmickView::CreateTreeView( TreeHandler* h, TimestampDatabaseHandler* tdh)
   {
     std::string name(h->GetTree().GetAttribute("Name"));
     GimmickMessage(2,"Creating the tree view for '"<<
                   name<<"'"<<std::endl);
     // Create the WxTreeView
-    WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
+    WxTreeView* view = new WxTreeView(h,tdh,this,mNotebook,-1);
 
     // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
     // ALREADY IN THE MAP
index 73b7d450ae152e522444d9ea160649d58ff092d9..302698fa701f382e55f30ac5ce556c86765bd792 100644 (file)
@@ -73,7 +73,7 @@ namespace creaImageIO
     
     /// Create the tree view for TreeHandler provided 
     /// (overloaded from GimmickView)
-    void CreateTreeView( TreeHandler* );
+    void CreateTreeView( TreeHandler*, TimestampDatabaseHandler* );
     
     
   private:
index 7e2cb866353cdd26e9dd64427798fdade4c52b8b..2050e53eb036adee2b39bde5d3141be49ba56757 100644 (file)
@@ -5,7 +5,6 @@
 #include <wx/gdicmn.h>
 #include <boost/date_time/gregorian/gregorian.hpp>
 
-
 const std::string empty_string("");
 
 //=====================================================================
@@ -107,11 +106,12 @@ namespace creaImageIO
   //=====================================================================
   // CTor
   WxTreeView::WxTreeView(TreeHandler* handler,
+                        TimestampDatabaseHandler* tdh,
                         GimmickView* gimmick,
                         wxWindow* parent,
                         const wxWindowID id)
     : wxPanel(parent,id),
-      TreeView(handler,gimmick)
+      TreeView(handler, tdh, gimmick)
   {
     GimmickDebugMessage(1,"WxTreeView::WxTreeView"
                        <<std::endl);
@@ -351,6 +351,7 @@ namespace creaImageIO
                          {
                            needRefresh=true;
                          }
+                        GetTimestampDatabaseHandler()->RemoveNode("PATH",(*i));
                        GetTreeHandler()->Remove(*i);
                      }
                    
@@ -377,9 +378,6 @@ namespace creaImageIO
   }
   
   
-  //=====================================================================
-
   //=====================================================================
   /// Updates a level of the view (adds or removes children, etc.)
   void WxTreeView::UpdateLevel( int level )
index 4b97590f6cf33284eb6e17fb6a94f0b900defaec..9e2072eb753bc37ae8a2c338a6230759017ef029 100644 (file)
@@ -24,7 +24,7 @@ namespace creaImageIO
     {
     public:
       /// Ctor
-      WxTreeView(TreeHandler*, GimmickView*, 
+      WxTreeView(TreeHandler*, TimestampDatabaseHandler*, GimmickView*, 
                 wxWindow* parent, const wxWindowID id);
       /// Virtual destructor
       virtual ~WxTreeView();
@@ -35,7 +35,7 @@ namespace creaImageIO
 
       ///Removes selected nodes on given level
       virtual void RemoveSelected();
-      
+
       /// Callback for item selection
       void OnItemSelected(wxListEvent& event);