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