Fixed notification manager, to display properly notifications from pluins
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 7 Sep 2010 06:09:51 +0000 (08:09 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 7 Sep 2010 06:09:51 +0000 (08:09 +0200)
16 files changed:
src/include/CommonDictInterface.h
src/include/DictDialog.h
src/mdictionary/backbone/backbone.cpp
src/mdictionary/backbone/backbone.h
src/mdictionary/gui/DictManagerWidget.cpp
src/mdictionary/gui/DictManagerWidget.h
src/mdictionary/gui/MainWindow.cpp
src/mdictionary/gui/MainWindow.h
src/mdictionary/gui/MenuWidget.cpp
src/mdictionary/gui/MenuWidget.h
src/mdictionary/gui/NotifyManager.cpp
src/mdictionary/gui/NotifyManager.h
src/plugins/xdxf/XdxfDialog.cpp
src/plugins/xdxf/XdxfDialog.h
src/plugins/xdxf/XdxfDictDialog.cpp
src/plugins/xdxf/xdxfplugin.cpp

index 329fd32..f09815d 100644 (file)
@@ -127,7 +127,7 @@ class CommonDictInterface : public QObject, public AccentsNormalizer {
             different ways
         \param QString text of the notification
     */
-    void notify(Notify::NotifyType, QString, QWidget* parent = 0);
+    void notify(Notify::NotifyType, QString);
     
 
 protected:
index f5f5ee0..03e067c 100644 (file)
@@ -49,7 +49,7 @@ public:
     virtual void changeSettings(QWidget *parent = 0) = 0;
 
 Q_SIGNALS:
-    void notify(Notify::NotifyType, QString, QWidget* parent = 0);
+    void notify(Notify::NotifyType, QString);
 };
 
 #endif // DICTDIALOG_H
index 36782d6..8f37781 100644 (file)
@@ -254,8 +254,8 @@ void Backbone::addInternalDictionary(CommonDictInterface* dict, bool active) {
         dict->setHash(++_dictNum); // Hash must be uniqe in every session but not between
         _dicts[dict] = active;
         connect(dict, SIGNAL(settingsChanged()), this, SLOT(dictUpdated()));
-        connect(dict, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)), this,
-            SIGNAL(notify(Notify::NotifyType,QString, QWidget*)));
+        connect(dict, SIGNAL(notify(Notify::NotifyType,QString)), this,
+            SIGNAL(notify(Notify::NotifyType,QString)));
     }
 }
 
@@ -363,8 +363,8 @@ void Backbone::loadPlugins() {
         if(!exists) {
             _plugins.append(plugin);
             plugin->retranslate();
-            connect(plugin, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)),
-                    this, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)));
+            connect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+                    this, SIGNAL(notify(Notify::NotifyType,QString)));
         }
     }
 }
index 2ef3bc7..89a9da7 100644 (file)
@@ -274,7 +274,7 @@ Q_SIGNALS:
             different ways
         \param QString text of the notification
     */
-    void notify(Notify::NotifyType, QString, QWidget*parent = 0);
+    void notify(Notify::NotifyType, QString);
 
 private Q_SLOTS:
     void bookmarksListReady();
