2013-08-01 16:20:37 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* KWin - the KDE window manager *
|
|
|
|
* This file is part of the KDE project. *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2013 Antonis Tsiapaliokas <kok3rs@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "effectconfig.h"
|
|
|
|
|
2014-03-17 12:13:17 +00:00
|
|
|
#include <KCModule>
|
|
|
|
#include <KPluginTrader>
|
2013-08-07 16:52:45 +00:00
|
|
|
|
2014-01-12 19:27:10 +00:00
|
|
|
#include <KNS3/DownloadDialog>
|
|
|
|
|
2013-08-07 07:09:56 +00:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QVBoxLayout>
|
2014-01-12 19:27:10 +00:00
|
|
|
#include <QPointer>
|
2014-03-27 10:51:50 +00:00
|
|
|
#include <QPushButton>
|
2013-08-01 16:20:37 +00:00
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QString>
|
|
|
|
|
2014-04-28 12:06:18 +00:00
|
|
|
static const QString s_pluginDir = QStringLiteral("kwin/effects/configs/");
|
2014-03-17 18:23:46 +00:00
|
|
|
|
2013-08-07 16:52:45 +00:00
|
|
|
namespace KWin {
|
|
|
|
namespace Compositing {
|
2013-08-01 16:20:37 +00:00
|
|
|
|
|
|
|
EffectConfig::EffectConfig(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-10 07:27:03 +00:00
|
|
|
void EffectConfig::openConfig(const QString &serviceName, bool scripted, const QString &title)
|
2013-08-28 07:36:53 +00:00
|
|
|
{
|
2013-08-07 07:09:56 +00:00
|
|
|
//setup the UI
|
|
|
|
QDialog dialog;
|
2014-06-10 07:27:03 +00:00
|
|
|
dialog.setWindowTitle(title);
|
2014-03-17 12:13:17 +00:00
|
|
|
|
|
|
|
// create the KCModule through the plugintrader
|
2014-03-17 18:23:46 +00:00
|
|
|
KCModule *kcm = nullptr;
|
|
|
|
if (scripted) {
|
|
|
|
// try generic module for scripted
|
|
|
|
const auto offers = KPluginTrader::self()->query(s_pluginDir, QString(),
|
|
|
|
QStringLiteral("[X-KDE-Library] == 'kcm_kwin4_genericscripted'"));
|
|
|
|
if (!offers.isEmpty()) {
|
|
|
|
const KPluginInfo &generic = offers.first();
|
|
|
|
KPluginLoader loader(generic.libraryPath());
|
|
|
|
KPluginFactory *factory = loader.factory();
|
|
|
|
if (factory) {
|
|
|
|
kcm = factory->create<KCModule>(serviceName, &dialog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
kcm = KPluginTrader::createInstanceFromQuery<KCModule>(s_pluginDir, QString(),
|
2015-03-04 23:44:47 +00:00
|
|
|
QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(serviceName),
|
2014-03-17 18:23:46 +00:00
|
|
|
&dialog);
|
|
|
|
}
|
2014-03-17 12:13:17 +00:00
|
|
|
if (!kcm) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(&dialog, &QDialog::accepted, kcm, &KCModule::save);
|
|
|
|
|
2014-03-27 10:51:50 +00:00
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok |
|
|
|
|
QDialogButtonBox::Cancel |
|
|
|
|
QDialogButtonBox::Apply |
|
|
|
|
QDialogButtonBox::RestoreDefaults |
|
|
|
|
QDialogButtonBox::Reset,
|
|
|
|
&dialog);
|
|
|
|
|
|
|
|
QPushButton *apply = buttons->button(QDialogButtonBox::Apply);
|
|
|
|
QPushButton *reset = buttons->button(QDialogButtonBox::Reset);
|
|
|
|
apply->setEnabled(false);
|
|
|
|
reset->setEnabled(false);
|
2013-08-07 07:09:56 +00:00
|
|
|
//Here we connect our buttons with the dialog
|
2014-03-17 12:13:17 +00:00
|
|
|
connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
2014-03-27 10:51:50 +00:00
|
|
|
connect(apply, &QPushButton::clicked, kcm, &KCModule::save);
|
|
|
|
connect(reset, &QPushButton::clicked, kcm, &KCModule::load);
|
|
|
|
auto changedSignal = static_cast<void(KCModule::*)(bool)>(&KCModule::changed);
|
|
|
|
connect(kcm, changedSignal, apply, &QPushButton::setEnabled);
|
|
|
|
connect(kcm, changedSignal, reset, &QPushButton::setEnabled);
|
|
|
|
connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, kcm, &KCModule::defaults);
|
2014-03-17 12:13:17 +00:00
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(&dialog);
|
|
|
|
layout->addWidget(kcm);
|
|
|
|
layout->addWidget(buttons);
|
|
|
|
dialog.exec();
|
2013-08-01 16:20:37 +00:00
|
|
|
}
|
2014-01-12 19:27:10 +00:00
|
|
|
|
|
|
|
void EffectConfig::openGHNS()
|
|
|
|
{
|
|
|
|
QPointer<KNS3::DownloadDialog> downloadDialog = new KNS3::DownloadDialog(QStringLiteral("kwineffect.knsrc"));
|
|
|
|
if (downloadDialog->exec() == QDialog::Accepted) {
|
|
|
|
emit effectListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete downloadDialog;
|
|
|
|
}
|
|
|
|
|
2013-08-07 16:52:45 +00:00
|
|
|
}//end namespace Compositing
|
|
|
|
}//end namespace KWin
|