diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,11 @@ set(SUPPORTED_ARK_MIMETYPES "") add_definitions(-DTRANSLATION_DOMAIN="ark") +# Until kf5 5.56 kconfig had some header which used Q_FOREACH +# Q_FOREACH will be deprecated/removed in qt6. With QT_NO_FOREACH we prepare the migration to qt6. +if (${KF5Config_VERSION} STRGREATER "5.56.0") + add_definitions(-DQT_NO_FOREACH) +endif() add_subdirectory(plugins) add_subdirectory(kerfuffle) diff --git a/app/batchextract.cpp b/app/batchextract.cpp --- a/app/batchextract.cpp +++ b/app/batchextract.cpp @@ -112,7 +112,7 @@ return; } - foreach (const auto& url, m_inputs) { + for (const auto& url : qAsConst(m_inputs)) { addExtraction(url); } diff --git a/app/extractHereDndPlugin.cpp b/app/extractHereDndPlugin.cpp --- a/app/extractHereDndPlugin.cpp +++ b/app/extractHereDndPlugin.cpp @@ -42,7 +42,7 @@ batchJob->setAutoSubfolder(true); batchJob->setDestinationFolder(m_dest.toDisplayString(QUrl::PreferLocalFile)); batchJob->setPreservePaths(true); - foreach(const QUrl& url, m_urls) { + for (const QUrl& url : qAsConst(m_urls)) { batchJob->addInput(url); } diff --git a/app/extractfileitemaction.cpp b/app/extractfileitemaction.cpp --- a/app/extractfileitemaction.cpp +++ b/app/extractfileitemaction.cpp @@ -48,7 +48,8 @@ bool readOnlyParentDir = false; QList supportedUrls; // Filter URLs by supported mimetypes. - foreach (const QUrl &url, fileItemInfos.urlList()) { + const auto urlList = fileItemInfos.urlList(); + for (const QUrl &url : urlList) { const QMimeType mimeType = determineMimeType(url.path()); if (m_pluginManager->preferredPluginsFor(mimeType).isEmpty()) { continue; diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -246,7 +246,8 @@ void MainWindow::closeEvent(QCloseEvent *event) { // Preview windows don't have a parent, so we need to manually close them. - foreach (QWidget *widget, qApp->topLevelWidgets()) { + const auto topLevelWidgets = qApp->topLevelWidgets(); + for (QWidget *widget : topLevelWidgets) { if (widget->isVisible()) { widget->close(); } @@ -271,7 +272,8 @@ auto dialog = new Kerfuffle::SettingsDialog(this, QStringLiteral("settings"), iface->config()); - foreach (Kerfuffle::SettingsPage *page, iface->settingsPages(this)) { + const auto pages = iface->settingsPages(this); + for (Kerfuffle::SettingsPage *page : pages) { dialog->addPage(page, page->name(), page->iconName()); connect(dialog, &KConfigDialog::settingsChanged, page, &Kerfuffle::SettingsPage::slotSettingsChanged); connect(dialog, &Kerfuffle::SettingsDialog::defaultsButtonClicked, page, &Kerfuffle::SettingsPage::slotDefaultsButtonClicked); diff --git a/autotests/kerfuffle/addtest.cpp b/autotests/kerfuffle/addtest.cpp --- a/autotests/kerfuffle/addtest.cpp +++ b/autotests/kerfuffle/addtest.cpp @@ -158,7 +158,7 @@ QStringList oldPaths = getEntryPaths(archive); // Check that the expected paths (after the AddJob) are not in the archive. - foreach (const auto &expectedPath, expectedNewPaths) { + for (const auto &expectedPath : qAsConst(expectedNewPaths)) { QVERIFY(!oldPaths.contains(expectedPath)); } @@ -171,7 +171,7 @@ QStringList newPaths = getEntryPaths(archive); // Check that the expected paths are now in the archive. - foreach (const auto &path, expectedNewPaths) { + for (const auto &path : qAsConst(expectedNewPaths)) { QVERIFY(newPaths.contains(path)); } diff --git a/autotests/kerfuffle/addtoarchivetest.cpp b/autotests/kerfuffle/addtoarchivetest.cpp --- a/autotests/kerfuffle/addtoarchivetest.cpp +++ b/autotests/kerfuffle/addtoarchivetest.cpp @@ -221,7 +221,7 @@ } QFETCH(QStringList, inputFiles); - foreach (const QString &file, inputFiles) { + for (const QString &file : qAsConst(inputFiles)) { addToArchiveJob->addInput(QUrl::fromUserInput(file)); } diff --git a/autotests/kerfuffle/copytest.cpp b/autotests/kerfuffle/copytest.cpp --- a/autotests/kerfuffle/copytest.cpp +++ b/autotests/kerfuffle/copytest.cpp @@ -267,12 +267,12 @@ QStringList oldPaths = getEntryPaths(archive); // Check that the entries to be copied are in the archive. - foreach (const auto entry, targetEntries) { + for (const auto entry : qAsConst(targetEntries)) { QVERIFY(oldPaths.contains(entry->fullPath())); } // Check that the expected paths (after the CopyJob) are not in the archive. - foreach (const auto &expectedPath, expectedNewPaths) { + for (const auto &expectedPath : qAsConst(expectedNewPaths)) { QVERIFY(!oldPaths.contains(expectedPath)); } @@ -285,12 +285,12 @@ QStringList newPaths = getEntryPaths(archive); // Check that the expected paths are now in the archive. - foreach (const auto &path, expectedNewPaths) { + for (const auto &path : qAsConst(expectedNewPaths)) { QVERIFY(newPaths.contains(path)); } // Check also that the target paths are still in the archive. - foreach (const auto entry, targetEntries) { + for (const auto entry : qAsConst(targetEntries)) { QVERIFY(newPaths.contains(entry->fullPath())); } diff --git a/autotests/kerfuffle/deletetest.cpp b/autotests/kerfuffle/deletetest.cpp --- a/autotests/kerfuffle/deletetest.cpp +++ b/autotests/kerfuffle/deletetest.cpp @@ -56,12 +56,13 @@ QTest::addColumn("expectedRemainingEntriesCount"); // Repeat the same test case for each format and for each plugin supporting the format. - foreach (const QString &format, TestHelper::testFormats()) { + const QStringList formats = TestHelper::testFormats(); + for (const QString &format : formats) { const QString filename = QStringLiteral("test.%1").arg(format); const auto mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension); const auto plugins = m_pluginManager.preferredWritePluginsFor(mime); - foreach (const auto plugin, plugins) { + for (const auto plugin : plugins) { QTest::newRow(qPrintable(QStringLiteral("delete a single file (%1, %2)").arg(format, plugin->metaData().pluginId()))) << filename << plugin diff --git a/autotests/kerfuffle/extracttest.cpp b/autotests/kerfuffle/extracttest.cpp --- a/autotests/kerfuffle/extracttest.cpp +++ b/autotests/kerfuffle/extracttest.cpp @@ -482,11 +482,12 @@ QTest::addColumn("expectedPermissions"); // Repeat the same test case for each format and for each plugin supporting the format. - foreach (const QString &format, TestHelper::testFormats()) { + const QStringList formats = TestHelper::testFormats(); + for (const QString &format : formats) { const QString filename = QFINDTESTDATA(QStringLiteral("data/test_permissions.%1").arg(format)); const auto mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension); const auto plugins = m_pluginManager.preferredWritePluginsFor(mime); - foreach (const auto plugin, plugins) { + for (const auto plugin : plugins) { QTest::newRow(QStringLiteral("test preserve 0755 permissions (%1, %2)").arg(format, plugin->metaData().pluginId()).toUtf8().constData()) << filename << plugin diff --git a/autotests/kerfuffle/jobstest.cpp b/autotests/kerfuffle/jobstest.cpp --- a/autotests/kerfuffle/jobstest.cpp +++ b/autotests/kerfuffle/jobstest.cpp @@ -318,7 +318,7 @@ QStringList fullPathsToDelete = iface->entryFullPaths(entriesToDelete); QVector expectedRemainingEntries; - Q_FOREACH (Archive::Entry *entry, entries) { + for (Archive::Entry *entry : qAsConst(entries)) { if (!fullPathsToDelete.contains(entry->fullPath())) { expectedRemainingEntries.append(entry); } @@ -412,7 +412,7 @@ QFETCH(QVector, originalEntries); QStringList originalFullPaths = QStringList(); - Q_FOREACH (const Archive::Entry *entry, originalEntries) { + for (const Archive::Entry *entry : qAsConst(originalEntries)) { originalFullPaths.append(entry->fullPath()); } auto currentEntries = listEntries(iface); @@ -426,7 +426,7 @@ QStringList expectedAddedFullPaths = QStringList(); const QString destinationPath = destinationEntry->fullPath(); int expectedEntriesCount = originalEntries.size(); - Q_FOREACH (const Archive::Entry *entry, entriesToAdd) { + for (const Archive::Entry *entry : qAsConst(entriesToAdd)) { const QString fullPath = destinationPath + entry->fullPath(); if (!originalFullPaths.contains(fullPath)) { expectedEntriesCount++; @@ -438,11 +438,11 @@ QCOMPARE(currentEntries.size(), expectedEntriesCount); QStringList currentFullPaths = QStringList(); - Q_FOREACH (const Archive::Entry* entry, currentEntries) { + for (const Archive::Entry* entry : qAsConst(currentEntries)) { currentFullPaths << entry->fullPath(); } - Q_FOREACH (const QString &fullPath, expectedAddedFullPaths) { + for (const QString &fullPath : qAsConst(expectedAddedFullPaths)) { QVERIFY(currentFullPaths.contains(fullPath)); } diff --git a/autotests/kerfuffle/jsonarchiveinterface.cpp b/autotests/kerfuffle/jsonarchiveinterface.cpp --- a/autotests/kerfuffle/jsonarchiveinterface.cpp +++ b/autotests/kerfuffle/jsonarchiveinterface.cpp @@ -69,7 +69,7 @@ Q_UNUSED(options) Q_UNUSED(numberOfEntriesToAdd) - foreach (const Kerfuffle::Archive::Entry *entry, files) { + for (const Kerfuffle::Archive::Entry *entry : files) { const QString &path = destination->fullPath() + entry->fullPath(); if (m_archive.contains(path)) { return false; @@ -113,7 +113,7 @@ bool JSONArchiveInterface::deleteFiles(const QVector& files) { - foreach (const Kerfuffle::Archive::Entry *file, files) { + for (const Kerfuffle::Archive::Entry *file : files) { const QString &fileName = file->fullPath(); if (m_archive.contains(fileName)) { m_archive.remove(fileName); diff --git a/autotests/kerfuffle/jsonparser.cpp b/autotests/kerfuffle/jsonparser.cpp --- a/autotests/kerfuffle/jsonparser.cpp +++ b/autotests/kerfuffle/jsonparser.cpp @@ -55,7 +55,8 @@ { JSONParser::JSONArchive archive; - foreach (const QVariant &entry, json.toList()) { + const auto jsonList = json.toList(); + for (const QVariant &entry : jsonList) { const QVariantMap entryMap = entry.toMap(); if (!entryMap.contains(QStringLiteral("fullPath"))) { diff --git a/autotests/kerfuffle/metadatatest.cpp b/autotests/kerfuffle/metadatatest.cpp --- a/autotests/kerfuffle/metadatatest.cpp +++ b/autotests/kerfuffle/metadatatest.cpp @@ -57,7 +57,7 @@ void MetaDataTest::testPluginMetadata() { - foreach (const KPluginMetaData& metaData, m_plugins) { + for (const KPluginMetaData& metaData : qAsConst(m_plugins)) { QVERIFY(metaData.serviceTypes().contains(QStringLiteral("Kerfuffle/Plugin"))); QVERIFY(!metaData.mimeTypes().isEmpty()); diff --git a/autotests/kerfuffle/movetest.cpp b/autotests/kerfuffle/movetest.cpp --- a/autotests/kerfuffle/movetest.cpp +++ b/autotests/kerfuffle/movetest.cpp @@ -231,12 +231,12 @@ QStringList oldPaths = getEntryPaths(archive); // Check that the entries to be moved are in the archive. - foreach (const auto entry, targetEntries) { + for (const auto entry : qAsConst(targetEntries)) { QVERIFY(oldPaths.contains(entry->fullPath())); } // Check that the expected paths (after the MoveJob) are not in the archive. - foreach (const auto &expectedPath, expectedNewPaths) { + for (const auto &expectedPath : qAsConst(expectedNewPaths)) { QVERIFY(!oldPaths.contains(expectedPath)); } @@ -249,12 +249,12 @@ QStringList newPaths = getEntryPaths(archive); // Check that the expected paths are now in the archive. - foreach (const auto &path, expectedNewPaths) { + for (const auto &path : qAsConst(expectedNewPaths)) { QVERIFY(newPaths.contains(path)); } // Check that the target paths are no longer in the archive. - foreach (const auto entry, targetEntries) { + for (const auto entry : qAsConst(targetEntries)) { QVERIFY(!newPaths.contains(entry->fullPath())); } diff --git a/autotests/plugins/cli7zplugin/cli7ztest.cpp b/autotests/plugins/cli7zplugin/cli7ztest.cpp --- a/autotests/plugins/cli7zplugin/cli7ztest.cpp +++ b/autotests/plugins/cli7zplugin/cli7ztest.cpp @@ -43,7 +43,8 @@ void Cli7zTest::initTestCase() { m_plugin = new Plugin(this); - foreach (Plugin *plugin, m_pluginManger.availablePlugins()) { + const auto plugins = m_pluginManger.availablePlugins(); + for (Plugin *plugin : plugins) { if (plugin->metaData().pluginId() == QStringLiteral("kerfuffle_cli7z")) { m_plugin = plugin; return; @@ -463,7 +464,7 @@ QFETCH(QVector, files); QStringList filesList; - foreach (const Archive::Entry *e, files) { + for (const Archive::Entry *e : qAsConst(files)) { filesList << e->fullPath(NoTrailingSlash); } diff --git a/autotests/plugins/clirarplugin/clirartest.cpp b/autotests/plugins/clirarplugin/clirartest.cpp --- a/autotests/plugins/clirarplugin/clirartest.cpp +++ b/autotests/plugins/clirarplugin/clirartest.cpp @@ -44,7 +44,8 @@ void CliRarTest::initTestCase() { m_plugin = new Plugin(this); - foreach (Plugin *plugin, m_pluginManger.availablePlugins()) { + const auto plugins = m_pluginManger.availablePlugins(); + for (Plugin *plugin : plugins) { if (plugin->metaData().pluginId() == QStringLiteral("kerfuffle_clirar")) { m_plugin = plugin; return; @@ -506,7 +507,7 @@ QFETCH(QVector, files); QStringList filesList; - foreach (const Archive::Entry *e, files) { + for (const Archive::Entry *e : qAsConst(files)) { filesList << e->fullPath(NoTrailingSlash); } diff --git a/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp b/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp --- a/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp +++ b/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp @@ -36,7 +36,8 @@ void CliUnarchiverTest::initTestCase() { m_plugin = new Plugin(this); - foreach (Plugin *plugin, m_pluginManger.availablePlugins()) { + const auto plugins = m_pluginManger.availablePlugins(); + for (Plugin *plugin : plugins) { if (plugin->metaData().pluginId() == QStringLiteral("kerfuffle_cliunarchiver")) { m_plugin = plugin; return; @@ -392,7 +393,7 @@ QFETCH(QVector, files); QStringList filesList; - foreach (const Archive::Entry *e, files) { + for (const Archive::Entry *e : qAsConst(files)) { filesList << e->fullPath(NoTrailingSlash); } diff --git a/autotests/plugins/clizipplugin/cliziptest.cpp b/autotests/plugins/clizipplugin/cliziptest.cpp --- a/autotests/plugins/clizipplugin/cliziptest.cpp +++ b/autotests/plugins/clizipplugin/cliziptest.cpp @@ -35,7 +35,8 @@ void CliZipTest::initTestCase() { m_plugin = new Plugin(this); - foreach (Plugin *plugin, m_pluginManger.availablePlugins()) { + const auto plugins = m_pluginManger.availablePlugins(); + for (Plugin *plugin : plugins) { if (plugin->metaData().pluginId() == QStringLiteral("kerfuffle_clizip")) { m_plugin = plugin; return; @@ -230,7 +231,7 @@ QFETCH(QVector, files); QStringList filesList; - foreach (const Archive::Entry *e, files) { + for (const Archive::Entry *e : qAsConst(files)) { filesList << e->fullPath(NoTrailingSlash); } diff --git a/autotests/testhelper/abstractaddtest.cpp b/autotests/testhelper/abstractaddtest.cpp --- a/autotests/testhelper/abstractaddtest.cpp +++ b/autotests/testhelper/abstractaddtest.cpp @@ -48,12 +48,13 @@ void AbstractAddTest::setupRows(const QString &testName, const QString &archiveName, const QVector &targetEntries, Archive::Entry *destination, const QStringList &expectedNewPaths, uint numberOfEntries) const { // Repeat the same test case for each format and for each plugin supporting the format. - foreach (const QString &format, TestHelper::testFormats()) { + const QStringList formats = TestHelper::testFormats(); + for (const QString &format : formats) { const QString filename = QStringLiteral("%1.%2").arg(archiveName, format); const auto mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension); const auto plugins = m_pluginManager.preferredWritePluginsFor(mime); - foreach (const auto plugin, plugins) { + for (const auto plugin : plugins) { QTest::newRow(QStringLiteral("%1 (%2, %3)").arg(testName, format, plugin->metaData().pluginId()).toUtf8().constData()) << filename << plugin diff --git a/kerfuffle/addtoarchive.cpp b/kerfuffle/addtoarchive.cpp --- a/kerfuffle/addtoarchive.cpp +++ b/kerfuffle/addtoarchive.cpp @@ -182,7 +182,7 @@ const QDir stripDir(m_firstPath); - foreach (Archive::Entry *entry, m_entries) { + for (Archive::Entry *entry : qAsConst(m_entries)) { entry->setFullPath(stripDir.absoluteFilePath(entry->fullPath())); } diff --git a/kerfuffle/archive_kerfuffle.cpp b/kerfuffle/archive_kerfuffle.cpp --- a/kerfuffle/archive_kerfuffle.cpp +++ b/kerfuffle/archive_kerfuffle.cpp @@ -62,7 +62,7 @@ } Archive *archive = nullptr; - foreach (Plugin *plugin, offers) { + for (Plugin *plugin : offers) { archive = create(fileName, plugin, parent); // Use the first valid plugin, according to the priority sorting. if (archive->isValid()) { diff --git a/kerfuffle/archiveentry.cpp b/kerfuffle/archiveentry.cpp --- a/kerfuffle/archiveentry.cpp +++ b/kerfuffle/archiveentry.cpp @@ -144,7 +144,7 @@ Archive::Entry *Archive::Entry::find(const QString &name) const { - foreach (Entry *entry, m_entries) { + for (Entry *entry : qAsConst(m_entries)) { if (entry && (entry->name() == name)) { return entry; } @@ -175,7 +175,8 @@ return; } - foreach (auto entry, entries()) { + const auto archiveEntries = entries(); + for (auto entry : archiveEntries) { if (entry->isDir()) { dirs++; } else { diff --git a/kerfuffle/archiveformat.cpp b/kerfuffle/archiveformat.cpp --- a/kerfuffle/archiveformat.cpp +++ b/kerfuffle/archiveformat.cpp @@ -65,7 +65,8 @@ ArchiveFormat ArchiveFormat::fromMetadata(const QMimeType& mimeType, const KPluginMetaData& metadata) { const QJsonObject json = metadata.rawData(); - foreach (const QString& mime, metadata.mimeTypes()) { + const QStringList mimeTypes = metadata.mimeTypes(); + for (const QString& mime : mimeTypes) { if (mimeType.name() != mime) { continue; } @@ -86,8 +87,8 @@ // We use a QStringList instead of QVariantMap for encryption methods, to // allow arbitrary ordering of the items. QStringList encryptionMethods; - QJsonArray array = formatProps[QStringLiteral("EncryptionMethods")].toArray(); - foreach (const QJsonValue &value, array) { + const QJsonArray array = formatProps[QStringLiteral("EncryptionMethods")].toArray(); + for (const QJsonValue &value : array) { encryptionMethods.append(value.toString()); } QString defaultEncMethod = formatProps[QStringLiteral("EncryptionMethodDefault")].toString(); diff --git a/kerfuffle/archiveinterface.cpp b/kerfuffle/archiveinterface.cpp --- a/kerfuffle/archiveinterface.cpp +++ b/kerfuffle/archiveinterface.cpp @@ -169,7 +169,7 @@ QStringList ReadOnlyArchiveInterface::entryFullPaths(const QVector &entries, PathFormat format) { QStringList filesList; - foreach (const Archive::Entry *file, entries) { + for (const Archive::Entry *file : entries) { filesList << file->fullPath(format); } return filesList; @@ -179,13 +179,13 @@ { // QMap is easy way to get entries sorted by their fullPath. QMap sortedEntries; - foreach (Archive::Entry *entry, entries) { + for (Archive::Entry *entry : entries) { sortedEntries.insert(entry->fullPath(), entry); } QVector filteredEntries; QString lastFolder; - foreach (Archive::Entry *entry, sortedEntries) { + for (Archive::Entry *entry : qAsConst(sortedEntries)) { if (lastFolder.count() > 0 && entry->fullPath().startsWith(lastFolder)) { continue; } @@ -206,7 +206,7 @@ QString newPath; int nameLength = 0; - foreach (const QString &entryPath, entries) { + for (const QString &entryPath : qAsConst(entries)) { if (lastFolder.count() > 0 && entryPath.startsWith(lastFolder)) { // Replace last moved or copied folder path with destination path. int charsCount = entryPath.count() - lastFolder.count(); diff --git a/kerfuffle/cliinterface.cpp b/kerfuffle/cliinterface.cpp --- a/kerfuffle/cliinterface.cpp +++ b/kerfuffle/cliinterface.cpp @@ -167,7 +167,7 @@ qDir.mkpath(absoluteDestinationPath); QObject *preservedParent = nullptr; - foreach (Archive::Entry *file, files) { + for (Archive::Entry *file : files) { // The entries may have parent. We have to save and apply it to our new entry in order to prevent memory // leaks. if (preservedParent == nullptr) { @@ -325,11 +325,11 @@ } if (m_operationMode == Delete || m_operationMode == Move) { - QStringList removedFullPaths = entryFullPaths(m_removedFiles); - foreach (const QString &fullPath, removedFullPaths) { + const QStringList removedFullPaths = entryFullPaths(m_removedFiles); + for (const QString &fullPath : removedFullPaths) { emit entryRemoved(fullPath); } - foreach (Archive::Entry *e, m_newMovedFiles) { + for (Archive::Entry *e : qAsConst(m_newMovedFiles)) { emit entry(e); } m_newMovedFiles.clear(); @@ -455,7 +455,7 @@ bool overwriteAll = false; bool skipAll = false; - foreach (const Archive::Entry *file, files) { + for (const Archive::Entry *file : files) { QFileInfo relEntry(file->fullPath().remove(file->rootNode)); QFileInfo absSourceEntry(QDir::current().absolutePath() + QLatin1Char('/') + file->fullPath()); @@ -647,15 +647,15 @@ { m_newMovedFiles.clear(); QMap entryMap; - foreach (const Archive::Entry* entry, entries) { + for (const Archive::Entry* entry : entries) { entryMap.insert(entry->fullPath(), entry); } QString lastFolder; QString newPath; int nameLength = 0; - foreach (const Archive::Entry* entry, entryMap) { + for (const Archive::Entry* entry : qAsConst(entryMap)) { if (lastFolder.count() > 0 && entry->fullPath().startsWith(lastFolder)) { // Replace last moved or copied folder path with destination path. int charsCount = entry->fullPath().count() - lastFolder.count(); @@ -690,7 +690,7 @@ QStringList CliInterface::extractFilesList(const QVector &entries) const { QStringList filesList; - foreach (const Archive::Entry *e, entries) { + for (const Archive::Entry *e : entries) { filesList << escapeFileName(e->fullPath(NoTrailingSlash)); } @@ -812,7 +812,7 @@ m_stdOutData = lines.takeLast(); } - foreach(const QByteArray& line, lines) { + for (const QByteArray& line : qAsConst(lines)) { if (!line.isEmpty() || (m_listEmptyLines && m_operationMode == List)) { if (!handleLine(QString::fromLocal8Bit(line))) { killProcess(); @@ -825,7 +825,7 @@ bool CliInterface::setAddedFiles() { QDir::setCurrent(m_tempAddDir->path()); - foreach (const Archive::Entry *file, m_passedFiles) { + for (const Archive::Entry *file : qAsConst(m_passedFiles)) { const QString oldPath = m_tempWorkingDir->path() + QLatin1Char('/') + file->fullPath(NoTrailingSlash); const QString newPath = m_tempAddDir->path() + QLatin1Char('/') + file->name(); if (!QFile::rename(oldPath, newPath)) { @@ -961,7 +961,8 @@ { // Check for a filename and store it. if (isFileExistsFileName(line)) { - foreach (const QString &pattern, m_cliProps->property("fileExistsFileNameRegExp").toStringList()) { + const QStringList fileExistsFileNameRegExp = m_cliProps->property("fileExistsFileNameRegExp").toStringList(); + for (const QString &pattern : fileExistsFileNameRegExp) { const QRegularExpression rxFileNamePattern(pattern); const QRegularExpressionMatch rxMatch = rxFileNamePattern.match(line); @@ -1027,7 +1028,7 @@ { QStringList pairList; if (entriesWithoutChildren.count() > 1) { - foreach (const Archive::Entry *file, entriesWithoutChildren) { + for (const Archive::Entry *file : entriesWithoutChildren) { pairList << file->fullPath(NoTrailingSlash) << destination->fullPath() + file->name(); } } else { @@ -1078,7 +1079,8 @@ QString oldSuffix = QMimeDatabase().suffixForFileName(filename()); QString name; - foreach (const QString &multiSuffix, m_cliProps->property("multiVolumeSuffix").toStringList()) { + const QStringList multiVolumeSuffix = m_cliProps->property("multiVolumeSuffix").toStringList(); + for (const QString &multiSuffix : multiVolumeSuffix) { QString newSuffix = multiSuffix; newSuffix.replace(QStringLiteral("$Suffix"), oldSuffix); name = filename().remove(oldSuffix).append(newSuffix); diff --git a/kerfuffle/cliproperties.cpp b/kerfuffle/cliproperties.cpp --- a/kerfuffle/cliproperties.cpp +++ b/kerfuffle/cliproperties.cpp @@ -47,7 +47,7 @@ } QStringList args; - foreach (const QString &s, m_addSwitch) { + for (const QString &s : qAsConst(m_addSwitch)) { args << s; } if (!password.isEmpty()) { @@ -75,7 +75,8 @@ QStringList CliProperties::commentArgs(const QString &archive, const QString &commentfile) { QStringList args; - foreach (const QString &s, substituteCommentSwitch(commentfile)) { + const QStringList commentSwitches = substituteCommentSwitch(commentfile); + for (const QString &s : commentSwitches) { args << s; } args << archive; @@ -92,7 +93,7 @@ args << substitutePasswordSwitch(password); } args << archive; - foreach (const Archive::Entry *e, files) { + for (const Archive::Entry *e : files) { args << e->fullPath(NoTrailingSlash); } @@ -123,7 +124,7 @@ QStringList CliProperties::listArgs(const QString &archive, const QString &password) { QStringList args; - foreach (const QString &s, m_listSwitch) { + for (const QString &s : qAsConst(m_listSwitch)) { args << s; } @@ -146,7 +147,7 @@ } args << archive; if (entries.count() > 1) { - foreach (const Archive::Entry *file, entries) { + for (const Archive::Entry *file : entries) { args << file->fullPath(NoTrailingSlash) << destination->fullPath() + file->name(); } } else { @@ -160,7 +161,7 @@ QStringList CliProperties::testArgs(const QString &archive, const QString &password) { QStringList args; - foreach (const QString &s, m_testSwitch) { + for (const QString &s : qAsConst(m_testSwitch)) { args << s; } if (!password.isEmpty()) { @@ -292,7 +293,7 @@ bool CliProperties::isTestPassedMsg(const QString &line) { - foreach(const QString &rx, m_testPassedPatterns) { + for (const QString &rx : qAsConst(m_testPassedPatterns)) { if (QRegularExpression(rx).match(line).hasMatch()) { return true; } diff --git a/kerfuffle/createdialog.cpp b/kerfuffle/createdialog.cpp --- a/kerfuffle/createdialog.cpp +++ b/kerfuffle/createdialog.cpp @@ -79,7 +79,7 @@ } // Populate combobox with mimetypes. - foreach (const QString &type, m_supportedMimeTypes) { + for (const QString &type : qAsConst(m_supportedMimeTypes)) { m_ui->mimeComboBox->addItem(QMimeDatabase().mimeTypeForName(type).comment()); } diff --git a/kerfuffle/jobs.cpp b/kerfuffle/jobs.cpp --- a/kerfuffle/jobs.cpp +++ b/kerfuffle/jobs.cpp @@ -645,7 +645,7 @@ uint totalCount = 0; QElapsedTimer timer; timer.start(); - foreach (const Archive::Entry* entry, m_entries) { + for (const Archive::Entry* entry : qAsConst(m_entries)) { totalCount++; if (QFileInfo(entry->fullPath()).isDir()) { QDirIterator it(entry->fullPath(), QDir::AllEntries | QDir::Readable | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); @@ -667,7 +667,7 @@ Q_ASSERT(m_writeInterface); // The file paths must be relative to GlobalWorkDir. - foreach (Archive::Entry *entry, m_entries) { + for (Archive::Entry *entry : qAsConst(m_entries)) { // #191821: workDir must be used instead of QDir::current() // so that symlinks aren't resolved automatically const QString &fullPath = entry->fullPath(); diff --git a/kerfuffle/plugin.cpp b/kerfuffle/plugin.cpp --- a/kerfuffle/plugin.cpp +++ b/kerfuffle/plugin.cpp @@ -69,7 +69,7 @@ QStringList readOnlyExecutables; const QJsonArray array = m_metaData.rawData()[QStringLiteral("X-KDE-Kerfuffle-ReadOnlyExecutables")].toArray(); - foreach (const QJsonValue &value, array) { + for (const QJsonValue &value : array) { readOnlyExecutables << value.toString(); } @@ -81,7 +81,7 @@ QStringList readWriteExecutables; const QJsonArray array = m_metaData.rawData()[QStringLiteral("X-KDE-Kerfuffle-ReadWriteExecutables")].toArray(); - foreach (const QJsonValue &value, array) { + for (const QJsonValue &value : array) { readWriteExecutables << value.toString(); } @@ -105,7 +105,7 @@ bool Plugin::findExecutables(const QStringList &executables) { - foreach (const QString &executable, executables) { + for (const QString &executable : executables) { if (executable.isEmpty()) { continue; } diff --git a/kerfuffle/pluginmanager.cpp b/kerfuffle/pluginmanager.cpp --- a/kerfuffle/pluginmanager.cpp +++ b/kerfuffle/pluginmanager.cpp @@ -57,7 +57,7 @@ QVector PluginManager::availablePlugins() const { QVector availablePlugins; - foreach (Plugin *plugin, m_plugins) { + for (Plugin *plugin : qAsConst(m_plugins)) { if (plugin->isValid()) { availablePlugins << plugin; } @@ -69,7 +69,8 @@ QVector PluginManager::availableWritePlugins() const { QVector availableWritePlugins; - foreach (Plugin *plugin, availablePlugins()) { + const auto plugins = availablePlugins(); + for (Plugin *plugin : plugins) { if (plugin->isReadWrite()) { availableWritePlugins << plugin; } @@ -81,7 +82,7 @@ QVector PluginManager::enabledPlugins() const { QVector enabledPlugins; - foreach (Plugin *plugin, m_plugins) { + for (Plugin *plugin : qAsConst(m_plugins)) { if (plugin->isEnabled()) { enabledPlugins << plugin; } @@ -123,8 +124,10 @@ { QSet supported; QMimeDatabase db; - foreach (Plugin *plugin, availablePlugins()) { - foreach (const auto& mimeType, plugin->metaData().mimeTypes()) { + const auto plugins = availablePlugins(); + for (Plugin *plugin : plugins) { + const auto mimeTypes = plugin->metaData().mimeTypes(); + for (const auto& mimeType : mimeTypes) { if (db.mimeTypeForName(mimeType).isValid()) { supported.insert(mimeType); } @@ -157,8 +160,10 @@ { QSet supported; QMimeDatabase db; - foreach (Plugin *plugin, availableWritePlugins()) { - foreach (const auto& mimeType, plugin->metaData().mimeTypes()) { + const auto plugins = availableWritePlugins(); + for (Plugin *plugin : plugins) { + const auto mimeTypes = plugin->metaData().mimeTypes(); + for (const auto& mimeType : mimeTypes) { if (db.mimeTypeForName(mimeType).isValid()) { supported.insert(mimeType); } @@ -191,10 +196,11 @@ { const bool supportedMime = supportedMimeTypes().contains(mimeType.name()); QVector filteredPlugins; - foreach (Plugin *plugin, plugins) { + for (Plugin *plugin : plugins) { if (!supportedMime) { // Check whether the mimetype inherits from a supported mimetype. - foreach (const QString &mime, plugin->metaData().mimeTypes()) { + const QStringList mimeTypes = plugin->metaData().mimeTypes(); + for (const QString &mime : mimeTypes) { if (mimeType.inherits(mime)) { filteredPlugins << plugin; } @@ -211,7 +217,7 @@ { const QVector plugins = KPluginLoader::findPlugins(QStringLiteral("kerfuffle")); QSet addedPlugins; - foreach (const KPluginMetaData &metaData, plugins) { + for (const KPluginMetaData &metaData : plugins) { const auto pluginId = metaData.pluginId(); // Filter out duplicate plugins. if (addedPlugins.contains(pluginId)) { @@ -241,14 +247,14 @@ QMap map; // Initialize the QMap to sort by comment. - foreach (const QString &mimeType, mimeTypes) { + for (const QString &mimeType : mimeTypes) { QMimeType mime(QMimeDatabase().mimeTypeForName(mimeType)); map[mime.comment().toLower()] = mime.name(); } // Convert to sorted QStringList. QStringList sortedMimeTypes; - foreach (const QString &value, map) { + for (const QString &value : qAsConst(map)) { sortedMimeTypes << value; } @@ -259,7 +265,8 @@ { // Step 1: look for the libarchive plugin, which is built against libarchive. const QString pluginPath = []() { - foreach (const QString &path, QCoreApplication::libraryPaths()) { + const QStringList paths = QCoreApplication::libraryPaths(); + for (const QString &path : paths) { const QString pluginPath = QStringLiteral("%1/kerfuffle/kerfuffle_libarchive.so").arg(path); if (QFileInfo::exists(pluginPath)) { return pluginPath; diff --git a/kerfuffle/pluginsettingspage.cpp b/kerfuffle/pluginsettingspage.cpp --- a/kerfuffle/pluginsettingspage.cpp +++ b/kerfuffle/pluginsettingspage.cpp @@ -40,7 +40,8 @@ { setupUi(this); - foreach (const auto plugin, m_pluginManager.installedPlugins()) { + const auto installedPlugins = m_pluginManager.installedPlugins(); + for (const auto plugin : installedPlugins) { const auto metaData = plugin->metaData(); auto item = new QTreeWidgetItem(kcfg_disabledPlugins); item->setData(0, Qt::UserRole, QVariant::fromValue(plugin)); diff --git a/part/archivemodel.cpp b/part/archivemodel.cpp --- a/part/archivemodel.cpp +++ b/part/archivemodel.cpp @@ -307,7 +307,8 @@ } QStringList paths; - foreach(const QUrl &url, data->urls()) { + const auto urls = data->urls(); + for (const QUrl &url : urls) { paths << url.toLocalFile(); } @@ -380,7 +381,7 @@ Archive::Entry *parent = m_rootEntry.data(); - foreach(const QString &piece, pieces) { + for (const QString &piece : qAsConst(pieces)) { Archive::Entry *entry = parent->find(piece); if (!entry) { // Directory entry will be traversed later (that happens for some archive formats, 7z for instance). @@ -742,7 +743,7 @@ const Archive::Entry *lastDirEntry = destination; QString skippedDirPath; - foreach (const QString &entry, entries) { + for (const QString &entry : entries) { if (skippedDirPath.count() > 0 && entry.startsWith(skippedDirPath)) { continue; } else { @@ -786,7 +787,7 @@ bool ArchiveModel::hasDuplicatedEntries(const QStringList &entries) { QStringList tempList; - foreach (const QString &entry, entries) { + for (const QString &entry : entries) { if (tempList.contains(entry)) { return true; } @@ -798,7 +799,7 @@ QMap ArchiveModel::entryMap(const QVector &entries) { QMap map; - foreach (Archive::Entry *entry, entries) { + for (Archive::Entry *entry : entries) { map.insert(entry->fullPath(), entry); } return map; @@ -835,7 +836,7 @@ } } - foreach(const QPersistentModelIndex& node, nodesToDelete) { + for (const QPersistentModelIndex& node : qAsConst(nodesToDelete)) { Archive::Entry *rawEntry = static_cast(node.internalPointer()); qCDebug(ARK) << "Delete with parent entries " << rawEntry->getParent()->entries() << " and row " << rawEntry->row(); beginRemoveRows(parent(node), rawEntry->row(), rawEntry->row()); @@ -868,7 +869,8 @@ void ArchiveModel::traverseAndCountDirNode(Archive::Entry *dir) { - foreach(Archive::Entry *entry, dir->entries()) { + const auto entries = dir->entries(); + for (Archive::Entry *entry : entries) { if (entry->isDir()) { traverseAndCountDirNode(entry); m_numberOfFolders++; diff --git a/part/infopanel.cpp b/part/infopanel.cpp --- a/part/infopanel.cpp +++ b/part/infopanel.cpp @@ -143,7 +143,7 @@ iconLabel->setPixmap(getDesktopIconForName(QStringLiteral("utilities-file-archiver"))); fileName->setText(i18np("One file selected", "%1 files selected", list.size())); quint64 totalSize = 0; - foreach(const QModelIndex& index, list) { + for (const QModelIndex& index : list) { const Archive::Entry *entry = m_model->entryForIndex(index); totalSize += entry->property("size").toULongLong(); } diff --git a/part/jobtracker.cpp b/part/jobtracker.cpp --- a/part/jobtracker.cpp +++ b/part/jobtracker.cpp @@ -38,7 +38,7 @@ JobTracker::~JobTracker() { - foreach(KJob *job, m_jobs) { + for (KJob *job : qAsConst(m_jobs)) { job->kill(); } } diff --git a/part/overwritedialog.cpp b/part/overwritedialog.cpp --- a/part/overwritedialog.cpp +++ b/part/overwritedialog.cpp @@ -51,7 +51,7 @@ connect(&m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(&m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); - foreach (const Archive::Entry *entry, entries) { + for (const Archive::Entry *entry : entries) { QListWidgetItem *item = new QListWidgetItem(icons.value(entry->fullPath(NoTrailingSlash)), entry->fullPath(NoTrailingSlash)); m_entriesList.addItem(item); } diff --git a/part/part.cpp b/part/part.cpp --- a/part/part.cpp +++ b/part/part.cpp @@ -724,7 +724,8 @@ QModelIndexList Part::getSelectedIndexes() { QModelIndexList list; - foreach (const QModelIndex &i, m_view->selectionModel()->selectedRows()) { + const auto selectedRows = m_view->selectionModel()->selectedRows(); + for (const QModelIndex &i : selectedRows) { list.append(m_filterModel->mapToSource(i)); } return list; @@ -1058,7 +1059,7 @@ // Find the relative path of the file within the archive. QString relPath = file; - foreach (QTemporaryDir *tmpDir, m_tmpExtractDirList) { + for (QTemporaryDir *tmpDir : qAsConst(m_tmpExtractDirList)) { relPath.remove(tmpDir->path()); //Remove tmpDir. } relPath = relPath.mid(1); //Remove leading slash. @@ -1196,7 +1197,7 @@ { QVector ret; - foreach(const QModelIndex& index, list) { + for (const QModelIndex& index : list) { ret << m_model->entryForIndex(index); } @@ -1208,7 +1209,7 @@ QVector fileList; QStringList fullPathsList; - foreach (const QModelIndex& index, list) { + for (const QModelIndex& index : list) { // Find the topmost unselected parent. This is done by iterating up // through the directory hierarchy and see if each parent is included @@ -1229,7 +1230,8 @@ // Append index with root node to fileList. QModelIndexList alist = QModelIndexList() << index; - foreach (Archive::Entry *entry, filesForIndexes(alist)) { + const auto filesIndexes = filesForIndexes(alist); + for (Archive::Entry *entry : filesIndexes) { const QString fullPath = entry->fullPath(); if (!fullPathsList.contains(fullPath)) { entry->rootNode = rootFileName; @@ -1270,7 +1272,7 @@ } QStringList withChildPaths; - foreach (const QString& file, filesToAdd) { + for (const QString& file : filesToAdd) { m_jobTempEntries.push_back(new Archive::Entry(nullptr, file)); if (QFileInfo(file).isDir()) { withChildPaths << file + QLatin1Char('/'); @@ -1401,11 +1403,11 @@ m_model->filesToMove = ArchiveModel::entryMap(filesForIndexes(selectedRows)); qCDebug(ARK) << "Entries marked to cut:" << m_model->filesToMove.values(); m_model->filesToCopy.clear(); - foreach (const QModelIndex &row, m_cutIndexes) { + for (const QModelIndex &row : qAsConst(m_cutIndexes)) { m_view->dataChanged(row, row); } m_cutIndexes = selectedRows; - foreach (const QModelIndex &row, m_cutIndexes) { + for (const QModelIndex &row : qAsConst(m_cutIndexes)) { m_view->dataChanged(row, row); } updateActions(); @@ -1415,7 +1417,7 @@ { m_model->filesToCopy = ArchiveModel::entryMap(filesForIndexes(addChildren(getSelectedIndexes()))); qCDebug(ARK) << "Entries marked to copy:" << m_model->filesToCopy.values(); - foreach (const QModelIndex &row, m_cutIndexes) { + for (const QModelIndex &row : qAsConst(m_cutIndexes)) { m_view->dataChanged(row, row); } m_cutIndexes.clear(); @@ -1467,7 +1469,7 @@ m_destination->setFullPath(m_destination->fullPath() + entryName); } - foreach (const Archive::Entry *entry, entriesWithoutChildren) { + for (const Archive::Entry *entry : qAsConst(entriesWithoutChildren)) { if (entry->isDir() && m_destination->fullPath().startsWith(entry->fullPath())) { KMessageBox::error(widget(), i18n("Folders can't be moved into themselves."), diff --git a/plugins/cli7zplugin/cliplugin.cpp b/plugins/cli7zplugin/cliplugin.cpp --- a/plugins/cli7zplugin/cliplugin.cpp +++ b/plugins/cli7zplugin/cliplugin.cpp @@ -319,7 +319,7 @@ void CliPlugin::handleMethods(const QStringList &methods) { - foreach (const QString &method, methods) { + for (const QString &method : methods) { QRegularExpression rxEncMethod(QStringLiteral("^(7zAES|AES-128|AES-192|AES-256|ZipCrypto)$")); if (rxEncMethod.match(method).hasMatch()) { diff --git a/plugins/cliunarchiverplugin/cliplugin.cpp b/plugins/cliunarchiverplugin/cliplugin.cpp --- a/plugins/cliunarchiverplugin/cliplugin.cpp +++ b/plugins/cliunarchiverplugin/cliplugin.cpp @@ -240,7 +240,7 @@ } const QJsonArray entries = json.value(QStringLiteral("lsarContents")).toArray(); - foreach (const QJsonValue& value, entries) { + for (const QJsonValue& value : entries) { const QJsonObject currentEntryJson = value.toObject(); Archive::Entry *currentEntry = new Archive::Entry(this); diff --git a/plugins/libarchive/libarchiveplugin.cpp b/plugins/libarchive/libarchiveplugin.cpp --- a/plugins/libarchive/libarchiveplugin.cpp +++ b/plugins/libarchive/libarchiveplugin.cpp @@ -53,7 +53,7 @@ LibarchivePlugin::~LibarchivePlugin() { - foreach (const auto e, m_emittedEntries) { + for (const auto e : qAsConst(m_emittedEntries)) { // Entries might be passed to pending slots, so we just schedule their deletion. e->deleteLater(); } diff --git a/plugins/libarchive/readwritelibarchiveplugin.cpp b/plugins/libarchive/readwritelibarchiveplugin.cpp --- a/plugins/libarchive/readwritelibarchiveplugin.cpp +++ b/plugins/libarchive/readwritelibarchiveplugin.cpp @@ -75,7 +75,7 @@ ? QString() : destination->fullPath(); - foreach(Archive::Entry *selectedFile, files) { + for (Archive::Entry *selectedFile : files) { if (QThread::currentThread()->isInterruptionRequested()) { break; } diff --git a/plugins/libsinglefileplugin/singlefileplugin.cpp b/plugins/libsinglefileplugin/singlefileplugin.cpp --- a/plugins/libsinglefileplugin/singlefileplugin.cpp +++ b/plugins/libsinglefileplugin/singlefileplugin.cpp @@ -146,7 +146,7 @@ return uncompressedName; } - foreach(const QString & extension, m_possibleExtensions) { + for (const QString & extension : qAsConst(m_possibleExtensions)) { qCDebug(ARK) << extension; if (uncompressedName.endsWith(extension, Qt::CaseInsensitive)) { diff --git a/plugins/libzipplugin/libzipplugin.cpp b/plugins/libzipplugin/libzipplugin.cpp --- a/plugins/libzipplugin/libzipplugin.cpp +++ b/plugins/libzipplugin/libzipplugin.cpp @@ -61,7 +61,7 @@ LibzipPlugin::~LibzipPlugin() { - foreach (const auto e, m_emittedEntries) { + for (const auto e : qAsConst(m_emittedEntries)) { // Entries might be passed to pending slots, so we just schedule their deletion. e->deleteLater(); } @@ -130,7 +130,7 @@ } uint i = 0; - foreach (const Archive::Entry* e, files) { + for (const Archive::Entry* e : files) { if (QThread::currentThread()->isInterruptionRequested()) { break; @@ -395,7 +395,7 @@ } qulonglong i = 0; - foreach (const Archive::Entry* e, files) { + for (const Archive::Entry* e : files) { if (QThread::currentThread()->isInterruptionRequested()) { break; @@ -572,7 +572,7 @@ } else { // We extract only the entries in files. qulonglong i = 0; - foreach (const Archive::Entry* e, files) { + for (const Archive::Entry* e : files) { if (QThread::currentThread()->isInterruptionRequested()) { break; }