xdxf wrong file format
[mdictionary] / src / mdictionary / gui / NotifyManager.cpp
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
22 //! \file NotifyManager.cpp
23 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
24
25 #include "NotifyManager.h"
26 #include <QMessageBox>
27 #ifdef Q_WS_MAEMO_5
28     #include <QMaemo5InformationBox>
29 #endif
30 #include <QDebug>
31 #include <QLabel>
32
33 NotifyManager::NotifyManager(QObject *parent) :
34     QObject(parent)
35 {
36 }
37
38
39 void NotifyManager::notificationClosed() {
40     QObject* dialog = QObject::sender();
41
42     QHash<QString, QDialog*>::Iterator it;
43
44     for(it = activeNotifies.begin(); it != activeNotifies.end(); it++) {
45         if(it.value() == dialog) {
46             activeNotifies.remove(it.key());
47             it.value()->deleteLater();
48             return;
49         }
50     }
51 }
52
53 void NotifyManager::screenChanged() {
54     QHash<QString, QDialog*>::Iterator it;
55
56     for(it = activeNotifies.begin(); it != activeNotifies.end(); it++) {
57         it.value()->hide();
58         it.value()->show();
59     }
60 }
61
62 void NotifyManager::showNotification(Notify::NotifyType type, QString text) {
63     if(activeNotifies.contains(text)) {
64         return;
65     }
66
67     #ifdef Q_WS_MAEMO_5
68         QMaemo5InformationBox* mbox =
69                 new QMaemo5InformationBox(0);
70
71         QLabel* infoLabel = new QLabel(text);
72         infoLabel->setAlignment(Qt::AlignCenter);
73         infoLabel->setWordWrap(true);
74
75         mbox->setWidget(infoLabel);
76     #else
77         QMessageBox* mbox =
78                 new QMessageBox(qobject_cast<QWidget*>(this->parent()));
79
80     #endif
81
82
83     switch(type) {
84
85     case Notify::Info:
86         #ifdef Q_WS_MAEMO_5
87             mbox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
88         #else
89             mbox->setText(text);
90             mbox->setWindowTitle(tr("Information"));
91             mbox->setIcon(QMessageBox::Information);
92
93         #endif
94         break;
95
96     case Notify::Warning:
97         #ifndef Q_WS_MAEMO_5
98                 mbox->setText(text);
99                 mbox->setWindowTitle(tr("Warning"));
100                 mbox->setIcon(QMessageBox::Warning);
101                 break;
102         #endif
103
104     case Notify::Error:
105         #ifdef Q_WS_MAEMO_5
106             mbox->setTimeout(QMaemo5InformationBox::NoTimeout);
107         #else
108             mbox->setText(text);
109             mbox->setWindowTitle(tr("Error"));
110             mbox->setIcon(QMessageBox::Critical);
111         #endif
112         break;
113     }
114
115     activeNotifies.insert(text, mbox);
116     connect(mbox, SIGNAL(finished(int)), this, SLOT(notificationClosed()));
117     mbox->exec();
118 }