Advance Wayland and KDE package bring-up
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
include(ECMMarkAsTest)
|
||||
|
||||
macro(knotifications_executable_tests)
|
||||
foreach(_testname ${ARGN})
|
||||
add_executable(${_testname} ${_testname}.cpp)
|
||||
target_link_libraries(${_testname} Qt6::DBus KF6::Notifications)
|
||||
ecm_mark_as_test(${_testname})
|
||||
endforeach(_testname)
|
||||
endmacro()
|
||||
|
||||
if (HAVE_DBUS)
|
||||
knotifications_executable_tests(
|
||||
unitylaunchertest
|
||||
knotificationdbustest
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <QTimer>
|
||||
#include <knotification.h>
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
|
||||
void notificationDBusCall(const QString &iconName, const QString &title, const QString &body, const QStringList &actions, bool persistent = false)
|
||||
{
|
||||
QDBusMessage dbusNotificationMessage = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("/org/freedesktop/Notifications"),
|
||||
QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("Notify"));
|
||||
|
||||
QList<QVariant> args;
|
||||
|
||||
args.append(QString()); // app_name
|
||||
args.append((uint)0); // notification to update
|
||||
args.append(iconName); // app_icon
|
||||
args.append(title); // summary
|
||||
args.append(body); // body
|
||||
|
||||
QStringList actionList;
|
||||
int actId = 0;
|
||||
for (const QString &actionName : actions) {
|
||||
actId++;
|
||||
actionList.append(QString::number(actId));
|
||||
actionList.append(actionName);
|
||||
}
|
||||
|
||||
args.append(actionList); // actions
|
||||
|
||||
args.append(QVariantMap()); // hints
|
||||
|
||||
// Persistent => 0 == infinite timeout
|
||||
// CloseOnTimeout => -1 == let the server decide
|
||||
int timeout = persistent ? 0 : -1;
|
||||
|
||||
args.append(timeout); // expire timeout
|
||||
|
||||
dbusNotificationMessage.setArguments(args);
|
||||
|
||||
QDBusMessage reply = QDBusConnection::sessionBus().call(dbusNotificationMessage, QDBus::Block, 4000);
|
||||
if (reply.type() == QDBusMessage::ErrorMessage) {
|
||||
qDebug() << "Error sending notification:" << reply.errorMessage();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
notificationDBusCall(QStringLiteral("amarok"),
|
||||
QStringLiteral("Testing notification #1"),
|
||||
QStringLiteral("Lorem ipsum dolor sit amet, consectetur adipiscing elit. In condimentum"),
|
||||
QStringList() << QStringLiteral("action1") << QStringLiteral("action2"));
|
||||
|
||||
// wait a little before sending another notification
|
||||
QEventLoop a;
|
||||
QTimer::singleShot(500, &a, &QEventLoop::quit);
|
||||
a.exec();
|
||||
|
||||
notificationDBusCall(QStringLiteral("kwalletmanager"),
|
||||
QStringLiteral("Testing notification #2"),
|
||||
QStringLiteral("Praesent odio ipsum, posuere a magna ac, egestas vehicula lectus"),
|
||||
QStringList() << QStringLiteral("action1") << QStringLiteral("action2"));
|
||||
|
||||
QTimer::singleShot(1000, &a, &QEventLoop::quit);
|
||||
a.exec();
|
||||
|
||||
notificationDBusCall(QStringLiteral("preferences-desktop-accessibility"),
|
||||
QStringLiteral("Testing notification #3"),
|
||||
QStringLiteral("Fusce hendrerit egestas pellentesque"),
|
||||
QStringList(),
|
||||
true);
|
||||
|
||||
QTimer::singleShot(2000, &app, SLOT(quit()));
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QTimer>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
|
||||
// for simplicity we'll just send along progress-visible true whenever progress is set and otherwise false
|
||||
QCommandLineOption progressOption(QStringLiteral("progress"), QStringLiteral("Show progress, 0-100"), QStringLiteral("progress"));
|
||||
parser.addOption(progressOption);
|
||||
// same for count
|
||||
QCommandLineOption countOption(QStringLiteral("count"), QStringLiteral("Show count badge, number"), QStringLiteral("count"));
|
||||
parser.addOption(countOption);
|
||||
|
||||
QCommandLineOption urgentOption(QStringLiteral("urgent"), QStringLiteral("Set urgent hint, flash task bar entry"));
|
||||
parser.addOption(urgentOption);
|
||||
|
||||
parser.addPositionalArgument(QStringLiteral("desktop-filename"), QStringLiteral("Desktop file name for the application"));
|
||||
|
||||
parser.process(app);
|
||||
|
||||
if (parser.positionalArguments().count() != 1) {
|
||||
parser.showHelp(1); // never returns
|
||||
}
|
||||
|
||||
QString launcherId = parser.positionalArguments().constFirst();
|
||||
if (!launcherId.startsWith(QLatin1String("application://"))) {
|
||||
launcherId.prepend(QLatin1String("application://"));
|
||||
}
|
||||
if (!launcherId.endsWith(QLatin1String(".desktop"))) {
|
||||
launcherId.append(QLatin1String(".desktop"));
|
||||
}
|
||||
|
||||
QVariantMap properties;
|
||||
|
||||
if (parser.isSet(progressOption)) {
|
||||
properties.insert(QStringLiteral("progress"), parser.value(progressOption).toInt() / 100.0);
|
||||
properties.insert(QStringLiteral("progress-visible"), true);
|
||||
} else {
|
||||
properties.insert(QStringLiteral("progress-visible"), false);
|
||||
}
|
||||
|
||||
if (parser.isSet(countOption)) {
|
||||
properties.insert(QStringLiteral("count"), parser.value(countOption).toInt());
|
||||
properties.insert(QStringLiteral("count-visible"), true);
|
||||
} else {
|
||||
properties.insert(QStringLiteral("count-visible"), false);
|
||||
}
|
||||
|
||||
properties.insert(QStringLiteral("urgent"), parser.isSet(urgentOption));
|
||||
|
||||
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/org/knotifications/UnityLauncherTest"),
|
||||
QStringLiteral("com.canonical.Unity.LauncherEntry"),
|
||||
QStringLiteral("Update"));
|
||||
message.setArguments({launcherId, properties});
|
||||
QDBusConnection::sessionBus().send(message);
|
||||
|
||||
// FIXME can we detect that the message was sent to the bus?
|
||||
QTimer::singleShot(500, &app, QCoreApplication::quit);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user