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 *******************************************************************************/
23 /*! \file xdxfplugin.h
25 #ifndef STARDICTPLUGIN_H
26 #define STARDICTPLUGIN_H
34 //#include <QXmlStreamReader>
40 #include "../../include/CommonDictInterface.h"
41 #include "../../include/settings.h"
42 #include "StarDictDialog.h"
43 #include "TranslationStarDict.h"
45 class TranslationXdxf;
47 class StarDictPlugin : public CommonDictInterface
50 Q_INTERFACES(CommonDictInterface)
52 StarDictPlugin(QObject *parent=0);
56 //! \returns source language code iso 639-2
57 QString langFrom() const;
59 //! \returns destination language code iso 639-2
60 QString langTo() const;
62 //! \returns dictionary name (like "old English" or so)
65 //! \returns dictionary type (xdxf, google translate, etc)
68 //! returns information about dictionary in xml (name, authors, etc)
69 QString infoNote() const;
71 /*! \returns DictDialog object that creates dialogs
72 for adding a new dictionary and changing plugin settings
74 DictDialog* dictDialog();
76 //! \returns new, clean copy of plugin with settings set as in Settings*
77 CommonDictInterface* getNew(const Settings*) const;
79 //! \returns whether plugin can start searching
80 bool isAvailable() const;
82 //! \returns a description of a word given by a QString
83 QString search(QString key) {
84 return search(key, 0, 0);
87 /*! \return a description of a word given by a QString
88 \param offset offset of translation to be cut out
89 \param len lenght of translation to be cut out
91 QString search(QString key, qint64 offset, qint32 len);
93 //! \returns current plugin settings
96 //! \returns words count in a dictionary
100 bool setSettings(const Settings*);
102 //! \returns plugin icon
105 /*! plugin should delete any files (eg. cache) that have been created and are ready
114 performs search in a dictionary
115 \param word word to search for in a dictionary
116 \param limit limit on number of results
118 After finishing search it has to emit
119 \see CommonDictInterface:finalTranslation finalTranslation
121 QList<Translation*> searchWordList(QString word, int limit=0);
123 //! stops current operation
126 //! loads translations for each plugin only once
133 searches for a list of words similar to a word in a database file
134 \param word key compared with keys in a database
135 \param limit limits the number of translations in returned list,
137 \returns list of translations
139 QList<Translation*> searchWordListCache(QString word, int limit=0);
142 searches for a list of words similar to a word in a xdxf file
143 \param word key compared with keys in a xdxf file
144 \param limit limits the number of translations in returned list,
146 \returns list of translations
148 QList<Translation*> searchWordListFile(QString word, int limit=0);
151 searches for a translation of a word which is exactly like a key
154 QString searchFile(QString key);
156 //! scans dictionary file to get information about it
157 bool getDictionaryInfo();
159 //! counts the keys in a xdxf file
163 //! language from which we translate
165 //! language to which we translate
167 //! name of a dictionary
169 //! information about dictionary
172 //! icon displayed during translations and when a dictionary is chosen
175 //! indicates if search is stopped
176 volatile bool stopped;
178 StarDictDialog* _dictDialog;
179 Settings* _ifoFileSettings;
182 Reads and process (converting to qstring) data from StarDict dictionary
184 \return converted translation
185 \param QByteArray raw data to process
186 \param mode StarDict parametr "sametypesequence"
188 QString format(QByteArray, QString mode,QString key);
191 Reads bytes bytes of data or reads until \0
192 \param it iterator to given data
193 \param end end of data
195 \return readed data chunk
197 QByteArray read(QByteArray::iterator it, QByteArray::iterator end,
201 Interpret data basis on mode (StarDict dict data type)
202 \param it iterator on given data set
203 \param end iterator pointing to the data end
204 \param mode stardict dict data type
205 \param last used to interpret sametypesequence field last letter (see
206 StarDict format description)
207 \return QSting containing interpreted data chunk
209 QString interpret(QByteArray::iterator it, QByteArray::iterator end,
210 QChar mode,QString key, bool last = false);
212 friend class StarDictTests;
215 #endif // XDXFPLUGIN_H