1 /*****************************************************************************
2 * dictcore.h - QStarDict, a StarDict clone written with using Qt *
3 * Copyright (C) 2007 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 *****************************************************************************/
25 #include <QStringList>
28 #include <QPluginLoader>
30 #include "../plugins/dictplugin.h"
37 * The DictCore is a base dictionary class.
39 class DictCore: public QObject
45 * This class represents a dictionary.
50 Dictionary(const QString &plugin, const QString &name)
57 const QString &plugin() const
59 const QString &name() const
61 void setPlugin(const QString &plugin)
62 { m_plugin = plugin; }
63 void setName(const QString &name)
65 bool operator == (const Dictionary &dict)
66 { return m_name == dict.m_name && m_plugin == dict.m_plugin; }
74 * Construct dictionary.
76 DictCore(QObject *parent = 0);
83 * Returns true if word is exists in dictionaries,
86 bool isTranslatable(const QString &word);
88 * Returns translation for word. If word not found, returns
91 QString translate(const QString &word);
93 * Returns a list of similar words contained in dictionaries.
95 QStringList findSimilarWords(const QString &word);
98 * Returns a list of available dictionary plugins.
100 QStringList availablePlugins() const;
103 * Returns a list of loaded dictionary plugins.
105 QStringList loadedPlugins() const
106 { return QStringList(m_plugins.keys()); }
109 * Sets a loaded plugins.
110 * If plugin cannot be loaded it will not be added to
111 * loadedPlugins list.
113 void setLoadedPlugins(const QStringList &loadedPlugins);
116 * Returns a list of available dictionaries.
117 * The first item in pair is a plugin name, the second item
118 * in pair is a dictionary name.
120 QList<Dictionary> availableDicts() const;
123 * Returns a list of loaded dictionaries.
124 * The first item in pair is a plugin name, the second item
125 * in pair is a dictionary name.
127 const QList<Dictionary> &loadedDicts() const
128 { return m_loadedDicts; }
131 * Sets a loaded dictionaries.
132 * The first item in pair is a plugin name, the second item
133 * in pair is a dictionary name.
134 * If dictionary cannot be loaded it will not be added to
135 * availableDicts list.
137 void setLoadedDicts(const QList<Dictionary> &loadedDicts);
140 * Reload loaded dicts.
145 * Returns pointer to plugin instance or 0 if not loaded.
147 DictPlugin *plugin(const QString &plugin)
148 { return m_plugins.contains(plugin) ? qobject_cast<DictPlugin*>(m_plugins[plugin]->instance()) : 0; }
162 QHash<QString, QPluginLoader*> m_plugins;
163 QList<Dictionary> m_loadedDicts;
170 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc