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