Clean and order documentation in source files. Source ready to beta 2 release
[mdictionary] / src / mdictionary / gui / MainWindow.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 MainWindow.h
22     \brief Implements interface for GUI
23
24     \author Mateusz Półrola <mateusz.polrola@comarch.pl>
25 */
26
27 #ifndef MAINWINDOW_H
28 #define MAINWINDOW_H
29
30 #include <QMainWindow>
31 #include "../../include/GUIInterface.h"
32 #include "../../include/settings.h"
33 #include "../backbone/backbone.h"
34 #include "TranslationWidget.h"
35 #include "WordListWidget.h"
36 #include "SearchBarWidget.h"
37 #include "MenuWidget.h"
38 #include "DictManagerWidget.h"
39 #include "SettingsWidget.h"
40 #include "HistoryListDialog.h"
41 #include "BookmarksWidget.h"
42 #include "WelcomeScreenWidget.h"
43 #include "AboutWidget.h"
44 #include "NotifyManager.h"
45
46
47 /*!
48   Creates all of GUI subcomponents, and connects all GUI interface signals
49   with suitable backbone signals and slots.
50   Only this class has direct access to backbone object.
51   It manages all requests of subcomponents e. g. searching for a given word,
52   displaying history, removing a dictionary.
53   It also provides data from backbone to subcomponents e. g. result of search.
54 */
55 class MainWindow : public GUIInterface
56 {
57     Q_OBJECT
58
59 public:
60     //! Constructor
61     /*!
62       \param backbone backbone object which will be doing all searches and returning data
63       \param parent parent widget of this window
64     */
65     MainWindow(Backbone* backbone, QWidget *parent = 0);
66     ~MainWindow();
67
68     //! Returns all loaded dictionaries with information if they are
69     //! active/inactive
70     /*!
71         \return Hash of pointers to a dictionary and boolean flag indicating if
72         a dictionary is active
73     */
74     QHash<CommonDictInterface*, bool> getDictionaries();
75
76     //! Returns all loaded plugins
77     /*!
78         \return List of pointers to plugins
79     */
80     QList<CommonDictInterface*> getPlugins();
81
82     //! Indicates if GUI is in exact search mode.
83     /*! When GUI is in exact search mode it searches for a word, and if it
84         finds exactly matching translation it displays matching words list
85         and then directly displays translation of first exactly matched word.
86         This mode is used for browsing search history and searching words
87         from application arguments.
88         \returns flag indicating if GUI is in exact search mode
89         \sa setExactSearch()
90         \sa setExactSearchString()
91     */
92     bool isInExactSearch();
93
94
95     //! Returns current application settings.
96     /*!
97        \returns Settings object containing current application settings
98     */
99     Settings* settings();
100
101
102     //! Sets new settings.
103     /*!
104        \param Settings object containing new application settings
105     */
106     void setSettings(Settings*);
107
108
109  public Q_SLOTS:
110     //! Searches in exact mode for a given word
111     /*!
112       GUI will be automatically set into exact search mode, and after search or
113       when user breaks the search it will be unset from exact search mode.
114       \param word which will be searched for in dictionaries
115       \sa search()
116     */
117     void searchExact(QString);
118
119
120     //! Searches for a given word
121     /*!
122       It sets passed word in line edit of a search bar and searches for a given word.
123       \param word which will be searched for in dictionaries
124       \sa SearchBarWidget
125       \sa searchExact()
126     */
127     void search(QString);
128
129     //! Starts searching for a given word after 500 ms delay
130     /*!
131       After time's up it sets passed word in line edit of search bar and searches
132       for a given word.
133       \param word which will be searched for in dictionaries
134       \sa SearchBarWidget
135       \sa searchExact()
136       \sa search()
137     */
138     void searchDelay(QString);
139
140     //! Sets string for exact search
141     /*!
142         Sets string for which current search is ongoing, is used to find exact
143         word when GUI is in search exact mode.
144     */
145     void setExactSearchString(QString);
146
147     //! Sets GUI exact search mode.
148     /*! When GUI is in exact search mode it searches for word, and if it
149         finds exactly matching translation it displays matching words list
150         and then directly displays translation of first exactly matched word.
151         This mode is used for browsing search history and searching words
152         from application arguments.
153         \param exactSearch flag indicating if GUI is in exact search mode
154         \sa isInExactSearch()
155         \sa setExactSearchString()
156     */
157     void setExactSearch(bool exactSearch);
158
159
160     //! Gets word list from backbone and prepares received list to display
161     /*!
162       Checks if received list is empty, in that case it displays suitable
163       information. Otherwise it merges results of the same key word and emits
164       signal to display word list.
165       If GUI is in exact search mode it will search for an exact word in received
166       list and if any of found words match exactly the word passed to
167       searchExact() method.
168       \sa isInExactSearch()
169       \sa searchExact()
170       \sa showTranslation()
171       \sa setExactSearchString()
172      */
173     void wordListReady();
174
175     //! Gets translation strings from backbone and emits signal to display them
176     void translationsReady();
177
178     //! Adds key words from given translations to history
179     /*!
180       By default this slot is connected to searchTranslations signal, and
181       passed translation list contains only translations with the same key, so
182       only one word is added to history.
183       \param list of translations with key words
184       \sa searchTranslations()
185       */
186     void addToHistory(QList<Translation*>);
187
188     //! Shows history dialog
189     /*!
190        In maemo it shows dialog with history.
191        In desktop it shows popup containing history, whose bottom edge is on the
192        same height as passed point.
193        \param point on screen where popup has to show
194     */
195     void showHistory(QPoint);
196
197     //! Shows translation of next word in history
198     /*!
199       It will work only if there is next word available in history.
200       Translation of a word is searched for with searchDelay() function.
201       On maemo search is in normal mode, on desktop in exact search mode.
202       \sa searchDelay()
203       \sa searchExact()
204       */
205     void historyNext();
206
207     //! Shows translation of previous word in history
208     /*!
209       It will work only if there is previous word available in history.
210       Translation of a word is searched for with searchDelay() function.
211       On maemo search is in normal mode, on desktop in exact search mode.
212       \sa searchDelay()
213       \sa searchExact()
214       */
215     void historyPrev();
216
217
218     //! Shows notification to user
219     /*!
220       It shows different types of notifications such as information, warnings and errors.
221       In maemo they are represented as notes, on desktop as message boxes.
222       \param type type of notification
223       \param message notification message
224     */
225     void showNotification(Notify::NotifyType type, QString message);
226
227 private Q_SLOTS:
228     //! Disables menu
229     void disableMenu();
230
231     //! Enables menu
232     void enableMenu();
233
234     //! When user breaks searching it makes sure that exact search mode will be
235     //! disabled
236     void searchingInterrupted();
237
238     //! Asks for confirmation when user clicks on "delete all bookmarks"
239     void removeBookmarks();
240
241 protected:
242     /*!
243         When user wants to close application, we first send signal to stop all
244         ongoing searches.
245     */
246     void closeEvent(QCloseEvent *);
247
248
249 private:
250     Backbone* backbone;
251
252     void initializeUI();
253     void initializeSearchWidgets();
254     void initializeMenu();
255     void initializeMenuWidgets();
256
257     void hideWelcomeScreen();
258
259     bool checkExactSearch(QHash<QString, QList<Translation*> > searchResult,
260                           QList<Translation*> &found);
261
262     SearchBarWidget* searchBarWidget;
263     QWidget* translationWidget;
264     QWidget* wordListWidget;
265     MenuWidget* menuWidget;
266     DictManagerWidget* dictManagerWidget;
267     SettingsWidget* settingsWidget;
268     BookmarksWidget* bookmarksWidget;
269     QWidget* welcomeScreenWidget;
270     AboutWidget* aboutWidget;
271     QMenuBar* menuBar;
272     QVBoxLayout* mainLayout;
273     NotifyManager* notifyManager;
274
275     #ifndef Q_WS_MAEMO_5
276         QSplitter* splitter;
277         QAction* dictionariesAction;
278         QAction* bookmarksShowAllAction;
279         QAction* bookmarksRemoveAllAction;
280         QAction* settingsAction;
281         QAction* aboutAction;
282     #endif
283
284     bool _exactSearch;
285     QString searchString;
286
287
288     void connectBackbone();
289     void connectSearchBar();
290     void connectWordList();
291     void connectTranslationWidget();
292     void connectDictManager();
293     void connectMenu();
294     void connectBookmarksWidget();
295 };
296
297 #endif // MAINWINDOW_H