diff options
| -rw-r--r-- | src/core/kauthorized.cpp | 6 | ||||
| -rw-r--r-- | src/core/kconfig.cpp | 6 | ||||
| -rw-r--r-- | src/core/kconfigdata.cpp | 2 | ||||
| -rw-r--r-- | src/core/kconfiggroup.cpp | 4 | ||||
| -rw-r--r-- | src/core/kconfigini.cpp | 14 | ||||
| -rw-r--r-- | src/core/kcoreconfigskeleton.cpp | 46 | ||||
| -rw-r--r-- | src/core/kcoreconfigskeleton_p.h | 5 | ||||
| -rw-r--r-- | src/core/kdesktopfile.cpp | 32 | ||||
| -rw-r--r-- | src/core/kemailsettings.cpp | 6 | ||||
| -rw-r--r-- | src/kconf_update/kconf_update.cpp | 26 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigHeaderGenerator.cpp | 6 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigSourceGenerator.cpp | 9 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigXmlParser.cpp | 25 | 
13 files changed, 88 insertions, 99 deletions
| diff --git a/src/core/kauthorized.cpp b/src/core/kauthorized.cpp index 46b33ab2..a8784a1c 100644 --- a/src/core/kauthorized.cpp +++ b/src/core/kauthorized.cpp @@ -251,9 +251,9 @@ 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) { -        if (cg.readEntry(*it, true)) { -            result.append(*it); +    for (const auto &id : menuIds) { +        if (cg.readEntry(id, true)) { +            result.append(id);          }      }      return result; diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp index 7f53847f..cc3700e1 100644 --- a/src/core/kconfig.cpp +++ b/src/core/kconfig.cpp @@ -125,7 +125,7 @@ void KConfigPrivate::copyGroup(const QByteArray &source, const QByteArray &desti      // as dirty erroneously      bool dirtied = false; -    for (KEntryMap::ConstIterator entryMapIt(entryMap.constBegin()); entryMapIt != entryMap.constEnd(); ++entryMapIt) { +    for (auto entryMapIt = entryMap.cbegin(); entryMapIt != entryMap.cend(); ++entryMapIt) {          const QByteArray &group = entryMapIt.key().mGroup;          if (!group.startsWith(source)) { // nothing to do @@ -266,7 +266,7 @@ QStringList KConfig::groupList() const      Q_D(const KConfig);      QSet<QString> groups; -    for (KEntryMap::ConstIterator entryMapIt(d->entryMap.constBegin()); entryMapIt != d->entryMap.constEnd(); ++entryMapIt) { +    for (auto entryMapIt = d->entryMap.cbegin(); entryMapIt != d->entryMap.cend(); ++entryMapIt) {          const KEntryKey &key = entryMapIt.key();          const QByteArray group = key.mGroup;          if (key.mKey.isNull() && !group.isEmpty() && group != "<default>" && group != "$Version") { @@ -283,7 +283,7 @@ QStringList KConfigPrivate::groupList(const QByteArray &group) const      QByteArray theGroup = group + '\x1d';      QSet<QString> groups; -    for (KEntryMap::ConstIterator entryMapIt(entryMap.constBegin()); entryMapIt != entryMap.constEnd(); ++entryMapIt) { +    for (auto entryMapIt = entryMap.cbegin(); entryMapIt != entryMap.cend(); ++entryMapIt) {          const KEntryKey &key = entryMapIt.key();          if (key.mKey.isNull() && key.mGroup.startsWith(theGroup)) {              const QString groupname = QString::fromUtf8(key.mGroup.mid(theGroup.length())); diff --git a/src/core/kconfigdata.cpp b/src/core/kconfigdata.cpp index 8ceea7ee..ada7125f 100644 --- a/src/core/kconfigdata.cpp +++ b/src/core/kconfigdata.cpp @@ -312,7 +312,7 @@ bool KEntryMap::revertEntry(const QByteArray &group, const QByteArray &key, KEnt          KEntryKey defaultKey(entry.key());          defaultKey.bDefault = true;          // qDebug() << "looking up default entry with key=" << defaultKey; -        const ConstIterator defaultEntry = constFind(defaultKey); +        const auto defaultEntry = constFind(defaultKey);          if (defaultEntry != constEnd()) {              Q_ASSERT(defaultEntry.key().bDefault);              // qDebug() << "found, update entry"; diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp index 8fcfafe7..c065be81 100644 --- a/src/core/kconfiggroup.cpp +++ b/src/core/kconfiggroup.cpp @@ -126,8 +126,8 @@ QByteArray KConfigGroupPrivate::serializeList(const QList<QByteArray> &list)      QByteArray value;      if (!list.isEmpty()) { -        QList<QByteArray>::ConstIterator it = list.constBegin(); -        const QList<QByteArray>::ConstIterator end = list.constEnd(); +        auto it = list.cbegin(); +        const auto end = list.cend();          value = QByteArray(*it).replace('\\', QByteArrayLiteral("\\\\")).replace(',', QByteArrayLiteral("\\,")); diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp index dd24a959..8c81db8f 100644 --- a/src/core/kconfigini.cpp +++ b/src/core/kconfigini.cpp @@ -298,8 +298,8 @@ void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file,  {      QByteArray currentGroup;      bool groupIsImmutable = false; -    const KEntryMapConstIterator end = map.constEnd(); -    for (KEntryMapConstIterator it = map.constBegin(); it != end; ++it) { +    const auto end = map.cend(); +    for (auto it = map.cbegin(); it != end; ++it) {          const KEntryKey &key = it.key();          // Either process the default group or all others @@ -746,13 +746,13 @@ public:  QByteArray KConfigIniBackend::stringToPrintable(const QByteArray &aString, StringType type)  { -    if (aString.isEmpty()) { +    const int len = aString.size(); +    if (len == 0) {          return aString;      } -    const int l = aString.length(); -    QByteArray result; // Guesstimated that it's good to avoid data() initialization for a length of l*4 -    result.resize(l * 4); // Maximum 4x as long as source string due to \x<ab> escape sequences +    QByteArray result; // Guesstimated that it's good to avoid data() initialization for a length of len*4 +    result.resize(len * 4); // Maximum 4x as long as source string due to \x<ab> escape sequences      const char *s = aString.constData();      int i = 0;      char *data = result.data(); @@ -766,7 +766,7 @@ QByteArray KConfigIniBackend::stringToPrintable(const QByteArray &aString, Strin      }      Utf8Char utf8; -    for (; i < l; ++i /*, r++*/) { +    for (; i < len; ++i) {          switch (s[i]) {          default:              if (utf8.addByte(s[i])) { diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp index 669e0ce5..ab968023 100644 --- a/src/core/kcoreconfigskeleton.cpp +++ b/src/core/kcoreconfigskeleton.cpp @@ -11,6 +11,8 @@  #include <QUrl> +#include <algorithm> +  static QString obscuredString(const QString &str)  {      QString result; @@ -606,7 +608,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 (auto it = mChoices.cbegin(); it != mChoices.cend(); ++it, ++i) {              QString choiceName = (*it).name;              if (valueForChoice(choiceName).toLower() == tmp) {                  mReference = i; @@ -1180,19 +1182,18 @@ bool KCoreConfigSkeleton::useDefaults(bool b)      }      d->mUseDefaults = b; -    KConfigSkeletonItem::List::ConstIterator it; -    for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { -        (*it)->swapDefault(); +    for (auto *skelItem : qAsConst(d->mItems)) { +        skelItem->swapDefault();      } +      usrUseDefaults(b);      return !d->mUseDefaults;  }  void KCoreConfigSkeleton::setDefaults()  { -    KConfigSkeletonItem::List::ConstIterator it; -    for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { -        (*it)->setDefault(); +    for (auto *skelItem : qAsConst(d->mItems)) { +        skelItem->setDefault();      }      usrSetDefaults();  } @@ -1205,42 +1206,33 @@ void KCoreConfigSkeleton::load()  void KCoreConfigSkeleton::read()  { -    KConfigSkeletonItem::List::ConstIterator it; -    for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { -        (*it)->readConfig(d->mConfig.data()); +    for (auto *skelItem : qAsConst(d->mItems)) { +        skelItem->readConfig(d->mConfig.data());      }      usrRead();  }  bool KCoreConfigSkeleton::isDefaults() const  { -    KConfigSkeletonItem::List::ConstIterator it; -    for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { -        if (!(*it)->isDefault()) { -            return false; -        } -    } -    return true; +    return std::all_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) { +        return skelItem->isDefault(); +    });  }  bool KCoreConfigSkeleton::isSaveNeeded() const  { -    KConfigSkeletonItem::List::ConstIterator it; -    for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { -        if ((*it)->isSaveNeeded()) { -            return true; -        } -    } -    return false; +    return std::any_of(d->mItems.cbegin(), d->mItems.cend(), [](KConfigSkeletonItem *skelItem) { +        return skelItem->isSaveNeeded(); +    });  }  bool KCoreConfigSkeleton::save()  {      // qDebug(); -    KConfigSkeletonItem::List::ConstIterator it; -    for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { -        (*it)->writeConfig(d->mConfig.data()); +    for (auto *skelItem : qAsConst(d->mItems)) { +        skelItem->writeConfig(d->mConfig.data());      } +      if (!usrSave()) {          return false;      } diff --git a/src/core/kcoreconfigskeleton_p.h b/src/core/kcoreconfigskeleton_p.h index d854cc43..a7417430 100644 --- a/src/core/kcoreconfigskeleton_p.h +++ b/src/core/kcoreconfigskeleton_p.h @@ -21,10 +21,7 @@ public:      }      ~KCoreConfigSkeletonPrivate()      { -        KConfigSkeletonItem::List::ConstIterator it; -        for (it = mItems.constBegin(); it != mItems.constEnd(); ++it) { -            delete *it; -        } +        qDeleteAll(mItems);      }      QString mCurrentGroup; diff --git a/src/core/kdesktopfile.cpp b/src/core/kdesktopfile.cpp index d5029ffe..cae8b98d 100644 --- a/src/core/kdesktopfile.cpp +++ b/src/core/kdesktopfile.cpp @@ -8,20 +8,22 @@  #include "kdesktopfile.h" -#ifndef Q_OS_WIN -#include <unistd.h> -#endif +#include "kauthorized.h" +#include "kconfig_core_log_settings.h" +#include "kconfig_p.h" +#include "kconfiggroup.h" +#include "kconfigini_p.h"  #include <QDir>  #include <QFileInfo>  #include <QStandardPaths>  #include <QUrl> -#include "kauthorized.h" -#include "kconfig_core_log_settings.h" -#include "kconfig_p.h" -#include "kconfiggroup.h" -#include "kconfigini_p.h" +#ifndef Q_OS_WIN +#include <unistd.h> +#endif + +#include <algorithm>  class KDesktopFilePrivate : public KConfigPrivate  { @@ -281,17 +283,15 @@ 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) { -            if (!KAuthorized::authorize((*it).trimmed())) { -                return false; -            } -        } +    const auto isNotAuthorized = std::any_of(list.cbegin(), list.cend(), [](const QString &action) { +        return !KAuthorized::authorize(action.trimmed()); +    }); +    if (isNotAuthorized) { +        return false;      }      // See also KService::username() -    bool su = d->desktopGroup.readEntry("X-KDE-SubstituteUID", false); +    const bool su = d->desktopGroup.readEntry("X-KDE-SubstituteUID", false);      if (su) {          QString user = d->desktopGroup.readEntry("X-KDE-Username", QString());          if (user.isEmpty()) { diff --git a/src/core/kemailsettings.cpp b/src/core/kemailsettings.cpp index cfebe2a8..9074a0a2 100644 --- a/src/core/kemailsettings.cpp +++ b/src/core/kemailsettings.cpp @@ -227,9 +227,9 @@ KEMailSettings::KEMailSettings()      p->m_pConfig = new KConfig(QStringLiteral("emaildefaults"));      const QStringList groups = p->m_pConfig->groupList(); -    for (QStringList::ConstIterator it = groups.begin(); it != groups.end(); ++it) { -        if ((*it).startsWith(QLatin1String("PROFILE_"))) { -            p->profiles += (*it).mid(8, (*it).length()); +    for (const auto &grp : groups) { +        if (grp.startsWith(QLatin1String("PROFILE_"))) { +            p->profiles += grp.mid(8 /* length of "PROFILE_" */);          }      } diff --git a/src/kconf_update/kconf_update.cpp b/src/kconf_update/kconf_update.cpp index a08ecaae..d4f7e15e 100644 --- a/src/kconf_update/kconf_update.cpp +++ b/src/kconf_update/kconf_update.cpp @@ -169,8 +169,8 @@ KonfUpdate::KonfUpdate(QCommandLineParser *parser)          cg.writeEntry("updateInfoAdded", true);          updateFiles = findUpdateFiles(false); -        for (QStringList::ConstIterator it = updateFiles.constBegin(); it != updateFiles.constEnd(); ++it) { -            checkFile(*it); +        for (const auto &file : qAsConst(updateFiles)) { +            checkFile(file);          }          updateFiles.clear();      } @@ -689,8 +689,8 @@ void KonfUpdate::gotAllGroups()      }      const QStringList allGroups = m_oldConfig1->groupList(); -    for (QStringList::ConstIterator it = allGroups.begin(); it != allGroups.end(); ++it) { -        m_oldGroup = QStringList() << *it; +    for (const auto &grp : allGroups) { +        m_oldGroup = QStringList{grp};          m_newGroup = m_oldGroup;          gotAllKeys();      } @@ -699,12 +699,12 @@ void KonfUpdate::gotAllGroups()  void KonfUpdate::gotOptions(const QString &_options)  {      const QStringList options = _options.split(QLatin1Char{','}); -    for (QStringList::ConstIterator it = options.begin(); it != options.end(); ++it) { -        if ((*it).toLower().trimmed() == QLatin1String("copy")) { -            m_bCopy = true; -        } +    for (const auto &opt : options) { +        const auto normalizedOpt = opt.toLower().trimmed(); -        if ((*it).toLower().trimmed() == QLatin1String("overwrite")) { +        if (normalizedOpt == QLatin1String("copy")) { +            m_bCopy = true; +        } else if (normalizedOpt == QLatin1String("overwrite")) {              m_bOverwrite = true;          }      } @@ -719,8 +719,8 @@ void KonfUpdate::copyGroup(const KConfigBase *cfg1, const QString &group1, KConf  void KonfUpdate::copyGroup(const KConfigGroup &cg1, KConfigGroup &cg2)  {      // Copy keys -    QMap<QString, QString> list = cg1.entryMap(); -    for (QMap<QString, QString>::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) { +    const auto map = cg1.entryMap(); +    for (auto it = map.cbegin(); it != map.cend(); ++it) {          if (m_bOverwrite || !cg2.hasKey(it.key())) {              cg2.writeEntry(it.key(), it.value());          } @@ -819,8 +819,8 @@ void KonfUpdate::gotScript(const QString &_script)          if (m_oldGroup.isEmpty()) {              // Write all entries to tmpFile;              const QStringList grpList = m_oldConfig1->groupList(); -            for (QStringList::ConstIterator it = grpList.begin(); it != grpList.end(); ++it) { -                copyGroup(m_oldConfig1, *it, &cfg, *it); +            for (const auto &grp : grpList) { +                copyGroup(m_oldConfig1, grp, &cfg, grp);              }          } else {              KConfigGroup cg1 = KConfigUtils::openGroup(m_oldConfig1, m_oldGroup); diff --git a/src/kconfig_compiler/KConfigHeaderGenerator.cpp b/src/kconfig_compiler/KConfigHeaderGenerator.cpp index 21eb51a5..08d383d8 100644 --- a/src/kconfig_compiler/KConfigHeaderGenerator.cpp +++ b/src/kconfig_compiler/KConfigHeaderGenerator.cpp @@ -254,8 +254,10 @@ void KConfigHeaderGenerator::createSignals()              stream() << whitespace() << "*/\n";          }          stream() << whitespace() << "void " << signal.name << "("; -        QList<Param>::ConstIterator it, itEnd = signal.arguments.constEnd(); -        for (it = signal.arguments.constBegin(); it != itEnd;) { + +        auto it = signal.arguments.cbegin(); +        const auto itEnd = signal.arguments.cend(); +        while (it != itEnd) {              Param argument = *it;              QString type = param(argument.type);              if (cfg().useEnumTypes && argument.type == QLatin1String("Enum")) { diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp index ce6378cd..d308ffcd 100644 --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -214,8 +214,8 @@ void KConfigSourceGenerator::createConstructorParameterList()          stream() << (parseResult.parameters.isEmpty() ? "" : ",");      } -    for (QList<Param>::ConstIterator it = parseResult.parameters.constBegin(); it != parseResult.parameters.constEnd(); ++it) { -        if (it != parseResult.parameters.constBegin()) { +    for (auto it = parseResult.parameters.cbegin(); it != parseResult.parameters.cend(); ++it) { +        if (it != parseResult.parameters.cbegin()) {              stream() << ",";          }          stream() << " " << param((*it).type) << " " << (*it).name; @@ -634,8 +634,9 @@ void KConfigSourceGenerator::createNonModifyingSignalsHelper()          stream() << "  if ( " << varPath(QStringLiteral("settingsChanged"), cfg()) << " & " << signalEnumName(signal.name) << " )\n";          stream() << "    Q_EMIT " << signal.name << "("; -        QList<Param>::ConstIterator it, itEnd = signal.arguments.constEnd(); -        for (it = signal.arguments.constBegin(); it != itEnd;) { +        auto it = signal.arguments.cbegin(); +        const auto itEnd = signal.arguments.cend(); +        while (it != itEnd) {              Param argument = *it;              bool cast = false;              if (cfg().useEnumTypes && argument.type == QLatin1String("Enum")) { diff --git a/src/kconfig_compiler/KConfigXmlParser.cpp b/src/kconfig_compiler/KConfigXmlParser.cpp index 97d61342..7dc1d9f0 100644 --- a/src/kconfig_compiler/KConfigXmlParser.cpp +++ b/src/kconfig_compiler/KConfigXmlParser.cpp @@ -27,7 +27,7 @@  static void preProcessDefault(QString &defaultValue,                                const QString &name,                                const QString &type, -                              const CfgEntry::Choices &choices, +                              const CfgEntry::Choices &cfgChoices,                                QString &code,                                const KConfigParameters &cfg)  { @@ -51,13 +51,12 @@ static void preProcessDefault(QString &defaultValue,              cpp << "  QStringList default" << name << ";\n";          }          const QStringList defaults = defaultValue.split(QLatin1Char(',')); -        QStringList::ConstIterator it; -        for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { +        for (const auto &val : defaults) {              cpp << "  default" << name << ".append( ";              if (type == QLatin1String("UrlList")) {                  cpp << "QUrl::fromUserInput(";              } -            cpp << "QString::fromUtf8( \"" << *it << "\" ) "; +            cpp << "QString::fromUtf8( \"" << val << "\" ) ";              if (type == QLatin1String("UrlList")) {                  cpp << ") ";              } @@ -66,7 +65,7 @@ static void preProcessDefault(QString &defaultValue,          defaultValue = QLatin1String("default") + name;      } else if (type == QLatin1String("Color") && !defaultValue.isEmpty()) { -        const QRegularExpression colorRe(QRegularExpression::anchoredPattern(QStringLiteral("\\d+,\\s*\\d+,\\s*\\d+(,\\s*\\d+)?"))); +        static const QRegularExpression colorRe(QRegularExpression::anchoredPattern(QStringLiteral("\\d+,\\s*\\d+,\\s*\\d+(,\\s*\\d+)?")));          if (colorRe.match(defaultValue).hasMatch()) {              defaultValue = QLatin1String("QColor( ") + defaultValue + QLatin1String(" )"); @@ -75,13 +74,12 @@ static void preProcessDefault(QString &defaultValue,          }      } else if (type == QLatin1String("Enum")) { -        QList<CfgEntry::Choice>::ConstIterator it; -        for (it = choices.choices.constBegin(); it != choices.choices.constEnd(); ++it) { -            if ((*it).name == defaultValue) { -                if (cfg.globalEnums && choices.name().isEmpty()) { -                    defaultValue.prepend(choices.prefix); +        for (const auto &choice : cfgChoices.choices) { +            if (choice.name == defaultValue) { +                if (cfg.globalEnums && cfgChoices.name().isEmpty()) { +                    defaultValue.prepend(cfgChoices.prefix);                  } else { -                    defaultValue.prepend(enumTypeQualifier(name, choices) + choices.prefix); +                    defaultValue.prepend(enumTypeQualifier(name, cfgChoices) + cfgChoices.prefix);                  }                  break;              } @@ -96,9 +94,8 @@ static void preProcessDefault(QString &defaultValue,          cpp << "  QList<int> default" << name << ";\n";          if (!defaultValue.isEmpty()) {              const QStringList defaults = defaultValue.split(QLatin1Char(',')); -            QStringList::ConstIterator it; -            for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { -                cpp << "  default" << name << ".append( " << *it << " );\n"; +            for (const auto &defaultVal : defaults) { +                cpp << "  default" << name << ".append( " << defaultVal << " );\n";              }          }          defaultValue = QLatin1String("default") + name; | 
