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 \brief Implementation of xdxf plugin's main class.
25 \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
36 #include <QSqlDatabase>
39 #include <QXmlStreamReader>
43 #include "../../include/CommonDictInterface.h"
44 #include "../../include/settings.h"
45 #include "XdxfDictDialog.h"
46 #include "XdxfCachingDialog.h"
47 #include "TranslationXdxf.h"
48 #include "XdxfDictDownloader.h"
50 class TranslationXdxf;
52 class XdxfPlugin : public CommonDictInterface
55 Q_INTERFACES(CommonDictInterface)
57 XdxfPlugin(QObject *parent=0);
60 //! \returns source language code iso 639-2
61 QString langFrom() const;
63 //! \returns destination language code iso 639-2
64 QString langTo() const;
66 //! \returns dictionary name (like "old English" or so)
69 //! \returns dictionary type (xdxf, google translate, etc)
72 //! \returns information about dictionary in xml (name, authors, etc)
73 QString infoNote() const;
76 \returns DictDialog object that creates dialogs
77 for adding a new dictionary and changing plugin settings
79 DictDialog* dictDialog();
81 //! \returns new, clean copy of plugin with settings set as in Settings*
82 CommonDictInterface* getNew(const Settings*) const;
84 //! \returns whether plugin can start searching
85 bool isAvailable() const;
87 //! \returns a description of a word given by a QString
88 QString search(QString key);
90 //! \returns current plugin settings
93 //! \returns words count in a dictionary
97 bool setSettings(const Settings*);
99 //! \returns plugin icon
102 //! \returns plugin icon's resource path
106 plugin should delete any files (eg. cache) that have been created and are ready
111 static XdxfDictDownloader dictDownloader;
115 performs search in a dictionary
116 \param word word to search for in a dictionary
117 \param limit limit on number of results
119 After finishing search it has to emit
120 \see CommonDictInterface:finalTranslation finalTranslation
122 QList<Translation*> searchWordList(QString word, int limit=0);
124 //! stops current operation
127 //! loads translations for each plugin only once
131 //! emitted with percent count of caching progress, and time elapsed from
133 void updateCachingProgress(int, int);
137 \returns true or false depending on whether the dictionary is cached
142 searches for a list of words similar to a word in a database file
143 \param word key compared with keys in a database
144 \param limit limits the number of translations in returned list,
146 \returns list of translations
148 QList<Translation*> searchWordListCache(QString word, int limit=0);
151 searches for a list of words similar to a word in a xdxf file
152 \param word key compared with keys in a xdxf file
153 \param limit limits the number of translations in returned list,
155 \returns list of translations
157 QList<Translation*> searchWordListFile(QString word, int limit=0);
160 searches for a translation of a word which is exactly like a key
163 QString searchFile(QString key);
166 searches for a translation of a word which is exactly like a key
169 QString searchCache(QString key);
171 //! scans dictionary file to get information about it
172 bool getDictionaryInfo();
174 //! counts the keys in a xdxf file
178 transforms xdxf files to database files (caching operation)
179 \returns true on success, false on failure
181 bool makeCache(QString dir);
183 static bool dictDownloaderInitialized;
189 QString _dictionaryInfo;
196 volatile bool stopped;
198 XdxfDictDialog* _dictDialog;
199 XdxfCachingDialog* cachingDialog;
202 #endif // XDXFPLUGIN_H