diff options
author | Thomas Braxton <kde.braxton@gmail.com> | 2014-06-11 08:40:44 -0500 |
---|---|---|
committer | Thomas Braxton <kde.braxton@gmail.com> | 2014-06-12 17:14:16 -0500 |
commit | ac6703215ba5e152379173ba503f5ba3bd7e8a85 (patch) | |
tree | d3072f5a03ec66569d4e2f6770fbaa06090cd98f /src | |
parent | 0ed55dfa5d25bdcbef24f1b06be34467b620ae99 (diff) | |
download | kconfig-ac6703215ba5e152379173ba503f5ba3bd7e8a85.tar.gz kconfig-ac6703215ba5e152379173ba503f5ba3bd7e8a85.tar.bz2 |
Simple Cleanups
- use Q_NULLPTR instead of 0 or NULL
- simplify some foreach loops
- use QStringLiteral in a few places
- added a few consts
REVIEW: 118666
Diffstat (limited to 'src')
-rw-r--r-- | src/core/bufferfragment_p.h | 6 | ||||
-rw-r--r-- | src/core/kconfig.cpp | 2 | ||||
-rw-r--r-- | src/core/kconfig.h | 2 | ||||
-rw-r--r-- | src/core/kconfigbackend.cpp | 4 | ||||
-rw-r--r-- | src/core/kconfigdata.h | 2 | ||||
-rw-r--r-- | src/core/kconfiggroup.cpp | 26 | ||||
-rw-r--r-- | src/core/kconfiggroup.h | 6 | ||||
-rw-r--r-- | src/core/kconfigini.cpp | 4 | ||||
-rw-r--r-- | src/core/kcoreconfigskeleton.h | 6 | ||||
-rw-r--r-- | src/core/kemailsettings.cpp | 2 | ||||
-rw-r--r-- | src/core/ksharedconfig.cpp | 12 | ||||
-rw-r--r-- | src/gui/kconfiggroupgui.cpp | 12 | ||||
-rw-r--r-- | src/gui/kconfiggui.cpp | 4 | ||||
-rw-r--r-- | src/gui/kconfigloader.cpp | 24 | ||||
-rw-r--r-- | src/gui/kconfigloader.h | 6 | ||||
-rw-r--r-- | src/gui/kconfigskeleton.h | 4 | ||||
-rw-r--r-- | src/kconf_update/kconf_update.cpp | 59 | ||||
-rw-r--r-- | src/kconf_update/kconfigutils.cpp | 25 |
18 files changed, 99 insertions, 107 deletions
diff --git a/src/core/bufferfragment_p.h b/src/core/bufferfragment_p.h index 8d0931bc..e2154a59 100644 --- a/src/core/bufferfragment_p.h +++ b/src/core/bufferfragment_p.h @@ -40,7 +40,7 @@ class KConfigIniBackend::BufferFragment public: - BufferFragment() : d(0), len(0) + BufferFragment() : d(Q_NULLPTR), len(0) { } @@ -103,7 +103,7 @@ public: bool isEmpty() const { - return (len == 0); + return !len; } BufferFragment left(unsigned int size) const @@ -127,7 +127,7 @@ public: bool isNull() const { - return (d == 0); + return !d; } BufferFragment mid(unsigned int pos, int length = -1) const diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp index ea9746c0..89e92333 100644 --- a/src/core/kconfig.cpp +++ b/src/core/kconfig.cpp @@ -56,7 +56,7 @@ bool KConfigPrivate::mappingsRegistered = false; KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags, QStandardPaths::StandardLocation resourceType) - : openFlags(flags), resourceType(resourceType), mBackend(0), + : openFlags(flags), resourceType(resourceType), mBackend(Q_NULLPTR), bDynamicBackend(true), bDirty(false), bReadDefaults(false), bFileImmutable(false), bForceGlobal(false), bSuppressGlobal(false), configState(KConfigBase::NoAccess) diff --git a/src/core/kconfig.h b/src/core/kconfig.h index d27eebe7..d7d4b7df 100644 --- a/src/core/kconfig.h +++ b/src/core/kconfig.h @@ -210,7 +210,7 @@ public: * * @return @p config if it was set, otherwise a new KConfig object */ - KConfig *copyTo(const QString &file, KConfig *config = 0) const; + KConfig *copyTo(const QString &file, KConfig *config = Q_NULLPTR) const; /** * Ensures that the configuration file contains a certain update. diff --git a/src/core/kconfigbackend.cpp b/src/core/kconfigbackend.cpp index 90655fac..bf2bc9c7 100644 --- a/src/core/kconfigbackend.cpp +++ b/src/core/kconfigbackend.cpp @@ -56,7 +56,7 @@ BackendPtr KConfigBackend::create(const QString &file, const QString &sys) { //qDebug() << "creating a backend for file" << file << "with system" << sys; const QString system = (sys.isEmpty() ? Private::whatSystem(file) : sys); - KConfigBackend *backend = 0; + KConfigBackend *backend = Q_NULLPTR; #if 0 // TODO port to Qt5 plugin loading if (system.compare(QLatin1String("INI"), Qt::CaseInsensitive) != 0) { @@ -65,7 +65,7 @@ BackendPtr KConfigBackend::create(const QString &file, const QString &sys) //qDebug() << "found" << offers.count() << "offers for KConfigBackend plugins with name" << system; foreach (const KService::Ptr &offer, offers) { - backend = offer->createInstance<KConfigBackend>(0); + backend = offer->createInstance<KConfigBackend>(Q_NULLPTR); if (backend) { //qDebug() << "successfully created a backend for" << system; backend->setFilePath(file); diff --git a/src/core/kconfigdata.h b/src/core/kconfigdata.h index e57becb2..fdec85dc 100644 --- a/src/core/kconfigdata.h +++ b/src/core/kconfigdata.h @@ -194,7 +194,7 @@ public: QString getEntry(const QByteArray &group, const QByteArray &key, const QString &defaultValue = QString(), SearchFlags flags = SearchFlags(), - bool *expand = 0) const; + bool *expand = Q_NULLPTR) const; bool hasEntry(const QByteArray &group, const QByteArray &key = QByteArray(), SearchFlags flags = SearchFlags()) const; diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp index 6f609bae..1ad79f8c 100644 --- a/src/core/kconfiggroup.cpp +++ b/src/core/kconfiggroup.cpp @@ -202,7 +202,7 @@ static QList<qreal> asRealList(const QByteArray &string) static QString errString(const char *pKey, const QByteArray &value, const QVariant &aDefault) { - return QString::fromLatin1("\"%1\" - conversion of \"%3\" to %2 failed") + return QStringLiteral("\"%1\" - conversion of \"%3\" to %2 failed") .arg(QString::fromLatin1(pKey)) .arg(QString::fromLatin1(QVariant::typeToName(aDefault.type()))) .arg(QString::fromLatin1(value)); @@ -210,7 +210,7 @@ static QString errString(const char *pKey, const QByteArray &value, const QVaria static QString formatError(int expected, int got) { - return QString::fromLatin1(" (wrong format: expected %1 items, got %2)").arg(expected).arg(got); + return QStringLiteral(" (wrong format: expected %1 items, got %2)").arg(expected).arg(got); } QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &value, const QVariant &aDefault) @@ -400,11 +400,11 @@ static bool cleanHomeDirPath(QString &path, const QString &homeDir) int len = homeDir.length(); // replace by "$HOME" if possible if (len && (path.length() == len || path[len] == QLatin1Char('/'))) { - path.replace(0, len, QString::fromLatin1("$HOME")); + path.replace(0, len, QStringLiteral("$HOME")); return true; - } else { - return false; } + + return false; } static QString translatePath(QString path) // krazy:exclude=passbyvalue @@ -448,19 +448,19 @@ static QString translatePath(QString path) // krazy:exclude=passbyvalue } if (startsWithFile) { - path.prepend(QString::fromLatin1("file://")); + path.prepend(QStringLiteral("file://")); } return path; } -KConfigGroup::KConfigGroup() : d(0) +KConfigGroup::KConfigGroup() : d() { } bool KConfigGroup::isValid() const { - return 0 != d.constData(); + return bool(d); } KConfigGroupGui _kde_internal_KConfigGroupGui; @@ -519,13 +519,13 @@ KConfigGroup &KConfigGroup::operator=(const KConfigGroup &rhs) } KConfigGroup::KConfigGroup(const KConfigGroup &rhs) - : KConfigBase(), d(rhs.d) + : d(rhs.d) { } KConfigGroup::~KConfigGroup() { - d = 0; + d.reset(); } KConfigGroup KConfigGroup::groupImpl(const QByteArray &aGroup) @@ -1094,7 +1094,7 @@ void KConfigGroup::writeXdgListEntry(const char *key, const QStringList &list, W const QStringList::ConstIterator end = list.constEnd(); for (; it != end; ++it) { QString val(*it); - val.replace(QLatin1Char('\\'), QLatin1String("\\\\")).replace(QLatin1Char(';'), QLatin1String("\\;")); + val.replace(QLatin1Char('\\'), QStringLiteral("\\\\")).replace(QLatin1Char(';'), QStringLiteral("\\;")); value += val; value += QLatin1Char(';'); } @@ -1254,7 +1254,7 @@ bool KConfigGroup::isGroupImmutableImpl(const QByteArray &b) const void KConfigGroup::copyTo(KConfigBase *other, WriteConfigFlags pFlags) const { Q_ASSERT_X(isValid(), "KConfigGroup::copyTo", "accessing an invalid group"); - Q_ASSERT(other != 0); + Q_ASSERT(other != Q_NULLPTR); if (KConfigGroup *otherGroup = dynamic_cast<KConfigGroup *>(other)) { config()->d_func()->copyGroup(d->fullName(), otherGroup->d->fullName(), otherGroup, pFlags); @@ -1271,7 +1271,7 @@ void KConfigGroup::reparent(KConfigBase *parent, WriteConfigFlags pFlags) Q_ASSERT_X(isValid(), "KConfigGroup::reparent", "accessing an invalid group"); Q_ASSERT_X(!d->bConst, "KConfigGroup::reparent", "reparenting a read-only group"); Q_ASSERT_X(!d->bImmutable, "KConfigGroup::reparent", "reparenting an immutable group"); - Q_ASSERT(parent != 0); + Q_ASSERT(parent != Q_NULLPTR); KConfigGroup oldGroup(*this); diff --git a/src/core/kconfiggroup.h b/src/core/kconfiggroup.h index 3c4bce84..abb246e3 100644 --- a/src/core/kconfiggroup.h +++ b/src/core/kconfiggroup.h @@ -88,7 +88,7 @@ public: KConfigGroup(const KSharedConfigPtr &master, const char *group); /** - * Creates a read-only copy of a read-only group. + * Creates a copy of a group. */ KConfigGroup(const KConfigGroup &); KConfigGroup &operator=(const KConfigGroup &); @@ -280,9 +280,9 @@ public: QString readEntry(const char *key, const QString &aDefault) const; /** Overload for readEntry(const QString&, const QString&) */ - QString readEntry(const QString &key, const char *aDefault = 0) const; + QString readEntry(const QString &key, const char *aDefault = Q_NULLPTR) const; /** Overload for readEntry(const QString&, const QString&) */ - QString readEntry(const char *key, const char *aDefault = 0) const; + QString readEntry(const char *key, const char *aDefault = Q_NULLPTR) const; /** * @copydoc readEntry(const char*, const QStringList&) const diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp index df834f57..a882ee31 100644 --- a/src/core/kconfigini.cpp +++ b/src/core/kconfigini.cpp @@ -51,7 +51,7 @@ QString KConfigIniBackend::warningProlog(const QFile &file, int line) } KConfigIniBackend::KConfigIniBackend() - : KConfigBackend(), lockFile(NULL) + : KConfigBackend(), lockFile(Q_NULLPTR) { } @@ -617,7 +617,7 @@ void KConfigIniBackend::unlock() { lockFile->unlock(); delete lockFile; - lockFile = NULL; + lockFile = Q_NULLPTR; } bool KConfigIniBackend::isLocked() const diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h index bb9c1cf9..f8313d1e 100644 --- a/src/core/kcoreconfigskeleton.h +++ b/src/core/kcoreconfigskeleton.h @@ -526,7 +526,7 @@ public: public: /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ ItemProperty(const QString &_group, const QString &_key, - QVariant &reference, const QVariant &defaultValue = 0); + QVariant &reference, const QVariant &defaultValue = QVariant()); void readConfig(KConfig *config); void setProperty(const QVariant &p); @@ -1004,7 +1004,7 @@ public: * config file as returned by KSharedConfig::openConfig() is used * @param parent the parent object (see QObject documentation) */ - explicit KCoreConfigSkeleton(const QString &configname = QString(), QObject *parent = 0); + explicit KCoreConfigSkeleton(const QString &configname = QString(), QObject *parent = Q_NULLPTR); /** * Constructor. @@ -1012,7 +1012,7 @@ public: * @param config configuration object to use * @param parent the parent object (see QObject documentation) */ - explicit KCoreConfigSkeleton(KSharedConfig::Ptr config, QObject *parent = 0); + explicit KCoreConfigSkeleton(KSharedConfig::Ptr config, QObject *parent = Q_NULLPTR); /** * Destructor diff --git a/src/core/kemailsettings.cpp b/src/core/kemailsettings.cpp index 230c2aa4..59d5f6e3 100644 --- a/src/core/kemailsettings.cpp +++ b/src/core/kemailsettings.cpp @@ -32,7 +32,7 @@ class KEMailSettingsPrivate { public: - KEMailSettingsPrivate() : m_pConfig(0) {} + KEMailSettingsPrivate() : m_pConfig(Q_NULLPTR) {} ~KEMailSettingsPrivate() { delete m_pConfig; diff --git a/src/core/ksharedconfig.cpp b/src/core/ksharedconfig.cpp index 34947065..f4b4c766 100644 --- a/src/core/ksharedconfig.cpp +++ b/src/core/ksharedconfig.cpp @@ -72,13 +72,13 @@ KSharedConfigPtr KSharedConfig::openConfig(const QString &_fileName, } if (list) { - for (QList<KSharedConfig *>::ConstIterator it = list->constBegin(); it != list->constEnd(); ++it) { - if ((*it)->name() == fileName && - (*it)->d_ptr->openFlags == flags && - (*it)->locationType() == resType -// (*it)->backEnd()->type() == backEnd + foreach (auto cfg, *static_cast<const GlobalSharedConfigList*>(list)) { + if (cfg->name() == fileName && + cfg->d_ptr->openFlags == flags && + cfg->locationType() == resType +// cfg->backend()->type() == backend ) { - return KSharedConfigPtr(*it); + return KSharedConfigPtr(cfg); } } } diff --git a/src/gui/kconfiggroupgui.cpp b/src/gui/kconfiggroupgui.cpp index a14c204c..e2eb950f 100644 --- a/src/gui/kconfiggroupgui.cpp +++ b/src/gui/kconfiggroupgui.cpp @@ -38,11 +38,11 @@ static bool readEntryGui(const QByteArray &data, const char *key, const QVariant &input, QVariant &output) { - const QString errString = QString::fromLatin1("\"%1\" - conversion from \"%3\" to %2 failed") + const QString errString = QStringLiteral("\"%1\" - conversion from \"%3\" to %2 failed") .arg(QLatin1String(key)) .arg(QLatin1String(QVariant::typeToName(input.type()))) .arg(QLatin1String(data.constData())); - const QString formatError = QString::fromLatin1(" (wrong format: expected '%1' items, read '%2')"); + const QString formatError = QStringLiteral(" (wrong format: expected '%1' items, read '%2')"); // set in case of failure output = input; @@ -70,7 +70,7 @@ static bool readEntryGui(const QByteArray &data, const char *key, const QVariant const int count = list.count(); if (count != 3 && count != 4) { - qCritical() << qPrintable(errString) << qPrintable(formatError.arg(QLatin1String("3' or '4")).arg(count)); + qCritical() << qPrintable(errString) << qPrintable(formatError.arg(QStringLiteral("3' or '4")).arg(count)); return true; // return default } @@ -84,12 +84,12 @@ static bool readEntryGui(const QByteArray &data, const char *key, const QVariant return true; // return default } if (j < 0 || j > 255) { - static const char *const components[6] = { + static const char *const components[] = { "red", "green", "blue", "alpha" }; - const QString boundsError = QLatin1String(" (bounds error: %1 component %2)"); + const QString boundsError = QStringLiteral(" (bounds error: %1 component %2)"); qCritical() << qPrintable(errString) - << qPrintable(boundsError.arg(QLatin1String(components[i])).arg(j < 0 ? QLatin1String("< 0") : QLatin1String("> 255"))); + << qPrintable(boundsError.arg(QLatin1String(components[i])).arg(j < 0 ? QStringLiteral("< 0") : QStringLiteral("> 255"))); return true; // return default } } diff --git a/src/gui/kconfiggui.cpp b/src/gui/kconfiggui.cpp index 1eee8ce5..0048c60a 100644 --- a/src/gui/kconfiggui.cpp +++ b/src/gui/kconfiggui.cpp @@ -25,7 +25,7 @@ #include <kconfig.h> -static KConfig *s_sessionConfig = 0; +static KConfig *s_sessionConfig = Q_NULLPTR; KConfig *KConfigGui::sessionConfig() { @@ -37,7 +37,7 @@ KConfig *KConfigGui::sessionConfig() bool KConfigGui::hasSessionConfig() { - return s_sessionConfig != 0; + return s_sessionConfig != Q_NULLPTR; } QString KConfigGui::sessionConfigName() diff --git a/src/gui/kconfigloader.cpp b/src/gui/kconfigloader.cpp index 1dd9e7fc..52ac6d17 100644 --- a/src/gui/kconfigloader.cpp +++ b/src/gui/kconfigloader.cpp @@ -76,7 +76,7 @@ bool ConfigLoaderHandler::startElement(const QString &namespaceURI, const QStrin } else { d->groups.append(group); if (!d->baseGroup.isEmpty()) { - group = d->baseGroup + QStringLiteral("\x1d") + group; + group = d->baseGroup + QLatin1Char('\x1d') + group; } } @@ -194,9 +194,9 @@ void ConfigLoaderHandler::addItem() m_name = m_key; } - m_name.remove(QStringLiteral(" ")); + m_name.remove(QLatin1Char(' ')); - KConfigSkeletonItem *item = 0; + KConfigSkeletonItem *item = Q_NULLPTR; if (m_type == QStringLiteral("bool")) { bool defaultValue = m_default.toLower() == QStringLiteral("true"); @@ -239,7 +239,7 @@ void ConfigLoaderHandler::addItem() } else if (m_type == QStringLiteral("stringlist")) { //FIXME: the split() is naive and will break on lists with ,'s in them item = m_config->addItemStringList(m_name, *d->newStringList(), - m_default.split(QStringLiteral(",")), m_key); + m_default.split(QLatin1Char(',')), m_key); } else if (m_type == QStringLiteral("uint")) { KConfigSkeleton::ItemUInt *uintItem = m_config->addItemUInt(m_name, *d->newUint(), m_default.toUInt(), m_key); @@ -269,7 +269,7 @@ void ConfigLoaderHandler::addItem() } item = doubleItem; } else if (m_type == QStringLiteral("intlist")) { - QStringList tmpList = m_default.split(QStringLiteral(",")); + QStringList tmpList = m_default.split(QLatin1Char(',')); QList<int> defaultList; foreach (const QString &tmp, tmpList) { defaultList.append(tmp.toInt()); @@ -292,7 +292,7 @@ void ConfigLoaderHandler::addItem() */ } else if (m_type == QStringLiteral("point")) { QPoint defaultPoint; - QStringList tmpList = m_default.split(QStringLiteral(",")); + QStringList tmpList = m_default.split(QLatin1Char(',')); if (tmpList.size() >= 2) { defaultPoint.setX(tmpList[0].toInt()); defaultPoint.setY(tmpList[1].toInt()); @@ -300,7 +300,7 @@ void ConfigLoaderHandler::addItem() item = m_config->addItemPoint(m_name, *d->newPoint(), defaultPoint, m_key); } else if (m_type == QStringLiteral("rect")) { QRect defaultRect; - QStringList tmpList = m_default.split(QStringLiteral(",")); + QStringList tmpList = m_default.split(QLatin1Char(',')); if (tmpList.size() >= 4) { defaultRect.setCoords(tmpList[0].toInt(), tmpList[1].toInt(), tmpList[2].toInt(), tmpList[3].toInt()); @@ -308,7 +308,7 @@ void ConfigLoaderHandler::addItem() item = m_config->addItemRect(m_name, *d->newRect(), defaultRect, m_key); } else if (m_type == QStringLiteral("size")) { QSize defaultSize; - QStringList tmpList = m_default.split(QStringLiteral(",")); + QStringList tmpList = m_default.split(QLatin1Char(',')); if (tmpList.size() >= 2) { defaultSize.setWidth(tmpList[0].toInt()); defaultSize.setHeight(tmpList[1].toInt()); @@ -382,7 +382,7 @@ KConfigLoader::KConfigLoader(const KConfigGroup &config, QIODevice *xml, QObject KConfigGroup group = config.parent(); d->baseGroup = config.name(); while (group.isValid() && group.name() != QStringLiteral("<default>")) { - d->baseGroup = group.name() + QStringLiteral("\x1d") + d->baseGroup; + d->baseGroup = group.name() + QLatin1Char('\x1d') + d->baseGroup; group = group.parent(); } d->parse(this, xml); @@ -427,10 +427,8 @@ QStringList KConfigLoader::groupList() const bool KConfigLoader::usrWriteConfig() { if (d->saveDefaults) { - KConfigSkeletonItem::List itemList = items(); - for (int i = 0; i < itemList.size(); i++) { - KConfigGroup cg(config(), itemList.at(i)->group()); - cg.writeEntry(itemList.at(i)->key(), ""); + foreach (const auto& item, items()) { + config()->group(item->group()).writeEntry(item->key(), ""); } } return true; diff --git a/src/gui/kconfigloader.h b/src/gui/kconfigloader.h index 36eb182f..0fb51421 100644 --- a/src/gui/kconfigloader.h +++ b/src/gui/kconfigloader.h @@ -107,7 +107,7 @@ public: * @param xml the xml data; must be valid KConfigXT data * @param parent optional QObject parent **/ - KConfigLoader(const QString &configFile, QIODevice *xml, QObject *parent = 0); + KConfigLoader(const QString &configFile, QIODevice *xml, QObject *parent = Q_NULLPTR); /** * Creates a KConfigSkeleton populated using the definition found in @@ -117,7 +117,7 @@ public: * @param xml the xml data; must be valid KConfigXT data * @param parent optional QObject parent **/ - KConfigLoader(KSharedConfigPtr config, QIODevice *xml, QObject *parent = 0); + KConfigLoader(KSharedConfigPtr config, QIODevice *xml, QObject *parent = Q_NULLPTR); /** * Creates a KConfigSkeleton populated using the definition found in @@ -127,7 +127,7 @@ public: * @param xml the xml data; must be valid KConfigXT data * @param parent optional QObject parent **/ - KConfigLoader(const KConfigGroup &config, QIODevice *xml, QObject *parent = 0); + KConfigLoader(const KConfigGroup &config, QIODevice *xml, QObject *parent = Q_NULLPTR); ~KConfigLoader(); diff --git a/src/gui/kconfigskeleton.h b/src/gui/kconfigskeleton.h index f87eef6e..4cd8d140 100644 --- a/src/gui/kconfigskeleton.h +++ b/src/gui/kconfigskeleton.h @@ -95,14 +95,14 @@ public: * @param configname name of config file. If no name is given, the default * config file as returned by KSharedConfig::openConfig() is used. */ - explicit KConfigSkeleton(const QString &configname = QString(), QObject *parent = 0); + explicit KConfigSkeleton(const QString &configname = QString(), QObject *parent = Q_NULLPTR); /** * Constructor. * * @param config configuration object to use. */ - explicit KConfigSkeleton(KSharedConfig::Ptr config, QObject *parent = 0); + explicit KConfigSkeleton(KSharedConfig::Ptr config, QObject *parent = Q_NULLPTR); /** * Register an item of type QColor. diff --git a/src/kconf_update/kconf_update.cpp b/src/kconf_update/kconf_update.cpp index 829d35e6..255a382e 100644 --- a/src/kconf_update/kconf_update.cpp +++ b/src/kconf_update/kconf_update.cpp @@ -104,12 +104,10 @@ protected: }; KonfUpdate::KonfUpdate(QCommandLineParser *parser) - : m_textStream(0), m_file(0) + : m_oldConfig1(Q_NULLPTR), m_oldConfig2(Q_NULLPTR), m_newConfig(Q_NULLPTR), + m_textStream(Q_NULLPTR), m_file(Q_NULLPTR) { bool updateAll = false; - m_oldConfig1 = 0; - m_oldConfig2 = 0; - m_newConfig = 0; m_config = new KConfig("kconf_updaterc"); KConfigGroup cg(m_config, QString()); @@ -121,7 +119,7 @@ KonfUpdate::KonfUpdate(QCommandLineParser *parser) m_bUseConfigInfo = false; if (parser->isSet("check")) { m_bUseConfigInfo = true; - QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kconf_update/" + parser->value("check")); + const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kconf_update/" + parser->value("check")); if (file.isEmpty()) { qWarning("File '%s' not found.", parser->value("check").toLocal8Bit().data()); log() << "File '" << parser->value("check") << "' passed on command line not found" << endl; @@ -138,10 +136,8 @@ KonfUpdate::KonfUpdate(QCommandLineParser *parser) updateAll = true; } - for (QStringList::ConstIterator it = updateFiles.constBegin(); - it != updateFiles.constEnd(); - ++it) { - updateFile(*it); + foreach (const QString& file, updateFiles) { + updateFile(file); } if (updateAll && !cg.readEntry("updateInfoAdded", false)) { @@ -205,15 +201,17 @@ QStringList KonfUpdate::findUpdateFiles(bool dirtyOnly) QStringList result; const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "kconf_update", QStandardPaths::LocateDirectory); - Q_FOREACH (const QString &dir, dirs) { - const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.upd")); + Q_FOREACH (const QString &d, dirs) { + const QDir dir(d); + + const QStringList fileNames = dir.entryList(QStringList(QStringLiteral("*.upd"))); Q_FOREACH (const QString &fileName, fileNames) { - const QString file = dir + '/' + fileName; + const QString file = dir.filePath(fileName); QFileInfo info(file); KConfigGroup cg(m_config, fileName); - const QDateTime ctime = QDateTime::fromTime_t(cg.readEntry("ctime", 0)); - const QDateTime mtime = QDateTime::fromTime_t(cg.readEntry("mtime", 0)); + const QDateTime ctime = QDateTime::fromTime_t(cg.readEntry("ctime", 0u)); + const QDateTime mtime = QDateTime::fromTime_t(cg.readEntry("mtime", 0u)); if (!dirtyOnly || (ctime != info.created()) || (mtime != info.lastModified())) { result.append(file); @@ -242,7 +240,7 @@ bool KonfUpdate::checkFile(const QString &filename) resetOptions(); QString id; while (!ts.atEnd()) { - QString line = ts.readLine().trimmed(); + const QString line = ts.readLine().trimmed(); lineCount++; if (line.isEmpty() || (line[0] == '#')) { continue; @@ -270,7 +268,7 @@ void KonfUpdate::checkGotFile(const QString &_file, const QString &id) // qDebug("File %s, id %s", file.toLatin1().constData(), id.toLatin1().constData()); KConfig cfg(file, KConfig::SimpleConfig); - KConfigGroup cg(&cfg, "$Version"); + KConfigGroup cg = cfg.group("$Version"); QStringList ids = cg.readEntry("update_info", QStringList()); if (ids.contains(id)) { return; @@ -320,7 +318,7 @@ bool KonfUpdate::updateFile(const QString &filename) while (!ts.atEnd()) { m_line = ts.readLine().trimmed(); m_lineCount++; - if (m_line.isEmpty() || (m_line[0] == '#')) { + if (m_line.isEmpty() || (m_line[0] == QLatin1Char('#'))) { continue; } if (m_line.startsWith(QLatin1String("Id="))) { @@ -349,10 +347,10 @@ bool KonfUpdate::updateFile(const QString &filename) } else if (m_line.startsWith(QLatin1String("RemoveKey="))) { gotRemoveKey(m_line.mid(10)); resetOptions(); - } else if (m_line == "AllKeys") { + } else if (m_line == QLatin1String("AllKeys")) { gotAllKeys(); resetOptions(); - } else if (m_line == "AllGroups") { + } else if (m_line == QLatin1String("AllGroups")) { gotAllGroups(); resetOptions(); } else { @@ -415,7 +413,7 @@ void KonfUpdate::gotFile(const QString &_file) if (!m_oldFile.isEmpty()) { // Close old file. delete m_oldConfig1; - m_oldConfig1 = 0; + m_oldConfig1 = Q_NULLPTR; KConfigGroup cg(m_oldConfig2, "$Version"); QStringList ids = cg.readEntry("update_info", QStringList()); @@ -426,7 +424,7 @@ void KonfUpdate::gotFile(const QString &_file) } cg.sync(); delete m_oldConfig2; - m_oldConfig2 = 0; + m_oldConfig2 = Q_NULLPTR; QString file = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + m_oldFile; QFileInfo info(file); @@ -448,11 +446,11 @@ void KonfUpdate::gotFile(const QString &_file) } m_newConfig->sync(); delete m_newConfig; - m_newConfig = 0; + m_newConfig = Q_NULLPTR; m_newFile.clear(); } - m_newConfig = 0; + m_newConfig = Q_NULLPTR; int i = _file.indexOf(','); if (i == -1) { @@ -499,7 +497,7 @@ void KonfUpdate::gotFile(const QString &_file) m_skipFile = false; if (!m_oldFile.isEmpty()) { // if File= is specified, it doesn't exist, is empty or contains only kconf_update's [$Version] group, skip - if (m_oldConfig1 != NULL + if (m_oldConfig1 != Q_NULLPTR && (m_oldConfig1->groupList().isEmpty() || (m_oldConfig1->groupList().count() == 1 && m_oldConfig1->groupList().first() == "$Version"))) { log() << m_currentFilename << ": File '" << m_oldFile << "' does not exist or empty, skipping" << endl; @@ -619,7 +617,7 @@ void KonfUpdate::copyOrMoveGroup(const QStringList &srcGroupPath, const QStringL // Subgroups Q_FOREACH (const QString &group, cg.groupList()) { - QStringList groupPath = QStringList() << group; + const QStringList groupPath(group); copyOrMoveGroup(srcGroupPath + groupPath, dstGroupPath + groupPath); } } @@ -684,11 +682,11 @@ void KonfUpdate::gotOptions(const QString &_options) for (QStringList::ConstIterator it = options.begin(); it != options.end(); ++it) { - if ((*it).toLower().trimmed() == "copy") { + if ((*it).toLower().trimmed() == QLatin1String("copy")) { m_bCopy = true; } - if ((*it).toLower().trimmed() == "overwrite") { + if ((*it).toLower().trimmed() == QLatin1String("overwrite")) { m_bOverwrite = true; } } @@ -697,9 +695,8 @@ void KonfUpdate::gotOptions(const QString &_options) void KonfUpdate::copyGroup(const KConfigBase *cfg1, const QString &group1, KConfigBase *cfg2, const QString &group2) { - KConfigGroup cg1(cfg1, group1); - KConfigGroup cg2(cfg2, group2); - copyGroup(cg1, cg2); + KConfigGroup cg2 = cfg2->group(group2); + copyGroup(cfg1->group(group1), cg2); } void KonfUpdate::copyGroup(const KConfigGroup &cg1, KConfigGroup &cg2) @@ -741,7 +738,7 @@ void KonfUpdate::gotScript(const QString &_script) return; } - QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kconf_update/" + script); + QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kconf_update/") + script); if (path.isEmpty()) { if (interpreter.isEmpty()) { path = CMAKE_INSTALL_PREFIX "/" LIB_INSTALL_DIR "/kconf_update_bin/" + script; diff --git a/src/kconf_update/kconfigutils.cpp b/src/kconf_update/kconfigutils.cpp index f2663e13..0fec63a6 100644 --- a/src/kconf_update/kconfigutils.cpp +++ b/src/kconf_update/kconfigutils.cpp @@ -33,16 +33,13 @@ bool hasGroup(KConfig *config, const QStringList &lst) return group.exists(); } -KConfigGroup openGroup(KConfig *config, const QStringList &_lst) +KConfigGroup openGroup(KConfig *config, const QStringList &lst) { - if (_lst.isEmpty()) { - return KConfigGroup(config, QString()); - } - - QStringList lst = _lst; + KConfigGroup cg = config->group(""); - KConfigGroup cg; - for (cg = KConfigGroup(config, lst.takeFirst()); !lst.isEmpty(); cg = KConfigGroup(&cg, lst.takeFirst())) {} + foreach (auto i, lst) { + cg = cg.group(i); + } return cg; } @@ -61,14 +58,14 @@ QStringList parseGroupString(const QString &_str, bool *ok, QString *error) if (!str.endsWith(']')) { *ok = false; - *error = QString("Missing closing ']' in %1").arg(_str); + *error = QStringLiteral("Missing closing ']' in %1").arg(_str); return QStringList(); } // trim outer brackets str.chop(1); str.remove(0, 1); - return str.split("]["); + return str.split(QStringLiteral("][")); } QString unescapeString(const QString &src, bool *ok, QString *error) @@ -83,7 +80,7 @@ QString unescapeString(const QString &src, bool *ok, QString *error) ++pos; if (pos == length) { *ok = false; - *error = QString("Unfinished escape sequence in %1").arg(src); + *error = QStringLiteral("Unfinished escape sequence in %1").arg(src); return QString(); } ch = src.at(pos); @@ -104,17 +101,17 @@ QString unescapeString(const QString &src, bool *ok, QString *error) dst += QChar::fromLatin1(value); pos += 2; } else { - *error = QString("Invalid hex escape sequence at column %1 in %2").arg(pos).arg(src); + *error = QStringLiteral("Invalid hex escape sequence at column %1 in %2").arg(pos).arg(src); return QString(); } } else { *ok = false; - *error = QString("Unfinished hex escape sequence at column %1 in %2").arg(pos).arg(src); + *error = QStringLiteral("Unfinished hex escape sequence at column %1 in %2").arg(pos).arg(src); return QString(); } } else { *ok = false; - *error = QString("Invalid escape sequence at column %1 in %2").arg(pos).arg(src); + *error = QStringLiteral("Invalid escape sequence at column %1 in %2").arg(pos).arg(src); return QString(); } } |