void KNotificationBackend::notify(const Notification &n)
{
    QString type;
    switch (n.type) {
    case Highlight:
        type = "Highlight"; break;
    case HighlightFocused:
        type = "HighlightFocused"; break;
    case PrivMsg:
        type = "PrivMsg"; break;
    case PrivMsgFocused:
        type = "PrivMsgFocused"; break;
    }

#if QT_VERSION < 0x050000
    QString message = QString("<b>&lt;%1&gt;</b> %2").arg(n.sender, Qt::escape(n.message));
#else
    QString message = QString("<b>&lt;%1&gt;</b> %2").arg(n.sender, n.message.toHtmlEscaped());
#endif
    KNotification *notification = KNotification::event(type, message, QIcon::fromTheme("dialog-information").pixmap(48), QtUi::mainWindow(),
        KNotification::RaiseWidgetOnActivation
        |KNotification::CloseWhenWidgetActivated
        |KNotification::CloseOnTimeout);
    connect(notification, SIGNAL(activated(uint)), SLOT(notificationActivated()));
    notification->setActions(QStringList("View"));
    notification->setProperty("notificationId", n.notificationId);

    _notifications.append(qMakePair(n.notificationId, QPointer<KNotification>(notification)));

    updateToolTip();
    QtUi::mainWindow()->systemTray()->setAlert(true);
}
SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
    : AbstractNotificationBackend(parent),
    _blockActivation(false)
{
    NotificationSettings notificationSettings;
    notificationSettings.initAndNotify("Systray/ShowBubble", this, SLOT(showBubbleChanged(QVariant)), true);
    notificationSettings.initAndNotify("Systray/Animate", this, SLOT(animateChanged(QVariant)), true);

    connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked(uint)), SLOT(notificationActivated(uint)));
    connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)),
        SLOT(notificationActivated(SystemTray::ActivationReason)));

    QApplication::instance()->installEventFilter(this);

    updateToolTip();
}
Beispiel #3
0
void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend)
{
    if (!_notificationBackends.contains(backend)) {
        _notificationBackends.append(backend);
        instance()->connect(backend, SIGNAL(activated(uint)), SLOT(notificationActivated(uint)));
    }
}
KNotificationBackend::KNotificationBackend(QObject *parent)
    : AbstractNotificationBackend(parent)
{
    connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)),
        SLOT(notificationActivated(SystemTray::ActivationReason)));

    updateToolTip();
}
void KNotificationBackend::notificationActivated(SystemTray::ActivationReason reason)
{
    if (reason == SystemTray::Trigger) {
        if (_notifications.count())
            notificationActivated(_notifications.first().first);  // oldest one
        else
            GraphicalUi::toggleMainWidget();
    }
}
void KNotificationBackend::notificationActivated()
{
    uint id = 0;
    KNotification *n = qobject_cast<KNotification *>(sender());
    if (n)
        id = n->property("notificationId").toUInt();

    notificationActivated(id);
}
void SystrayNotificationBackend::notificationActivated(SystemTray::ActivationReason reason)
{
    if (reason == SystemTray::Trigger) {
        notificationActivated(0);
    }
}