Fix random error when remove word from bookmark. Fix show all bookmark feature.
[mdictionary] / src / include / GUIInterface.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 /*! \file GUIInterface.h
22     \brief Defines interface for GUI
23
24     \author Mateusz Półrola <mateusz.polrola@comarch.pl>
25 */
26
27
28
29 #ifndef GUIINTERFACE_H
30 #define GUIINTERFACE_H
31 #include <QMainWindow>
32 #include <QMultiHash>
33
34 #include "translation.h"
35 #include "CommonDictInterface.h"
36
37 class Settings;
38
39 //! Interface for different GUIs
40 /*!
41   Default base class for all GUIs is QMainWindow
42   */
43 class GUIInterface : public QMainWindow {
44     Q_OBJECT
45
46 public:
47     GUIInterface(QWidget *parent = 0) :QMainWindow(parent) {}
48     virtual ~GUIInterface() {}
49
50     //! Returns all loaded dictionaries with information if they are
51     //! active/inactive
52     /*!
53         \return Hash of pointers to a dictionary and boolean flag indicating if
54         a dictionary is active
55      */
56     virtual QHash<CommonDictInterface*, bool> getDictionaries() = 0;
57
58
59     //! Returns all loaded plugins
60     /*!
61         \return List of pointers to plugins
62      */
63     virtual QList<CommonDictInterface*> getPlugins() = 0;
64
65     //! Indicates if GUI is in exact search mode.
66     /*! When GUI is in exact search mode it searches for a word, and
67         if it finds exactly matching translation it directly displays it, without
68         displaying matching words list. This mode should be
69         used for browsing search history and searching for words from application
70         arguments.
71         \returns flag indicating if GUI is in exact search mode
72     */
73     bool exactSearch();
74
75     //! Sets GUI exact search mode.
76     /*! \sa exactSearch() */
77     void setExactSearch(bool exactSearch);
78
79     virtual Settings* settings() = 0;
80
81     virtual void setSettings(Settings*) = 0;
82
83
84 public Q_SLOTS:
85     //! Searches in exact mode for a given word
86     /*!
87       GUI will be automatically set into exact search mode, and after search or
88       break it will be unset from exact search mode.
89       \param word word which will be searched for in dictionaries
90       */
91     virtual void searchExact(QString word) = 0;
92
93     //! Adds key words from given translations to history
94     /*!
95       By default this slot is connected to searchTranslations signal, and
96       passed translations list contains only translations with the same key, so
97       only one word is added to history.
98       \param list of translations with key words
99       \sa searchTranslations();
100       */
101     virtual void addToHistory(QList<Translation*>) = 0;
102
103     //! Shows history dialog
104     virtual void showHistory(QPoint) = 0;
105
106     //! Shows translation of next word in history
107     /*!
108       It will work only if there is next word available in history.
109       Translation of a word is searched for with searchExact() function
110       \sa searchExact()
111       */
112     virtual void historyNext() = 0;
113
114     //! Shows translation of previous word in history
115     /*!
116       It will work only if there is previous word available in history.
117       Translation of a word is searched for with searchExact() function
118       \sa searchExact()
119       */
120     virtual void historyPrev() = 0;
121
122     //! Gets words list from backbone and prepares received list to display
123     /*!
124       Checks if received list is empty, in that case it displays suitable
125       information. If GUI is in exact search mode it will search for exact
126       word in received list, and if the word is found it will emit signal to
127       display its translation. Otherwise it will display list of matching
128       words and show suitable information.
129       \sa exactSearch()
130       \sa showTranslation()
131      */
132     virtual void wordListReady() = 0;
133
134     //! Gets translation strings from backbone and emits signal to display them
135     virtual void translationsReady() = 0;
136
137 Q_SIGNALS:
138     //! Should be emitted when user wants to close application to stop
139     //! all ongoing searches
140     void quit();
141
142     //! Emitted when user wants to search for a list of words matching a given word
143     /*! \param word word which will be matched, it can contain wildcards
144     */
145     void searchWordList(QString word);
146
147     //! Emitted when user wants to see translation of words.
148     /*! \param list of translations for a given word which will be received
149         in wordListReady() slot
150         \sa wordListReady()
151     */
152     void searchTranslations(QList<Translation*>);
153
154     //! Emitted when starting search, will disable GUI components
155     //! and show progress bars
156     void setBusy();
157
158     //! Emitted when searching ends, will enable GUI components
159     void setIdle();
160
161     //! Emitted when user wants to break search
162     void stopSearching();
163
164     //! Emitted after receiving words list in wordListReady() slot, will display
165     //! list of matched words
166     /*! \param hash of a word and list of translations of this word found
167          in dictionaries
168      */
169     void showWordList(QHash<QString, QList<Translation*> >);
170
171     //! Emitted after receiving translation strings in translationsReady() slot,
172     //! will display translation of a given word
173     /*! \param list of translations from different dictionaries
174          in dictionaries
175      */
176     void showTranslation(QStringList);
177
178     //! Emitted when user wants to add a new dictionary
179     /*! \param new dictionary returned by specific plugin dialog
180       */
181     void addNewDictionary(CommonDictInterface*);
182
183     //! Emitted when user wants to remove a dictionary
184     /*! \param dictionary which will be removed
185       */
186     void removeDictionary(CommonDictInterface*);
187
188     //! Emitted when user changes dictionaries active/inactive states
189     /*! \param list of only active dictionaries
190       */
191     void selectedDictionaries(QList<CommonDictInterface* >);
192
193     void addToBookmarks(QList<Translation*>);
194
195     void bookmarkMode();
196 };
197
198 #endif // GUIINTERFACE_H