File: actiontest.cpp

package info (click to toggle)
kf6-knotifications 6.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,816 kB
  • sloc: cpp: 3,180; java: 309; xml: 122; python: 24; sh: 14; makefile: 7; ansic: 4
file content (33 lines) | stat: -rw-r--r-- 1,159 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
   SPDX-FileCopyrightText: 2023 Nicolas Fella <nicolas.fella@gmx.de>

   SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */

#include <KNotification>

#include <QGuiApplication>

int main(int argc, char **argv)
{
    QGuiApplication app(argc, argv);

    KNotification *notification = new KNotification(QStringLiteral("notification"));
    notification->setComponentName(QStringLiteral("plasma_workspace"));
    notification->setText(QStringLiteral("Hello!"));
    notification->setTitle(QStringLiteral("Yo"));

    KNotificationAction *action = notification->addAction(QStringLiteral("Open it"));
    QObject::connect(action, &KNotificationAction::activated, &app, [notification] {
        qWarning() << "action activated" << notification->xdgActivationToken();
    });

    KNotificationAction *defaultAction = notification->addDefaultAction(QStringLiteral("Aaaa"));
    QObject::connect(defaultAction, &KNotificationAction::activated, &app, [notification] {
        qWarning() << "default action activated" << notification->xdgActivationToken();
    });

    notification->sendEvent();

    return app.exec();
}