diff ui/trayicon.cpp @ 871:4efd6378c001

(issue51) Add fallback in case systemtray is unavailable. If no systemtray is available it will now show a message box as notification.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 06 Aug 2014 18:03:23 +0200
parents
children c096881e8ed0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/trayicon.cpp	Wed Aug 06 18:03:23 2014 +0200
@@ -0,0 +1,51 @@
+/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=2)
+ * and comes with ABSOLUTELY NO WARRANTY!
+ * See LICENSE.txt for details.
+ */
+
+#include "trayicon.h"
+
+#include <QMessageBox>
+#include <QSystemTrayIcon>
+#include <QDebug>
+#include <QAbstractButton>
+#include <QMainWindow>
+
+TrayIcon::TrayIcon (QObject *parent) :
+    QSystemTrayIcon (parent),
+    useAlt(false)
+{
+    if (QSystemTrayIcon::isSystemTrayAvailable() &&
+        qgetenv("XDG_CURRENT_DESKTOP") != "Unity") {
+        return;
+    }
+    qDebug() << "Platform is without systray. Using Alternative notifications";
+    useAlt = true;
+
+}
+
+void TrayIcon::show() {
+    if (useAlt) {
+        qDebug() << "Would show";
+        return;
+    }
+    QSystemTrayIcon::show();
+}
+
+void TrayIcon::showMessage(const QString &title, const QString &msg,
+                           QSystemTrayIcon::MessageIcon msg_icon, int msecs) {
+    if (!useAlt) {
+        QSystemTrayIcon::showMessage(title, msg, msg_icon, msecs);
+        return;
+    }
+    QMessageBox *theMessage = new QMessageBox (QMessageBox::Information,
+            title, msg, QMessageBox::Ok | QMessageBox::No, qobject_cast<QWidget*>(parent()));
+    theMessage->setIconPixmap (icon().pixmap(theMessage->iconPixmap().size()));
+    theMessage->button(QMessageBox::Ok)->setText (tr("Install update"));
+    theMessage->button(QMessageBox::No)->setText (tr("Remind me later"));
+    connect(theMessage->button(QMessageBox::Ok), SIGNAL(clicked()), this, SIGNAL(messageClicked()));
+    theMessage->show();
+}

http://wald.intevation.org/projects/trustbridge/