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 QString desktopId = desktopEntry + QLatin1String(".desktop"); | ||||
284 | // HACK Querying for XDG lists in KServiceTypeTrader does not work, do it manually | ||||
285 | const auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), | ||||
286 | QStringLiteral("exist Exec and exist [X-Flatpak-RenamedFrom]")); | ||||
287 | for (auto it = services.constBegin(); it != services.constEnd() && !service; ++it) { | ||||
288 | const QVariant renamedFrom = (*it)->property(QStringLiteral("X-Flatpak-RenamedFrom"), QVariant::String); | ||||
289 | const auto names = renamedFrom.toString().split(QChar(';')); | ||||
290 | for (const QString &name : names) { | ||||
291 | if (name == desktopId) { | ||||
292 | service = *it; | ||||
293 | break; | ||||
294 | } | ||||
295 | } | ||||
296 | } | ||||
297 | } | ||||
298 | | ||||
299 | return service; | ||||
300 | } | ||||
301 | | ||||
271 | void Notification::Private::processHints(const QVariantMap &hints) | 302 | void Notification::Private::processHints(const QVariantMap &hints) | ||
272 | { | 303 | { | ||
273 | auto end = hints.end(); | 304 | auto end = hints.end(); | ||
274 | 305 | | |||
275 | desktopEntry = hints.value(QStringLiteral("desktop-entry")).toString(); | 306 | desktopEntry = hints.value(QStringLiteral("desktop-entry")).toString(); | ||
276 | 307 | | |||
277 | QString serviceName; | 308 | QString serviceName; | ||
278 | 309 | | |||
279 | configurableService = false; | 310 | configurableService = false; | ||
280 | if (!desktopEntry.isEmpty()) { | 311 | | ||
281 | KService::Ptr service = KService::serviceByDesktopName(desktopEntry); | 312 | 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) { | 313 | if (service) { | ||
314 | desktopEntry = service->desktopEntryName(); | ||||
292 | serviceName = service->name(); | 315 | serviceName = service->name(); | ||
293 | applicationIconName = service->icon(); | 316 | applicationIconName = service->icon(); | ||
294 | configurableService = !service->noDisplay(); | 317 | configurableService = !service->noDisplay(); | ||
295 | } | 318 | } | ||
296 | } | | |||
297 | 319 | | |||
298 | notifyRcName = hints.value(QStringLiteral("x-kde-appname")).toString(); | 320 | notifyRcName = hints.value(QStringLiteral("x-kde-appname")).toString(); | ||
299 | const bool isDefaultEvent = (notifyRcName == defaultComponentName()); | 321 | const bool isDefaultEvent = (notifyRcName == defaultComponentName()); | ||
300 | configurableNotifyRc = false; | 322 | configurableNotifyRc = false; | ||
301 | if (!notifyRcName.isEmpty()) { | 323 | if (!notifyRcName.isEmpty()) { | ||
302 | // Check whether the application actually has notifications we can configure | 324 | // Check whether the application actually has notifications we can configure | ||
303 | KConfig config(notifyRcName + QStringLiteral(".notifyrc"), KConfig::NoGlobals); | 325 | KConfig config(notifyRcName + QStringLiteral(".notifyrc"), KConfig::NoGlobals); | ||
304 | config.addConfigSources(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | 326 | config.addConfigSources(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | ||
▲ Show 20 Lines • Show All 350 Lines • Show Last 20 Lines |