Added Backbone::removeDicitionary and tests for it
[mdictionary] / trunk / src / base / backbone / backbone.h
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 // Created by Bartosz Szatkowski
23
24 #ifndef BACKBONE_H
25 #define BACKBONE_H
26
27 #include <QObject>
28 #include <QList>
29 #include <QHash>
30 #include <QPluginLoader>
31 #include <QFuture>
32 #include <QtConcurrentRun>
33 #include <QTimer>
34 #include <QTime>
35 #include <QDir>
36 #include "../../includes/CommonDictInterface.h"
37 #include "../../includes/settings.h"
38 #include "../../includes/translation.h"
39
40
41 //! Inner part of dictionary - glues together GUI and plugins
42 class Backbone : public QObject
43 {
44     Q_OBJECT
45
46 public:
47     Backbone(QObject *parent = 0);
48     ~Backbone();
49     Backbone(const Backbone& b);
50
51     //! \return all loadded dictionaries with activity state flag
52     QHash<CommonDictInterface*, bool> getDictionaries();
53
54     //! \return all loadded plugins
55     QList<CommonDictInterface*> getPlugins();
56
57     //! \return history of performed searches
58     QList<QString> getHistory(); //TODO implementation needed (in future)
59
60     //! \return return search fesult
61     QMultiHash<QString, Translation*> result();
62
63     //! \return maximum number of word that plugin could find
64     int searchLimit() const;
65
66     //! \return number of active searches
67     int activeSearches() const;
68
69 public Q_SLOTS:
70     //! stops all current searches
71     void stopSearching();
72
73     //! search for a word translation
74     void search(QString word);
75
76     //! sets active dictionaries
77     void selectedDictionaries(QList<CommonDictInterface* >);
78
79     //! adds new dictionary
80     void addDictionary(CommonDictInterface* dict);
81
82
83     //! stops all current activity and kill plugins - be ready to exit
84     void quit();
85
86
87     //! Fired when dictionary call finalTranslation(..) with translation ready
88     void translation();
89
90     void removeDictionary(CommonDictInterface* dict);
91     // TODO addToBookmark(Translation*);
92     // TODO removeFromBookmark(Translation*);
93
94 Q_SIGNALS:
95     //! emmited when backbone is ready to close - after getting stop signal it
96     //!     should kill all threads and so on
97     void closeOk();
98
99     //! emitted when there are search result ready to fetch
100     void ready();
101
102
103
104 private:
105     void loadPlugins(); //< locate and load plugins
106     QHash<CommonDictInterface*, bool> _dicts;
107     QList<CommonDictInterface*> _plugins;
108     QList<QFuture<QList<Translation*> > > _innerResult;
109     QMultiHash<QString, Translation*> _result;
110     QTimer _timer;
111     int _searchLimit;
112     int _activeSearchNum;
113     QTime _time;
114     int _interval; //Search fetching timer.timeout interval in msec
115     QString _pluginPath;
116
117     void init();
118
119 };
120
121 #endif // BACKBONE_H