Commit 613d5e12 authored by Cyril Rossi's avatar Cyril Rossi
Browse files

KCM LookAndFeel : port to KConfig XT

Reviewers: #plasma, ervin, mart, bport, davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25274
parent 56140163
......@@ -15,6 +15,8 @@ set(kcm_lookandfeel_SRCS
set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml)
qt5_add_dbus_interface(kcm_lookandfeel_SRCS ${klauncher_xml} klauncher_iface)
kconfig_add_kcfg_files(kcm_lookandfeel_SRCS lookandfeelsettings.kcfgc GENERATE_MOC)
add_library(kcm_lookandfeel MODULE ${kcm_lookandfeel_SRCS})
target_link_libraries(kcm_lookandfeel
......@@ -48,6 +50,7 @@ endif ()
kcoreaddons_desktop_to_json(kcm_lookandfeel "kcm_lookandfeel.desktop" SERVICE_TYPES kcmodule.desktop)
#this desktop file is installed only for retrocompatibility with sycoca
install(FILES lookandfeelsettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(FILES kcm_lookandfeel.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS kcm_lookandfeel DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms)
install(FILES lookandfeel.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR})
......@@ -72,6 +75,8 @@ set(lookandfeeltool_SRCS
qt5_add_dbus_interface(lookandfeeltool_SRCS ${klauncher_xml} klauncher_iface)
kconfig_add_kcfg_files(lookandfeeltool_SRCS lookandfeelsettings.kcfgc GENERATE_MOC)
add_executable(lookandfeeltool ${lookandfeeltool_SRCS})
target_link_libraries(lookandfeeltool
......
......@@ -13,6 +13,8 @@ set( kcmTest_SRCS
set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml)
qt5_add_dbus_interface(kcmTest_SRCS ${klauncher_xml} klauncher_iface)
kconfig_add_kcfg_files(kcmTest_SRCS ../lookandfeelsettings.kcfgc GENERATE_MOC)
add_executable(kcmTest ${kcmTest_SRCS})
add_dependencies(kcmTest kcm_lookandfeel)
......
/* This file is part of the KDE Project
Copyright (c) 2014 Marco Martin <mart@kde.org>
Copyright (c) 2014 Vishesh Handa <me@vhanda.in>
Copyright (c) 2019 Cyril Rossi <cyril.rossi@enioka.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -46,12 +47,15 @@
#include <X11/Xlib.h>
#include <X11/Xcursor/Xcursor.h>
#include "lookandfeelsettings.h"
#ifdef HAVE_XFIXES
# include <X11/extensions/Xfixes.h>
#endif
KCMLookandFeel::KCMLookandFeel(QObject* parent, const QVariantList& args)
: KQuickAddons::ConfigModule(parent, args)
KCMLookandFeel::KCMLookandFeel(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_settings(new LookAndFeelSettings(this))
, m_config(QStringLiteral("kdeglobals"))
, m_configGroup(m_config.group("KDE"))
, m_applyColors(true)
......@@ -64,9 +68,11 @@ KCMLookandFeel::KCMLookandFeel(QObject* parent, const QVariantList& args)
, m_resetDefaultLayout(false)
, m_applyWindowDecoration(true)
{
qmlRegisterType<LookAndFeelSettings>();
qmlRegisterType<QStandardItemModel>();
qmlRegisterType<KCMLookandFeel>();
KAboutData* about = new KAboutData(QStringLiteral("kcm_lookandfeel"), i18n("Global Theme"),
KAboutData *about = new KAboutData(QStringLiteral("kcm_lookandfeel"), i18n("Global Theme"),
QStringLiteral("0.1"), QString(), KAboutLicense::LGPL);
about->addAuthor(i18n("Marco Martin"), QString(), QStringLiteral("mart@kde.org"));
setAboutData(about);
......@@ -108,34 +114,13 @@ QStandardItemModel *KCMLookandFeel::lookAndFeelModel() const
return m_model;
}
QString KCMLookandFeel::selectedPlugin() const
{
return m_selectedPlugin;
}
void KCMLookandFeel::setSelectedPlugin(const QString &plugin)
int KCMLookandFeel::pluginIndex(const QString &pluginName) const
{
if (m_selectedPlugin == plugin) {
return;
}
const bool firstTime = m_selectedPlugin.isNull();
m_selectedPlugin = plugin;
emit selectedPluginChanged();
emit selectedPluginIndexChanged();
if (!firstTime) {
setNeedsSave(true);
const auto results = m_model->match(m_model->index(0, 0), PluginNameRole, pluginName);
if (results.count() == 1) {
return results.first().row();
}
}
int KCMLookandFeel::selectedPluginIndex() const
{
for (int i = 0; i < m_model->rowCount(); ++i) {
if (m_model->data(m_model->index(i, 0), PluginNameRole).toString() == m_selectedPlugin) {
return i;
}
}
return -1;
}
......@@ -170,6 +155,11 @@ QList<KPackage::Package> KCMLookandFeel::availablePackages(const QStringList &co
return packages;
}
LookAndFeelSettings *KCMLookandFeel::lookAndFeelSettings() const
{
return m_settings;
}
void KCMLookandFeel::loadModel()
{
m_model->clear();
......@@ -179,7 +169,7 @@ void KCMLookandFeel::loadModel()
if (!pkg.metadata().isValid()) {
continue;
}
QStandardItem* row = new QStandardItem(pkg.metadata().name());
QStandardItem *row = new QStandardItem(pkg.metadata().name());
row->setData(pkg.metadata().pluginId(), PluginNameRole);
row->setData(pkg.metadata().description(), DescriptionRole);
row->setData(pkg.filePath("preview"), ScreenshotRole);
......@@ -226,45 +216,36 @@ void KCMLookandFeel::loadModel()
m_model->appendRow(row);
}
m_model->sort(0 /*column*/);
emit selectedPluginIndexChanged();
//Model has been cleared so pretend the selected look and fell changed to force view update
emit m_settings->lookAndFeelPackageChanged();
}
void KCMLookandFeel::load()
{
m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE");
const QString packageName = cg.readEntry("LookAndFeelPackage", QString());
if (!packageName.isEmpty()) {
m_package.setPath(packageName);
}
if (!m_package.metadata().isValid()) {
return;
}
setSelectedPlugin(m_package.metadata().pluginId());
ManagedConfigModule::load();
setNeedsSave(false);
m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
m_package.setPath(m_settings->lookAndFeelPackage());
}
void KCMLookandFeel::save()
{
KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
package.setPath(m_selectedPlugin);
package.setPath(m_settings->lookAndFeelPackage());
if (!package.isValid()) {
return;
}
m_configGroup.writeEntry("LookAndFeelPackage", m_selectedPlugin);
ManagedConfigModule::save();
if (m_resetDefaultLayout) {
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), QStringLiteral("/PlasmaShell"),
QStringLiteral("org.kde.PlasmaShell"), QStringLiteral("loadLookAndFeelDefaultLayout"));
QList<QVariant> args;
args << m_selectedPlugin;
args << m_settings->lookAndFeelPackage();
message.setArguments(args);
QDBusConnection::sessionBus().call(message, QDBus::NoBlock);
......@@ -407,23 +388,14 @@ void KCMLookandFeel::save()
}
//TODO: option to enable/disable apply? they don't seem required by UI design
setSplashScreen(m_selectedPlugin);
setLockScreen(m_selectedPlugin);
setSplashScreen(m_settings->lookAndFeelPackage());
setLockScreen(m_settings->lookAndFeelPackage());
m_configGroup.sync();
m_package.setPath(m_selectedPlugin);
m_package.setPath(m_settings->lookAndFeelPackage());
runRdb(KRdbExportQtColors | KRdbExportGtkTheme | KRdbExportColors | KRdbExportQtSettings | KRdbExportXftSettings);
}
void KCMLookandFeel::defaults()
{
if (!m_package.metadata().isValid()) {
return;
}
setSelectedPlugin(m_package.metadata().pluginId());
}
void KCMLookandFeel::setWidgetStyle(const QString &style)
{
if (style.isEmpty()) {
......
/*
Copyright (c) 2014 Marco Martin <mart@kde.org>
Copyright (c) 2014 Vishesh Handa <me@vhanda.in>
Copyright (c) 2019 Cyril Rossi <cyril.rossi@enioka.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -25,17 +26,17 @@
#include <QDir>
#include <KPackage/Package>
#include <KQuickAddons/ConfigModule>
#include <KQuickAddons/ManagedConfigModule>
class QQuickItem;
class QStandardItemModel;
class LookAndFeelSettings;
class KCMLookandFeel : public KQuickAddons::ConfigModule
class KCMLookandFeel : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(LookAndFeelSettings *lookAndFeelSettings READ lookAndFeelSettings CONSTANT)
Q_PROPERTY(QStandardItemModel *lookAndFeelModel READ lookAndFeelModel CONSTANT)
Q_PROPERTY(QString selectedPlugin READ selectedPlugin WRITE setSelectedPlugin NOTIFY selectedPluginChanged)
Q_PROPERTY(int selectedPluginIndex READ selectedPluginIndex NOTIFY selectedPluginIndexChanged)
Q_PROPERTY(bool resetDefaultLayout READ resetDefaultLayout WRITE setResetDefaultLayout NOTIFY resetDefaultLayoutChanged)
public:
......@@ -60,15 +61,10 @@ public:
KCMLookandFeel(QObject* parent, const QVariantList& args);
~KCMLookandFeel() override;
//List only packages which provide at least one of the components
QList<KPackage::Package> availablePackages(const QStringList &components);
LookAndFeelSettings *lookAndFeelSettings() const;
QStandardItemModel *lookAndFeelModel() const;
QString selectedPlugin() const;
void setSelectedPlugin(const QString &plugin);
int selectedPluginIndex() const;
Q_INVOKABLE int pluginIndex(const QString &pluginName) const;
bool resetDefaultLayout() const;
void setResetDefaultLayout(bool reset);
......@@ -90,20 +86,20 @@ public:
public Q_SLOTS:
void load() override;
void save() override;
void defaults() override;
Q_SIGNALS:
void selectedPluginChanged();
void selectedPluginIndexChanged();
void resetDefaultLayoutChanged();
private:
//List only packages which provide at least one of the components
QList<KPackage::Package> availablePackages(const QStringList &components);
void loadModel();
QDir cursorThemeDir(const QString &theme, const int depth);
const QStringList cursorSearchPaths();
LookAndFeelSettings *m_settings;
QStandardItemModel *m_model;
KPackage::Package m_package;
QString m_selectedPlugin;
QStringList m_cursorSearchPaths;
KConfig m_config;
......
......@@ -32,6 +32,8 @@
#include <KPackage/Package>
#include <KPackage/PackageLoader>
#include "lookandfeelsettings.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
......@@ -88,7 +90,7 @@ int main(int argc, char **argv)
KCMLookandFeel *kcm = new KCMLookandFeel(nullptr, QVariantList());
kcm->load();
kcm->setResetDefaultLayout(parser.isSet(_resetLayout));
kcm->setSelectedPlugin(parser.value(_apply));
kcm->lookAndFeelSettings()->setLookAndFeelPackage(parser.value(_apply));
kcm->save();
delete kcm;
}
......
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kdeglobals" />
<group name="KDE">
<entry name="lookAndFeelPackage" key="LookAndFeelPackage" type="String">
<label>Global look and feel</label>
<default>org.kde.breeze.desktop</default>
</entry>
</group>
</kcfg>
File=lookandfeelsettings.kcfg
ClassName=LookAndFeelSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
......@@ -29,7 +29,7 @@ KCM.GridViewKCM {
KCM.ConfigModule.quickHelp: i18n("This module lets you choose the global look and feel.")
view.model: kcm.lookAndFeelModel
view.currentIndex: kcm.selectedPluginIndex
view.currentIndex: kcm.pluginIndex(kcm.lookAndFeelSettings.lookAndFeelPackage)
view.delegate: KCM.GridDelegate {
id: delegate
......@@ -55,7 +55,7 @@ KCM.GridViewKCM {
}
]
onClicked: {
kcm.selectedPlugin = model.pluginName;
kcm.lookAndFeelSettings.lookAndFeelPackage = model.pluginName;
view.forceActiveFocus();
resetCheckbox.checked = false;
}
......
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