aurorae: Fix build with KWIN_BUILD_KCMS=OFF

Moves the KCM into a separate file
This commit is contained in:
Aleix Pol 2023-05-12 18:26:06 +02:00
parent 52a96996f3
commit 7580f74d95
6 changed files with 209 additions and 143 deletions

View file

@ -25,12 +25,11 @@ target_compile_definitions(kwin5_aurorae PRIVATE
target_link_libraries(kwin5_aurorae
KDecoration2::KDecoration
kwineffects
KF6::KCMUtils
KF6::I18n
KF6::Package
KF6::WindowSystem
KF6::ConfigGui
Qt::Quick
Qt::UiTools
)
install(TARGETS kwin5_aurorae DESTINATION ${KDE_INSTALL_PLUGINDIR}/org.kde.kdecoration2)
@ -57,7 +56,22 @@ configure_file(aurorae.knsrc.cmake ${CMAKE_CURRENT_BINARY_DIR}/aurorae.knsrc)
########### install files ###############
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/aurorae.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR})
if (KWIN_BUILD_KCMS)
kwin_add_effect_config(kwin_aurorae_config auroraeconfig.cpp)
target_link_libraries(kwin_aurorae_config
KF6::ConfigGui
KF6::KCMUtils
KF6::I18n
KDecoration2::KDecoration
Qt::DBus
Qt::UiTools
Qt::Widgets
KWinEffectsInterface
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/aurorae.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR})
endif()
install(
FILES
qml/AppMenuButton.qml

View file

@ -8,6 +8,7 @@
#include "config-kwin.h"
#include "libkwineffects/kwineffects.h"
#include "auroraeshared.h"
#include "auroraetheme.h"
#include "libkwineffects/kwinoffscreenquickview.h"
// qml imports
@ -26,11 +27,9 @@
#include <KPluginFactory>
#include <KSharedConfig>
// Qt
#include <QComboBox>
#include <QDebug>
#include <QDirIterator>
#include <QGuiApplication>
#include <QLabel>
#include <QOffscreenSurface>
#include <QOpenGLContext>
#include <QOpenGLFramebufferObject>
@ -43,14 +42,11 @@
#include <QQuickWindow>
#include <QStandardPaths>
#include <QTimer>
#include <QUiLoader>
#include <QVBoxLayout>
K_PLUGIN_FACTORY_WITH_JSON(AuroraeDecoFactory,
"aurorae.json",
registerPlugin<Aurorae::Decoration>();
registerPlugin<Aurorae::ThemeProvider>();
registerPlugin<Aurorae::ConfigurationModule>();)
registerPlugin<Aurorae::ThemeProvider>();)
namespace Aurorae
{
@ -107,12 +103,6 @@ void Helper::unref()
static const QString s_defaultTheme = QStringLiteral("kwin4_decoration_qml_plastik");
static const QString s_qmlPackageFolder = QStringLiteral("kwin/decorations/");
/*
* KDecoration2::BorderSize doesn't map to the indices used for the Aurorae SVG Button Sizes.
* BorderSize defines None and NoSideBorder as index 0 and 1. These do not make sense for Button
* Size, thus we need to perform a mapping between the enum value and the config value.
*/
static const int s_indexMapper = 2;
QQmlComponent *Helper::component(const QString &themeName)
{
@ -228,19 +218,6 @@ void Helper::init()
qRegisterMetaType<KDecoration2::BorderSize>();
}
static QString findTheme(const QVariantList &args)
{
if (args.isEmpty()) {
return QString();
}
const auto map = args.first().toMap();
auto it = map.constFind(QStringLiteral("theme"));
if (it == map.constEnd()) {
return QString();
}
return it.value().toString();
}
Decoration::Decoration(QObject *parent, const QVariantList &args)
: KDecoration2::Decoration(parent, args)
, m_item(nullptr)
@ -693,104 +670,6 @@ bool ThemeProvider::hasConfiguration(const QString &theme)
QStringLiteral("kwin/decorations/%1/contents/config/main.xml").arg(theme));
return !(ui.isEmpty() || xml.isEmpty());
}
ConfigurationModule::ConfigurationModule(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: KCModule(parent, data, args)
, m_theme(findTheme(args))
, m_buttonSize(int(KDecoration2::BorderSize::Normal) - s_indexMapper)
{
init();
}
void ConfigurationModule::init()
{
if (m_theme.startsWith(QLatin1String("__aurorae__svg__"))) {
// load the generic setting module
initSvg();
} else {
initQml();
}
}
void ConfigurationModule::initSvg()
{
QWidget *form = new QWidget(widget());
form->setLayout(new QHBoxLayout(form));
QComboBox *sizes = new QComboBox(form);
sizes->addItem(i18nc("@item:inlistbox Button size:", "Tiny"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Normal"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Large"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Very Large"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Huge"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Very Huge"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Oversized"));
sizes->setObjectName(QStringLiteral("kcfg_ButtonSize"));
QLabel *label = new QLabel(i18n("Button size:"), form);
label->setBuddy(sizes);
form->layout()->addWidget(label);
form->layout()->addWidget(sizes);
widget()->layout()->addWidget(form);
KCoreConfigSkeleton *skel = new KCoreConfigSkeleton(KSharedConfig::openConfig(QStringLiteral("auroraerc")), this);
skel->setCurrentGroup(m_theme.mid(16));
skel->addItemInt(QStringLiteral("ButtonSize"),
m_buttonSize,
int(KDecoration2::BorderSize::Normal) - s_indexMapper,
QStringLiteral("ButtonSize"));
addConfig(skel, form);
}
void ConfigurationModule::initQml()
{
const QString packageRoot = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QLatin1String("kwin/decorations/") + m_theme,
QStandardPaths::LocateDirectory);
if (packageRoot.isEmpty()) {
return;
}
const KPluginMetaData metaData = KPluginMetaData::fromJsonFile(packageRoot + QLatin1String("/metadata.json"));
if (!metaData.isValid()) {
return;
}
const QString xml = packageRoot + QLatin1String("/contents/config/main.xml");
const QString ui = packageRoot + QLatin1String("/contents/ui/config.ui");
if (!QFileInfo::exists(xml) || !QFileInfo::exists(ui)) {
return;
}
KLocalizedTranslator *translator = new KLocalizedTranslator(this);
QCoreApplication::instance()->installTranslator(translator);
const QString translationDomain = metaData.value("X-KWin-Config-TranslationDomain");
if (!translationDomain.isEmpty()) {
translator->setTranslationDomain(translationDomain);
}
// load the KConfigSkeleton
QFile configFile(xml);
KSharedConfigPtr auroraeConfig = KSharedConfig::openConfig("auroraerc");
KConfigGroup configGroup = auroraeConfig->group(m_theme);
m_skeleton = new KConfigLoader(configGroup, &configFile, this);
// load the ui file
QUiLoader *loader = new QUiLoader(this);
loader->setLanguageChangeEnabled(true);
QFile uiFile(ui);
uiFile.open(QFile::ReadOnly);
QWidget *customConfigForm = loader->load(&uiFile, widget());
translator->addContextToMonitor(customConfigForm->objectName());
uiFile.close();
widget()->layout()->addWidget(customConfigForm);
// connect the ui file with the skeleton
addConfig(m_skeleton, customConfigForm);
// send a custom event to the translator to retranslate using our translator
QEvent le(QEvent::LanguageChange);
QCoreApplication::sendEvent(customConfigForm, &le);
}
}
#include "aurorae.moc"

View file

@ -6,7 +6,6 @@
#pragma once
#include <KCModule>
#include <KDecoration2/Decoration>
#include <KDecoration2/DecorationThemeProvider>
#include <KPluginMetaData>
@ -101,20 +100,4 @@ private:
QList<KDecoration2::DecorationThemeMetaData> m_themes;
const KPluginMetaData m_data;
};
class ConfigurationModule : public KCModule
{
Q_OBJECT
public:
ConfigurationModule(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
private:
void init();
void initSvg();
void initQml();
QString m_theme;
KConfigLoader *m_skeleton = nullptr;
int m_buttonSize;
};
}

View file

@ -0,0 +1,122 @@
/*
SPDX-FileCopyrightText: 2009, 2010, 2012 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "auroraeconfig.h"
#include "auroraeshared.h"
#include <KDecoration2/DecorationButton>
#include <KLocalizedString>
#include <KLocalizedTranslator>
#include <KPluginFactory>
#include <QComboBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QUiLoader>
K_PLUGIN_CLASS(Aurorae::ConfigurationModule)
namespace Aurorae
{
ConfigurationModule::ConfigurationModule(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: KCModule(parent, data, args)
, m_theme(findTheme(args))
, m_buttonSize(int(KDecoration2::BorderSize::Normal) - s_indexMapper)
{
init();
}
void ConfigurationModule::init()
{
if (m_theme.startsWith(QLatin1String("__aurorae__svg__"))) {
// load the generic setting module
initSvg();
} else {
initQml();
}
}
void ConfigurationModule::initSvg()
{
QWidget *form = new QWidget(widget());
form->setLayout(new QHBoxLayout(form));
QComboBox *sizes = new QComboBox(form);
sizes->addItem(i18nc("@item:inlistbox Button size:", "Tiny"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Normal"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Large"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Very Large"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Huge"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Very Huge"));
sizes->addItem(i18nc("@item:inlistbox Button size:", "Oversized"));
sizes->setObjectName(QStringLiteral("kcfg_ButtonSize"));
QLabel *label = new QLabel(i18n("Button size:"), form);
label->setBuddy(sizes);
form->layout()->addWidget(label);
form->layout()->addWidget(sizes);
widget()->layout()->addWidget(form);
KCoreConfigSkeleton *skel = new KCoreConfigSkeleton(KSharedConfig::openConfig(QStringLiteral("auroraerc")), this);
skel->setCurrentGroup(m_theme.mid(16));
skel->addItemInt(QStringLiteral("ButtonSize"),
m_buttonSize,
int(KDecoration2::BorderSize::Normal) - s_indexMapper,
QStringLiteral("ButtonSize"));
addConfig(skel, form);
}
void ConfigurationModule::initQml()
{
const QString packageRoot = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QLatin1String("kwin/decorations/") + m_theme,
QStandardPaths::LocateDirectory);
if (packageRoot.isEmpty()) {
return;
}
const KPluginMetaData metaData = KPluginMetaData::fromJsonFile(packageRoot + QLatin1String("/metadata.json"));
if (!metaData.isValid()) {
return;
}
const QString xml = packageRoot + QLatin1String("/contents/config/main.xml");
const QString ui = packageRoot + QLatin1String("/contents/ui/config.ui");
if (!QFileInfo::exists(xml) || !QFileInfo::exists(ui)) {
return;
}
KLocalizedTranslator *translator = new KLocalizedTranslator(this);
QCoreApplication::instance()->installTranslator(translator);
const QString translationDomain = metaData.value("X-KWin-Config-TranslationDomain");
if (!translationDomain.isEmpty()) {
translator->setTranslationDomain(translationDomain);
}
// load the KConfigSkeleton
QFile configFile(xml);
KSharedConfigPtr auroraeConfig = KSharedConfig::openConfig("auroraerc");
KConfigGroup configGroup = auroraeConfig->group(m_theme);
m_skeleton = new KConfigLoader(configGroup, &configFile, this);
// load the ui file
QUiLoader *loader = new QUiLoader(this);
loader->setLanguageChangeEnabled(true);
QFile uiFile(ui);
uiFile.open(QFile::ReadOnly);
QWidget *customConfigForm = loader->load(&uiFile, widget());
translator->addContextToMonitor(customConfigForm->objectName());
uiFile.close();
widget()->layout()->addWidget(customConfigForm);
// connect the ui file with the skeleton
addConfig(m_skeleton, customConfigForm);
// send a custom event to the translator to retranslate using our translator
QEvent le(QEvent::LanguageChange);
QCoreApplication::sendEvent(customConfigForm, &le);
}
}
#include "auroraeconfig.moc"

View file

@ -0,0 +1,33 @@
/*
SPDX-FileCopyrightText: 2009, 2010, 2012 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef AURORAECONFIG_H
#define AURORAECONFIG_H
#include <KCModule>
#include <KConfigLoader>
namespace Aurorae
{
class ConfigurationModule : public KCModule
{
Q_OBJECT
public:
ConfigurationModule(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
private:
void init();
void initSvg();
void initQml();
QString m_theme;
KConfigLoader *m_skeleton = nullptr;
int m_buttonSize;
};
}
#endif // AURORAECONFIG_H

View file

@ -0,0 +1,35 @@
/*
SPDX-FileCopyrightText: 2009, 2010, 2012 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QString>
#include <QVariantList>
namespace Aurorae
{
/*
* KDecoration2::BorderSize doesn't map to the indices used for the Aurorae SVG Button Sizes.
* BorderSize defines None and NoSideBorder as index 0 and 1. These do not make sense for Button
* Size, thus we need to perform a mapping between the enum value and the config value.
*/
static const int s_indexMapper = 2;
static QString findTheme(const QVariantList &args)
{
if (args.isEmpty()) {
return QString();
}
const auto map = args.first().toMap();
auto it = map.constFind(QStringLiteral("theme"));
if (it == map.constEnd()) {
return QString();
}
return it.value().toString();
}
}