1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
21 //! \file MainWindow.h
22 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
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"
44 //! Implements interface for GUI
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.
53 class MainWindow : public GUIInterface
60 \param backbone backbone object which will be doing all searches and returning data
61 \param parent parent widget of this window
63 MainWindow(Backbone* backbone, QWidget *parent = 0);
66 //! Returns all loaded dictionaries with information if they are
69 \return Hash of pointers to a dictionary and boolean flag indicating if
70 a dictionary is active
72 QHash<CommonDictInterface*, bool> getDictionaries();
74 //! Returns all loaded plugins
76 \return List of pointers to plugins
78 QList<CommonDictInterface*> getPlugins();
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
88 \sa setExactSearchString()
90 bool isInExactSearch();
93 //! Returns current application settings.
95 \returns Settings object containing current application settings
100 //! Sets new settings.
102 \param Settings object containing new application settings
104 void setSettings(Settings*);
108 //! Searches in exact mode for a given word
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
115 void searchExact(QString);
118 //! Searches for a given word
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
125 void search(QString);
127 //! Starts searching for a given word after 500 ms delay
129 After time's up it sets passed word in line edit of search bar and searches
131 \param word which will be searched for in dictionaries
136 void searchDelay(QString);
138 //! Sets string for exact search
140 Sets string for which current search is ongoing, is used to find exact
141 word when GUI is in search exact mode.
143 void setExactSearchString(QString);
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()
155 void setExactSearch(bool exactSearch);
158 //! Gets word list from backbone and prepares received list to display
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()
168 \sa showTranslation()
169 \sa setExactSearchString()
171 void wordListReady();
173 //! Gets translation strings from backbone and emits signal to display them
174 void translationsReady();
176 //! Adds key words from given translations to history
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()
184 void addToHistory(QList<Translation*>);
186 //! Shows history dialog
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
193 void showHistory(QPoint);
195 //! Shows translation of next word in history
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.
205 //! Shows translation of previous word in history
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.
216 //! Shows notification to user
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
223 void showNotification(Notify::NotifyType type, QString message);
232 //! When user breaks searching it makes sure that exact search mode will be
234 void searchingInterrupted();
236 //! Asks for confirmation when user clicks on "delete all bookmarks"
237 void removeBookmarks();
241 When user wants to close application, we first send signal to stop all
244 void closeEvent(QCloseEvent *);
251 void initializeSearchWidgets();
252 void initializeMenu();
253 void initializeMenuWidgets();
255 void hideWelcomeScreen();
257 bool checkExactSearch(QHash<QString, QList<Translation*> > searchResult,
258 QList<Translation*> &found);
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;
270 QVBoxLayout* mainLayout;
271 NotifyManager* notifyManager;
275 QAction* dictionariesAction;
276 QAction* bookmarksShowAllAction;
277 QAction* bookmarksRemoveAllAction;
278 QAction* settingsAction;
279 QAction* aboutAction;
283 QString searchString;
286 void connectBackbone();
287 void connectSearchBar();
288 void connectWordList();
289 void connectTranslationWidget();
290 void connectDictManager();
292 void connectBookmarksWidget();
295 #endif // MAINWINDOW_H