From 7546af6b4cdc333dff5eb429aa3ad05947bf2bd7 Mon Sep 17 00:00:00 2001 From: Benjamin Port Date: Wed, 30 Sep 2020 14:24:02 +0200 Subject: [PATCH] KCM KWin Decoration: Add module data depends on https://invent.kde.org/frameworks/kcmutils/-/merge_requests/19 --- CMakeLists.txt | 1 + kcmkwin/kwindecoration/CMakeLists.txt | 9 ++++++ kcmkwin/kwindecoration/kcm.cpp | 41 ++++++++++++++------------- kcmkwin/kwindecoration/kcm.h | 3 +- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d07858987..362756268c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -414,6 +414,7 @@ include_directories(BEFORE add_subdirectory(libkwineffects) if (KWIN_BUILD_KCMS) + include(KCMUtilsGenerateModuleData) add_subdirectory(kcmkwin) endif() diff --git a/kcmkwin/kwindecoration/CMakeLists.txt b/kcmkwin/kwindecoration/CMakeLists.txt index 5be0504848..0012230082 100644 --- a/kcmkwin/kwindecoration/CMakeLists.txt +++ b/kcmkwin/kwindecoration/CMakeLists.txt @@ -10,6 +10,14 @@ set(kcmkwindecoration_SRCS utils.cpp ) +kcmutils_generate_module_data( + kcmkwindecoration_SRCS + MODULE_DATA_HEADER kwindecorationdata.h + MODULE_DATA_CLASS_NAME KWinDecorationData + SETTINGS_HEADERS kwindecorationsettings.h + SETTINGS_CLASSES KWinDecorationSettings +) + kconfig_add_kcfg_files(kcmkwindecoration_SRCS kwindecorationsettings.kcfgc GENERATE_MOC) add_library(kcm_kwindecoration MODULE ${kcmkwindecoration_SRCS}) @@ -17,6 +25,7 @@ add_library(kcm_kwindecoration MODULE ${kcmkwindecoration_SRCS}) target_link_libraries(kcm_kwindecoration KDecoration2::KDecoration KF5::I18n + KF5::KCMUtils KF5::NewStuff KF5::QuickAddons Qt5::Quick diff --git a/kcmkwin/kwindecoration/kcm.cpp b/kcmkwin/kwindecoration/kcm.cpp index 5d4ca7cb85..0b4de6da68 100644 --- a/kcmkwin/kwindecoration/kcm.cpp +++ b/kcmkwin/kwindecoration/kcm.cpp @@ -25,9 +25,10 @@ #include +#include "kwindecorationdata.h" #include "kwindecorationsettings.h" -K_PLUGIN_FACTORY_WITH_JSON(KCMKWinDecorationFactory, "kwindecoration.json", registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(KCMKWinDecorationFactory, "kwindecoration.json", registerPlugin();registerPlugin();) Q_DECLARE_METATYPE(KDecoration2::BorderSize) @@ -44,7 +45,7 @@ KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &argume , m_leftButtonsModel(new KDecoration2::Preview::ButtonsModel(DecorationButtonsList(), this)) , m_rightButtonsModel(new KDecoration2::Preview::ButtonsModel(DecorationButtonsList(), this)) , m_availableButtonsModel(new KDecoration2::Preview::ButtonsModel(this)) - , m_settings(new KWinDecorationSettings(this)) + , m_data(new KWinDecorationData(this)) { auto about = new KAboutData(QStringLiteral("kcm_kwindecoration"), i18n("Window Decorations"), @@ -64,8 +65,8 @@ KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &argume m_proxyThemesModel->setSortCaseSensitivity(Qt::CaseInsensitive); m_proxyThemesModel->sort(0); - connect(m_settings, &KWinDecorationSettings::themeChanged, this, &KCMKWinDecoration::themeChanged); - connect(m_settings, &KWinDecorationSettings::borderSizeChanged, this, &KCMKWinDecoration::borderSizeChanged); + connect(m_data->settings(), &KWinDecorationSettings::themeChanged, this, &KCMKWinDecoration::themeChanged); + connect(m_data->settings(), &KWinDecorationSettings::borderSizeChanged, this, &KCMKWinDecoration::borderSizeChanged); connect(m_leftButtonsModel, &QAbstractItemModel::rowsInserted, this, &KCMKWinDecoration::onLeftButtonsChanged); connect(m_leftButtonsModel, &QAbstractItemModel::rowsMoved, this, &KCMKWinDecoration::onLeftButtonsChanged); @@ -89,7 +90,7 @@ KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &argume KWinDecorationSettings *KCMKWinDecoration::settings() const { - return m_settings; + return m_data->settings(); } void KCMKWinDecoration::reloadKWinSettings() @@ -120,20 +121,20 @@ void KCMKWinDecoration::load() { ManagedConfigModule::load(); - m_leftButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnLeft())); - m_rightButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnRight())); + m_leftButtonsModel->replace(Utils::buttonsFromString(settings()->buttonsOnLeft())); + m_rightButtonsModel->replace(Utils::buttonsFromString(settings()->buttonsOnRight())); - setBorderSize(borderSizeIndexFromString(m_settings->borderSize())); + setBorderSize(borderSizeIndexFromString(settings()->borderSize())); emit themeChanged(); } void KCMKWinDecoration::save() { - if (!m_settings->borderSizeAuto()) { - m_settings->setBorderSize(borderSizeIndexToString(m_borderSizeIndex)); + if (!settings()->borderSizeAuto()) { + settings()->setBorderSize(borderSizeIndexToString(m_borderSizeIndex)); } else { - m_settings->setBorderSize(m_settings->defaultBorderSizeValue()); + settings()->setBorderSize(settings()->defaultBorderSizeValue()); } ManagedConfigModule::save(); @@ -151,18 +152,18 @@ void KCMKWinDecoration::defaults() setBorderSize(recommendedBorderSize()); - m_leftButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnLeft())); - m_rightButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnRight())); + m_leftButtonsModel->replace(Utils::buttonsFromString(settings()->buttonsOnLeft())); + m_rightButtonsModel->replace(Utils::buttonsFromString(settings()->buttonsOnRight())); } void KCMKWinDecoration::onLeftButtonsChanged() { - m_settings->setButtonsOnLeft(Utils::buttonsToString(m_leftButtonsModel->buttons())); + settings()->setButtonsOnLeft(Utils::buttonsToString(m_leftButtonsModel->buttons())); } void KCMKWinDecoration::onRightButtonsChanged() { - m_settings->setButtonsOnRight(Utils::buttonsToString(m_rightButtonsModel->buttons())); + settings()->setButtonsOnRight(Utils::buttonsToString(m_rightButtonsModel->buttons())); } QSortFilterProxyModel *KCMKWinDecoration::themesModel() const @@ -211,7 +212,7 @@ int KCMKWinDecoration::recommendedBorderSize() const int KCMKWinDecoration::theme() const { - return m_proxyThemesModel->mapFromSource(m_themesModel->findDecoration(m_settings->pluginName(), m_settings->theme())).row(); + return m_proxyThemesModel->mapFromSource(m_themesModel->findDecoration(settings()->pluginName(), settings()->theme())).row(); } void KCMKWinDecoration::setBorderSize(int index) @@ -224,22 +225,22 @@ void KCMKWinDecoration::setBorderSize(int index) void KCMKWinDecoration::setBorderSize(KDecoration2::BorderSize size) { - m_settings->setBorderSize(Utils::borderSizeToString(size)); + settings()->setBorderSize(Utils::borderSizeToString(size)); } void KCMKWinDecoration::setTheme(int index) { QModelIndex dataIndex = m_proxyThemesModel->index(index, 0); if (dataIndex.isValid()) { - m_settings->setTheme(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::ThemeNameRole).toString()); - m_settings->setPluginName(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::PluginNameRole).toString()); + settings()->setTheme(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::ThemeNameRole).toString()); + settings()->setPluginName(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::PluginNameRole).toString()); emit themeChanged(); } } bool KCMKWinDecoration::isSaveNeeded() const { - return !m_settings->borderSizeAuto() && borderSizeIndexFromString(m_settings->borderSize()) != m_borderSizeIndex; + return !settings()->borderSizeAuto() && borderSizeIndexFromString(settings()->borderSize()) != m_borderSizeIndex; } int KCMKWinDecoration::borderSizeIndexFromString(const QString &size) const diff --git a/kcmkwin/kwindecoration/kcm.h b/kcmkwin/kwindecoration/kcm.h index e3a99b8144..f5f1c3cdf4 100644 --- a/kcmkwin/kwindecoration/kcm.h +++ b/kcmkwin/kwindecoration/kcm.h @@ -36,6 +36,7 @@ class DecorationsModel; } class KWinDecorationSettings; +class KWinDecorationData; class KCMKWinDecoration : public KQuickAddons::ManagedConfigModule { @@ -100,5 +101,5 @@ private: QPointer m_newStuffDialog; int m_borderSizeIndex = -1; - KWinDecorationSettings *m_settings; + KWinDecorationData *m_data; };