2015-09-10 15:36:03 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2015 Holger Kaelberer <holger.k@elberer.de>
|
2015-09-10 15:36:03 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2015-09-10 15:36:03 +01:00
|
|
|
*/
|
2019-02-03 00:44:22 +00:00
|
|
|
#include "notificationslistener.h"
|
2015-09-10 15:36:03 +01:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2016-04-27 18:45:58 +01:00
|
|
|
#include <KConfig>
|
|
|
|
#include <KConfigGroup>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QDBusArgument>
|
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QImage>
|
2023-03-13 02:20:12 +00:00
|
|
|
#include <QScopeGuard>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QtDebug>
|
2023-03-13 02:20:12 +00:00
|
|
|
|
2016-01-07 16:37:35 +00:00
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <kicontheme.h>
|
|
|
|
|
2015-09-10 15:36:03 +01:00
|
|
|
#include <core/device.h>
|
|
|
|
#include <core/kdeconnectplugin.h>
|
|
|
|
|
2019-06-09 16:28:49 +01:00
|
|
|
#include <dbushelper.h>
|
|
|
|
|
2015-12-05 22:11:57 +00:00
|
|
|
#include "notifyingapplication.h"
|
2022-09-10 22:23:52 +01:00
|
|
|
#include "plugin_sendnotification_debug.h"
|
|
|
|
#include "sendnotificationsplugin.h"
|
2015-09-10 15:36:03 +01:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
// In older Qt released, qAsConst isnt available
|
Build kdeconnect on sailfish and port some simple plugins
Summary:
Below is a lost of the commits, but, in summary
Port the build system for Sailfish, which means selectively building only the bits we need/can, and only against the KF5 libs that are available.
Allow to build on Qt 5.6
Switch from knotification to nemo notification (not complete!)
Add a very simple example sailfish app.
Note, there is still much missing functionality. Notifications dont work, pairing sort of works but not really, but when it is paired you can send a ping to the desktop client
Dont build kio for Sailfish
Port core build system
Port daemon buld system
Require CoreAddons on Sailfish
Port plugins build for sailfish and include the ping plugin for now
Final build changes for sailfish.
Disable tests and other not needed parts
Add includes for QCA
Fix build errors on sailfish
Get core/ to build on sailfish
Get interfaces/ to build on sailfish
Build daemon on sailfish
On sailfish, dont install the kcm file
Start port plugin to sailfish
Fixup installed files
Add sfos app
Hack declarative plugin to give a public interface
Build sfos app
Compile declarativeplugin into the sfos app for now
Redefine qAsConst for qt 5.6
Packaging fixes
Use official icon
Package .desktop
Reviewers: #kde_connect, apol, nicolasfella, albertvaka
Reviewed By: #kde_connect, apol, nicolasfella, albertvaka
Subscribers: kdeconnect, andyholmes, albertvaka, kossebau, mtijink, vonreth, apol, #kde_connect, nicolasfella
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D10703
2018-08-02 20:10:59 +01:00
|
|
|
#include "qtcompat_p.h"
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
NotificationsListener::NotificationsListener(KdeConnectPlugin *aPlugin)
|
2023-03-13 02:20:12 +00:00
|
|
|
: QObject(aPlugin)
|
2022-09-10 22:23:52 +01:00
|
|
|
, m_plugin(aPlugin)
|
2015-09-10 15:36:03 +01:00
|
|
|
{
|
2015-12-05 22:11:57 +00:00
|
|
|
qRegisterMetaTypeStreamOperators<NotifyingApplication>("NotifyingApplication");
|
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
GError *error = nullptr;
|
|
|
|
m_gdbusConnection = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error);
|
|
|
|
g_assert_no_error(error);
|
|
|
|
m_gdbusFilterId = g_dbus_connection_add_filter(m_gdbusConnection, NotificationsListener::onMessageFiltered, this, nullptr);
|
|
|
|
|
|
|
|
g_autoptr(GDBusMessage) msg =
|
|
|
|
g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus.Monitoring", "BecomeMonitor");
|
|
|
|
|
|
|
|
GVariantBuilder *arrayBuilder = g_variant_builder_new(G_VARIANT_TYPE("as"));
|
|
|
|
g_variant_builder_add(arrayBuilder, "s", "interface='org.freedesktop.Notifications'");
|
|
|
|
g_variant_builder_add(arrayBuilder, "s", "member='Notify'");
|
2015-09-10 15:36:03 +01:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
g_dbus_message_set_body(msg, g_variant_new("(asu)", arrayBuilder, 0u));
|
|
|
|
g_dbus_connection_send_message(m_gdbusConnection, msg, GDBusSendMessageFlags::G_DBUS_SEND_MESSAGE_FLAGS_NONE, nullptr, &error);
|
|
|
|
g_assert_no_error(error);
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2016-04-27 18:45:58 +01:00
|
|
|
setTranslatedAppName();
|
2015-12-05 22:11:57 +00:00
|
|
|
loadApplications();
|
|
|
|
|
2017-09-03 20:39:44 +01:00
|
|
|
connect(m_plugin->config(), &KdeConnectPluginConfig::configChanged, this, &NotificationsListener::loadApplications);
|
2015-09-10 15:36:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
NotificationsListener::~NotificationsListener()
|
|
|
|
{
|
2016-05-25 19:49:13 +01:00
|
|
|
qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Destroying NotificationsListener";
|
2023-03-13 02:20:12 +00:00
|
|
|
g_dbus_connection_remove_filter(m_gdbusConnection, m_gdbusFilterId);
|
|
|
|
g_object_unref(m_gdbusConnection);
|
2015-09-10 15:36:03 +01:00
|
|
|
}
|
|
|
|
|
2016-04-27 18:45:58 +01:00
|
|
|
void NotificationsListener::setTranslatedAppName()
|
|
|
|
{
|
2022-09-10 22:23:52 +01:00
|
|
|
QString filePath =
|
|
|
|
QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("knotifications5/kdeconnect.notifyrc"), QStandardPaths::LocateFile);
|
2016-04-27 18:45:58 +01:00
|
|
|
if (filePath.isEmpty()) {
|
2016-05-31 16:48:55 +01:00
|
|
|
qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Couldn't find kdeconnect.notifyrc to hide kdeconnect notifications on the devices. Using default name.";
|
2017-09-03 20:39:44 +01:00
|
|
|
m_translatedAppName = QStringLiteral("KDE Connect");
|
2016-04-27 18:45:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfig config(filePath, KConfig::OpenFlag::SimpleConfig);
|
|
|
|
KConfigGroup globalgroup(&config, QStringLiteral("Global"));
|
2017-09-03 20:39:44 +01:00
|
|
|
m_translatedAppName = globalgroup.readEntry(QStringLiteral("Name"), QStringLiteral("KDE Connect"));
|
2016-04-27 18:45:58 +01:00
|
|
|
}
|
|
|
|
|
2015-12-05 22:11:57 +00:00
|
|
|
void NotificationsListener::loadApplications()
|
|
|
|
{
|
2017-09-03 20:39:44 +01:00
|
|
|
m_applications.clear();
|
|
|
|
const QVariantList list = m_plugin->config()->getList(QStringLiteral("applications"));
|
2022-09-10 22:23:52 +01:00
|
|
|
for (const auto &a : list) {
|
2015-12-05 22:11:57 +00:00
|
|
|
NotifyingApplication app = a.value<NotifyingApplication>();
|
2019-07-04 23:13:55 +01:00
|
|
|
if (!m_applications.contains(app.name)) {
|
2017-09-03 20:39:44 +01:00
|
|
|
m_applications.insert(app.name, app);
|
2019-07-04 23:13:55 +01:00
|
|
|
}
|
2015-12-05 22:11:57 +00:00
|
|
|
}
|
2022-09-10 22:23:52 +01:00
|
|
|
// qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Loaded" << applications.size() << " applications";
|
2015-12-05 22:11:57 +00:00
|
|
|
}
|
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
bool NotificationsListener::parseImageDataArgument(GVariant *argument,
|
2022-09-10 22:23:52 +01:00
|
|
|
int &width,
|
|
|
|
int &height,
|
|
|
|
int &rowStride,
|
|
|
|
int &bitsPerSample,
|
|
|
|
int &channels,
|
|
|
|
bool &hasAlpha,
|
|
|
|
QByteArray &imageData) const
|
2016-08-27 12:59:25 +01:00
|
|
|
{
|
2023-03-13 02:20:12 +00:00
|
|
|
if (g_variant_n_children(argument) != 7) {
|
2016-08-27 12:59:25 +01:00
|
|
|
return false;
|
2023-03-13 02:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_autoptr(GVariant) variant;
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(argument, 0);
|
|
|
|
if (g_variant_is_of_type(variant, G_VARIANT_TYPE_INT32)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
width = g_variant_get_int32(variant);
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(argument, 1);
|
|
|
|
if (g_variant_is_of_type(variant, G_VARIANT_TYPE_INT32)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
height = g_variant_get_int32(variant);
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(argument, 2);
|
|
|
|
if (g_variant_is_of_type(variant, G_VARIANT_TYPE_INT32)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rowStride = g_variant_get_int32(variant);
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(argument, 3);
|
|
|
|
if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
hasAlpha = g_variant_get_boolean(variant);
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(argument, 4);
|
|
|
|
if (g_variant_is_of_type(variant, G_VARIANT_TYPE_INT32)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bitsPerSample = g_variant_get_int32(variant);
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(argument, 5);
|
|
|
|
if (g_variant_is_of_type(variant, G_VARIANT_TYPE_INT32)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
channels = g_variant_get_int32(variant);
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(argument, 6);
|
|
|
|
if (g_variant_is_of_type(variant, G_VARIANT_TYPE_ARRAY)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
imageData = g_variant_get_bytestring(variant);
|
|
|
|
|
2016-08-27 12:59:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
QSharedPointer<QIODevice> NotificationsListener::iconForImageData(GVariant *argument) const
|
2016-08-27 12:59:25 +01:00
|
|
|
{
|
|
|
|
int width, height, rowStride, bitsPerSample, channels;
|
|
|
|
bool hasAlpha;
|
|
|
|
QByteArray imageData;
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
if (!parseImageDataArgument(argument, width, height, rowStride, bitsPerSample, channels, hasAlpha, imageData))
|
2016-08-27 12:59:25 +01:00
|
|
|
return QSharedPointer<QIODevice>();
|
|
|
|
|
|
|
|
if (bitsPerSample != 8) {
|
|
|
|
qCWarning(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Unsupported image format:"
|
2022-09-10 22:23:52 +01:00
|
|
|
<< "width=" << width << "height=" << height << "rowStride=" << rowStride
|
|
|
|
<< "bitsPerSample=" << bitsPerSample << "channels=" << channels << "hasAlpha=" << hasAlpha;
|
2016-08-27 12:59:25 +01:00
|
|
|
return QSharedPointer<QIODevice>();
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QImage image(reinterpret_cast<uchar *>(imageData.data()), width, height, rowStride, hasAlpha ? QImage::Format_ARGB32 : QImage::Format_RGB32);
|
2016-08-27 12:59:25 +01:00
|
|
|
if (hasAlpha)
|
2022-09-10 22:23:52 +01:00
|
|
|
image = image.rgbSwapped(); // RGBA --> ARGB
|
2016-08-27 12:59:25 +01:00
|
|
|
|
|
|
|
QSharedPointer<QBuffer> buffer = QSharedPointer<QBuffer>(new QBuffer);
|
2022-09-10 22:23:52 +01:00
|
|
|
if (!buffer || !buffer->open(QIODevice::WriteOnly) || !image.save(buffer.data(), "PNG")) {
|
2016-08-27 12:59:25 +01:00
|
|
|
qCWarning(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Could not initialize image buffer";
|
|
|
|
return QSharedPointer<QIODevice>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
QSharedPointer<QIODevice> NotificationsListener::iconForIconName(const QString &iconName)
|
2016-08-27 12:59:25 +01:00
|
|
|
{
|
2022-09-10 22:23:52 +01:00
|
|
|
int size = KIconLoader::SizeEnormous; // use big size to allow for good
|
|
|
|
// quality on high-DPI mobile devices
|
2016-08-27 12:59:25 +01:00
|
|
|
QString iconPath = KIconLoader::global()->iconPath(iconName, -size, true);
|
|
|
|
if (!iconPath.isEmpty()) {
|
2022-09-10 22:23:52 +01:00
|
|
|
if (!iconPath.endsWith(QLatin1String(".png")) && KIconLoader::global()->theme()->name() != QLatin1String("hicolor")) {
|
2016-08-27 12:59:25 +01:00
|
|
|
// try falling back to hicolor theme:
|
|
|
|
KIconTheme hicolor(QStringLiteral("hicolor"));
|
|
|
|
if (hicolor.isValid()) {
|
2019-06-10 15:40:28 +01:00
|
|
|
iconPath = hicolor.iconPath(iconName + QStringLiteral(".png"), size, KIconLoader::MatchBest);
|
2022-09-10 22:23:52 +01:00
|
|
|
// qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Found non-png icon in default theme trying fallback to hicolor:" << iconPath;
|
2016-08-27 12:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iconPath.endsWith(QLatin1String(".png")))
|
|
|
|
return QSharedPointer<QIODevice>(new QFile(iconPath));
|
|
|
|
return QSharedPointer<QIODevice>();
|
|
|
|
}
|
Build kdeconnect on sailfish and port some simple plugins
Summary:
Below is a lost of the commits, but, in summary
Port the build system for Sailfish, which means selectively building only the bits we need/can, and only against the KF5 libs that are available.
Allow to build on Qt 5.6
Switch from knotification to nemo notification (not complete!)
Add a very simple example sailfish app.
Note, there is still much missing functionality. Notifications dont work, pairing sort of works but not really, but when it is paired you can send a ping to the desktop client
Dont build kio for Sailfish
Port core build system
Port daemon buld system
Require CoreAddons on Sailfish
Port plugins build for sailfish and include the ping plugin for now
Final build changes for sailfish.
Disable tests and other not needed parts
Add includes for QCA
Fix build errors on sailfish
Get core/ to build on sailfish
Get interfaces/ to build on sailfish
Build daemon on sailfish
On sailfish, dont install the kcm file
Start port plugin to sailfish
Fixup installed files
Add sfos app
Hack declarative plugin to give a public interface
Build sfos app
Compile declarativeplugin into the sfos app for now
Redefine qAsConst for qt 5.6
Packaging fixes
Use official icon
Package .desktop
Reviewers: #kde_connect, apol, nicolasfella, albertvaka
Reviewed By: #kde_connect, apol, nicolasfella, albertvaka
Subscribers: kdeconnect, andyholmes, albertvaka, kossebau, mtijink, vonreth, apol, #kde_connect, nicolasfella
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D10703
2018-08-02 20:10:59 +01:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
GDBusMessage *NotificationsListener::onMessageFiltered(GDBusConnection *, GDBusMessage *msg, int, void *parent)
|
2015-09-10 15:36:03 +01:00
|
|
|
{
|
2023-03-13 02:20:12 +00:00
|
|
|
static unsigned id = 0;
|
|
|
|
if (!msg) {
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *interface = g_dbus_message_get_interface(msg);
|
|
|
|
if (!interface || strcmp(interface, "org.freedesktop.Notifications")) {
|
|
|
|
// The first message will be from org.freedesktop.DBus.Monitoring
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
const gchar *member = g_dbus_message_get_member(msg);
|
|
|
|
if (!member || strcmp(member, "Notify")) {
|
|
|
|
// Even if member is set, the monitor will still notify messages from other members.
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
g_autoptr(GVariant) bodyVariant = g_dbus_message_get_body(msg);
|
|
|
|
Q_ASSERT(bodyVariant);
|
2015-09-10 15:36:03 +01:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
// Data order and types: https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html
|
|
|
|
g_autoptr(GVariant) variant = g_variant_get_child_value(bodyVariant, 0);
|
|
|
|
const QString appName = QString::fromUtf8(g_variant_get_string(variant, nullptr));
|
2015-09-10 15:36:03 +01:00
|
|
|
// skip our own notifications
|
2023-03-13 02:20:12 +00:00
|
|
|
auto listener = static_cast<NotificationsListener *>(parent);
|
|
|
|
|
|
|
|
if (appName == listener->m_translatedAppName) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(bodyVariant, 2);
|
|
|
|
const QString appIcon = QString::fromUtf8(g_variant_get_string(variant, nullptr));
|
2015-09-10 15:36:03 +01:00
|
|
|
|
2015-12-05 22:11:57 +00:00
|
|
|
NotifyingApplication app;
|
2023-03-13 02:20:12 +00:00
|
|
|
if (!listener->m_applications.contains(appName)) {
|
2015-12-05 22:11:57 +00:00
|
|
|
// new application -> add to config
|
|
|
|
app.name = appName;
|
|
|
|
app.icon = appIcon;
|
|
|
|
app.active = true;
|
|
|
|
app.blacklistExpression = QRegularExpression();
|
2023-03-13 02:20:12 +00:00
|
|
|
listener->m_applications.insert(app.name, app);
|
2015-12-05 22:11:57 +00:00
|
|
|
// update config:
|
|
|
|
QVariantList list;
|
2023-03-13 02:20:12 +00:00
|
|
|
for (const auto &a : std::as_const(listener->m_applications))
|
2015-12-05 22:11:57 +00:00
|
|
|
list << QVariant::fromValue<NotifyingApplication>(a);
|
2023-03-13 02:20:12 +00:00
|
|
|
listener->m_plugin->config()->setList(QStringLiteral("applications"), list);
|
2022-09-10 22:23:52 +01:00
|
|
|
// qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Added new application to config:" << app;
|
2019-07-04 23:13:55 +01:00
|
|
|
} else {
|
2023-03-13 02:20:12 +00:00
|
|
|
app = listener->m_applications.value(appName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!app.active) {
|
|
|
|
return nullptr;
|
2019-07-04 23:13:55 +01:00
|
|
|
}
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
variant = g_variant_get_child_value(bodyVariant, 7);
|
|
|
|
const auto timeout = g_variant_get_int32(variant);
|
|
|
|
if (timeout > 0 && listener->m_plugin->config()->getBool(QStringLiteral("generalPersistent"), false)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(bodyVariant, 6);
|
|
|
|
std::unordered_map<QString, GVariant *> hints;
|
|
|
|
GVariantIter *iter;
|
|
|
|
const gchar *key;
|
|
|
|
GVariant *value = nullptr;
|
|
|
|
g_variant_get(variant, "a{sv}", &iter);
|
|
|
|
while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
|
|
|
|
hints.emplace(QString::fromUtf8(key), value);
|
|
|
|
}
|
|
|
|
g_variant_iter_free(iter);
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
QScopeGuard cleanupHints([&hints] {
|
|
|
|
for (auto &[_, hint] : hints) {
|
|
|
|
g_variant_unref(hint);
|
|
|
|
}
|
|
|
|
});
|
2015-12-05 22:11:57 +00:00
|
|
|
|
|
|
|
int urgency = -1;
|
2023-03-13 02:20:12 +00:00
|
|
|
if (auto it = hints.find(QStringLiteral("urgency")); it != hints.end()) {
|
|
|
|
if (g_variant_is_of_type(it->second, G_VARIANT_TYPE_BYTE)) {
|
|
|
|
urgency = g_variant_get_byte(it->second);
|
|
|
|
}
|
2015-12-07 02:21:35 +00:00
|
|
|
}
|
2023-03-13 02:20:12 +00:00
|
|
|
if (urgency > -1 && urgency < listener->m_plugin->config()->getInt(QStringLiteral("generalUrgency"), 0))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
variant = g_variant_get_child_value(bodyVariant, 3);
|
|
|
|
QString ticker = QString::fromUtf8(g_variant_get_string(variant, nullptr));
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
variant = g_variant_get_child_value(bodyVariant, 4);
|
|
|
|
const QString body = QString::fromUtf8(g_variant_get_string(variant, nullptr));
|
|
|
|
|
|
|
|
if (!body.isEmpty() && listener->m_plugin->config()->getBool(QStringLiteral("generalIncludeBody"), true)) {
|
2016-11-26 14:38:08 +00:00
|
|
|
ticker += QStringLiteral(": ") + body;
|
2023-03-13 02:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (app.blacklistExpression.isValid() && !app.blacklistExpression.pattern().isEmpty() && app.blacklistExpression.match(ticker).hasMatch()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
variant = g_variant_get_child_value(bodyVariant, 1);
|
|
|
|
const unsigned replacesId = g_variant_get_uint32(variant);
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
// qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Sending notification from" << appName << ":" <<ticker << "; appIcon=" << appIcon;
|
|
|
|
NetworkPacket np(PACKET_TYPE_NOTIFICATION,
|
|
|
|
{{QStringLiteral("id"), QString::number(replacesId > 0 ? replacesId : ++id)},
|
|
|
|
{QStringLiteral("appName"), appName},
|
|
|
|
{QStringLiteral("ticker"), ticker},
|
|
|
|
{QStringLiteral("isClearable"), timeout == 0}}); // KNotifications are persistent if
|
|
|
|
// timeout == 0, for other notifications
|
|
|
|
// clearability is pointless
|
2015-09-10 15:36:03 +01:00
|
|
|
|
2016-08-27 12:59:25 +01:00
|
|
|
// sync any icon data?
|
2023-03-13 02:20:12 +00:00
|
|
|
if (listener->m_plugin->config()->getBool(QStringLiteral("generalSynchronizeIcons"), true)) {
|
2016-08-27 12:59:25 +01:00
|
|
|
QSharedPointer<QIODevice> iconSource;
|
|
|
|
// try different image sources according to priorities in notifications-
|
|
|
|
// spec version 1.2:
|
2023-03-13 02:20:12 +00:00
|
|
|
if (auto it = hints.find(QStringLiteral("image-data")); it != hints.end()) {
|
|
|
|
iconSource = listener->iconForImageData(it->second);
|
|
|
|
} else if (auto it = hints.find(QStringLiteral("image_data")); it != hints.end()) { // 1.1 backward compatibility
|
|
|
|
iconSource = listener->iconForImageData(it->second);
|
|
|
|
} else if (auto it = hints.find(QStringLiteral("image-path")); it != hints.end()) {
|
|
|
|
iconSource = iconForIconName(QString::fromUtf8(g_variant_get_string(it->second, nullptr)));
|
|
|
|
} else if (auto it = hints.find(QStringLiteral("image_path")); it != hints.end()) { // 1.1 backward compatibility
|
|
|
|
iconSource = iconForIconName(QString::fromUtf8(g_variant_get_string(it->second, nullptr)));
|
|
|
|
} else if (!appIcon.isEmpty()) {
|
2016-08-27 12:59:25 +01:00
|
|
|
iconSource = iconForIconName(appIcon);
|
2023-03-13 02:20:12 +00:00
|
|
|
} else if (auto it = hints.find(QStringLiteral("icon_data")); it != hints.end()) { // < 1.1 backward compatibility
|
|
|
|
iconSource = listener->iconForImageData(it->second);
|
|
|
|
}
|
2016-08-27 12:59:25 +01:00
|
|
|
|
|
|
|
if (iconSource)
|
|
|
|
np.setPayload(iconSource, iconSource->size());
|
2016-01-07 16:37:35 +00:00
|
|
|
}
|
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
listener->m_plugin->sendPacket(np);
|
|
|
|
|
|
|
|
qCDebug(KDECONNECT_PLUGIN_SENDNOTIFICATION) << "Got notification appName=" << appName << "replacesId=" << replacesId << "appIcon=" << appIcon
|
|
|
|
<< "summary=" << ticker << "body=" << body << "hints=" << hints.size() << "urgency=" << urgency
|
|
|
|
<< "timeout=" << timeout;
|
2015-09-10 15:36:03 +01:00
|
|
|
|
2023-03-13 02:20:12 +00:00
|
|
|
return nullptr;
|
2015-09-10 15:36:03 +01:00
|
|
|
}
|