Mercurial > trustbridge
comparison 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 |
comparison
equal
deleted
inserted
replaced
870:e93ae5233217 | 871:4efd6378c001 |
---|---|
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
8 | |
9 #include "trayicon.h" | |
10 | |
11 #include <QMessageBox> | |
12 #include <QSystemTrayIcon> | |
13 #include <QDebug> | |
14 #include <QAbstractButton> | |
15 #include <QMainWindow> | |
16 | |
17 TrayIcon::TrayIcon (QObject *parent) : | |
18 QSystemTrayIcon (parent), | |
19 useAlt(false) | |
20 { | |
21 if (QSystemTrayIcon::isSystemTrayAvailable() && | |
22 qgetenv("XDG_CURRENT_DESKTOP") != "Unity") { | |
23 return; | |
24 } | |
25 qDebug() << "Platform is without systray. Using Alternative notifications"; | |
26 useAlt = true; | |
27 | |
28 } | |
29 | |
30 void TrayIcon::show() { | |
31 if (useAlt) { | |
32 qDebug() << "Would show"; | |
33 return; | |
34 } | |
35 QSystemTrayIcon::show(); | |
36 } | |
37 | |
38 void TrayIcon::showMessage(const QString &title, const QString &msg, | |
39 QSystemTrayIcon::MessageIcon msg_icon, int msecs) { | |
40 if (!useAlt) { | |
41 QSystemTrayIcon::showMessage(title, msg, msg_icon, msecs); | |
42 return; | |
43 } | |
44 QMessageBox *theMessage = new QMessageBox (QMessageBox::Information, | |
45 title, msg, QMessageBox::Ok | QMessageBox::No, qobject_cast<QWidget*>(parent())); | |
46 theMessage->setIconPixmap (icon().pixmap(theMessage->iconPixmap().size())); | |
47 theMessage->button(QMessageBox::Ok)->setText (tr("Install update")); | |
48 theMessage->button(QMessageBox::No)->setText (tr("Remind me later")); | |
49 connect(theMessage->button(QMessageBox::Ok), SIGNAL(clicked()), this, SIGNAL(messageClicked())); | |
50 theMessage->show(); | |
51 } |