Commit 38a874ab authored by Benjamin Port's avatar Benjamin Port

[KCM Spellchecking] port to KPropertySkeletonItem

Reviewers: #plasma, meven, crossi, ervin

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27503
parent fff5c048
set(kcm_spellchecking_SRCS
spellcheckingskeleton.cpp
spellchecking.cpp
)
......@@ -6,6 +7,7 @@ add_library(kcmspellchecking MODULE ${kcm_spellchecking_SRCS})
target_link_libraries(kcmspellchecking
KF5::ConfigWidgets
KF5::SonnetCore
KF5::SonnetUi
)
......
/*
Copyright 2008 Albert Astals Cid <aacid@kde.org>
Copyright 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
......@@ -22,35 +23,93 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "spellchecking.h"
#include <kpluginfactory.h>
#include <sonnet/configwidget.h>
#include <KConfig>
#include <QBoxLayout>
#include <QSet>
#include <KConfigDialogManager>
#include <Sonnet/ConfigView>
#include <Sonnet/Settings>
#include <KPluginFactory>
#include "spellcheckingskeleton.h"
K_PLUGIN_FACTORY(SpellFactory, registerPlugin<SonnetSpellCheckingModule>();)
SonnetSpellCheckingModule::SonnetSpellCheckingModule(QWidget* parent, const QVariantList&):
KCModule(parent)
SonnetSpellCheckingModule::SonnetSpellCheckingModule(QWidget *parent, const QVariantList &)
: KCModule(parent)
{
QBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_skeleton = new SpellCheckingSkeleton(this);
m_configWidget = new Sonnet::ConfigView(this);
m_configWidget->setNoBackendFoundVisible(m_skeleton->clients().isEmpty());
layout->addWidget(m_configWidget);
m_managedConfig = addConfig(m_skeleton, m_configWidget);
connect(m_configWidget, &Sonnet::ConfigView::configChanged, this, &SonnetSpellCheckingModule::stateChanged);
}
void SonnetSpellCheckingModule::stateChanged()
{
QBoxLayout *layout = new QVBoxLayout( this );
layout->setContentsMargins(0, 0, 0, 0);
m_configWidget = new Sonnet::ConfigWidget( this );
layout->addWidget(m_configWidget);
connect(m_configWidget, SIGNAL(configChanged()), this, SLOT(changed()));
bool unmanagedChangeState = false;
bool unmanagedDefaultState = true;
QStringList refIgnoreList(m_skeleton->ignoreList());
QStringList currentIgnoreList(m_configWidget->ignoreList());
QStringList defaultIgnoreList(Sonnet::Settings::defaultIgnoreList());
QSet<QString> refIgnoreSet(refIgnoreList.begin(), refIgnoreList.end());
QSet<QString> currentIgnoreSet(currentIgnoreList.begin(), currentIgnoreList.end());
QSet<QString> defaultIgnoreSet(defaultIgnoreList.begin(), defaultIgnoreList.end());
unmanagedChangeState |= currentIgnoreSet != refIgnoreSet;
unmanagedDefaultState &= currentIgnoreSet == defaultIgnoreSet;
QStringList refPreferredLanguagesList(m_skeleton->preferredLanguages());
QStringList currentPreferredLanguagesList(m_configWidget->preferredLanguages());
QStringList defaultPreferredLanguagesList(Sonnet::Settings::defaultPreferredLanguages());
QSet<QString> refPreferredLanguages(refPreferredLanguagesList.begin(), refPreferredLanguagesList.end());
QSet<QString> currentPreferredLanguages(currentPreferredLanguagesList.begin(), currentPreferredLanguagesList.end());
QSet<QString> defaultPreferredLanguages(defaultPreferredLanguagesList.begin(), defaultPreferredLanguagesList.end());
unmanagedChangeState |= currentPreferredLanguages != refPreferredLanguages;
unmanagedDefaultState &= currentPreferredLanguages == defaultPreferredLanguages;
unmanagedChangeState |= m_skeleton->defaultLanguage() != m_configWidget->language();
unmanagedDefaultState &= m_configWidget->language() == Sonnet::Settings::defaultDefaultLanguage();
unmanagedWidgetDefaultState(unmanagedDefaultState);
unmanagedWidgetChangeState(unmanagedChangeState);
}
SonnetSpellCheckingModule::~SonnetSpellCheckingModule()
{
}
void SonnetSpellCheckingModule::load()
{
KCModule::load();
// Set unmanaged widget value
m_configWidget->setIgnoreList(m_skeleton->ignoreList());
m_configWidget->setPreferredLanguages(m_skeleton->preferredLanguages());
m_configWidget->setLanguage(m_skeleton->defaultLanguage());
}
void SonnetSpellCheckingModule::save()
{
m_configWidget->save();
m_skeleton->setIgnoreList(m_configWidget->ignoreList());
m_skeleton->setPreferredLanguages(m_configWidget->preferredLanguages());
m_skeleton->setDefaultLanguage(m_configWidget->language());
// with addConfig, save on skeleton will be trigger only if one managed widget changed
if (!m_managedConfig->hasChanged()) {
m_skeleton->save();
}
KCModule::save();
}
void SonnetSpellCheckingModule::defaults()
{
m_configWidget->slotDefault();
KCModule::defaults();
// set default value for unmanaged widgets
m_configWidget->setIgnoreList(Sonnet::Settings::defaultIgnoreList());
m_configWidget->setPreferredLanguages(Sonnet::Settings::defaultPreferredLanguages());
m_configWidget->setLanguage(Sonnet::Settings::defaultDefaultLanguage());
}
#include "spellchecking.moc"
/*
Copyright 2008 Albert Astals Cid <aacid@kde.org>
Copyright 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
......@@ -24,26 +25,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define SONNETSPELLCHECKINGMODULE_H
#include "kcmodule.h"
#include "spellcheckingskeleton.h"
class KConfigDialogManager;
namespace Sonnet
{
class ConfigWidget;
class ConfigView;
}
class SonnetSpellCheckingModule : public KCModule
{
Q_OBJECT
Q_OBJECT
public:
SonnetSpellCheckingModule(QWidget* parent, const QVariantList&);
~SonnetSpellCheckingModule() override;
public:
SonnetSpellCheckingModule(QWidget *parent, const QVariantList &);
~SonnetSpellCheckingModule() override;
void save() override;
void defaults() override;
void save() override;
void load() override;
void defaults() override;
private:
Sonnet::ConfigWidget *m_configWidget;
private:
void stateChanged();
Sonnet::Settings *m_settings;
Sonnet::ConfigView *m_configWidget;
SpellCheckingSkeleton *m_skeleton;
KConfigDialogManager *m_managedConfig;
};
#endif
/*
Copyright 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 "spellcheckingskeleton.h"
#include <Sonnet/ConfigView>
#include <Sonnet/Settings>
SpellCheckingSkeleton::SpellCheckingSkeleton(QObject *parent)
: KCoreConfigSkeleton(QStringLiteral(""), parent), m_store(new Sonnet::Settings(this))
{
// Associated with managed widget
addItem(new KPropertySkeletonItem(m_store, "skipUppercase", Sonnet::Settings::defaultSkipUppercase()), "skipUppercase");
addItem(new KPropertySkeletonItem(m_store, "autodetectLanguage", Sonnet::Settings::defaultAutodetectLanguage()), "autodetectLanguage");
addItem(new KPropertySkeletonItem(m_store, "backgroundCheckerEnabled", Sonnet::Settings::defaultBackgroundCheckerEnabled()), "backgroundCheckerEnabled");
addItem(new KPropertySkeletonItem(m_store, "checkerEnabledByDefault", Sonnet::Settings::defaultCheckerEnabledByDefault()), "checkerEnabledByDefault");
addItem(new KPropertySkeletonItem(m_store, "skipRunTogether", Sonnet::Settings::defauktSkipRunTogether()), "skipRunTogether");
usrRead();
}
void SpellCheckingSkeleton::usrRead()
{
m_ignoreList = m_store->currentIgnoreList();
m_preferredLanguages = m_store->preferredLanguages();
m_defaultLanguage = m_store->defaultLanguage();
KCoreConfigSkeleton::usrRead();
}
bool SpellCheckingSkeleton::usrSave()
{
m_store->setCurrentIgnoreList(m_ignoreList);
m_store->setPreferredLanguages(m_preferredLanguages);
m_store->setDefaultLanguage(m_defaultLanguage);
m_store->save();
return KCoreConfigSkeleton::usrSave();
}
void SpellCheckingSkeleton::setPreferredLanguages(const QStringList &preferredLanguages)
{
m_preferredLanguages = preferredLanguages;
}
QStringList SpellCheckingSkeleton::preferredLanguages() const
{
return m_preferredLanguages;
}
void SpellCheckingSkeleton::setIgnoreList(const QStringList &ignoreList)
{
m_ignoreList = ignoreList;
}
QStringList SpellCheckingSkeleton::ignoreList() const
{
return m_ignoreList;
}
void SpellCheckingSkeleton::setDefaultLanguage(const QString &defaultLanguage)
{
m_defaultLanguage = defaultLanguage;
}
QString SpellCheckingSkeleton::defaultLanguage() const
{
return m_defaultLanguage;
}
QStringList SpellCheckingSkeleton::clients() const
{
return m_store->clients();
}
#include "spellcheckingskeleton.moc"
/*
Copyright 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 SPELLCHECKINGSKELETON_H
#define SPELLCHECKINGSKELETON_H
#include <KConfigCore/KCoreConfigSkeleton>
namespace Sonnet {
class Settings;
class ConfigView;
}
class SpellCheckingSkeleton : public KCoreConfigSkeleton
{
Q_OBJECT
public:
explicit SpellCheckingSkeleton(QObject *parent = nullptr);
bool usrSave() override;
void usrRead() override;
void setPreferredLanguages(const QStringList &preferredLanguages);
QStringList preferredLanguages() const;
void setIgnoreList(const QStringList &ignoreList);
QStringList ignoreList() const;
void setDefaultLanguage(const QString &defaultLanguage);
QString defaultLanguage() const;
QStringList clients() const;
private:
Sonnet::Settings *m_store;
QStringList m_preferredLanguages;
QStringList m_ignoreList;
QString m_defaultLanguage;
};
#endif
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