]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmick.h
Remove timestamp_database and timestamp files (now management only with maintenance_d...
[creaImageIO.git] / src2 / creaImageIOGimmick.h
1 #ifndef __creaImageIOGimmick_h_INCLUDED__
2 #define __creaImageIOGimmick_h_INCLUDED__
3
4 #include <creaImageIOSQLiteTreeHandler.h>
5 #include <creaImageIOTreeHandlerImageAdder.h>
6 #include <creaImageIOSynchron.h>
7 #include <creaImageIOSettings.h>
8
9 namespace creaImageIO
10 {
11         /**
12         * \defgroup Controller Controller
13         */
14         /**
15         * \defgroup View View
16         */
17         /**
18         * \defgroup Model Model
19         */
20         /**
21         * \defgroup GUI Top level graphical user interfaces
22         */
23         /**
24         * \defgroup IO Image I/O classes
25         */
26         /**
27         * \defgroup Tree Attributed tree management
28         */
29         /**
30         * \defgroup Previewer Preview related
31         */
32
33         /**
34         * \ingroup Controller
35         */
36
37   //=======================================================================
38   /// Central controler of the gimmick application
39   class CREAIMAGEIO_EXPORT Gimmick
40   {
41   public:
42     /// Ctor
43     Gimmick();
44     /// Dtor
45     ~Gimmick();
46     
47     ///
48     typedef TreeHandlerImageAdder::Progress AddProgress;
49     typedef TreeHandlerImageAdder::ProgressCallbackType AddProgressCallbackType;
50     
51     /// Adds the function f to the list of functions to call 
52     /// when addition operations progres.
53     /// f is of type AddProgressCallbackType which is:
54     /// void (*AddProgressCallbackType)(AddProgress&)
55     /// To pass a member function 'f' of an instance 'c' of a class 'C' 
56     /// as callback you have to 'bind' it, i.e. call:
57     /// ConnectAddProgressObserver ( boost::bind( &C::f , c, _1 ) );
58      void ConnectAddProgressObserver( AddProgressCallbackType callback )
59     { mImageAdder.ConnectProgressObserver(callback); }
60     
61
62     ///
63     const AddProgress& GetAddProgress() const { return mImageAdder.GetProgress(); }
64
65     /// Initializes with default values (read/creates databases, etc.)
66     void Initialize();
67
68         /// Initializes with the local database descriptor in the path given (read/creates databases, etc.)
69     void Initialize(const std::string& path);
70     
71     /// Finalize (closes databases, etc.)
72     void Finalize();
73
74     /// Sets level for messages "Gimmick!" 
75     static void SetMessageLevel(int level);
76     /// Sets level for debug messages "Gimmick! DEBUG" 
77     static void SetDebugMessageLevel(int level);
78     
79     /// Type of map from TreeHandler name to TreeHandler*
80     typedef std::map<std::string, TreeHandler*> TreeHandlerMapType;
81
82     /// Returns the TreeHandlerMap (ref)
83     TreeHandlerMapType& GetTreeHandlerMap() { return mTreeHandlerMap; }
84     /// Returns the TreeHandlerMap (const ref)
85     const TreeHandlerMapType& GetTreeHandlerMap() const
86     { return mTreeHandlerMap; }
87     
88
89     /// Add the files to the given TreeHandler
90     void AddFiles(const std::string& handler,
91                   const std::vector<std::string>& filenames);
92
93     /// Add a dir to the given TreeHandler
94     void AddDir(const std::string& handler, const std::string& path, 
95                 bool recurse);
96
97         /// Removes a file from the given TreeHandler
98         void RemoveFile(const std::string& d, 
99                         tree::Node* filename);
100
101         ///Deletes the given drive name from the databases
102         void DeleteDrive(const std::string& drive);
103   
104
105         /// Copies the files into the local directory
106         void CopyFiles(const std::vector<std::string>& filenames, const std::string& d );
107   
108
109         ///Synchronizes the loaded data with the database d. If repair is true the database will be updated, otherwise 
110         ///only a warning sign will be issued
111         std::string Synchronize(const std::string& d, bool repair, bool checkAttributes);
112
113     /// Prints the tree handled by the handler
114     void Print(const std::string& handler);
115         
116     ///create a DB from a given descriptor file and for a specific location
117     SQLiteTreeHandler *createDB(const std::string &i_name, 
118                                 const std::string &i_locDesc, 
119                                 const std::string &i_locDB);
120
121         /// add an existent DB 
122         void addDB(const std::string &i_nameDB, const std::string &i_locationDB);
123
124     /// Returns the TreeHandler with a given name
125     TreeHandler* GetTreeHandler(const std::string& name) const;
126
127         /// 
128     SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
129
130     const SQLiteTreeHandler* GetLocalDatabase() const 
131     { return mLocalDatabase; }
132
133         ///Returns the given setting value for the given setting parameter
134         void GetSetting(const std::string& name, std::string& value);
135
136         ///Updates the settings file
137         void UpdateSetting(const std::string& name, const std::string& value);
138
139         /// add DB from Settings file
140     void addDBSettings();
141
142         ///Edits the field described by the name and key provided with the value given
143         void EditField(tree::Node* node, const std::string& d, const std::string& name, const std::string& key, const std::string& val);
144
145         /// Returns the attributes in results described in params
146         void GetAttributes(const std::string& d, 
147           const std::string& filename, 
148           const std::vector<std::string>& params, 
149           std::vector<std::string>& results);
150   
151     /// 
152     const std::string& GetHomeDirectory();
153     const std::string& GetUserSettingsDirectory();
154     void CreateUserSettingsDirectory();
155     const std::string& GetLocalDatabasePath();
156         
157
158
159     //=============================================
160   private:
161     SQLiteTreeHandler* mLocalDatabase;
162         TreeHandlerMapType mTreeHandlerMap;
163         Synchronizer* mSynchronizer;
164
165     std::string mCurrentDirectory;
166     std::string mHomeDirectory;
167     std::string mUserSettingsDirectory;
168     std::string mLocalDatabasePath;
169         Settings        *mSettings;
170     TreeHandlerImageAdder mImageAdder;
171   };
172   // EO class Gimmick
173   //=======================================================================
174
175
176 } // EO namespace creaImageIO
177
178 // EOF
179 #endif  
180
181