+/*******************************************************************************
+
+ 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();
+}