diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2021-02-22 17:38:09 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2021-02-22 17:38:09 +0200 |
commit | 8bed00ab34e31f2b9c70026d418d923913325798 (patch) | |
tree | f289c15575415a36bc19c047a2037998e9b11ce8 /src/core | |
parent | 186755fd56b58dc97250846c5305ef89f9487f86 (diff) | |
download | kconfig-8bed00ab34e31f2b9c70026d418d923913325798.tar.gz kconfig-8bed00ab34e31f2b9c70026d418d923913325798.tar.bz2 |
Run clang-format on all cpp/h files
NO_CHANGELOG
Diffstat (limited to 'src/core')
29 files changed, 911 insertions, 1108 deletions
diff --git a/src/core/bufferfragment_p.h b/src/core/bufferfragment_p.h index 3edbb6b6..f75af1d6 100644 --- a/src/core/bufferfragment_p.h +++ b/src/core/bufferfragment_p.h @@ -24,14 +24,16 @@ class KConfigIniBackend::BufferFragment { - public: - - BufferFragment() : d(nullptr), len(0) + BufferFragment() + : d(nullptr) + , len(0) { } - BufferFragment(char *buf, int size) : d(buf), len(size) + BufferFragment(char *buf, int size) + : d(buf) + , len(size) { } @@ -184,7 +186,7 @@ private: uint qHash(const KConfigIniBackend::BufferFragment fragment) { - const uchar *p = reinterpret_cast<const uchar*>(fragment.constData()); + const uchar *p = reinterpret_cast<const uchar *>(fragment.constData()); const int len = fragment.length(); // This algorithm is copied from qhash.cpp (Qt5 version). diff --git a/src/core/conversioncheck.h b/src/core/conversioncheck.h index 7f0e78a4..8537d81e 100644 --- a/src/core/conversioncheck.h +++ b/src/core/conversioncheck.h @@ -8,11 +8,11 @@ #ifndef CONVERSION_CHECK_H #define CONVERSION_CHECK_H -#include <QString> #include <QDate> #include <QPoint> -#include <QSize> #include <QRect> +#include <QSize> +#include <QString> #include <QVariant> class QColor; @@ -20,20 +20,21 @@ class QFont; namespace ConversionCheck { - // used to distinguish between supported/unsupported types -struct supported { }; -struct unsupported { }; +struct supported { +}; +struct unsupported { +}; // traits type class to define support for constraints -template <typename T> +template<typename T> struct QVconvertible { typedef unsupported toQString; typedef unsupported toQVariant; }; // constraint classes -template <typename T> +template<typename T> struct type_toQString { void constraint() { @@ -43,7 +44,7 @@ struct type_toQString { typename QVconvertible<T>::toQString y; }; -template <typename T> +template<typename T> struct type_toQVariant { void constraint() { @@ -55,7 +56,7 @@ struct type_toQVariant { // check if T is convertible to QString thru QVariant // if not supported can't be used in QList<T> functions -template <typename T> +template<typename T> inline void to_QString() { void (type_toQString<T>::*x)() = &type_toQString<T>::constraint; @@ -63,7 +64,7 @@ inline void to_QString() } // check if T is convertible to QVariant & supported in readEntry/writeEntry -template <typename T> +template<typename T> inline void to_QVariant() { void (type_toQVariant<T>::*x)() = &type_toQVariant<T>::constraint; @@ -74,10 +75,11 @@ inline void to_QVariant() // string_support - is supported by QVariant(type).toString(), // can be used in QList<T> functions // variant_support - has a QVariant constructor -#define QVConversions(type, string_support, variant_support) \ - template <> struct QVconvertible<type> {\ - typedef string_support toQString;\ - typedef variant_support toQVariant;\ +#define QVConversions(type, string_support, variant_support) \ + template<> \ + struct QVconvertible<type> { \ + typedef string_support toQString; \ + typedef variant_support toQVariant; \ } // The only types needed here are the types handled in readEntry/writeEntry @@ -108,4 +110,3 @@ QVConversions(QList<QUrl>, unsupported, supported); } #endif - diff --git a/src/core/kauthorized.cpp b/src/core/kauthorized.cpp index 1abd83eb..a08586c5 100644 --- a/src/core/kauthorized.cpp +++ b/src/core/kauthorized.cpp @@ -15,41 +15,54 @@ #include <ksharedconfig.h> #include <stdlib.h> // srand(), rand() #ifndef Q_OS_WIN -#include <unistd.h> #include <netdb.h> +#include <unistd.h> #endif #include <kconfiggroup.h> -#include <QRecursiveMutex> #include <QMutexLocker> +#include <QRecursiveMutex> extern bool kde_kiosk_exception; class URLActionRule { public: -#define checkExactMatch(s, b) \ - if (s.isEmpty()) b = true; \ - else if (s[s.length()-1] == QLatin1Char('!')) \ - { b = false; s.chop(1); } \ - else b = true; -#define checkStartWildCard(s, b) \ - if (s.isEmpty()) b = true; \ - else if (s[0] == QLatin1Char('*')) \ - { b = true; s.remove(0, 1); } \ - else b = false; -#define checkEqual(s, b) \ - b = (s == QLatin1String("=")); +#define checkExactMatch(s, b) \ + if (s.isEmpty()) \ + b = true; \ + else if (s[s.length() - 1] == QLatin1Char('!')) { \ + b = false; \ + s.chop(1); \ + } else \ + b = true; +#define checkStartWildCard(s, b) \ + if (s.isEmpty()) \ + b = true; \ + else if (s[0] == QLatin1Char('*')) { \ + b = true; \ + s.remove(0, 1); \ + } else \ + b = false; +#define checkEqual(s, b) b = (s == QLatin1String("=")); URLActionRule(const QByteArray &act, - const QString &bProt, const QString &bHost, const QString &bPath, - const QString &dProt, const QString &dHost, const QString &dPath, + const QString &bProt, + const QString &bHost, + const QString &bPath, + const QString &dProt, + const QString &dHost, + const QString &dPath, bool perm) - : action(act), - baseProt(bProt), baseHost(bHost), basePath(bPath), - destProt(dProt), destHost(dHost), destPath(dPath), - permission(perm) + : action(act) + , baseProt(bProt) + , baseHost(bHost) + , basePath(bPath) + , destProt(dProt) + , destHost(dHost) + , destPath(dPath) + , permission(perm) { checkExactMatch(baseProt, baseProtWildCard); checkStartWildCard(baseHost, baseHostWildCard); @@ -64,13 +77,11 @@ public: bool baseMatch(const QUrl &url, const QString &protClass) const { if (baseProtWildCard) { - if (!baseProt.isEmpty() && !url.scheme().startsWith(baseProt) && - (protClass.isEmpty() || (protClass != baseProt))) { + if (!baseProt.isEmpty() && !url.scheme().startsWith(baseProt) && (protClass.isEmpty() || (protClass != baseProt))) { return false; } } else { - if ((url.scheme() != baseProt) && - (protClass.isEmpty() || (protClass != baseProt))) { + if ((url.scheme() != baseProt) && (protClass.isEmpty() || (protClass != baseProt))) { return false; } } @@ -98,18 +109,15 @@ public: bool destMatch(const QUrl &url, const QString &protClass, const QUrl &base, const QString &baseClass) const { if (destProtEqual) { - if ((url.scheme() != base.scheme()) && - (protClass.isEmpty() || baseClass.isEmpty() || protClass != baseClass)) { + if ((url.scheme() != base.scheme()) && (protClass.isEmpty() || baseClass.isEmpty() || protClass != baseClass)) { return false; } } else if (destProtWildCard) { - if (!destProt.isEmpty() && !url.scheme().startsWith(destProt) && - (protClass.isEmpty() || (protClass != destProt))) { + if (!destProt.isEmpty() && !url.scheme().startsWith(destProt) && (protClass.isEmpty() || (protClass != destProt))) { return false; } } else { - if ((url.scheme() != destProt) && - (protClass.isEmpty() || (protClass != destProt))) { + if ((url.scheme() != destProt) && (protClass.isEmpty() || (protClass != destProt))) { return false; } } @@ -151,8 +159,8 @@ public: bool destProtWildCard : 1; bool destHostWildCard : 1; bool destPathWildCard : 1; - bool destProtEqual : 1; - bool destHostEqual : 1; + bool destProtEqual : 1; + bool destHostEqual : 1; bool permission; }; @@ -160,7 +168,8 @@ class KAuthorizedPrivate { public: KAuthorizedPrivate() - : actionRestrictions(false), blockEverything(false) + : actionRestrictions(false) + , blockEverything(false) { Q_ASSERT_X(QCoreApplication::instance(), "KAuthorizedPrivate()", "There has to be an existing QCoreApplication::instance() pointer"); @@ -185,12 +194,12 @@ public: }; Q_GLOBAL_STATIC(KAuthorizedPrivate, authPrivate) -#define MY_D KAuthorizedPrivate *d=authPrivate(); +#define MY_D KAuthorizedPrivate *d = authPrivate(); bool KAuthorized::authorize(const QString &genericAction) { - MY_D - if (d->blockEverything) { + MY_D if (d->blockEverything) + { return false; } @@ -204,8 +213,8 @@ bool KAuthorized::authorize(const QString &genericAction) bool KAuthorized::authorizeAction(const QString &action) { - MY_D - if (d->blockEverything) { + MY_D if (d->blockEverything) + { return false; } if (!d->actionRestrictions || action.isEmpty()) { @@ -235,8 +244,7 @@ QStringList KAuthorized::authorizeControlModules(const QStringList &menuIds) { KConfigGroup cg(KSharedConfig::openConfig(), "KDE Control Module Restrictions"); QStringList result; - for (QStringList::ConstIterator it = menuIds.begin(); - it != menuIds.end(); ++it) { + for (QStringList::ConstIterator it = menuIds.begin(); it != menuIds.end(); ++it) { if (cg.readEntry(*it, true)) { result.append(*it); } @@ -247,49 +255,37 @@ QStringList KAuthorized::authorizeControlModules(const QStringList &menuIds) // Exported for unittests (e.g. in KIO, we're missing tests for this in kconfig) KCONFIGCORE_EXPORT void loadUrlActionRestrictions(const KConfigGroup &cg) { - MY_D - const QString Any; + MY_D const QString Any; d->urlActionRestrictions.clear(); - d->urlActionRestrictions.append( - URLActionRule("open", Any, Any, Any, Any, Any, Any, true)); - d->urlActionRestrictions.append( - URLActionRule("list", Any, Any, Any, Any, Any, Any, true)); -// TEST: -// d->urlActionRestrictions.append( -// URLActionRule("list", Any, Any, Any, Any, Any, Any, false)); -// d->urlActionRestrictions.append( -// URLActionRule("list", Any, Any, Any, "file", Any, QDir::homePath(), true)); - d->urlActionRestrictions.append( - URLActionRule("link", Any, Any, Any, QStringLiteral(":internet"), Any, Any, true)); - d->urlActionRestrictions.append( - URLActionRule("redirect", Any, Any, Any, QStringLiteral(":internet"), Any, Any, true)); + d->urlActionRestrictions.append(URLActionRule("open", Any, Any, Any, Any, Any, Any, true)); + d->urlActionRestrictions.append(URLActionRule("list", Any, Any, Any, Any, Any, Any, true)); + // TEST: + // d->urlActionRestrictions.append( + // URLActionRule("list", Any, Any, Any, Any, Any, Any, false)); + // d->urlActionRestrictions.append( + // URLActionRule("list", Any, Any, Any, "file", Any, QDir::homePath(), true)); + d->urlActionRestrictions.append(URLActionRule("link", Any, Any, Any, QStringLiteral(":internet"), Any, Any, true)); + d->urlActionRestrictions.append(URLActionRule("redirect", Any, Any, Any, QStringLiteral(":internet"), Any, Any, true)); // We allow redirections to file: but not from internet protocols, redirecting to file: // is very popular among io-slaves and we don't want to break them - d->urlActionRestrictions.append( - URLActionRule("redirect", Any, Any, Any, QStringLiteral("file"), Any, Any, true)); - d->urlActionRestrictions.append( - URLActionRule("redirect", QStringLiteral(":internet"), Any, Any, QStringLiteral("file"), Any, Any, false)); + d->urlActionRestrictions.append(URLActionRule("redirect", Any, Any, Any, QStringLiteral("file"), Any, Any, true)); + d->urlActionRestrictions.append(URLActionRule("redirect", QStringLiteral(":internet"), Any, Any, QStringLiteral("file"), Any, Any, false)); // local protocols may redirect everywhere - d->urlActionRestrictions.append( - URLActionRule("redirect", QStringLiteral(":local"), Any, Any, Any, Any, Any, true)); + d->urlActionRestrictions.append(URLActionRule("redirect", QStringLiteral(":local"), Any, Any, Any, Any, Any, true)); // Anyone may redirect to about: - d->urlActionRestrictions.append( - URLActionRule("redirect", Any, Any, Any, QStringLiteral("about"), Any, Any, true)); + d->urlActionRestrictions.append(URLActionRule("redirect", Any, Any, Any, QStringLiteral("about"), Any, Any, true)); // Anyone may redirect to mailto: - d->urlActionRestrictions.append( - URLActionRule("redirect", Any, Any, Any, QStringLiteral("mailto"), Any, Any, true)); + d->urlActionRestrictions.append(URLActionRule("redirect", Any, Any, Any, QStringLiteral("mailto"), Any, Any, true)); // Anyone may redirect to itself, cq. within it's own group - d->urlActionRestrictions.append( - URLActionRule("redirect", Any, Any, Any, QStringLiteral("="), Any, Any, true)); + d->urlActionRestrictions.append(URLActionRule("redirect", Any, Any, Any, QStringLiteral("="), Any, Any, true)); - d->urlActionRestrictions.append( - URLActionRule("redirect", QStringLiteral("about"), Any, Any, Any, Any, Any, true)); + d->urlActionRestrictions.append(URLActionRule("redirect", QStringLiteral("about"), Any, Any, Any, Any, Any, true)); int count = cg.readEntry("rule_count", 0); QString keyFormat = QStringLiteral("rule_%1"); @@ -326,8 +322,7 @@ KCONFIGCORE_EXPORT void loadUrlActionRestrictions(const KConfigGroup &cg) urlPath.replace(0, 4, QDir::tempPath()); } - d->urlActionRestrictions.append( - URLActionRule(action, refProt, refHost, refPath, urlProt, urlHost, urlPath, bEnabled)); + d->urlActionRestrictions.append(URLActionRule(action, refProt, refHost, refPath, urlProt, urlHost, urlPath, bEnabled)); } } @@ -339,25 +334,23 @@ namespace KAuthorized */ KCONFIGCORE_EXPORT void allowUrlActionInternal(const QString &action, const QUrl &_baseURL, const QUrl &_destURL) { - MY_D - QMutexLocker locker((&d->mutex)); + MY_D QMutexLocker locker((&d->mutex)); const QString basePath = _baseURL.adjusted(QUrl::StripTrailingSlash).path(); const QString destPath = _destURL.adjusted(QUrl::StripTrailingSlash).path(); - d->urlActionRestrictions.append(URLActionRule - (action.toLatin1(), _baseURL.scheme(), _baseURL.host(), basePath, - _destURL.scheme(), _destURL.host(), destPath, true)); + d->urlActionRestrictions.append( + URLActionRule(action.toLatin1(), _baseURL.scheme(), _baseURL.host(), basePath, _destURL.scheme(), _destURL.host(), destPath, true)); } /** * Helper for KAuthorized::authorizeUrlAction in KIO * @private */ -KCONFIGCORE_EXPORT bool authorizeUrlActionInternal(const QString &action, const QUrl &_baseURL, const QUrl &_destURL, const QString &baseClass, const QString &destClass) +KCONFIGCORE_EXPORT bool +authorizeUrlActionInternal(const QString &action, const QUrl &_baseURL, const QUrl &_destURL, const QString &baseClass, const QString &destClass) { - MY_D - QMutexLocker locker(&(d->mutex)); + MY_D QMutexLocker locker(&(d->mutex)); if (d->blockEverything) { return false; } @@ -380,9 +373,8 @@ KCONFIGCORE_EXPORT bool authorizeUrlActionInternal(const QString &action, const for (const URLActionRule &rule : qAsConst(d->urlActionRestrictions)) { if ((result != rule.permission) && // No need to check if it doesn't make a difference - (action == QLatin1String(rule.action.constData())) && - rule.baseMatch(baseURL, baseClass) && - rule.destMatch(destURL, destClass, baseURL, baseClass)) { + (action == QLatin1String(rule.action.constData())) && rule.baseMatch(baseURL, baseClass) + && rule.destMatch(destURL, destClass, baseURL, baseClass)) { result = rule.permission; } } diff --git a/src/core/kauthorized.h b/src/core/kauthorized.h index 57a99e23..ac3cfa7e 100644 --- a/src/core/kauthorized.h +++ b/src/core/kauthorized.h @@ -16,13 +16,13 @@ class QUrl; class QString; /** -* The functions in this namespace provide the core of the Kiosk action -* restriction system; the KIO and KXMLGui frameworks build on this. -* -* The relevant settings are read from the application's KSharedConfig -* instance, so actions can be disabled on a per-application or global -* basis (by using the kdeglobals file). -*/ + * The functions in this namespace provide the core of the Kiosk action + * restriction system; the KIO and KXMLGui frameworks build on this. + * + * The relevant settings are read from the application's KSharedConfig + * instance, so actions can be disabled on a per-application or global + * basis (by using the kdeglobals file). + */ namespace KAuthorized { /** diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp index ed389ea3..2da1dd48 100644 --- a/src/core/kconfig.cpp +++ b/src/core/kconfig.cpp @@ -19,20 +19,19 @@ #include "kconfigbackend_p.h" #include "kconfiggroup.h" -#include <QCoreApplication> -#include <QProcess> +#include <QBasicMutex> #include <QByteArray> +#include <QCoreApplication> +#include <QDir> #include <QFile> #include <QLocale> -#include <QDir> +#include <QMutexLocker> #include <QProcess> #include <QSet> -#include <QBasicMutex> -#include <QMutexLocker> #if KCONFIG_USE_DBUS -#include <QDBusMessage> #include <QDBusConnection> +#include <QDBusMessage> #include <QDBusMetaType> #endif @@ -51,12 +50,17 @@ static const Qt::CaseSensitivity sPathCaseSensitivity = Qt::CaseSensitive; static const Qt::CaseSensitivity sPathCaseSensitivity = Qt::CaseInsensitive; #endif -KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags, - QStandardPaths::StandardLocation resourceType) - : openFlags(flags), resourceType(resourceType), mBackend(nullptr), - bDynamicBackend(true), bDirty(false), bReadDefaults(false), - bFileImmutable(false), bForceGlobal(false), bSuppressGlobal(false), - configState(KConfigBase::NoAccess) +KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags, QStandardPaths::StandardLocation resourceType) + : openFlags(flags) + , resourceType(resourceType) + , mBackend(nullptr) + , bDynamicBackend(true) + , bDirty(false) + , bReadDefaults(false) + , bFileImmutable(false) + , bForceGlobal(false) + , bSuppressGlobal(false) + , configState(KConfigBase::NoAccess) { const bool isTestMode = QStandardPaths::isTestModeEnabled(); // If sGlobalFileName was initialised and testMode has been toggled, @@ -68,7 +72,7 @@ KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags, static QBasicAtomicInt use_etc_kderc = Q_BASIC_ATOMIC_INITIALIZER(-1); if (use_etc_kderc.loadRelaxed() < 0) { - use_etc_kderc.storeRelaxed( !qEnvironmentVariableIsSet("KDE_SKIP_KDERC")); // for unit tests + use_etc_kderc.storeRelaxed(!qEnvironmentVariableIsSet("KDE_SKIP_KDERC")); // for unit tests } if (use_etc_kderc.loadRelaxed()) { etc_kderc = @@ -83,20 +87,20 @@ KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags, } } -// if (!mappingsRegistered) { -// KEntryMap tmp; -// if (!etc_kderc.isEmpty()) { -// QExplicitlySharedDataPointer<KConfigBackend> backend = KConfigBackend::create(etc_kderc, QLatin1String("INI")); -// backend->parseConfig( "en_US", tmp, KConfigBackend::ParseDefaults); -// } -// const QString kde5rc(QDir::home().filePath(".kde5rc")); -// if (KStandardDirs::checkAccess(kde5rc, R_OK)) { -// QExplicitlySharedDataPointer<KConfigBackend> backend = KConfigBackend::create(kde5rc, QLatin1String("INI")); -// backend->parseConfig( "en_US", tmp, KConfigBackend::ParseOptions()); -// } -// KConfigBackend::registerMappings(tmp); -// mappingsRegistered = true; -// } + // if (!mappingsRegistered) { + // KEntryMap tmp; + // if (!etc_kderc.isEmpty()) { + // QExplicitlySharedDataPointer<KConfigBackend> backend = KConfigBackend::create(etc_kderc, QLatin1String("INI")); + // backend->parseConfig( "en_US", tmp, KConfigBackend::ParseDefaults); + // } + // const QString kde5rc(QDir::home().filePath(".kde5rc")); + // if (KStandardDirs::checkAccess(kde5rc, R_OK)) { + // QExplicitlySharedDataPointer<KConfigBackend> backend = KConfigBackend::create(kde5rc, QLatin1String("INI")); + // backend->parseConfig( "en_US", tmp, KConfigBackend::ParseOptions()); + // } + // KConfigBackend::registerMappings(tmp); + // mappingsRegistered = true; + // } setLocale(QLocale().name()); } @@ -110,8 +114,7 @@ bool KConfigPrivate::lockLocal() return true; } -void KConfigPrivate::copyGroup(const QByteArray &source, const QByteArray &destination, - KConfigGroup *otherGroup, KConfigBase::WriteConfigFlags flags) const +void KConfigPrivate::copyGroup(const QByteArray &source, const QByteArray &destination, KConfigGroup *otherGroup, KConfigBase::WriteConfigFlags flags) const { KEntryMap &otherMap = otherGroup->config()->d_ptr->entryMap; const int len = source.length(); @@ -144,7 +147,7 @@ void KConfigPrivate::copyGroup(const QByteArray &source, const QByteArray &desti newKey.mGroup.replace(0, len, destination); } - KEntry entry = entryMap[ entryMapIt.key() ]; + KEntry entry = entryMap[entryMapIt.key()]; dirtied = entry.bDirty = flags & KConfigBase::Persistent; if (flags & KConfigBase::Global) { @@ -182,10 +185,7 @@ QString KConfigPrivate::expandString(const QString &value) ++nEndPos; aVarName = aValue.midRef(nDollarPos + 2, nEndPos - nDollarPos - 3); } else { - while (nEndPos < aValue.length() && - (aValue[nEndPos].isNumber() || - aValue[nEndPos].isLetter() || - aValue[nEndPos] == QLatin1Char('_'))) { + while (nEndPos < aValue.length() && (aValue[nEndPos].isNumber() || aValue[nEndPos].isLetter() || aValue[nEndPos] == QLatin1Char('_'))) { ++nEndPos; } aVarName = aValue.midRef(nDollarPos + 1, nEndPos - nDollarPos - 1); @@ -227,8 +227,7 @@ QString KConfigPrivate::expandString(const QString &value) return aValue; } -KConfig::KConfig(const QString &file, OpenFlags mode, - QStandardPaths::StandardLocation resourceType) +KConfig::KConfig(const QString &file, OpenFlags mode, QStandardPaths::StandardLocation resourceType) : d_ptr(new KConfigPrivate(mode, resourceType)) { d_ptr->changeFileName(file); // set the local file name @@ -298,7 +297,7 @@ QStringList KConfigPrivate::groupList(const QByteArray &group) const static bool isGroupOrSubGroupMatch(const QByteArray &potentialGroup, const QByteArray &group) { if (!potentialGroup.startsWith(group)) { - return false; + return false; } return potentialGroup.length() == group.length() || potentialGroup[group.length()] == '\x1d'; } @@ -441,7 +440,7 @@ bool KConfig::sync() if (d->configState == ReadWrite && !tmp->lock()) { qCWarning(KCONFIG_CORE_LOG) << "couldn't lock global file"; - //unlock the local config if we're returning early + // unlock the local config if we're returning early if (d->mBackend->isLocked()) { d->mBackend->unlock(); } @@ -484,9 +483,7 @@ void KConfigPrivate::notifyClients(const QHash<QString, QByteArrayList> &changes qDBusRegisterMetaType<QHash<QString, QByteArrayList>>(); - QDBusMessage message = QDBusMessage::createSignal(path, - QStringLiteral("org.kde.kconfig.notify"), - QStringLiteral("ConfigChanged")); + QDBusMessage message = QDBusMessage::createSignal(path, QStringLiteral("org.kde.kconfig.notify"), QStringLiteral("ConfigChanged")); message.setArguments({QVariant::fromValue(changes)}); QDBusConnection::sessionBus().send(message); #else @@ -520,7 +517,7 @@ void KConfig::checkUpdate(const QString &id, const QString &updateFile) const QString cfg_id = updateFile + QLatin1Char(':') + id; const QStringList ids = cg.readEntry("update_info", QStringList()); if (!ids.contains(cfg_id)) { - QProcess::execute(QStringLiteral(KCONF_UPDATE_INSTALL_LOCATION), QStringList { QStringLiteral("--check"), updateFile }); + QProcess::execute(QStringLiteral(KCONF_UPDATE_INSTALL_LOCATION), QStringList{QStringLiteral("--check"), updateFile}); reparseConfiguration(); } } @@ -550,15 +547,13 @@ QString KConfig::name() const return d->fileName; } - KConfig::OpenFlags KConfig::openFlags() const { Q_D(const KConfig); return d->openFlags; } -struct KConfigStaticData -{ +struct KConfigStaticData { QString globalMainConfigName; // Keep a copy so we can use it in global dtors, after qApp is gone QStringList appArgs; @@ -572,7 +567,7 @@ void KConfig::setMainConfigName(const QString &str) QString KConfig::mainConfigName() { - KConfigStaticData* data = globalData(); + KConfigStaticData *data = globalData(); if (data->appArgs.isEmpty()) data->appArgs = QCoreApplication::arguments(); @@ -690,7 +685,7 @@ QStringList KConfigPrivate::getGlobalFiles() const void KConfigPrivate::parseGlobalFiles() { const QStringList globalFiles = getGlobalFiles(); -// qDebug() << "parsing global files" << globalFiles; + // qDebug() << "parsing global files" << globalFiles; // TODO: can we cache the values in etc_kderc / other global files // on a per-application basis? @@ -712,7 +707,6 @@ void KConfigPrivate::parseConfigFiles() { // can only read the file if there is a backend and a file name if (mBackend && !fileName.isEmpty()) { - bFileImmutable = false; QList<QString> files; @@ -745,7 +739,7 @@ void KConfigPrivate::parseConfigFiles() files = QList<QString>(extraFiles.cbegin(), extraFiles.cend()) + files; } -// qDebug() << "parsing local files" << files; + // qDebug() << "parsing local files" << files; const QByteArray utf8Locale = locale.toUtf8(); for (const QString &file : qAsConst(files)) { @@ -762,8 +756,7 @@ void KConfigPrivate::parseConfigFiles() } } else { QExplicitlySharedDataPointer<KConfigBackend> backend = KConfigBackend::create(file); - bFileImmutable = (backend->parseConfig(utf8Locale, entryMap, - KConfigBackend::ParseDefaults | KConfigBackend::ParseExpansions) + bFileImmutable = (backend->parseConfig(utf8Locale, entryMap, KConfigBackend::ParseDefaults | KConfigBackend::ParseExpansions) == KConfigBackend::ParseImmutable); } @@ -844,7 +837,7 @@ bool KConfig::isImmutable() const bool KConfig::isGroupImmutableImpl(const QByteArray &aGroup) const { Q_D(const KConfig); - return isImmutable() || d->entryMap.getEntryOption(aGroup, {},{}, KEntryMap::EntryImmutable); + return isImmutable() || d->entryMap.getEntryOption(aGroup, {}, {}, KEntryMap::EntryImmutable); } #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(4, 0) @@ -925,13 +918,12 @@ bool KConfig::isConfigWritable(bool warnUser) errorMsg += QCoreApplication::translate("KConfig", "Please contact your system administrator."); QString cmdToExec = QStandardPaths::findExecutable(QStringLiteral("kdialog")); if (!cmdToExec.isEmpty()) { - QProcess::execute(cmdToExec, QStringList() - << QStringLiteral("--title") << QCoreApplication::applicationName() - << QStringLiteral("--msgbox") << errorMsg); + QProcess::execute(cmdToExec, + QStringList() << QStringLiteral("--title") << QCoreApplication::applicationName() << QStringLiteral("--msgbox") << errorMsg); } } - d->configState = allWritable ? ReadWrite : ReadOnly; // update the read/write status + d->configState = allWritable ? ReadWrite : ReadOnly; // update the read/write status return allWritable; } @@ -948,15 +940,13 @@ bool KConfig::hasGroupImpl(const QByteArray &aGroup) const bool KConfigPrivate::canWriteEntry(const QByteArray &group, const char *key, bool isDefault) const { - if (bFileImmutable || - entryMap.getEntryOption(group, key, KEntryMap::SearchLocalized, KEntryMap::EntryImmutable)) { + if (bFileImmutable || entryMap.getEntryOption(group, key, KEntryMap::SearchLocalized, KEntryMap::EntryImmutable)) { return isDefault; } return true; } -void KConfigPrivate::putData(const QByteArray &group, const char *key, - const QByteArray &value, KConfigBase::WriteConfigFlags flags, bool expand) +void KConfigPrivate::putData(const QByteArray &group, const char *key, const QByteArray &value, KConfigBase::WriteConfigFlags flags, bool expand) { KEntryMap::EntryOptions options = convertToOptions(flags); @@ -987,8 +977,7 @@ void KConfigPrivate::revertEntry(const QByteArray &group, const char *key, KConf } } -QByteArray KConfigPrivate::lookupData(const QByteArray &group, const char *key, - KEntryMap::SearchFlags flags) const +QByteArray KConfigPrivate::lookupData(const QByteArray &group, const char *key, KEntryMap::SearchFlags flags) const { if (bReadDefaults) { flags |= KEntryMap::SearchDefaults; @@ -1000,8 +989,7 @@ QByteArray KConfigPrivate::lookupData(const QByteArray &group, const char *key, return it->mValue; } -QString KConfigPrivate::lookupData(const QByteArray &group, const char *key, - KEntryMap::SearchFlags flags, bool *expand) const +QString KConfigPrivate::lookupData(const QByteArray &group, const char *key, KEntryMap::SearchFlags flags, bool *expand) const { if (bReadDefaults) { flags |= KEntryMap::SearchDefaults; diff --git a/src/core/kconfig.h b/src/core/kconfig.h index 4b652059..792a9a6b 100644 --- a/src/core/kconfig.h +++ b/src/core/kconfig.h @@ -15,11 +15,11 @@ #include <kconfigcore_export.h> -#include <QString> -#include <QVariant> #include <QByteArray> #include <QList> #include <QStandardPaths> +#include <QString> +#include <QVariant> class KConfigGroup; class KEntryMap; @@ -80,13 +80,13 @@ public: * @see OpenFlags */ enum OpenFlag { - IncludeGlobals = 0x01, ///< Blend kdeglobals into the config object. - CascadeConfig = 0x02, ///< Cascade to system-wide config files. + IncludeGlobals = 0x01, ///< Blend kdeglobals into the config object. + CascadeConfig = 0x02, ///< Cascade to system-wide config files. - SimpleConfig = 0x00, ///< Just a single config file. - NoCascade = IncludeGlobals, ///< Include user's globals, but omit system settings. - NoGlobals = CascadeConfig, ///< Cascade to system settings, but omit user's globals. - FullConfig = IncludeGlobals | CascadeConfig, ///< Fully-fledged config, including globals and cascading to system settings + SimpleConfig = 0x00, ///< Just a single config file. + NoCascade = IncludeGlobals, ///< Include user's globals, but omit system settings. + NoGlobals = CascadeConfig, ///< Cascade to system settings, but omit user's globals. + FullConfig = IncludeGlobals | CascadeConfig, ///< Fully-fledged config, including globals and cascading to system settings }; /** * Stores a combination of #OpenFlag values. @@ -121,7 +121,8 @@ public: * * @sa KSharedConfig::openConfig(const QString&, OpenFlags, QStandardPaths::StandardLocation) */ - explicit KConfig(const QString &file = QString(), OpenFlags mode = FullConfig, + explicit KConfig(const QString &file = QString(), + OpenFlags mode = FullConfig, QStandardPaths::StandardLocation type = QStandardPaths::GenericConfigLocation); /** diff --git a/src/core/kconfig_p.h b/src/core/kconfig_p.h index 917872f3..b201df17 100644 --- a/src/core/kconfig_p.h +++ b/src/core/kconfig_p.h @@ -11,18 +11,19 @@ #ifndef KCONFIG_P_H #define KCONFIG_P_H -#include "kconfigdata.h" #include "kconfigbackend_p.h" +#include "kconfigdata.h" #include "kconfiggroup.h" -#include <QStringList> -#include <QStack> -#include <QFile> #include <QDir> +#include <QFile> +#include <QStack> +#include <QStringList> class KConfigPrivate { friend class KConfig; + public: KConfig::OpenFlags openFlags; QStandardPaths::StandardLocation resourceType; @@ -31,19 +32,15 @@ public: // functions for KConfigGroup bool canWriteEntry(const QByteArray &group, const char *key, bool isDefault = false) const; - QString lookupData(const QByteArray &group, const char *key, KEntryMap::SearchFlags flags, - bool *expand) const; + QString lookupData(const QByteArray &group, const char *key, KEntryMap::SearchFlags flags, bool *expand) const; QByteArray lookupData(const QByteArray &group, const char *key, KEntryMap::SearchFlags flags) const; - void putData(const QByteArray &group, const char *key, const QByteArray &value, - KConfigBase::WriteConfigFlags flags, bool expand = false); - void revertEntry(const QByteArray &group, const char *key, - KConfigBase::WriteConfigFlags flags); + void putData(const QByteArray &group, const char *key, const QByteArray &value, KConfigBase::WriteConfigFlags flags, bool expand = false); + void revertEntry(const QByteArray &group, const char *key, KConfigBase::WriteConfigFlags flags); QStringList groupList(const QByteArray &group) const; // copies the entries from @p source to @p otherGroup changing all occurrences // of @p source with @p destination - void copyGroup(const QByteArray &source, const QByteArray &destination, - KConfigGroup *otherGroup, KConfigBase::WriteConfigFlags flags) const; + void copyGroup(const QByteArray &source, const QByteArray &destination, KConfigGroup *otherGroup, KConfigBase::WriteConfigFlags flags) const; QStringList keyListImpl(const QByteArray &theGroup) const; QSet<QByteArray> allSubGroups(const QByteArray &parentGroup) const; bool hasNonDeletedEntries(const QByteArray &group) const; @@ -55,20 +52,19 @@ public: protected: QExplicitlySharedDataPointer<KConfigBackend> mBackend; - KConfigPrivate(KConfig::OpenFlags flags, - QStandardPaths::StandardLocation type); + KConfigPrivate(KConfig::OpenFlags flags, QStandardPaths::StandardLocation type); virtual ~KConfigPrivate() { } - bool bDynamicBackend: 1; // do we own the backend? + bool bDynamicBackend : 1; // do we own the backend? private: - bool bDirty: 1; - bool bReadDefaults: 1; - bool bFileImmutable: 1; - bool bForceGlobal: 1; - bool bSuppressGlobal: 1; + bool bDirty : 1; + bool bReadDefaults : 1; + bool bFileImmutable : 1; + bool bForceGlobal : 1; + bool bSuppressGlobal : 1; static bool mappingsRegistered; diff --git a/src/core/kconfigbackend.cpp b/src/core/kconfigbackend.cpp index 0f95a5f6..13455dbd 100644 --- a/src/core/kconfigbackend.cpp +++ b/src/core/kconfigbackend.cpp @@ -10,14 +10,14 @@ #include "kconfigbackend_p.h" #include <QDateTime> -#include <QStringList> +#include <QDebug> #include <QDir> #include <QFileInfo> #include <QHash> -#include <QDebug> +#include <QStringList> -#include "kconfigini_p.h" #include "kconfigdata.h" +#include "kconfigini_p.h" typedef QExplicitlySharedDataPointer<KConfigBackend> BackendPtr; @@ -38,7 +38,7 @@ void KConfigBackend::registerMappings(const KEntryMap & /*entryMap*/) BackendPtr KConfigBackend::create(const QString &file, const QString &sys) { - //qDebug() << "creating a backend for file" << file << "with system" << sys; + // qDebug() << "creating a backend for file" << file << "with system" << sys; KConfigBackend *backend = nullptr; #if 0 // TODO port to Qt5 plugin loading @@ -61,7 +61,7 @@ BackendPtr KConfigBackend::create(const QString &file, const QString &sys) Q_UNUSED(sys); #endif - //qDebug() << "default creation of the Ini backend"; + // qDebug() << "default creation of the Ini backend"; backend = new KConfigIniBackend; backend->setFilePath(file); return BackendPtr(backend); diff --git a/src/core/kconfigbackend_p.h b/src/core/kconfigbackend_p.h index 7eb1774e..5b38634f 100644 --- a/src/core/kconfigbackend_p.h +++ b/src/core/kconfigbackend_p.h @@ -10,12 +10,12 @@ #ifndef KCONFIGBACKEND_H #define KCONFIGBACKEND_H +#include <QExplicitlySharedDataPointer> #include <QObject> #include <QString> -#include <QExplicitlySharedDataPointer> -#include <kconfigcore_export.h> #include <kconfigbase.h> +#include <kconfigcore_export.h> class KConfigBackendPrivate; class KEntryMap; @@ -48,8 +48,7 @@ public: * @param system the configuration system to use * @return a KConfigBackend object to be used with KConfig */ - static QExplicitlySharedDataPointer<KConfigBackend> create(const QString &fileName = QString(), - const QString &system = QString()); + static QExplicitlySharedDataPointer<KConfigBackend> create(const QString &fileName = QString(), const QString &system = QString()); /** * Registers mappings from directories/files to configuration systems @@ -99,9 +98,7 @@ public: * @param options See ParseOptions * @return See ParseInfo */ - virtual ParseInfo parseConfig(const QByteArray &locale, - KEntryMap &pWriteBackMap, - ParseOptions options = ParseOptions()) = 0; + virtual ParseInfo parseConfig(const QByteArray &locale, KEntryMap &pWriteBackMap, ParseOptions options = ParseOptions()) = 0; /** * Write the @em dirty entries to permanent storage @@ -112,8 +109,7 @@ public: * * @return @c true if the write was successful, @c false if writing the configuration failed */ - virtual bool writeConfig(const QByteArray &locale, KEntryMap &entryMap, - WriteOptions options) = 0; + virtual bool writeConfig(const QByteArray &locale, KEntryMap &entryMap, WriteOptions options) = 0; /** * If isWritable() returns false, writeConfig() will always fail. @@ -185,8 +181,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(KConfigBackend::WriteOptions) /** * Register a KConfig backend when it is contained in a loadable module */ -#define K_EXPORT_KCONFIGBACKEND(libname, classname) \ - K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) +#define K_EXPORT_KCONFIGBACKEND(libname, classname) K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) #endif #endif // KCONFIGBACKEND_H diff --git a/src/core/kconfigbase.cpp b/src/core/kconfigbase.cpp index 6bae0e25..9eee6420 100644 --- a/src/core/kconfigbase.cpp +++ b/src/core/kconfigbase.cpp @@ -89,10 +89,13 @@ bool KConfigBase::isGroupImmutable(const char *aGroup) const } KConfigBase::~KConfigBase() -{} +{ +} KConfigBase::KConfigBase() -{} +{ +} void KConfigBase::virtual_hook(int, void *) -{} +{ +} diff --git a/src/core/kconfigbase.h b/src/core/kconfigbase.h index a7693275..79af8854 100644 --- a/src/core/kconfigbase.h +++ b/src/core/kconfigbase.h @@ -56,9 +56,9 @@ public: */ Normal = Persistent, /**< - * Save the entry to the application specific config file without - * a locale tag. This is the default. - */ + * Save the entry to the application specific config file without + * a locale tag. This is the default. + */ }; /** diff --git a/src/core/kconfigdata.cpp b/src/core/kconfigdata.cpp index 5ead8167..accf869b 100644 --- a/src/core/kconfigdata.cpp +++ b/src/core/kconfigdata.cpp @@ -11,28 +11,26 @@ QDebug operator<<(QDebug dbg, const KEntryKey &key) { - dbg.nospace() << "[" << key.mGroup << ", " << key.mKey << (key.bLocal ? " localized" : "") << - (key.bDefault ? " default" : "") << (key.bRaw ? " raw" : "") << "]"; + dbg.nospace() << "[" << key.mGroup << ", " << key.mKey << (key.bLocal ? " localized" : "") << (key.bDefault ? " default" : "") << (key.bRaw ? " raw" : "") + << "]"; return dbg.space(); } QDebug operator<<(QDebug dbg, const KEntry &entry) { - dbg.nospace() << "[" << entry.mValue << (entry.bDirty ? " dirty" : "") << - (entry.bGlobal ? " global" : "") << (entry.bImmutable ? " immutable" : "") << - (entry.bDeleted ? " deleted" : "") << (entry.bReverted ? " reverted" : "") << - (entry.bExpand ? " expand" : "") << "]"; + dbg.nospace() << "[" << entry.mValue << (entry.bDirty ? " dirty" : "") << (entry.bGlobal ? " global" : "") << (entry.bImmutable ? " immutable" : "") + << (entry.bDeleted ? " deleted" : "") << (entry.bReverted ? " reverted" : "") << (entry.bExpand ? " expand" : "") << "]"; return dbg.space(); } -QMap< KEntryKey, KEntry >::Iterator KEntryMap::findExactEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) +QMap<KEntryKey, KEntry>::Iterator KEntryMap::findExactEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) { KEntryKey theKey(group, key, bool(flags & SearchLocalized), bool(flags & SearchDefaults)); return find(theKey); } -QMap< KEntryKey, KEntry >::Iterator KEntryMap::findEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) +QMap<KEntryKey, KEntry>::Iterator KEntryMap::findEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) { KEntryKey theKey(group, key, false, bool(flags & SearchDefaults)); @@ -50,7 +48,7 @@ QMap< KEntryKey, KEntry >::Iterator KEntryMap::findEntry(const QByteArray &group return find(theKey); } -QMap< KEntryKey, KEntry >::ConstIterator KEntryMap::findEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) const +QMap<KEntryKey, KEntry>::ConstIterator KEntryMap::findEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) const { KEntryKey theKey(group, key, false, bool(flags & SearchDefaults)); @@ -95,11 +93,11 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q if (it != end()) { if (it->bImmutable) { - return false; // we cannot change this entry. Inherits group immutability. + return false; // we cannot change this entry. Inherits group immutability. } k = it.key(); e = *it; - //qDebug() << "found existing entry for key" << k; + // qDebug() << "found existing entry for key" << k; // If overridden entry is global and not default. And it's overridden by a non global if (e.bGlobal && !(options & EntryGlobal) && !k.bDefault) { e.bOverridesGlobal = true; @@ -111,7 +109,7 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q if (cit == constEnd()) { insert(KEntryKey(group), KEntry()); } else if (cit->bImmutable) { - return false; // this group is immutable, so we cannot change this entry. + return false; // this group is immutable, so we cannot change this entry. } k = KEntryKey(group, key); @@ -127,14 +125,14 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q e.bDirty = e.bDirty || (options & EntryDirty); e.bNotify = e.bNotify || (options & EntryNotify); - e.bGlobal = (options & EntryGlobal); //we can't use || here, because changes to entries in - //kdeglobals would be written to kdeglobals instead - //of the local config file, regardless of the globals flag + e.bGlobal = (options & EntryGlobal); // we can't use || here, because changes to entries in + // kdeglobals would be written to kdeglobals instead + // of the local config file, regardless of the globals flag e.bImmutable = e.bImmutable || (options & EntryImmutable); if (value.isNull()) { e.bDeleted = e.bDeleted || (options & EntryDeleted); } else { - e.bDeleted = false; // setting a value to a previously deleted entry + e.bDeleted = false; // setting a value to a previously deleted entry } e.bExpand = (options & EntryExpansion); e.bReverted = false; @@ -145,17 +143,17 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q } if (newKey) { - //qDebug() << "inserting" << k << "=" << value; + // qDebug() << "inserting" << k << "=" << value; insert(k, e); if (k.bDefault) { k.bDefault = false; - //qDebug() << "also inserting" << k << "=" << value; + // qDebug() << "also inserting" << k << "=" << value; insert(k, e); } // TODO check for presence of unlocalized key return true; } else { -// KEntry e2 = it.value(); + // KEntry e2 = it.value(); if (options & EntryLocalized) { // fast exit checks for cases where the existing entry is more specific const KEntry &e2 = it.value(); @@ -165,7 +163,7 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q } } if (it.value() != e) { - //qDebug() << "changing" << k << "from" << e.mValue << "to" << value; + // qDebug() << "changing" << k << "from" << e.mValue << "to" << value; it.value() = e; if (k.bDefault) { KEntryKey nonDefaultKey(k); @@ -174,7 +172,7 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q } if (!(options & EntryLocalized)) { KEntryKey theKey(group, key, true, false); - //qDebug() << "non-localized entry, remove localized one:" << theKey; + // qDebug() << "non-localized entry, remove localized one:" << theKey; remove(theKey); if (k.bDefault) { theKey.bDefault = true; @@ -183,9 +181,9 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q } return true; } else { - //qDebug() << k << "was already set to" << e.mValue; + // qDebug() << k << "was already set to" << e.mValue; if (!(options & EntryLocalized)) { - //qDebug() << "unchanged non-localized entry, remove localized one."; + // qDebug() << "unchanged non-localized entry, remove localized one."; KEntryKey theKey(group, key, true, false); bool ret = false; Iterator cit = find(theKey); @@ -203,7 +201,7 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q } return ret; } - //qDebug() << "localized entry, unchanged, return false"; + // qDebug() << "localized entry, unchanged, return false"; // When we are writing a default, we know that the non- // default is the same as the default, so we can simply // use the same branch. @@ -246,7 +244,7 @@ bool KEntryMap::hasEntry(const QByteArray &group, const QByteArray &key, KEntryM return true; } -bool KEntryMap::getEntryOption(const QMap< KEntryKey, KEntry >::ConstIterator &it, KEntryMap::EntryOption option) const +bool KEntryMap::getEntryOption(const QMap<KEntryKey, KEntry>::ConstIterator &it, KEntryMap::EntryOption option) const { if (it != constEnd()) { switch (option) { @@ -272,7 +270,7 @@ bool KEntryMap::getEntryOption(const QMap< KEntryKey, KEntry >::ConstIterator &i return false; } -void KEntryMap::setEntryOption(QMap< KEntryKey, KEntry >::Iterator it, KEntryMap::EntryOption option, bool bf) +void KEntryMap::setEntryOption(QMap<KEntryKey, KEntry>::Iterator it, KEntryMap::EntryOption option, bool bf) { if (it != end()) { switch (option) { @@ -305,18 +303,18 @@ bool KEntryMap::revertEntry(const QByteArray &group, const QByteArray &key, KEnt Q_ASSERT((flags & KEntryMap::SearchDefaults) == 0); Iterator entry = findEntry(group, key, flags); if (entry != end()) { - //qDebug() << "reverting" << entry.key() << " = " << entry->mValue; + // qDebug() << "reverting" << entry.key() << " = " << entry->mValue; if (entry->bReverted) { // already done before return false; } KEntryKey defaultKey(entry.key()); defaultKey.bDefault = true; - //qDebug() << "looking up default entry with key=" << defaultKey; + // qDebug() << "looking up default entry with key=" << defaultKey; const ConstIterator defaultEntry = constFind(defaultKey); if (defaultEntry != constEnd()) { Q_ASSERT(defaultEntry.key().bDefault); - //qDebug() << "found, update entry"; + // qDebug() << "found, update entry"; *entry = *defaultEntry; // copy default value, for subsequent lookups } else { entry->mValue = QByteArray(); @@ -325,7 +323,7 @@ bool KEntryMap::revertEntry(const QByteArray &group, const QByteArray &key, KEnt entry->bDirty = true; entry->bReverted = true; // skip it when writing out to disk - //qDebug() << "Here's what we have now:" << *this; + // qDebug() << "Here's what we have now:" << *this; return true; } return false; diff --git a/src/core/kconfigdata.h b/src/core/kconfigdata.h index 36d90335..bb9ee717 100644 --- a/src/core/kconfigdata.h +++ b/src/core/kconfigdata.h @@ -11,9 +11,9 @@ #define KCONFIGDATA_H #include <QByteArray> -#include <QString> -#include <QMap> #include <QDebug> +#include <QMap> +#include <QString> /** * map/dict/list config node entry. @@ -22,60 +22,67 @@ struct KEntry { /** Constructor. @internal */ KEntry() - : mValue(), bDirty(false), - bGlobal(false), bImmutable(false), bDeleted(false), bExpand(false), bReverted(false), - bLocalizedCountry(false), bNotify(false), bOverridesGlobal(false) {} + : mValue() + , bDirty(false) + , bGlobal(false) + , bImmutable(false) + , bDeleted(false) + , bExpand(false) + , bReverted(false) + , bLocalizedCountry(false) + , bNotify(false) + , bOverridesGlobal(false) + { + } /** @internal */ QByteArray mValue; /** * Must the entry be written back to disk? */ - bool bDirty : 1; + bool bDirty : 1; /** * Entry should be written to the global config file */ - bool bGlobal: 1; + bool bGlobal : 1; /** * Entry can not be modified. */ - bool bImmutable: 1; + bool bImmutable : 1; /** * Entry has been deleted. */ - bool bDeleted: 1; + bool bDeleted : 1; /** * Whether to apply dollar expansion or not. */ - bool bExpand: 1; + bool bExpand : 1; /** * Entry has been reverted to its default value (from a more global file). */ - bool bReverted: 1; + bool bReverted : 1; /** * Entry is for a localized key. If @c false the value references just language e.g. "de", * if @c true the value references language and country, e.g. "de_DE". **/ - bool bLocalizedCountry: 1; + bool bLocalizedCountry : 1; - bool bNotify: 1; + bool bNotify : 1; /** * Entry will need to be written on a non global file even if it matches default value */ - bool bOverridesGlobal: 1; + bool bOverridesGlobal : 1; }; // These operators are used to check whether an entry which is about // to be written equals the previous value. As such, this intentionally // omits the dirty/notify flag from the comparison. -inline bool operator ==(const KEntry &k1, const KEntry &k2) +inline bool operator==(const KEntry &k1, const KEntry &k2) { - return k1.bGlobal == k2.bGlobal && k1.bImmutable == k2.bImmutable - && k1.bDeleted == k2.bDeleted && k1.bExpand == k2.bExpand - && k1.mValue == k2.mValue; + return k1.bGlobal == k2.bGlobal && k1.bImmutable == k2.bImmutable && k1.bDeleted == k2.bDeleted && k1.bExpand == k2.bExpand && k1.mValue == k2.mValue; } -inline bool operator !=(const KEntry &k1, const KEntry &k2) +inline bool operator!=(const KEntry &k1, const KEntry &k2) { return !(k1 == k2); } @@ -87,9 +94,12 @@ inline bool operator !=(const KEntry &k1, const KEntry &k2) */ struct KEntryKey { /** Constructor. @internal */ - KEntryKey(const QByteArray &_group = QByteArray(), - const QByteArray &_key = QByteArray(), bool isLocalized = false, bool isDefault = false) - : mGroup(_group), mKey(_key), bLocal(isLocalized), bDefault(isDefault), bRaw(false) + KEntryKey(const QByteArray &_group = QByteArray(), const QByteArray &_key = QByteArray(), bool isLocalized = false, bool isDefault = false) + : mGroup(_group) + , mKey(_key) + , bLocal(isLocalized) + , bDefault(isDefault) + , bRaw(false) { ; } @@ -104,16 +114,16 @@ struct KEntryKey { /** * Entry is localised or not */ - bool bLocal : 1; + bool bLocal : 1; /** * Entry indicates if this is a default value. */ - bool bDefault: 1; + bool bDefault : 1; /** @internal * Key is a raw unprocessed key. * @warning this should only be set during merging, never for normal use. */ - bool bRaw: 1; + bool bRaw : 1; }; /** @@ -121,7 +131,7 @@ struct KEntryKey { * non-localized, non-localized-default * @internal */ -inline bool operator <(const KEntryKey &k1, const KEntryKey &k2) +inline bool operator<(const KEntryKey &k1, const KEntryKey &k2) { int result = qstrcmp(k1.mGroup, k2.mGroup); if (result != 0) { @@ -172,45 +182,38 @@ public: }; Q_DECLARE_FLAGS(EntryOptions, EntryOption) - Iterator findExactEntry(const QByteArray &group, const QByteArray &key = QByteArray(), - SearchFlags flags = SearchFlags()); + Iterator findExactEntry(const QByteArray &group, const QByteArray &key = QByteArray(), SearchFlags flags = SearchFlags()); - Iterator findEntry(const QByteArray &group, const QByteArray &key = QByteArray(), - SearchFlags flags = SearchFlags()); + Iterator findEntry(const QByteArray &group, const QByteArray &key = QByteArray(), SearchFlags flags = SearchFlags()); - ConstIterator findEntry(const QByteArray &group, const QByteArray &key = QByteArray(), - SearchFlags flags = SearchFlags()) const; + ConstIterator findEntry(const QByteArray &group, const QByteArray &key = QByteArray(), SearchFlags flags = SearchFlags()) const; /** * Returns true if the entry gets dirtied or false in other case */ - bool setEntry(const QByteArray &group, const QByteArray &key, - const QByteArray &value, EntryOptions options); + bool setEntry(const QByteArray &group, const QByteArray &key, const QByteArray &value, EntryOptions options); - void setEntry(const QByteArray &group, const QByteArray &key, - const QString &value, EntryOptions options) + void setEntry(const QByteArray &group, const QByteArray &key, const QString &value, EntryOptions options) { setEntry(group, key, value.toUtf8(), options); } - QString getEntry(const QByteArray &group, const QByteArray &key, + QString getEntry(const QByteArray &group, + const QByteArray &key, const QString &defaultValue = QString(), SearchFlags flags = SearchFlags(), bool *expand = nullptr) const; - bool hasEntry(const QByteArray &group, const QByteArray &key = QByteArray(), - SearchFlags flags = SearchFlags()) const; + bool hasEntry(const QByteArray &group, const QByteArray &key = QByteArray(), SearchFlags flags = SearchFlags()) const; bool getEntryOption(const ConstIterator &it, EntryOption option) const; - bool getEntryOption(const QByteArray &group, const QByteArray &key, - SearchFlags flags, EntryOption option) const + bool getEntryOption(const QByteArray &group, const QByteArray &key, SearchFlags flags, EntryOption option) const { return getEntryOption(findEntry(group, key, flags), option); } void setEntryOption(Iterator it, EntryOption option, bool bf); - void setEntryOption(const QByteArray &group, const QByteArray &key, SearchFlags flags, - EntryOption option, bool bf) + void setEntryOption(const QByteArray &group, const QByteArray &key, SearchFlags flags, EntryOption option, bool bf) { setEntryOption(findEntry(group, key, flags), option, bf); } diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp index d900458f..8fcfafe7 100644 --- a/src/core/kconfiggroup.cpp +++ b/src/core/kconfiggroup.cpp @@ -11,41 +11,50 @@ #include "kconfiggroup_p.h" #include "kconfig.h" -#include "kconfig_p.h" #include "kconfig_core_log_settings.h" -#include "ksharedconfig.h" +#include "kconfig_p.h" #include "kconfigdata.h" +#include "ksharedconfig.h" #include <QDate> -#include <QSharedData> +#include <QDir> #include <QFile> #include <QPoint> #include <QRect> +#include <QSharedData> #include <QString> #include <QTextStream> -#include <QDir> #include <QUrl> -#include <stdlib.h> #include <math.h> +#include <stdlib.h> class KConfigGroupPrivate : public QSharedData { public: KConfigGroupPrivate(KConfig *owner, bool isImmutable, bool isConst, const QByteArray &name) - : mOwner(owner), mName(name), bImmutable(isImmutable), bConst(isConst) + : mOwner(owner) + , mName(name) + , bImmutable(isImmutable) + , bConst(isConst) { } KConfigGroupPrivate(const KSharedConfigPtr &owner, const QByteArray &name) - : sOwner(owner), mOwner(sOwner.data()), mName(name), - bImmutable(name.isEmpty() ? owner->isImmutable() : owner->isGroupImmutable(name)), bConst(false) + : sOwner(owner) + , mOwner(sOwner.data()) + , mName(name) + , bImmutable(name.isEmpty() ? owner->isImmutable() : owner->isGroupImmutable(name)) + , bConst(false) { } KConfigGroupPrivate(KConfigGroup *parent, bool isImmutable, bool isConst, const QByteArray &name) - : sOwner(parent->d->sOwner), mOwner(parent->d->mOwner), mName(name), - bImmutable(isImmutable), bConst(isConst) + : sOwner(parent->d->sOwner) + , mOwner(parent->d->mOwner) + , mName(name) + , bImmutable(isImmutable) + , bConst(isConst) { if (!parent->d->mName.isEmpty()) { mParent = parent->d; @@ -53,8 +62,11 @@ public: } KConfigGroupPrivate(const KConfigGroupPrivate *other, bool isImmutable, const QByteArray &name) - : sOwner(other->sOwner), mOwner(other->mOwner), mName(name), - bImmutable(isImmutable), bConst(other->bConst) + : sOwner(other->sOwner) + , mOwner(other->mOwner) + , mName(name) + , bImmutable(isImmutable) + , bConst(other->bConst) { if (!other->mName.isEmpty()) { mParent = const_cast<KConfigGroupPrivate *>(other); @@ -67,8 +79,8 @@ public: QByteArray mName; /* bitfield */ - const bool bImmutable: 1; // is this group immutable? - const bool bConst: 1; // is this group read-only? + const bool bImmutable : 1; // is this group immutable? + const bool bConst : 1; // is this group read-only? QByteArray fullName() const { @@ -94,10 +106,7 @@ public: return fullName() + '\x1d' + aGroup; } - static QExplicitlySharedDataPointer<KConfigGroupPrivate> create(KConfigBase *master, - const QByteArray &name, - bool isImmutable, - bool isConst) + static QExplicitlySharedDataPointer<KConfigGroupPrivate> create(KConfigBase *master, const QByteArray &name, bool isImmutable, bool isConst) { QExplicitlySharedDataPointer<KConfigGroupPrivate> data; if (dynamic_cast<KConfigGroup *>(master)) { @@ -198,9 +207,7 @@ static QVector<qreal> asRealList(const QByteArray &string) static QString errString(const char *pKey, const QByteArray &value, const QVariant &aDefault) { return QStringLiteral("\"%1\" - conversion of \"%3\" to %2 failed") - .arg( QString::fromLatin1(pKey), - QString::fromLatin1(QVariant::typeToName(aDefault.type())), - QString::fromLatin1(value) ); + .arg(QString::fromLatin1(pKey), QString::fromLatin1(QVariant::typeToName(aDefault.type())), QString::fromLatin1(value)); } static QString formatError(int expected, int got) @@ -249,8 +256,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val const auto list = asIntList(value); if (list.count() != 2) { - qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) - << formatError(2, list.count()); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(2, list.count()); return aDefault; } return QPoint(list.at(0), list.at(1)); @@ -259,8 +265,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val const auto list = asRealList(value); if (list.count() != 2) { - qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) - << formatError(2, list.count()); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(2, list.count()); return aDefault; } return QPointF(list.at(0), list.at(1)); @@ -269,8 +274,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val const auto list = asIntList(value); if (list.count() != 4) { - qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) - << formatError(4, list.count()); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(4, list.count()); return aDefault; } const QRect rect(list.at(0), list.at(1), list.at(2), list.at(3)); @@ -284,8 +288,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val const auto list = asRealList(value); if (list.count() != 4) { - qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) - << formatError(4, list.count()); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(4, list.count()); return aDefault; } const QRectF rect(list.at(0), list.at(1), list.at(2), list.at(3)); @@ -299,8 +302,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val const auto list = asIntList(value); if (list.count() != 2) { - qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) - << formatError(2, list.count()); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(2, list.count()); return aDefault; } const QSize size(list.at(0), list.at(1)); @@ -314,8 +316,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val const auto list = asRealList(value); if (list.count() != 2) { - qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) - << formatError(2, list.count()); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(2, list.count()); return aDefault; } const QSizeF size(list.at(0), list.at(1)); @@ -328,8 +329,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val case QMetaType::QDateTime: { const auto list = asRealList(value); if (list.count() < 6) { - qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) - << formatError(6, list.count()); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(6, list.count()); return aDefault; } const QDate date(list.at(0), list.at(1), list.at(2)); @@ -348,11 +348,10 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val case QMetaType::QDate: { auto list = asIntList(value); if (list.count() == 6) { - list = list.mid(0, 3); // don't break config files that stored QDate as QDateTime + list = list.mid(0, 3); // don't break config files that stored QDate as QDateTime } if (list.count() != 3) { - qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) - << formatError(3, list.count()); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(3, list.count()); return aDefault; } const QDate date(list.at(0), list.at(1), list.at(2)); @@ -364,10 +363,9 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val } case QMetaType::QColor: case QMetaType::QFont: - qCWarning(KCONFIG_CORE_LOG) << "KConfigGroup::readEntry was passed GUI type '" - << aDefault.typeName() - << "' but KConfigGui isn't linked! If it is linked to your program, " - "this is a platform bug. Please inform the KDE developers"; + qCWarning(KCONFIG_CORE_LOG) << "KConfigGroup::readEntry was passed GUI type '" << aDefault.typeName() + << "' but KConfigGui isn't linked! If it is linked to your program, " + "this is a platform bug. Please inform the KDE developers"; break; case QMetaType::QUrl: return QUrl(QString::fromUtf8(value)); @@ -381,12 +379,12 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val } #ifdef Q_OS_WIN -# include <QDir> +#include <QDir> #endif static bool cleanHomeDirPath(QString &path, const QString &homeDir) { -#ifdef Q_OS_WIN //safer +#ifdef Q_OS_WIN // safer if (!QDir::toNativeSeparators(path).startsWith(QDir::toNativeSeparators(homeDir))) { return false; } @@ -406,7 +404,7 @@ static bool cleanHomeDirPath(QString &path, const QString &homeDir) return false; } -static QString translatePath(QString path) // krazy:exclude=passbyvalue +static QString translatePath(QString path) // krazy:exclude=passbyvalue { if (path.isEmpty()) { return path; @@ -429,9 +427,7 @@ static QString translatePath(QString path) // krazy:exclude=passbyvalue const QString homeDir0 = QFile::decodeName(qgetenv("HOME")); const QString homeDir1 = QDir::homePath(); const QString homeDir2 = QDir(homeDir1).canonicalPath(); - if (cleanHomeDirPath(path, homeDir0) || - cleanHomeDirPath(path, homeDir1) || - cleanHomeDirPath(path, homeDir2)) { + if (cleanHomeDirPath(path, homeDir0) || cleanHomeDirPath(path, homeDir1) || cleanHomeDirPath(path, homeDir2)) { // qDebug() << "Path was replaced\n"; } @@ -442,7 +438,8 @@ static QString translatePath(QString path) // krazy:exclude=passbyvalue return path; } -KConfigGroup::KConfigGroup() : d() +KConfigGroup::KConfigGroup() + : d() { } @@ -452,8 +449,7 @@ bool KConfigGroup::isValid() const } KConfigGroupGui _kde_internal_KConfigGroupGui; -static inline bool readEntryGui(const QByteArray &data, const char *key, const QVariant &input, - QVariant &output) +static inline bool readEntryGui(const QByteArray &data, const char *key, const QVariant &input, QVariant &output) { if (_kde_internal_KConfigGroupGui.readEntryGui) { return _kde_internal_KConfigGroupGui.readEntryGui(data, key, input, output); @@ -461,8 +457,7 @@ static inline bool readEntryGui(const QByteArray &data, const char *key, const Q return false; } -static inline bool writeEntryGui(KConfigGroup *cg, const char *key, const QVariant &input, - KConfigGroup::WriteConfigFlags flags) +static inline bool writeEntryGui(KConfigGroup *cg, const char *key, const QVariant &input, KConfigGroup::WriteConfigFlags flags) { if (_kde_internal_KConfigGroupGui.writeEntryGui) { return _kde_internal_KConfigGroupGui.writeEntryGui(cg, key, input, flags); @@ -535,8 +530,7 @@ const KConfigGroup KConfigGroup::groupImpl(const QByteArray &aGroup) const KConfigGroup newGroup; - newGroup.d = new KConfigGroupPrivate(const_cast<KConfigGroup *>(this), isGroupImmutableImpl(aGroup), - true, aGroup); + newGroup.d = new KConfigGroupPrivate(const_cast<KConfigGroup *>(this), isGroupImmutableImpl(aGroup), true, aGroup); return newGroup; } @@ -634,8 +628,7 @@ bool KConfigGroup::isEntryImmutable(const char *key) const { Q_ASSERT_X(isValid(), "KConfigGroup::isEntryImmutable", "accessing an invalid group"); - return (isImmutable() || - !config()->d_func()->canWriteEntry(d->fullName(), key, config()->readDefaults())); + return (isImmutable() || !config()->d_func()->canWriteEntry(d->fullName(), key, config()->readDefaults())); } bool KConfigGroup::isEntryImmutable(const QString &key) const @@ -676,8 +669,7 @@ QString KConfigGroup::readEntry(const char *key, const QString &aDefault) const bool expand = false; // read value from the entry map - QString aValue = config()->d_func()->lookupData(d->fullName(), key, KEntryMap::SearchLocalized, - &expand); + QString aValue = config()->d_func()->lookupData(d->fullName(), key, KEntryMap::SearchLocalized, &expand); if (aValue.isNull()) { aValue = aDefault; } @@ -809,8 +801,7 @@ QString KConfigGroup::readPathEntry(const char *key, const QString &aDefault) co bool expand = false; - QString aValue = config()->d_func()->lookupData(d->fullName(), key, KEntryMap::SearchLocalized, - &expand); + QString aValue = config()->d_func()->lookupData(d->fullName(), key, KEntryMap::SearchLocalized, &expand); if (aValue.isNull()) { aValue = aDefault; } @@ -861,8 +852,7 @@ void KConfigGroup::writeEntry(const char *key, const char *value, WriteConfigFla writeEntry(key, QVariant(QString::fromLatin1(value)), pFlags); } -void KConfigGroup::writeEntry(const char *key, const QByteArray &value, - WriteConfigFlags flags) +void KConfigGroup::writeEntry(const char *key, const QByteArray &value, WriteConfigFlags flags) { Q_ASSERT_X(isValid(), "KConfigGroup::writeEntry", "accessing an invalid group"); Q_ASSERT_X(!d->bConst, "KConfigGroup::writeEntry", "writing to a read-only group"); @@ -870,8 +860,7 @@ void KConfigGroup::writeEntry(const char *key, const QByteArray &value, config()->d_func()->putData(d->fullName(), key, value.isNull() ? QByteArray("") : value, flags); } -void KConfigGroup::writeEntry(const QString &key, const QByteArray &value, - WriteConfigFlags pFlags) +void KConfigGroup::writeEntry(const QString &key, const QByteArray &value, WriteConfigFlags pFlags) { writeEntry(key.toUtf8().constData(), value, pFlags); } @@ -915,14 +904,13 @@ void KConfigGroup::writeEntry(const char *key, const QVariantList &list, WriteCo writeEntry(key, KConfigGroupPrivate::serializeList(data), flags); } -void KConfigGroup::writeEntry(const char *key, const QVariant &value, - WriteConfigFlags flags) +void KConfigGroup::writeEntry(const char *key, const QVariant &value, WriteConfigFlags flags) { Q_ASSERT_X(isValid(), "KConfigGroup::writeEntry", "accessing an invalid group"); Q_ASSERT_X(!d->bConst, "KConfigGroup::writeEntry", "writing to a read-only group"); if (writeEntryGui(this, key, value, flags)) { - return; // GUI type that was handled + return; // GUI type that was handled } QByteArray data; @@ -948,8 +936,9 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, break; case QMetaType::QVariantList: if (!value.canConvert(QMetaType::QStringList)) - qCWarning(KCONFIG_CORE_LOG) << "not all types in \"" << key << "\" can convert to QString," - " information will be lost"; + qCWarning(KCONFIG_CORE_LOG) << "not all types in \"" << key + << "\" can convert to QString," + " information will be lost"; Q_FALLTHROUGH(); case QMetaType::QStringList: writeEntry(key, value.toList(), flags); @@ -957,10 +946,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, case QMetaType::QPoint: { const QPoint rPoint = value.toPoint(); - const QVariantList list{ - rPoint.x(), - rPoint.y() - }; + const QVariantList list{rPoint.x(), rPoint.y()}; writeEntry(key, list, flags); return; @@ -968,10 +954,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, case QMetaType::QPointF: { const QPointF point = value.toPointF(); - const QVariantList list{ - point.x(), - point.y() - }; + const QVariantList list{point.x(), point.y()}; writeEntry(key, list, flags); return; @@ -979,12 +962,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, case QMetaType::QRect: { const QRect rRect = value.toRect(); - const QVariantList list{ - rRect.left(), - rRect.top(), - rRect.width(), - rRect.height() - }; + const QVariantList list{rRect.left(), rRect.top(), rRect.width(), rRect.height()}; writeEntry(key, list, flags); return; @@ -992,12 +970,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, case QMetaType::QRectF: { const QRectF rRectF = value.toRectF(); - const QVariantList list{ - rRectF.left(), - rRectF.top(), - rRectF.width(), - rRectF.height() - }; + const QVariantList list{rRectF.left(), rRectF.top(), rRectF.width(), rRectF.height()}; writeEntry(key, list, flags); return; @@ -1005,10 +978,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, case QMetaType::QSize: { const QSize rSize = value.toSize(); - const QVariantList list{ - rSize.width(), - rSize.height() - }; + const QVariantList list{rSize.width(), rSize.height()}; writeEntry(key, list, flags); return; @@ -1016,10 +986,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, case QMetaType::QSizeF: { const QSizeF rSizeF = value.toSizeF(); - const QVariantList list{ - rSizeF.width(), - rSizeF.height() - }; + const QVariantList list{rSizeF.width(), rSizeF.height()}; writeEntry(key, list, flags); return; @@ -1027,11 +994,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, case QMetaType::QDate: { const QDate date = value.toDate(); - const QVariantList list{ - date.year(), - date.month(), - date.day() - }; + const QVariantList list{date.year(), date.month(), date.day()}; writeEntry(key, list, flags); return; @@ -1049,7 +1012,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, time.hour(), time.minute(), - time.second() + time.msec()/1000.0, + time.second() + time.msec() / 1000.0, }; writeEntry(key, list, flags); @@ -1058,10 +1021,9 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value, case QMetaType::QColor: case QMetaType::QFont: - qCWarning(KCONFIG_CORE_LOG) << "KConfigGroup::writeEntry was passed GUI type '" - << value.typeName() - << "' but KConfigGui isn't linked! If it is linked to your program, this is a platform bug. " - "Please inform the KDE developers"; + qCWarning(KCONFIG_CORE_LOG) << "KConfigGroup::writeEntry was passed GUI type '" << value.typeName() + << "' but KConfigGui isn't linked! If it is linked to your program, this is a platform bug. " + "Please inform the KDE developers"; break; case QMetaType::QUrl: data = QUrl(value.toUrl()).toString().toUtf8(); @@ -1260,7 +1222,7 @@ bool KConfigGroup::isGroupImmutableImpl(const QByteArray &b) const Q_ASSERT_X(isValid(), "KConfigGroup::isGroupImmutableImpl", "accessing an invalid group"); if (!hasGroupImpl(b)) { // group doesn't exist yet - return d->bImmutable; // child groups are immutable if the parent is immutable. + return d->bImmutable; // child groups are immutable if the parent is immutable. } return config()->isGroupImmutable(d->fullName(b)); diff --git a/src/core/kconfiggroup.h b/src/core/kconfiggroup.h index 620f04c0..5c125dd2 100644 --- a/src/core/kconfiggroup.h +++ b/src/core/kconfiggroup.h @@ -16,8 +16,8 @@ #include <kconfigcore_export.h> #include <QExplicitlySharedDataPointer> -#include <QVariant> #include <QStringList> +#include <QVariant> class KConfig; class KConfigGroupPrivate; @@ -246,7 +246,7 @@ public: * * @see writeEntry(), deleteEntry(), hasKey() */ - template <typename T> + template<typename T> T readEntry(const QString &key, const T &aDefault) const { return readEntry(key.toUtf8().constData(), aDefault); @@ -255,7 +255,7 @@ public: * Overload for readEntry<T>(const QString&, const T&) const * @param key name of key, encoded in UTF-8 */ - template <typename T> + template<typename T> T readEntry(const char *key, const T &aDefault) const; /** @@ -414,14 +414,12 @@ public: * @param aDefault a default value returned if the key was not found * @return the value for this key, or @p aDefault if the key does not exist */ - QString readEntryUntranslated(const QString &pKey, - const QString &aDefault = QString()) const; + QString readEntryUntranslated(const QString &pKey, const QString &aDefault = QString()) const; /** * Overload for readEntryUntranslated(const QString&, const QString&) const * @param key name of key, encoded in UTF-8 */ - QString readEntryUntranslated(const char *key, - const QString &aDefault = QString()) const; + QString readEntryUntranslated(const char *key, const QString &aDefault = QString()) const; /** * Writes a value to the configuration object. @@ -432,34 +430,28 @@ public: * * @see readEntry(), writeXdgListEntry(), deleteEntry() */ - void writeEntry(const QString &key, const QVariant &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags = Normal); /** * Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - void writeEntry(const char *key, const QVariant &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const char *key, const QVariant &value, WriteConfigFlags pFlags = Normal); /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */ - void writeEntry(const QString &key, const QString &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const QString &key, const QString &value, WriteConfigFlags pFlags = Normal); /** * Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - void writeEntry(const char *key, const QString &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const char *key, const QString &value, WriteConfigFlags pFlags = Normal); /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */ - void writeEntry(const QString &key, const QByteArray &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const QString &key, const QByteArray &value, WriteConfigFlags pFlags = Normal); /** * Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - void writeEntry(const char *key, const QByteArray &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const char *key, const QByteArray &value, WriteConfigFlags pFlags = Normal); /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */ void writeEntry(const QString &key, const char *value, WriteConfigFlags pFlags = Normal); @@ -473,37 +465,33 @@ public: * Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - template <typename T> + template<typename T> void writeEntry(const char *key, const T &value, WriteConfigFlags pFlags = Normal); /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */ - template <typename T> + template<typename T> void writeEntry(const QString &key, const T &value, WriteConfigFlags pFlags = Normal) { writeEntry(key.toUtf8().constData(), value, pFlags); } /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */ - void writeEntry(const QString &key, const QStringList &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const QString &key, const QStringList &value, WriteConfigFlags pFlags = Normal); /** * Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - void writeEntry(const char *key, const QStringList &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const char *key, const QStringList &value, WriteConfigFlags pFlags = Normal); /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */ - void writeEntry(const QString &key, const QVariantList &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const QString &key, const QVariantList &value, WriteConfigFlags pFlags = Normal); /** * Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - void writeEntry(const char *key, const QVariantList &value, - WriteConfigFlags pFlags = Normal); + void writeEntry(const char *key, const QVariantList &value, WriteConfigFlags pFlags = Normal); /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */ - template <typename T> + template<typename T> void writeEntry(const QString &key, const QList<T> &value, WriteConfigFlags pFlags = Normal) { writeEntry(key.toUtf8().constData(), value, pFlags); @@ -512,7 +500,7 @@ public: * Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - template <typename T> + template<typename T> void writeEntry(const char *key, const QList<T> &value, WriteConfigFlags pFlags = Normal); /** @@ -525,14 +513,12 @@ public: * * @see writeEntry(), readXdgListEntry() */ - void writeXdgListEntry(const QString &pKey, const QStringList &value, - WriteConfigFlags pFlags = Normal); + void writeXdgListEntry(const QString &pKey, const QStringList &value, WriteConfigFlags pFlags = Normal); /** * Overload for writeXdgListEntry(const QString&, const QStringList&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - void writeXdgListEntry(const char *key, const QStringList &value, - WriteConfigFlags pFlags = Normal); + void writeXdgListEntry(const char *key, const QStringList &value, WriteConfigFlags pFlags = Normal); /** * Writes a file path to the configuration @@ -547,14 +533,12 @@ public: * * @see writeEntry(), readPathEntry() */ - void writePathEntry(const QString &pKey, const QString &path, - WriteConfigFlags pFlags = Normal); + void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags = Normal); /** * Overload for writePathEntry(const QString&, const QString&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - void writePathEntry(const char *Key, const QString &path, - WriteConfigFlags pFlags = Normal); + void writePathEntry(const char *Key, const QString &path, WriteConfigFlags pFlags = Normal); /** * Writes a list of paths to the configuration @@ -569,14 +553,12 @@ public: * * @see writeEntry(), readPathEntry() */ - void writePathEntry(const QString &pKey, const QStringList &value, - WriteConfigFlags pFlags = Normal); + void writePathEntry(const QString &pKey, const QStringList &value, WriteConfigFlags pFlags = Normal); /** * Overload for writePathEntry(const QString&, const QStringList&, WriteConfigFlags) * @param key name of key, encoded in UTF-8 */ - void writePathEntry(const char *key, const QStringList &value, - WriteConfigFlags pFlags = Normal); + void writePathEntry(const char *key, const QStringList &value, WriteConfigFlags pFlags = Normal); /** * Deletes the entry specified by @p pKey in the current group @@ -742,9 +724,7 @@ private: friend class KServicePrivate; // XXX yeah, ugly^5 }; -#define KCONFIGGROUP_ENUMERATOR_ERROR(ENUM) \ - "The Qt MetaObject system does not seem to know about \"" ENUM \ - "\" please use Q_ENUM or Q_FLAG to register it." +#define KCONFIGGROUP_ENUMERATOR_ERROR(ENUM) "The Qt MetaObject system does not seem to know about \"" ENUM "\" please use Q_ENUM or Q_FLAG to register it." /** * To add support for your own enums in KConfig, you can declare them with Q_ENUM() @@ -754,70 +734,88 @@ private: * <code>KCONFIGGROUP_DECLARE_ENUM_QOBJECT(MyClass, MyEnum)</code> * */ -#define KCONFIGGROUP_DECLARE_ENUM_QOBJECT(Class, Enum) \ - template<> \ - Class::Enum KConfigGroup::readEntry(const char* key, const Class::Enum& def) const\ - { \ - const QMetaObject* M_obj = &Class::staticMetaObject; \ - const int M_index = M_obj->indexOfEnumerator(#Enum); \ - if(M_index == -1) qFatal(KCONFIGGROUP_ENUMERATOR_ERROR(#Enum)); \ - const QMetaEnum M_enum = M_obj->enumerator(M_index); \ - const QByteArray M_data = readEntry(key, QByteArray(M_enum.valueToKey(def)));\ - return static_cast<Class::Enum>(M_enum.keyToValue(M_data.constData())); \ - } \ - inline Class::Enum Q_DECL_DEPRECATED readEntry(const KConfigGroup& group, const char* key, const Class::Enum& def)\ - { return group.readEntry(key, def); } \ - template<> \ - void KConfigGroup::writeEntry(const char* key, const Class::Enum& value, KConfigBase::WriteConfigFlags flags)\ - { \ - const QMetaObject* M_obj = &Class::staticMetaObject; \ - const int M_index = M_obj->indexOfEnumerator(#Enum); \ - if(M_index == -1) qFatal(KCONFIGGROUP_ENUMERATOR_ERROR(#Enum)); \ - const QMetaEnum M_enum = M_obj->enumerator(M_index); \ - writeEntry(key, QByteArray(M_enum.valueToKey(value)), flags); \ - } \ - inline void Q_DECL_DEPRECATED writeEntry(KConfigGroup& group, const char* key, const Class::Enum& value, KConfigBase::WriteConfigFlags flags = KConfigBase::Normal)\ - { group.writeEntry(key, value, flags); } +#define KCONFIGGROUP_DECLARE_ENUM_QOBJECT(Class, Enum) \ + template<> \ + Class::Enum KConfigGroup::readEntry(const char *key, const Class::Enum &def) const \ + { \ + const QMetaObject *M_obj = &Class::staticMetaObject; \ + const int M_index = M_obj->indexOfEnumerator(#Enum); \ + if (M_index == -1) \ + qFatal(KCONFIGGROUP_ENUMERATOR_ERROR(#Enum)); \ + const QMetaEnum M_enum = M_obj->enumerator(M_index); \ + const QByteArray M_data = readEntry(key, QByteArray(M_enum.valueToKey(def))); \ + return static_cast<Class::Enum>(M_enum.keyToValue(M_data.constData())); \ + } \ + inline Class::Enum Q_DECL_DEPRECATED readEntry(const KConfigGroup &group, const char *key, const Class::Enum &def) \ + { \ + return group.readEntry(key, def); \ + } \ + template<> \ + void KConfigGroup::writeEntry(const char *key, const Class::Enum &value, KConfigBase::WriteConfigFlags flags) \ + { \ + const QMetaObject *M_obj = &Class::staticMetaObject; \ + const int M_index = M_obj->indexOfEnumerator(#Enum); \ + if (M_index == -1) \ + qFatal(KCONFIGGROUP_ENUMERATOR_ERROR(#Enum)); \ + const QMetaEnum M_enum = M_obj->enumerator(M_index); \ + writeEntry(key, QByteArray(M_enum.valueToKey(value)), flags); \ + } \ + inline void Q_DECL_DEPRECATED writeEntry(KConfigGroup &group, \ + const char *key, \ + const Class::Enum &value, \ + KConfigBase::WriteConfigFlags flags = KConfigBase::Normal) \ + { \ + group.writeEntry(key, value, flags); \ + } /** * Similar to KCONFIGGROUP_DECLARE_ENUM_QOBJECT but for flags declared with Q_FLAG() * (where multiple values can be set at the same time) */ -#define KCONFIGGROUP_DECLARE_FLAGS_QOBJECT(Class, Flags) \ - template<> \ - Class::Flags KConfigGroup::readEntry(const char* key, const Class::Flags& def) const\ - { \ - const QMetaObject* M_obj = &Class::staticMetaObject; \ - const int M_index = M_obj->indexOfEnumerator(#Flags); \ - if(M_index == -1) qFatal(KCONFIGGROUP_ENUMERATOR_ERROR(#Flags)); \ - const QMetaEnum M_enum = M_obj->enumerator(M_index); \ - const QByteArray M_data = readEntry(key, QByteArray(M_enum.valueToKeys(def)));\ - return static_cast<Class::Flags>(M_enum.keysToValue(M_data.constData())); \ - } \ - inline Class::Flags Q_DECL_DEPRECATED readEntry(const KConfigGroup& group, const char* key, const Class::Flags& def)\ - { return group.readEntry(key, def);} \ - template<> \ - void KConfigGroup::writeEntry(const char* key, const Class::Flags& value, KConfigBase::WriteConfigFlags flags)\ - { \ - const QMetaObject* M_obj = &Class::staticMetaObject; \ - const int M_index = M_obj->indexOfEnumerator(#Flags); \ - if(M_index == -1) qFatal(KCONFIGGROUP_ENUMERATOR_ERROR(#Flags)); \ - const QMetaEnum M_enum = M_obj->enumerator(M_index); \ - writeEntry(key, QByteArray(M_enum.valueToKeys(value)), flags); \ - } \ - inline void Q_DECL_DEPRECATED writeEntry(KConfigGroup& group, const char* key, const Class::Flags& value, KConfigBase::WriteConfigFlags flags = KConfigBase::Normal)\ - { group.writeEntry(key, value, flags); } +#define KCONFIGGROUP_DECLARE_FLAGS_QOBJECT(Class, Flags) \ + template<> \ + Class::Flags KConfigGroup::readEntry(const char *key, const Class::Flags &def) const \ + { \ + const QMetaObject *M_obj = &Class::staticMetaObject; \ + const int M_index = M_obj->indexOfEnumerator(#Flags); \ + if (M_index == -1) \ + qFatal(KCONFIGGROUP_ENUMERATOR_ERROR(#Flags)); \ + const QMetaEnum M_enum = M_obj->enumerator(M_index); \ + const QByteArray M_data = readEntry(key, QByteArray(M_enum.valueToKeys(def))); \ + return static_cast<Class::Flags>(M_enum.keysToValue(M_data.constData())); \ + } \ + inline Class::Flags Q_DECL_DEPRECATED readEntry(const KConfigGroup &group, const char *key, const Class::Flags &def) \ + { \ + return group.readEntry(key, def); \ + } \ + template<> \ + void KConfigGroup::writeEntry(const char *key, const Class::Flags &value, KConfigBase::WriteConfigFlags flags) \ + { \ + const QMetaObject *M_obj = &Class::staticMetaObject; \ + const int M_index = M_obj->indexOfEnumerator(#Flags); \ + if (M_index == -1) \ + qFatal(KCONFIGGROUP_ENUMERATOR_ERROR(#Flags)); \ + const QMetaEnum M_enum = M_obj->enumerator(M_index); \ + writeEntry(key, QByteArray(M_enum.valueToKeys(value)), flags); \ + } \ + inline void Q_DECL_DEPRECATED writeEntry(KConfigGroup &group, \ + const char *key, \ + const Class::Flags &value, \ + KConfigBase::WriteConfigFlags flags = KConfigBase::Normal) \ + { \ + group.writeEntry(key, value, flags); \ + } #include "conversioncheck.h" -template <typename T> +template<typename T> T KConfigGroup::readEntry(const char *key, const T &defaultValue) const { ConversionCheck::to_QVariant<T>(); return qvariant_cast<T>(readEntry(key, QVariant::fromValue(defaultValue))); } -template <typename T> +template<typename T> QList<T> KConfigGroup::readEntry(const char *key, const QList<T> &defaultValue) const { ConversionCheck::to_QVariant<T>(); @@ -839,14 +837,14 @@ QList<T> KConfigGroup::readEntry(const char *key, const QList<T> &defaultValue) return list; } -template <typename T> +template<typename T> void KConfigGroup::writeEntry(const char *key, const T &value, WriteConfigFlags pFlags) { ConversionCheck::to_QVariant<T>(); writeEntry(key, QVariant::fromValue(value), pFlags); } -template <typename T> +template<typename T> void KConfigGroup::writeEntry(const char *key, const QList<T> &list, WriteConfigFlags pFlags) { ConversionCheck::to_QVariant<T>(); diff --git a/src/core/kconfiggroup_p.h b/src/core/kconfiggroup_p.h index 923387e7..2744c153 100644 --- a/src/core/kconfiggroup_p.h +++ b/src/core/kconfiggroup_p.h @@ -8,16 +8,14 @@ #ifndef KCONFIGGROUP_P_H #define KCONFIGGROUP_P_H -#include <QVariant> #include "kconfiggroup.h" +#include <QVariant> class KConfigGroup; struct KConfigGroupGui { - typedef bool (*kReadEntryGui)(const QByteArray &data, const char *key, const QVariant &input, - QVariant &output); - typedef bool (*kWriteEntryGui)(KConfigGroup *, const char *key, const QVariant &input, - KConfigGroup::WriteConfigFlags flags); + typedef bool (*kReadEntryGui)(const QByteArray &data, const char *key, const QVariant &input, QVariant &output); + typedef bool (*kWriteEntryGui)(KConfigGroup *, const char *key, const QVariant &input, KConfigGroup::WriteConfigFlags flags); kReadEntryGui readEntryGui; kWriteEntryGui writeEntryGui; diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp index 96cd3763..6271bcd5 100644 --- a/src/core/kconfigini.cpp +++ b/src/core/kconfigini.cpp @@ -9,26 +9,26 @@ #include "kconfigini_p.h" +#include "bufferfragment_p.h" #include "kconfig.h" +#include "kconfig_core_log_settings.h" #include "kconfigbackend_p.h" -#include "bufferfragment_p.h" #include "kconfigdata.h" -#include "kconfig_core_log_settings.h" -#include <QSaveFile> -#include <QLockFile> #include <QDateTime> +#include <QDebug> #include <QDir> #include <QFile> #include <QFileInfo> -#include <QDebug> +#include <QLockFile> +#include <QSaveFile> #include <qplatformdefs.h> #ifndef Q_OS_WIN #include <unistd.h> // getuid, close #endif -#include <sys/types.h> // uid_t #include <fcntl.h> // open +#include <sys/types.h> // uid_t KCONFIGCORE_EXPORT bool kde_kiosk_exception = false; // flag to disable kiosk restrictions @@ -44,12 +44,12 @@ static QByteArray lookup(const KConfigIniBackend::BufferFragment fragment, QHash QString KConfigIniBackend::warningProlog(const QFile &file, int line) { - return QStringLiteral("KConfigIni: In file %2, line %1: ") - .arg(line).arg(file.fileName()); + return QStringLiteral("KConfigIni: In file %2, line %1: ").arg(line).arg(file.fileName()); } KConfigIniBackend::KConfigIniBackend() - : KConfigBackend(), lockFile(nullptr) + : KConfigBackend() + , lockFile(nullptr) { } @@ -57,18 +57,14 @@ KConfigIniBackend::~KConfigIniBackend() { } -KConfigBackend::ParseInfo -KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entryMap, - ParseOptions options) +KConfigBackend::ParseInfo KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entryMap, ParseOptions options) { return parseConfig(currentLocale, entryMap, options, false); } // merging==true is the merging that happens at the beginning of writeConfig: // merge changes in the on-disk file with the changes in the KConfig object. -KConfigBackend::ParseInfo -KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entryMap, - ParseOptions options, bool merging) +KConfigBackend::ParseInfo KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entryMap, ParseOptions options, bool merging) { if (filePath().isEmpty() || !QFile::exists(filePath())) { return ParseOk; @@ -137,8 +133,7 @@ KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entry } ++end; } - if (end + 1 == line.length() && start + 2 == end && - line.at(start) == '$' && line.at(start + 1) == 'i') { + if (end + 1 == line.length() && start + 2 == end && line.at(start) == '$' && line.at(start + 1) == 'i') { if (newGroup.isEmpty()) { fileOptionImmutable = !kde_kiosk_exception; } else { @@ -162,14 +157,14 @@ KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entry } if (groupOptionImmutable) - // Do not make the groups immutable until the entries from - // this file have been added. + // Do not make the groups immutable until the entries from + // this file have been added. { immutableGroups.append(currentGroup); } } else { if (groupSkip && !bDefault) { - continue; // skip entry + continue; // skip entry } BufferFragment aKey; @@ -199,8 +194,7 @@ KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entry while ((start = aKey.lastIndexOf('[')) >= 0) { int end = aKey.indexOf(']', start); if (end < 0) { - qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) - << "Invalid entry (missing ']')"; + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (missing ']')"; goto next_line; } else if (end > start + 1 && aKey.at(start + 1) == '$') { // found option(s) int i = start + 2; @@ -229,8 +223,7 @@ KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entry } } else { // found a locale if (!locale.isNull()) { - qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) - << "Invalid entry (second locale!?)"; + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (second locale!?)"; goto next_line; } @@ -250,7 +243,7 @@ KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entry if (merging) { entryOptions |= KEntryMap::EntryRawKey; } else { - goto next_line; // skip this entry if we're not merging + goto next_line; // skip this entry if we're not merging } } } @@ -295,8 +288,7 @@ KConfigIniBackend::parseConfig(const QByteArray ¤tLocale, KEntryMap &entry return fileOptionImmutable ? ParseImmutable : ParseOk; } -void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file, - const KEntryMap &map, bool defaultGroup, bool &firstEntry) +void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file, const KEntryMap &map, bool defaultGroup, bool &firstEntry) { QByteArray currentGroup; bool groupIsImmutable = false; @@ -306,7 +298,7 @@ void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file, // Either process the default group or all others if ((key.mGroup != "<default>") == defaultGroup) { - continue; // skip + continue; // skip } // the only thing we care about groups is, is it immutable? @@ -366,9 +358,9 @@ void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file, } if (currentEntry.bDeleted) { if (currentEntry.bImmutable) { - file.write("[$di]", 5); // Deleted + immutable + file.write("[$di]", 5); // Deleted + immutable } else { - file.write("[$d]", 4); // Deleted + file.write("[$d]", 4); // Deleted } } else { if (currentEntry.bImmutable || currentEntry.bExpand) { @@ -399,8 +391,7 @@ void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file, writeEntries(locale, file, map, false, firstEntry); } -bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMap, - WriteOptions options) +bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMap, WriteOptions options) { Q_ASSERT(!filePath().isEmpty()); @@ -442,10 +433,10 @@ bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMa defaultKey.bDefault = true; if (!entryMap.contains(defaultKey)) { writeMap.remove(key); // remove the deleted entry if there is no default - //qDebug() << "Detected as deleted=>removed:" << key.mGroup << key.mKey << "global=" << bGlobal; + // qDebug() << "Detected as deleted=>removed:" << key.mGroup << key.mKey << "global=" << bGlobal; } else { writeMap[key] = *it; // otherwise write an explicitly deleted entry - //qDebug() << "Detected as deleted=>[$d]:" << key.mGroup << key.mKey << "global=" << bGlobal; + // qDebug() << "Detected as deleted=>[$d]:" << key.mGroup << key.mKey << "global=" << bGlobal; } } it->bDirty = false; @@ -462,7 +453,7 @@ bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMa QFileInfo fi(filePath()); if (fi.exists()) { #ifdef Q_OS_WIN - //TODO: getuid does not exist on windows, use GetSecurityInfo and GetTokenInformation instead + // TODO: getuid does not exist on windows, use GetSecurityInfo and GetTokenInformation instead createNew = false; #else if (fi.ownerId() == ::getuid()) { @@ -574,7 +565,7 @@ void KConfigIniBackend::createEnclosing() { const QString file = filePath(); if (file.isEmpty()) { - return; // nothing to do + return; // nothing to do } // Create the containing dir, maybe it wasn't there @@ -639,106 +630,112 @@ bool KConfigIniBackend::isLocked() const return lockFile && lockFile->isLocked(); } -namespace { - // serialize an escaped byte at the end of @param data - // @param data should have room for 4 bytes - char* escapeByte(char* data, unsigned char s) { - static const char nibbleLookup[] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' - }; - *data++ = '\\'; - *data++ = 'x'; - *data++ = nibbleLookup[s >> 4]; - *data++ = nibbleLookup[s & 0x0f]; - return data; - } +namespace +{ +// serialize an escaped byte at the end of @param data +// @param data should have room for 4 bytes +char *escapeByte(char *data, unsigned char s) +{ + static const char nibbleLookup[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + *data++ = '\\'; + *data++ = 'x'; + *data++ = nibbleLookup[s >> 4]; + *data++ = nibbleLookup[s & 0x0f]; + return data; +} - // Struct that represents a multi-byte UTF-8 character. - // This struct is used to keep track of bytes that seem to be valid - // UTF-8. - struct Utf8Char { - public: - unsigned char bytes[4]; - unsigned char count; - unsigned char charLength; - - Utf8Char() { - clear(); - charLength = 0; - } - void clear() { - count = 0; - } - // Add a byte to the UTF8 character. - // When an additional byte leads to an invalid character, return false. - bool addByte(unsigned char b) { - if (count == 0) { - if (b > 0xc1 && (b & 0xe0) == 0xc0) { - charLength = 2; - } else if ((b & 0xf0) == 0xe0) { - charLength = 3; - } else if (b < 0xf5 && (b & 0xf8) == 0xf0) { - charLength = 4; - } else { - return false; +// Struct that represents a multi-byte UTF-8 character. +// This struct is used to keep track of bytes that seem to be valid +// UTF-8. +struct Utf8Char { +public: + unsigned char bytes[4]; + unsigned char count; + unsigned char charLength; + + Utf8Char() + { + clear(); + charLength = 0; + } + void clear() + { + count = 0; + } + // Add a byte to the UTF8 character. + // When an additional byte leads to an invalid character, return false. + bool addByte(unsigned char b) + { + if (count == 0) { + if (b > 0xc1 && (b & 0xe0) == 0xc0) { + charLength = 2; + } else if ((b & 0xf0) == 0xe0) { + charLength = 3; + } else if (b < 0xf5 && (b & 0xf8) == 0xf0) { + charLength = 4; + } else { + return false; + } + bytes[0] = b; + count = 1; + } else if (count < 4 && (b & 0xc0) == 0x80) { + if (count == 1) { + if (charLength == 3 && bytes[0] == 0xe0 && b < 0xa0) { + return false; // overlong 3 byte sequence } - bytes[0] = b; - count = 1; - } else if (count < 4 && (b & 0xc0) == 0x80) { - if (count == 1) { - if (charLength == 3 && bytes[0] == 0xe0 && b < 0xa0) { - return false; // overlong 3 byte sequence + if (charLength == 4) { + if (bytes[0] == 0xf0 && b < 0x90) { + return false; // overlong 4 byte sequence } - if (charLength == 4) { - if (bytes[0] == 0xf0 && b < 0x90) { - return false; // overlong 4 byte sequence - } - if (bytes[0] == 0xf4 && b > 0x8f) { - return false; // Unicode value larger than U+10FFFF - } + if (bytes[0] == 0xf4 && b > 0x8f) { + return false; // Unicode value larger than U+10FFFF } } - bytes[count++] = b; - } else { - return false; } - return true; - } - // Return true if Utf8Char contains one valid character. - bool isComplete() { - return count > 0 && count == charLength; + bytes[count++] = b; + } else { + return false; } - // Add the bytes in this UTF8 character in escaped form to data. - char* escapeBytes(char* data) { - for (unsigned char i = 0; i < count; ++i) { - data = escapeByte(data, bytes[i]); - } - clear(); - return data; + return true; + } + // Return true if Utf8Char contains one valid character. + bool isComplete() + { + return count > 0 && count == charLength; + } + // Add the bytes in this UTF8 character in escaped form to data. + char *escapeBytes(char *data) + { + for (unsigned char i = 0; i < count; ++i) { + data = escapeByte(data, bytes[i]); } - // Add the bytes of the UTF8 character to a buffer. - // Only call this if isComplete() returns true. - char* writeUtf8(char* data) { - for (unsigned char i = 0; i < count; ++i) { - *data++ = bytes[i]; - } - clear(); - return data; + clear(); + return data; + } + // Add the bytes of the UTF8 character to a buffer. + // Only call this if isComplete() returns true. + char *writeUtf8(char *data) + { + for (unsigned char i = 0; i < count; ++i) { + *data++ = bytes[i]; } - // Write the bytes in the UTF8 character literally, or, if the - // character is not complete, write the escaped bytes. - // This is useful to handle the state that remains after handling - // all bytes in a buffer. - char* write(char* data) { - if (isComplete()) { - data = writeUtf8(data); - } else { - data = escapeBytes(data); - } - return data; + clear(); + return data; + } + // Write the bytes in the UTF8 character literally, or, if the + // character is not complete, write the escaped bytes. + // This is useful to handle the state that remains after handling + // all bytes in a buffer. + char *write(char *data) + { + if (isComplete()) { + data = writeUtf8(data); + } else { + data = escapeBytes(data); } - }; + return data; + } +}; } QByteArray KConfigIniBackend::stringToPrintable(const QByteArray &aString, StringType type) @@ -763,7 +760,7 @@ QByteArray KConfigIniBackend::stringToPrintable(const QByteArray &aString, Strin } Utf8Char utf8; - for (; i < l; ++i/*, r++*/) { + for (; i < l; ++i /*, r++*/) { switch (s[i]) { default: if (utf8.addByte(s[i])) { @@ -847,8 +844,8 @@ char KConfigIniBackend::charFromHex(const char *str, const QFile &file, int line } else { QByteArray e(str, 2); e.prepend("\\x"); - qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << "Invalid hex character " << c - << " in \\x<nn>-type escape sequence \"" << e.constData() << "\"."; + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << "Invalid hex character " << c << " in \\x<nn>-type escape sequence \"" << e.constData() + << "\"."; return 'x'; } } @@ -915,8 +912,7 @@ void KConfigIniBackend::printableToString(BufferFragment *aString, const QFile & break; default: *r = '\\'; - qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) - << QStringLiteral("Invalid escape sequence \"\\%1\".").arg(str[i]); + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << QStringLiteral("Invalid escape sequence \"\\%1\".").arg(str[i]); } } } diff --git a/src/core/kconfigini_p.h b/src/core/kconfigini_p.h index d760170d..3397857c 100644 --- a/src/core/kconfigini_p.h +++ b/src/core/kconfigini_p.h @@ -10,15 +10,15 @@ #ifndef KCONFIGINI_P_H #define KCONFIGINI_P_H -#include <kconfigcore_export.h> #include <kconfigbackend_p.h> +#include <kconfigcore_export.h> class QLockFile; class QIODevice; class KConfigIniBackend : public KConfigBackend { -Q_OBJECT + Q_OBJECT private: QLockFile *lockFile; @@ -28,15 +28,9 @@ public: KConfigIniBackend(); ~KConfigIniBackend() override; - ParseInfo parseConfig(const QByteArray &locale, - KEntryMap &entryMap, - ParseOptions options) override; - ParseInfo parseConfig(const QByteArray &locale, - KEntryMap &entryMap, - ParseOptions options, - bool merging); - bool writeConfig(const QByteArray &locale, KEntryMap &entryMap, - WriteOptions options) override; + ParseInfo parseConfig(const QByteArray &locale, KEntryMap &entryMap, ParseOptions options) override; + ParseInfo parseConfig(const QByteArray &locale, KEntryMap &entryMap, ParseOptions options, bool merging); + bool writeConfig(const QByteArray &locale, KEntryMap &entryMap, WriteOptions options) override; bool isWritable() const override; QString nonWritableErrorMessage() const override; @@ -48,7 +42,6 @@ public: bool isLocked() const override; protected: - enum StringType { GroupString = 0, KeyString = 1, @@ -62,8 +55,7 @@ protected: static QString warningProlog(const QFile &file, int line); void writeEntries(const QByteArray &locale, QIODevice &file, const KEntryMap &map); - void writeEntries(const QByteArray &locale, QIODevice &file, const KEntryMap &map, - bool defaultGroup, bool &firstEntry); + void writeEntries(const QByteArray &locale, QIODevice &file, const KEntryMap &map, bool defaultGroup, bool &firstEntry); }; #endif // KCONFIGINI_P_H diff --git a/src/core/kconfigwatcher.cpp b/src/core/kconfigwatcher.cpp index c5aa6205..3da2d535 100644 --- a/src/core/kconfigwatcher.cpp +++ b/src/core/kconfigwatcher.cpp @@ -16,17 +16,18 @@ #endif #include <QDebug> -#include <QThreadStorage> #include <QHash> +#include <QThreadStorage> -class KConfigWatcherPrivate { +class KConfigWatcherPrivate +{ public: KSharedConfig::Ptr m_config; }; KConfigWatcher::Ptr KConfigWatcher::create(const KSharedConfig::Ptr &config) { - static QThreadStorage<QHash<KSharedConfig*, QWeakPointer<KConfigWatcher>>> watcherList; + static QThreadStorage<QHash<KSharedConfig *, QWeakPointer<KConfigWatcher>>> watcherList; auto c = config.data(); KConfigWatcher::Ptr watcher; @@ -43,9 +44,9 @@ KConfigWatcher::Ptr KConfigWatcher::create(const KSharedConfig::Ptr &config) return watcherList.localData().value(c).toStrongRef(); } -KConfigWatcher::KConfigWatcher(const KSharedConfig::Ptr &config): - QObject (nullptr), - d(new KConfigWatcherPrivate) +KConfigWatcher::KConfigWatcher(const KSharedConfig::Ptr &config) + : QObject(nullptr) + , d(new KConfigWatcherPrivate) { Q_ASSERT(config); #if KCONFIG_USE_DBUS @@ -65,13 +66,13 @@ KConfigWatcher::KConfigWatcher(const KSharedConfig::Ptr &config): watchedPaths << QStringLiteral("/kdeglobals"); } - for(const QString &path: qAsConst(watchedPaths)) { + for (const QString &path : qAsConst(watchedPaths)) { QDBusConnection::sessionBus().connect(QString(), path, QStringLiteral("org.kde.kconfig.notify"), QStringLiteral("ConfigChanged"), this, - SLOT(onConfigChangeNotification(QHash<QString,QByteArrayList>))); + SLOT(onConfigChangeNotification(QHash<QString, QByteArrayList>))); } #else qCWarning(KCONFIG_CORE_LOG) << "Use of KConfigWatcher without DBus support. You will not receive updates"; @@ -87,17 +88,16 @@ KSharedConfig::Ptr KConfigWatcher::config() const void KConfigWatcher::onConfigChangeNotification(const QHash<QString, QByteArrayList> &changes) { - //should we ever need it we can determine the file changed with QDbusContext::message().path(), but it doesn't seem too useful + // should we ever need it we can determine the file changed with QDbusContext::message().path(), but it doesn't seem too useful d->m_config->reparseConfiguration(); - for(auto it = changes.constBegin(); it != changes.constEnd(); it++) { - KConfigGroup group = d->m_config->group(QString());//top level group - const auto parts = it.key().split(QLatin1Char('\x1d')); //magic char, see KConfig - for(const QString &groupName: parts) { + for (auto it = changes.constBegin(); it != changes.constEnd(); it++) { + KConfigGroup group = d->m_config->group(QString()); // top level group + const auto parts = it.key().split(QLatin1Char('\x1d')); // magic char, see KConfig + for (const QString &groupName : parts) { group = group.group(groupName); } Q_EMIT configChanged(group, it.value()); } } - diff --git a/src/core/kconfigwatcher.h b/src/core/kconfigwatcher.h index 28576bb4..76418c9b 100644 --- a/src/core/kconfigwatcher.h +++ b/src/core/kconfigwatcher.h @@ -10,8 +10,8 @@ #include <QObject> #include <QSharedPointer> -#include <KSharedConfig> #include <KConfigGroup> +#include <KSharedConfig> #include <kconfigcore_export.h> @@ -23,7 +23,7 @@ class KConfigWatcherPrivate; * Notifies when another client has updated this config file with the Notify flag set. * @since 5.51 */ -class KCONFIGCORE_EXPORT KConfigWatcher: public QObject +class KCONFIGCORE_EXPORT KConfigWatcher : public QObject { Q_OBJECT public: diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp index d5af41e4..669e0ce5 100644 --- a/src/core/kcoreconfigskeleton.cpp +++ b/src/core/kcoreconfigskeleton.cpp @@ -18,16 +18,14 @@ static QString obscuredString(const QString &str) for (int i = 0; i < str.length(); ++i) // yes, no typo. can't encode ' ' or '!' because // they're the unicode BOM. stupid scrambling. stupid. - result += (unicode[ i ].unicode() <= 0x21) ? unicode[ i ] - : QChar(0x1001F - unicode[ i ].unicode()); + result += (unicode[i].unicode() <= 0x21) ? unicode[i] : QChar(0x1001F - unicode[i].unicode()); return result; } KConfigSkeletonItemPrivate::~KConfigSkeletonItemPrivate() = default; -KConfigSkeletonItem::KConfigSkeletonItem(const QString &_group, - const QString &_key) +KConfigSkeletonItem::KConfigSkeletonItem(const QString &_group, const QString &_key) : mGroup(_group) , mKey(_key) , d_ptr(new KConfigSkeletonItemPrivate) @@ -179,19 +177,19 @@ void KConfigSkeletonItem::readImmutability(const KConfigGroup &group) d->mIsImmutable = group.isEntryImmutable(mKey); } -void KConfigSkeletonItem::setIsDefaultImpl(const std::function<bool ()> &impl) +void KConfigSkeletonItem::setIsDefaultImpl(const std::function<bool()> &impl) { Q_D(KConfigSkeletonItem); d->mIsDefaultImpl = impl; } -void KConfigSkeletonItem::setIsSaveNeededImpl(const std::function<bool ()> &impl) +void KConfigSkeletonItem::setIsSaveNeededImpl(const std::function<bool()> &impl) { Q_D(KConfigSkeletonItem); d->mIsSaveNeededImpl = impl; } -void KConfigSkeletonItem::setGetDefaultImpl(const std::function<QVariant ()> &impl) +void KConfigSkeletonItem::setGetDefaultImpl(const std::function<QVariant()> &impl) { Q_D(KConfigSkeletonItem); d->mGetDefaultImpl = impl; @@ -276,18 +274,15 @@ void KPropertySkeletonItem::swapDefault() } } -void KPropertySkeletonItem::setNotifyFunction(const std::function<void ()> &impl) +void KPropertySkeletonItem::setNotifyFunction(const std::function<void()> &impl) { Q_D(KPropertySkeletonItem); d->mNotifyFunction = impl; } -KCoreConfigSkeleton::ItemString::ItemString(const QString &_group, const QString &_key, - QString &reference, - const QString &defaultValue, - Type type) - : KConfigSkeletonGenericItem<QString>(_group, _key, reference, defaultValue), - mType(type) +KCoreConfigSkeleton::ItemString::ItemString(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue, Type type) + : KConfigSkeletonGenericItem<QString>(_group, _key, reference, defaultValue) + , mType(type) { } @@ -341,23 +336,17 @@ QVariant KCoreConfigSkeleton::ItemString::property() const return QVariant(mReference); } -KCoreConfigSkeleton::ItemPassword::ItemPassword(const QString &_group, const QString &_key, - QString &reference, - const QString &defaultValue) +KCoreConfigSkeleton::ItemPassword::ItemPassword(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue) : ItemString(_group, _key, reference, defaultValue, Password) { } -KCoreConfigSkeleton::ItemPath::ItemPath(const QString &_group, const QString &_key, - QString &reference, - const QString &defaultValue) +KCoreConfigSkeleton::ItemPath::ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue) : ItemString(_group, _key, reference, defaultValue, Path) { } -KCoreConfigSkeleton::ItemUrl::ItemUrl(const QString &_group, const QString &_key, - QUrl &reference, - const QUrl &defaultValue) +KCoreConfigSkeleton::ItemUrl::ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue) : KConfigSkeletonGenericItem<QUrl>(_group, _key, reference, defaultValue) { } @@ -400,10 +389,7 @@ QVariant KCoreConfigSkeleton::ItemUrl::property() const return QVariant::fromValue<QUrl>(mReference); } -KCoreConfigSkeleton::ItemProperty::ItemProperty(const QString &_group, - const QString &_key, - QVariant &reference, - const QVariant &defaultValue) +KCoreConfigSkeleton::ItemProperty::ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue) : KConfigSkeletonGenericItem<QVariant>(_group, _key, reference, defaultValue) { } @@ -424,7 +410,7 @@ void KCoreConfigSkeleton::ItemProperty::setProperty(const QVariant &p) bool KCoreConfigSkeleton::ItemProperty::isEqual(const QVariant &v) const { - //this might cause problems if the QVariants are not of default types + // this might cause problems if the QVariants are not of default types return mReference == v; } @@ -433,8 +419,7 @@ QVariant KCoreConfigSkeleton::ItemProperty::property() const return mReference; } -KCoreConfigSkeleton::ItemBool::ItemBool(const QString &_group, const QString &_key, - bool &reference, bool defaultValue) +KCoreConfigSkeleton::ItemBool::ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue) : KConfigSkeletonGenericItem<bool>(_group, _key, reference, defaultValue) { } @@ -463,10 +448,10 @@ QVariant KCoreConfigSkeleton::ItemBool::property() const return QVariant(mReference); } -KCoreConfigSkeleton::ItemInt::ItemInt(const QString &_group, const QString &_key, - qint32 &reference, qint32 defaultValue) +KCoreConfigSkeleton::ItemInt::ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue) : KConfigSkeletonGenericItem<qint32>(_group, _key, reference, defaultValue) - , mHasMin(false), mHasMax(false) + , mHasMin(false) + , mHasMax(false) { } @@ -528,10 +513,10 @@ void KCoreConfigSkeleton::ItemInt::setMaxValue(qint32 v) mMax = v; } -KCoreConfigSkeleton::ItemLongLong::ItemLongLong(const QString &_group, const QString &_key, - qint64 &reference, qint64 defaultValue) +KCoreConfigSkeleton::ItemLongLong::ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue) : KConfigSkeletonGenericItem<qint64>(_group, _key, reference, defaultValue) - , mHasMin(false), mHasMax(false) + , mHasMin(false) + , mHasMax(false) { } @@ -606,11 +591,9 @@ void KCoreConfigSkeleton::ItemEnum::setValueForChoice(const QString &name, const d_ptr->mValues.insert(name, value); } -KCoreConfigSkeleton::ItemEnum::ItemEnum(const QString &_group, const QString &_key, - qint32 &reference, - const QList<Choice> &choices, - qint32 defaultValue) - : ItemInt(_group, _key, reference, defaultValue), mChoices(choices) +KCoreConfigSkeleton::ItemEnum::ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList<Choice> &choices, qint32 defaultValue) + : ItemInt(_group, _key, reference, defaultValue) + , mChoices(choices) { } @@ -623,8 +606,7 @@ void KCoreConfigSkeleton::ItemEnum::readConfig(KConfig *config) int i = 0; mReference = -1; QString tmp = cg.readEntry(mKey, QString()).toLower(); - for (QList<Choice>::ConstIterator it = mChoices.constBegin(); - it != mChoices.constEnd(); ++it, ++i) { + for (QList<Choice>::ConstIterator it = mChoices.constBegin(); it != mChoices.constEnd(); ++it, ++i) { QString choiceName = (*it).name; if (valueForChoice(choiceName).toLower() == tmp) { mReference = i; @@ -665,11 +647,10 @@ QList<KCoreConfigSkeleton::ItemEnum::Choice> KCoreConfigSkeleton::ItemEnum::choi return mChoices; } -KCoreConfigSkeleton::ItemUInt::ItemUInt(const QString &_group, const QString &_key, - quint32 &reference, - quint32 defaultValue) +KCoreConfigSkeleton::ItemUInt::ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue) : KConfigSkeletonGenericItem<quint32>(_group, _key, reference, defaultValue) - , mHasMin(false), mHasMax(false) + , mHasMin(false) + , mHasMax(false) { } @@ -731,10 +712,10 @@ void KCoreConfigSkeleton::ItemUInt::setMaxValue(quint32 v) mMax = v; } -KCoreConfigSkeleton::ItemULongLong::ItemULongLong(const QString &_group, const QString &_key, - quint64 &reference, quint64 defaultValue) +KCoreConfigSkeleton::ItemULongLong::ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue) : KConfigSkeletonGenericItem<quint64>(_group, _key, reference, defaultValue) - , mHasMin(false), mHasMax(false) + , mHasMin(false) + , mHasMax(false) { } @@ -796,10 +777,10 @@ void KCoreConfigSkeleton::ItemULongLong::setMaxValue(quint64 v) mMax = v; } -KCoreConfigSkeleton::ItemDouble::ItemDouble(const QString &_group, const QString &_key, - double &reference, double defaultValue) +KCoreConfigSkeleton::ItemDouble::ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue) : KConfigSkeletonGenericItem<double>(_group, _key, reference, defaultValue) - , mHasMin(false), mHasMax(false) + , mHasMin(false) + , mHasMax(false) { } @@ -861,9 +842,7 @@ void KCoreConfigSkeleton::ItemDouble::setMaxValue(double v) mMax = v; } -KCoreConfigSkeleton::ItemRect::ItemRect(const QString &_group, const QString &_key, - QRect &reference, - const QRect &defaultValue) +KCoreConfigSkeleton::ItemRect::ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue) : KConfigSkeletonGenericItem<QRect>(_group, _key, reference, defaultValue) { } @@ -892,9 +871,7 @@ QVariant KCoreConfigSkeleton::ItemRect::property() const return QVariant(mReference); } -KCoreConfigSkeleton::ItemPoint::ItemPoint(const QString &_group, const QString &_key, - QPoint &reference, - const QPoint &defaultValue) +KCoreConfigSkeleton::ItemPoint::ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue) : KConfigSkeletonGenericItem<QPoint>(_group, _key, reference, defaultValue) { } @@ -923,9 +900,7 @@ QVariant KCoreConfigSkeleton::ItemPoint::property() const return QVariant(mReference); } -KCoreConfigSkeleton::ItemSize::ItemSize(const QString &_group, const QString &_key, - QSize &reference, - const QSize &defaultValue) +KCoreConfigSkeleton::ItemSize::ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue) : KConfigSkeletonGenericItem<QSize>(_group, _key, reference, defaultValue) { } @@ -954,9 +929,7 @@ QVariant KCoreConfigSkeleton::ItemSize::property() const return QVariant(mReference); } -KCoreConfigSkeleton::ItemDateTime::ItemDateTime(const QString &_group, const QString &_key, - QDateTime &reference, - const QDateTime &defaultValue) +KCoreConfigSkeleton::ItemDateTime::ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue) : KConfigSkeletonGenericItem<QDateTime>(_group, _key, reference, defaultValue) { } @@ -985,9 +958,7 @@ QVariant KCoreConfigSkeleton::ItemDateTime::property() const return QVariant(mReference); } -KCoreConfigSkeleton::ItemStringList::ItemStringList(const QString &_group, const QString &_key, - QStringList &reference, - const QStringList &defaultValue) +KCoreConfigSkeleton::ItemStringList::ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue) : KConfigSkeletonGenericItem<QStringList>(_group, _key, reference, defaultValue) { } @@ -1020,9 +991,7 @@ QVariant KCoreConfigSkeleton::ItemStringList::property() const return QVariant(mReference); } -KCoreConfigSkeleton::ItemPathList::ItemPathList(const QString &_group, const QString &_key, - QStringList &reference, - const QStringList &defaultValue) +KCoreConfigSkeleton::ItemPathList::ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue) : ItemStringList(_group, _key, reference, defaultValue) { } @@ -1054,10 +1023,8 @@ void KCoreConfigSkeleton::ItemPathList::writeConfig(KConfig *config) } } -KCoreConfigSkeleton::ItemUrlList::ItemUrlList(const QString &_group, const QString &_key, - QList<QUrl> &reference, - const QList<QUrl> &defaultValue) - : KConfigSkeletonGenericItem<QList<QUrl> >(_group, _key, reference, defaultValue) +KCoreConfigSkeleton::ItemUrlList::ItemUrlList(const QString &_group, const QString &_key, QList<QUrl> &reference, const QList<QUrl> &defaultValue) + : KConfigSkeletonGenericItem<QList<QUrl>>(_group, _key, reference, defaultValue) { } @@ -1101,23 +1068,21 @@ void KCoreConfigSkeleton::ItemUrlList::writeConfig(KConfig *config) void KCoreConfigSkeleton::ItemUrlList::setProperty(const QVariant &p) { - mReference = qvariant_cast<QList<QUrl> >(p); + mReference = qvariant_cast<QList<QUrl>>(p); } bool KCoreConfigSkeleton::ItemUrlList::isEqual(const QVariant &v) const { - return mReference == qvariant_cast<QList<QUrl> >(v); + return mReference == qvariant_cast<QList<QUrl>>(v); } QVariant KCoreConfigSkeleton::ItemUrlList::property() const { - return QVariant::fromValue<QList<QUrl> >(mReference); + return QVariant::fromValue<QList<QUrl>>(mReference); } -KCoreConfigSkeleton::ItemIntList::ItemIntList(const QString &_group, const QString &_key, - QList<int> &reference, - const QList<int> &defaultValue) - : KConfigSkeletonGenericItem<QList<int> >(_group, _key, reference, defaultValue) +KCoreConfigSkeleton::ItemIntList::ItemIntList(const QString &_group, const QString &_key, QList<int> &reference, const QList<int> &defaultValue) + : KConfigSkeletonGenericItem<QList<int>>(_group, _key, reference, defaultValue) { } @@ -1136,35 +1101,35 @@ void KCoreConfigSkeleton::ItemIntList::readConfig(KConfig *config) void KCoreConfigSkeleton::ItemIntList::setProperty(const QVariant &p) { - mReference = qvariant_cast< QList<int> >(p); + mReference = qvariant_cast<QList<int>>(p); } bool KCoreConfigSkeleton::ItemIntList::isEqual(const QVariant &v) const { - return mReference == qvariant_cast< QList<int> >(v); + return mReference == qvariant_cast<QList<int>>(v); } QVariant KCoreConfigSkeleton::ItemIntList::property() const { - return QVariant::fromValue< QList<int> >(mReference); + return QVariant::fromValue<QList<int>>(mReference); } -//static int kCoreConfigSkeletionDebugArea() { static int s_area = KDebug::registerArea("kdecore (KConfigSkeleton)"); return s_area; } +// static int kCoreConfigSkeletionDebugArea() { static int s_area = KDebug::registerArea("kdecore (KConfigSkeleton)"); return s_area; } KCoreConfigSkeleton::KCoreConfigSkeleton(const QString &configname, QObject *parent) - : QObject(parent), - d(new KCoreConfigSkeletonPrivate) + : QObject(parent) + , d(new KCoreConfigSkeletonPrivate) { - //qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")"; + // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")"; d->mConfig = KSharedConfig::openConfig(configname, KConfig::FullConfig); } KCoreConfigSkeleton::KCoreConfigSkeleton(KSharedConfig::Ptr pConfig, QObject *parent) - : QObject(parent), - d(new KCoreConfigSkeletonPrivate) + : QObject(parent) + , d(new KCoreConfigSkeletonPrivate) { - //qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")"; + // qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")"; d->mConfig = std::move(pConfig); } @@ -1271,7 +1236,7 @@ bool KCoreConfigSkeleton::isSaveNeeded() const bool KCoreConfigSkeleton::save() { - //qDebug(); + // qDebug(); KConfigSkeletonItem::List::ConstIterator it; for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { (*it)->writeConfig(d->mConfig.data()); @@ -1330,8 +1295,7 @@ bool KCoreConfigSkeleton::usrWriteConfig() void KCoreConfigSkeleton::addItem(KConfigSkeletonItem *item, const QString &name) { if (d->mItems.contains(item)) { - if (item->name() == name || - (name.isEmpty() && item->name() == item->key())) { + if (item->name() == name || (name.isEmpty() && item->name() == item->key())) { // nothing to do -> it is already in our collection // and the name isn't changing return; @@ -1366,185 +1330,149 @@ void KCoreConfigSkeleton::clearItems() qDeleteAll(items); } -KCoreConfigSkeleton::ItemString *KCoreConfigSkeleton::addItemString(const QString &name, QString &reference, - const QString &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemString *KCoreConfigSkeleton::addItemString(const QString &name, QString &reference, const QString &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemString *item; - item = new KCoreConfigSkeleton::ItemString(d->mCurrentGroup, key.isEmpty() ? name : key, - reference, defaultValue, - KCoreConfigSkeleton::ItemString::Normal); + item = new KCoreConfigSkeleton::ItemString(d->mCurrentGroup, key.isEmpty() ? name : key, reference, defaultValue, KCoreConfigSkeleton::ItemString::Normal); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemPassword *KCoreConfigSkeleton::addItemPassword(const QString &name, QString &reference, - const QString &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemPassword * +KCoreConfigSkeleton::addItemPassword(const QString &name, QString &reference, const QString &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemPassword *item; - item = new KCoreConfigSkeleton::ItemPassword(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemPassword(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemPath *KCoreConfigSkeleton::addItemPath(const QString &name, QString &reference, - const QString &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemPath *KCoreConfigSkeleton::addItemPath(const QString &name, QString &reference, const QString &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemPath *item; - item = new KCoreConfigSkeleton::ItemPath(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemPath(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemProperty *KCoreConfigSkeleton::addItemProperty(const QString &name, QVariant &reference, - const QVariant &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemProperty * +KCoreConfigSkeleton::addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemProperty *item; - item = new KCoreConfigSkeleton::ItemProperty(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemProperty(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemBool *KCoreConfigSkeleton::addItemBool(const QString &name, bool &reference, - bool defaultValue, const QString &key) +KCoreConfigSkeleton::ItemBool *KCoreConfigSkeleton::addItemBool(const QString &name, bool &reference, bool defaultValue, const QString &key) { KCoreConfigSkeleton::ItemBool *item; - item = new KCoreConfigSkeleton::ItemBool(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemBool(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemInt *KCoreConfigSkeleton::addItemInt(const QString &name, qint32 &reference, - qint32 defaultValue, const QString &key) +KCoreConfigSkeleton::ItemInt *KCoreConfigSkeleton::addItemInt(const QString &name, qint32 &reference, qint32 defaultValue, const QString &key) { KCoreConfigSkeleton::ItemInt *item; - item = new KCoreConfigSkeleton::ItemInt(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemUInt *KCoreConfigSkeleton::addItemUInt(const QString &name, quint32 &reference, - quint32 defaultValue, const QString &key) +KCoreConfigSkeleton::ItemUInt *KCoreConfigSkeleton::addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue, const QString &key) { KCoreConfigSkeleton::ItemUInt *item; - item = new KCoreConfigSkeleton::ItemUInt(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemUInt(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemLongLong(const QString &name, qint64 &reference, - qint64 defaultValue, const QString &key) +KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue, const QString &key) { KCoreConfigSkeleton::ItemLongLong *item; - item = new KCoreConfigSkeleton::ItemLongLong(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemLongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0) -KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemInt64( - const QString &name, - qint64 &reference, - qint64 defaultValue, - const QString &key) +KCoreConfigSkeleton::ItemLongLong *KCoreConfigSkeleton::addItemInt64(const QString &name, qint64 &reference, qint64 defaultValue, const QString &key) { return addItemLongLong(name, reference, defaultValue, key); } #endif -KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemULongLong(const QString &name, quint64 &reference, - quint64 defaultValue, const QString &key) +KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue, const QString &key) { KCoreConfigSkeleton::ItemULongLong *item; - item = new KCoreConfigSkeleton::ItemULongLong(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemULongLong(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0) -KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemUInt64( - const QString &name, - quint64 &reference, - quint64 defaultValue, - const QString &key) +KCoreConfigSkeleton::ItemULongLong *KCoreConfigSkeleton::addItemUInt64(const QString &name, quint64 &reference, quint64 defaultValue, const QString &key) { return addItemULongLong(name, reference, defaultValue, key); } #endif -KCoreConfigSkeleton::ItemDouble *KCoreConfigSkeleton::addItemDouble(const QString &name, double &reference, - double defaultValue, const QString &key) +KCoreConfigSkeleton::ItemDouble *KCoreConfigSkeleton::addItemDouble(const QString &name, double &reference, double defaultValue, const QString &key) { KCoreConfigSkeleton::ItemDouble *item; - item = new KCoreConfigSkeleton::ItemDouble(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemDouble(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemRect *KCoreConfigSkeleton::addItemRect(const QString &name, QRect &reference, - const QRect &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemRect *KCoreConfigSkeleton::addItemRect(const QString &name, QRect &reference, const QRect &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemRect *item; - item = new KCoreConfigSkeleton::ItemRect(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemRect(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemPoint *KCoreConfigSkeleton::addItemPoint(const QString &name, QPoint &reference, - const QPoint &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemPoint *KCoreConfigSkeleton::addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemPoint *item; - item = new KCoreConfigSkeleton::ItemPoint(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemPoint(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemSize *KCoreConfigSkeleton::addItemSize(const QString &name, QSize &reference, - const QSize &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemSize *KCoreConfigSkeleton::addItemSize(const QString &name, QSize &reference, const QSize &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemSize *item; - item = new KCoreConfigSkeleton::ItemSize(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemSize(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemDateTime *KCoreConfigSkeleton::addItemDateTime(const QString &name, QDateTime &reference, - const QDateTime &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemDateTime * +KCoreConfigSkeleton::addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemDateTime *item; - item = new KCoreConfigSkeleton::ItemDateTime(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemDateTime(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemStringList *KCoreConfigSkeleton::addItemStringList(const QString &name, QStringList &reference, - const QStringList &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemStringList * +KCoreConfigSkeleton::addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemStringList *item; - item = new KCoreConfigSkeleton::ItemStringList(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemStringList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } -KCoreConfigSkeleton::ItemIntList *KCoreConfigSkeleton::addItemIntList(const QString &name, QList<int> &reference, - const QList<int> &defaultValue, const QString &key) +KCoreConfigSkeleton::ItemIntList * +KCoreConfigSkeleton::addItemIntList(const QString &name, QList<int> &reference, const QList<int> &defaultValue, const QString &key) { KCoreConfigSkeleton::ItemIntList *item; - item = new KCoreConfigSkeleton::ItemIntList(d->mCurrentGroup, key.isNull() ? name : key, - reference, defaultValue); + item = new KCoreConfigSkeleton::ItemIntList(d->mCurrentGroup, key.isNull() ? name : key, reference, defaultValue); addItem(item, name); return item; } @@ -1560,25 +1488,36 @@ KConfigSkeletonItem *KCoreConfigSkeleton::findItem(const QString &name) const return d->mItemDict.value(name); } -KConfigCompilerSignallingItem::KConfigCompilerSignallingItem(KConfigSkeletonItem* item, QObject* object, - KConfigCompilerSignallingItem::NotifyFunction targetFunction, quint64 userData) - : KConfigSkeletonItem(item->group(), item->key()), mItem(item), mTargetFunction(targetFunction), - mObject(object), mUserData(userData) +KConfigCompilerSignallingItem::KConfigCompilerSignallingItem(KConfigSkeletonItem *item, + QObject *object, + KConfigCompilerSignallingItem::NotifyFunction targetFunction, + quint64 userData) + : KConfigSkeletonItem(item->group(), item->key()) + , mItem(item) + , mTargetFunction(targetFunction) + , mObject(object) + , mUserData(userData) { Q_ASSERT(mTargetFunction); Q_ASSERT(mItem); Q_ASSERT(mObject); - setIsDefaultImpl([this] { return mItem->isDefault(); }); - setIsSaveNeededImpl([this] { return mItem->isSaveNeeded(); }); - setGetDefaultImpl([this] {return mItem->getDefault(); }); + setIsDefaultImpl([this] { + return mItem->isDefault(); + }); + setIsSaveNeededImpl([this] { + return mItem->isSaveNeeded(); + }); + setGetDefaultImpl([this] { + return mItem->getDefault(); + }); } KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem() { } -bool KConfigCompilerSignallingItem::isEqual(const QVariant& p) const +bool KConfigCompilerSignallingItem::isEqual(const QVariant &p) const { return mItem->isEqual(p); } @@ -1588,11 +1527,11 @@ QVariant KConfigCompilerSignallingItem::property() const return mItem->property(); } -void KConfigCompilerSignallingItem::readConfig(KConfig* c) +void KConfigCompilerSignallingItem::readConfig(KConfig *c) { QVariant oldValue = mItem->property(); mItem->readConfig(c); - //readConfig() changes mIsImmutable, update it here as well + // readConfig() changes mIsImmutable, update it here as well KConfigGroup cg = configGroup(c); readImmutability(cg); if (!mItem->isEqual(oldValue)) { @@ -1600,15 +1539,15 @@ void KConfigCompilerSignallingItem::readConfig(KConfig* c) } } -void KConfigCompilerSignallingItem::readDefault(KConfig* c) +void KConfigCompilerSignallingItem::readDefault(KConfig *c) { mItem->readDefault(c); - //readDefault() changes mIsImmutable, update it here as well + // readDefault() changes mIsImmutable, update it here as well KConfigGroup cg = configGroup(c); readImmutability(cg); } -void KConfigCompilerSignallingItem::writeConfig(KConfig* c) +void KConfigCompilerSignallingItem::writeConfig(KConfig *c) { mItem->writeConfig(c); } @@ -1622,7 +1561,7 @@ void KConfigCompilerSignallingItem::setDefault() } } -void KConfigCompilerSignallingItem::setProperty(const QVariant& p) +void KConfigCompilerSignallingItem::setProperty(const QVariant &p) { if (!mItem->isEqual(p)) { mItem->setProperty(p); diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h index e7b814e8..aafc417c 100644 --- a/src/core/kcoreconfigskeleton.h +++ b/src/core/kcoreconfigskeleton.h @@ -12,15 +12,15 @@ #include <kconfigcore_export.h> -#include <ksharedconfig.h> #include <kconfiggroup.h> +#include <ksharedconfig.h> #include <QDate> #include <QHash> #include <QRect> #include <QStringList> -#include <QVariant> #include <QUrl> +#include <QVariant> class KCoreConfigSkeletonPrivate; @@ -42,9 +42,9 @@ class KCONFIGCORE_EXPORT KConfigSkeletonItem { Q_DECLARE_PRIVATE(KConfigSkeletonItem) public: - typedef QList < KConfigSkeletonItem * >List; - typedef QHash < QString, KConfigSkeletonItem * > Dict; - typedef QHash < QString, KConfigSkeletonItem * >::Iterator DictIterator; + typedef QList<KConfigSkeletonItem *> List; + typedef QHash<QString, KConfigSkeletonItem *> Dict; + typedef QHash<QString, KConfigSkeletonItem *>::Iterator DictIterator; /** * Constructor. @@ -310,29 +310,35 @@ public: * Set a notify function, it will be invoked when the value of the property changes. * @since 5.68 */ - void setNotifyFunction(const std::function<void ()> &impl); + void setNotifyFunction(const std::function<void()> &impl); }; - /** * \class KConfigSkeletonGenericItem kcoreconfigskeleton.h <KConfigSkeletonGenericItem> */ -template < typename T > class KConfigSkeletonGenericItem: public KConfigSkeletonItem +template<typename T> +class KConfigSkeletonGenericItem : public KConfigSkeletonItem { public: /** @copydoc KConfigSkeletonItem(const QString&, const QString&) @param reference The initial value to hold in the item @param defaultValue The default value for the item */ - KConfigSkeletonGenericItem(const QString &_group, const QString &_key, T &reference, - T defaultValue) - : KConfigSkeletonItem(_group, _key), mReference(reference), - mDefault(defaultValue), mLoadedValue(defaultValue) + KConfigSkeletonGenericItem(const QString &_group, const QString &_key, T &reference, T defaultValue) + : KConfigSkeletonItem(_group, _key) + , mReference(reference) + , mDefault(defaultValue) + , mLoadedValue(defaultValue) { - setIsDefaultImpl([this] { return mReference == mDefault; }); - setIsSaveNeededImpl([this] { return mReference != mLoadedValue; }); - setGetDefaultImpl([this] { return QVariant::fromValue(mDefault); }); - + setIsDefaultImpl([this] { + return mReference == mDefault; + }); + setIsSaveNeededImpl([this] { + return mReference != mLoadedValue; + }); + setGetDefaultImpl([this] { + return QVariant::fromValue(mDefault); + }); } /** @@ -407,7 +413,7 @@ public: } protected: - T &mReference; ///< Stores the value for this item + T &mReference; ///< Stores the value for this item T mDefault; ///< The default value for this item T mLoadedValue; }; @@ -428,17 +434,16 @@ protected: class KCONFIGCORE_EXPORT KConfigCompilerSignallingItem : public KConfigSkeletonItem { public: - typedef void (QObject::* NotifyFunction)(quint64 arg); - /** - * Constructor. - * - * @param item the KConfigSkeletonItem to wrap - * @param targetFunction the method to invoke whenever the value of @p item changes - * @param object The object on which the method is invoked. - * @param userData This data will be passed to @p targetFunction on every property change - */ - KConfigCompilerSignallingItem(KConfigSkeletonItem *item, QObject* object, - NotifyFunction targetFunction, quint64 userData); + typedef void (QObject::*NotifyFunction)(quint64 arg); + /** + * Constructor. + * + * @param item the KConfigSkeletonItem to wrap + * @param targetFunction the method to invoke whenever the value of @p item changes + * @param object The object on which the method is invoked. + * @param userData This data will be passed to @p targetFunction on every property change + */ + KConfigCompilerSignallingItem(KConfigSkeletonItem *item, QObject *object, NotifyFunction targetFunction, quint64 userData); ~KConfigCompilerSignallingItem() override; void readConfig(KConfig *) override; @@ -466,14 +471,14 @@ private: // call the pointer to member function using the strange ->* operator (mObject->*mTargetFunction)(mUserData); } + private: QScopedPointer<KConfigSkeletonItem> mItem; NotifyFunction mTargetFunction; - QObject* mObject; + QObject *mObject; quint64 mUserData; }; - /** * \class KCoreConfigSkeleton kcoreconfigskeleton.h <KCoreConfigSkeleton> * @@ -540,7 +545,7 @@ public: /** * Class for handling a string preferences item. */ - class KCONFIGCORE_EXPORT ItemString: public KConfigSkeletonGenericItem < QString > + class KCONFIGCORE_EXPORT ItemString : public KConfigSkeletonGenericItem<QString> { public: enum Type { @@ -565,9 +570,10 @@ public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem @param type The type of string held by the item */ - ItemString(const QString &_group, const QString &_key, + ItemString(const QString &_group, + const QString &_key, QString &reference, - const QString &defaultValue = QLatin1String(""), // NOT QString() !! + const QString &defaultValue = QLatin1String(""), // NOT QString() !! Type type = Normal); /** @copydoc KConfigSkeletonItem::writeConfig(KConfig*) */ @@ -592,39 +598,33 @@ public: /** * Class for handling a password preferences item. */ - class KCONFIGCORE_EXPORT ItemPassword: public ItemString + class KCONFIGCORE_EXPORT ItemPassword : public ItemString { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemPassword(const QString &_group, const QString &_key, - QString &reference, - const QString &defaultValue = QLatin1String("")); // NOT QString() !! + ItemPassword(const QString &_group, const QString &_key, QString &reference, + const QString &defaultValue = QLatin1String("")); // NOT QString() !! }; /** * Class for handling a path preferences item. */ - class KCONFIGCORE_EXPORT ItemPath: public ItemString + class KCONFIGCORE_EXPORT ItemPath : public ItemString { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemPath(const QString &_group, const QString &_key, - QString &reference, - const QString &defaultValue = QString()); + ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue = QString()); }; /** * Class for handling a url preferences item. */ - class KCONFIGCORE_EXPORT ItemUrl: public KConfigSkeletonGenericItem < QUrl > + class KCONFIGCORE_EXPORT ItemUrl : public KConfigSkeletonGenericItem<QUrl> { public: - /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemUrl(const QString &_group, const QString &_key, - QUrl &reference, - const QUrl &defaultValue = QUrl()); + ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue = QUrl()); /** @copydoc KConfigSkeletonItem::writeConfig(KConfig*) */ void writeConfig(KConfig *config) override; @@ -645,12 +645,11 @@ public: /** * Class for handling a QVariant preferences item. */ - class KCONFIGCORE_EXPORT ItemProperty: public KConfigSkeletonGenericItem < QVariant > + class KCONFIGCORE_EXPORT ItemProperty : public KConfigSkeletonGenericItem<QVariant> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemProperty(const QString &_group, const QString &_key, - QVariant &reference, const QVariant &defaultValue = QVariant()); + ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue = QVariant()); void readConfig(KConfig *config) override; void setProperty(const QVariant &p) override; @@ -665,12 +664,11 @@ public: /** * Class for handling a bool preferences item. */ - class KCONFIGCORE_EXPORT ItemBool: public KConfigSkeletonGenericItem < bool > + class KCONFIGCORE_EXPORT ItemBool : public KConfigSkeletonGenericItem<bool> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemBool(const QString &_group, const QString &_key, bool &reference, - bool defaultValue = true); + ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue = true); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -688,12 +686,11 @@ public: /** * Class for handling a 32-bit integer preferences item. */ - class KCONFIGCORE_EXPORT ItemInt: public KConfigSkeletonGenericItem < qint32 > + class KCONFIGCORE_EXPORT ItemInt : public KConfigSkeletonGenericItem<qint32> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemInt(const QString &_group, const QString &_key, qint32 &reference, - qint32 defaultValue = 0); + ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue = 0); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -733,12 +730,11 @@ public: /** * Class for handling a 64-bit integer preferences item. */ - class KCONFIGCORE_EXPORT ItemLongLong: public KConfigSkeletonGenericItem < qint64 > + class KCONFIGCORE_EXPORT ItemLongLong : public KConfigSkeletonGenericItem<qint64> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, - qint64 defaultValue = 0); + ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue = 0); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -777,7 +773,7 @@ public: /** * Class for handling enums. */ - class KCONFIGCORE_EXPORT ItemEnum: public ItemInt + class KCONFIGCORE_EXPORT ItemEnum : public ItemInt { public: struct Choice { @@ -790,8 +786,7 @@ public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem @param choices The list of enums that can be stored in this item */ - ItemEnum(const QString &_group, const QString &_key, qint32 &reference, - const QList<Choice> &choices, qint32 defaultValue = 0); + ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList<Choice> &choices, qint32 defaultValue = 0); QList<Choice> choices() const; @@ -823,12 +818,11 @@ public: /** * Class for handling an unsigned 32-bit integer preferences item. */ - class KCONFIGCORE_EXPORT ItemUInt: public KConfigSkeletonGenericItem < quint32 > + class KCONFIGCORE_EXPORT ItemUInt : public KConfigSkeletonGenericItem<quint32> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemUInt(const QString &_group, const QString &_key, - quint32 &reference, quint32 defaultValue = 0); + ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue = 0); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -864,12 +858,11 @@ public: /** * Class for handling unsigned 64-bit integer preferences item. */ - class KCONFIGCORE_EXPORT ItemULongLong: public KConfigSkeletonGenericItem < quint64 > + class KCONFIGCORE_EXPORT ItemULongLong : public KConfigSkeletonGenericItem<quint64> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, - quint64 defaultValue = 0); + ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue = 0); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -908,12 +901,11 @@ public: /** * Class for handling a floating point preference item. */ - class KCONFIGCORE_EXPORT ItemDouble: public KConfigSkeletonGenericItem < double > + class KCONFIGCORE_EXPORT ItemDouble : public KConfigSkeletonGenericItem<double> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemDouble(const QString &_group, const QString &_key, - double &reference, double defaultValue = 0); + ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue = 0); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -949,12 +941,11 @@ public: /** * Class for handling a QRect preferences item. */ - class KCONFIGCORE_EXPORT ItemRect: public KConfigSkeletonGenericItem < QRect > + class KCONFIGCORE_EXPORT ItemRect : public KConfigSkeletonGenericItem<QRect> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemRect(const QString &_group, const QString &_key, QRect &reference, - const QRect &defaultValue = QRect()); + ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue = QRect()); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -972,12 +963,11 @@ public: /** * Class for handling a QPoint preferences item. */ - class KCONFIGCORE_EXPORT ItemPoint: public KConfigSkeletonGenericItem < QPoint > + class KCONFIGCORE_EXPORT ItemPoint : public KConfigSkeletonGenericItem<QPoint> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemPoint(const QString &_group, const QString &_key, QPoint &reference, - const QPoint &defaultValue = QPoint()); + ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue = QPoint()); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -995,12 +985,11 @@ public: /** * Class for handling a QSize preferences item. */ - class KCONFIGCORE_EXPORT ItemSize: public KConfigSkeletonGenericItem < QSize > + class KCONFIGCORE_EXPORT ItemSize : public KConfigSkeletonGenericItem<QSize> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemSize(const QString &_group, const QString &_key, QSize &reference, - const QSize &defaultValue = QSize()); + ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue = QSize()); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -1018,13 +1007,11 @@ public: /** * Class for handling a QDateTime preferences item. */ - class KCONFIGCORE_EXPORT ItemDateTime: public KConfigSkeletonGenericItem < QDateTime > + class KCONFIGCORE_EXPORT ItemDateTime : public KConfigSkeletonGenericItem<QDateTime> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemDateTime(const QString &_group, const QString &_key, - QDateTime &reference, - const QDateTime &defaultValue = QDateTime()); + ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue = QDateTime()); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -1042,13 +1029,11 @@ public: /** * Class for handling a string list preferences item. */ - class KCONFIGCORE_EXPORT ItemStringList: public KConfigSkeletonGenericItem < QStringList > + class KCONFIGCORE_EXPORT ItemStringList : public KConfigSkeletonGenericItem<QStringList> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemStringList(const QString &_group, const QString &_key, - QStringList &reference, - const QStringList &defaultValue = QStringList()); + ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue = QStringList()); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -1066,13 +1051,11 @@ public: /** * Class for handling a path list preferences item. */ - class KCONFIGCORE_EXPORT ItemPathList: public ItemStringList + class KCONFIGCORE_EXPORT ItemPathList : public ItemStringList { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemPathList(const QString &_group, const QString &_key, - QStringList &reference, - const QStringList &defaultValue = QStringList()); + ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue = QStringList()); /** @copydoc KConfigSkeletonItem::readConfig */ void readConfig(KConfig *config) override; @@ -1083,13 +1066,11 @@ public: /** * Class for handling a url list preferences item. */ - class KCONFIGCORE_EXPORT ItemUrlList: public KConfigSkeletonGenericItem < QList<QUrl> > + class KCONFIGCORE_EXPORT ItemUrlList : public KConfigSkeletonGenericItem<QList<QUrl>> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemUrlList(const QString &_group, const QString &_key, - QList<QUrl> &reference, - const QList<QUrl> &defaultValue = QList<QUrl>()); + ItemUrlList(const QString &_group, const QString &_key, QList<QUrl> &reference, const QList<QUrl> &defaultValue = QList<QUrl>()); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -1110,13 +1091,11 @@ public: /** * Class for handling an integer list preferences item. */ - class KCONFIGCORE_EXPORT ItemIntList: public KConfigSkeletonGenericItem < QList < int > > + class KCONFIGCORE_EXPORT ItemIntList : public KConfigSkeletonGenericItem<QList<int>> { public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ - ItemIntList(const QString &_group, const QString &_key, - QList < int > &reference, - const QList < int > &defaultValue = QList < int >()); + ItemIntList(const QString &_group, const QString &_key, QList<int> &reference, const QList<int> &defaultValue = QList<int>()); /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ void readConfig(KConfig *config) override; @@ -1246,8 +1225,9 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemString *addItemString(const QString &name, QString &reference, - const QString &defaultValue = QLatin1String(""), // NOT QString() !! + ItemString *addItemString(const QString &name, + QString &reference, + const QString &defaultValue = QLatin1String(""), // NOT QString() !! const QString &key = QString()); /** @@ -1263,9 +1243,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemPassword *addItemPassword(const QString &name, QString &reference, - const QString &defaultValue = QLatin1String(""), - const QString &key = QString()); + ItemPassword *addItemPassword(const QString &name, QString &reference, const QString &defaultValue = QLatin1String(""), const QString &key = QString()); /** * Register a path item of type QString. The string value is interpreted @@ -1280,9 +1258,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemPath *addItemPath(const QString &name, QString &reference, - const QString &defaultValue = QLatin1String(""), - const QString &key = QString()); + ItemPath *addItemPath(const QString &name, QString &reference, const QString &defaultValue = QLatin1String(""), const QString &key = QString()); /** * Register a property item of type QVariant. Note that only the following @@ -1297,9 +1273,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemProperty *addItemProperty(const QString &name, QVariant &reference, - const QVariant &defaultValue = QVariant(), - const QString &key = QString()); + ItemProperty *addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue = QVariant(), const QString &key = QString()); /** * Register an item of type bool. * @@ -1311,9 +1285,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemBool *addItemBool(const QString &name, bool &reference, - bool defaultValue = false, - const QString &key = QString()); + ItemBool *addItemBool(const QString &name, bool &reference, bool defaultValue = false, const QString &key = QString()); /** * Register an item of type qint32. @@ -1326,8 +1298,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemInt *addItemInt(const QString &name, qint32 &reference, qint32 defaultValue = 0, - const QString &key = QString()); + ItemInt *addItemInt(const QString &name, qint32 &reference, qint32 defaultValue = 0, const QString &key = QString()); /** * Register an item of type quint32. @@ -1340,9 +1311,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemUInt *addItemUInt(const QString &name, quint32 &reference, - quint32 defaultValue = 0, - const QString &key = QString()); + ItemUInt *addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue = 0, const QString &key = QString()); /** * Register an item of type qint64. @@ -1355,18 +1324,14 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemLongLong *addItemLongLong(const QString &name, qint64 &reference, - qint64 defaultValue = 0, - const QString &key = QString()); + ItemLongLong *addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue = 0, const QString &key = QString()); #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0) /** * @deprecated Since 5.0, use addItemLongLong(). */ KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use KCoreConfigSkeleton::addItemLongLong(...)") - ItemLongLong *addItemInt64(const QString &name, qint64 &reference, - qint64 defaultValue = 0, - const QString &key = QString()); + ItemLongLong *addItemInt64(const QString &name, qint64 &reference, qint64 defaultValue = 0, const QString &key = QString()); #endif /** @@ -1380,18 +1345,14 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemULongLong *addItemULongLong(const QString &name, quint64 &reference, - quint64 defaultValue = 0, - const QString &key = QString()); + ItemULongLong *addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue = 0, const QString &key = QString()); #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0) /** * @deprecated Since 5.0, use addItemULongLong(). */ KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use KCoreConfigSkeleton::addItemULongLong(...)") - ItemULongLong *addItemUInt64(const QString &name, quint64 &reference, - quint64 defaultValue = 0, - const QString &key = QString()); + ItemULongLong *addItemUInt64(const QString &name, quint64 &reference, quint64 defaultValue = 0, const QString &key = QString()); #endif /** @@ -1405,9 +1366,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemDouble *addItemDouble(const QString &name, double &reference, - double defaultValue = 0.0, - const QString &key = QString()); + ItemDouble *addItemDouble(const QString &name, double &reference, double defaultValue = 0.0, const QString &key = QString()); /** * Register an item of type QRect. @@ -1420,9 +1379,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemRect *addItemRect(const QString &name, QRect &reference, - const QRect &defaultValue = QRect(), - const QString &key = QString()); + ItemRect *addItemRect(const QString &name, QRect &reference, const QRect &defaultValue = QRect(), const QString &key = QString()); /** * Register an item of type QPoint. @@ -1435,9 +1392,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemPoint *addItemPoint(const QString &name, QPoint &reference, - const QPoint &defaultValue = QPoint(), - const QString &key = QString()); + ItemPoint *addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue = QPoint(), const QString &key = QString()); /** * Register an item of type QSize. @@ -1450,9 +1405,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemSize *addItemSize(const QString &name, QSize &reference, - const QSize &defaultValue = QSize(), - const QString &key = QString()); + ItemSize *addItemSize(const QString &name, QSize &reference, const QSize &defaultValue = QSize(), const QString &key = QString()); /** * Register an item of type QDateTime. @@ -1465,9 +1418,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemDateTime *addItemDateTime(const QString &name, QDateTime &reference, - const QDateTime &defaultValue = QDateTime(), - const QString &key = QString()); + ItemDateTime *addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue = QDateTime(), const QString &key = QString()); /** * Register an item of type QStringList. @@ -1480,9 +1431,8 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemStringList *addItemStringList(const QString &name, QStringList &reference, - const QStringList &defaultValue = QStringList(), - const QString &key = QString()); + ItemStringList * + addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue = QStringList(), const QString &key = QString()); /** * Register an item of type QList<int>. @@ -1495,10 +1445,7 @@ public: * @param key Key used in config file. If key is null, name is used as key. * @return The created item */ - ItemIntList *addItemIntList(const QString &name, QList < int > &reference, - const QList < int > &defaultValue = - QList < int >(), - const QString &key = QString()); + ItemIntList *addItemIntList(const QString &name, QList<int> &reference, const QList<int> &defaultValue = QList<int>(), const QString &key = QString()); /** * Return the @ref KConfig object used for reading and writing the settings. @@ -1623,7 +1570,7 @@ protected: virtual bool usrSave(); #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0) - /** + /** * @deprecated since 5.0, override usrRead instead. This method is still called from usrRead * for compatibility. */ @@ -1632,7 +1579,7 @@ protected: #endif #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0) - /** + /** * @deprecated since 5.0, override usrSave instead. This method is still called from usrSave * for compatibility. */ @@ -1643,7 +1590,6 @@ protected: private: KCoreConfigSkeletonPrivate *const d; friend class KConfigSkeleton; - }; #endif diff --git a/src/core/kcoreconfigskeleton_p.h b/src/core/kcoreconfigskeleton_p.h index 006bd45f..d854cc43 100644 --- a/src/core/kcoreconfigskeleton_p.h +++ b/src/core/kcoreconfigskeleton_p.h @@ -15,8 +15,10 @@ class KCoreConfigSkeletonPrivate { public: KCoreConfigSkeletonPrivate() - : mCurrentGroup(QStringLiteral("No Group")), mUseDefaults(false) - {} + : mCurrentGroup(QStringLiteral("No Group")) + , mUseDefaults(false) + { + } ~KCoreConfigSkeletonPrivate() { KConfigSkeletonItem::List::ConstIterator it; @@ -40,7 +42,8 @@ public: KConfigSkeletonItemPrivate() : mIsImmutable(true) , mWriteFlags(KConfigBase::Normal) - {} + { + } virtual ~KConfigSkeletonItemPrivate(); bool mIsImmutable; ///< Indicates this item is immutable KConfigBase::WriteConfigFlags mWriteFlags; ///< The flags to pass to calls of writeEntry() and revertToDefault() @@ -79,5 +82,4 @@ public: std::function<void()> mNotifyFunction; }; - #endif diff --git a/src/core/kdesktopfile.cpp b/src/core/kdesktopfile.cpp index 0dccd2d2..d5029ffe 100644 --- a/src/core/kdesktopfile.cpp +++ b/src/core/kdesktopfile.cpp @@ -14,14 +14,14 @@ #include <QDir> #include <QFileInfo> -#include <QUrl> #include <QStandardPaths> +#include <QUrl> #include "kauthorized.h" +#include "kconfig_core_log_settings.h" #include "kconfig_p.h" #include "kconfiggroup.h" #include "kconfigini_p.h" -#include "kconfig_core_log_settings.h" class KDesktopFilePrivate : public KConfigPrivate { @@ -71,9 +71,8 @@ QString KDesktopFile::locateLocal(const QString &path) // Relative to config? (e.g. for autostart) const QStringList lstGenericConfigLocation = QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation); // Iterate from the last item since some items may be subfolders of others. - for (QStringList::const_reverse_iterator constIterator = lstGenericConfigLocation.crbegin(); - constIterator != lstGenericConfigLocation.crend(); - ++constIterator) { + for (QStringList::const_reverse_iterator constIterator = lstGenericConfigLocation.crbegin(); constIterator != lstGenericConfigLocation.crend(); + ++constIterator) { const QString &dir = (*constIterator); if (path.startsWith(dir + plus)) { relativePath = path.mid(dir.length() + 1); @@ -102,16 +101,16 @@ bool KDesktopFile::isDesktopFile(const QString &path) bool KDesktopFile::isAuthorizedDesktopFile(const QString &path) { if (path.isEmpty()) { - return false; // Empty paths are not ok. + return false; // Empty paths are not ok. } if (QDir::isRelativePath(path)) { - return true; // Relative paths are ok. + return true; // Relative paths are ok. } const QString realPath = QFileInfo(path).canonicalFilePath(); if (realPath.isEmpty()) { - return false; // File doesn't exist. + return false; // File doesn't exist. } #ifndef Q_OS_WIN @@ -284,9 +283,7 @@ bool KDesktopFile::tryExec() const const QStringList list = d->desktopGroup.readEntry("X-KDE-AuthorizeAction", QStringList()); if (!list.isEmpty()) { - for (QStringList::ConstIterator it = list.begin(); - it != list.end(); - ++it) { + for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { if (!KAuthorized::authorize((*it).trimmed())) { return false; } @@ -314,24 +311,23 @@ bool KDesktopFile::tryExec() const /** * @return the filename as passed to the constructor. */ -//QString KDesktopFile::fileName() const { return backEnd->fileName(); } +// QString KDesktopFile::fileName() const { return backEnd->fileName(); } /** * @return the resource type as passed to the constructor. */ -//QString -//KDesktopFile::resource() const { return backEnd->resource(); } +// QString +// KDesktopFile::resource() const { return backEnd->resource(); } #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 42) -QStringList -KDesktopFile::sortOrder() const +QStringList KDesktopFile::sortOrder() const { Q_D(const KDesktopFile); return d->desktopGroup.readXdgListEntry("SortOrder"); } #endif -//void KDesktopFile::virtual_hook( int id, void* data ) +// void KDesktopFile::virtual_hook( int id, void* data ) //{ KConfig::virtual_hook( id, data ); } QString KDesktopFile::readDocPath() const @@ -344,7 +340,7 @@ KDesktopFile *KDesktopFile::copyTo(const QString &file) const { KDesktopFile *config = new KDesktopFile(QString()); this->KConfig::copyTo(file, config); -// config->setDesktopGroup(); + // config->setDesktopGroup(); return config; } diff --git a/src/core/kdesktopfile.h b/src/core/kdesktopfile.h index 4d817181..c98bf1bb 100644 --- a/src/core/kdesktopfile.h +++ b/src/core/kdesktopfile.h @@ -241,9 +241,8 @@ protected: /** Virtual hook, used to add new "virtual" functions while maintaining binary compatibility. Unused in this class. */ -// virtual void virtual_hook( int id, void* data ); + // virtual void virtual_hook( int id, void* data ); private: - Q_DISABLE_COPY(KDesktopFile) Q_DECLARE_PRIVATE(KDesktopFile) diff --git a/src/core/kemailsettings.cpp b/src/core/kemailsettings.cpp index ed4255b5..cfebe2a8 100644 --- a/src/core/kemailsettings.cpp +++ b/src/core/kemailsettings.cpp @@ -12,7 +12,10 @@ class KEMailSettingsPrivate { public: - KEMailSettingsPrivate() : m_pConfig(nullptr) {} + KEMailSettingsPrivate() + : m_pConfig(nullptr) + { + } ~KEMailSettingsPrivate() { delete m_pConfig; @@ -97,7 +100,7 @@ QString KEMailSettings::getSetting(KEMailSettings::Setting s) const }; return QString(); } -void KEMailSettings::setSetting(KEMailSettings::Setting s, const QString &v) +void KEMailSettings::setSetting(KEMailSettings::Setting s, const QString &v) { KConfigGroup cg(p->m_pConfig, QLatin1String("PROFILE_") + p->m_sCurrentProfile); switch (s) { @@ -191,7 +194,6 @@ void KEMailSettings::setDefault(const QString &s) p->m_pConfig->group("Defaults").writeEntry("Profile", s); p->m_pConfig->sync(); p->m_sDefaultProfile = s; - } void KEMailSettings::setProfile(const QString &s) diff --git a/src/core/kemailsettings.h b/src/core/kemailsettings.h index 30f9942c..eb701f8c 100644 --- a/src/core/kemailsettings.h +++ b/src/core/kemailsettings.h @@ -15,29 +15,29 @@ class KEMailSettingsPrivate; /** - * \class KEMailSettings kemailsettings.h <KEMailSettings> - * - * This is just a small class to facilitate accessing e-mail settings in - * a sane way, and allowing any program to manage multiple e-mail - * profiles effortlessly - * - * The default profile is automatically selected in the constructor. - * - * @author Alex Zepeda zipzippy@sonic.net - **/ + * \class KEMailSettings kemailsettings.h <KEMailSettings> + * + * This is just a small class to facilitate accessing e-mail settings in + * a sane way, and allowing any program to manage multiple e-mail + * profiles effortlessly + * + * The default profile is automatically selected in the constructor. + * + * @author Alex Zepeda zipzippy@sonic.net + **/ class KCONFIGCORE_EXPORT KEMailSettings { Q_DECLARE_TR_FUNCTIONS(KEMailSettings) public: /** - * The list of settings that I thought of when I wrote this - * class. Any extra settings thought of later can be accessed - * easily with getExtendedSetting and setExtendedSetting. - * @see getSetting() - * @see setSetting() - * @see getExtendedSetting() - * @see setExtendedSetting() - **/ + * The list of settings that I thought of when I wrote this + * class. Any extra settings thought of later can be accessed + * easily with getExtendedSetting and setExtendedSetting. + * @see getSetting() + * @see setSetting() + * @see getExtendedSetting() + * @see setExtendedSetting() + **/ enum Setting { ClientProgram, ClientTerminal, @@ -86,8 +86,8 @@ public: }; /** - * The various extensions allowed. - **/ + * The various extensions allowed. + **/ enum Extension { POP3, SMTP, @@ -95,40 +95,40 @@ public: }; /** - * Default constructor, just sets things up and sets the default profile - * as the current profile - **/ + * Default constructor, just sets things up and sets the default profile + * as the current profile + **/ KEMailSettings(); KEMailSettings(const KEMailSettings &) = delete; - KEMailSettings& operator=(const KEMailSettings &) = delete; + KEMailSettings &operator=(const KEMailSettings &) = delete; /** - * Default destructor, nothing to see here. - **/ + * Default destructor, nothing to see here. + **/ ~KEMailSettings(); /** - * List of profiles available. - * @return the list of profiles - **/ + * List of profiles available. + * @return the list of profiles + **/ QStringList profiles() const; #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0) /** - * Returns the name of the current profile. - * @returns what profile we're currently using - * @deprecated Since 5.0 - **/ + * Returns the name of the current profile. + * @returns what profile we're currently using + * @deprecated Since 5.0 + **/ KCONFIGCORE_DEPRECATED_VERSION(5, 0, "API planned to be changed") QString currentProfileName() const; // see https://git.reviewboard.kde.org/r/111910/ #endif /** - * Change the current profile. - * @param s the name of the new profile - **/ + * Change the current profile. + * @param s the name of the new profile + **/ void setProfile(const QString &s); /** @@ -138,25 +138,25 @@ public: QString defaultProfileName() const; /** - * Sets a new default. - * @param def the new default - **/ + * Sets a new default. + * @param def the new default + **/ void setDefault(const QString &def); /** - * Get one of the predefined "basic" settings. - * @param s the setting to get - * @return the value of the setting, or QString() if not - * set - **/ + * Get one of the predefined "basic" settings. + * @param s the setting to get + * @return the value of the setting, or QString() if not + * set + **/ QString getSetting(KEMailSettings::Setting s) const; /** - * Set one of the predefined "basic" settings. - * @param s the setting to set - * @param v the new value of the setting, or QString() to - * unset - **/ + * Set one of the predefined "basic" settings. + * @param s the setting to set + * @param v the new value of the setting, or QString() to + * unset + **/ void setSetting(KEMailSettings::Setting s, const QString &v); private: diff --git a/src/core/ksharedconfig.cpp b/src/core/ksharedconfig.cpp index cc6adeb9..98aa4c5e 100644 --- a/src/core/ksharedconfig.cpp +++ b/src/core/ksharedconfig.cpp @@ -7,9 +7,9 @@ */ #include "ksharedconfig.h" +#include "kconfig_p.h" #include "kconfigbackend_p.h" #include "kconfiggroup.h" -#include "kconfig_p.h" #include <QCoreApplication> #include <QThread> #include <QThreadStorage> @@ -40,8 +40,8 @@ public: }; static QThreadStorage<GlobalSharedConfigList *> s_storage; -template <typename T> -T * perThreadGlobalStatic() +template<typename T> +T *perThreadGlobalStatic() { if (!s_storage.hasLocalData()) { s_storage.setLocalData(new T); @@ -50,7 +50,10 @@ T * perThreadGlobalStatic() } // Q_GLOBAL_STATIC(GlobalSharedConfigList, globalSharedConfigList), but per thread: -static GlobalSharedConfigList *globalSharedConfigList() { return perThreadGlobalStatic<GlobalSharedConfigList>(); } +static GlobalSharedConfigList *globalSharedConfigList() +{ + return perThreadGlobalStatic<GlobalSharedConfigList>(); +} void _k_globalMainConfigSync() { @@ -60,9 +63,7 @@ void _k_globalMainConfigSync() } } -KSharedConfigPtr KSharedConfig::openConfig(const QString &_fileName, - OpenFlags flags, - QStandardPaths::StandardLocation resType) +KSharedConfigPtr KSharedConfig::openConfig(const QString &_fileName, OpenFlags flags, QStandardPaths::StandardLocation resType) { QString fileName(_fileName); GlobalSharedConfigList *list = globalSharedConfigList(); @@ -78,11 +79,9 @@ KSharedConfigPtr KSharedConfig::openConfig(const QString &_fileName, } for (auto *cfg : qAsConst(*list)) { - if (cfg->name() == fileName && - cfg->d_ptr->openFlags == flags && - cfg->locationType() == resType -// cfg->backend()->type() == backend - ) { + if (cfg->name() == fileName && cfg->d_ptr->openFlags == flags && cfg->locationType() == resType + // cfg->backend()->type() == backend + ) { return KSharedConfigPtr(cfg); } } @@ -121,9 +120,7 @@ KSharedConfig::Ptr KSharedConfig::openStateConfig(const QString &_fileName) return openConfig(fileName, SimpleConfig, QStandardPaths::AppDataLocation); } -KSharedConfig::KSharedConfig(const QString &fileName, - OpenFlags flags, - QStandardPaths::StandardLocation resType) +KSharedConfig::KSharedConfig(const QString &fileName, OpenFlags flags, QStandardPaths::StandardLocation resType) : KConfig(fileName, flags, resType) { globalSharedConfigList()->append(this); diff --git a/src/core/ksharedconfig.h b/src/core/ksharedconfig.h index be01401c..e23d17c6 100644 --- a/src/core/ksharedconfig.h +++ b/src/core/ksharedconfig.h @@ -9,8 +9,8 @@ #ifndef KSHAREDCONFIG_H #define KSHAREDCONFIG_H -#include <kconfig.h> #include <QExplicitlySharedDataPointer> +#include <kconfig.h> /** * \class KSharedConfig ksharedconfig.h <KSharedConfig> @@ -28,7 +28,7 @@ * using reparseConfiguration after a manual change notification, just like you have * to do between processes. */ -class KCONFIGCORE_EXPORT KSharedConfig : public KConfig, public QSharedData //krazy:exclude=dpointer (only for refcounting) +class KCONFIGCORE_EXPORT KSharedConfig : public KConfig, public QSharedData // krazy:exclude=dpointer (only for refcounting) { public: typedef QExplicitlySharedDataPointer<KSharedConfig> Ptr; @@ -58,9 +58,8 @@ public: * * @sa KConfig */ - static KSharedConfig::Ptr openConfig(const QString &fileName = QString(), - OpenFlags mode = FullConfig, - QStandardPaths::StandardLocation type = QStandardPaths::GenericConfigLocation); + static KSharedConfig::Ptr + openConfig(const QString &fileName = QString(), OpenFlags mode = FullConfig, QStandardPaths::StandardLocation type = QStandardPaths::GenericConfigLocation); /** * Creates a KSharedConfig object to manipulate a configuration file suitable @@ -91,9 +90,7 @@ private: KConfigGroup groupImpl(const QByteArray &aGroup) override; const KConfigGroup groupImpl(const QByteArray &aGroup) const override; - KSharedConfig(const QString &file, OpenFlags mode, - QStandardPaths::StandardLocation resourceType); - + KSharedConfig(const QString &file, OpenFlags mode, QStandardPaths::StandardLocation resourceType); }; typedef KSharedConfig::Ptr KSharedConfigPtr; |