Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/notification.cpp
Show All 31 Lines | |||||
32 | #include <QImageReader> | 32 | #include <QImageReader> | ||
33 | #include <QRegularExpression> | 33 | #include <QRegularExpression> | ||
34 | #include <QXmlStreamReader> | 34 | #include <QXmlStreamReader> | ||
35 | 35 | | |||
36 | #include <KConfig> | 36 | #include <KConfig> | ||
37 | #include <KConfigGroup> | 37 | #include <KConfigGroup> | ||
38 | #include <KIconLoader> | 38 | #include <KIconLoader> | ||
39 | #include <KService> | 39 | #include <KService> | ||
40 | #include <KServiceTypeTrader> | ||||
40 | 41 | | |||
41 | #include "debug.h" | 42 | #include "debug.h" | ||
42 | 43 | | |||
43 | #include "notifications.h" | 44 | #include "notifications.h" | ||
44 | 45 | | |||
45 | using namespace NotificationManager; | 46 | using namespace NotificationManager; | ||
46 | 47 | | |||
47 | Notification::Private::Private() | 48 | Notification::Private::Private() | ||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Line(s) | 262 | { | |||
263 | return QStringLiteral("plasma_workspace"); | 264 | return QStringLiteral("plasma_workspace"); | ||
264 | } | 265 | } | ||
265 | 266 | | |||
266 | QSize Notification::Private::maximumImageSize() | 267 | QSize Notification::Private::maximumImageSize() | ||
267 | { | 268 | { | ||
268 | return QSize(256, 256); | 269 | return QSize(256, 256); | ||
269 | } | 270 | } | ||
270 | 271 | | |||
272 | KService::Ptr Notification::Private::serviceForDesktopEntry(const QString &desktopEntry) | ||||
273 | { | ||||
274 | KService::Ptr service = KService::serviceByDesktopName(desktopEntry); | ||||
275 | | ||||
276 | if (!service) { | ||||
277 | const QString lowerDesktopEntry = desktopEntry.toLower(); | ||||
278 | service = KService::serviceByDesktopName(lowerDesktopEntry); | ||||
279 | } | ||||
280 | | ||||
281 | // Try if it's a renamed flatpak | ||||
282 | if (!service) { | ||||
283 | const auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), | ||||
284 | QStringLiteral("exist Exec and ('%1' in [X-Flatpak-RenamedFrom])") | ||||
285 | .arg(desktopEntry + QLatin1String(".desktop"))); | ||||
286 | if (!services.isEmpty()) { | ||||
287 | service = services.first(); | ||||
288 | } | ||||
289 | } | ||||
290 | | ||||
291 | return service; | ||||
292 | } | ||||
293 | | ||||
271 | void Notification::Private::processHints(const QVariantMap &hints) | 294 | void Notification::Private::processHints(const QVariantMap &hints) | ||
272 | { | 295 | { | ||
273 | auto end = hints.end(); | 296 | auto end = hints.end(); | ||
274 | 297 | | |||
275 | desktopEntry = hints.value(QStringLiteral("desktop-entry")).toString(); | 298 | desktopEntry = hints.value(QStringLiteral("desktop-entry")).toString(); | ||
276 | 299 | | |||
277 | QString serviceName; | 300 | QString serviceName; | ||
278 | 301 | | |||
279 | configurableService = false; | 302 | configurableService = false; | ||
280 | if (!desktopEntry.isEmpty()) { | 303 | | ||
281 | KService::Ptr service = KService::serviceByDesktopName(desktopEntry); | 304 | KService::Ptr service = serviceForDesktopEntry(desktopEntry); | ||
282 | // Also try lower-case desktopEntry (Firefox sends "Firefox" which doesn't match "firefox"...) | | |||
283 | if (!service) { | | |||
284 | const QString lowerDesktopEntry = desktopEntry.toLower(); | | |||
285 | service = KService::serviceByDesktopName(lowerDesktopEntry); | | |||
286 | if (service) { | | |||
287 | qCInfo(NOTIFICATIONMANAGER) << "Application sent desktop-entry" << desktopEntry << "but it actually was" << lowerDesktopEntry << ", this is an application bug!"; | | |||
288 | desktopEntry = lowerDesktopEntry; | | |||
289 | } | | |||
290 | } | | |||
291 | if (service) { | 305 | if (service) { | ||
306 | desktopEntry = service->desktopEntryName(); | ||||
292 | serviceName = service->name(); | 307 | serviceName = service->name(); | ||
293 | applicationIconName = service->icon(); | 308 | applicationIconName = service->icon(); | ||
294 | configurableService = !service->noDisplay(); | 309 | configurableService = !service->noDisplay(); | ||
295 | } | 310 | } | ||
296 | } | | |||
297 | 311 | | |||
298 | notifyRcName = hints.value(QStringLiteral("x-kde-appname")).toString(); | 312 | notifyRcName = hints.value(QStringLiteral("x-kde-appname")).toString(); | ||
299 | const bool isDefaultEvent = (notifyRcName == defaultComponentName()); | 313 | const bool isDefaultEvent = (notifyRcName == defaultComponentName()); | ||
300 | configurableNotifyRc = false; | 314 | configurableNotifyRc = false; | ||
301 | if (!notifyRcName.isEmpty()) { | 315 | if (!notifyRcName.isEmpty()) { | ||
302 | // Check whether the application actually has notifications we can configure | 316 | // Check whether the application actually has notifications we can configure | ||
303 | KConfig config(notifyRcName + QStringLiteral(".notifyrc"), KConfig::NoGlobals); | 317 | KConfig config(notifyRcName + QStringLiteral(".notifyrc"), KConfig::NoGlobals); | ||
304 | config.addConfigSources(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | 318 | config.addConfigSources(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | ||
▲ Show 20 Lines • Show All 350 Lines • Show Last 20 Lines |