From 686f99c9c3ef83bc2796083dd3177ea54288cece Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 4 Aug 2023 00:42:34 +0300 Subject: [PATCH] kcrash: use persistent notifications Signed-off-by: Ivailo Monev --- kcrash/kded/kded_kcrash.cpp | 25 ++++++++++++++++++++++--- kcrash/kded/kded_kcrash.h | 5 ++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/kcrash/kded/kded_kcrash.cpp b/kcrash/kded/kded_kcrash.cpp index c919dfb5..7c533bd4 100644 --- a/kcrash/kded/kded_kcrash.cpp +++ b/kcrash/kded/kded_kcrash.cpp @@ -18,7 +18,6 @@ #include "kded_kcrash.h" #include -#include #include #include #include @@ -56,7 +55,15 @@ KCrashModule::KCrashModule(QObject *parent, const QList &args) KCrashModule::~KCrashModule() { - m_dirwatch->deleteLater(); + delete m_dirwatch; + kDebug() << "Closing notifications" << m_notifications.size(); + QMutableListIterator iter(m_notifications); + while (iter.hasNext()) { + KNotification* knotification = iter.next(); + disconnect(knotification, 0, this, 0); + knotification->close(); + iter.remove(); + } } void KCrashModule::slotDirty(const QString &path) @@ -94,11 +101,14 @@ void KCrashModule::slotDirty(const QString &path) kcrashappname = kcrashdata["appname"].toString(); } kDebug() << "Sending notification for" << kcrashfilepath; - KNotification* knotification = new KNotification("Crash"); + // NOTE: when the notification is closed/deleted the actions become non-operational + KNotification* knotification = new KNotification("Crash", KNotification::Persistent, this); knotification->setComponentData(KComponentData("kcrash")); knotification->setTitle(i18n("%1 crashed", kcrashappname)); knotification->setText(i18n("For details about the crash look into the system log.")); knotification->setActions(QStringList() << i18n("Report")); + m_notifications.append(knotification); + connect(knotification, SIGNAL(closed()), this, SLOT(slotClosed())); connect(knotification, SIGNAL(action1Activated()), this, SLOT(slotReport())); knotification->sendEvent(); } @@ -116,8 +126,17 @@ void KCrashModule::slotDirty(const QString &path) } } +void KCrashModule::slotClosed() +{ + KNotification* knotification = qobject_cast(sender()); + kDebug() << "Notification closed" << knotification; + m_notifications.removeAll(knotification); +} + void KCrashModule::slotReport() { + KNotification* knotification = qobject_cast(sender()); + knotification->close(); const QString kcrashreporturl = KDE_BUG_REPORT_URL; KToolInvocation::invokeBrowser(kcrashreporturl); } diff --git a/kcrash/kded/kded_kcrash.h b/kcrash/kded/kded_kcrash.h index b345bdfb..60042e8d 100644 --- a/kcrash/kded/kded_kcrash.h +++ b/kcrash/kded/kded_kcrash.h @@ -21,7 +21,8 @@ #include "kdedmodule.h" -#include +#include +#include class KCrashModule: public KDEDModule { @@ -34,11 +35,13 @@ public: private Q_SLOTS: void slotDirty(const QString &path); + void slotClosed(); void slotReport(); private: QString m_kcrashpath; KDirWatch *m_dirwatch; + QList m_notifications; }; #endif // KCRASH_KDED_H