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
43 Backbone is responsible for managing plugins and dictionaries, starting
44 new searches and threads, merging search results from multiple dictionaries.
46 Each plugin may live in multiple instances - each with its own dictionary,
47 backbone must provide way to create them at start (with specific Settings) and
48 distinguich each ditionary.
51 class Backbone : public QObject
56 /*!\param pluginPath path to plugins (leave blank for default)
57 \param configPath path to folder with configuration files*/
58 Backbone(QString pluginPath="", QString configPath="", QObject *parent = 0);
60 Backbone(const Backbone& b);
62 //! \return all loadded dictionaries with activity state flag
63 QHash<CommonDictInterface*, bool> getDictionaries();
65 //! \return all loadded plugins
66 QList<CommonDictInterface*> getPlugins();
68 //! \return history of performed searches
69 QList<QString> getHistory(); //TODO implementation needed (in future)
71 //! \return return search fesult
72 QMultiHash<QString, Translation*> result();
74 //! \return maximum number of word that plugin could find
75 int searchLimit() const;
77 //! \return number of active searches
78 int activeSearches() const;
81 //! stops all current searches
84 /*! search for a word translation
85 \param word word to be translated
87 void search(QString word);
89 /*! sets active dictionaries (searches are performed only in active dicts
90 \param List of dictionaris to be activated
92 void selectedDictionaries(QList<CommonDictInterface* >);
94 /*! adds new dictionary and activate it
95 \param dict dictionary to be added
97 void addDictionary(CommonDictInterface* dict);
100 //! stops all current activity - emiting signal \see closeOk
104 /*! Fired with given interval during searches -
105 checking if translation is ready
109 /*! Removes given dictionary
110 \param dict dictionary to be deleted
112 void removeDictionary(CommonDictInterface* dict);
114 // TODO addToBookmark(Translation*);
115 // TODO removeFromBookmark(Translation*);
118 /*! emmited when backbone is ready to close - after getting stop signal it
119 should kill all threads and so on */
122 //! emitted when there are search result ready to fetch
128 QHash<CommonDictInterface*, bool> _dicts;
129 QList<CommonDictInterface*> _plugins;
130 QList<QFuture<QList<Translation*> > > _innerResult;
131 QMultiHash<QString, Translation*> _result;
134 int _activeSearchNum;
136 int _interval; //Search fetching timer.timeout interval in msec
141 QStringList getFilesFromDir(QString dir, QStringList nameFilter);
142 void loadPlugins(); //< locate and load plugins
143 //void writeConfig(QString key, QString value);