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
26 Backbone::Backbone(QObject *parent)
37 QListIterator<CommonDictInterface*> it(dicts.keys());
42 it = QListIterator<CommonDictInterface*>(plugins);
46 QHashIterator<QString, Translation*> it2(_result);
48 delete it2.next().value();
55 Backbone::Backbone(const Backbone &b) :QObject(b.parent()) {
56 dicts = QHash<CommonDictInterface*, bool > (b.dicts);
57 plugins = QList<CommonDictInterface* > (b.plugins);
58 _result = QHash<QString, Translation* > (b._result);
59 searchLimitv = b.searchLimit();
65 int Backbone::searchLimit() const {
72 QHash<CommonDictInterface*, bool > Backbone::getDictionaries() {
79 QList<CommonDictInterface* > Backbone::getPlugins() {
86 QList<QString> Backbone::getHistory() {
93 QMultiHash<QString, Translation*> Backbone::result() {
100 void Backbone::stopSearching() {
101 foreach(CommonDictInterface* dict, dicts.keys())
108 void Backbone::search(QString word) {
109 //TODO add running searches in new threads
112 foreach(CommonDictInterface* dict, dicts.keys())
113 if(dicts[dict] == 1) {
117 foreach(CommonDictInterface* dict, dicts.keys())
118 if(dicts[dict] == 1) {
119 dict->searchWordList(word, searchLimit());
126 void Backbone::selectedDictionaries(QList<CommonDictInterface* > activeDicts) {
127 foreach(CommonDictInterface* dict, dicts.keys())
128 if(activeDicts.contains(dict))
137 void Backbone::addDictionary(CommonDictInterface* dict) {
139 connect(dict, SIGNAL(finalTranslation(QList<Translation*>)),
140 this, SLOT(translation(QList<Translation*>)),
141 Qt::UniqueConnection);
146 void Backbone::quit() {
153 int Backbone::activeSearches() const {
154 return activeSearchNum;
159 void Backbone::translation(QList<Translation *> trans) {
161 foreach(Translation* t, trans)
162 _result.insert(t->key(), t);
164 if(activeSearchNum < 1)
171 void Backbone::loadPlugins() {
172 QPluginLoader loader("xdxf.so");
175 qDebug()<<loader.errorString();
178 QObject *pl = loader.instance();
181 CommonDictInterface *plugin = qobject_cast<CommonDictInterface*>(pl);
182 plugins.append(plugin);
183 addDictionary(plugin);