andre@871: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik andre@871: * Software engineering by Intevation GmbH andre@871: * andre@871: * This file is Free Software under the GNU GPL (v>=2) andre@871: * and comes with ABSOLUTELY NO WARRANTY! andre@871: * See LICENSE.txt for details. andre@871: */ andre@871: andre@871: #include "trayicon.h" andre@871: andre@871: #include andre@871: #include andre@871: #include andre@871: #include andre@871: #include andre@871: andre@871: TrayIcon::TrayIcon (QObject *parent) : andre@871: QSystemTrayIcon (parent), andre@969: useAlt(false), andre@969: mMessageBox(NULL) andre@871: { andre@871: if (QSystemTrayIcon::isSystemTrayAvailable() && andre@871: qgetenv("XDG_CURRENT_DESKTOP") != "Unity") { andre@871: return; andre@871: } andre@871: qDebug() << "Platform is without systray. Using Alternative notifications"; andre@871: useAlt = true; andre@871: andre@871: } andre@871: andre@871: void TrayIcon::show() { andre@871: if (useAlt) { andre@871: qDebug() << "Would show"; andre@871: return; andre@871: } andre@871: QSystemTrayIcon::show(); andre@871: } andre@871: andre@871: void TrayIcon::showMessage(const QString &title, const QString &msg, andre@1144: QSystemTrayIcon::MessageIcon msg_icon, int msecs, andre@1144: const QString &okBtnText) { andre@871: if (!useAlt) { andre@871: QSystemTrayIcon::showMessage(title, msg, msg_icon, msecs); andre@871: return; andre@871: } andre@969: if (!mMessageBox) { andre@969: mMessageBox = new QMessageBox (QMessageBox::Information, andre@969: title, msg, QMessageBox::Ok | QMessageBox::No, andre@969: qobject_cast(parent())); andre@969: connect(mMessageBox->button(QMessageBox::Ok), SIGNAL(clicked()), this, SIGNAL(messageClicked())); andre@969: connect(mMessageBox, SIGNAL(destroyed()), this, SLOT(messageDestroyed())); andre@969: } andre@970: mMessageBox->setIconPixmap(icon().pixmap(mMessageBox->iconPixmap().size())); andre@1314: mMessageBox->setWindowIcon(QIcon(":/img/logo.png")); andre@1314: andre@1144: if (!okBtnText.isEmpty()) { andre@1144: mMessageBox->button(QMessageBox::Ok)->setText (okBtnText); andre@1144: } else { andre@1144: mMessageBox->button(QMessageBox::Ok)->setText (tr("Install update")); andre@1144: } andre@969: mMessageBox->button(QMessageBox::No)->setText (tr("Remind me later")); andre@969: mMessageBox->show(); andre@871: } andre@969: andre@969: void TrayIcon::messageDestroyed() { andre@969: mMessageBox = NULL; andre@969: }