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
34 #include <QSqlDatabase>
37 #include <QXmlStreamReader>
41 #include "../../include/CommonDictInterface.h"
42 #include "../../include/settings.h"
43 #include "XdxfDictDialog.h"
44 #include "XdxfCachingDialog.h"
45 #include "TranslationXdxf.h"
46 #include "XdxfDictDownloader.h"
48 class TranslationXdxf;
50 class XdxfPlugin : public CommonDictInterface
53 Q_INTERFACES(CommonDictInterface)
55 XdxfPlugin(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);
88 //! \returns current plugin settings
91 //! \returns words count in a dictionary
95 bool setSettings(const Settings*);
97 //! \returns plugin icon
100 /*! plugin should delete any files (eg. cache) that have been created and are ready
105 static XdxfDictDownloader dictDownloader;
108 /*! performs search in a dictionary
109 \param word word to search for in a dictionary
110 \param limit limit on number of results
112 After finishing search it has to emit
113 \see CommonDictInterface:finalTranslation finalTranslation
115 QList<Translation*> searchWordList(QString word, int limit=0);
117 //! stops current operation
120 //! loads translations for each plugin only once
124 //! emitted with percent count of caching progress, and time elapsed from
126 void updateCachingProgress(int, int);
131 /*! \returns true or false depending on whether the dictionary is cached
135 /*! searches for a list of words similar to a word in a database file
136 \param word key compared with keys in a database
137 \param limit limits the number of translations in returned list,
139 \returns list of translations
141 QList<Translation*> searchWordListCache(QString word, int limit=0);
143 /*! searches for a list of words similar to a word in a xdxf file
144 \param word key compared with keys in a xdxf file
145 \param limit limits the number of translations in returned list,
147 \returns list of translations
149 QList<Translation*> searchWordListFile(QString word, int limit=0);
151 /*! searches for a translation of a word which is exactly like a key
153 QString searchFile(QString key);
155 /*! searches for a translation of a word which is exactly like a key
156 in a database file */
157 QString searchCache(QString key);
159 //! scans dictionary file to get information about it
160 bool getDictionaryInfo();
162 //! counts the keys in a xdxf file
165 /*! transforms xdxf files to database files (caching operation)
166 \returns true on success, false on failure */
167 bool makeCache(QString dir);
169 //! language from which we translate
171 //! language to which we translate
173 //! name of a dictionary
175 //! information about dictionary
178 QString _dictionaryInfo;
180 //! icon displayed during translations and when a dictionary is chosen
184 //! number of words in a dictionary
186 //! indicates if search is stopped
187 volatile bool stopped;
189 XdxfDictDialog* _dictDialog;
190 XdxfCachingDialog* cachingDialog;
193 #endif // XDXFPLUGIN_H