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