]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmick.h
Added Add DataBase event.
[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 <creaImageIOTimestampDatabaseHandler.h>
7 #include <creaImageIOSynchronizer.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 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     /// Initialize (read/creates databases, etc.)
66     void Initialize();
67     
68     /// Finalize (closes databases, etc.)
69     void Finalize();
70
71     /// Sets level for messages "Gimmick!" 
72     static void SetMessageLevel(int level);
73     /// Sets level for debug messages "Gimmick! DEBUG" 
74     static void SetDebugMessageLevel(int level);
75     
76     /// Type of map from TreeHandler name to TreeHandler*
77     typedef std::map<std::string, TreeHandler*> TreeHandlerMapType;
78
79     /// Returns the TreeHandlerMap (ref)
80     TreeHandlerMapType& GetTreeHandlerMap() { return mTreeHandlerMap; }
81     /// Returns the TreeHandlerMap (const ref)
82     const TreeHandlerMapType& GetTreeHandlerMap() const
83     { return mTreeHandlerMap; }
84     
85
86     /// Add the files to the given TreeHandler
87     void AddFiles(const std::string& handler,
88                   const std::vector<std::string>& filenames);
89
90     /// Add a dir to the given TreeHandler
91     void AddDir(const std::string& handler, const std::string& path, 
92                 bool recurse);
93
94         ///Synchronizes the loaded data with the database. If remove is true the database will be updated, otherwise 
95         ///only a warning sign will be issued
96         void Synchronize(bool update, TreeHandler* handler);
97
98     /// Prints the tree handled by the handler
99     void Print(const std::string& handler);
100         
101         ///create a DB from a given descriptor file and for a specific location
102         SQLiteTreeHandler *createDB(std::string &i_locDesc, std::string &i_locDB);
103
104         // add an existent DB 
105         void addDB(std::string &i_nameDB, std::string &i_locationDB);
106
107     /// Returns the TreeHandler with a given name
108     TreeHandler* GetTreeHandler(const std::string& name) const;
109
110         /// Returns the TimestampDatabase
111         TimestampDatabaseHandler* GetTimestampDatabase() const;
112     /// 
113     SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
114
115     const SQLiteTreeHandler* GetLocalDatabase() const 
116     { return mLocalDatabase; }
117
118     
119
120     /// 
121     const std::string& GetHomeDirectory();
122     const std::string& GetUserSettingsDirectory();
123     void CreateUserSettingsDirectory();
124     const std::string& GetLocalDatabasePath();
125         const std::string& GetTimestampDatabasePath();
126
127
128     //=============================================
129   private:
130     SQLiteTreeHandler* mLocalDatabase;
131         TimestampDatabaseHandler* mTimestampDatabase;
132     TreeHandlerMapType mTreeHandlerMap;
133         Synchronizer* mSynchronizer;
134
135     std::string mCurrentDirectory;
136     std::string mHomeDirectory;
137     std::string mUserSettingsDirectory;
138     std::string mLocalDatabasePath;
139         std::string mTimestampDatabasePath;
140
141     TreeHandlerImageAdder mImageAdder;
142   };
143   // EO class Gimmick
144   //=======================================================================
145
146
147 } // EO namespace creaImageIO
148
149 // EOF
150 #endif  
151
152