[Notifications] Resolve X-Flatpak-RenamedFrom

When an application got renamed by flatpak-builder without knowing it, it will still send its original value as desktop-entry breaking the mapping and settings.

CHANGELOG: Improved notification identification for Flatpak applications

Differential Revision: https://phabricator.kde.org/D21779
wilder-5.19
Kai Uwe Broulik 7 years ago
parent 2f71aa8217
commit 9258ef5863
  1. 54
      libnotificationmanager/notification.cpp
  2. 4
      libnotificationmanager/notification_p.h

@ -37,6 +37,7 @@
#include <KConfigGroup>
#include <KIconLoader>
#include <KService>
#include <KServiceTypeTrader>
#include "debug.h"
@ -268,6 +269,36 @@ QSize Notification::Private::maximumImageSize()
return QSize(256, 256);
}
KService::Ptr Notification::Private::serviceForDesktopEntry(const QString &desktopEntry)
{
KService::Ptr service = KService::serviceByDesktopName(desktopEntry);
if (!service) {
const QString lowerDesktopEntry = desktopEntry.toLower();
service = KService::serviceByDesktopName(lowerDesktopEntry);
}
// Try if it's a renamed flatpak
if (!service) {
const QString desktopId = desktopEntry + QLatin1String(".desktop");
// HACK Querying for XDG lists in KServiceTypeTrader does not work, do it manually
const auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"),
QStringLiteral("exist Exec and exist [X-Flatpak-RenamedFrom]"));
for (auto it = services.constBegin(); it != services.constEnd() && !service; ++it) {
const QVariant renamedFrom = (*it)->property(QStringLiteral("X-Flatpak-RenamedFrom"), QVariant::String);
const auto names = renamedFrom.toString().split(QChar(';'));
for (const QString &name : names) {
if (name == desktopId) {
service = *it;
break;
}
}
}
}
return service;
}
void Notification::Private::processHints(const QVariantMap &hints)
{
auto end = hints.end();
@ -277,22 +308,13 @@ void Notification::Private::processHints(const QVariantMap &hints)
QString serviceName;
configurableService = false;
if (!desktopEntry.isEmpty()) {
KService::Ptr service = KService::serviceByDesktopName(desktopEntry);
// Also try lower-case desktopEntry (Firefox sends "Firefox" which doesn't match "firefox"...)
if (!service) {
const QString lowerDesktopEntry = desktopEntry.toLower();
service = KService::serviceByDesktopName(lowerDesktopEntry);
if (service) {
qCInfo(NOTIFICATIONMANAGER) << "Application sent desktop-entry" << desktopEntry << "but it actually was" << lowerDesktopEntry << ", this is an application bug!";
desktopEntry = lowerDesktopEntry;
}
}
if (service) {
serviceName = service->name();
applicationIconName = service->icon();
configurableService = !service->noDisplay();
}
KService::Ptr service = serviceForDesktopEntry(desktopEntry);
if (service) {
desktopEntry = service->desktopEntryName();
serviceName = service->name();
applicationIconName = service->icon();
configurableService = !service->noDisplay();
}
notifyRcName = hints.value(QStringLiteral("x-kde-appname")).toString();

@ -28,6 +28,8 @@
#include <QString>
#include <QUrl>
#include <KService>
#include "notifications.h"
namespace NotificationManager
@ -48,6 +50,8 @@ public:
static QString defaultComponentName();
static QSize maximumImageSize();
static KService::Ptr serviceForDesktopEntry(const QString &desktopEntry);
void processHints(const QVariantMap &hints);
void setUrgency(Notifications::Urgency urgency);

Loading…
Cancel
Save