Backbone branch with some initial code
[mdictionary] / trunk / src / base / backbone / backbone.cpp
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
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.
9
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.
14
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/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 // Created by Bartosz Szatkowski
23
24 #include "backbone.h"
25
26 Backbone::Backbone(QObject *parent)
27     : QObject(parent)
28 {
29    searchLimitv = 10;
30 }
31
32 Backbone::~Backbone()
33 {
34
35 }
36
37 Backbone::Backbone(const Backbone &b) {
38     dicts = QList<CommonDictInterface* > (b.dicts);
39     plugins = QList<CommonDictInterface* > (b.plugins);
40     resultv = QHash<QString, Translation* > (b.resultv);
41 }
42
43 int Backbone::searchLimit() {
44     return searchLimitv;
45 }
46
47 QHash<const CommonDictInterface*, bool > Backbone::getDictionaries() {
48     return dicts;
49 }
50
51 QList<const CommonDictInterface* > Backbone::getPlugins() {
52     return plugins;
53 }
54
55 QHash<QString, Translation*> Backbone::result() {
56     return resultv;
57 }
58
59 void Backbone::stopSearching() {
60     foreach(CommonDictInterface* dict, dicts)
61         dict->stop();
62 }
63
64 void Backbone::search(QString word) {
65     //TODO add running searches in new threads
66     foreach(CommonDictInterface* dict, dicts)
67         dict->search(word, searchLimit());
68 }
69
70  void Backbone::selectedDictionaries(QList<CommonDictInterface* > activeDicts) {
71      foreach(CommonDictInterface* dict, dicts.keys())
72          if(activeDicts.contains(dict))
73              dicts[dict] = 1;
74          else
75              dicts[dict] = 0;
76  }
77
78
79