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>
37 #include "../../includes/CommonDictInterface.h"
38 #include "../../includes/settings.h"
39 #include "../../includes/translation.h"
42 /*! Inner part of dictionary - glues together GUI and plugins
44 Backbone is responsible for managing plugins and dictionaries, starting
45 new searches and threads, merging search results from multiple dictionaries.
47 Each plugin may live in multiple instances - each with its own dictionary,
48 backbone must provide way to create them at start (with specific Settings) and
49 distinguich each ditionary.
52 class Backbone : public QObject
57 /*!\param pluginPath path to plugins (leave blank for default)
58 \param configPath path to folder with configuration files*/
59 Backbone(QString pluginPath="", QString configPath="", QObject *parent = 0);
61 Backbone(const Backbone& b);
63 //! \return all loadded dictionaries with activity state flag
64 QHash<CommonDictInterface*, bool> getDictionaries();
66 //! \return all loadded plugins
67 QList<CommonDictInterface*> getPlugins();
69 //! \return history of performed searches
70 QList<QString> getHistory(); //TODO implementation needed (in future)
72 //! \return return search fesult
73 QMultiHash<QString, Translation*> result();
75 //! \return maximum number of word that plugin could find
76 int searchLimit() const;
78 //! \return number of active searches
79 int activeSearches() const;
81 /*! Performs search for final translation (html/xml) form
82 \param list of Translation* to be searched for
84 void searchHtml(QList<Translation*>);
86 //! \return final translation (after searching for html)
91 //! stops all current searches
94 /*! search for a word translation
95 \param word list of words to be translated
97 void search(QStringList word);
99 /*! sets active dictionaries (searches are performed only in active dicts
100 \param List of dictionaris to be activated
102 void selectedDictionaries(QList<CommonDictInterface* >);
104 /*! adds new dictionary and activate it
105 \param dict dictionary to be added
106 \param active decides whether searches are perfomed in given dictionaries
108 void addDictionary(CommonDictInterface* dict, bool active = 1);
111 //! stops all current activity - emiting signal \see closeOk
115 /*! Fired with given interval during searches -
116 checking if translation is ready
118 void translationReady();
120 /*! Fired with given interval during html searches -
121 checking if html is ready
123 void htmlTranslationReady();
125 /*! Removes given dictionary
126 \param dict dictionary to be deleted
128 void removeDictionary(CommonDictInterface* dict);
130 /*! saves plugins new state/configuration after each change */
133 // TODO addToBookmark(Translation*);
134 // TODO removeFromBookmark(Translation*);
137 /*! emmited when backbone is ready to close - after getting stop signal it
138 should kill all threads and so on */
141 //! emitted when there are search result ready to fetch
144 //! emitted when html result is ready to fetch
150 QHash<CommonDictInterface*, bool> _dicts;
151 QList<CommonDictInterface*> _plugins;
152 QList<QFuture<QList<Translation*> > > _innerResult;
153 QList<QFuture<QString> > _innerHtmlResult;
154 QMultiHash<QString, Translation*> _result;
155 QStringList _htmlResult;
156 QTimer _timerSearch, _timerHtmlSearch;
161 int _activeSearchNum;
162 int _interval; //Search fetching timer.timeout interval in msec
166 QStringList getFilesFromDir(QString dir, QStringList nameFilter);
167 void loadPlugins(); //< locate and load plugins
170 void saveState(QSettings*, Settings*, bool, uint);
171 void addInternalDictionary(CommonDictInterface*, bool);
172 CommonDictInterface* plugin(QString type); //< search for given type plugin
173 //void writeConfig(QString key, QString value);