1 /*****************************************************************************
2 * dictplugin.h - QStarDict, a StarDict clone written using Qt *
3 * Copyright (C) 2008 Alexander Rodin *
5 * This program 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 2 of the License, or *
8 * (at your option) any later version. *
10 * This program 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 along *
16 * with this program; if not, write to the Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18 *****************************************************************************/
24 #include <QStringList>
26 #include <QCoreApplication>
33 * This is a base class for all dictionary plugins classes.
39 * This enum describes a features of dictionary plugin.
48 * Dictionary plugin can search for similar words using
53 * Dictionary plugin has a settings dialog.
55 SettingsDialog = 0x02,
57 Q_DECLARE_FLAGS(Features, Feature)
60 * This class represents information about dictionary.
66 * Construct empty DictInfo object.
72 * Construct DictInfo object from data.
73 * @param plugin A plugin name
74 * @param name A dictionary name
75 * @param author A dictionary author
76 * @param desription A dictionary description
77 * @param wordsCount A count of words that available in dictionary
79 DictInfo(const QString &plugin,
81 const QString &author = QString(),
82 const QString &description = QString(),
83 long wordsCount = -1L)
87 m_description(description),
88 m_wordsCount(wordsCount)
91 const QString &plugin() const
93 const QString &name() const
95 const QString &author() const
97 const QString &description() const
98 { return m_description; }
99 long wordsCount() const
100 { return m_wordsCount; }
102 void setPlugin(const QString &plugin)
103 { m_plugin = plugin; }
104 void setName(const QString &name)
106 void setAuthor(const QString &author)
107 { m_author = author; }
108 void setDescription(const QString &description)
109 { m_description = description; }
110 void setWordsCount(long wordsCount)
111 { m_wordsCount = wordsCount; }
117 QString m_description;
122 * This class represent a translation.
128 * Construct an empty translation.
134 * Construct a translation from data.
135 * @param title A translation title
136 * @param dictName A full dictionary name
137 * @param translation A translation
139 Translation(const QString &title,
140 const QString &dictName,
141 const QString &translation)
143 m_dictName(dictName),
144 m_translation(translation)
148 * Return the translation title.
150 const QString &title() const
154 * Return the dictionary name.
156 const QString &dictName() const
157 { return m_dictName; }
160 * Return the translation.
162 const QString &translation() const
163 { return m_translation; }
166 * Set a translation title.
168 void setTitle(const QString &title)
172 * Set a dictionary name.
174 void setDictName(const QString &dictName)
175 { m_dictName = dictName; }
180 void setTranslation(const QString &translation)
181 { m_translation = translation; }
186 QString m_translation;
192 virtual ~DictPlugin() { }
195 * Return the plugin name.
197 virtual QString name() const = 0;
200 * Return the plugin version.
202 virtual QString version() const = 0;
205 * Return the plugin description.
207 virtual QString description() const = 0;
210 * Return the plugin authors.
212 virtual QStringList authors() const = 0;
215 * Return a features supported by dictionary plugin.
217 virtual Features features() const
218 { return Features(None); }
221 * Return a list of available dictionaries.
223 virtual QStringList availableDicts() const = 0;
226 * Return a list of loaded dictionaries.
228 virtual QStringList loadedDicts() const = 0;
231 * Set a list of loaded dictionaries.
233 virtual void setLoadedDicts(const QStringList &loadedDicts) = 0;
236 * Return true if translation exists in dictionary,
237 * otherwise returns false.
239 virtual bool isTranslatable(const QString &dict, const QString &word) = 0;
241 * Return translation for word from dictionary. If word not found
242 * returns empty string.
244 virtual Translation translate(const QString &dict, const QString &word) = 0;
246 * Return a list of similar to "word" words from all loaded dictionaries.
247 * Works only if SearchSimilar feature is enabled.
249 virtual QStringList findSimilarWords(const QString &dict, const QString &word)
250 { Q_UNUSED(dict); return QStringList(word); }
253 * Return a required resource. Scheme of URLs:
254 * plugin://plugin_name/...
256 virtual QVariant resource(int type, const QUrl &name)
257 { Q_UNUSED(type) Q_UNUSED(name) return QVariant(); }
260 * Return an information about dictionary. The dictionary may be not loaded
263 virtual DictInfo dictInfo(const QString &dict) = 0;
266 * Run a settings dialog and return QDialog::DialogCode.
268 virtual int execSettingsDialog(QWidget *parent = 0)
269 { Q_UNUSED(parent); return 0; }
273 * Return a directory that contains plugin's data.
275 QString workPath() const
277 QString path = QDir::homePath() + "/.config/qstardict/pluginsdata/" + name();
279 if (! QDir::root().exists(path))
280 QDir::root().mkpath(path);
285 Q_DECLARE_OPERATORS_FOR_FLAGS(DictPlugin::Features)
289 Q_DECLARE_INTERFACE(QStarDict::DictPlugin, "org.qstardict.DictPlugin/1.0")
291 #endif // DICTPLUGIN_H
293 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent