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