Added context menu to TranslationWidget
[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 "../../includes/CommonDictInterface.h"
32 #include "../../includes/settings.h"
33 #include "../../includes/translation.h"
34
35
36 //! Inner part of dictionary - glues together GUI and plugins
37 class Backbone : public QObject
38 {
39     Q_OBJECT
40
41 public:
42     Backbone(QObject *parent = 0);
43     ~Backbone();
44     Backbone(const Backbone& b);
45
46     //! \return all loadded dictionaries with activity state flag
47     QHash<CommonDictInterface*, bool> getDictionaries();
48
49     //! \return all loadded plugins
50     QList<CommonDictInterface*> getPlugins();
51
52     //! \return history of performed searches
53     QList<QString> getHistory(); //TODO implementation needed (in future)
54
55     //! \return return search fesult
56     QMultiHash<QString, Translation*> result();
57
58     //! \return maximum number of word that plugin could find
59     int searchLimit() const;
60
61     //! \return number of active searches
62     int activeSearches() const;
63
64 public Q_SLOTS:
65     //! stops all current searches
66     void stopSearching();
67
68     //! search for a word translation
69     void search(QString word);
70
71     //! sets active dictionaries
72     void selectedDictionaries(QList<CommonDictInterface* >);
73
74     //! adds new dictionary
75     void addDictionary(CommonDictInterface* dict);
76
77
78     //! stops all current activity and kill plugins - be ready to exit
79     void quit();
80
81
82     //! Fired when dictionary call finalTranslation(..) with translation ready
83     void translation(QList<Translation*>);
84
85     // TODO void removeDictionary(CommonDictInterface* dict);
86     // TODO addToBookmark(Translation*);
87     // TODO removeFromBookmark(Translation*);
88
89 Q_SIGNALS:
90     //! emmited when backbone is ready to close - after getting stop signal it
91     //!     should kill all threads and so on
92     void closeOk();
93
94     //! emitted when there are search result ready to fetch
95     void ready();
96
97
98
99 private:
100     void loadPlugins(); //< locate and load plugins
101     QHash<CommonDictInterface*, bool> dicts;
102     QList<CommonDictInterface*> plugins;
103     QMultiHash<QString, Translation*> _result;
104     int searchLimitv;
105     int activeSearchNum;
106
107 };
108
109 #endif // BACKBONE_H