Escape HTML in notifications when server supports HTML
This commit is contained in:
@@ -27,6 +27,7 @@ class NotificationsManager : public QObject {
|
|||||||
private:
|
private:
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
||||||
QDBusInterface dbus;
|
QDBusInterface dbus;
|
||||||
|
bool serverSupportsHtml = false;
|
||||||
uint showNotification(const QString summary,
|
uint showNotification(const QString summary,
|
||||||
const QString text,
|
const QString text,
|
||||||
const QImage image);
|
const QImage image);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <QtDBus/QDBusConnection>
|
#include <QtDBus/QDBusConnection>
|
||||||
#include <QtDBus/QDBusMessage>
|
#include <QtDBus/QDBusMessage>
|
||||||
#include <QtDBus/QDBusMetaType>
|
#include <QtDBus/QDBusMetaType>
|
||||||
|
#include <QtDBus/QDBusReply>
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject *parent)
|
NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
@@ -13,6 +14,15 @@ NotificationsManager::NotificationsManager(QObject *parent)
|
|||||||
this) {
|
this) {
|
||||||
qDBusRegisterMetaType<QImage>();
|
qDBusRegisterMetaType<QImage>();
|
||||||
|
|
||||||
|
const QDBusReply<QStringList> capabilitiesReply = dbus.call("GetCapabilities");
|
||||||
|
|
||||||
|
if (capabilitiesReply.isValid()) {
|
||||||
|
const QStringList capabilities = capabilitiesReply.value();
|
||||||
|
serverSupportsHtml = capabilities.contains("body-markup");
|
||||||
|
} else {
|
||||||
|
qWarning() << "Could not get notification server capabilities" << capabilitiesReply.error();
|
||||||
|
}
|
||||||
|
|
||||||
QDBusConnection::sessionBus().connect(
|
QDBusConnection::sessionBus().connect(
|
||||||
"org.freedesktop.Notifications", "/org/freedesktop/Notifications",
|
"org.freedesktop.Notifications", "/org/freedesktop/Notifications",
|
||||||
"org.freedesktop.Notifications", "ActionInvoked", this,
|
"org.freedesktop.Notifications", "ActionInvoked", this,
|
||||||
@@ -54,6 +64,8 @@ uint NotificationsManager::showNotification(const QString summary,
|
|||||||
croppedImage = image;
|
croppedImage = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString body = serverSupportsHtml ? text.toHtmlEscaped() : text;
|
||||||
|
|
||||||
QVariantMap hints;
|
QVariantMap hints;
|
||||||
hints["image-data"] = croppedImage;
|
hints["image-data"] = croppedImage;
|
||||||
QList<QVariant> argumentList;
|
QList<QVariant> argumentList;
|
||||||
@@ -61,7 +73,7 @@ uint NotificationsManager::showNotification(const QString summary,
|
|||||||
argumentList << uint(0); // replace_id
|
argumentList << uint(0); // replace_id
|
||||||
argumentList << ""; // app_icon
|
argumentList << ""; // app_icon
|
||||||
argumentList << summary; // summary
|
argumentList << summary; // summary
|
||||||
argumentList << text; // body
|
argumentList << body; // body
|
||||||
argumentList << (QStringList("default") << "reply"); // actions
|
argumentList << (QStringList("default") << "reply"); // actions
|
||||||
argumentList << hints; // hints
|
argumentList << hints; // hints
|
||||||
argumentList << int(-1); // timeout in ms
|
argumentList << int(-1); // timeout in ms
|
||||||
|
|||||||
Reference in New Issue
Block a user