annotate ui/trayicon.cpp @ 1296:13b56e9c7e7b

(issue149) licenses/README.txt additions and corrections.
author Bernhard Reiter <bernhard@intevation.de>
date Mon, 29 Sep 2014 16:12:47 +0200
parents a4282bc67a8b
children 5f4e77acb2f3
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,
1144
a4282bc67a8b (issue99) Make OK button in message box notification configurable and change it for list updates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 970
diff changeset
40 QSystemTrayIcon::MessageIcon msg_icon, int msecs,
a4282bc67a8b (issue99) Make OK button in message box notification configurable and change it for list updates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 970
diff changeset
41 const QString &okBtnText) {
871
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 if (!useAlt) {
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 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
44 return;
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45 }
969
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
46 if (!mMessageBox) {
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
47 mMessageBox = new QMessageBox (QMessageBox::Information,
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
48 title, msg, QMessageBox::Ok | QMessageBox::No,
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
49 qobject_cast<QWidget*>(parent()));
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
50 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
51 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
52 }
970
c80777457133 (issue50) Add window icon and icon for 48x48px
Andre Heinecke <andre.heinecke@intevation.de>
parents: 969
diff changeset
53 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
54 mMessageBox->setWindowIcon(icon());
1144
a4282bc67a8b (issue99) Make OK button in message box notification configurable and change it for list updates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 970
diff changeset
55 if (!okBtnText.isEmpty()) {
a4282bc67a8b (issue99) Make OK button in message box notification configurable and change it for list updates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 970
diff changeset
56 mMessageBox->button(QMessageBox::Ok)->setText (okBtnText);
a4282bc67a8b (issue99) Make OK button in message box notification configurable and change it for list updates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 970
diff changeset
57 } else {
a4282bc67a8b (issue99) Make OK button in message box notification configurable and change it for list updates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 970
diff changeset
58 mMessageBox->button(QMessageBox::Ok)->setText (tr("Install update"));
a4282bc67a8b (issue99) Make OK button in message box notification configurable and change it for list updates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 970
diff changeset
59 }
969
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
60 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
61 mMessageBox->show();
871
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 }
969
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
63
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
64 void TrayIcon::messageDestroyed() {
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
65 mMessageBox = NULL;
c096881e8ed0 (issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
66 }

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