really delete awaiting applets on quit

Change-Id: I3b9107f988bde75262f27c1fd7e851b868140ccf
This commit is contained in:
Marco Martin 2014-10-28 15:55:12 +01:00
parent af6149c9d0
commit 2475a2560e
3 changed files with 43 additions and 7 deletions

View File

@ -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);

View File

@ -27,6 +27,7 @@
#include <QFile>
#include <qstandardpaths.h>
#include <QTimer>
#include <QDebug>
#include <QMessageBox>
@ -35,7 +36,6 @@
#include <kglobalaccel.h>
#include <KConfigLoader>
#include <KServiceTypeTrader>
#include <knotification.h>
#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()) {

View File

@ -29,6 +29,7 @@
#include <kconfigskeleton.h>
#include <kservice.h>
#include <kplugininfo.h>
#include <knotification.h>
#include "plasma/applet.h"
@ -104,6 +105,9 @@ public:
QBasicTimer constraintsTimer;
QBasicTimer *modificationsTimer;
QPointer <KNotification> deleteNotification;
QTimer *deleteNotificationTimer;
// a great green field of booleans :)
bool hasConfigurationInterface : 1;
bool failed : 1;