Changeset View
Changeset View
Standalone View
Standalone View
dataengines/notifications/notificationsengine.cpp
Show All 14 Lines | |||||
15 | * along with this library; see the file COPYING.LIB. If not, write to | 15 | * along with this library; see the file COPYING.LIB. If not, write to | ||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "notificationsengine.h" | 20 | #include "notificationsengine.h" | ||
21 | #include "notificationservice.h" | 21 | #include "notificationservice.h" | ||
22 | #include "notificationsadaptor.h" | 22 | #include "notificationsadaptor.h" | ||
23 | #include "notificationsanitizer.h" | ||||
23 | 24 | | |||
24 | #include <QDebug> | 25 | #include <QDebug> | ||
25 | #include <KConfigGroup> | 26 | #include <KConfigGroup> | ||
26 | #include <klocalizedstring.h> | 27 | #include <klocalizedstring.h> | ||
27 | #include <KNotifyConfigWidget> | 28 | #include <KNotifyConfigWidget> | ||
28 | #include <QGuiApplication> | 29 | #include <QGuiApplication> | ||
29 | 30 | | |||
30 | #include <QRegularExpression> | 31 | #include <QRegularExpression> | ||
▲ Show 20 Lines • Show All 225 Lines • ▼ Show 20 Line(s) | 253 | if (timeout <= 0) { | |||
256 | // it last at least five seconds, otherwise all the user see is a | 257 | // it last at least five seconds, otherwise all the user see is a | ||
257 | // flash | 258 | // flash | ||
258 | timeout = 2000 + qMax(timeout, 3000); | 259 | timeout = 2000 + qMax(timeout, 3000); | ||
259 | } | 260 | } | ||
260 | 261 | | |||
261 | const QString source = QStringLiteral("notification %1").arg(id); | 262 | const QString source = QStringLiteral("notification %1").arg(id); | ||
262 | 263 | | |||
263 | QString bodyFinal = (partOf == 0 ? body : _body); | 264 | QString bodyFinal = (partOf == 0 ? body : _body); | ||
264 | // First trim whitespace from beginning and end | 265 | bodyFinal = NotificationSanitizer::parse(bodyFinal); | ||
broulik: Won't you end up with piles of `<html>` tags since `_body` is the body text of the notification… | |||||
Oh, I didn't think about that code. You're right. I'll add a .mid() davidedmundson: Oh, I didn't think about that code. You're right.
I'll add a .mid() | |||||
265 | bodyFinal = bodyFinal.trimmed(); | | |||
266 | // Now replace all \ns with <br/> | | |||
267 | bodyFinal = bodyFinal.replace(QLatin1String("\n"), QLatin1String("<br/>")); | | |||
268 | // Now remove all inner whitespace (\ns are already <br/>s | | |||
269 | bodyFinal = bodyFinal.simplified(); | | |||
270 | // Finally, check if we don't have multiple <br/>s following, | | |||
271 | // can happen for example when "\n \n" is sent, this replaces | | |||
272 | // all <br/>s in succsession with just one | | |||
273 | bodyFinal.replace(QRegularExpression(QStringLiteral("<br/>\\s*<br/>(\\s|<br/>)*")), QLatin1String("<br/>")); | | |||
274 | // This fancy RegExp escapes every occurence of & since QtQuick Text will blatantly cut off | | |||
275 | // text where it finds a stray ampersand. | | |||
276 | // Only &{apos, quot, gt, lt, amp}; as well as { character references will be allowed | | |||
277 | bodyFinal.replace(QRegularExpression(QStringLiteral("&(?!(?:apos|quot|[gl]t|amp);|#)")), QLatin1String("&")); | | |||
278 | // The Text.StyledText format handles only html3.2 stuff and ' is html4 stuff | | |||
279 | // so we need to replace it here otherwise it will not render at all. | | |||
280 | bodyFinal.replace(QLatin1String("'"), QChar('\'')); | | |||
281 | 266 | | |||
282 | Plasma::DataEngine::Data notificationData; | 267 | Plasma::DataEngine::Data notificationData; | ||
283 | notificationData.insert(QStringLiteral("id"), QString::number(id)); | 268 | notificationData.insert(QStringLiteral("id"), QString::number(id)); | ||
284 | notificationData.insert(QStringLiteral("eventId"), eventId); | 269 | notificationData.insert(QStringLiteral("eventId"), eventId); | ||
285 | notificationData.insert(QStringLiteral("appName"), appname_str); | 270 | notificationData.insert(QStringLiteral("appName"), appname_str); | ||
286 | notificationData.insert(QStringLiteral("appIcon"), app_icon); | 271 | notificationData.insert(QStringLiteral("appIcon"), app_icon); | ||
287 | notificationData.insert(QStringLiteral("summary"), summary); | 272 | notificationData.insert(QStringLiteral("summary"), summary); | ||
288 | notificationData.insert(QStringLiteral("body"), bodyFinal); | 273 | notificationData.insert(QStringLiteral("body"), bodyFinal); | ||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |
Won't you end up with piles of <html> tags since _body is the body text of the notification it would group to.
Not that it really matters, though.