From b9a3005f39a5c2f0336b7f687abe1e86d595a40d Mon Sep 17 00:00:00 2001 From: Fushan Wen Date: Wed, 22 Jun 2022 12:39:27 +0800 Subject: [PATCH] Restore old applet configuration after switching to alternative In task manager, switching between icon task manager and text task manager loses the old settings, which is inconvenient. This copies the old configuration to the new applet to fix that behavior. BUG: 355588 FIXED-IN: 5.26 --- shell/alternativeshelper.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/shell/alternativeshelper.cpp b/shell/alternativeshelper.cpp index 4d8e9bb58..97263eb1e 100644 --- a/shell/alternativeshelper.cpp +++ b/shell/alternativeshelper.cpp @@ -9,6 +9,8 @@ #include #include +#include + #include #include @@ -60,21 +62,23 @@ void AlternativesHelper::loadAlternative(const QString &plugin) const QPoint newPos = appletItem->mapToItem(contItem, QPointF(0, 0)).toPoint(); - m_applet->destroy(); + Plasma::Applet *newApplet = nullptr; + QMetaObject::invokeMethod(contItem, + "createApplet", + Q_RETURN_ARG(Plasma::Applet *, newApplet), + Q_ARG(QString, plugin), + Q_ARG(QVariantList, QVariantList()), + Q_ARG(QPoint, newPos)); + + if (newApplet) { + newApplet->setGlobalShortcut(shortcut); + KConfigGroup newCg(newApplet->config()); + m_applet->config().copyTo(&newCg); + // To let ConfigPropertyMap reload its config + Q_EMIT newApplet->configScheme()->configChanged(); + } - connect(m_applet, &QObject::destroyed, contItem, [=]() { - Plasma::Applet *newApplet = nullptr; - QMetaObject::invokeMethod(contItem, - "createApplet", - Q_RETURN_ARG(Plasma::Applet *, newApplet), - Q_ARG(QString, plugin), - Q_ARG(QVariantList, QVariantList()), - Q_ARG(QPoint, newPos)); - - if (newApplet) { - newApplet->setGlobalShortcut(shortcut); - } - }); + m_applet->destroy(); } #include "moc_alternativeshelper.cpp"