fix small bug's
[mdictionary] / trunk / src / includes / CommonDictInterface.h
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
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.
9
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.
14
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/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 /*! \file CommonDictInterface.h
23 \brief Common interface for all dicts and plugins \see CommonDictInterface
24
25 \author Bartosz Szatkowski <bulislaw@linux.com>
26 */
27
28 #ifndef COMMONDICTINTERFACE_H
29 #define COMMONDICTINTERFACE_H
30
31 #include <QString>
32 #include <QDialog>
33 #include <QObject>
34 #include <QList>
35 #include "translation.h"
36 #include "Notify.h"
37 #include "settings.h"
38 #include "AccentsNormalizer.h"
39
40 class DictDialog;
41
42
43 //! Interface for dict engines plugins
44 class CommonDictInterface : public QObject, public AccentsNormalizer {
45   Q_OBJECT
46   public:
47     CommonDictInterface(QObject *parent = 0):QObject(parent) {}
48
49     virtual ~CommonDictInterface() {}
50
51     //! returns source language code iso 639-2
52     virtual QString langFrom() const = 0;
53
54     //! returns destination language code iso 639-2
55     virtual QString langTo() const = 0;
56
57     //! returns dictionary name (like "old English" or so
58     virtual QString name() const = 0;
59
60     //! returns dictionary type (xdxf, google translate, etc)
61     virtual QString type() const = 0;
62
63     //! returns information about dictionary in html (name, authors, etc)
64     virtual QString infoNote() const = 0;
65
66     /*! returns DictDialog object that creates dialogs
67         for adding new dictionary and changing plugin settings*/
68     virtual DictDialog* dictDialog() = 0;
69
70
71     //! returns new, clean copy of plugin with setting set as in Settings*
72     virtual CommonDictInterface* getNew(const Settings*) const = 0;
73
74     //! returns whether plugin can start searching
75     virtual bool isAvailable() const = 0;
76
77     //! returns the actual translation of a word given in key
78     virtual QString search(QString key) = 0;
79
80     //! \returns unique value (unique for every dictionary not plugin)
81     virtual uint hash() const = 0;
82
83     //! sets unique value (unique for every dictionary not plugin)
84     virtual void setHash(uint) = 0;
85
86     //! returns current plugin settings
87     virtual Settings* settings() = 0;
88
89     //! returns plugin icon
90     virtual QIcon* icon() = 0;
91
92     virtual Translation* getTranslationFor(QString) {return 0;}
93
94  public Q_SLOTS:
95     /*! performs search in dictionary
96         \param  word word to search in dictionary
97         \param  limit limit on number of results,
98                 if limit=0 all matching words are returned
99
100         After finishing search it has to emit
101         \see CommonDictInterface:finalTranslation  finalTranslation
102     */
103     virtual QList<Translation*> searchWordList(QString word, int limit=0) = 0;
104
105     //! stops current operation
106     virtual void stop() = 0;
107
108   Q_SIGNALS:
109
110     //! emited after dictionary is ready to use afer being loaded
111     void loaded(CommonDictInterface*);
112
113     //! emited after change dictionary settings
114     void settingsChanged();
115
116     /*! emitted to backbone when needed to inform user about something
117         \param Backbone::NotifyType gui my dacide to show different typet in
118             different ways
119         \param QString text of the notification
120     */
121     void notify(Notify::NotifyType, QString);
122     
123 protected:
124     QString removeAccents(QString string) {
125         if(settings()->value("strip_accents") == "true")
126             return AccentsNormalizer::removeAccents(string);
127         return string;
128     }
129
130     void initAccents() { AccentsNormalizer::initAccents(); }
131
132
133
134 };
135
136 Q_DECLARE_INTERFACE(CommonDictInterface, "CommonDictInterface/0.1");
137
138 #endif