code clean
[mdictionary] / src / include / 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     virtual ~CommonDictInterface() {}
49
50     //! \returns source language code iso 639-2
51     virtual QString langFrom() const = 0;
52
53     //! \returns destination language code iso 639-2
54     virtual QString langTo() const = 0;
55
56     //! \returns dictionary name (like "old English" or so)
57     virtual QString name() const = 0;
58
59     //! \returns dictionary type (xdxf, google translate, etc)
60     virtual QString type() const = 0;
61
62     //! returns information about dictionary (name, authors, etc)
63     virtual QString infoNote() const = 0;
64
65     /*! \returns DictDialog object that creates dialogs
66         for adding a new dictionary and changing plugin settings*/
67     virtual DictDialog* dictDialog() = 0;
68
69     //! \returns new, clean copy of plugin with settings set as in Settings*
70     virtual CommonDictInterface* getNew(const Settings*) const = 0;
71
72     //! \returns whether plugin can start searching
73     virtual bool isAvailable() const = 0;
74
75     //! \returns the actual translation of a word given in a key
76     virtual QString search(QString key) = 0;
77
78     //! \returns unique value (unique for every dictionary, not plugin)
79     virtual uint hash() const {
80         return _hash;
81     }
82
83     //! sets unique value (unique for every dictionary, not plugin)
84     virtual void setHash(uint h) {
85         this->_hash=h;
86     }
87
88     //! \returns current plugin settings
89     virtual Settings* settings() = 0;
90
91     //! \returns plugin icon
92     virtual QIcon* icon() = 0;
93
94     //! \returns plugin icon's path
95     virtual QString iconPath() = 0;
96
97     //! \returns empty translation object (to be fetched later) for a given key
98     virtual Translation* getTranslationFor(QString ) {return 0;}
99
100     /*! plugin should delete any files (eg. cache) that have been created and are ready
101         to be deleted
102         */
103     virtual void clean() {}
104
105
106  public Q_SLOTS:
107     /*! performs search in a dictionary
108         \param  word word to search for in a dictionary
109         \param  limit limit on number of results,
110                 if limit=0 all matching words are returned
111
112         After finishing search it has to emit
113         \see CommonDictInterface:finalTranslation  finalTranslation
114     */
115     virtual QList<Translation*> searchWordList(QString word, int limit=0) = 0;
116
117     //! stops current operation
118     virtual void stop() = 0;
119
120     //! loads translations for each plugin only once
121     virtual void retranslate() {}
122
123   Q_SIGNALS:
124     //! emitted after change in dictionary settings
125     void settingsChanged();
126
127     /*! emitted to backbone when it's needed to inform user about something
128         \param Backbone::NotifyType GUI may decide to show different types in
129             different ways
130         \param text of the notification
131     */
132     void notify(Notify::NotifyType, QString);
133     
134
135 protected:
136 //! removes accents from letters in a word searched for (e.g. ą -> a, ł -> l)
137     QString removeAccents(QString string) {
138         if(settings()->value("strip_accents") == "true")
139             return AccentsNormalizer::removeAccents(string);
140         return string;
141     }
142
143     uint _hash;
144
145 };
146
147 Q_DECLARE_INTERFACE(CommonDictInterface, "CommonDictInterface/0.1");
148
149 #endif