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 <QSqlDatabase>
37 #include <QXmlStreamReader>
43 #include "../../include/CommonDictInterface.h"
44 #include "../../include/settings.h"
45 #include "StarDictDialog.h"
46 #include "TranslationStarDict.h"
48 class TranslationXdxf;
50 class StarDictPlugin : public CommonDictInterface
53 Q_INTERFACES(CommonDictInterface)
55 StarDictPlugin(QObject *parent=0);
59 //! \returns source language code iso 639-2
60 QString langFrom() const;
62 //! \returns destination language code iso 639-2
63 QString langTo() const;
65 //! \returns dictionary name (like "old English" or so)
68 //! \returns dictionary type (xdxf, google translate, etc)
71 //! returns information about dictionary in xml (name, authors, etc)
72 QString infoNote() const;
74 /*! \returns DictDialog object that creates dialogs
75 for adding a new dictionary and changing plugin settings
77 DictDialog* dictDialog();
79 //! \returns new, clean copy of plugin with settings set as in Settings*
80 CommonDictInterface* getNew(const Settings*) const;
82 //! \returns whether plugin can start searching
83 bool isAvailable() const;
85 //! \returns a description of a word given by a QString
86 QString search(QString key) {
87 return search(key, 0, 0);
90 /*! \return a description of a word given by a QString
91 \param offset offset of translation to be cut out
92 \param len lenght of translation to be cut out
94 QString search(QString key, qint64 offset, qint32 len);
96 //! \returns current plugin settings
99 //! \returns words count in a dictionary
102 //! Sets new settings
103 bool setSettings(const Settings*);
105 //! \returns plugin icon
108 /*! plugin should delete any files (eg. cache) that have been created and are ready
116 /*! performs search in a dictionary
117 \param word word to search for in a dictionary
118 \param limit limit on number of results
120 After finishing search it has to emit
121 \see CommonDictInterface:finalTranslation finalTranslation
123 QList<Translation*> searchWordList(QString word, int limit=0);
125 //! stops current operation
128 //! loads translations for each plugin only once
134 /*! \returns true or false depending on whether the dictionary is cached
138 /*! searches for a list of words similar to a word in a database file
139 \param word key compared with keys in a database
140 \param limit limits the number of translations in returned list,
142 \returns list of translations
144 QList<Translation*> searchWordListCache(QString word, int limit=0);
146 /*! searches for a list of words similar to a word in a xdxf file
147 \param word key compared with keys in a xdxf file
148 \param limit limits the number of translations in returned list,
150 \returns list of translations
152 QList<Translation*> searchWordListFile(QString word, int limit=0);
154 /*! searches for a translation of a word which is exactly like a key
156 QString searchFile(QString key);
158 //! scans dictionary file to get information about it
159 bool getDictionaryInfo();
161 //! counts the keys in a xdxf file
165 //! language from which we translate
167 //! language to which we translate
169 //! name of a dictionary
171 //! information about dictionary
174 QString _dictionaryInfo;
176 //! icon displayed during translations and when a dictionary is chosen
179 //! number of words in a dictionary
181 //! indicates if search is stopped
182 volatile bool stopped;
184 StarDictDialog* _dictDialog;
185 Settings* _ifoFileSettings;
186 StarDictReader * dictReader;
188 /*! Reads and process (converting to qstring) data from StarDict dictionary
190 \return converted translation
191 \param QByteArray raw data to process
192 \param mode StarDict parametr "sametypesequence" */
193 QString format(QByteArray, QString mode,QString key);
195 /*! Reads bytes bytes of data or reads until \0
196 \param it iterator to given data
197 \param end end of data
199 \return readed data chunk*/
200 QByteArray read(QByteArray::iterator it, QByteArray::iterator end,
203 /*! Interpret data basis on mode (StarDict dict data type)
204 \param it iterator on given data set
205 \param end iterator pointing to the data end
206 \param mode stardict dict data type
207 \param last used to interpret sametypesequence field last letter (see
208 StarDict format description)
209 \return QSting containing interpreted data chunk */
210 QString interpret(QByteArray::iterator it, QByteArray::iterator end,
211 QChar mode,QString key, bool last = false);
214 #endif // XDXFPLUGIN_H