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