2014-10-31 06:53:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
*
|
|
|
|
* 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) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* 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 "previewbridge.h"
|
|
|
|
#include "previewclient.h"
|
|
|
|
#include "previewitem.h"
|
|
|
|
#include "previewsettings.h"
|
|
|
|
|
|
|
|
#include <KDecoration2/DecoratedClient>
|
|
|
|
#include <KDecoration2/Decoration>
|
|
|
|
|
2014-12-05 12:44:16 +00:00
|
|
|
#include <KCModule>
|
2014-10-31 06:53:04 +00:00
|
|
|
#include <KPluginLoader>
|
|
|
|
#include <KPluginFactory>
|
|
|
|
#include <KPluginTrader>
|
|
|
|
|
|
|
|
#include <QDebug>
|
2014-12-05 14:58:05 +00:00
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
2014-12-05 12:44:16 +00:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QPushButton>
|
2020-05-06 13:15:03 +00:00
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QQuickRenderControl>
|
|
|
|
#include <QQuickWindow>
|
2014-12-05 12:44:16 +00:00
|
|
|
#include <QVBoxLayout>
|
2020-05-06 13:15:03 +00:00
|
|
|
#include <QWindow>
|
2014-10-31 06:53:04 +00:00
|
|
|
|
|
|
|
namespace KDecoration2
|
|
|
|
{
|
|
|
|
namespace Preview
|
|
|
|
{
|
|
|
|
|
|
|
|
static const QString s_pluginName = QStringLiteral("org.kde.kdecoration2");
|
|
|
|
|
|
|
|
PreviewBridge::PreviewBridge(QObject *parent)
|
|
|
|
: DecorationBridge(parent)
|
|
|
|
, m_lastCreatedClient(nullptr)
|
|
|
|
, m_lastCreatedSettings(nullptr)
|
|
|
|
, m_valid(false)
|
|
|
|
{
|
|
|
|
connect(this, &PreviewBridge::pluginChanged, this, &PreviewBridge::createFactory);
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewBridge::~PreviewBridge() = default;
|
|
|
|
|
|
|
|
std::unique_ptr<DecoratedClientPrivate> PreviewBridge::createClient(DecoratedClient *client, Decoration *decoration)
|
|
|
|
{
|
|
|
|
auto ptr = std::unique_ptr<PreviewClient>(new PreviewClient(client, decoration));
|
|
|
|
m_lastCreatedClient = ptr.get();
|
2019-07-09 21:28:04 +00:00
|
|
|
return ptr;
|
2014-10-31 06:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewBridge::update(Decoration *decoration, const QRect &geometry)
|
|
|
|
{
|
|
|
|
Q_UNUSED(geometry)
|
|
|
|
auto it = std::find_if(m_previewItems.constBegin(), m_previewItems.constEnd(), [decoration](PreviewItem *item) {
|
|
|
|
return item->decoration() == decoration;
|
|
|
|
});
|
|
|
|
if (it != m_previewItems.constEnd()) {
|
|
|
|
(*it)->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<DecorationSettingsPrivate> PreviewBridge::settings(DecorationSettings *parent)
|
|
|
|
{
|
|
|
|
auto ptr = std::unique_ptr<PreviewSettings>(new PreviewSettings(parent));
|
|
|
|
m_lastCreatedSettings = ptr.get();
|
2019-07-09 21:28:04 +00:00
|
|
|
return ptr;
|
2014-10-31 06:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewBridge::registerPreviewItem(PreviewItem *item)
|
|
|
|
{
|
|
|
|
m_previewItems.append(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewBridge::unregisterPreviewItem(PreviewItem *item)
|
|
|
|
{
|
|
|
|
m_previewItems.removeAll(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewBridge::setPlugin(const QString &plugin)
|
|
|
|
{
|
|
|
|
if (m_plugin == plugin) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_plugin = plugin;
|
|
|
|
emit pluginChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString PreviewBridge::theme() const
|
|
|
|
{
|
|
|
|
return m_theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewBridge::setTheme(const QString &theme)
|
|
|
|
{
|
|
|
|
if (m_theme == theme) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_theme = theme;
|
|
|
|
emit themeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString PreviewBridge::plugin() const
|
|
|
|
{
|
|
|
|
return m_plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewBridge::createFactory()
|
|
|
|
{
|
|
|
|
m_factory.clear();
|
[kcmkwin/kwindecoration] Rewrite the KWin decorations settings as a ConfigModule
Summary:
* Wrote new KCM based on KQuickAddons::ConfigModule.
* Remade QMLs for Buttons and Themes tabs.
* Updated bridge model code for new plugin lookup API (fixes warnings).
* Fixed decoration shadow changing messing with the previews sizes.
* Fixed button drag and drop issues (see D18104).
* Fixed default settings button behavior and detection of settings changes.
* Updated Get Hot New Stuff.
* Removed apply button in previewbridge.cpp: After applying changes, a theme's KCModule is invalidated.
BUG: 389431
BUG: 350122
BUG: 346222
BUG: 342816
BUG: 397595
{F6574963} | {F6574962} | {F6574961} | {F6574960}
Test Plan:
* Verified saving and loading for every setting
* Checked shadows of Breeze and Oxygen
* Tested all possible drag&drop operations on both sides of the fake titlebar
* Changed color schemes (with `kcmshell5 colors`) while showing the Themes tab to see if all previews update correctly their palettes
* Tested on a fresh Neon-developer account, via kcmshell and systemsettings
Reviewers: #vdg, abetts, ngraham, #kwin, davidedmundson
Reviewed By: #vdg, #kwin, davidedmundson
Subscribers: zzag, GB_2, ngraham, broulik, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18458
2019-02-07 15:32:05 +00:00
|
|
|
|
2014-10-31 06:53:04 +00:00
|
|
|
if (m_plugin.isNull()) {
|
|
|
|
setValid(false);
|
[kcmkwin/kwindecoration] Rewrite the KWin decorations settings as a ConfigModule
Summary:
* Wrote new KCM based on KQuickAddons::ConfigModule.
* Remade QMLs for Buttons and Themes tabs.
* Updated bridge model code for new plugin lookup API (fixes warnings).
* Fixed decoration shadow changing messing with the previews sizes.
* Fixed button drag and drop issues (see D18104).
* Fixed default settings button behavior and detection of settings changes.
* Updated Get Hot New Stuff.
* Removed apply button in previewbridge.cpp: After applying changes, a theme's KCModule is invalidated.
BUG: 389431
BUG: 350122
BUG: 346222
BUG: 342816
BUG: 397595
{F6574963} | {F6574962} | {F6574961} | {F6574960}
Test Plan:
* Verified saving and loading for every setting
* Checked shadows of Breeze and Oxygen
* Tested all possible drag&drop operations on both sides of the fake titlebar
* Changed color schemes (with `kcmshell5 colors`) while showing the Themes tab to see if all previews update correctly their palettes
* Tested on a fresh Neon-developer account, via kcmshell and systemsettings
Reviewers: #vdg, abetts, ngraham, #kwin, davidedmundson
Reviewed By: #vdg, #kwin, davidedmundson
Subscribers: zzag, GB_2, ngraham, broulik, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18458
2019-02-07 15:32:05 +00:00
|
|
|
qWarning() << "Plugin not set";
|
2014-10-31 06:53:04 +00:00
|
|
|
return;
|
|
|
|
}
|
[kcmkwin/kwindecoration] Rewrite the KWin decorations settings as a ConfigModule
Summary:
* Wrote new KCM based on KQuickAddons::ConfigModule.
* Remade QMLs for Buttons and Themes tabs.
* Updated bridge model code for new plugin lookup API (fixes warnings).
* Fixed decoration shadow changing messing with the previews sizes.
* Fixed button drag and drop issues (see D18104).
* Fixed default settings button behavior and detection of settings changes.
* Updated Get Hot New Stuff.
* Removed apply button in previewbridge.cpp: After applying changes, a theme's KCModule is invalidated.
BUG: 389431
BUG: 350122
BUG: 346222
BUG: 342816
BUG: 397595
{F6574963} | {F6574962} | {F6574961} | {F6574960}
Test Plan:
* Verified saving and loading for every setting
* Checked shadows of Breeze and Oxygen
* Tested all possible drag&drop operations on both sides of the fake titlebar
* Changed color schemes (with `kcmshell5 colors`) while showing the Themes tab to see if all previews update correctly their palettes
* Tested on a fresh Neon-developer account, via kcmshell and systemsettings
Reviewers: #vdg, abetts, ngraham, #kwin, davidedmundson
Reviewed By: #vdg, #kwin, davidedmundson
Subscribers: zzag, GB_2, ngraham, broulik, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18458
2019-02-07 15:32:05 +00:00
|
|
|
|
|
|
|
const auto offers = KPluginTrader::self()->query(s_pluginName, s_pluginName);
|
|
|
|
auto item = std::find_if(offers.constBegin(), offers.constEnd(), [this](const auto &plugin) { return plugin.pluginName() == m_plugin; });
|
|
|
|
if (item != offers.constEnd()) {
|
|
|
|
KPluginLoader loader(item->libraryPath());
|
|
|
|
m_factory = loader.factory();
|
2014-10-31 06:53:04 +00:00
|
|
|
}
|
[kcmkwin/kwindecoration] Rewrite the KWin decorations settings as a ConfigModule
Summary:
* Wrote new KCM based on KQuickAddons::ConfigModule.
* Remade QMLs for Buttons and Themes tabs.
* Updated bridge model code for new plugin lookup API (fixes warnings).
* Fixed decoration shadow changing messing with the previews sizes.
* Fixed button drag and drop issues (see D18104).
* Fixed default settings button behavior and detection of settings changes.
* Updated Get Hot New Stuff.
* Removed apply button in previewbridge.cpp: After applying changes, a theme's KCModule is invalidated.
BUG: 389431
BUG: 350122
BUG: 346222
BUG: 342816
BUG: 397595
{F6574963} | {F6574962} | {F6574961} | {F6574960}
Test Plan:
* Verified saving and loading for every setting
* Checked shadows of Breeze and Oxygen
* Tested all possible drag&drop operations on both sides of the fake titlebar
* Changed color schemes (with `kcmshell5 colors`) while showing the Themes tab to see if all previews update correctly their palettes
* Tested on a fresh Neon-developer account, via kcmshell and systemsettings
Reviewers: #vdg, abetts, ngraham, #kwin, davidedmundson
Reviewed By: #vdg, #kwin, davidedmundson
Subscribers: zzag, GB_2, ngraham, broulik, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18458
2019-02-07 15:32:05 +00:00
|
|
|
|
2014-10-31 06:53:04 +00:00
|
|
|
setValid(!m_factory.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PreviewBridge::isValid() const
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewBridge::setValid(bool valid)
|
|
|
|
{
|
|
|
|
if (m_valid == valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_valid = valid;
|
|
|
|
emit validChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
Decoration *PreviewBridge::createDecoration(QObject *parent)
|
|
|
|
{
|
|
|
|
if (!m_valid) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
QVariantMap args({ {QStringLiteral("bridge"), QVariant::fromValue(this)} });
|
|
|
|
if (!m_theme.isNull()) {
|
|
|
|
args.insert(QStringLiteral("theme"), m_theme);
|
|
|
|
}
|
|
|
|
return m_factory->create<KDecoration2::Decoration>(parent, QVariantList({args}));
|
|
|
|
}
|
|
|
|
|
2014-11-03 15:12:54 +00:00
|
|
|
DecorationButton *PreviewBridge::createButton(KDecoration2::Decoration *decoration, KDecoration2::DecorationButtonType type, QObject *parent)
|
|
|
|
{
|
|
|
|
if (!m_valid) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return m_factory->create<KDecoration2::DecorationButton>(QStringLiteral("button"), parent, QVariantList({QVariant::fromValue(type), QVariant::fromValue(decoration)}));
|
|
|
|
}
|
|
|
|
|
2020-05-06 13:15:03 +00:00
|
|
|
void PreviewBridge::configure(QQuickItem *ctx)
|
2014-12-05 12:44:16 +00:00
|
|
|
{
|
|
|
|
if (!m_valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//setup the UI
|
2020-05-06 13:15:03 +00:00
|
|
|
QDialog *dialog = new QDialog();
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
2014-12-05 12:44:16 +00:00
|
|
|
if (m_lastCreatedClient) {
|
2020-05-06 13:15:03 +00:00
|
|
|
dialog->setWindowTitle(m_lastCreatedClient->caption());
|
2014-12-05 12:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create the KCModule through the plugintrader
|
|
|
|
QVariantMap args;
|
|
|
|
if (!m_theme.isNull()) {
|
|
|
|
args.insert(QStringLiteral("theme"), m_theme);
|
|
|
|
}
|
2020-05-06 13:15:03 +00:00
|
|
|
KCModule *kcm = m_factory->create<KCModule>(QStringLiteral("kcmodule"), dialog, QVariantList({args}));
|
2014-12-05 12:44:16 +00:00
|
|
|
if (!kcm) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-05 14:58:05 +00:00
|
|
|
auto save = [this,kcm] {
|
|
|
|
kcm->save();
|
2016-04-08 07:26:43 +00:00
|
|
|
if (m_lastCreatedSettings) {
|
|
|
|
emit m_lastCreatedSettings->decorationSettings()->reconfigured();
|
2014-12-05 14:58:05 +00:00
|
|
|
}
|
|
|
|
// Send signal to all kwin instances
|
|
|
|
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"),
|
|
|
|
QStringLiteral("org.kde.KWin"),
|
|
|
|
QStringLiteral("reloadConfig"));
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
|
|
|
};
|
2020-05-06 13:15:03 +00:00
|
|
|
connect(dialog, &QDialog::accepted, this, save);
|
2014-12-05 12:44:16 +00:00
|
|
|
|
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok |
|
|
|
|
QDialogButtonBox::Cancel |
|
|
|
|
QDialogButtonBox::RestoreDefaults |
|
|
|
|
QDialogButtonBox::Reset,
|
2020-05-06 13:15:03 +00:00
|
|
|
dialog);
|
2014-12-05 12:44:16 +00:00
|
|
|
|
|
|
|
QPushButton *reset = buttons->button(QDialogButtonBox::Reset);
|
|
|
|
reset->setEnabled(false);
|
|
|
|
// Here we connect our buttons with the dialog
|
2020-05-06 13:15:03 +00:00
|
|
|
connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
|
2014-12-05 12:44:16 +00:00
|
|
|
connect(reset, &QPushButton::clicked, kcm, &KCModule::load);
|
|
|
|
auto changedSignal = static_cast<void(KCModule::*)(bool)>(&KCModule::changed);
|
|
|
|
connect(kcm, changedSignal, reset, &QPushButton::setEnabled);
|
|
|
|
connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, kcm, &KCModule::defaults);
|
|
|
|
|
2020-05-06 13:15:03 +00:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(dialog);
|
2014-12-05 12:44:16 +00:00
|
|
|
layout->addWidget(kcm);
|
|
|
|
layout->addWidget(buttons);
|
2020-05-06 13:15:03 +00:00
|
|
|
|
|
|
|
if (ctx->window()) {
|
|
|
|
dialog->winId(); // so it creates windowHandle
|
|
|
|
dialog->windowHandle()->setTransientParent(QQuickRenderControl::renderWindowFor(ctx->window()));
|
|
|
|
dialog->setModal(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog->show();
|
2014-12-05 12:44:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 12:22:05 +00:00
|
|
|
BridgeItem::BridgeItem(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_bridge(new PreviewBridge())
|
|
|
|
{
|
|
|
|
connect(m_bridge, &PreviewBridge::themeChanged, this, &BridgeItem::themeChanged);
|
|
|
|
connect(m_bridge, &PreviewBridge::pluginChanged, this, &BridgeItem::pluginChanged);
|
|
|
|
connect(m_bridge, &PreviewBridge::validChanged, this, &BridgeItem::validChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
BridgeItem::~BridgeItem()
|
|
|
|
{
|
|
|
|
m_bridge->deleteLater();
|
|
|
|
}
|
|
|
|
|
2014-10-31 06:53:04 +00:00
|
|
|
}
|
|
|
|
}
|