Added notify manager, which prevent from showing the same notify multiple times
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 1 Sep 2010 12:00:14 +0000 (14:00 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 1 Sep 2010 12:00:14 +0000 (14:00 +0200)
data/other/mdictionarywidget.desktop
trunk/src/base/base.pro
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/MainWindow.h
trunk/src/base/gui/NotifyManager.cpp [new file with mode: 0644]
trunk/src/base/gui/NotifyManager.h [new file with mode: 0644]
trunk/src/desktopWidget/MainWidget.cpp
trunk/src/desktopWidget/MainWidget.h
trunk/src/desktopWidget/main.cpp

index a7d2a2c..826b54f 100644 (file)
@@ -1,5 +1,5 @@
 [Desktop Entry]
-Name=mDictionary Widget
+Name=mDictionary
 Type=qt
 X-Path=/usr/lib/hildon-desktop/mdictionarywidget
 X-Multiple-Instances=false
index f1086ab..12381c9 100644 (file)
@@ -34,7 +34,8 @@ SOURCES += gui/main.cpp \
     gui/WelcomeScreenWidget.cpp \
     gui/AboutWidget.cpp \
     gui/TranslationTextEdit.cpp \
-    gui/DBusAdapter.cpp
+    gui/DBusAdapter.cpp \
+    gui/NotifyManager.cpp
 HEADERS += gui/MainWindow.h \
     backbone/ConfigGenerator.h \
     gui/AboutWidget.h \
@@ -63,7 +64,8 @@ HEADERS += gui/MainWindow.h \
     gui/TranslationTextEdit.h \
     ../includes/AccentsNormalizer.h \
     ../includes/DictDialog.h \
-    gui/DBusAdapter.h
+    gui/DBusAdapter.h \
+    gui/NotifyManager.h
 RESOURCES += ../../../data/icons/gui.qrc
 unix { 
     # VARIABLES
index 7203a76..d34d81a 100644 (file)
@@ -19,7 +19,8 @@
 
 *******************************************************************************/
 
-//Created by Mateusz Półrola
+//! \file MainWindow.cpp
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
 
 #include "MainWindow.h"
 #include <QtGui>
@@ -46,8 +47,6 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
 
     setExactSearch(false);
 
-    setWindowTitle("mDictionary");
-
     showMaximized();
 }
 
@@ -62,27 +61,41 @@ void MainWindow::initializeUI() {
         setAttribute(Qt::WA_Maemo5StackedWindow);
     #endif
 
-    //translationWidget is another stacked window, so we don't add it to layout
-    //only create it with this widget as parent
-    translationWidget = new TranslationWidget(this);
 
+    setWindowIcon(QIcon(":/icons/64x64/mdictionary.png"));
+    setWindowTitle("mDictionary");
+
+    /*translationWidget is another stacked window, so we don't add it to
+      layout only create it with this widget as parent
+      it must be created as first object in main window, otherwise sometimes
+      when app starts in maemo, when trying to set stacked window attribure
+      it segfaults*/
+    translationWidget = new TranslationWidget(this);
 
     mainLayout = new QVBoxLayout();
     QWidget* w = new QWidget();
     w->setLayout(mainLayout);
     setCentralWidget(w);
+
     menuBar = new QMenuBar();
     setMenuBar(menuBar);
 
+    initializeSearchWidgets();
+
+    initializeMenu();
+
+    notifyManager = new NotifyManager(this);
+}
+
+void MainWindow::initializeSearchWidgets() {
     searchBarWidget = new SearchBarWidget();
 
     wordListWidget = new WordListWidget();
 
     welcomeScreenWidget = new WelcomeScreenWidget();
 
-
     #ifdef Q_WS_MAEMO_5
-    //At start we set widget as welcome screen widget
+        //At start we set widget as welcome screen widget
         mainLayout->addWidget(welcomeScreenWidget);
         mainLayout->addWidget(searchBarWidget, 0, Qt::AlignBottom);
     #else
@@ -92,11 +105,48 @@ void MainWindow::initializeUI() {
         splitter->addWidget(wordListWidget);
         splitter->addWidget(welcomeScreenWidget);
         splitter->setStretchFactor(1, 150);
+
         mainLayout->addWidget(splitter);
         mainLayout->addWidget(searchBarWidget);
     #endif
+}
 
+void MainWindow::initializeMenu() {
+    initializeMenuWidgets();
 
+#ifdef Q_WS_MAEMO_5
+    menuWidget = new MenuWidget(this);
+
+    menuWidget->addSubMenu(tr("Settings"), settingsWidget);
+    menuWidget->addSubMenu(tr("Dictionaries"), dictManagerWidget);
+    menuWidget->addSubMenu(tr("Bookmarks"), bookmarksWidget);
+    menuWidget->addSubMenu(tr("About"), aboutWidget);
+
+    menuBar->addAction(menuWidget);
+#else
+    dictionariesAction = menuBar->addAction(tr("Dictionaries"));
+    connect(dictionariesAction, SIGNAL(triggered()),
+            dictManagerWidget, SLOT(show()));
+
+    settingsAction = menuBar->addAction(tr("Settings"));
+    connect(settingsAction, SIGNAL(triggered()),
+            settingsWidget, SLOT(show()));
+
+    QMenu* m = menuBar->addMenu(tr("Bookmarks"));
+    bookmarksShowAllAction = new QAction(tr("Show all"), m);
+
+    bookmarksRemoveAllAction = new QAction(tr("Remove all"), m);
+
+    m->addAction(bookmarksShowAllAction);
+    m->addAction(bookmarksRemoveAllAction);
+
+    aboutAction = menuBar->addAction(tr("About"));
+    connect(aboutAction, SIGNAL(triggered()),
+            aboutWidget, SLOT(show()));
+#endif
+}
+
+void MainWindow::initializeMenuWidgets() {
     dictManagerWidget = new DictManagerWidget(this);
     dictManagerWidget->hide();
 
@@ -108,46 +158,15 @@ void MainWindow::initializeUI() {
 
     aboutWidget = new AboutWidget(this);
     aboutWidget->hide();
-
-    //creating menus
-
-    #ifdef Q_WS_MAEMO_5
-        menuWidget = new MenuWidget(this);
-        menuWidget->addSubMenu(tr("Settings"), settingsWidget);
-        menuWidget->addSubMenu(tr("Dictionaries"), dictManagerWidget);
-        menuWidget->addSubMenu(tr("Bookmarks"), bookmarksWidget);
-        menuWidget->addSubMenu(tr("About"), aboutWidget);
-        menuBar->addAction(menuWidget);
-    #else
-        dictionariesAction = menuBar->addAction(tr("Dictionaries"));
-        connect(dictionariesAction, SIGNAL(triggered()),
-                dictManagerWidget, SLOT(show()));
-
-        settingsAction = menuBar->addAction(tr("Settings"));
-        connect(settingsAction, SIGNAL(triggered()),
-                settingsWidget, SLOT(show()));
-
-        QMenu* m = menuBar->addMenu(tr("Bookmarks"));
-        bookmarksShowAllAction = new QAction(tr("Show all"), m);
-
-        bookmarksRemoveAllAction = new QAction(tr("Remove all"), m);
-
-        m->addAction(bookmarksShowAllAction);
-        m->addAction(bookmarksRemoveAllAction);
-
-        aboutAction = menuBar->addAction(tr("About"));
-        connect(aboutAction, SIGNAL(triggered()),
-                aboutWidget, SLOT(show()));
-    #endif
 }
 
 void MainWindow::closeEvent(QCloseEvent *event) {
     //request to stop all searches and close app
-        Q_EMIT quit();
-        event->accept();
+    Q_EMIT quit();
+    event->accept();
 }
 
-bool MainWindow::exactSearch() {
+bool MainWindow::isInExactSearch() {
     return _exactSearch;
 }
 
@@ -155,28 +174,21 @@ void MainWindow::setExactSearch(bool exact) {
     _exactSearch = exact;
 }
 
-void MainWindow::setSearchString(QString word) {
+void MainWindow::setExactSearchString(QString word) {
     searchString = word;
 }
 
 void MainWindow::wordListReady() {
     //gets results from backbone
-    QMultiHash<QString, Translation*> res = backbone->result();
+    QMultiHash<QString, Translation*> backboneResult = backbone->result();
     QHash<QString, QList<Translation*> > searchResult;
 
     #ifdef Q_WS_MAEMO_5
-    //switch welcome screen with word list
-    if(!wordListWidget->isVisible()) {
-        int i = mainLayout->indexOf(welcomeScreenWidget);
-        QBoxLayout* l = (QBoxLayout*)(mainLayout);
-        l->removeWidget(welcomeScreenWidget);
-        welcomeScreenWidget->deleteLater();
-        l->insertWidget(0, wordListWidget);
-    }
+        hideWelcomeScreen();
     #endif
 
     //if nothing was found
-    if(res.count() == 0) {
+    if(backboneResult.count() == 0) {
         showNotify(Notify::Info, tr("Can't find any matching words"));
 
         //show empty list to remove results of old search
@@ -185,55 +197,73 @@ void MainWindow::wordListReady() {
     else {
         //find translations of the same key word
         QMultiHash<QString, Translation*>::iterator i;
-        for(i = res.begin(); i != res.end(); i++) {
+        for(i = backboneResult.begin(); i != backboneResult.end(); i++) {
             searchResult[i.key()].push_back(i.value());
         }
 
+        //show search results
+        Q_EMIT showWordList(searchResult);
 
-        if(!exactSearch()) {
-            Q_EMIT showWordList(searchResult);
-        }
-        else {
-            #ifndef Q_WS_MAEMO_5
-            //on desktop we show word list in exact search
-                Q_EMIT showWordList(searchResult);
-            #endif
-            bool foundExactMatch = false;
-            QHash<QString, QList<Translation*> >::iterator j;
-            for(j = searchResult.begin(); j != searchResult.end(); j++) {
-                if(j.key().toLower() == searchString.toLower()
-                    && !foundExactMatch) {
-                    foundExactMatch = true;
-                    Q_EMIT searchTranslations(j.value());
-                    break;
-                }
-            }
 
-            if(!foundExactMatch) {
+        if(isInExactSearch()) {
+            QList<Translation*> exactTranslation;
+            if(checkExactSearch(searchResult, exactTranslation)) {
+                qDebug()<<exactTranslation.count();
+                Q_EMIT searchTranslations(exactTranslation);
+            }
+            else {
                 showNotify(Notify::Info,
                            tr("Can't find exactly matching word"));
-
-                Q_EMIT showWordList(searchResult);
             }
 
+            setExactSearch(false);
         }
     }
-    setExactSearch(false);
+}
+
+bool MainWindow::checkExactSearch(
+        QHash<QString, QList<Translation *> > searchResult,
+        QList<Translation *> &found) {
+
+    bool foundExactMatch = false;
+    QHash<QString, QList<Translation*> >::iterator j;
+    for(j = searchResult.begin(); j != searchResult.end(); j++) {
+        if(j.key().toLower() == searchString.toLower()
+            && !foundExactMatch) {
+            found = j.value();
+            return true;
+        }
+    }
+    return false;
 }
 
 void MainWindow::translationsReady() {
     #ifndef Q_WS_MAEMO_5
+        hideWelcomeScreen();
+    #endif
+
+    Q_EMIT showTranslation(backbone->htmls());
+    notifyManager->screenChanged();
+}
+
+
+void MainWindow::hideWelcomeScreen() {
+#ifdef Q_WS_MAEMO_5
+    //switch welcome screen with word list
+    if(!wordListWidget->isVisible()) {
+        mainLayout->removeWidget(welcomeScreenWidget);
+        welcomeScreenWidget->deleteLater();
+
+        mainLayout->insertWidget(0, wordListWidget);
+    }
+#else
     //switch welcome screen with translation widget
     if(!translationWidget->isVisible()) {
-        QBoxLayout* l = (QBoxLayout*)(mainLayout);
-        QSplitter* s = (QSplitter*)((QWidgetItem*)(l->itemAt(0))->widget());
-        s->insertWidget(1,translationWidget);
-        s->setStretchFactor(1, 150);
+        splitter->insertWidget(1,translationWidget);
+        splitter->setStretchFactor(1, 150);
         welcomeScreenWidget->deleteLater();
     }
-    #endif
-
-    Q_EMIT showTranslation(backbone->htmls());
+#endif
 }
 
 QList<CommonDictInterface*> MainWindow::getPlugins() {
@@ -252,15 +282,18 @@ void MainWindow::search(QString word) {
 
 void MainWindow::searchExact(QString word) {
     setExactSearch(true);
-    //searching with searchBar, not directly by emitting searchWordList(),
-    //because it will set search word in searchBar's edit line
-    //this function is only used by history and when searching from attributes
     searchBarWidget->search(word);
 }
 
+void MainWindow::searchDelay(QString word) {
+    searchBarWidget->searchDelay(word);
+}
+
 
 
-void MainWindow::breakSearching() {
+
+
+void MainWindow::searchingInterrupted() {
     //make sure to unset exact search mode
     setExactSearch(false);
 }
@@ -277,7 +310,7 @@ void MainWindow::historyNext() {
         #ifndef Q_WS_MAEMO_5
             setExactSearch(true);
         #endif
-        searchBarWidget->searchDelay(next);
+        searchDelay(next);
     }
 }
 
@@ -287,7 +320,7 @@ void MainWindow::historyPrev() {
             setExactSearch(true);
         #endif
         QString prev = backbone->history()->previous();
-        searchBarWidget->searchDelay(prev);
+        searchDelay(prev);
     }
 }
 
@@ -312,6 +345,7 @@ void MainWindow::enableMenu() {
 }
 
 void MainWindow::showHistory(QPoint p) {
+
     HistoryListDialog historyDialog(backbone->history()->list(), searchBarWidget);
 
     #ifndef Q_WS_MAEMO_5
@@ -339,37 +373,28 @@ Settings* MainWindow::settings() {
 
 
 void MainWindow::showNotify(Notify::NotifyType type, QString text) {
+    notifyManager->showNotify(type, text);
+}
 
-    switch(type) {
-    case Notify::Info:
-        #ifdef Q_WS_MAEMO_5
-            QMaemo5InformationBox::information(this,
-                                text,
-                                QMaemo5InformationBox::DefaultTimeout);
-        #else
-            QMessageBox::information(this, "Information", text);
-        #endif
-        break;
+void MainWindow::connectBackbone() {
+
+    connect(this, SIGNAL(searchWordList(QString)),
+            this, SIGNAL(setBusy()));
+
+    connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
+            this, SIGNAL(setBusy()));
+
+    connect(this, SIGNAL(stopSearching()),
+            this, SIGNAL(setIdle()));
+
+    connect(this, SIGNAL(searchWordList(QString)),
+            this, SLOT(setExactSearchString(QString)));
+
+    connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
+            this, SLOT(addToHistory(QList<Translation*>)));
 
-    case Notify::Warning:
-        #ifndef Q_WS_MAEMO_5
-                QMessageBox::warning(this, "Warning", text);
-                break;
-        #endif
 
-    case Notify::Error:
-        #ifdef Q_WS_MAEMO_5
-            QMaemo5InformationBox::information(this,
-                                text,
-                                QMaemo5InformationBox::NoTimeout);
-        #else
-            QMessageBox::critical(this, "Error", text);
-        #endif
-        break;
-    }
-}
 
-void MainWindow::connectBackbone() {
     connect(this, SIGNAL(quit()),
             backbone, SLOT(quit()));
 
@@ -383,7 +408,7 @@ void MainWindow::connectBackbone() {
             backbone, SLOT(stopSearching()));
 
     connect(this, SIGNAL(stopSearching()),
-            this, SLOT(breakSearching()));
+            this, SLOT(searchingInterrupted()));
 
     connect(this, SIGNAL(addNewDictionary(CommonDictInterface*)),
             backbone, SLOT(addDictionary(CommonDictInterface*)));
@@ -413,26 +438,6 @@ void MainWindow::connectBackbone() {
 
     connect(backbone, SIGNAL(notify(Notify::NotifyType,QString)),
             this, SLOT(showNotify(Notify::NotifyType,QString)));
-
-
-
-
-    connect(this, SIGNAL(searchWordList(QString)),
-            this, SIGNAL(setBusy()));
-
-    connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
-            this, SIGNAL(setBusy()));
-
-    connect(this, SIGNAL(stopSearching()),
-            this, SIGNAL(setIdle()));
-
-    connect(this, SIGNAL(searchWordList(QString)),
-            this, SLOT(setSearchString(QString)));
-
-    connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
-            this, SLOT(addToHistory(QList<Translation*>)));
-
-
 }
 
 void MainWindow::connectSearchBar() {
index 1046fde..4ed7c8d 100644 (file)
@@ -19,7 +19,6 @@
 
 *******************************************************************************/
 //! \file MainWindow.h
-//! \brief Implements interface for GUI
 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
 
 #ifndef MAINWINDOW_H
 #include "BookmarksWidget.h"
 #include "WelcomeScreenWidget.h"
 #include "AboutWidget.h"
+#include "NotifyManager.h"
 
 
 //! Implements interface for GUI
 /*!
-  Creates all of GUI subcomponents, and connects all GUI interface signals with
-  suitable backbone signals and slots. Only this class has direct access to
-  backbone object. It manages all requests of subcomponents e. g. searching of
-  given word, displaying history, removing dictionary.
+  Creates all of GUI subcomponents, and connects all GUI interface signals
+  with suitable backbone signals and slots.
+  Only this class has direct access to backbone object.
+  It manages all requests of subcomponents e. g. searching of given word,
+  displaying history, removing dictionary.
   It also provide data from backbone to subcomponents e. g. result of search.
 */
 class MainWindow : public GUIInterface
@@ -58,9 +59,8 @@ public:
     /*!
       \param backbone object which will be doing all searches and returning data
       \param parent parent widget of this window
-      */
-
-    explicit MainWindow(Backbone* backbone, QWidget *parent = 0);
+    */
+    MainWindow(Backbone* backbone, QWidget *parent = 0);
     ~MainWindow();
 
     //! Returns all loaded dictionaries with infromation about that they are
@@ -68,46 +68,39 @@ public:
     /*!
         \return Hash of pointers to dictionary and boolean flag indicating if
         dictionary is active
-     */
+    */
     QHash<CommonDictInterface*, bool> getDictionaries();
 
     //! Returns all loaded plugins
     /*!
         \return List of pointers to plugins
-     */
+    */
     QList<CommonDictInterface*> getPlugins();
 
     //! Indicates if GUI is in exact search mode.
-    /*! When GUI is in exact search mode it searches for word, and
-        if it finds exactly matching translation it directly displays it, without
-        displaying matching word list. This mode is used for browsing search
-        history and searching words from application arguments.
+    /*! When GUI is in exact search mode it searches for word, and if it
+        finds exactly matching translation it displaying matching words list
+        and then directly displays translation of first exactly matched word.
+        This mode is used for browsing search history and searching words
+        from application arguments.
         \returns flag indicating if GUI is in exact search mode
+        \sa setExactSearch()
+        \sa setExactSearchString()
     */
-    bool exactSearch();
-
-    //! Sets GUI exact search mode.
-    /*! When GUI is in exact search mode it searches for word, and
-        if it finds exactly matching translation it directly displays it, without
-        displaying matching word list. This mode is used for browsing search
-        history and searching words from application arguments.
-        \param exactSearch flag indicating if GUI will be in exact search mode
-        \sa exactSearch()
-    */
-    void setExactSearch(bool);
+    bool isInExactSearch();
 
 
-    //! Returns current settings.
+    //! Returns current application settings.
     /*!
        \returns Settings object containing current application settings
-      */
+    */
     Settings* settings();
 
 
     //! Sets new settings.
     /*!
        \param Settings object containing new application settings
-      */
+    */
     void setSettings(Settings*);
 
 
@@ -115,29 +108,65 @@ public:
     //! Searches in exact mode for given word
     /*!
       GUI will be automatically set into exact search mode, and after search or
-      break will be unset from exact search mode.
+      when user break the search it will be unset from exact search mode.
       \param word which will be searched in dictionaries
-      */
+      \sa search()
+    */
     void searchExact(QString);
 
 
     //! Search for given word
     /*!
+      It sets passed word in line edit of search bar and search for given word.
       \param word which will be searched in dictionaries
-      */
+      \sa SearchBarWidget
+      \sa searchExact()
+    */
     void search(QString);
 
+    //! Start searching for given word after 500 ms delay
+    /*!
+      After times up it sets passed word in line edit of search bar and search
+      for given word.
+      \param word which will be searched in dictionaries
+      \sa SearchBarWidget
+      \sa searchExact()
+      \sa search()
+    */
+    void searchDelay(QString);
+
+    //! Sets string for exact search
+    /*!
+        Sets string for which current search is ongoing, is used to find exact
+        word when GUI is in search exact mode.
+    */
+    void setExactSearchString(QString);
+
+    //! Sets GUI exact search mode.
+    /*! When GUI is in exact search mode it searches for word, and if it
+        finds exactly matching translation it displaying matching words list
+        and then directly displays translation of first exactly matched word.
+        This mode is used for browsing search history and searching words
+        from application arguments.
+        \param exactSearch flag indicating if GUI will be in exact search mode
+        \sa isInExactSearch()
+        \sa setExactSearchString()
+    */
+    void setExactSearch(bool);
 
 
     //! Gets word list from backbone and prepares received list to display
     /*!
       Checks if received list is empty, in that case displays suitable
-      information. If GUI is in exact search mode it will search for exact
-      word in received list, and if word is found it will emit signal to
-      display its translation. Otherwise it will display list of matching
-      words and show suitable information.
-      \sa exactSearch()
+      information. Otherwise it merge results of the same key word and emit
+      signal to display word list.
+      If GUI is in exact search mode it will search for exact word in received
+      list and if any of found words match exacly the word passed to
+      searchExact() method.
+      \sa isInExactSearch()
+      \sa searchExact()
       \sa showTranslation()
+      \sa setExactSearchString()
      */
     void wordListReady();
 
@@ -155,12 +184,20 @@ public:
     void addToHistory(QList<Translation*>);
 
     //! Shows history dialog
+    /*!
+       In meamo shows dialog with history.
+       In desktop shows popup containing history, which bottom edge is on the
+       same height as passed point.
+       \param point on screen when popup has to show
+    */
     void showHistory(QPoint);
 
     //! Shows translation of next word in history
     /*!
       It will work only if there is available next word in history.
-      Translation of word is searched with searchExact() function
+      Translation of word is searched with searchDelay() function.
+      On maemo search is in normal mode, on desktop in exact search mode.
+      \sa searchDelay()
       \sa searchExact()
       */
     void historyNext();
@@ -168,20 +205,25 @@ public:
     //! Shows translation of previous word in history
     /*!
       It will work only if there is available previous word in history.
-      Translation of word is searched with searchExact() function
+      Translation of word is searched with searchDelay() function.
+      On maemo search is in normal mode, on desktop in exact search mode.
+      \sa searchDelay()
       \sa searchExact()
       */
     void historyPrev();
 
 
-    void showNotify(Notify::NotifyType, QString);
+    //! Shows notify to user
+    /*!
+      It shows different type of notyfies as informations, warnings and errors.
+      In maemo they are represented as notes, on desktop as message boxes.
+      \param type type of notify
+      \param message notify message
+    */
+    void showNotify(Notify::NotifyType type, QString message);
 
 private Q_SLOTS:
-    //! Sets string for which current search is ongoing, is used to find exact
-    //! word when GUI is in search exact mode.
-    void setSearchString(QString);
-
-    //! Disables menu when search is ongoing
+    //! Disables menu
     void disableMenu();
 
     //! Enables menu
@@ -189,14 +231,14 @@ private Q_SLOTS:
 
     //! When user breaks searching it makes sure that exact search mode will be
     //! disabled
-    void breakSearching();
+    void searchingInterrupted();
 
     //! Asks for confirmation when user click on "delete all bookmarks"
     void removeBookmarks();
 
-
 protected:
-    /*! When user wants to close application, we first send signal to stop all
+    /*!
+        When user wants to close application, we first send signal to stop all
         ongoing searches.
     */
     void closeEvent(QCloseEvent *);
@@ -206,6 +248,14 @@ private:
     Backbone* backbone;
 
     void initializeUI();
+    void initializeSearchWidgets();
+    void initializeMenu();
+    void initializeMenuWidgets();
+
+    void hideWelcomeScreen();
+
+    bool checkExactSearch(QHash<QString, QList<Translation*> > searchResult,
+                          QList<Translation*> &found);
 
     SearchBarWidget* searchBarWidget;
     QWidget* translationWidget;
@@ -216,8 +266,9 @@ private:
     BookmarksWidget* bookmarksWidget;
     QWidget* welcomeScreenWidget;
     AboutWidget* aboutWidget;
-    QVBoxLayout* mainLayout;
     QMenuBar* menuBar;
+    QVBoxLayout* mainLayout;
+    NotifyManager* notifyManager;
 
     #ifndef Q_WS_MAEMO_5
         QSplitter* splitter;
diff --git a/trunk/src/base/gui/NotifyManager.cpp b/trunk/src/base/gui/NotifyManager.cpp
new file mode 100644 (file)
index 0000000..257f611
--- /dev/null
@@ -0,0 +1,116 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "NotifyManager.h"
+#include <QMessageBox>
+#ifdef Q_WS_MAEMO_5
+    #include <QMaemo5InformationBox>
+#endif
+#include <QDebug>
+#include <QLabel>
+
+NotifyManager::NotifyManager(QObject *parent) :
+    QObject(parent)
+{
+}
+
+void NotifyManager::notifyClosed() {
+    QObject* dialog = QObject::sender();
+
+    QHash<QString, QDialog*>::Iterator it;
+
+    for(it = activeNotifies.begin(); it != activeNotifies.end(); it++) {
+        if(it.value() == dialog) {
+            activeNotifies.remove(it.key());
+            return;
+        }
+    }
+}
+
+void NotifyManager::screenChanged() {
+    QHash<QString, QDialog*>::Iterator it;
+
+    for(it = activeNotifies.begin(); it != activeNotifies.end(); it++) {
+        it.value()->hide();
+        it.value()->show();
+    }
+}
+
+void NotifyManager::showNotify(Notify::NotifyType type, QString text) {
+
+    if(activeNotifies.contains(text)) {
+        return;
+    }
+
+    #ifdef Q_WS_MAEMO_5
+        QMaemo5InformationBox* mbox =
+                new QMaemo5InformationBox(0);
+
+        QLabel* infoLabel = new QLabel(text);
+        infoLabel->setAlignment(Qt::AlignCenter);
+        infoLabel->setWordWrap(true);
+
+        mbox->setWidget(infoLabel);
+    #else
+        QMessageBox* mbox =
+                new QMessageBox(qobject_cast<QWidget*>(this->parent()));
+
+    #endif
+
+
+    switch(type) {
+
+    case Notify::Info:
+        #ifdef Q_WS_MAEMO_5
+            mbox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
+        #else
+            mbox->setText(text);
+            mbox->setWindowTitle(tr("Information"));
+            mbox->setIcon(QMessageBox::Information);
+
+        #endif
+        break;
+
+    case Notify::Warning:
+        #ifndef Q_WS_MAEMO_5
+                mbox->setText(text);
+                mbox->setWindowTitle(tr("Warning"));
+                mbox->setIcon(QMessageBox::Warning);
+                break;
+        #endif
+
+    case Notify::Error:
+        #ifdef Q_WS_MAEMO_5
+            mbox->setTimeout(QMaemo5InformationBox::NoTimeout);
+        #else
+            mbox->setText(text);
+            mbox->setWindowTitle(tr("Error"));
+            mbox->setIcon(QMessageBox::Critical);
+        #endif
+        break;
+    }
+
+    activeNotifies.insert(text, mbox);
+    connect(mbox, SIGNAL(finished(int)), this, SLOT(notifyClosed()));
+    mbox->exec();
+}
diff --git a/trunk/src/base/gui/NotifyManager.h b/trunk/src/base/gui/NotifyManager.h
new file mode 100644 (file)
index 0000000..be5507f
--- /dev/null
@@ -0,0 +1,50 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef NOTIFYMANAGER_H
+#define NOTIFYMANAGER_H
+
+#include <QObject>
+#include <QHash>
+#include <QString>
+#include <QDialog>
+#include "../../includes/Notify.h"
+
+class NotifyManager : public QObject
+{
+    Q_OBJECT
+public:
+    NotifyManager(QObject *parent = 0);
+
+public slots:
+    void showNotify(Notify::NotifyType type, QString text);
+    void screenChanged();
+
+private slots:
+    void notifyClosed();
+
+private:
+    QHash<QString, QDialog*> activeNotifies;
+};
+
+#endif // NOTIFYMANAGER_H
index c9833d4..a4977a6 100644 (file)
 #include <QDebug>
 
 
-MainWidget::MainWidget(QWidget *parent):
+HomeWidget::HomeWidget(QWidget *parent):
     QWidget(parent)
 {
-    setAttribute(Qt::WA_TranslucentBackground);
-
-
+    //setting application name, it will use it later to set home applet id
     QCoreApplication::instance()->setApplicationName(
             "mDictionary desktop widget");
 
-    // Get required atoms
-    Atom winTypeAtom = XInternAtom(
-            QX11Info::display(), "_NET_WM_WINDOW_TYPE", false);
-
-    Atom homeAppletAto = XInternAtom(
-            QX11Info::display(), "_HILDON_WM_WINDOW_TYPE_HOME_APPLET", false);
-
-    Atom appletIDAtom = XInternAtom(
-            QX11Info::display(), "_HILDON_APPLET_ID", false);
-
-    Atom utf8Atom = XInternAtom(
-            QX11Info::display(), "UTF8_STRING", false);
-
-
-    // Set correct window type
-    XChangeProperty(QX11Info::display(), winId(), winTypeAtom, XA_ATOM, 32,
-                    PropModeReplace, (unsigned char *) &homeAppletAto, 1);
+    //setting this attribute to get transparent backgorund
+    setAttribute(Qt::WA_TranslucentBackground);
 
+    initializeX11();
 
+    initializeUI();
+}
 
-    // Use application name to fill AppletID
-    QByteArray id (QCoreApplication::instance()->applicationName().remove(' ').toUtf8());
 
-    XChangeProperty(QX11Info::display(), winId(), appletIDAtom, utf8Atom, 8,
-                    PropModeReplace, (unsigned char *)id.constData(),
-                    id.length());
+void HomeWidget::initializeUI() {
 
 
     horizontalLayout = new QHBoxLayout;
     setLayout(horizontalLayout);
 
+
     searchStringLineEdit = new QLineEdit;
-    searchButton = new QPushButton(tr("Search"));
 
+    searchButton = new QPushButton(tr("Search"));
     searchButton->setMaximumHeight(60);
 
     logo = new QToolButton();
     logo->setIcon(QIcon(":/icons/64x64/mdictionary.png"));
 
-
     horizontalLayout->addWidget(logo);
     horizontalLayout->addWidget(searchStringLineEdit);
     horizontalLayout->addWidget(searchButton);
     horizontalLayout->setContentsMargins(10,10,10,10);
 
-
     connect(searchStringLineEdit, SIGNAL(returnPressed()),
             this, SLOT(search()));
 
@@ -101,7 +82,41 @@ MainWidget::MainWidget(QWidget *parent):
     setMaximumHeight(100);
 }
 
-void MainWidget::search() {
+void HomeWidget::initializeX11() {
+
+    Atom winTypeAtom = XInternAtom(QX11Info::display(),
+                                   "_NET_WM_WINDOW_TYPE",
+                                   false);
+
+    Atom homeAppletAtom = XInternAtom(QX11Info::display(),
+                                     "_HILDON_WM_WINDOW_TYPE_HOME_APPLET",
+                                     false);
+
+    Atom appletIDAtom = XInternAtom(QX11Info::display(),
+                                    "_HILDON_APPLET_ID",
+                                    false);
+
+    Atom utf8Atom = XInternAtom(QX11Info::display(),
+                                "UTF8_STRING",
+                                false);
+
+
+    // Set window type to home applet
+    XChangeProperty(QX11Info::display(), winId(), winTypeAtom,
+                    XA_ATOM, 32, PropModeReplace,
+                    (unsigned char *) &homeAppletAtom, 1);
+
+    // Applet id will be the same as application name
+    QByteArray id (
+            QCoreApplication::instance()->applicationName().remove(' ').toUtf8());
+
+
+    XChangeProperty(QX11Info::display(), winId(), appletIDAtom, utf8Atom, 8,
+                    PropModeReplace, (unsigned char *)id.constData(),
+                    id.length());
+}
+
+void HomeWidget::search() {
     if(searchStringLineEdit->text().isEmpty()) return;
 
     QDBusMessage message =
@@ -117,7 +132,7 @@ void MainWidget::search() {
     QDBusConnection::sessionBus().send(message);
 }
 
-void MainWidget::logoClicked() {
+void HomeWidget::logoClicked() {
     QDBusMessage message =
             QDBusMessage::createMethodCall("com.comarch.mdictionary",
                                            "/mainWindow",
@@ -128,8 +143,8 @@ void MainWidget::logoClicked() {
 
 
 
-void MainWidget::paintEvent(QPaintEvent *event) {
-
+void HomeWidget::paintEvent(QPaintEvent *event) {
+    //custom painting of rounded corners
     QPainter p(this);
     p.setBrush(QColor(0, 0, 0, 255));
 
@@ -138,4 +153,6 @@ void MainWidget::paintEvent(QPaintEvent *event) {
     p.drawRoundedRect(rect(), 25, 25);
 
     p.end();
+
+    QWidget::paintEvent(event);
 }
index 0fb7d10..375951d 100644 (file)
@@ -19,7 +19,8 @@
 
 *******************************************************************************/
 
-//Created by Mateusz Półrola
+//! \file MainWidget.cpp
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
 
 #ifndef MAINWIDGET_H
 #define MAINWIDGET_H
 #include <QtDBus/QDBusConnection>
 #include <QPushButton>
 
-class MainWidget : public QWidget
+//! Implements widget for maemo that allows user to quick search using mdictionary right of home screen.
+/*!
+  Shows tool button with logo of mDictionary which can start application.
+  In line edit user inputs word, and using button next to it or by pressing enter, widget start mDictionary already witch started search for given word.
+  If mDictionary is already running in background it will show the program.
+  */
+class HomeWidget : public QWidget
 {
     Q_OBJECT
 public:
-    explicit MainWidget(QWidget *parent = 0);
+    HomeWidget(QWidget *parent = 0);
 
 private slots:
     void search();
     void logoClicked();
 
 protected:
+    /*! Reimplemented paintEvent to display rounded corners with transparency */
     void paintEvent(QPaintEvent *);
 
 private:
+    /*! Initializes ui of widget*/
+    void initializeUI();
+
+    /*! Initializes X11 to set application type as home widget*/
+    void initializeX11();
+
+
     QLineEdit* searchStringLineEdit;
     QPushButton* searchButton;
     QToolButton* logo;
index bc4d769..2f9b15d 100644 (file)
 
 //Created by Mateusz Półrola
 
-#include <QtGui/QApplication>
 #include "MainWidget.h"
+#include <QtGui/QApplication>
 #include <X11/extensions/Xrender.h>
-#include <QtDBus/QDBusConnection>
+
 
 int main(int argc, char *argv[]) {
 
@@ -39,7 +39,7 @@ int main(int argc, char *argv[]) {
     QApplication::setOrganizationDomain("comarch.com");
     QApplication::setApplicationName("mDictionaryWidget");
 
-    MainWidget w;
+    HomeWidget w;
 
     w.show();