Commit c5a838e5 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port some foreach

parent 285a1ef8
Pipeline #49298 failed with stage
in 19 minutes and 21 seconds
......@@ -56,7 +56,7 @@ void EwsModifyItemFlagsJob::start()
{
Item::List items[EwsItemTypeUnknown];
Q_FOREACH (const Item &item, mItems) {
for (const Item &item : qAsConst(mItems)) {
EwsItemType type = EwsItemHandler::mimeToItemType(item.mimeType());
if (type == EwsItemTypeUnknown) {
setErrorText(QStringLiteral("Unknown item type %1 for item %2").arg(item.mimeType(), item.remoteId()));
......
......@@ -73,7 +73,8 @@ void EwsMtaResource::sendItem(const Akonadi::Item &item)
msg->changeEncoding(KMime::Headers::CEbase64);
msg->contentTransferEncoding(true)->setEncoding(KMime::Headers::CEbase64);
} else {
Q_FOREACH (KMime::Content *content, msg->contents()) {
const auto contents = msg->contents();
for (KMime::Content *content : contents) {
content->changeEncoding(KMime::Headers::CEbase64);
content->contentTransferEncoding(true)->setEncoding(KMime::Headers::CEbase64);
}
......
......@@ -244,7 +244,7 @@ void EwsSubscriptionWidgetPrivate::populateFolderTree()
mFolderItemHash.insert(id.id(), item);
}
Q_FOREACH (QStandardItem *item, mFolderItemHash) {
for (QStandardItem *item : qAsConst(mFolderItemHash)) {
if (!item->parent()) {
mFolderTreeModel->appendRow(item);
}
......
......@@ -107,7 +107,7 @@ Akonadi::Collection ImapTestBase::createCollectionChain(const QString &remoteId)
Akonadi::Collection collection = parent;
const QStringList collections = remoteId.split(separator, Qt::SkipEmptyParts);
Q_FOREACH (const QString &colId, collections) {
for (const QString &colId : collections) {
collection = Akonadi::Collection(id);
collection.setRemoteId(separator + colId);
collection.setParentCollection(parent);
......
......@@ -1090,7 +1090,7 @@ void KAlarmDirResource::setCompatibility(bool writeAttr)
mCompatibility = KACalendar::Current;
} else {
mCompatibility = KACalendar::Unknown;
foreach (const EventFile &data, mEvents) {
for (const EventFile &data : qAsConst(mEvents)) {
const KAEvent &event = data.event;
mCompatibility |= event.compatibility();
if ((mCompatibility & AllCompat) == AllCompat) {
......
......@@ -21,7 +21,8 @@ void V2Test::testReadDistlistUID()
Kolab::XMLObject xo;
const Kolab::DistList distlist = xo.readDistlist(buffer.str(), Kolab::KolabV2);
foreach (const Kolab::ContactReference &contact, distlist.members()) {
const auto members = distlist.members();
for (const Kolab::ContactReference &contact : members) {
QVERIFY(!contact.uid().empty());
}
QVERIFY(!Kolab::ErrorHandler::errorOccured());
......
......@@ -135,7 +135,7 @@ void Event::delegate(const std::vector<Attendee> &delegators, const std::vector<
}
std::vector<Kolab::Attendee *> delegatorsRef;
foreach (const Attendee &a, delegators) {
for (const Attendee &a : delegators) {
if (Attendee *attendee = getAttendee(a.contact())) {
delegatorsRef.push_back(attendee);
} else {
......@@ -143,9 +143,9 @@ void Event::delegate(const std::vector<Attendee> &delegators, const std::vector<
}
}
foreach (Attendee *delegatee, delegateesRef) {
for (Attendee *delegatee : qAsConst(delegateesRef)) {
std::vector<Kolab::ContactReference> delegatedFrom = delegatee->delegatedFrom();
foreach (Attendee *delegator, delegatorsRef) {
for (Attendee *delegator : qAsConst(delegatorsRef)) {
// Set the delegator on each delegatee
const ContactReference &delegatorRef = delegator->contact();
if (!contains(delegatorRef, delegatedFrom)) {
......
......@@ -381,7 +381,7 @@ template<typename T> void setCustom(const std::string &value, const std::string
template<typename T> std::string getCustom(const std::string &id, T &object)
{
const std::vector<Kolab::CustomProperty> &properties = object.customProperties();
foreach (const Kolab::CustomProperty &prop, properties) {
for (const Kolab::CustomProperty &prop : properties) {
if (prop.identifier == id) {
return prop.value;
}
......
......@@ -23,7 +23,8 @@ KMime::Content *findContentByType(const KMime::Message::Ptr &data, const QByteAr
return nullptr;
}
Q_ASSERT(!data->contents().isEmpty());
Q_FOREACH (KMime::Content *c, data->contents()) {
const auto contents = data->contents();
for (KMime::Content *c : contents) {
// qCDebug(PIMKOLAB_LOG) << c->contentType()->mimeType() << type;
if (c->contentType()->mimeType() == type) {
return c;
......@@ -35,7 +36,8 @@ KMime::Content *findContentByType(const KMime::Message::Ptr &data, const QByteAr
KMime::Content *findContentByName(const KMime::Message::Ptr &data, const QString &name, QByteArray &type)
{
Q_ASSERT(!data->contents().isEmpty());
Q_FOREACH (KMime::Content *c, data->contents()) {
const auto contents = data->contents();
for (KMime::Content *c : contents) {
// qCDebug(PIMKOLAB_LOG) << "searching: " << c->contentType()->name().toUtf8();
if (c->contentType()->name() == name) {
type = c->contentType()->mimeType();
......@@ -52,7 +54,8 @@ KMime::Content *findContentById(const KMime::Message::Ptr &data, const QByteArra
return nullptr;
}
Q_ASSERT(!data->contents().isEmpty());
Q_FOREACH (KMime::Content *c, data->contents()) {
const auto contents = data->contents();
for (KMime::Content *c : contents) {
// qCDebug(PIMKOLAB_LOG) << "searching: " << c->contentID()->identifier();
if (c->contentID()->identifier() == id) {
type = c->contentType()->mimeType();
......@@ -68,7 +71,8 @@ QList<QByteArray> getContentMimeTypeList(const KMime::Message::Ptr &data)
QList<QByteArray> typeList;
Q_ASSERT(!data->contents().isEmpty());
typeList.reserve(data->contents().count());
Q_FOREACH (KMime::Content *c, data->contents()) {
const auto contents = data->contents();
for (KMime::Content *c : contents) {
typeList.append(c->contentType()->mimeType());
}
return typeList;
......
......@@ -127,7 +127,8 @@ void UpdateMessageJob::onSearchDone(KJob *job)
if (search->results().count() >= 1) {
mOldUids = KIMAP::ImapSet();
foreach (qint64 id, search->results()) {
const auto results = search->results();
for (qint64 id : results) {
mOldUids.add(id);
}
......
......@@ -105,11 +105,11 @@ void ItemModifyTest::testExpectedFail()
QFileInfo fileInfo2(topDir.path(), QStringLiteral("collection2"));
MBox mbox2;
QVERIFY(mbox2.load(fileInfo2.absoluteFilePath()));
MBoxEntry::List entryList2 = mbox2.entries();
const MBoxEntry::List entryList2 = mbox2.entries();
QCOMPARE((int)entryList2.count(), 4);
QSet<qint64> entrySet2;
Q_FOREACH (const MBoxEntry &entry, entryList2) {
for (const MBoxEntry &entry : entryList2) {
entrySet2 << entry.messageOffset();
}
......@@ -385,7 +385,7 @@ void ItemModifyTest::testModifyFlags()
KPIM::Maildir topLevelMd(topDir.path(), true);
KPIM::Maildir md1 = topLevelMd.subFolder(QStringLiteral("collection1"));
QStringList entryList1 = md1.entryList();
const QStringList entryList1 = md1.entryList();
QCOMPARE((int)entryList1.count(), 4);
QFileInfo fileInfo2(topDir.path(), QStringLiteral("collection2"));
......@@ -456,7 +456,7 @@ void ItemModifyTest::testModifyFlags()
// no change in number of entries, one difference
QStringList entryList3 = md1.entryList();
QCOMPARE(entryList3.count(), entryList1.count());
Q_FOREACH (const QString &oldEntry, entryList1) {
for (const QString &oldEntry : entryList1) {
entryList3.removeAll(oldEntry);
}
QCOMPARE(entryList3.count(), 1);
......@@ -550,7 +550,7 @@ void ItemModifyTest::testModifyFlagsAndPayload()
KPIM::Maildir topLevelMd(topDir.path(), true);
KPIM::Maildir md1 = topLevelMd.subFolder(QStringLiteral("collection1"));
QStringList entryList1 = md1.entryList();
const QStringList entryList1 = md1.entryList();
QCOMPARE((int)entryList1.count(), 4);
QFileInfo fileInfo2(topDir.path(), QStringLiteral("collection2"));
......@@ -612,7 +612,7 @@ void ItemModifyTest::testModifyFlagsAndPayload()
// no change in number of entries, one difference
QStringList entryList3 = md1.entryList();
QCOMPARE(entryList3.count(), entryList1.count());
Q_FOREACH (const QString &oldEntry, entryList1) {
for (const QString &oldEntry : entryList1) {
entryList3.removeAll(oldEntry);
}
QCOMPARE(entryList3.count(), 1);
......
......@@ -111,11 +111,11 @@ void ItemMoveTest::testExpectedFail()
QFileInfo fileInfo2(topDir.path(), QStringLiteral("collection2"));
MBox mbox2;
QVERIFY(mbox2.load(fileInfo2.absoluteFilePath()));
MBoxEntry::List entryList2 = mbox2.entries();
const MBoxEntry::List entryList2 = mbox2.entries();
QCOMPARE((int)entryList2.count(), 4);
QSet<qint64> entrySet2;
Q_FOREACH (const MBoxEntry &entry, entryList2) {
for (const MBoxEntry &entry : entryList2) {
entrySet2 << entry.messageOffset();
}
......
......@@ -335,7 +335,7 @@ void StoreCompactTest::testCompact()
QCOMPARE(itemsFromSpy(itemSpy), items);
QHash<QString, Collection> compactedCollections;
Q_FOREACH (const Collection &col, collections) {
for (const Collection &col : qAsConst(collections)) {
compactedCollections.insert(col.remoteId(), col);
}
QCOMPARE(compactedCollections.count(), 2);
......
......@@ -32,7 +32,7 @@ void TestDataTest::testResources()
QStringList() << QStringLiteral("dimap") << QStringLiteral("maildir") << QStringLiteral("maildir-tagged") << QStringLiteral("mbox")
<< QStringLiteral("mbox-tagged") << QStringLiteral("mbox-unpurged"));
Q_FOREACH (const QString testDataName, testDataNames) {
for (const QString &testDataName : testDataNames) {
if (testDataName.startsWith(QLatin1String("mbox"))) {
QVERIFY(TestDataUtil::folderType(testDataName) == TestDataUtil::MBoxFolder);
} else {
......
......@@ -87,8 +87,8 @@ void Pop3Test::initTestCase()
while (!found) {
CollectionFetchJob *job = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive);
QVERIFY(job->exec());
Collection::List collections = job->collections();
foreach (const Collection &col, collections) {
const Collection::List collections = job->collections();
for (const Collection &col : collections) {
if (col.resource() == AgentManager::self()->instance(mMaildirIdentifier).identifier() && col.remoteId() == maildirRootPath) {
mMaildirCollection = col;
found = true;
......@@ -273,13 +273,13 @@ Akonadi::Item::List Pop3Test::checkMailsOnAkonadiServer(const QList<QByteArray>
auto job = new ItemFetchJob(mMaildirCollection);
job->fetchScope().fetchFullPayload();
Q_ASSERT(job->exec());
Item::List items = job->items();
const Item::List items = job->items();
Q_ASSERT(mails.size() == items.size());
QSet<QByteArray> ourMailBodies;
QSet<QByteArray> itemMailBodies;
foreach (const Item &item, items) {
for (const Item &item : items) {
KMime::Message::Ptr itemMail = item.payload<KMime::Message::Ptr>();
QByteArray itemMailBody = itemMail->body();
......
......@@ -282,7 +282,7 @@ void POP3Resource::doStateStep()
// remember which UIDs we have downloaded in the settings)
QList<int> idsToDownload = mIdsToSizeMap.keys();
const QStringList alreadyDownloadedUIDs = mSettings.seenUidList();
foreach (const QString &uidOnServer, mIdsToUidsMap) {
for (const QString &uidOnServer : qAsConst(mIdsToUidsMap)) {
if (alreadyDownloadedUIDs.contains(uidOnServer)) {
const int idOfUIDOnServer = mUidsToIdsMap.value(uidOnServer, -1);
Q_ASSERT(idOfUIDOnServer != -1);
......@@ -296,7 +296,7 @@ void POP3Resource::doStateStep()
// put them into a list here
QList<int> sizesOfMessagesToDownload;
sizesOfMessagesToDownload.reserve(idsToDownload.count());
foreach (int id, idsToDownload) {
for (int id : qAsConst(idsToDownload)) {
sizesOfMessagesToDownload.append(mIdsToSizeMap.value(id));
}
......@@ -637,7 +637,7 @@ int POP3Resource::idOfOldestMessage(const QSet<int> &idList) const
{
int timeOfOldestMessage = time(nullptr) + 999;
int idOfOldestMessage = -1;
foreach (int id, idList) {
for (int id : idList) {
const int idTime = idToTime(id);
if (idTime < timeOfOldestMessage) {
timeOfOldestMessage = idTime;
......@@ -666,7 +666,7 @@ QList<int> POP3Resource::shouldDeleteId(int downloadedId) const
if (mSettings.leaveOnServerDays() > 0) {
const int secondsPerDay = 86400;
time_t timeLimit = time(nullptr) - (secondsPerDay * mSettings.leaveOnServerDays());
foreach (int idToDelete, idsOnServer) {
for (int idToDelete : idsOnServer) {
const int msgTime = idToTime(idToDelete);
if (msgTime >= timeLimit) {
mIdsToSave << idToDelete;
......@@ -841,7 +841,7 @@ void POP3Resource::saveSeenUIDList()
}
}
Q_ASSERT(seenUIDs.size() == timeOfSeenUIDs.size());
foreach (const QString &uid, uidsOfMessagesDownloadedButNotDeleted) {
for (const QString &uid : qAsConst(uidsOfMessagesDownloadedButNotDeleted)) {
if (!seenUIDs.contains(uid)) {
seenUIDs.append(uid);
timeOfSeenUIDs.append(time(nullptr));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment