plasma: do not use global static for the notifications applet adaptors

because the adaptors are parented to the application instance for object
registration purpose the global static deleter double-deletes them

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-19 19:38:22 +03:00
parent f1eb5815cb
commit 3b86c8487a
4 changed files with 20 additions and 2 deletions

View file

@ -23,7 +23,7 @@
#include <QDBusConnection>
#include <KGlobal>
K_GLOBAL_STATIC_WITH_ARGS(JobTrackerAdaptor, kJobTrackerAdaptor, (qApp))
static JobTrackerAdaptor* kJobTrackerAdaptor = nullptr;
JobTrackerAdaptor::JobTrackerAdaptor(QObject *parent)
: QDBusAbstractAdaptor(parent),
@ -31,6 +31,11 @@ JobTrackerAdaptor::JobTrackerAdaptor(QObject *parent)
{
}
JobTrackerAdaptor::~JobTrackerAdaptor()
{
Q_ASSERT(m_ref == 0);
}
void JobTrackerAdaptor::addJob(const QString &name)
{
emit jobAdded(name);
@ -48,6 +53,9 @@ void JobTrackerAdaptor::stopJob(const QString &name)
JobTrackerAdaptor* JobTrackerAdaptor::self()
{
if (!kJobTrackerAdaptor) {
kJobTrackerAdaptor = new JobTrackerAdaptor(qApp);
}
return kJobTrackerAdaptor;
}

View file

@ -31,6 +31,7 @@ class JobTrackerAdaptor: public QDBusAbstractAdaptor
Q_CLASSINFO("D-Bus Interface", "org.kde.JobTracker")
public:
JobTrackerAdaptor(QObject *parent);
~JobTrackerAdaptor();
static JobTrackerAdaptor* self();
void registerObject();

View file

@ -23,7 +23,7 @@
#include <QDBusConnection>
#include <KGlobal>
K_GLOBAL_STATIC_WITH_ARGS(NotificationsAdaptor, kNotificationsAdaptor, (qApp))
static NotificationsAdaptor* kNotificationsAdaptor = nullptr;
NotificationsAdaptor::NotificationsAdaptor(QObject *parent)
: QDBusAbstractAdaptor(parent),
@ -31,6 +31,11 @@ NotificationsAdaptor::NotificationsAdaptor(QObject *parent)
{
}
NotificationsAdaptor::~NotificationsAdaptor()
{
Q_ASSERT(m_ref == 0);
}
void NotificationsAdaptor::addNotification(const QString &name)
{
emit notificationAdded(name);
@ -53,6 +58,9 @@ void NotificationsAdaptor::invokeAction(const QString &name, const QString &acti
NotificationsAdaptor* NotificationsAdaptor::self()
{
if (!kNotificationsAdaptor) {
kNotificationsAdaptor = new NotificationsAdaptor(qApp);
}
return kNotificationsAdaptor;
}

View file

@ -31,6 +31,7 @@ class NotificationsAdaptor: public QDBusAbstractAdaptor
Q_CLASSINFO("D-Bus Interface", "org.kde.Notifications")
public:
NotificationsAdaptor(QObject *parent);
~NotificationsAdaptor();
static NotificationsAdaptor* self();
void registerObject();