annotate ui/trayicon.cpp @ 1093:153af47456d0

Add option "USE_REAL_RESOURCES" to avoid the if 1 dance for test/release builds. If the option is not set the download resource is trustbridge-development.*
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 15 Sep 2014 10:17:17 +0200
parents c80777457133
children a4282bc67a8b
rev   line source
871
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
3 *
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
6 * See LICENSE.txt for details.
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7 */
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 #include "trayicon.h"
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11 #include <QMessageBox>
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 #include <QSystemTrayIcon>
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13 #include <QDebug>
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 #include <QAbstractButton>
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 #include <QMainWindow>
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 TrayIcon::TrayIcon (QObject *parent) :
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 QSystemTrayIcon (parent),
969
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
19 useAlt(false),
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
20 mMessageBox(NULL)
871
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 {
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22 if (QSystemTrayIcon::isSystemTrayAvailable() &&
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 qgetenv("XDG_CURRENT_DESKTOP") != "Unity") {
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 return;
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 }
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 qDebug() << "Platform is without systray. Using Alternative notifications";
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 useAlt = true;
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 }
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 void TrayIcon::show() {
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32 if (useAlt) {
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 qDebug() << "Would show";
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 return;
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 }
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 QSystemTrayIcon::show();
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 }
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 void TrayIcon::showMessage(const QString &title, const QString &msg,
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 QSystemTrayIcon::MessageIcon msg_icon, int msecs) {
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 if (!useAlt) {
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 QSystemTrayIcon::showMessage(title, msg, msg_icon, msecs);
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 return;
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44 }
969
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
45 if (!mMessageBox) {
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
46 mMessageBox = new QMessageBox (QMessageBox::Information,
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
47 title, msg, QMessageBox::Ok | QMessageBox::No,
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
48 qobject_cast<QWidget*>(parent()));
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
49 connect(mMessageBox->button(QMessageBox::Ok), SIGNAL(clicked()), this, SIGNAL(messageClicked()));
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
50 connect(mMessageBox, SIGNAL(destroyed()), this, SLOT(messageDestroyed()));
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
51 }
970
c80777457133 (issue50) Add window icon and icon for 48x48px
Andre Heinecke <andre.heinecke@intevation.de>
parents: 969
diff changeset
52 mMessageBox->setIconPixmap(icon().pixmap(mMessageBox->iconPixmap().size()));
c80777457133 (issue50) Add window icon and icon for 48x48px
Andre Heinecke <andre.heinecke@intevation.de>
parents: 969
diff changeset
53 mMessageBox->setWindowIcon(icon());
969
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
54 mMessageBox->button(QMessageBox::Ok)->setText (tr("Install update"));
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
55 mMessageBox->button(QMessageBox::No)->setText (tr("Remind me later"));
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
56 mMessageBox->show();
871
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57 }
969
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
58
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
59 void TrayIcon::messageDestroyed() {
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
60 mMessageBox = NULL;
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
61 }

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