1 #ifndef __creaImageIOTreeHandlerImageAdder_h_INCLUDED__
2 #define __creaImageIOTreeHandlerImageAdder_h_INCLUDED__
4 #include <creaImageIOTreeHandler.h>
5 #include <creaImageIOTimestampDatabaseHandler.h>
6 #include <creaImageIOSynchron.h>
7 #include <creaImageIOImageReader.h>
9 #include <wx/progdlg.h>
11 // Signal/slot mechanism for progress events
12 #include <boost/signal.hpp>
13 #include <boost/bind.hpp>
22 //=======================================================================
23 /// Object which can add images files to a TreeHandler. Is able to parse (recursively) a part of a filesystem to look for known images and load their attributes in order to add the images to a Tree (submission via a TreeHandler::AddBranch)
25 class TreeHandlerImageAdder
29 //====================================================================
31 TreeHandlerImageAdder(TreeHandler* tree);
33 ~TreeHandlerImageAdder();
34 /// Sets the TreeHandler
35 void SetTreeHandler(TreeHandler* tree) { mTreeHandler = tree;}
36 /// Sets the TimestampDatabaseHandler
37 void SetTimestampHandler(TimestampDatabaseHandler* tdh) { mTimestampHandler = tdh;}
38 /// Sets the synchronizer
39 void SetSynchronizer(Synchronizer* s){mSynchronizer=s;}
40 /// Sets the synchronizer
41 void SetCurrentDatabase(std::string cur){mCurrentDB=cur;}
42 //====================================================================
44 //====================================================================
45 /// Structure which holds progress information
46 /// To stop the image adder use SetStop()
50 Progress() { Reset(); }
56 mNumberScannedFiles = 0;
57 mNumberScannedDirs = 0;
58 mNumberHandledFiles = 0;
59 mNumberAddedFiles = 0;
62 int GetNumberScannedFiles() const { return mNumberScannedFiles; }
63 int GetNumberScannedDirs() const { return mNumberScannedDirs; }
64 int GetNumberHandledFiles() const { return mNumberHandledFiles; }
65 int GetNumberAddedFiles() const { return mNumberAddedFiles; }
67 void IncNumberScannedFiles() { mNumberScannedFiles++; }
68 void IncNumberScannedDirs() { mNumberScannedDirs++; }
69 void IncNumberHandledFiles() { mNumberHandledFiles++; }
70 void IncNumberAddedFiles() { mNumberAddedFiles++; }
72 void SetStop() { mStop = true; }
73 bool GetStop() const { return mStop; }
77 int mNumberScannedFiles;
78 int mNumberScannedDirs;
79 int mNumberHandledFiles;
80 int mNumberAddedFiles;
82 //=============================================
84 //=============================================
85 const Progress& GetProgress() const { return mProgress; }
86 //=============================================
88 //=============================================
89 typedef boost::signal<void (Progress&)> ProgressSignalType;
90 typedef ProgressSignalType::slot_function_type ProgressCallbackType;
91 //=============================================
93 //==================================================================
94 /// Adds the function f to the list of functions to call
95 /// when the addition progresses.
96 /// f is of type ProgressCallbackType which is:
97 /// void (*ProgressCallbackType)(Progress&)
98 /// To pass a member function 'f' of an instance 'c' of a class 'C'
99 /// as callback you have to 'bind' it, i.e. call:
100 /// ConnectProgressObserver ( boost::bind( &C::f , c, _1 ) );
101 void ConnectProgressObserver(ProgressCallbackType callback);
102 //==================================================================
104 //====================================================================
105 /// Returns if the file can be read or not
106 bool IsHandledFile( const std::string& filename);
107 /// Adds a list of files to the TreeHandler
108 void AddFiles( const std::vector<std::string>& filename );
109 /// (Recursively) adds the files of a directory to the TreeHandler
110 void AddDirectory( const std::string& directory,
112 /// Removes a file from the databases
113 void RemoveFile(tree::Node* node);
114 /// Removes files from the databases
115 void RemoveFiles(const std::vector<tree::Node*>& nodes);
116 /// Synchronizes the DB and disk by repeating the operations the user has done and returns a report
117 std::string Synchronize(bool repair, bool checkAttributes);
118 ///Recursively checks if the directory is synchronized and optionally the state of the attributes
119 void CheckSyncDirectory(const std::string &dirpath,
122 bool checkAttributes,
123 std::vector<std::string> &i_ignorefiles,
124 std::vector<std::string> & attsModified,
125 std::vector<std::string> & newfiles);
126 ///Copies the files indicated in the vector and updates all databases
127 void CopyFiles(const std::vector<std::string>& filenames, const std::string directory );
128 ///Finds the node that matches the specified parameters
129 void FindNode(tree::Node* parent, int level,
130 const std::string& searchParam,
131 const std::string& searchVal,
134 ///Finds the nodes that partially match the searchVal
135 void FindNodePartial(tree::Node* parent, int level, const std::string& searchParam, const std::string& searchVal, tree::Node*& node);
137 ///Checks the attributes of the database against the ones in disk
138 void CheckAttributes(bool repair, std::string& file, std::vector<std::string>& attsModified);
139 ///Deletes the drive with the given name (use for all databases except maintenance and timestamp)
140 void DeleteDriveFromMainDB(const std::string& drive);
141 ///Deletes the drive with the given name (use for maintenance and timestamp databases)
142 void DeleteDriveFromOtherDB(const std::string& drive);
143 ///Edits the given field and sets the new parameters
144 void EditField(tree::Node* node, const std::string& name, const std::string& key, const std::string& val);
145 ///Returns the demanded attributes for the given file
146 void GetAttributes(const std::vector<std::string>& params,
147 const std::string& filename,
148 std::vector<std::string>& results);
153 //====================================================================
157 /// Adds a single file to the TreeHandler
158 /// **WITHOUT** testing wether it is handled or not
159 /// hence you have to call IsHandledFile before using AddFile!
160 void AddFile( const std::string& filename );
162 /// Recursive method which does the main job for AddDirectory
163 void AddDirectoryRecursor( const std::string& directory,
165 const std::string &addKey);
167 TreeHandler* mTreeHandler;
168 TimestampDatabaseHandler* mTimestampHandler;
169 Synchronizer* mSynchronizer;
171 std::string mCurrentDB;
174 ProgressSignalType mProgressSignal;
178 // EO class TreeHandlerImageAdder
179 //=======================================================================
185 } // EO namespace creaImageIO
188 inline std::ostream& operator << ( std::ostream& o,
189 const creaImageIO::TreeHandlerImageAdder::Progress& p)
191 o << p.GetNumberScannedFiles() << " files - "
192 << p.GetNumberScannedDirs() << " dirs - "
193 << p.GetNumberHandledFiles() << " handled -"
194 << p.GetNumberAddedFiles() << " added";