Commit fbed4b3e authored by Cyril Rossi's avatar Cyril Rossi
Browse files

KCM Style port to KConfigXT

Reviewers: ervin, mart, bport, #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24917
parent 45439589
......@@ -7,9 +7,10 @@ set(kcm_style_PART_SRCS ../krdb/krdb.cpp styleconfdialog.cpp kcmstyle.cpp styles
set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml)
qt5_add_dbus_interface(kcm_style_PART_SRCS ${klauncher_xml} klauncher_iface)
ki18n_wrap_ui(kcm_style_PART_SRCS stylepreview.ui)
kconfig_add_kcfg_files(kcm_style_PART_SRCS stylesettings.kcfgc GENERATE_MOC)
add_library(kcm_style MODULE ${kcm_style_PART_SRCS})
target_link_libraries(kcm_style
......@@ -29,6 +30,7 @@ target_link_libraries(kcm_style
kcoreaddons_desktop_to_json(kcm_style "kcm_style.desktop")
install(FILES stylesettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(FILES kcm_style.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS kcm_style DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms)
......
......@@ -5,6 +5,7 @@
* Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
* Copyright (C) 2009 by Davide Bettio <davide.bettio@kdemail.net>
* Copyright (C) 2019 Kai Uwe Broulik <kde@broulik.de>
* Copyright (C) 2019 Cyril Rossi <cyril.rossi@enioka.com>
*
* Portions Copyright (C) 2007 Paolo Capriotti <p.capriotti@gmail.com>
* Portions Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
......@@ -53,6 +54,7 @@
#include "stylesmodel.h"
#include "previewitem.h"
#include "stylesettings.h"
K_PLUGIN_FACTORY_WITH_JSON(KCMStyleFactory, "kcm_style.json", registerPlugin<KCMStyle>();)
......@@ -72,16 +74,13 @@ extern "C"
}
}
QString KCMStyle::defaultStyle()
{
return QStringLiteral("Breeze");
}
KCMStyle::KCMStyle(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args)
, m_settings(new StyleSettings(this))
, m_model(new StylesModel(this))
{
qmlRegisterUncreatableType<KCMStyle>("org.kde.private.kcms.style", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM"));
qmlRegisterType<StyleSettings>();
qmlRegisterType<StylesModel>();
qmlRegisterType<PreviewItem>("org.kde.private.kcms.style", 1, 0, "PreviewItem");
......@@ -99,6 +98,14 @@ KCMStyle::KCMStyle(QObject *parent, const QVariantList &args)
m_selectedStyleDirty = true;
setNeedsSave(true);
});
connect(m_settings, &StyleSettings::iconsOnButtonsChanged, this, [this] {
m_effectsDirty = true;
setNeedsSave(true);
});
connect(m_settings, &StyleSettings::iconsInMenusChanged, this, [this] {
m_effectsDirty = true;
setNeedsSave(true);
});
}
KCMStyle::~KCMStyle() = default;
......@@ -108,36 +115,9 @@ StylesModel *KCMStyle::model() const
return m_model;
}
bool KCMStyle::iconsOnButtons() const
{
return m_iconsOnButtons;
}
void KCMStyle::setIconsOnButtons(bool enable)
{
if (m_iconsOnButtons != enable) {
m_iconsOnButtons = enable;
emit iconsOnButtonsChanged();
m_effectsDirty = true;
setNeedsSave(true);
}
}
bool KCMStyle::iconsInMenus() const
{
return m_iconsInMenus;
}
void KCMStyle::setIconsInMenus(bool enable)
StyleSettings *KCMStyle::styleSettings() const
{
if (m_iconsInMenus != enable) {
m_iconsInMenus = enable;
emit iconsInMenusChanged();
m_effectsDirty = true;
setNeedsSave(true);
}
return m_settings;
}
KCMStyle::ToolBarStyle KCMStyle::mainToolBarStyle() const
......@@ -251,25 +231,9 @@ void KCMStyle::load()
{
m_model->load();
KConfig config(QStringLiteral("kdeglobals"));
// Current style
KConfigGroup kdeGroup = config.group("KDE");
const QString widgetStyle = kdeGroup.readEntry("widgetStyle", KCMStyle::defaultStyle());
m_model->setSelectedStyle(widgetStyle);
m_settings->load();
// Effects settings
setIconsOnButtons(kdeGroup.readEntry("ShowIconsOnPushButtons", true));
setIconsInMenus(kdeGroup.readEntry("ShowIconsInMenuItems", true));
KConfigGroup toolBarGroup = config.group("Toolbar style");
const QString mainToolBarStyle = toolBarGroup.readEntry("ToolButtonStyle", "TextBesideIcon");
const QString otherToolBarStyle = toolBarGroup.readEntry("ToolButtonStyleOtherToolbars", "TextBesideIcon");
const QMetaEnum toolBarStyleEnum = QMetaEnum::fromType<ToolBarStyle>();
setMainToolBarStyle(static_cast<ToolBarStyle>(toolBarStyleEnum.keyToValue(qUtf8Printable(mainToolBarStyle))));
setOtherToolBarStyle(static_cast<ToolBarStyle>(toolBarStyleEnum.keyToValue(qUtf8Printable(otherToolBarStyle))));
loadSettingsToModel();
m_selectedStyleDirty = false;
m_effectsDirty = false;
......@@ -295,24 +259,15 @@ void KCMStyle::save()
}
}
KConfig config(QStringLiteral("kdeglobals"));
KConfigGroup kdeGroup = config.group("KDE");
if (newStyleLoaded) {
kdeGroup.writeEntry("widgetStyle", m_model->selectedStyle());
m_settings->setWidgetStyle(m_model->selectedStyle());
}
kdeGroup.writeEntry("ShowIconsOnPushButtons", m_iconsOnButtons);
kdeGroup.writeEntry("ShowIconsInMenuItems", m_iconsInMenus);
KConfigGroup toolBarGroup = config.group("Toolbar style");
const QMetaEnum toolBarStyleEnum = QMetaEnum::fromType<ToolBarStyle>();
m_settings->setToolButtonStyle(toolBarStyleEnum.valueToKey(m_mainToolBarStyle));
m_settings->setToolButtonStyleOtherToolbars(toolBarStyleEnum.valueToKey(m_otherToolBarStyle));
toolBarGroup.writeEntry("ToolButtonStyle", toolBarStyleEnum.valueToKey(m_mainToolBarStyle));
toolBarGroup.writeEntry("ToolButtonStyleOtherToolbars", toolBarStyleEnum.valueToKey(m_otherToolBarStyle));
config.sync();
m_settings->save();
// Export the changes we made to qtrc, and update all qt-only
// applications on the fly, ensuring that we still follow the user's
......@@ -342,12 +297,11 @@ void KCMStyle::save()
// Reset selected style back to current in case of failure
if (!newStyleLoaded) {
const QString widgetStyle = kdeGroup.readEntry("widgetStyle", KCMStyle::defaultStyle());
m_model->setSelectedStyle(widgetStyle);
m_model->setSelectedStyle(m_settings->widgetStyle());
}
m_selectedStyleDirty = false;
m_effectsDirty = false;
setNeedsSave(false);
}
void KCMStyle::defaults()
......@@ -355,14 +309,20 @@ void KCMStyle::defaults()
// TODO the old code had a fallback chain but do we actually support not having Breeze for Plasma?
// defaultStyle() -> oxygen -> plastique -> windows -> platinum -> motif
m_model->setSelectedStyle(defaultStyle());
m_settings->setDefaults();
loadSettingsToModel();
setIconsOnButtons(true);
setIconsInMenus(true);
setMainToolBarStyle(TextBesideIcon);
setOtherToolBarStyle(TextBesideIcon);
setNeedsSave(m_settings->isSaveNeeded());
}
#include "kcmstyle.moc"
void KCMStyle::loadSettingsToModel()
{
m_model->setSelectedStyle(m_settings->widgetStyle());
// vim: set noet ts=4:
const QMetaEnum toolBarStyleEnum = QMetaEnum::fromType<ToolBarStyle>();
setMainToolBarStyle(static_cast<ToolBarStyle>(toolBarStyleEnum.keyToValue(qUtf8Printable(m_settings->toolButtonStyle()))));
setOtherToolBarStyle(static_cast<ToolBarStyle>(toolBarStyleEnum.keyToValue(qUtf8Printable(m_settings->toolButtonStyleOtherToolbars()))));
}
#include "kcmstyle.moc"
......@@ -4,6 +4,7 @@
* Copyright (C) 2002 Daniel Molkentin <molkentin@kde.org>
* Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
* Copyright (C) 2019 Kai Uwe Broulik <kde@broulik.de>
* Copyright (C) 2019 Cyril Rossi <cyril.rossi@enioka.com>
*
* Portions Copyright (C) TrollTech AS.
*
......@@ -35,6 +36,7 @@
class QQuickItem;
class StyleSettings;
class StylesModel;
class StyleConfigDialog;
......@@ -43,9 +45,7 @@ class KCMStyle : public KQuickAddons::ConfigModule
Q_OBJECT
Q_PROPERTY(StylesModel *model READ model CONSTANT)
Q_PROPERTY(bool iconsOnButtons READ iconsOnButtons WRITE setIconsOnButtons NOTIFY iconsOnButtonsChanged)
Q_PROPERTY(bool iconsInMenus READ iconsInMenus WRITE setIconsInMenus NOTIFY iconsInMenusChanged)
Q_PROPERTY(StyleSettings *styleSettings READ styleSettings CONSTANT)
Q_PROPERTY(ToolBarStyle mainToolBarStyle READ mainToolBarStyle WRITE setMainToolBarStyle NOTIFY mainToolBarStyleChanged)
Q_PROPERTY(ToolBarStyle otherToolBarStyle READ otherToolBarStyle WRITE setOtherToolBarStyle NOTIFY otherToolBarStyleChanged)
......@@ -63,13 +63,7 @@ public:
StylesModel *model() const;
bool iconsOnButtons() const;
void setIconsOnButtons(bool enable);
Q_SIGNAL void iconsOnButtonsChanged();
bool iconsInMenus() const;
void setIconsInMenus(bool enable);
Q_SIGNAL void iconsInMenusChanged();
StyleSettings *styleSettings() const;
ToolBarStyle mainToolBarStyle() const;
void setMainToolBarStyle(ToolBarStyle style);
......@@ -85,21 +79,19 @@ public:
void save() override;
void defaults() override;
static QString defaultStyle();
Q_SIGNALS:
void showErrorMessage(const QString &message);
void styleReconfigured(const QString &styleName);
private:
void loadSettingsToModel();
StyleSettings *m_settings;
StylesModel *m_model;
bool m_selectedStyleDirty = false;
bool m_effectsDirty = false;
bool m_iconsOnButtons = false;
bool m_iconsInMenus = false;
ToolBarStyle m_mainToolBarStyle = NoText;
ToolBarStyle m_otherToolBarStyle = NoText;
......@@ -107,5 +99,3 @@ private:
};
#endif // __KCMSTYLE_H
// vim: set noet ts=4:
......@@ -42,14 +42,14 @@ QtControls.Popup {
id: iconsOnButtonsCheckBox
Kirigami.FormData.label: i18n("Show icons:")
text: i18n("On buttons")
checked: kcm.iconsOnButtons
onClicked: kcm.iconsOnButtons = checked
checked: kcm.styleSettings.iconsOnButtons
onClicked: kcm.styleSettings.iconsOnButtons = checked
}
QtControls.CheckBox {
text: i18n("In menus")
checked: kcm.iconsInMenus
onClicked: kcm.iconsInMenus = checked
checked: kcm.styleSettings.iconsInMenus
onClicked: kcm.styleSettings.iconsInMenus = checked
}
QtControls.ComboBox {
......
<?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="widgetStyle" type="String">
<label>Application style</label>
<default>Breeze</default>
</entry>
<entry name="iconsOnButtons" key="ShowIconsOnPushButtons" type="Bool">
<label>Show icons on buttons</label>
<default>true</default>
</entry>
<entry name="iconsInMenus" key="ShowIconsInMenuItems" type="Bool">
<label>Show icons in menus</label>
<default>true</default>
</entry>
</group>
<group name="Toolbar style">
<entry name="toolButtonStyle" key="ToolButtonStyle" type="String">
<label>Main toolbar label</label>
<default>TextBesideIcon</default>
</entry>
<entry name="toolButtonStyleOtherToolbars" key="ToolButtonStyleOtherToolbars" type="String">
<label>Secondary toolbar label</label>
<default>TextBesideIcon</default>
</entry>
</group>
</kcfg>
File=stylesettings.kcfg
ClassName=StyleSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
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