view ui/trayicon.cpp @ 1316:ff9cd05e861e

(issue166) Fix certificiate removal The index that should be removed came from the filter proxy model and did not map to the real index. This was broken.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 13 Oct 2014 17:23:35 +0200
parents 5f4e77acb2f3
children
line wrap: on
line source
/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU GPL (v>=2)
 * and comes with ABSOLUTELY NO WARRANTY!
 * See LICENSE.txt for details.
 */

#include "trayicon.h"

#include <QMessageBox>
#include <QSystemTrayIcon>
#include <QDebug>
#include <QAbstractButton>
#include <QMainWindow>

TrayIcon::TrayIcon (QObject *parent) :
    QSystemTrayIcon (parent),
    useAlt(false),
    mMessageBox(NULL)
{
    if (QSystemTrayIcon::isSystemTrayAvailable() &&
        qgetenv("XDG_CURRENT_DESKTOP") != "Unity") {
        return;
    }
    qDebug() << "Platform is without systray. Using Alternative notifications";
    useAlt = true;

}

void TrayIcon::show() {
    if (useAlt) {
        qDebug() << "Would show";
        return;
    }
    QSystemTrayIcon::show();
}

void TrayIcon::showMessage(const QString &title, const QString &msg,
                           QSystemTrayIcon::MessageIcon msg_icon, int msecs,
                           const QString &okBtnText) {
    if (!useAlt) {
        QSystemTrayIcon::showMessage(title, msg, msg_icon, msecs);
        return;
    }
    if (!mMessageBox) {
        mMessageBox = new QMessageBox (QMessageBox::Information,
                                       title, msg, QMessageBox::Ok | QMessageBox::No,
                                       qobject_cast<QWidget*>(parent()));
        connect(mMessageBox->button(QMessageBox::Ok), SIGNAL(clicked()), this, SIGNAL(messageClicked()));
        connect(mMessageBox, SIGNAL(destroyed()), this, SLOT(messageDestroyed()));
    }
    mMessageBox->setIconPixmap(icon().pixmap(mMessageBox->iconPixmap().size()));
    mMessageBox->setWindowIcon(QIcon(":/img/logo.png"));

    if (!okBtnText.isEmpty()) {
        mMessageBox->button(QMessageBox::Ok)->setText (okBtnText);
    } else {
        mMessageBox->button(QMessageBox::Ok)->setText (tr("Install update"));
    }
    mMessageBox->button(QMessageBox::No)->setText (tr("Remind me later"));
    mMessageBox->show();
}

void TrayIcon::messageDestroyed() {
    mMessageBox = NULL;
}

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