Commit 623ca94a authored by David Kahles's avatar David Kahles
Browse files

Don't hardcode app name to filter notifications

The app name used by KNotification is translated, and thus the filtering
doesn't work if the translated app name is different.

REVIEW: 127768
parent 0c95010c
find_package(KF5 REQUIRED COMPONENTS Notifications KCMUtils I18n IconThemes)
find_package(KF5 REQUIRED COMPONENTS Notifications KCMUtils I18n IconThemes Config)
set(kdeconnect_notifications_SRCS
notification.cpp
......@@ -16,6 +16,7 @@ target_link_libraries(kdeconnect_notifications
KF5::Notifications
KF5::I18n
KF5::IconThemes
KF5::ConfigCore
)
#######################################
......
......@@ -22,6 +22,9 @@
#include <QtDBus/QDBusInterface>
#include <QtDebug>
#include <QLoggingCategory>
#include <QStandardPaths>
#include <KConfig>
#include <KConfigGroup>
#include <kiconloader.h>
#include <kicontheme.h>
......@@ -62,6 +65,7 @@ NotificationsListener::NotificationsListener(KdeConnectPlugin* aPlugin,
iface.call("AddMatch",
"interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'");
setTranslatedAppName();
loadApplications();
connect(mPlugin->config(), SIGNAL(configChanged()), this, SLOT(loadApplications()));
......@@ -77,6 +81,20 @@ NotificationsListener::~NotificationsListener()
QDBusConnection::sessionBus().unregisterObject("/org/freedesktop/Notifications");
}
void NotificationsListener::setTranslatedAppName()
{
QString filePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("knotifications5/kdeconnect.notifyrc"), QStandardPaths::LocateFile);
if (filePath.isEmpty()) {
qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Couldn't find kdeconnect.notifyrc to hide kdeconnect notifications on the devices. Using default name.";
mTranslatedAppName = QStringLiteral("KDE Connect");
return;
}
KConfig config(filePath, KConfig::OpenFlag::SimpleConfig);
KConfigGroup globalgroup(&config, QStringLiteral("Global"));
mTranslatedAppName = globalgroup.readEntry(QStringLiteral("Name"), QStringLiteral("KDE Connect"));
}
void NotificationsListener::loadApplications()
{
applications.clear();
......@@ -101,7 +119,7 @@ uint NotificationsListener::Notify(const QString &appName, uint replacesId,
//qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Got notification appName=" << appName << "replacesId=" << replacesId << "appIcon=" << appIcon << "summary=" << summary << "body=" << body << "actions=" << actions << "hints=" << hints << "timeout=" << timeout;
// skip our own notifications
if (appName == QLatin1String("KDE Connect"))
if (appName == mTranslatedAppName)
return 0;
NotifyingApplication app;
......
......@@ -49,4 +49,7 @@ public Q_SLOTS:
private Q_SLOTS:
void loadApplications();
private:
void setTranslatedAppName();
QString mTranslatedAppName;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment