Commit 0536cf41 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

[kcms/style] Fix setting to default and apply button enablement

Track the selected GTK theme in the model only. This fixes setting to default when the GTK pages was never opened

Override isSaveNeeded instead of calling setNeedsSave, this fixes the apply button enablement
parent 0c1157a0
Pipeline #225841 passed with stage
in 10 minutes and 40 seconds
......@@ -31,12 +31,6 @@ GtkPage::GtkPage(QObject *parent)
GtkPage::~GtkPage() = default;
QString GtkPage::gtkThemeFromConfig()
{
// FIXME make aysnc but that requires some refactoring on the UI side
return m_gtkConfigInterface.gtkTheme().value();
}
bool GtkPage::gtkPreviewAvailable()
{
return !QStandardPaths::findExecutable(QStringLiteral("gtk3_preview"), {CMAKE_INSTALL_FULL_LIBEXECDIR}).isEmpty();
......@@ -94,17 +88,21 @@ void GtkPage::save()
void GtkPage::defaults()
{
Q_EMIT selectGtkThemeInCombobox(QStringLiteral("Breeze"));
m_gtkThemesModel->setSelectedTheme(QStringLiteral("Breeze"));
}
void GtkPage::load()
{
m_gtkThemesModel->load();
m_gtkThemesModel->setSelectedTheme(m_gtkConfigInterface.gtkTheme());
Q_EMIT selectGtkThemeInCombobox(gtkThemeFromConfig());
}
bool GtkPage::isDefaults() const
{
return m_gtkThemesModel->selectedTheme() == QLatin1String("Breeze");
}
bool GtkPage::isSaveNeeded()
{
return m_gtkThemesModel->selectedTheme() != m_gtkConfigInterface.gtkTheme();
}
......@@ -27,10 +27,9 @@ public:
void save();
void defaults();
bool isDefaults() const;
bool isSaveNeeded();
public Q_SLOTS:
QString gtkThemeFromConfig();
bool gtkPreviewAvailable();
void showGtkPreview();
......@@ -43,7 +42,6 @@ Q_SIGNALS:
void gtkThemesModelChanged(GtkThemesModel *model);
void showErrorMessage(const QString &message);
void selectGtkThemeInCombobox(const QString &themeName);
void gtkThemeSettingsChanged();
......
......@@ -103,6 +103,7 @@ QMap<QString, QString> GtkThemesModel::themesList()
void GtkThemesModel::setSelectedTheme(const QString &themeName)
{
m_selectedTheme = themeName;
Q_EMIT selectedThemeChanged(themeName);
}
QString GtkThemesModel::selectedTheme()
......
......@@ -90,7 +90,6 @@ KCMStyle::KCMStyle(QObject *parent, const KPluginMetaData &data, const QVariantL
m_gtkPage = new GtkPage(this);
connect(m_gtkPage, &GtkPage::gtkThemeSettingsChanged, this, [this]() {
settingsChanged();
setNeedsSave(true);
});
}
......@@ -338,4 +337,9 @@ bool KCMStyle::isDefaults() const
return m_gtkPage->isDefaults();
}
bool KCMStyle::isSaveNeeded() const
{
return m_gtkPage->isSaveNeeded();
}
#include "kcmstyle.moc"
......@@ -76,6 +76,7 @@ public:
void defaults() override;
bool isDefaults() const override;
bool isSaveNeeded() const override;
Q_SIGNALS:
void showErrorMessage(const QString &message);
......
......@@ -49,20 +49,13 @@ Kirigami.Page {
QtControls.ComboBox {
id: gtkThemeCombo
model: kcm.gtkPage.gtkThemesModel
currentIndex: model.findThemeIndex(kcm.gtkPage.gtkThemeFromConfig())
currentIndex: model.findThemeIndex(kcm.gtkPage.gtkThemesModel.selectedTheme)
onCurrentTextChanged: function() {
model.selectedTheme = currentText
gtkRemoveButton.enabled = model.selectedThemeRemovable()
}
onActivated: model.setSelectedThemeDirty()
textRole: "theme-name"
Connections {
target: kcm.gtkPage
function onSelectGtkThemeInCombobox(themeName) {
gtkThemeCombo.currentIndex = gtkThemeCombo.model.findThemeIndex(themeName)
}
}
}
QtControls.Button {
......
Supports Markdown
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