index 2e96e65..00ce860 100644 (file)
@@ -178,11 +178,11 @@ void DictManagerWidget::addNewDictButtonClicked() {
    CommonDictInterface* selectedPlugin =
            DictTypeSelectDialog::addNewDict(
                    guiInterface->getPlugins(),
-                   menuWidget->applicationMenu());
+                   this->parentWidget());
 
    if(selectedPlugin != NULL) {
        Settings* settings =
-               selectedPlugin->dictDialog()->addNewDictionary(menuWidget->applicationMenu());
+               selectedPlugin->dictDialog()->addNewDictionary(this->parentWidget());
 
        if(settings != NULL) {
            CommonDictInterface* newDict = selectedPlugin->getNew(settings);
@@ -225,7 +225,7 @@ void DictManagerWidget::settingsButtonClicked() {
     #endif
    QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
    if(selected.count() > 0) {
-       dictsHash[selected[0]]->dictDialog()->changeSettings(menuWidget->applicationMenu());
+       dictsHash[selected[0]]->dictDialog()->changeSettings(this->parentWidget());
    }
    refreshDictsList();
 }
index 56e5989..f55949f 100644 (file)
@@ -49,8 +49,6 @@ public:
     */
     explicit DictManagerWidget(GUIInterface *parent = 0);
 
-    void setMenuWidget(MenuWidget *w) {menuWidget = w;}
-
 protected:
     void showEvent(QShowEvent *e);
     void hideEvent(QHideEvent *e);
@@ -126,8 +124,6 @@ private:
         QPushButton* closeButton;
         bool _save;
     #endif
-
-    MenuWidget* menuWidget;
 };
 
 #endif // DICTMANAGERWIDGET_H
index 42bd584..c5a6cc1 100644 (file)
@@ -80,11 +80,13 @@ void MainWindow::initializeUI() {
     menuBar = new QMenuBar();
     setMenuBar(menuBar);
 
+    notifyManager = new NotifyManager(this);
+
     initializeSearchWidgets();
 
     initializeMenu();
 
-    notifyManager = new NotifyManager(this);
+
 }
 
 void MainWindow::initializeSearchWidgets() {
@@ -124,7 +126,8 @@ void MainWindow::initializeMenu() {
 
     menuBar->addAction(menuWidget);
 
-    dictManagerWidget->setMenuWidget(menuWidget);
+    connect(menuWidget, SIGNAL(setApplicationMenu(QWidget*)),
+            notifyManager, SLOT(setMenu(QWidget*)));
 #else
     dictionariesAction = menuBar->addAction(tr("Dictionaries"));
     connect(dictionariesAction, SIGNAL(triggered()),
@@ -374,8 +377,8 @@ Settings* MainWindow::settings() {
 }
 
 
-void MainWindow::showNotification(Notify::NotifyType type, QString text, QWidget* parent) {
-    notifyManager->showNotification(type, text, parent);
+void MainWindow::showNotification(Notify::NotifyType type, QString text) {
+    notifyManager->showNotification(type, text);
 }
 
 void MainWindow::connectBackbone() {
@@ -438,8 +441,8 @@ void MainWindow::connectBackbone() {
     connect(backbone, SIGNAL(searchCanceled()),
             this, SIGNAL(setIdle()));
 
-    connect(backbone, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)),
-            this, SLOT(showNotification(Notify::NotifyType,QString, QWidget*)));
+    connect(backbone, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SLOT(showNotification(Notify::NotifyType,QString)));
 }
 
 void MainWindow::connectSearchBar() {
index 3e7e95c..b4738b3 100644 (file)
@@ -220,7 +220,7 @@ public:
       \param type type of notification
       \param message notification message
     */
-    void showNotification(Notify::NotifyType type, QString message, QWidget *parent=0);
+    void showNotification(Notify::NotifyType type, QString message);
 
 private Q_SLOTS:
     //! Disables menu
index 146b765..e447d2f 100644 (file)
@@ -33,6 +33,8 @@ MenuWidget::MenuWidget(QWidget *parent) :
     tabWidget = new MenuTabWidget();
     tabWidget->setStyleSheet("QTabWidget::tab-bar {alignment: center;}");
 
+    applicationMenu = 0;
+
 }
 
 MenuWidget::~MenuWidget() {
@@ -58,17 +60,18 @@ void MenuWidget::removeSubMenu(QString title) {
     }
 }
 
-QWidget* MenuWidget::createWidget(QWidget *) {
+QWidget* MenuWidget::createWidget(QWidget *parent) {
     /*When we have request to create new widget we return tabWidget.
     When the menu is closing, tabWidget will receive hideEvent which will set
     its parent to NULL and prevent it from delete, so we can still use this
     widget*/
+    if(applicationMenu==0) {
+        applicationMenu = parent;
+        Q_EMIT setApplicationMenu(applicationMenu);
+    }
     return tabWidget;
 }
 
-QWidget* MenuWidget::applicationMenu() {
-    return tabWidget->parentWidget();
-}
 
 void MenuWidget::hideMenu() {
     tabWidget->parentWidget()->hide();
index 448e31c..aa31fc3 100644 (file)
@@ -50,7 +50,8 @@ public:
     */
     void removeSubMenu(QString title);
 
-    QWidget* applicationMenu();
+Q_SIGNALS:
+    void setApplicationMenu(QWidget*);
 
 public Q_SLOTS:
     /*!
@@ -61,8 +62,11 @@ public Q_SLOTS:
     void showMenu();
 
 protected:
-    MenuTabWidget* tabWidget;
     QWidget* createWidget(QWidget *parent);
+
+private:
+    MenuTabWidget* tabWidget;
+    QWidget* applicationMenu;
 };
 
 #endif // MENUWIDGET_H
index eeed43b..d8b60ed 100644 (file)
@@ -33,7 +33,7 @@
 NotifyManager::NotifyManager(QObject *parent) :
     QObject(parent)
 {
-
+    menu = 0;
 }
 
 
@@ -60,13 +60,18 @@ void NotifyManager::screenChanged() {
     }
 }
 
-void NotifyManager::showNotification(Notify::NotifyType type, QString text, QWidget* parent) {
+void NotifyManager::showNotification(Notify::NotifyType type, QString text) {
     if(activeNotifies.contains(text)) {
         return;
     }
 
-    if(parent == 0)
+    QWidget* parent;
+
+    if(menu && menu->isVisible())
+        parent = menu;
+    else
         parent = qobject_cast<QWidget*>(this->parent());
+
     #ifdef Q_WS_MAEMO_5
         QMaemo5InformationBox* mbox =
                 new QMaemo5InformationBox(parent);
@@ -123,3 +128,8 @@ void NotifyManager::showNotification(Notify::NotifyType type, QString text, QWid
     connect(mbox, SIGNAL(finished(int)), this, SLOT(notificationClosed()));
     mbox->exec();
 }
+
+void NotifyManager::setMenu(QWidget *w) {
+    menu = w;
+    qDebug()<<w<<"mM";
+}
index f42645e..831fcda 100644 (file)
@@ -53,17 +53,20 @@ public slots:
         \param text text of notification
         \sa Notify::NotifyType
     */
-    void showNotification(Notify::NotifyType type, QString text, QWidget*parent=0);
+    void showNotification(Notify::NotifyType type, QString text);
 
     //! Refresh all notifications when stacked widgets changes
     void screenChanged();
 
+    void setMenu(QWidget*);
+
 private slots:
     //! Informs that notification was closed and can be deleted
     void notificationClosed();
 
 private:
     QHash<QString, QDialog*> activeNotifies;
+    QWidget* menu;
 };
 
 #endif // NOTIFYMANAGER_H
index dee28ef..c34b50a 100644 (file)
@@ -217,7 +217,7 @@ void XdxfDialog::saveSettings() {
 
 void XdxfDialog::accept() {
     if(type == New && _dictionaryFilePath.isEmpty()) {
-        Q_EMIT notify(Notify::Warning, tr("File path is not set"), this);
+        Q_EMIT notify(Notify::Warning, tr("File path is not set"));
 
         return;
     }
@@ -231,11 +231,11 @@ Settings* XdxfDialog::getSettings() {
 }
 
 void XdxfDialog::showCacheInfo() {
-    Q_EMIT notify(Notify::Info, tr("Optimize for quicker searches (may take some time)"), this);
+    Q_EMIT notify(Notify::Warning, tr("Optimize for quicker searches (may take some time)"));
 }
 
 void XdxfDialog::showAccentsInfo() {
-    Q_EMIT notify(Notify::Info, tr("Strip accents (searching takes more "
-                                   "time, but spelling don't have to be exact)"), this);
+    Q_EMIT notify(Notify::Warning, tr("Strip accents (searching takes more "
+                                   "time, but spelling don't have to be exact)"));
 }
 
index a9af3d8..d1c8225 100644 (file)
@@ -41,7 +41,7 @@ public:
     Settings* getSettings();
 
 Q_SIGNALS:
-    void notify(Notify::NotifyType, QString, QWidget*);
+    void notify(Notify::NotifyType, QString);
 
 public Q_SLOTS:
     void accept();
index f1bcad2..de4d9aa 100644 (file)
@@ -39,8 +39,8 @@ Settings* XdxfDictDialog::addNewDictionary(QWidget *parent) {
     qDebug()<<parent;
     XdxfDialog d(0, XdxfDialog::New, parent);
 
-    connect(&d, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)),
-            this, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)));
+    connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
 
     if(d.exec() == QDialog::Accepted) {
         return d.getSettings();
@@ -51,8 +51,8 @@ Settings* XdxfDictDialog::addNewDictionary(QWidget *parent) {
 void XdxfDictDialog::changeSettings(QWidget * parent) {
     XdxfDialog d(plugin, XdxfDialog::Change, parent);
 
-    connect(&d, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)),
-            this, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)));
+    connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
 
     if(d.exec() == QDialog::Accepted) {
         plugin->setSettings(d.getSettings());
index 533350b..c06eac5 100644 (file)
@@ -32,8 +32,8 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
     _settings = new Settings();
     _dictDialog = new XdxfDictDialog(this, this);
 
-    connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)),
-            this, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)));
+    connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
 
     cachingDialog = new XdxfCachingDialog(this);
 
@@ -329,6 +329,8 @@ DictDialog* XdxfPlugin::dictDialog() {
 
 CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
     XdxfPlugin *plugin = new XdxfPlugin();
+    connect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
     if(settings && plugin->setSettings(settings)) {
         return plugin;
     }