diff --git a/kcmkwin/common/effectmodel.cpp b/kcmkwin/common/effectmodel.cpp
index a443a2a3b3..9ca380876b 100644
--- a/kcmkwin/common/effectmodel.cpp
+++ b/kcmkwin/common/effectmodel.cpp
@@ -26,6 +26,7 @@ along with this program. If not, see .
#include
#include
+#include
#include
#include
#include
@@ -36,6 +37,10 @@ along with this program. If not, see .
#include
#include
#include
+#include
+#include
+#include
+#include
namespace KWin
{
@@ -536,6 +541,78 @@ QModelIndex EffectModel::findByPluginId(const QString &pluginId) const
return index(std::distance(m_effectsList.constBegin(), it), 0);
}
+static KCModule *findBinaryConfig(const QString &pluginId, QObject *parent)
+{
+ return KPluginTrader::createInstanceFromQuery(
+ QStringLiteral("kwin/effects/configs/"),
+ QString(),
+ QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(pluginId),
+ parent
+ );
+}
+
+static KCModule *findScriptedConfig(const QString &pluginId, QObject *parent)
+{
+ const auto offers = KPluginTrader::self()->query(
+ QStringLiteral("kwin/effects/configs/"),
+ QString(),
+ QStringLiteral("[X-KDE-Library] == 'kcm_kwin4_genericscripted'")
+ );
+
+ if (offers.isEmpty()) {
+ return nullptr;
+ }
+
+ const KPluginInfo &generic = offers.first();
+ KPluginLoader loader(generic.libraryPath());
+ KPluginFactory *factory = loader.factory();
+ if (!factory) {
+ return nullptr;
+ }
+
+ return factory->create(pluginId, parent);
+}
+
+void EffectModel::requestConfigure(const QModelIndex &index, QWindow *transientParent)
+{
+ if (!index.isValid()) {
+ return;
+ }
+
+ QPointer dialog = new QDialog();
+
+ KCModule *module = index.data(ScriptedRole).toBool()
+ ? findScriptedConfig(index.data(ServiceNameRole).toString(), dialog)
+ : findBinaryConfig(index.data(ServiceNameRole).toString(), dialog);
+ if (!module) {
+ delete dialog;
+ return;
+ }
+
+ dialog->setWindowTitle(index.data(NameRole).toString());
+ dialog->winId();
+ dialog->windowHandle()->setTransientParent(transientParent);
+
+ auto buttons = new QDialogButtonBox(
+ QDialogButtonBox::Ok |
+ QDialogButtonBox::Cancel |
+ QDialogButtonBox::RestoreDefaults,
+ dialog
+ );
+ connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
+ connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
+ connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked,
+ module, &KCModule::defaults);
+
+ auto layout = new QVBoxLayout(dialog);
+ layout->addWidget(module);
+ layout->addWidget(buttons);
+
+ dialog->exec();
+
+ delete dialog;
+}
+
bool EffectModel::shouldStore(const EffectData &data) const
{
Q_UNUSED(data)
diff --git a/kcmkwin/common/effectmodel.h b/kcmkwin/common/effectmodel.h
index 8c1ba77885..bbbaf9689f 100644
--- a/kcmkwin/common/effectmodel.h
+++ b/kcmkwin/common/effectmodel.h
@@ -29,6 +29,7 @@ along with this program. If not, see .
#include
#include
#include
+#include
namespace KWin
{
@@ -187,6 +188,14 @@ public:
**/
QModelIndex findByPluginId(const QString &pluginId) const;
+ /**
+ * Shows a configuration dialog for a given effect.
+ *
+ * @param index An effect represented by the given index.
+ * @param transientParent The transient parent of the configuration dialog.
+ **/
+ void requestConfigure(const QModelIndex &index, QWindow *transientParent);
+
protected:
enum class Kind {
BuiltIn,
diff --git a/kcmkwin/kwindesktop/virtualdesktops.cpp b/kcmkwin/kwindesktop/virtualdesktops.cpp
index 99d441c807..2960beba69 100644
--- a/kcmkwin/kwindesktop/virtualdesktops.cpp
+++ b/kcmkwin/kwindesktop/virtualdesktops.cpp
@@ -22,16 +22,8 @@
#include
#include
-#include
#include
#include
-#include
-#include
-
-#include
-#include
-#include
-#include
K_PLUGIN_FACTORY_WITH_JSON(VirtualDesktopsFactory, "kcm_kwin_virtualdesktops.json", registerPlugin();)
@@ -198,50 +190,7 @@ void VirtualDesktops::configureAnimation()
return;
}
- const QString name = index.data(AnimationsModel::NameRole).toString();
- const QString serviceName = index.data(AnimationsModel::ServiceNameRole).toString();
-
- QPointer configDialog = new QDialog();
-
- KCModule *kcm = KPluginTrader::createInstanceFromQuery(
- QStringLiteral("kwin/effects/configs/"),
- QString(),
- QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(serviceName),
- configDialog
- );
-
- if (!kcm) {
- delete configDialog;
- return;
- }
-
- configDialog->setWindowTitle(name);
- configDialog->setLayout(new QVBoxLayout);
-
- auto buttons = new QDialogButtonBox(
- QDialogButtonBox::Ok |
- QDialogButtonBox::Cancel |
- QDialogButtonBox::RestoreDefaults,
- configDialog
- );
- QObject::connect(buttons, &QDialogButtonBox::accepted, configDialog, &QDialog::accept);
- QObject::connect(buttons, &QDialogButtonBox::rejected, configDialog, &QDialog::reject);
- QObject::connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, kcm, &KCModule::defaults);
-
- auto showWidget = new QWidget(configDialog);
- auto layout = new QVBoxLayout;
- showWidget->setLayout(layout);
- layout->addWidget(kcm);
- configDialog->layout()->addWidget(showWidget);
- configDialog->layout()->addWidget(buttons);
-
- if (configDialog->exec() == QDialog::Accepted) {
- kcm->save();
- } else if (!configDialog.isNull()) {
- kcm->load();
- }
-
- delete configDialog;
+ m_animationsModel->requestConfigure(index, nullptr);
}
void VirtualDesktops::showAboutAnimation()
diff --git a/kcmkwin/kwineffects/kcm.cpp b/kcmkwin/kwineffects/kcm.cpp
index 078a104814..d35a38621a 100644
--- a/kcmkwin/kwineffects/kcm.cpp
+++ b/kcmkwin/kwineffects/kcm.cpp
@@ -20,16 +20,10 @@
#include "effectsfilterproxymodel.h"
#include
-#include
#include
#include
-#include
-#include
-#include
-#include
#include
-#include
#include
K_PLUGIN_FACTORY_WITH_JSON(DesktopEffectsKCMFactory,
@@ -106,80 +100,16 @@ void DesktopEffectsKCM::openGHNS(QQuickItem *context)
delete dialog;
}
-static KCModule *findBinaryConfig(const QString &pluginId, QObject *parent)
-{
- return KPluginTrader::createInstanceFromQuery(
- QStringLiteral("kwin/effects/configs/"),
- QString(),
- QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(pluginId),
- parent
- );
-}
-
-static KCModule *findScriptedConfig(const QString &pluginId, QObject *parent)
-{
- const auto offers = KPluginTrader::self()->query(
- QStringLiteral("kwin/effects/configs/"),
- QString(),
- QStringLiteral("[X-KDE-Library] == 'kcm_kwin4_genericscripted'")
- );
-
- if (offers.isEmpty()) {
- return nullptr;
- }
-
- const KPluginInfo &generic = offers.first();
- KPluginLoader loader(generic.libraryPath());
- KPluginFactory *factory = loader.factory();
- if (!factory) {
- return nullptr;
- }
-
- return factory->create(pluginId, parent);
-}
-
void DesktopEffectsKCM::configure(const QString &pluginId, QQuickItem *context)
{
- const QModelIndex idx = m_model->findByPluginId(pluginId);
- if (!idx.isValid()) {
- return;
- }
-
- QPointer dialog = new QDialog();
-
- KCModule *module = idx.data(EffectModel::ScriptedRole).toBool()
- ? findScriptedConfig(pluginId, dialog)
- : findBinaryConfig(pluginId, dialog);
- if (!module) {
- delete dialog;
- return;
- }
-
- dialog->setWindowTitle(idx.data(EffectModel::NameRole).toString());
- dialog->winId();
-
- auto buttons = new QDialogButtonBox(
- QDialogButtonBox::Ok |
- QDialogButtonBox::Cancel |
- QDialogButtonBox::RestoreDefaults,
- dialog
- );
- connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
- connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
- connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked,
- module, &KCModule::defaults);
-
- auto layout = new QVBoxLayout(dialog);
- layout->addWidget(module);
- layout->addWidget(buttons);
+ const QModelIndex index = m_model->findByPluginId(pluginId);
+ QWindow *transientParent = nullptr;
if (context && context->window()) {
- dialog->windowHandle()->setTransientParent(context->window());
+ transientParent = context->window();
}
- dialog->exec();
-
- delete dialog;
+ m_model->requestConfigure(index, transientParent);
}
void DesktopEffectsKCM::updateNeedsSave()