plasma: manually delete the buttons for applications actions on frame removal

to prevent signals delivery mostly

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-09-18 13:23:33 +03:00
parent 21d66f5e75
commit f6a407ab6b

View file

@ -27,6 +27,27 @@
#include <KNotificationConfigWidget> #include <KNotificationConfigWidget>
#include <KDebug> #include <KDebug>
static void kClearButtons(QGraphicsGridLayout *framelayout)
{
// row insertation starts at 0, count is +1
if (framelayout->rowCount() >= 4) {
QGraphicsLinearLayout* buttonslayout = static_cast<QGraphicsLinearLayout*>(framelayout->itemAt(3, 0));
// redo the buttons layout in case of notification update
QList<Plasma::PushButton*> actionbuttons;
for (int i = 0; i < buttonslayout->count(); i++) {
Plasma::PushButton* actionbutton = static_cast<Plasma::PushButton*>(buttonslayout->itemAt(i));
if (actionbutton) {
actionbuttons.append(actionbutton);
}
buttonslayout->removeAt(i);
}
qDeleteAll(actionbuttons);
actionbuttons.clear();
framelayout->removeItem(buttonslayout);
delete buttonslayout;
}
}
ApplicationFrame::ApplicationFrame(const QString &_name, QGraphicsWidget *parent) ApplicationFrame::ApplicationFrame(const QString &_name, QGraphicsWidget *parent)
: Plasma::Frame(parent), : Plasma::Frame(parent),
iconwidget(nullptr), iconwidget(nullptr),
@ -173,25 +194,8 @@ void ApplicationsWidget::dataUpdated(const QString &name, const Plasma::DataEngi
// qDebug() << Q_FUNC_INFO << actions; // qDebug() << Q_FUNC_INFO << actions;
QGraphicsGridLayout* framelayout = static_cast<QGraphicsGridLayout*>(frame->layout()); QGraphicsGridLayout* framelayout = static_cast<QGraphicsGridLayout*>(frame->layout());
Q_ASSERT(framelayout != nullptr); Q_ASSERT(framelayout != nullptr);
kClearButtons(framelayout);
QGraphicsLinearLayout* buttonslayout = nullptr; QGraphicsLinearLayout* buttonslayout = nullptr;
// row insertation starts at 0, count is +1
if (framelayout->rowCount() >= 4) {
buttonslayout = static_cast<QGraphicsLinearLayout*>(framelayout->itemAt(3, 0));
// redo the buttons layout in case of notification update
QList<Plasma::PushButton*> actionbuttons;
for (int i = 0; i < buttonslayout->count(); i++) {
Plasma::PushButton* actionbutton = static_cast<Plasma::PushButton*>(buttonslayout->itemAt(i));
if (actionbutton) {
actionbuttons.append(actionbutton);
}
buttonslayout->removeAt(i);
}
qDeleteAll(actionbuttons);
actionbuttons.clear();
framelayout->removeItem(buttonslayout);
delete buttonslayout;
buttonslayout = nullptr;
}
for (int i = 0; i < actions.size(); i++) { for (int i = 0; i < actions.size(); i++) {
const QString actionid = actions[i]; const QString actionid = actions[i];
i++; i++;
@ -254,6 +258,9 @@ void ApplicationsWidget::slotRemoveActivated()
(void)plasmaservice->startOperationCall("userClosed", plasmaserviceargs); (void)plasmaservice->startOperationCall("userClosed", plasmaserviceargs);
} }
m_layout->removeItem(frame); m_layout->removeItem(frame);
QGraphicsGridLayout* framelayout = static_cast<QGraphicsGridLayout*>(frame->layout());
Q_ASSERT(framelayout != nullptr);
kClearButtons(framelayout);
frame->deleteLater(); frame->deleteLater();
iter.remove(); iter.remove();
break; break;
@ -292,7 +299,7 @@ void ApplicationsWidget::slotActionReleased()
plasmaserviceargs["actionId"] = actionid; plasmaserviceargs["actionId"] = actionid;
(void)plasmaservice->startOperationCall("invokeAction", plasmaserviceargs); (void)plasmaservice->startOperationCall("invokeAction", plasmaserviceargs);
} }
locker.unlock();
// remove notification too (compat) // remove notification too (compat)
QTimer::singleShot(200, actionframe->removewidget, SIGNAL(activated())); QTimer::singleShot(200, actionframe->removewidget, SIGNAL(activated()));
} }