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)
36 QListIterator<CommonDictInterface*> it(dicts.keys());
41 it = QListIterator<CommonDictInterface*>(plugins);
45 QHashIterator<QString, Translation*> it2(_result);
47 delete it2.next().value();
54 Backbone::Backbone(const Backbone &b) :QObject(b.parent()) {
55 dicts = QHash<CommonDictInterface*, bool > (b.dicts);
56 plugins = QList<CommonDictInterface* > (b.plugins);
57 _result = QHash<QString, Translation* > (b._result);
58 searchLimitv = b.searchLimit();
64 int Backbone::searchLimit() const {
71 QHash<CommonDictInterface*, bool > Backbone::getDictionaries() {
78 QList<CommonDictInterface* > Backbone::getPlugins() {
85 QList<QString> Backbone::getHistory() {
92 QMultiHash<QString, Translation*> Backbone::result() {
99 void Backbone::stopSearching() {
100 foreach(CommonDictInterface* dict, dicts.keys())
107 void Backbone::search(QString word) {
108 //TODO add running searches in new threads
111 foreach(CommonDictInterface* dict, dicts.keys())
112 if(dicts[dict] == 1) {
116 foreach(CommonDictInterface* dict, dicts.keys())
117 if(dicts[dict] == 1) {
118 dict->search(word, searchLimit());
125 void Backbone::selectedDictionaries(QList<CommonDictInterface* > activeDicts) {
126 foreach(CommonDictInterface* dict, dicts.keys())
127 if(activeDicts.contains(dict))
136 void Backbone::addDictionary(CommonDictInterface* dict) {
138 connect(dict, SIGNAL(finalTranslation(QList<Translation*>)),
139 this, SLOT(translation(QList<Translation*>)),
140 Qt::UniqueConnection);
145 void Backbone::quit() {
152 int Backbone::activeSearches() const {
153 return activeSearchNum;
158 void Backbone::translation(QList<Translation *> trans) {
160 foreach(Translation* t, trans)
161 _result.insert(t->key(), t);
163 if(activeSearchNum < 1)
170 void Backbone::loadPlugins() {
171 QObject *pl = QPluginLoader("xdxf.so").instance();
174 CommonDictInterface *plugin = qobject_cast<CommonDictInterface*>(pl);
175 plugins.append(plugin);
176 addDictionary(plugin);