2019-02-02 20:49:38 +00:00
|
|
|
/*
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-02-02 20:49:38 +00:00
|
|
|
|
|
|
|
#include "kcm.h"
|
|
|
|
#include "effectsfilterproxymodel.h"
|
2019-02-03 20:04:09 +00:00
|
|
|
#include "effectsmodel.h"
|
2019-02-02 20:49:38 +00:00
|
|
|
|
|
|
|
#include <KAboutData>
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KNS3/DownloadDialog>
|
2020-10-01 15:50:15 +00:00
|
|
|
#include <KPluginFactory>
|
2019-02-02 20:49:38 +00:00
|
|
|
|
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QWindow>
|
|
|
|
|
|
|
|
K_PLUGIN_FACTORY_WITH_JSON(DesktopEffectsKCMFactory,
|
|
|
|
"kcm_kwin_effects.json",
|
|
|
|
registerPlugin<KWin::DesktopEffectsKCM>();)
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
DesktopEffectsKCM::DesktopEffectsKCM(QObject *parent, const QVariantList &args)
|
|
|
|
: KQuickAddons::ConfigModule(parent, args)
|
2019-02-03 20:04:09 +00:00
|
|
|
, m_model(new EffectsModel(this))
|
2019-02-02 20:49:38 +00:00
|
|
|
{
|
|
|
|
qmlRegisterType<EffectsFilterProxyModel>("org.kde.private.kcms.kwin.effects", 1, 0, "EffectsFilterProxyModel");
|
|
|
|
|
|
|
|
auto about = new KAboutData(
|
|
|
|
QStringLiteral("kcm_kwin_effects"),
|
2019-09-15 22:02:32 +00:00
|
|
|
i18n("Desktop Effects"),
|
2019-02-02 20:49:38 +00:00
|
|
|
QStringLiteral("2.0"),
|
|
|
|
QString(),
|
|
|
|
KAboutLicense::GPL
|
|
|
|
);
|
2020-01-14 16:17:18 +00:00
|
|
|
about->addAuthor(i18n("Vlad Zahorodnii"), QString(), QStringLiteral("vlad.zahorodnii@kde.org"));
|
2019-02-02 20:49:38 +00:00
|
|
|
setAboutData(about);
|
|
|
|
|
|
|
|
setButtons(Apply | Default);
|
|
|
|
|
2019-02-03 20:04:09 +00:00
|
|
|
connect(m_model, &EffectsModel::dataChanged, this, &DesktopEffectsKCM::updateNeedsSave);
|
2019-12-16 09:23:18 +00:00
|
|
|
connect(m_model, &EffectsModel::loaded, this, &DesktopEffectsKCM::updateNeedsSave);
|
2019-02-02 20:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopEffectsKCM::~DesktopEffectsKCM()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractItemModel *DesktopEffectsKCM::effectsModel() const
|
|
|
|
{
|
|
|
|
return m_model;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopEffectsKCM::load()
|
|
|
|
{
|
|
|
|
m_model->load();
|
|
|
|
setNeedsSave(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopEffectsKCM::save()
|
|
|
|
{
|
|
|
|
m_model->save();
|
|
|
|
setNeedsSave(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopEffectsKCM::defaults()
|
|
|
|
{
|
|
|
|
m_model->defaults();
|
|
|
|
updateNeedsSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopEffectsKCM::openGHNS(QQuickItem *context)
|
|
|
|
{
|
|
|
|
QPointer<KNS3::DownloadDialog> dialog = new KNS3::DownloadDialog(QStringLiteral("kwineffect.knsrc"));
|
|
|
|
dialog->setWindowTitle(i18n("Download New Desktop Effects"));
|
|
|
|
dialog->winId();
|
|
|
|
|
|
|
|
if (context && context->window()) {
|
|
|
|
dialog->windowHandle()->setTransientParent(context->window());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog->exec() == QDialog::Accepted) {
|
|
|
|
if (!dialog->changedEntries().isEmpty()) {
|
2019-02-03 20:04:09 +00:00
|
|
|
m_model->load(EffectsModel::LoadOptions::KeepDirty);
|
2019-02-02 20:49:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopEffectsKCM::configure(const QString &pluginId, QQuickItem *context)
|
|
|
|
{
|
2019-02-03 15:18:42 +00:00
|
|
|
const QModelIndex index = m_model->findByPluginId(pluginId);
|
2019-02-02 20:49:38 +00:00
|
|
|
|
2019-02-03 15:18:42 +00:00
|
|
|
QWindow *transientParent = nullptr;
|
2019-02-02 20:49:38 +00:00
|
|
|
if (context && context->window()) {
|
2019-02-03 15:18:42 +00:00
|
|
|
transientParent = context->window();
|
2019-02-02 20:49:38 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 15:18:42 +00:00
|
|
|
m_model->requestConfigure(index, transientParent);
|
2019-02-02 20:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopEffectsKCM::updateNeedsSave()
|
|
|
|
{
|
|
|
|
setNeedsSave(m_model->needsSave());
|
2019-12-16 09:23:18 +00:00
|
|
|
setRepresentsDefaults(m_model->isDefaults());
|
2019-02-02 20:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
#include "kcm.moc"
|