aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKai Uwe Broulik <kde@privat.broulik.de>2019-04-24 16:20:56 +0200
committerKai Uwe Broulik <kde@privat.broulik.de>2019-04-24 16:21:29 +0200
commit5d2ed13479a480111355657bf22324118fa576e9 (patch)
treed55fe47fa3d017391b8c6c1a735d4b098adbe8f8 /src
parentb327f5f6cef127980e84926b134d5c7c72e833b1 (diff)
downloadkconfig-5d2ed13479a480111355657bf22324118fa576e9.tar.gz
kconfig-5d2ed13479a480111355657bf22324118fa576e9.tar.bz2
Add Notify capability to KConfigXT
Lets you specify Notifiers= in .kcfg for config entries that should be written with Notify flag, i.e. announce the change to KConfigWatcher Differential Revision: https://phabricator.kde.org/D20196
Diffstat (limited to 'src')
-rw-r--r--src/core/kcoreconfigskeleton.cpp36
-rw-r--r--src/core/kcoreconfigskeleton.h18
-rw-r--r--src/core/kcoreconfigskeleton_p.h2
-rw-r--r--src/kconfig_compiler/kconfig_compiler.cpp8
4 files changed, 49 insertions, 15 deletions
diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp
index 50f91e93..384efdb4 100644
--- a/src/core/kcoreconfigskeleton.cpp
+++ b/src/core/kcoreconfigskeleton.cpp
@@ -110,6 +110,16 @@ QString KConfigSkeletonItem::whatsThis() const
return d->mWhatsThis;
}
+void KConfigSkeletonItem::setWriteFlags(KConfigBase::WriteConfigFlags flags)
+{
+ d->mWriteFlags = flags;
+}
+
+KConfigBase::WriteConfigFlags KConfigSkeletonItem::writeFlags() const
+{
+ return d->mWriteFlags;
+}
+
QVariant KConfigSkeletonItem::minValue() const
{
return QVariant();
@@ -144,13 +154,13 @@ void KCoreConfigSkeleton::ItemString::writeConfig(KConfig *config)
if (mReference != mLoadedValue) { // WABA: Is this test needed?
KConfigGroup cg(config, mGroup);
if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
- cg.revertToDefault(mKey);
+ cg.revertToDefault(mKey, writeFlags());
} else if (mType == Path) {
- cg.writePathEntry(mKey, mReference);
+ cg.writePathEntry(mKey, mReference, writeFlags());
} else if (mType == Password) {
- cg.writeEntry(mKey, obscuredString(mReference));
+ cg.writeEntry(mKey, obscuredString(mReference), writeFlags());
} else {
- cg.writeEntry(mKey, mReference);
+ cg.writeEntry(mKey, mReference, writeFlags());
}
mLoadedValue = mReference;
}
@@ -215,9 +225,9 @@ void KCoreConfigSkeleton::ItemUrl::writeConfig(KConfig *config)
if (mReference != mLoadedValue) { // WABA: Is this test needed?
KConfigGroup cg(config, mGroup);
if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
- cg.revertToDefault(mKey);
+ cg.revertToDefault(mKey, writeFlags());
} else {
- cg.writeEntry<QString>(mKey, mReference.toString());
+ cg.writeEntry<QString>(mKey, mReference.toString(), writeFlags());
}
mLoadedValue = mReference;
}
@@ -479,11 +489,11 @@ void KCoreConfigSkeleton::ItemEnum::writeConfig(KConfig *config)
if (mReference != mLoadedValue) { // WABA: Is this test needed?
KConfigGroup cg(config, mGroup);
if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
- cg.revertToDefault(mKey);
+ cg.revertToDefault(mKey, writeFlags());
} else if ((mReference >= 0) && (mReference < mChoices.count())) {
- cg.writeEntry(mKey, mChoices[mReference].name);
+ cg.writeEntry(mKey, mChoices[mReference].name, writeFlags());
} else {
- cg.writeEntry(mKey, mReference);
+ cg.writeEntry(mKey, mReference, writeFlags());
}
mLoadedValue = mReference;
}
@@ -879,10 +889,10 @@ void KCoreConfigSkeleton::ItemPathList::writeConfig(KConfig *config)
if (mReference != mLoadedValue) { // WABA: Is this test needed?
KConfigGroup cg(config, mGroup);
if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
- cg.revertToDefault(mKey);
+ cg.revertToDefault(mKey, writeFlags());
} else {
QStringList sl = mReference;
- cg.writePathEntry(mKey, sl);
+ cg.writePathEntry(mKey, sl, writeFlags());
}
mLoadedValue = mReference;
}
@@ -921,13 +931,13 @@ void KCoreConfigSkeleton::ItemUrlList::writeConfig(KConfig *config)
if (mReference != mLoadedValue) { // WABA: Is this test needed?
KConfigGroup cg(config, mGroup);
if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
- cg.revertToDefault(mKey);
+ cg.revertToDefault(mKey, writeFlags());
} else {
QStringList strList;
for (const QUrl &url : qAsConst(mReference)) {
strList.append(url.toString());
}
- cg.writeEntry<QStringList>(mKey, strList);
+ cg.writeEntry<QStringList>(mKey, strList, writeFlags());
}
mLoadedValue = mReference;
}
diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h
index b384129d..771d8cc9 100644
--- a/src/core/kcoreconfigskeleton.h
+++ b/src/core/kcoreconfigskeleton.h
@@ -133,6 +133,19 @@ public:
QString whatsThis() const;
/**
+ The write flags to be used when writing configuration.
+ @since 5.58
+ */
+ void setWriteFlags(KConfigBase::WriteConfigFlags flags);
+
+ /**
+ Return write flags to be used when writing configuration.
+ They should be passed to every call of writeEntry() and revertToDefault().
+ @since 5.58
+ */
+ KConfigBase::WriteConfigFlags writeFlags() const;
+
+ /**
* This function is called by @ref KCoreConfigSkeleton to read the value for this setting
* from a config file.
*/
@@ -141,6 +154,7 @@ public:
/**
* This function is called by @ref KCoreConfigSkeleton to write the value of this setting
* to a config file.
+ * Make sure to pass writeFlags() to every call of writeEntry() and revertToDefault().
*/
virtual void writeConfig(KConfig *) = 0;
@@ -274,9 +288,9 @@ public:
if (mReference != mLoadedValue) { // Is this needed?
KConfigGroup cg(config, mGroup);
if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
- cg.revertToDefault(mKey);
+ cg.revertToDefault(mKey, writeFlags());
} else {
- cg.writeEntry(mKey, mReference);
+ cg.writeEntry(mKey, mReference, writeFlags());
}
mLoadedValue = mReference;
}
diff --git a/src/core/kcoreconfigskeleton_p.h b/src/core/kcoreconfigskeleton_p.h
index 88a41d8d..41005c6f 100644
--- a/src/core/kcoreconfigskeleton_p.h
+++ b/src/core/kcoreconfigskeleton_p.h
@@ -52,8 +52,10 @@ class KConfigSkeletonItemPrivate
public:
KConfigSkeletonItemPrivate()
: mIsImmutable(true)
+ , mWriteFlags(KConfigBase::Normal)
{}
bool mIsImmutable; ///< Indicates this item is immutable
+ KConfigBase::WriteConfigFlags mWriteFlags; ///< The flags to pass to calls of writeEntry() and revertToDefault()
QString mLabel; ///< The label for this item
QString mToolTip; ///< The ToolTip text for this item
diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp
index b467a20a..abb8e115 100644
--- a/src/kconfig_compiler/kconfig_compiler.cpp
+++ b/src/kconfig_compiler/kconfig_compiler.cpp
@@ -94,6 +94,8 @@ public:
setUserTexts = codegenConfig.value(QStringLiteral("SetUserTexts"), false).toBool();
defaultGetters = codegenConfig.value(QStringLiteral("DefaultValueGetters"), QStringList()).toStringList();
allDefaultGetters = (defaultGetters.count() == 1) && (defaultGetters.at(0).toLower() == QLatin1String("true"));
+ notifiers = codegenConfig.value(QStringLiteral("Notifiers"), QStringList()).toStringList();
+ allNotifiers = ((notifiers.count() == 1) && (notifiers.at(0).toLower() == QLatin1String("true")));
globalEnums = codegenConfig.value(QStringLiteral("GlobalEnums"), false).toBool();
useEnumTypes = codegenConfig.value(QStringLiteral("UseEnumTypes"), false).toBool();
const QString trString = codegenConfig.value(QStringLiteral("TranslationSystem")).toString().toLower();
@@ -132,6 +134,7 @@ public:
QStringList sourceIncludes;
QStringList mutators;
QStringList defaultGetters;
+ QStringList notifiers;
QString qCategoryLoggingName;
QString headerExtension;
QString sourceExtension;
@@ -142,6 +145,7 @@ public:
bool globalEnums;
bool useEnumTypes;
bool itemAccessors;
+ bool allNotifiers;
TranslationSystem translationSystem;
QString translationDomain;
bool generateProperties;
@@ -2484,6 +2488,10 @@ int main(int argc, char **argv)
cpp << userTextsFunctions((*itEntry), cfg);
}
+ if (cfg.allNotifiers || cfg.notifiers.contains((*itEntry)->name())) {
+ cpp << " " << itemPath(*itEntry, cfg) << "->setWriteFlags(KConfigBase::Notify);" << endl;
+ }
+
cpp << " addItem( " << itemPath(*itEntry, cfg);
QString quotedName = (*itEntry)->name();
addQuotes(quotedName);