diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ find_package(KF5I18n ${KF5_DEP_VERSION} REQUIRED) find_package(KF5DocTools ${KF5_DEP_VERSION}) +add_definitions(-DQT_NO_FOREACH) add_definitions(-DTRANSLATION_DOMAIN=\"kwalletd5\") if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ki18n_install(po) diff --git a/src/api/KWallet/kwallet.cpp b/src/api/KWallet/kwallet.cpp --- a/src/api/KWallet/kwallet.cpp +++ b/src/api/KWallet/kwallet.cpp @@ -179,7 +179,8 @@ KSecretsService::SearchCollectionItemsJob *searchItemsJob = secretsCollection->searchItems(attrs); if (searchItemsJob->exec()) { QRegExp re(key, Qt::CaseSensitive, QRegExp::Wildcard); - foreach (KSecretsService::SearchCollectionItemsJob::Item item, searchItemsJob->items()) { + const auto list = searchItemsJob->items(); + for (KSecretsService::SearchCollectionItemsJob::Item item : list) { KSecretsService::ReadItemPropertyJob *readLabelJob = item->label(); if (readLabelJob->exec()) { QString label = readLabelJob->propertyValue().toString(); @@ -718,8 +719,8 @@ KSecretsService::SearchCollectionItemsJob *searchJob = d->secretsCollection->searchItems(attrs); if (searchJob->exec()) { - KSecretsService::ReadCollectionItemsJob::ItemList itemList = searchJob->items(); - foreach (const KSecretsService::ReadCollectionItemsJob::Item &item, itemList) { + const KSecretsService::ReadCollectionItemsJob::ItemList itemList = searchJob->items(); + for (const KSecretsService::ReadCollectionItemsJob::Item &item : itemList) { KSecretsService::ReadItemPropertyJob *readAttrsJob = item->attributes(); if (readAttrsJob->exec()) { KSecretsService::StringStringMap attrs = readAttrsJob->propertyValue().value(); @@ -762,7 +763,8 @@ attrs[KSS_ATTR_ENTRYFOLDER] = d->folder; KSecretsService::SearchCollectionItemsJob *readItemsJob = d->secretsCollection->searchItems(attrs); if (readItemsJob->exec()) { - foreach (KSecretsService::SearchCollectionItemsJob::Item item, readItemsJob->items()) { + const auto list = readItemsJob->items(); + for (KSecretsService::SearchCollectionItemsJob::Item item : list) { KSecretsService::ReadItemPropertyJob *readLabelJob = item->label(); if (readLabelJob->exec()) { result.append(readLabelJob->propertyValue().toString()); @@ -894,10 +896,10 @@ attrs[KSS_ATTR_ENTRYFOLDER] = f; KSecretsService::SearchCollectionItemsJob *searchJob = d->secretsCollection->searchItems(attrs); if (searchJob->exec()) { - KSecretsService::SearchCollectionItemsJob::ItemList itemList = searchJob->items(); + const KSecretsService::SearchCollectionItemsJob::ItemList itemList = searchJob->items(); if (!itemList.isEmpty()) { result = true; - foreach (const KSecretsService::SearchCollectionItemsJob::Item &item, itemList) { + for (const KSecretsService::SearchCollectionItemsJob::Item &item : itemList) { KSecretsService::SecretItemDeleteJob *deleteJob = item->deleteItem(); if (!deleteJob->exec()) { qCDebug(KWALLET_API_LOG) << "Cannot delete item : " << deleteJob->errorString(); diff --git a/src/runtime/kwalletd/ktimeout.cpp b/src/runtime/kwalletd/ktimeout.cpp --- a/src/runtime/kwalletd/ktimeout.cpp +++ b/src/runtime/kwalletd/ktimeout.cpp @@ -34,7 +34,7 @@ void KTimeout::clear() { - foreach (int timerId, _timers) { + for (int timerId : qAsConst(_timers)) { killTimer(timerId); } _timers.clear(); diff --git a/src/runtime/kwalletd/kwalletd.cpp b/src/runtime/kwalletd/kwalletd.cpp --- a/src/runtime/kwalletd/kwalletd.cpp +++ b/src/runtime/kwalletd/kwalletd.cpp @@ -1178,7 +1178,8 @@ dir.setFilter(QDir::Files | QDir::Hidden); - foreach (const QFileInfo& fi, dir.entryInfoList()) { + const auto list = dir.entryInfoList(); + for (const QFileInfo& fi : list) { QString fn = fi.fileName(); if (fn.endsWith(QLatin1String(".kwl"))) { fn.truncate(fn.length() - 4); @@ -1309,7 +1310,8 @@ if ((b = getWallet(appid, handle))) { b->setFolder(folder); QVariantMap rc; - foreach (KWallet::Entry* entry, b->readEntryList(key)) { + const auto lst = b->readEntryList(key); + for (KWallet::Entry* entry : lst) { if (entry->type() == KWallet::Wallet::Map) { rc.insert(entry->key(), entry->map()); } @@ -1344,7 +1346,8 @@ if ((b = getWallet(appid, handle))) { b->setFolder(folder); QVariantMap rc; - foreach (KWallet::Entry* entry, b->readEntryList(key)) { + const auto lst = b->readEntryList(key); + for (KWallet::Entry* entry : lst) { rc.insert(entry->key(), entry->value()); } return rc; @@ -1390,7 +1393,8 @@ if ((b = getWallet(appid, handle))) { b->setFolder(folder); QVariantMap rc; - foreach (KWallet::Entry* entry, b->readEntryList(key)) { + const auto lst = b->readEntryList(key); + for (KWallet::Entry* entry : lst) { if (entry->type() == KWallet::Wallet::Password) { rc.insert(entry->key(), entry->password()); } @@ -1550,20 +1554,20 @@ // all sessions. As an application can basically open wallets // with several appids, we can't stop if we found one. QString service(oldOwner); - QList sessremove(_sessions.findSessions(service)); + const QList sessremove(_sessions.findSessions(service)); KWallet::Backend* b = nullptr; // check all sessions for wallets to close - Q_FOREACH (const KWalletAppHandlePair& s, sessremove) { + for (const KWalletAppHandlePair& s : sessremove) { b = getWallet(s.first, s.second); if (b) { b->deref(); internalClose(b, s.second, false); } } // remove all the sessions in case they aren't gone yet - Q_FOREACH (const KWalletAppHandlePair& s, sessremove) { + for (const KWalletAppHandlePair& s : sessremove) { _sessions.removeSession(s.first, service, s.second); } @@ -1688,7 +1692,8 @@ void KWalletD::emitWalletListDirty() { const QStringList walletsInDisk = wallets(); - foreach (auto i, _wallets.values()) { + const auto lst = _wallets.values(); + for (auto i : lst) { if (!walletsInDisk.contains(i->walletName())) { internalClose(i, _wallets.key(i), true, false); } diff --git a/src/runtime/kwalletd/kwalletsessionstore.cpp b/src/runtime/kwalletd/kwalletsessionstore.cpp --- a/src/runtime/kwalletd/kwalletsessionstore.cpp +++ b/src/runtime/kwalletd/kwalletsessionstore.cpp @@ -34,7 +34,7 @@ KWalletSessionStore::~KWalletSessionStore() { - Q_FOREACH (const QList &l, m_sessions) { + for (const QList &l : qAsConst(m_sessions)) { qDeleteAll(l); } } @@ -70,9 +70,10 @@ QList KWalletSessionStore::findSessions(const QString &service) const { QList rc; - QList sessionKeys(m_sessions.keys()); - Q_FOREACH (const QString &appid, sessionKeys) { - Q_FOREACH (const Session *sess, m_sessions[appid]) { + const QList sessionKeys(m_sessions.keys()); + for (const QString &appid : sessionKeys) { + const auto lst = m_sessions[appid]; + for (const Session *sess : lst) { Q_ASSERT(sess); if (sess->m_service == service) { rc.append(qMakePair(appid, sess->m_handle)); @@ -134,8 +135,8 @@ { QList appremove; int numrem = 0; - QList sessionKeys(m_sessions.keys()); - Q_FOREACH (const QString &appid, sessionKeys) { + const QList sessionKeys(m_sessions.keys()); + for (const QString &appid : sessionKeys) { QList::iterator it; QList::iterator end = m_sessions[appid].end(); for (it = m_sessions[appid].begin(); it != end; ++it) { @@ -154,7 +155,7 @@ } // now remove all applications without sessions - Q_FOREACH (const QString &appid, appremove) { + for (const QString &appid : qAsConst(appremove)) { m_sessions.remove(appid); } @@ -164,7 +165,8 @@ QStringList KWalletSessionStore::getApplications(int handle) const { QStringList rc; - Q_FOREACH (const QString &appid, m_sessions.uniqueKeys()) { + const auto lst = m_sessions.uniqueKeys(); + for (const QString &appid : lst) { if (hasSession(appid, handle)) { rc.append(appid); } diff --git a/src/runtime/kwalletd/migrationagent.cpp b/src/runtime/kwalletd/migrationagent.cpp --- a/src/runtime/kwalletd/migrationagent.cpp +++ b/src/runtime/kwalletd/migrationagent.cpp @@ -196,7 +196,7 @@ this, [this] { return _kde4_daemon->wallets(); }, i18n("Cannot read old wallet list. Aborting.")); - foreach (const QString &wallet, wallets) { + for (const QString &wallet : qAsConst(wallets)) { emit progressMessage(i18n("Migrating wallet: %1", wallet)); emit progressMessage(i18n("* Creating KF5 wallet: %1", wallet)); @@ -223,14 +223,14 @@ this, [this, handle4, appId] { return _kde4_daemon->folderList(handle4, appId); }, i18n("Cannot retrieve folder list. Aborting.")); - foreach (const QString &folder, folders) { + for (const QString &folder : folders) { emit progressMessage(i18n("* Migrating folder %1", folder)); - QStringList entries = invokeAndCheck( + const QStringList entries = invokeAndCheck( this, [this, handle4, folder, appId] { return _kde4_daemon->entryList(handle4, folder, appId); }, i18n("Cannot retrieve folder %1 entries. Aborting.", folder)); - foreach (const QString &key, entries) { + for (const QString &key : entries) { int entryType = invokeAndCheck( this, [this, handle4, folder, key, appId] { return _kde4_daemon->entryType(handle4, folder, key, appId); },