1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 // Created by Bartosz Szatkowski
30 #include <QPluginLoader>
32 #include <QtConcurrentRun>
36 #include "../../includes/CommonDictInterface.h"
37 #include "../../includes/settings.h"
38 #include "../../includes/translation.h"
41 //! Inner part of dictionary - glues together GUI and plugins
42 class Backbone : public QObject
47 Backbone(QObject *parent = 0);
49 Backbone(const Backbone& b);
51 //! \return all loadded dictionaries with activity state flag
52 QHash<CommonDictInterface*, bool> getDictionaries();
54 //! \return all loadded plugins
55 QList<CommonDictInterface*> getPlugins();
57 //! \return history of performed searches
58 QList<QString> getHistory(); //TODO implementation needed (in future)
60 //! \return return search fesult
61 QMultiHash<QString, Translation*> result();
63 //! \return maximum number of word that plugin could find
64 int searchLimit() const;
66 //! \return number of active searches
67 int activeSearches() const;
70 //! stops all current searches
73 //! search for a word translation
74 void search(QString word);
76 //! sets active dictionaries
77 void selectedDictionaries(QList<CommonDictInterface* >);
79 //! adds new dictionary
80 void addDictionary(CommonDictInterface* dict);
83 //! stops all current activity and kill plugins - be ready to exit
87 //! Fired when dictionary call finalTranslation(..) with translation ready
90 void removeDictionary(CommonDictInterface* dict);
91 // TODO addToBookmark(Translation*);
92 // TODO removeFromBookmark(Translation*);
95 //! emmited when backbone is ready to close - after getting stop signal it
96 //! should kill all threads and so on
99 //! emitted when there are search result ready to fetch
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;
112 int _activeSearchNum;
114 int _interval; //Search fetching timer.timeout interval in msec