#include <creaImageIOGimmick.h>
#include <creaImageIOSystem.h>
-#include <creaImageIOImageFinder.h>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
//==============================================================
Gimmick::Gimmick()
+ : mImageAdder(0)
{
RegisterGimmickMessageTypes();
}
CreateUserSettingsDirectory();
// 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() ) )
{
}
}
+
+
+ // 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()<<"'");
+ }
+
+ }
+
}
//================================================================
void Gimmick::Finalize()
{
delete mLocalDatabase;
+ delete mTimestampDatabase;
}
//==============================================================
}
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;
+ }
//========================================================================
//========================================================================
//========================================================================
//========================================================================
- /// 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;
return i->second;
}
+ //========================================================================
+ ///Returns the timestamp database handler
+ TimestampDatabaseHandler* Gimmick::GetTimestampDatabase() const
+ {
+ return mTimestampDatabase;
+ }
+
//========================================================================
- /// Add a file to the local database
- void Gimmick::AddFile(const std::string& d, const std::string& f)
+ /// Add the files to the tree handler
+ void Gimmick::AddFiles(const std::string& d,
+ const std::vector<std::string>& filenames)
{
- GimmickMessage(2,"Adding file '"<<f<<"' to '"<<d<<"'"<<std::endl);
+ GimmickMessage(2,"Adding files to '"<<d<<"'"<<std::endl);
- ImageFinder finder(GetTreeHandler(d));
- if (finder.IsHandledFile(f))
- {
- finder.AddFile(f);
- }
- else
- {
- GimmickError("File '"<<f<<"' does not exist or is not handled");
- }
+ mImageAdder.SetTreeHandler(GetTreeHandler(d));
+ mImageAdder.SetTimestampHandler(mTimestampDatabase);
+ mImageAdder.AddFiles(filenames);
+
}
//========================================================================
GimmickMessage(2,"Adding dir '"<<f<<"' to '"<<d<<"' recurse:"
<<recurse<<std::endl);
- ImageFinder finder(GetTreeHandler(d));
-
- finder.AddDirectory(f,recurse);
+ TreeHandler * handler=GetTreeHandler(d);
+ mImageAdder.SetTreeHandler(handler);
+ mImageAdder.SetTimestampHandler(mTimestampDatabase);
+ mImageAdder.AddDirectory(f,recurse);
+ //Synchronize(true, handler);
}
+
+ //========================================================================
+
//========================================================================
+
+ void Gimmick::Synchronize(bool update, TreeHandler* handler)
+ {
+ GimmickMessage(4,"Synchronizing. Update:"<<update<<std::endl);
+ if(mSynchronizer==0)
+ {
+ mSynchronizer=new Synchronizer(handler);
+ }
+ else
+ {
+ mSynchronizer->SetTreeHandler(handler);
+ }
+ mSynchronizer->Synchronize(update);
+
+ }
//========================================================================
///