Mercurial > trustbridge
annotate ui/trayicon.cpp @ 1380:77c9e35657ab
(issue83) Remove testversion note
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 15 Jan 2015 15:28:40 +0100 |
parents | 5f4e77acb2f3 |
children |
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())); |
1314
5f4e77acb2f3
(issue155) Use the logo as the window icon.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1144
diff
changeset
|
54 mMessageBox->setWindowIcon(QIcon(":/img/logo.png")); |
5f4e77acb2f3
(issue155) Use the logo as the window icon.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1144
diff
changeset
|
55 |
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
|
56 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
|
57 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
|
58 } 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
|
59 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
|
60 } |
969
c096881e8ed0
(issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
871
diff
changeset
|
61 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
|
62 mMessageBox->show(); |
871
4efd6378c001
(issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 } |
969
c096881e8ed0
(issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
871
diff
changeset
|
64 |
c096881e8ed0
(issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
871
diff
changeset
|
65 void TrayIcon::messageDestroyed() { |
c096881e8ed0
(issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
871
diff
changeset
|
66 mMessageBox = NULL; |
c096881e8ed0
(issue50) Make message box a member variable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
871
diff
changeset
|
67 } |