kcms/decoration: Use KCMultiDialog to open decoration kcms
Now that decoration configs are separate plugins we can plug those into KCMultiDialog instead of hand-rolling it ourselves As a nice side-effect this should allow to implement the decoration config in QML BUG: 470902
This commit is contained in:
parent
23f533aa52
commit
bc62760186
1 changed files with 6 additions and 34 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <KDecoration2/Decoration>
|
#include <KDecoration2/Decoration>
|
||||||
|
|
||||||
#include <KCModule>
|
#include <KCModule>
|
||||||
|
#include <KCMultiDialog>
|
||||||
#include <KPluginFactory>
|
#include <KPluginFactory>
|
||||||
#include <KPluginMetaData>
|
#include <KPluginMetaData>
|
||||||
|
|
||||||
|
@ -173,33 +174,23 @@ void PreviewBridge::configure(QQuickItem *ctx)
|
||||||
qWarning() << "Cannot show an invalid decoration's configuration dialog";
|
qWarning() << "Cannot show an invalid decoration's configuration dialog";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// setup the UI
|
|
||||||
QDialog *dialog = new QDialog();
|
KCMultiDialog *dialog = new KCMultiDialog;
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
if (m_lastCreatedClient) {
|
if (m_lastCreatedClient) {
|
||||||
dialog->setWindowTitle(m_lastCreatedClient->caption());
|
dialog->setWindowTitle(m_lastCreatedClient->caption());
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the KCModule through the plugintrader
|
|
||||||
QVariantMap args;
|
QVariantMap args;
|
||||||
if (!m_theme.isNull()) {
|
if (!m_theme.isNull()) {
|
||||||
args.insert(QStringLiteral("theme"), m_theme);
|
args.insert(QStringLiteral("theme"), m_theme);
|
||||||
}
|
}
|
||||||
Q_ASSERT(!m_kcmoduleName.isEmpty());
|
Q_ASSERT(!m_kcmoduleName.isEmpty());
|
||||||
const auto md = KPluginMetaData::findPluginById(s_kcmName, m_kcmoduleName);
|
|
||||||
const auto result = KPluginFactory::instantiatePlugin<KCModule>(md, dialog, QVariantList({args}));
|
|
||||||
if (!result) {
|
|
||||||
qWarning() << "error loading kcm" << result.errorReason << result.errorText;
|
|
||||||
}
|
|
||||||
|
|
||||||
KCModule *kcm = result.plugin;
|
dialog->addModule(KPluginMetaData(s_kcmName + QLatin1Char('/') + m_kcmoduleName), {args});
|
||||||
if (!kcm) {
|
|
||||||
qWarning() << "Could not find the kcm for" << args << m_kcmoduleName << m_theme;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto save = [this, kcm] {
|
connect(dialog, &KCMultiDialog::configCommitted, this, [this] {
|
||||||
kcm->save();
|
|
||||||
if (m_lastCreatedSettings) {
|
if (m_lastCreatedSettings) {
|
||||||
Q_EMIT m_lastCreatedSettings->decorationSettings()->reconfigured();
|
Q_EMIT m_lastCreatedSettings->decorationSettings()->reconfigured();
|
||||||
}
|
}
|
||||||
|
@ -208,26 +199,7 @@ void PreviewBridge::configure(QQuickItem *ctx)
|
||||||
QStringLiteral("org.kde.KWin"),
|
QStringLiteral("org.kde.KWin"),
|
||||||
QStringLiteral("reloadConfig"));
|
QStringLiteral("reloadConfig"));
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
};
|
|
||||||
connect(dialog, &QDialog::accepted, this, save);
|
|
||||||
|
|
||||||
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Reset,
|
|
||||||
dialog);
|
|
||||||
|
|
||||||
QPushButton *reset = buttons->button(QDialogButtonBox::Reset);
|
|
||||||
reset->setEnabled(false);
|
|
||||||
// Here we connect our buttons with the dialog
|
|
||||||
connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
|
|
||||||
connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
|
|
||||||
connect(reset, &QPushButton::clicked, kcm, &KCModule::load);
|
|
||||||
connect(kcm, &KCModule::needsSaveChanged, reset, [reset, kcm]() {
|
|
||||||
reset->setEnabled(kcm->needsSave());
|
|
||||||
});
|
});
|
||||||
connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, kcm, &KCModule::defaults);
|
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(dialog);
|
|
||||||
layout->addWidget(kcm->widget());
|
|
||||||
layout->addWidget(buttons);
|
|
||||||
|
|
||||||
if (ctx->window()) {
|
if (ctx->window()) {
|
||||||
dialog->winId(); // so it creates windowHandle
|
dialog->winId(); // so it creates windowHandle
|
||||||
|
|
Loading…
Reference in a new issue