From 2475a2560e91f467c2e5769c093c0879d42ce7bd Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 28 Oct 2014 15:55:12 +0100 Subject: [PATCH] really delete awaiting applets on quit Change-Id: I3b9107f988bde75262f27c1fd7e851b868140ccf --- src/plasma/applet.cpp | 4 ++++ src/plasma/private/applet_p.cpp | 42 +++++++++++++++++++++++++++------ src/plasma/private/applet_p.h | 4 ++++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/plasma/applet.cpp b/src/plasma/applet.cpp index f4b5410c5..0139309a0 100644 --- a/src/plasma/applet.cpp +++ b/src/plasma/applet.cpp @@ -104,6 +104,10 @@ Applet::Applet(const QString &packagePath, uint appletId) Applet::~Applet() { + if (status() == Types::AwaitingDeletionStatus) { + d->transient = true; + d->resetConfigurationObject(); + } //let people know that i will die emit appletDeleted(this); diff --git a/src/plasma/private/applet_p.cpp b/src/plasma/private/applet_p.cpp index 571d35a61..9f433af12 100644 --- a/src/plasma/private/applet_p.cpp +++ b/src/plasma/private/applet_p.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -35,7 +36,6 @@ #include #include #include -#include #include "containment.h" #include "corona.h" @@ -63,6 +63,7 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int activationAction(0), itemStatus(Types::UnknownStatus), modificationsTimer(0), + deleteNotificationTimer(0), hasConfigurationInterface(false), failed(false), transient(false), @@ -90,6 +91,10 @@ AppletPrivate::~AppletPrivate() KGlobalAccel::self()->removeAllShortcuts(activationAction); } + if (deleteNotification) { + deleteNotification->close(); + } + delete script; script = 0; delete package; @@ -226,17 +231,40 @@ void AppletPrivate::askDestroy() cleanUpAndDelete(); } else { q->setStatus(Types::AwaitingDeletionStatus); - KNotification *notification = new KNotification("plasmoidDeleted", KNotification::Persistent | - KNotification::CloseWhenWidgetActivated, q); + //no parent, but it won't leak, since it will be closed both in case of timeout + //or direct action + deleteNotification = new KNotification("plasmoidDeleted", KNotification::Persistent, 0); QStringList actions; - notification->setText(i18n("The widget \"%1\" has been deleted.", q->title())); + deleteNotification->setText(i18n("The widget \"%1\" has been deleted.", q->title())); actions.append(i18n("Undo")); - notification->setActions(actions); - QObject::connect(notification, &KNotification::action1Activated, + deleteNotification->setActions(actions); + QObject::connect(deleteNotification.data(), &KNotification::action1Activated, [=]() { q->setStatus(Types::PassiveStatus); + if (deleteNotification) { + deleteNotification->close(); + } + if (deleteNotificationTimer) { + delete deleteNotificationTimer; + deleteNotificationTimer = 0; + } }); - notification->sendEvent(); + deleteNotification->sendEvent(); + if (!deleteNotificationTimer) { + deleteNotificationTimer = new QTimer(q); + //really delete after 2 minutes + deleteNotificationTimer->setInterval(2 * 60 * 1000); + deleteNotificationTimer->setSingleShot(true); + QObject::connect(deleteNotificationTimer, &QTimer::timeout, + [=]() { + if (deleteNotification) { + deleteNotification->close(); + } + transient = true; + cleanUpAndDelete(); + }); + deleteNotificationTimer->start(); + } } /* if (q->isContainment()) { diff --git a/src/plasma/private/applet_p.h b/src/plasma/private/applet_p.h index 76a1270be..d97499d7c 100644 --- a/src/plasma/private/applet_p.h +++ b/src/plasma/private/applet_p.h @@ -29,6 +29,7 @@ #include #include #include +#include #include "plasma/applet.h" @@ -104,6 +105,9 @@ public: QBasicTimer constraintsTimer; QBasicTimer *modificationsTimer; + QPointer deleteNotification; + QTimer *deleteNotificationTimer; + // a great green field of booleans :) bool hasConfigurationInterface : 1; bool failed : 1;