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 <KSharedConfig> | 28 | #include <KSharedConfig> | ||
28 | #include <KNotifyConfigWidget> | 29 | #include <KNotifyConfigWidget> | ||
29 | #include <KUser> | 30 | #include <KUser> | ||
30 | #include <QGuiApplication> | 31 | #include <QGuiApplication> | ||
▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Line(s) | 274 | if (timeout <= 0) { | |||
276 | // Add two seconds for the user to notice the notification, and ensure | 277 | // Add two seconds for the user to notice the notification, and ensure | ||
277 | // it last at least five seconds, otherwise all the user see is a | 278 | // it last at least five seconds, otherwise all the user see is a | ||
278 | // flash | 279 | // flash | ||
279 | timeout = 2000 + qMax(timeout, 3000); | 280 | timeout = 2000 + qMax(timeout, 3000); | ||
280 | } | 281 | } | ||
281 | 282 | | |||
282 | const QString source = QStringLiteral("notification %1").arg(id); | 283 | const QString source = QStringLiteral("notification %1").arg(id); | ||
283 | 284 | | |||
284 | // First trim whitespace from beginning and end | 285 | 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() | |||||
285 | bodyFinal = bodyFinal.trimmed(); | | |||
286 | // Now replace all \ns with <br/> | | |||
287 | bodyFinal = bodyFinal.replace(QLatin1String("\n"), QLatin1String("<br/>")); | | |||
288 | // Now remove all inner whitespace (\ns are already <br/>s | | |||
289 | bodyFinal = bodyFinal.simplified(); | | |||
290 | // Finally, check if we don't have multiple <br/>s following, | | |||
291 | // can happen for example when "\n \n" is sent, this replaces | | |||
292 | // all <br/>s in succsession with just one | | |||
293 | bodyFinal.replace(QRegularExpression(QStringLiteral("<br/>\\s*<br/>(\\s|<br/>)*")), QLatin1String("<br/>")); | | |||
294 | // This fancy RegExp escapes every occurence of & since QtQuick Text will blatantly cut off | | |||
295 | // text where it finds a stray ampersand. | | |||
296 | // Only &{apos, quot, gt, lt, amp}; as well as { character references will be allowed | | |||
297 | bodyFinal.replace(QRegularExpression(QStringLiteral("&(?!(?:apos|quot|[gl]t|amp);|#)")), QLatin1String("&")); | | |||
298 | // The Text.StyledText format handles only html3.2 stuff and ' is html4 stuff | | |||
299 | // so we need to replace it here otherwise it will not render at all. | | |||
300 | bodyFinal.replace(QLatin1String("'"), QChar('\'')); | | |||
301 | 286 | | |||
302 | Plasma::DataEngine::Data notificationData; | 287 | Plasma::DataEngine::Data notificationData; | ||
303 | notificationData.insert(QStringLiteral("id"), QString::number(id)); | 288 | notificationData.insert(QStringLiteral("id"), QString::number(id)); | ||
304 | notificationData.insert(QStringLiteral("eventId"), eventId); | 289 | notificationData.insert(QStringLiteral("eventId"), eventId); | ||
305 | notificationData.insert(QStringLiteral("appName"), appname_str); | 290 | notificationData.insert(QStringLiteral("appName"), appname_str); | ||
306 | notificationData.insert(QStringLiteral("appIcon"), app_icon); | 291 | notificationData.insert(QStringLiteral("appIcon"), app_icon); | ||
307 | notificationData.insert(QStringLiteral("summary"), summaryFinal); | 292 | notificationData.insert(QStringLiteral("summary"), summaryFinal); | ||
308 | notificationData.insert(QStringLiteral("body"), bodyFinal); | 293 | notificationData.insert(QStringLiteral("body"), bodyFinal); | ||
▲ Show 20 Lines • Show All 184 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.