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 *******************************************************************************/
22 /*! \file NotifyManager.cpp
23 \brief Manages notifications in applications
25 \author Mateusz Półrola <mateusz.polrola@comarch.pl>
28 #include "NotifyManager.h"
29 #include <QMessageBox>
31 #include <QMaemo5InformationBox>
36 NotifyManager::NotifyManager(QObject *parent) :
43 void NotifyManager::notificationClosed() {
44 QObject* dialog = QObject::sender();
46 QHash<QString, QDialog*>::Iterator it;
48 for(it = activeNotifies.begin(); it != activeNotifies.end(); it++) {
49 if(it.value() == dialog) {
50 activeNotifies.remove(it.key());
51 it.value()->deleteLater();
57 void NotifyManager::screenChanged() {
58 QHash<QString, QDialog*>::Iterator it;
60 for(it = activeNotifies.begin(); it != activeNotifies.end(); it++) {
66 void NotifyManager::showNotification(Notify::NotifyType type, QString text) {
67 if(activeNotifies.contains(text)) {
73 if(menu && menu->isVisible())
76 parent = qobject_cast<QWidget*>(this->parent());
79 QMaemo5InformationBox* mbox =
80 new QMaemo5InformationBox(parent);
82 QLabel* infoLabel = new QLabel(text);
83 infoLabel->setAlignment(Qt::AlignCenter);
84 infoLabel->setWordWrap(true);
87 mbox->setWidget(infoLabel);
91 new QMessageBox(parent);
101 mbox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
104 mbox->setWindowTitle(tr("Information"));
105 mbox->setIcon(QMessageBox::Information);
112 case Notify::Warning:
115 mbox->setWindowTitle(tr("Warning"));
116 mbox->setIcon(QMessageBox::Warning);
122 mbox->setTimeout(QMaemo5InformationBox::NoTimeout);
123 ((QLabel*)mbox->widget())->setContentsMargins(5,15,5,15);
126 mbox->setWindowTitle(tr("Error"));
127 mbox->setIcon(QMessageBox::Critical);
131 activeNotifies.insert(text, mbox);
132 connect(mbox, SIGNAL(finished(int)), this, SLOT(notificationClosed()));
136 void NotifyManager::setMenu(QWidget *w) {