Commit 3f937101 authored by Benjamin Port's avatar Benjamin Port
Browse files

[KCM]Add KCModuleData

Summary: Use KCModuleData for:
- baloo
- colors
- cursors
- fontscursors
- launch
- lookandfeel
- spellchecking
- smserver
- splash
- style

Reviewers: #plasma, ervin, meven, crossi, hchain

Subscribers: broulik, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28462

Signed-off-by: Benjamin Port's avatarBenjamin Port <benjamin.port@enioka.com>

# Conflicts:
#	kcms/cursortheme/kcmcursortheme.cpp
parent 9aa7f986
......@@ -4,6 +4,7 @@ set(kcm_file_SRCS
kcm.cpp
fileexcludefilters.cpp
filteredfoldermodel.cpp
baloodata.cpp
)
add_library(kcm_baloofile MODULE ${kcm_file_SRCS})
......
/*
* Copyright (c) 2020 Benjamin Port <benjamin.port@enioka.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) 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 "baloodata.h"
#include <QVariantList>
#include <baloo/baloosettings.h>
using namespace Baloo;
BalooData::BalooData(QObject *parent, const QVariantList &args)
: KCModuleData(parent, args)
, m_settings(new BalooSettings(this))
{
autoRegisterSkeletons();
}
BalooSettings *BalooData::settings() const
{
return m_settings;
}
#include "baloodata.moc"
/*
* Copyright (c) 2020 Benjamin Port <benjamin.port@enioka.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) 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/>.
*/
#ifndef BALOODATA_H
#define BALOODATA_H
#include <QObject>
#include "kcmoduledata.h"
class BalooSettings;
class BalooData : public KCModuleData
{
Q_OBJECT
public:
explicit BalooData(QObject *parent = nullptr, const QVariantList &args = QVariantList());
BalooSettings *settings() const;
private:
BalooSettings *m_settings;
};
#endif
......@@ -36,15 +36,16 @@
#include <Baloo/IndexerConfig>
#include <baloo/baloosettings.h>
#include <baloodata.h>
K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_baloofile.json", registerPlugin<Baloo::ServerConfigModule>();)
K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_baloofile.json", registerPlugin<Baloo::ServerConfigModule>(); registerPlugin<BalooData>();)
using namespace Baloo;
ServerConfigModule::ServerConfigModule(QObject* parent, const QVariantList& args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_settings(new BalooSettings(this))
, m_filteredFolderModel(new FilteredFolderModel(m_settings, this))
, m_data(new BalooData(this))
, m_filteredFolderModel(new FilteredFolderModel(m_data->settings(), this))
{
qmlRegisterType<FilteredFolderModel>();
qmlRegisterType<BalooSettings>();
......@@ -61,8 +62,8 @@ ServerConfigModule::ServerConfigModule(QObject* parent, const QVariantList& args
setAboutData(about);
setButtons(Help | Apply | Default);
connect(m_settings, &BalooSettings::excludedFoldersChanged, m_filteredFolderModel, &FilteredFolderModel::updateDirectoryList);
connect(m_settings, &BalooSettings::foldersChanged, m_filteredFolderModel, &FilteredFolderModel::updateDirectoryList);
connect(balooSettings(), &BalooSettings::excludedFoldersChanged, m_filteredFolderModel, &FilteredFolderModel::updateDirectoryList);
connect(balooSettings(), &BalooSettings::foldersChanged, m_filteredFolderModel, &FilteredFolderModel::updateDirectoryList);
m_filteredFolderModel->updateDirectoryList();
}
......@@ -80,7 +81,7 @@ void ServerConfigModule::save()
ManagedConfigModule::save();
// Update Baloo config or start Baloo
if (m_settings->indexingEnabled()) {
if (balooSettings()->indexingEnabled()) {
// Update the baloo_file's config cache - if it not yet running,
// the DBus call goes nowhere
Baloo::IndexerConfig config;
......@@ -109,7 +110,7 @@ FilteredFolderModel *ServerConfigModule::filteredModel() const
BalooSettings *ServerConfigModule::balooSettings() const
{
return m_settings;
return m_data->settings();
}
#include "kcm.moc"
......@@ -26,6 +26,7 @@
#include "filteredfoldermodel.h"
class BalooSettings;
class BalooData;
namespace Baloo
{
......@@ -48,7 +49,7 @@ public Q_SLOTS:
void save() override;
private:
BalooSettings *m_settings;
BalooData *m_data;
FilteredFolderModel *m_filteredFolderModel;
};
}
......
......@@ -4,6 +4,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kcm_colors\")
set(kcm_colors_SRCS
../krdb/krdb.cpp
colors.cpp
colorsdata.cpp
colorsmodel.cpp
filterproxymodel.cpp
)
......
......@@ -59,14 +59,15 @@
#include "colorsmodel.h"
#include "filterproxymodel.h"
#include "colorssettings.h"
#include "colorsdata.h"
K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_colors.json", registerPlugin<KCMColors>();)
K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_colors.json", registerPlugin<KCMColors>();registerPlugin<ColorsData>();)
KCMColors::KCMColors(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_model(new ColorsModel(this))
, m_filteredModel(new FilterProxyModel(this))
, m_settings(new ColorsSettings(this))
, m_data(new ColorsData(this))
, m_config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")))
{
qmlRegisterUncreatableType<KCMColors>("org.kde.private.kcms.colors", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM"));
......@@ -83,11 +84,11 @@ KCMColors::KCMColors(QObject *parent, const QVariantList &args)
connect(m_model, &ColorsModel::selectedSchemeChanged, this, [this](const QString &scheme) {
m_selectedSchemeDirty = true;
m_settings->setColorScheme(scheme);
colorsSettings()->setColorScheme(scheme);
});
connect(m_settings, &ColorsSettings::colorSchemeChanged, this, [this] {
m_model->setSelectedScheme(m_settings->colorScheme());
connect(colorsSettings(), &ColorsSettings::colorSchemeChanged, this, [this] {
m_model->setSelectedScheme(colorsSettings()->colorScheme());
});
connect(m_model, &ColorsModel::selectedSchemeChanged, m_filteredModel, &FilterProxyModel::setSelectedScheme);
......@@ -111,7 +112,7 @@ FilterProxyModel *KCMColors::filteredModel() const
ColorsSettings *KCMColors::colorsSettings() const
{
return m_settings;
return m_data->settings();
}
bool KCMColors::downloadingFile() const
......@@ -271,7 +272,7 @@ void KCMColors::editScheme(const QString &schemeName, QQuickItem *ctx)
m_model->load(); // would be cool to just reload/add the changed/new ones
// If the currently active scheme was edited, consider settings dirty even if the scheme itself didn't change
if (savedThemes.contains(m_settings->colorScheme())) {
if (savedThemes.contains(colorsSettings()->colorScheme())) {
m_activeSchemeEdited = true;
settingsChanged();
}
......@@ -319,14 +320,14 @@ void KCMColors::load()
m_config->markAsClean();
m_config->reparseConfiguration();
const QString schemeName = m_settings->colorScheme();
const QString schemeName = colorsSettings()->colorScheme();
// If the scheme named in kdeglobals doesn't exist, show a warning and use default scheme
if (m_model->indexOfScheme(schemeName) == -1) {
m_model->setSelectedScheme(m_settings->defaultColorSchemeValue());
m_model->setSelectedScheme(colorsSettings()->defaultColorSchemeValue());
// These are normally synced but initially the model doesn't emit a change to avoid the
// Apply button from being enabled without any user interaction. Sync manually here.
m_filteredModel->setSelectedScheme(m_settings->defaultColorSchemeValue());
m_filteredModel->setSelectedScheme(colorsSettings()->defaultColorSchemeValue());
emit showSchemeNotInstalledWarning(schemeName);
} else {
m_model->setSelectedScheme(schemeName);
......
......@@ -41,6 +41,7 @@ class FileCopyJob;
class ColorsModel;
class FilterProxyModel;
class ColorsSettings;
class ColorsData;
class KCMColors : public KQuickAddons::ManagedConfigModule
{
......@@ -94,7 +95,7 @@ private:
ColorsModel *m_model;
FilterProxyModel *m_filteredModel;
ColorsSettings *m_settings;
ColorsData *m_data;
bool m_selectedSchemeDirty = false;
bool m_activeSchemeEdited = false;
......
/*
* Copyright (c) 2020 Benjamin Port <benjamin.port@enioka.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) 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 "colorsdata.h"
#include <QVariantList>
#include "colorssettings.h"
ColorsData::ColorsData(QObject *parent, const QVariantList &args)
: KCModuleData(parent, args)
, m_settings(new ColorsSettings(this))
{
autoRegisterSkeletons();
}
ColorsSettings *ColorsData::settings() const
{
return m_settings;
}
#include "colorsdata.moc"
/*
* Copyright (c) 2020 Benjamin Port <benjamin.port@enioka.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) 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/>.
*/
#ifndef COLORSDATA_H
#define COLORSDATA_H
#include <QObject>
#include "kcmoduledata.h"
class ColorsSettings;
class ColorsData : public KCModuleData
{
Q_OBJECT
public:
explicit ColorsData(QObject *parent = nullptr, const QVariantList &args = QVariantList());
ColorsSettings *settings() const;
private:
ColorsSettings *m_settings;
};
#endif
......@@ -15,7 +15,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/xcursor/ )
########### next target ###############
set(kcm_cursortheme_PART_SRCS kcmcursortheme.cpp ${libnoinst_SRCS})
set(kcm_cursortheme_PART_SRCS kcmcursortheme.cpp cursorthemedata.cpp ${libnoinst_SRCS})
kconfig_add_kcfg_files(kcm_cursortheme_PART_SRCS cursorthemesettings.kcfgc GENERATE_MOC)
add_library(kcm_cursortheme MODULE ${kcm_cursortheme_PART_SRCS})
......
/*
* Copyright (c) 2020 Benjamin Port <benjamin.port@enioka.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) 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 "cursorthemedata.h"
#include <QVariantList>
#include "cursorthemesettings.h"
CursorThemeData::CursorThemeData(QObject *parent, const QVariantList &args)
: KCModuleData(parent, args)
, m_settings(new CursorThemeSettings(this))
{
autoRegisterSkeletons();
}
CursorThemeSettings *CursorThemeData::settings() const
{
return m_settings;
}
#include "cursorthemedata.moc"
/*
* Copyright (c) 2020 Benjamin Port <benjamin.port@enioka.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) 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/>.
*/
#ifndef CURSORTHEMEDATA_H
#define CURSORTHEMEDATA_H
#include <QObject>
#include "kcmoduledata.h"
class CursorThemeSettings;
class CursorThemeData : public KCModuleData
{
Q_OBJECT
public:
explicit CursorThemeData(QObject *parent = nullptr, const QVariantList &args = QVariantList());
CursorThemeSettings *settings() const;
private:
CursorThemeSettings *m_settings;
};
#endif
......@@ -20,6 +20,7 @@
#include <config-X11.h>
#include "kcmcursortheme.h"
#include "cursorthemedata.h"
#include "xcursor/thememodel.h"
#include "xcursor/sortproxymodel.h"
......@@ -59,17 +60,17 @@
# include <X11/extensions/Xfixes.h>
#endif
K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin<CursorThemeConfig>();)
K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin<CursorThemeConfig>();registerPlugin<CursorThemeData>();)
CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args),
m_settings(new CursorThemeSettings(this)),
m_data(new CursorThemeData(this)),
m_canInstall(true),
m_canResize(true),
m_canConfigure(true)
{
m_preferredSize = m_settings->cursorSize();
connect(m_settings, &CursorThemeSettings::cursorThemeChanged, this, &CursorThemeConfig::updateSizeComboBox);
m_preferredSize = cursorThemeSettings()->cursorSize();
connect(cursorThemeSettings(), &CursorThemeSettings::cursorThemeChanged, this, &CursorThemeConfig::updateSizeComboBox);
qmlRegisterType<PreviewWidget>("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget");
qmlRegisterType<SortProxyModel>();
qmlRegisterType<CursorThemeSettings>();
......@@ -111,7 +112,7 @@ CursorThemeConfig::~CursorThemeConfig()
CursorThemeSettings *CursorThemeConfig::cursorThemeSettings() const
{
return m_settings;
return m_data->settings();
}
void CursorThemeConfig::setCanInstall(bool can)
......@@ -204,7 +205,7 @@ void CursorThemeConfig::updateSizeComboBox()
m_sizesModel->clear();
// refill the combo box and adopt its icon size
int row = cursorThemeIndex(m_settings->cursorTheme());
int row = cursorThemeIndex(cursorThemeSettings()->cursorTheme());
QModelIndex selected = m_themeProxyModel->index(row, 0);
int maxIconWidth = 0;
int maxIconHeight = 0;
......@@ -268,18 +269,18 @@ void CursorThemeConfig::updateSizeComboBox()
}
}
}
m_settings->setCursorSize(size);
cursorThemeSettings()->setCursorSize(size);
}
}
// enable or disable the combobox
if (m_settings->isImmutable("cursorSize")) {
if (cursorThemeSettings()->isImmutable("cursorSize")) {
setCanResize(false);
} else {
setCanResize(m_sizesModel->rowCount() > 0);
}
// We need to emit a cursorSizeChanged in all case to refresh UI
emit m_settings->cursorSizeChanged();
emit cursorThemeSettings()->cursorSizeChanged();
}
bool CursorThemeConfig::applyTheme(const CursorTheme *theme, const int size)
......@@ -367,13 +368,13 @@ QString CursorThemeConfig::cursorThemeFromIndex(int index) const
void CursorThemeConfig::save()
{
ManagedConfigModule::save();
setPreferredSize(m_settings->cursorSize());
setPreferredSize(cursorThemeSettings()->cursorSize());
int row = cursorThemeIndex(m_settings->cursorTheme());
int row = cursorThemeIndex(cursorThemeSettings()->cursorTheme());
QModelIndex selected = m_themeProxyModel->index(row, 0);
const CursorTheme *theme = selected.isValid() ? m_themeProxyModel->theme(selected) : nullptr;
if (!applyTheme(theme, m_settings->cursorSize())) {
if (!applyTheme(theme, cursorThemeSettings()->cursorSize())) {
emit showInfoMessage(i18n("You have to restart the Plasma session for these changes to take effect."));
}
removeThemes();
......@@ -385,12 +386,12 @@ void CursorThemeConfig::save()
void CursorThemeConfig::load()
{
ManagedConfigModule::load();
setPreferredSize(m_settings->cursorSize());
setPreferredSize(cursorThemeSettings()->cursorSize());
// Get the name of the theme KDE is configured to use
QString currentTheme = m_settings->cursorTheme();
QString currentTheme = cursorThemeSettings()->cursorTheme();
// Disable the listview and the buttons if we're in kiosk mode
if (m_settings->isImmutable( QStringLiteral( "cursorTheme" ))) {
if (cursorThemeSettings()->isImmutable( QStringLiteral( "cursorTheme" ))) {
setCanConfigure(false);
setCanInstall(false);
}
......@@ -404,7 +405,7 @@ void CursorThemeConfig::load()
void CursorThemeConfig::defaults()
{
ManagedConfigModule::defaults();
m_preferredSize = m_settings->cursorSize();
m_preferredSize = cursorThemeSettings()->cursorSize();
}
bool CursorThemeConfig::isSaveNeeded() const
......
......@@ -31,6 +31,7 @@ class CursorThemeModel;
class SortProxyModel;
class CursorTheme;
class CursorThemeSettings;
class CursorThemeData;
namespace KIO
{
......@@ -126,7 +127,7 @@ private:
CursorThemeModel *m_themeModel;
SortProxyModel *m_themeProxyModel;
QStandardItemModel *m_sizesModel;
CursorThemeSettings *m_settings;
CursorThemeData *m_data;
/** Holds the last size that was chosen by the user. Example: The user chooses
theme1 which provides the sizes 24 and 36. He chooses 36. preferredSize gets
......
......@@ -10,7 +10,7 @@ include_directories(${FREETYPE_INCLUDE_DIRS})
include_directories(../kfontinst/lib)
set(kcm_fonts_PART_SRCS ../krdb/krdb.cpp previewrenderengine.cpp previewimageprovider.cpp fonts.cpp fontsaasettings.cpp ../kfontinst/lib/FcEngine.cpp)
set(kcm_fonts_PART_SRCS ../krdb/krdb.cpp previewrenderengine.cpp previewimageprovider.cpp fonts.cpp fontsaasettings.cpp fontsdata.cpp ../kfontinst/lib/FcEngine.cpp)
if(X11_FOUND)
set(kcm_fonts_PART_SRCS ${kcm_fonts_PART_SRCS} ${libkxftconfig_SRCS})
......
......@@ -51,15 +51,16 @@
#include "fontssettings.h"
#include "fontsaasettings.h"
#include "fontsdata.h"
/**** DLL Interface ****/
K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin<KFonts>();)
K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin<KFonts>();registerPlugin<FontsData>();)
/**** KFonts ****/
KFonts::KFonts(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_settings(new FontsSettings(this))
, m_settingsAA(new FontsAASettings(this))
, m_data(new FontsData(this))
, m_subPixelOptionsModel(new QStandardItemModel(this))
, m_hintingOptionsModel(new QStandardItemModel(this))
{
......@@ -82,8 +83,8 @@ KFonts::KFonts(QObject *parent, const QVariantList &args)
auto item = new QStandardItem(KXftConfig::description(s));
m_hintingOptionsModel->appendRow(item);
}
connect(m_settingsAA, &FontsAASettings::hintingChanged, this, &KFonts::hintingCurrentIndexChanged);
connect(m_settingsAA, &FontsAASettings::subPixelChanged, this, &KFonts::subPixelCurrentIndexChanged);
connect(fontsAASettings(), &FontsAASettings::hintingChanged, this, &KFonts::hintingCurrentIndexChanged);
connect(fontsAASettings(), &FontsAASettings::subPixelChanged, this, &KFonts::subPixelCurrentIndexChanged);
}
KFonts::~KFonts()
......@@ -92,12 +93,12 @@ KFonts::~KFonts()
FontsSettings *KFonts::fontsSettings() const
{
return m_settings;
return m_data->settings();
}
FontsAASettings *KFonts::fontsAASettings() const
{
return m_settingsAA;
</