Commit 0be05533 authored by Benjamin Port's avatar Benjamin Port Committed by Benjamin Port
Browse files

[KCM] Use KCModuleData in order to allow settings loading without UI

- desktop theme
- icons
parent 22c636ab
......@@ -3,6 +3,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kcm_desktoptheme\")
set(kcm_desktoptheme_SRCS
kcm.cpp
desktopthemedata.cpp
themesmodel.cpp
filterproxymodel.cpp
)
......
/*
* 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 "desktopthemedata.h"
#include <QVariantList>
#include "desktopthemesettings.h"
DesktopThemeData::DesktopThemeData(QObject *parent, const QVariantList &args)
: KCModuleData(parent, args)
, m_settings(new DesktopThemeSettings(this))
{
autoRegisterSkeletons();
}
DesktopThemeSettings *DesktopThemeData::settings() const
{
return m_settings;
}
#include "desktopthemedata.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 DESKTOPTHEMEDATA_H
#define DESKTOPTHEMEDATA_H
#include <QObject>
#include "kcmoduledata.h"
class DesktopThemeSettings;
class DesktopThemeData : public KCModuleData
{
Q_OBJECT
public:
explicit DesktopThemeData(QObject *parent = nullptr, const QVariantList &args = QVariantList());
DesktopThemeSettings *settings() const;
private:
DesktopThemeSettings *m_settings;
};
#endif
......@@ -41,16 +41,17 @@
#include <QTemporaryFile>
#include "desktopthemesettings.h"
#include "desktopthemedata.h"
#include "filterproxymodel.h"
#include "themesmodel.h"
Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME, "kcm_desktoptheme")
K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin<KCMDesktopTheme>();)
K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin<KCMDesktopTheme>();registerPlugin<DesktopThemeData>();)
KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_settings(new DesktopThemeSettings(this))
, m_data(new DesktopThemeData(this))
, m_model(new ThemesModel(this))
, m_filteredModel(new FilterProxyModel(this))
, m_haveThemeExplorerInstalled(false)
......@@ -70,11 +71,11 @@ KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args)
connect(m_model, &ThemesModel::pendingDeletionsChanged, this, &KCMDesktopTheme::settingsChanged);
connect(m_model, &ThemesModel::selectedThemeChanged, this, [this](const QString &pluginName) {
m_settings->setName(pluginName);
desktopThemeSettings()->setName(pluginName);
});
connect(m_settings, &DesktopThemeSettings::nameChanged, this, [this] {
m_model->setSelectedTheme(m_settings->name());
connect(desktopThemeSettings(), &DesktopThemeSettings::nameChanged, this, [this] {
m_model->setSelectedTheme(desktopThemeSettings()->name());
});
connect(m_model, &ThemesModel::selectedThemeChanged, m_filteredModel, &FilterProxyModel::setSelectedTheme);
......@@ -88,7 +89,7 @@ KCMDesktopTheme::~KCMDesktopTheme()
DesktopThemeSettings *KCMDesktopTheme::desktopThemeSettings() const
{
return m_settings;
return m_data->settings();
}
ThemesModel *KCMDesktopTheme::desktopThemeModel() const
......@@ -193,13 +194,13 @@ void KCMDesktopTheme::load()
{
ManagedConfigModule::load();
m_model->load();
m_model->setSelectedTheme(m_settings->name());
m_model->setSelectedTheme(desktopThemeSettings()->name());
}
void KCMDesktopTheme::save()
{
ManagedConfigModule::save();
Plasma::Theme().setThemeName(m_settings->name());
Plasma::Theme().setThemeName(desktopThemeSettings()->name());
processPendingDeletions();
}
......@@ -245,7 +246,7 @@ void KCMDesktopTheme::processPendingDeletions()
const QString pluginName = idx.data(ThemesModel::PluginNameRole).toString();
const QString displayName = idx.data(Qt::DisplayRole).toString();
Q_ASSERT(pluginName != m_settings->name());
Q_ASSERT(pluginName != desktopThemeSettings()->name());
const QStringList arguments = {QStringLiteral("-t"), QStringLiteral("theme"), QStringLiteral("-r"), pluginName};
......
......@@ -38,6 +38,7 @@ class FileCopyJob;
class QQuickItem;
class DesktopThemeSettings;
class DesktopThemeData;
class FilterProxyModel;
class ThemesModel;
......@@ -88,7 +89,7 @@ private:
void installTheme(const QString &path);
DesktopThemeSettings *m_settings;
DesktopThemeData *m_data;
ThemesModel *m_model;
FilterProxyModel *m_filteredModel;
......
......@@ -2,7 +2,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kcm5_icons\")
########### next target ###############
set(kcm_icons_PART_SRCS main.cpp iconsmodel.cpp iconsizecategorymodel.cpp iconssettings.cpp)
set(kcm_icons_PART_SRCS main.cpp iconsmodel.cpp iconsizecategorymodel.cpp iconssettings.cpp iconsdata.cpp)
kconfig_add_kcfg_files(kcm_icons_PART_SRCS iconssettingsbase.kcfgc GENERATE_MOC)
add_library(kcm_icons MODULE ${kcm_icons_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 "iconsdata.h"
#include <QVariantList>
#include "iconssettings.h"
IconsData::IconsData(QObject *parent, const QVariantList &args)
: KCModuleData(parent, args)
, m_settings(new IconsSettings(this))
{
autoRegisterSkeletons();
}
IconsSettings *IconsData::settings() const
{
return m_settings;
}
#include "iconsdata.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 ICONSDATA_H
#define ICONSDATA_H
#include <QObject>
#include "kcmoduledata.h"
class IconsSettings;
class IconsData : public KCModuleData
{
Q_OBJECT
public:
explicit IconsData(QObject *parent = nullptr, const QVariantList &args = QVariantList());
IconsSettings *settings() const;
private:
IconsSettings *m_settings;
};
#endif
......@@ -57,17 +57,18 @@
#include <unistd.h> // for unlink
#include "iconssettings.h"
#include "iconsdata.h"
#include "iconsmodel.h"
#include "iconsizecategorymodel.h"
#include "config.h" // for CMAKE_INSTALL_FULL_LIBEXECDIR
K_PLUGIN_FACTORY_WITH_JSON(IconsFactory, "kcm_icons.json", registerPlugin<IconModule>();)
K_PLUGIN_FACTORY_WITH_JSON(IconsFactory, "kcm_icons.json", registerPlugin<IconModule>();registerPlugin<IconsData>();)
IconModule::IconModule(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_settings(new IconsSettings(this))
, m_model(new IconsModel(m_settings, this))
, m_data(new IconsData(this))
, m_model(new IconsModel(m_data->settings(), this))
, m_iconSizeCategoryModel(new IconSizeCategoryModel(this))
{
qmlRegisterType<IconsSettings>();
......@@ -101,7 +102,7 @@ IconModule::~IconModule()
IconsSettings *IconModule::iconsSettings() const
{
return m_settings;
return m_data->settings();
}
IconsModel *IconModule::iconsModel() const
......@@ -121,8 +122,8 @@ bool IconModule::downloadingFile() const
QList<int> IconModule::availableIconSizes(int group) const
{
const auto themeName = m_settings->theme();
if (!m_kiconThemeCache.contains(m_settings->theme())) {
const auto themeName = iconsSettings()->theme();
if (!m_kiconThemeCache.contains(iconsSettings()->theme())) {
m_kiconThemeCache.insert(themeName, new KIconTheme(themeName));
}
return m_kiconThemeCache[themeName]->querySizes(static_cast<KIconLoader::Group>(group));
......@@ -133,19 +134,19 @@ void IconModule::load()
ManagedConfigModule::load();
m_model->load();
// Model has been cleared so pretend the theme name changed to force view update
emit m_settings->ThemeChanged();
emit iconsSettings()->ThemeChanged();
}
void IconModule::save()
{
bool needToExportToKDE4 = m_settings->isSaveNeeded();
bool needToExportToKDE4 = iconsSettings()->isSaveNeeded();
// keep track of Group of icons size that has changed
QList<int> notifyList;
for (int i = 0; i < m_iconSizeCategoryModel->rowCount(); ++i) {
const QModelIndex index = m_iconSizeCategoryModel->index(i, 0);
const QString key = index.data(IconSizeCategoryModel::ConfigKeyRole).toString();
if (m_settings->findItem(key)->isSaveNeeded()) {
if (iconsSettings()->findItem(key)->isSaveNeeded()) {
notifyList << index.data(IconSizeCategoryModel::KIconLoaderGroupRole).toInt();
}
}
......@@ -174,7 +175,7 @@ void IconModule::processPendingDeletions()
const QStringList pendingDeletions = m_model->pendingDeletions();
for (const QString &themeName : pendingDeletions) {
Q_ASSERT(themeName != m_settings->theme());
Q_ASSERT(themeName != iconsSettings()->theme());
KIconTheme theme(themeName);
auto *job = KIO::del(QUrl::fromLocalFile(theme.dir()), KIO::HideProgressInfo);
......@@ -266,7 +267,7 @@ void IconModule::exportToKDE4()
KConfig kde4config(configFilePath, KConfig::SimpleConfig);
KConfigGroup kde4IconGroup(&kde4config, "Icons");
kde4IconGroup.writeEntry("Theme", m_settings->theme());
kde4IconGroup.writeEntry("Theme", iconsSettings()->theme());
//Synchronize icon effects
for (int row = 0; row < m_iconSizeCategoryModel->rowCount(); row++) {
......
......@@ -33,6 +33,7 @@
class KIconTheme;
class IconsSettings;
class IconsData;
class QQuickItem;
class QTemporaryFile;
......@@ -105,7 +106,7 @@ private:
static QPixmap getBestIcon(KIconTheme &theme, const QStringList &iconNames, int size, qreal dpr);
IconsSettings *m_settings;
IconsData *m_data;
IconsModel *m_model;
IconSizeCategoryModel *m_iconSizeCategoryModel;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment