fix small bug(wildcard), and change some comments
[mdictionary] / src / plugins / stardict / TranslationStarDict.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     \file TranslationStarDict.cpp
23     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
24 */
25
26 #include "TranslationStarDict.h"
27 #include <QDebug>
28
29
30 TranslationStarDict::TranslationStarDict():_key(""),_dictionaryInfo("") {
31     starDictPlugin=0;
32 }
33
34
35 TranslationStarDict::TranslationStarDict(QString _key, QString _dictionaryInfo,
36          StarDictPlugin *starDictPlugin): _key(_key),_dictionaryInfo(_dictionaryInfo) {
37     this->starDictPlugin=starDictPlugin;
38     if(starDictPlugin)
39         _dictHash = starDictPlugin->hash();
40     _bookmark=0;
41 }
42
43
44 TranslationStarDict::TranslationStarDict(const TranslationStarDict &base) {
45     _key = base.key();
46     _dictHash = base._dictHash;
47     _dictionaryInfo = base._dictionaryInfo;
48     lengths = base.lengths;
49     offsets = base.offsets;
50     starDictPlugin = base.starDictPlugin;
51 }
52
53
54 void TranslationStarDict::add(qint64 offset, qint32 len) {
55     offsets.append(offset);
56     lengths.append(len);
57 }
58
59
60 QString TranslationStarDict::key() const {
61     return _key;
62 }
63
64
65 QString TranslationStarDict::toXml() const {
66     QString result("");
67     if(!starDictPlugin)
68         return result;
69
70     for(int i = 0; i < offsets.size(); i++) {
71         result=result + "<dict> <info path=\"/usr/share/mdictionary/stardict.png\" ";
72         if(isBookmark())
73             result+= " bookmark=\"true\" > \n";
74         else
75             result+= " bookmark=\"false\" > \n";
76             if(_dictionaryInfo.isEmpty())
77                 result+= "starDict dictionary </info>";
78             else
79                 result+= _dictionaryInfo +"</info>";
80
81             /*conwert returned string to XML format*/
82             result+=starDictPlugin->search(_key, offsets.at(i), lengths.at(i));
83             result+= "</dict>";
84    }
85    return result;
86 }
87
88
89 void TranslationStarDict::setKey(QString _key) {
90     this->_key=_key;
91 }
92
93
94 void TranslationStarDict::setDictionaryInfo(QString _dictionaryInfo) {
95     this->_dictionaryInfo=_dictionaryInfo;
96 }
97