Simplify determination of whether markup is supported

This should also result in a speed increase (however slight), since the capabilities are now sorted through only once.
This commit is contained in:
Loren Burkholder 2021-02-20 12:00:13 -05:00 committed by Nicolas Werner
parent 4150d75be7
commit 4a86e14d04
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9

View File

@ -9,6 +9,8 @@
#include <QImage> #include <QImage>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
#include <functional>
#include "Utils.h" #include "Utils.h"
NotificationsManager::NotificationsManager(QObject *parent) NotificationsManager::NotificationsManager(QObject *parent)
@ -161,14 +163,18 @@ NotificationsManager::notificationClosed(uint id, uint reason)
QString QString
NotificationsManager::formatNotification(const QString &text) NotificationsManager::formatNotification(const QString &text)
{ {
static auto capabilites = dbus.call("GetCapabilities").arguments(); static const auto hasMarkup = std::invoke([this]() -> bool {
for (auto x : capabilites) for (auto x : dbus.call("GetCapabilities").arguments())
if (x.toStringList().contains("body-markup")) if (x.toStringList().contains("body-markup"))
return QString(text) return true;
.replace("<em>", "<i>") return false;
.replace("</em>", "</i>") });
.replace("<strong>", "<b>") if (hasMarkup)
.replace("</strong>", "</b>"); return QString(text)
.replace("<em>", "<i>")
.replace("</em>", "</i>")
.replace("<strong>", "<b>")
.replace("</strong>", "</b>");
return QTextDocumentFragment::fromHtml(text).toPlainText(); return QTextDocumentFragment::fromHtml(text).toPlainText();
} }