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 //====================================================================
42 //====================================================================
43 /// Structure which holds progress information
44 /// To stop the image adder use SetStop()
48 Progress() { Reset(); }
54 mNumberScannedFiles = 0;
55 mNumberScannedDirs = 0;
56 mNumberHandledFiles = 0;
57 mNumberAddedFiles = 0;
60 int GetNumberScannedFiles() const { return mNumberScannedFiles; }
61 int GetNumberScannedDirs() const { return mNumberScannedDirs; }
62 int GetNumberHandledFiles() const { return mNumberHandledFiles; }
63 int GetNumberAddedFiles() const { return mNumberAddedFiles; }
65 void IncNumberScannedFiles() { mNumberScannedFiles++; }
66 void IncNumberScannedDirs() { mNumberScannedDirs++; }
67 void IncNumberHandledFiles() { mNumberHandledFiles++; }
68 void IncNumberAddedFiles() { mNumberAddedFiles++; }
70 void SetStop() { mStop = true; }
71 bool GetStop() const { return mStop; }
75 int mNumberScannedFiles;
76 int mNumberScannedDirs;
77 int mNumberHandledFiles;
78 int mNumberAddedFiles;
80 //=============================================
82 //=============================================
83 const Progress& GetProgress() const { return mProgress; }
84 //=============================================
86 //=============================================
87 typedef boost::signal<void (Progress&)> ProgressSignalType;
88 typedef ProgressSignalType::slot_function_type ProgressCallbackType;
89 //=============================================
91 //==================================================================
92 /// Adds the function f to the list of functions to call
93 /// when the addition progresses.
94 /// f is of type ProgressCallbackType which is:
95 /// void (*ProgressCallbackType)(Progress&)
96 /// To pass a member function 'f' of an instance 'c' of a class 'C'
97 /// as callback you have to 'bind' it, i.e. call:
98 /// ConnectProgressObserver ( boost::bind( &C::f , c, _1 ) );
99 void ConnectProgressObserver(ProgressCallbackType callback);
100 //==================================================================
102 //====================================================================
103 /// Returns if the file can be read or not
104 bool IsHandledFile( const std::string& filename);
105 /// Adds a list of files to the TreeHandler
106 void AddFiles( const std::vector<std::string>& filename );
107 /// (Recursively) adds the files of a directory to the TreeHandler
108 void AddDirectory( const std::string& directory,
110 /// Removes a file from the databases
111 void RemoveFile(tree::Node* node);
112 /// Removes files from the databases
113 void RemoveFiles(const std::vector<tree::Node*>& nodes);
114 /// Synchronizes the DB and disk by repeating the operations the user has done and returns a report
115 std::string Synchronize(bool repair, bool checkAttributes);
116 ///Recursively checks if the directory is synchronized and optionally the state of the attributes
117 void CheckSyncDirectory(const std::string &dirpath,
120 bool checkAttributes,
121 std::vector<std::string> &i_ignorefiles,
122 std::vector<std::string> & attsModified,
123 std::vector<std::string> & newfiles);
124 ///Finds the node that matches the specified parameters
125 void FindNode(tree::Node* parent, int level,
126 const std::string& searchParam,
127 const std::string& searchVal,
129 ///Checks the attributes of the database against the ones in disk
130 void CheckAttributes(bool repair, std::string& file, std::vector<std::string>& attsModified);
132 //====================================================================
136 /// Adds a single file to the TreeHandler
137 /// **WITHOUT** testing wether it is handled or not
138 /// hence you have to call IsHandledFile before using AddFile!
139 void AddFile( const std::string& filename );
141 /// Recursive method which does the main job for AddDirectory
142 void AddDirectoryRecursor( const std::string& directory,
144 const std::string &addKey);
146 TreeHandler* mTreeHandler;
147 TimestampDatabaseHandler* mTimestampHandler;
148 Synchronizer* mSynchronizer;
152 ProgressSignalType mProgressSignal;
156 // EO class TreeHandlerImageAdder
157 //=======================================================================
163 } // EO namespace creaImageIO
166 inline std::ostream& operator << ( std::ostream& o,
167 const creaImageIO::TreeHandlerImageAdder::Progress& p)
169 o << p.GetNumberScannedFiles() << " files - "
170 << p.GetNumberScannedDirs() << " dirs - "
171 << p.GetNumberHandledFiles() << " handled -"
172 << p.GetNumberAddedFiles() << " added";