1 /*****************************************************************************
2  * dictcore.h - QStarDict, a StarDict clone written with using Qt            *
3  * Copyright (C) 2007 Alexander Rodin                                        *
4  *                                                                           *
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.                                       *
9  *                                                                           *
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.                              *
14  *                                                                           *
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  *****************************************************************************/
19 
20 #ifndef DICTCORE_H
21 #define DICTCORE_H
22 
23 #include <QObject>
24 
25 #include <QStringList>
26 #include <QPair>
27 #include <QHash>
28 
29 #include "../plugins/dictplugin.h"
30 
31 
32 namespace QStarDict
33 {
34 
35 /**
36  * The DictCore is a base dictionary class.
37  */
38 class DictCore: public QObject
39 {
40     Q_OBJECT
41 
42     public:
43         /**
44          * This class represents a dictionary.
45          */
46         class Dictionary
47         {
48             public:
Dictionary(const QString & plugin,const QString & name)49                 Dictionary(const QString &plugin, const QString &name)
50                     : m_plugin(plugin),
51                       m_name(name)
52                 {  }
Dictionary()53                 Dictionary()
54                 { }
55 
plugin()56                 const QString &plugin() const
57                 { return m_plugin; }
name()58                 const QString &name() const
59                 { return m_name; }
setPlugin(const QString & plugin)60                 void setPlugin(const QString &plugin)
61                 { m_plugin = plugin; }
setName(const QString & name)62                 void setName(const QString &name)
63                 { m_name = name; }
64                 bool operator == (const Dictionary &dict)
65                 { return m_name == dict.m_name && m_plugin == dict.m_plugin; }
66 
67             private:
68                 QString m_plugin;
69                 QString m_name;
70         };
71 
72         /**
73          * Construct dictionary.
74          */
75         DictCore(QObject *parent = 0);
76         /**
77          * Destructor.
78          */
79         ~DictCore();
80 
81         /**
82          * Returns true if word is exists in dictionaries,
83          * otherwise false.
84          */
85         bool isTranslatable(const QString &word);
86         /**
87          * Returns translation for word. If word not found, returns
88          * "Not found!"
89          */
90         QString translate(const QString &word);
91         /**
92          * Returns a list of similar words contained in dictionaries.
93          */
94         QStringList findSimilarWords(const QString &word);
95 
96         /**
97          * Returns a list of available dictionaries.
98          * The first item in pair is a plugin name, the second item
99          * in pair is a dictionary name.
100          */
101         QList<Dictionary> availableDicts() const;
102 
103         /**
104          * Returns a list of loaded dictionaries.
105          * The first item in pair is a plugin name, the second item
106          * in pair is a dictionary name.
107          */
loadedDicts()108         const QList<Dictionary> &loadedDicts() const
109         { return m_loadedDicts; }
110 
111         /**
112          * Sets a loaded dictionaries.
113          * The first item in pair is a plugin name, the second item
114          * in pair is a dictionary name.
115          * If dictionary cannot be loaded it will not be added to
116          * availableDicts list.
117          */
118         void setLoadedDicts(const QList<Dictionary> &loadedDicts);
119 
120         /**
121          * Reload loaded dicts.
122          */
123         void reloadDicts();
124 
125         /**
126          * Save settings.
127          */
128         void saveSettings();
129 
130     private:
131 
132         /**
133          * Load settings.
134          */
135         void loadSettings();
136 
137         QList<Dictionary> m_loadedDicts;
138 };
139 
140 }
141 
142 #endif // DICTCORE_H
143 
144 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc
145 
146