mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 08:27:24 -06:00
Convert all foreach() to range-based for()
This commit is contained in:
committed by
sledgehammer999
parent
62e71a15a4
commit
e2ee928017
@@ -83,10 +83,10 @@ MagnetUri::MagnetUri(const QString &source)
|
||||
m_hash = m_addTorrentParams.info_hash;
|
||||
m_name = QString::fromStdString(m_addTorrentParams.name);
|
||||
|
||||
foreach (const std::string &tracker, m_addTorrentParams.trackers)
|
||||
for (const std::string &tracker : m_addTorrentParams.trackers)
|
||||
m_trackers.append(QString::fromStdString(tracker));
|
||||
|
||||
foreach (const std::string &urlSeed, m_addTorrentParams.url_seeds)
|
||||
for (const std::string &urlSeed : m_addTorrentParams.url_seeds)
|
||||
m_urlSeeds.append(QUrl(urlSeed.c_str()));
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace
|
||||
|
||||
for (auto i = categories.cbegin(); i != categories.cend(); ++i) {
|
||||
const QString &category = i.key();
|
||||
foreach (const QString &subcat, Session::expandCategory(category)) {
|
||||
for (const QString &subcat : copyAsConst(Session::expandCategory(category))) {
|
||||
if (!expanded.contains(subcat))
|
||||
expanded[subcat] = "";
|
||||
}
|
||||
@@ -610,7 +610,7 @@ void Session::setTempPathEnabled(bool enabled)
|
||||
{
|
||||
if (enabled != isTempPathEnabled()) {
|
||||
m_isTempPathEnabled = enabled;
|
||||
foreach (TorrentHandle *const torrent, m_torrents)
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
torrent->handleTempPathChanged();
|
||||
}
|
||||
}
|
||||
@@ -624,7 +624,7 @@ void Session::setAppendExtensionEnabled(bool enabled)
|
||||
{
|
||||
if (isAppendExtensionEnabled() != enabled) {
|
||||
// append or remove .!qB extension for incomplete files
|
||||
foreach (TorrentHandle *const torrent, m_torrents)
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
torrent->handleAppendExtensionToggled();
|
||||
|
||||
m_isAppendExtensionEnabled = enabled;
|
||||
@@ -752,7 +752,7 @@ bool Session::addCategory(const QString &name, const QString &savePath)
|
||||
return false;
|
||||
|
||||
if (isSubcategoriesEnabled()) {
|
||||
foreach (const QString &parent, expandCategory(name)) {
|
||||
for (const QString &parent : copyAsConst(expandCategory(name))) {
|
||||
if ((parent != name) && !m_categories.contains(parent)) {
|
||||
m_categories[parent] = "";
|
||||
emit categoryAdded(parent);
|
||||
@@ -775,12 +775,12 @@ bool Session::editCategory(const QString &name, const QString &savePath)
|
||||
m_categories[name] = savePath;
|
||||
m_storedCategories = map_cast(m_categories);
|
||||
if (isDisableAutoTMMWhenCategorySavePathChanged()) {
|
||||
foreach (TorrentHandle *const torrent, torrents())
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
if (torrent->category() == name)
|
||||
torrent->setAutoTMMEnabled(false);
|
||||
}
|
||||
else {
|
||||
foreach (TorrentHandle *const torrent, torrents())
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
if (torrent->category() == name)
|
||||
torrent->handleCategorySavePathChanged();
|
||||
}
|
||||
@@ -790,7 +790,7 @@ bool Session::editCategory(const QString &name, const QString &savePath)
|
||||
|
||||
bool Session::removeCategory(const QString &name)
|
||||
{
|
||||
foreach (TorrentHandle *const torrent, torrents())
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
if (torrent->belongsToCategory(name))
|
||||
torrent->setCategory("");
|
||||
|
||||
@@ -877,7 +877,7 @@ bool Session::addTag(const QString &tag)
|
||||
bool Session::removeTag(const QString &tag)
|
||||
{
|
||||
if (m_tags.remove(tag)) {
|
||||
foreach (TorrentHandle *const torrent, torrents())
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
torrent->removeTag(tag);
|
||||
m_storedTags = m_tags.toList();
|
||||
emit tagRemoved(tag);
|
||||
@@ -1085,7 +1085,7 @@ void Session::configure()
|
||||
void Session::processBannedIPs(libt::ip_filter &filter)
|
||||
{
|
||||
// First, import current filter
|
||||
foreach (const QString &ip, m_bannedIPs.value()) {
|
||||
for (const QString &ip : copyAsConst(m_bannedIPs.value())) {
|
||||
boost::system::error_code ec;
|
||||
libt::address addr = libt::address::from_string(ip.toLatin1().constData(), ec);
|
||||
Q_ASSERT(!ec);
|
||||
@@ -1204,7 +1204,7 @@ void Session::configure(libtorrent::settings_pack &settingsPack)
|
||||
const ushort port = this->port();
|
||||
std::pair<int, int> ports(port, port);
|
||||
settingsPack.set_int(libt::settings_pack::max_retry_port_bind, ports.second - ports.first);
|
||||
foreach (QString ip, getListeningIPs()) {
|
||||
for (QString ip : getListeningIPs()) {
|
||||
libt::error_code ec;
|
||||
std::string interfacesStr;
|
||||
|
||||
@@ -1770,7 +1770,7 @@ void Session::enableBandwidthScheduler()
|
||||
void Session::populateAdditionalTrackers()
|
||||
{
|
||||
m_additionalTrackerList.clear();
|
||||
foreach (QString tracker, additionalTrackers().split('\n')) {
|
||||
for (QString tracker : copyAsConst(additionalTrackers().split('\n'))) {
|
||||
tracker = tracker.trimmed();
|
||||
if (!tracker.isEmpty())
|
||||
m_additionalTrackerList << tracker;
|
||||
@@ -1781,7 +1781,7 @@ void Session::processShareLimits()
|
||||
{
|
||||
qDebug("Processing share limits...");
|
||||
|
||||
foreach (TorrentHandle *const torrent, m_torrents) {
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents())) {
|
||||
if (torrent->isSeed() && !torrent->isForced()) {
|
||||
if (torrent->ratioLimit() != TorrentHandle::NO_RATIO_LIMIT) {
|
||||
const qreal ratio = torrent->realRatio();
|
||||
@@ -1934,7 +1934,7 @@ bool Session::deleteTorrent(const QString &hash, bool deleteLocalFiles)
|
||||
m_nativeSession->remove_torrent(torrent->nativeHandle(), libt::session::delete_partfile);
|
||||
#endif
|
||||
// Remove unwanted and incomplete files
|
||||
foreach (const QString &unwantedFile, unwantedFiles) {
|
||||
for (const QString &unwantedFile : qAsConst(unwantedFiles)) {
|
||||
qDebug("Removing unwanted file: %s", qUtf8Printable(unwantedFile));
|
||||
Utils::Fs::forceRemove(unwantedFile);
|
||||
const QString parentFolder = Utils::Fs::branchPath(unwantedFile);
|
||||
@@ -1948,7 +1948,7 @@ bool Session::deleteTorrent(const QString &hash, bool deleteLocalFiles)
|
||||
QStringList filters;
|
||||
filters << QString("%1.*").arg(torrent->hash());
|
||||
const QStringList files = resumeDataDir.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
foreach (const QString &file, files)
|
||||
for (const QString &file : files)
|
||||
Utils::Fs::forceRemove(resumeDataDir.absoluteFilePath(file));
|
||||
|
||||
delete torrent;
|
||||
@@ -1983,7 +1983,7 @@ void Session::increaseTorrentsPriority(const QStringList &hashes)
|
||||
std::greater<QPair<int, TorrentHandle *>>> torrentQueue;
|
||||
|
||||
// Sort torrents by priority
|
||||
foreach (const InfoHash &infoHash, hashes) {
|
||||
for (const InfoHash infoHash : hashes) {
|
||||
TorrentHandle *const torrent = m_torrents.value(infoHash);
|
||||
if (torrent && !torrent->isSeed())
|
||||
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
|
||||
@@ -2006,7 +2006,7 @@ void Session::decreaseTorrentsPriority(const QStringList &hashes)
|
||||
std::less<QPair<int, TorrentHandle *>>> torrentQueue;
|
||||
|
||||
// Sort torrents by priority
|
||||
foreach (const InfoHash &infoHash, hashes) {
|
||||
for (const InfoHash infoHash : hashes) {
|
||||
TorrentHandle *const torrent = m_torrents.value(infoHash);
|
||||
if (torrent && !torrent->isSeed())
|
||||
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
|
||||
@@ -2032,7 +2032,7 @@ void Session::topTorrentsPriority(const QStringList &hashes)
|
||||
std::greater<QPair<int, TorrentHandle *>>> torrentQueue;
|
||||
|
||||
// Sort torrents by priority
|
||||
foreach (const InfoHash &infoHash, hashes) {
|
||||
for (const InfoHash infoHash : hashes) {
|
||||
TorrentHandle *const torrent = m_torrents.value(infoHash);
|
||||
if (torrent && !torrent->isSeed())
|
||||
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
|
||||
@@ -2055,7 +2055,7 @@ void Session::bottomTorrentsPriority(const QStringList &hashes)
|
||||
std::less<QPair<int, TorrentHandle *>>> torrentQueue;
|
||||
|
||||
// Sort torrents by priority
|
||||
foreach (const InfoHash &infoHash, hashes) {
|
||||
for (const InfoHash infoHash : hashes) {
|
||||
TorrentHandle *const torrent = m_torrents.value(infoHash);
|
||||
if (torrent && !torrent->isSeed())
|
||||
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
|
||||
@@ -2367,7 +2367,7 @@ void Session::exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolde
|
||||
|
||||
void Session::generateResumeData(bool final)
|
||||
{
|
||||
foreach (TorrentHandle *const torrent, m_torrents) {
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents)) {
|
||||
if (!torrent->isValid()) continue;
|
||||
if (torrent->isChecking() || torrent->isPaused()) continue;
|
||||
if (!final && !torrent->needSaveResumeData()) continue;
|
||||
@@ -2444,10 +2444,10 @@ void Session::setDefaultSavePath(QString path)
|
||||
m_defaultSavePath = path;
|
||||
|
||||
if (isDisableAutoTMMWhenDefaultSavePathChanged())
|
||||
foreach (TorrentHandle *const torrent, torrents())
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
torrent->setAutoTMMEnabled(false);
|
||||
else
|
||||
foreach (TorrentHandle *const torrent, torrents())
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
torrent->handleCategorySavePathChanged();
|
||||
}
|
||||
|
||||
@@ -2458,7 +2458,7 @@ void Session::setTempPath(QString path)
|
||||
|
||||
m_tempPath = path;
|
||||
|
||||
foreach (TorrentHandle *const torrent, m_torrents)
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
torrent->handleTempPathChanged();
|
||||
}
|
||||
|
||||
@@ -2532,7 +2532,7 @@ const QStringList Session::getListeningIPs()
|
||||
QHostAddress ip;
|
||||
QString ipString;
|
||||
QAbstractSocket::NetworkLayerProtocol protocol;
|
||||
foreach (const QNetworkAddressEntry &entry, addresses) {
|
||||
for (const QNetworkAddressEntry &entry : addresses) {
|
||||
ip = entry.ip();
|
||||
ipString = ip.toString();
|
||||
protocol = ip.protocol();
|
||||
@@ -2578,7 +2578,7 @@ void Session::configureListeningInterface()
|
||||
libt::error_code ec;
|
||||
const QStringList IPs = getListeningIPs();
|
||||
|
||||
foreach (const QString ip, IPs) {
|
||||
for (const QString ip : IPs) {
|
||||
if (ip.isEmpty()) {
|
||||
logger->addMessage(tr("qBittorrent is trying to listen on any interface port: %1", "e.g: qBittorrent is trying to listen on any interface port: TCP/6881").arg(QString::number(port)), Log::INFO);
|
||||
m_nativeSession->listen_on(ports, ec, 0, libt::session::listen_no_system_port);
|
||||
@@ -3776,7 +3776,7 @@ void Session::handleTorrentTrackerWarning(TorrentHandle *const torrent, const QS
|
||||
|
||||
bool Session::hasPerTorrentRatioLimit() const
|
||||
{
|
||||
foreach (TorrentHandle *const torrent, m_torrents)
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
if (torrent->ratioLimit() >= 0) return true;
|
||||
|
||||
return false;
|
||||
@@ -3784,7 +3784,7 @@ bool Session::hasPerTorrentRatioLimit() const
|
||||
|
||||
bool Session::hasPerTorrentSeedingTimeLimit() const
|
||||
{
|
||||
foreach (TorrentHandle *const torrent, m_torrents)
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
if (torrent->seedingTimeLimit() >= 0) return true;
|
||||
|
||||
return false;
|
||||
@@ -3928,7 +3928,7 @@ void Session::startUpTorrents()
|
||||
QMap<int, TorrentResumeData> queuedResumeData;
|
||||
int nextQueuePosition = 1;
|
||||
int numOfRemappedFiles = 0;
|
||||
foreach (const QString &fastresumeName, fastresumes) {
|
||||
for (const QString &fastresumeName : qAsConst(fastresumes)) {
|
||||
const QRegularExpressionMatch rxMatch = rx.match(fastresumeName);
|
||||
if (!rxMatch.hasMatch()) continue;
|
||||
|
||||
@@ -3967,7 +3967,7 @@ void Session::startUpTorrents()
|
||||
}
|
||||
|
||||
// starting up downloading torrents (queue position > 0)
|
||||
foreach (const TorrentResumeData &torrentResumeData, queuedResumeData)
|
||||
for (const TorrentResumeData &torrentResumeData : qAsConst(queuedResumeData))
|
||||
startupTorrent(torrentResumeData);
|
||||
|
||||
return;
|
||||
@@ -4547,14 +4547,14 @@ void Session::handleStateUpdateAlert(libt::state_update_alert *p)
|
||||
updateStats();
|
||||
#endif
|
||||
|
||||
foreach (const libt::torrent_status &status, p->status) {
|
||||
for (const libt::torrent_status &status : p->status) {
|
||||
TorrentHandle *const torrent = m_torrents.value(status.info_hash);
|
||||
if (torrent)
|
||||
torrent->handleStateUpdate(status);
|
||||
}
|
||||
|
||||
m_torrentStatusReport = TorrentStatusReport();
|
||||
foreach (TorrentHandle *const torrent, m_torrents) {
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents)) {
|
||||
if (torrent->isDownloading())
|
||||
++m_torrentStatusReport.nbDownloading;
|
||||
if (torrent->isUploading())
|
||||
|
||||
@@ -141,14 +141,14 @@ void TorrentCreatorThread::run()
|
||||
#endif
|
||||
|
||||
// Add url seeds
|
||||
foreach (QString seed, m_params.urlSeeds) {
|
||||
for (QString seed : qAsConst(m_params.urlSeeds)) {
|
||||
seed = seed.trimmed();
|
||||
if (!seed.isEmpty())
|
||||
newTorrent.add_url_seed(seed.toStdString());
|
||||
}
|
||||
|
||||
int tier = 0;
|
||||
foreach (const QString &tracker, m_params.trackers) {
|
||||
for (const QString &tracker : qAsConst(m_params.trackers)) {
|
||||
if (tracker.isEmpty())
|
||||
++tier;
|
||||
else
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "base/global.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/profile.h"
|
||||
@@ -77,7 +78,7 @@ namespace
|
||||
ListType setToEntryList(const QSet<QString> &input)
|
||||
{
|
||||
ListType entryList;
|
||||
foreach (const QString &setValue, input)
|
||||
for (const QString &setValue : input)
|
||||
entryList.emplace_back(setValue.toStdString());
|
||||
return entryList;
|
||||
}
|
||||
@@ -374,10 +375,9 @@ QString TorrentHandle::nativeActualSavePath() const
|
||||
QList<TrackerEntry> TorrentHandle::trackers() const
|
||||
{
|
||||
QList<TrackerEntry> entries;
|
||||
std::vector<libt::announce_entry> announces;
|
||||
const std::vector<libt::announce_entry> announces = m_nativeHandle.trackers();
|
||||
|
||||
announces = m_nativeHandle.trackers();
|
||||
foreach (const libt::announce_entry &tracker, announces)
|
||||
for (const libt::announce_entry &tracker : announces)
|
||||
entries << tracker;
|
||||
|
||||
return entries;
|
||||
@@ -391,7 +391,7 @@ QHash<QString, TrackerInfo> TorrentHandle::trackerInfos() const
|
||||
void TorrentHandle::addTrackers(const QList<TrackerEntry> &trackers)
|
||||
{
|
||||
QList<TrackerEntry> addedTrackers;
|
||||
foreach (const TrackerEntry &tracker, trackers) {
|
||||
for (const TrackerEntry &tracker : trackers) {
|
||||
if (addTracker(tracker))
|
||||
addedTrackers << tracker;
|
||||
}
|
||||
@@ -400,13 +400,13 @@ void TorrentHandle::addTrackers(const QList<TrackerEntry> &trackers)
|
||||
m_session->handleTorrentTrackersAdded(this, addedTrackers);
|
||||
}
|
||||
|
||||
void TorrentHandle::replaceTrackers(QList<TrackerEntry> trackers)
|
||||
void TorrentHandle::replaceTrackers(const QList<TrackerEntry> &trackers)
|
||||
{
|
||||
QList<TrackerEntry> existingTrackers = this->trackers();
|
||||
QList<TrackerEntry> addedTrackers;
|
||||
|
||||
std::vector<libt::announce_entry> announces;
|
||||
foreach (const TrackerEntry &tracker, trackers) {
|
||||
for (const TrackerEntry &tracker : trackers) {
|
||||
announces.push_back(tracker.nativeEntry());
|
||||
if (!existingTrackers.contains(tracker))
|
||||
addedTrackers << tracker;
|
||||
@@ -438,9 +438,9 @@ bool TorrentHandle::addTracker(const TrackerEntry &tracker)
|
||||
QList<QUrl> TorrentHandle::urlSeeds() const
|
||||
{
|
||||
QList<QUrl> urlSeeds;
|
||||
std::set<std::string> seeds = m_nativeHandle.url_seeds();
|
||||
const std::set<std::string> seeds = m_nativeHandle.url_seeds();
|
||||
|
||||
foreach (const std::string &urlSeed, seeds)
|
||||
for (const std::string &urlSeed : seeds)
|
||||
urlSeeds.append(QUrl(urlSeed.c_str()));
|
||||
|
||||
return urlSeeds;
|
||||
@@ -449,7 +449,7 @@ QList<QUrl> TorrentHandle::urlSeeds() const
|
||||
void TorrentHandle::addUrlSeeds(const QList<QUrl> &urlSeeds)
|
||||
{
|
||||
QList<QUrl> addedUrlSeeds;
|
||||
foreach (const QUrl &urlSeed, urlSeeds) {
|
||||
for (const QUrl &urlSeed : urlSeeds) {
|
||||
if (addUrlSeed(urlSeed))
|
||||
addedUrlSeeds << urlSeed;
|
||||
}
|
||||
@@ -461,7 +461,7 @@ void TorrentHandle::addUrlSeeds(const QList<QUrl> &urlSeeds)
|
||||
void TorrentHandle::removeUrlSeeds(const QList<QUrl> &urlSeeds)
|
||||
{
|
||||
QList<QUrl> removedUrlSeeds;
|
||||
foreach (const QUrl &urlSeed, urlSeeds) {
|
||||
for (const QUrl &urlSeed : urlSeeds) {
|
||||
if (removeUrlSeed(urlSeed))
|
||||
removedUrlSeeds << urlSeed;
|
||||
}
|
||||
@@ -596,8 +596,7 @@ bool TorrentHandle::removeTag(const QString &tag)
|
||||
|
||||
void TorrentHandle::removeAllTags()
|
||||
{
|
||||
// QT automatically copies the container in foreach, so it's safe to mutate it.
|
||||
foreach (const QString &tag, m_tags)
|
||||
for (const QString &tag : copyAsConst(tags()))
|
||||
removeTag(tag);
|
||||
}
|
||||
|
||||
@@ -883,9 +882,9 @@ bool TorrentHandle::hasError() const
|
||||
|
||||
bool TorrentHandle::hasFilteredPieces() const
|
||||
{
|
||||
std::vector<int> pp = m_nativeHandle.piece_priorities();
|
||||
const std::vector<int> pp = m_nativeHandle.piece_priorities();
|
||||
|
||||
foreach (const int priority, pp)
|
||||
for (const int priority : pp)
|
||||
if (priority == 0) return true;
|
||||
|
||||
return false;
|
||||
@@ -1087,7 +1086,7 @@ QList<PeerInfo> TorrentHandle::peers() const
|
||||
|
||||
m_nativeHandle.get_peer_info(nativePeers);
|
||||
|
||||
foreach (const libt::peer_info &peer, nativePeers)
|
||||
for (const libt::peer_info &peer : nativePeers)
|
||||
peers << PeerInfo(this, peer);
|
||||
|
||||
return peers;
|
||||
|
||||
@@ -356,7 +356,7 @@ namespace BitTorrent
|
||||
void setSuperSeeding(bool enable);
|
||||
void flushCache();
|
||||
void addTrackers(const QList<TrackerEntry> &trackers);
|
||||
void replaceTrackers(QList<TrackerEntry> trackers);
|
||||
void replaceTrackers(const QList<TrackerEntry> &trackers);
|
||||
void addUrlSeeds(const QList<QUrl> &urlSeeds);
|
||||
void removeUrlSeeds(const QList<QUrl> &urlSeeds);
|
||||
bool connectPeer(const PeerAddress &peerAddress);
|
||||
|
||||
@@ -247,7 +247,7 @@ QList<TrackerEntry> TorrentInfo::trackers() const
|
||||
if (!isValid()) return QList<TrackerEntry>();
|
||||
|
||||
QList<TrackerEntry> trackers;
|
||||
foreach (const libt::announce_entry &tracker, m_nativeInfo->trackers())
|
||||
for (const libt::announce_entry &tracker : m_nativeInfo->trackers())
|
||||
trackers.append(tracker);
|
||||
|
||||
return trackers;
|
||||
@@ -258,7 +258,7 @@ QList<QUrl> TorrentInfo::urlSeeds() const
|
||||
if (!isValid()) return QList<QUrl>();
|
||||
|
||||
QList<QUrl> urlSeeds;
|
||||
foreach (const libt::web_seed_entry &webSeed, m_nativeInfo->web_seeds())
|
||||
for (const libt::web_seed_entry &webSeed : m_nativeInfo->web_seeds())
|
||||
if (webSeed.type == libt::web_seed_entry::url_seed)
|
||||
urlSeeds.append(QUrl(webSeed.url.c_str()));
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ bool Connection::acceptsGzipEncoding(QString codings)
|
||||
|
||||
const auto isCodingAvailable = [](const QStringList &list, const QString &encoding) -> bool
|
||||
{
|
||||
foreach (const QString &str, list) {
|
||||
for (const QString &str : list) {
|
||||
if (!str.startsWith(encoding))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -146,9 +146,9 @@ QList<QSslCipher> Server::safeCipherList() const
|
||||
const QStringList badCiphers = {"idea", "rc4"};
|
||||
const QList<QSslCipher> allCiphers = QSslSocket::supportedCiphers();
|
||||
QList<QSslCipher> safeCiphers;
|
||||
foreach (const QSslCipher &cipher, allCiphers) {
|
||||
for (const QSslCipher &cipher : allCiphers) {
|
||||
bool isSafe = true;
|
||||
foreach (const QString &badCipher, badCiphers) {
|
||||
for (const QString &badCipher : badCiphers) {
|
||||
if (cipher.name().contains(badCipher, Qt::CaseInsensitive)) {
|
||||
isSafe = false;
|
||||
break;
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <QSslError>
|
||||
#include <QUrl>
|
||||
|
||||
#include "base/global.h"
|
||||
#include "base/preferences.h"
|
||||
#include "downloadhandler.h"
|
||||
#include "proxyconfigurationmanager.h"
|
||||
@@ -56,7 +57,7 @@ namespace
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QList<QNetworkCookie> cookies = Preferences::instance()->getNetworkCookies();
|
||||
foreach (const QNetworkCookie &cookie, Preferences::instance()->getNetworkCookies()) {
|
||||
for (const QNetworkCookie &cookie : copyAsConst(Preferences::instance()->getNetworkCookies())) {
|
||||
if (cookie.isSessionCookie() || (cookie.expirationDate() <= now))
|
||||
cookies.removeAll(cookie);
|
||||
}
|
||||
@@ -68,7 +69,7 @@ namespace
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QList<QNetworkCookie> cookies = allCookies();
|
||||
foreach (const QNetworkCookie &cookie, allCookies()) {
|
||||
for (const QNetworkCookie &cookie : copyAsConst(allCookies())) {
|
||||
if (cookie.isSessionCookie() || (cookie.expirationDate() <= now))
|
||||
cookies.removeAll(cookie);
|
||||
}
|
||||
@@ -83,7 +84,7 @@ namespace
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QList<QNetworkCookie> cookies = QNetworkCookieJar::cookiesForUrl(url);
|
||||
foreach (const QNetworkCookie &cookie, QNetworkCookieJar::cookiesForUrl(url)) {
|
||||
for (const QNetworkCookie &cookie : copyAsConst(QNetworkCookieJar::cookiesForUrl(url))) {
|
||||
if (!cookie.isSessionCookie() && (cookie.expirationDate() <= now))
|
||||
cookies.removeAll(cookie);
|
||||
}
|
||||
@@ -95,7 +96,7 @@ namespace
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QList<QNetworkCookie> cookies = cookieList;
|
||||
foreach (const QNetworkCookie &cookie, cookieList) {
|
||||
for (const QNetworkCookie &cookie : cookieList) {
|
||||
if (!cookie.isSessionCookie() && (cookie.expirationDate() <= now))
|
||||
cookies.removeAll(cookie);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <QTcpSocket>
|
||||
#endif
|
||||
|
||||
#include "base/global.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/preferences.h"
|
||||
|
||||
@@ -291,7 +292,7 @@ QByteArray Smtp::encodeMimeHeader(const QString &key, const QString &value, QTex
|
||||
if (!prefix.isEmpty()) line += prefix;
|
||||
if (!value.contains("=?") && latin1->canEncode(value)) {
|
||||
bool firstWord = true;
|
||||
foreach (const QByteArray &word, value.toLatin1().split(' ')) {
|
||||
for (const QByteArray &word : copyAsConst(value.toLatin1().split(' '))) {
|
||||
if (line.size() > 78) {
|
||||
rv = rv + line + "\r\n";
|
||||
line.clear();
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#endif
|
||||
|
||||
#include "global.h"
|
||||
#include "logger.h"
|
||||
#include "settingsstorage.h"
|
||||
#include "utils/fs.h"
|
||||
@@ -505,7 +506,7 @@ void Preferences::setWebUiAuthSubnetWhitelistEnabled(bool enabled)
|
||||
QList<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
|
||||
{
|
||||
QList<Utils::Net::Subnet> subnets;
|
||||
foreach (const QString &rawSubnet, value("Preferences/WebUI/AuthSubnetWhitelist").toStringList()) {
|
||||
for (const QString &rawSubnet : copyAsConst(value("Preferences/WebUI/AuthSubnetWhitelist").toStringList())) {
|
||||
bool ok = false;
|
||||
const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(rawSubnet.trimmed(), &ok);
|
||||
if (ok)
|
||||
@@ -1426,8 +1427,8 @@ void Preferences::setToolbarTextPosition(const int position)
|
||||
QList<QNetworkCookie> Preferences::getNetworkCookies() const
|
||||
{
|
||||
QList<QNetworkCookie> cookies;
|
||||
QStringList rawCookies = value("Network/Cookies").toStringList();
|
||||
foreach (const QString &rawCookie, rawCookies)
|
||||
const QStringList rawCookies = value("Network/Cookies").toStringList();
|
||||
for (const QString &rawCookie : rawCookies)
|
||||
cookies << QNetworkCookie::parseCookies(rawCookie.toUtf8());
|
||||
|
||||
return cookies;
|
||||
@@ -1436,7 +1437,7 @@ QList<QNetworkCookie> Preferences::getNetworkCookies() const
|
||||
void Preferences::setNetworkCookies(const QList<QNetworkCookie> &cookies)
|
||||
{
|
||||
QStringList rawCookies;
|
||||
foreach (const QNetworkCookie &cookie, cookies)
|
||||
for (const QNetworkCookie &cookie : cookies)
|
||||
rawCookies << cookie.toRawForm();
|
||||
|
||||
setValue("Network/Cookies", rawCookies);
|
||||
@@ -1477,10 +1478,10 @@ void Preferences::upgrade()
|
||||
{
|
||||
SettingsStorage *settingsStorage = SettingsStorage::instance();
|
||||
|
||||
QStringList labels = value("TransferListFilters/customLabels").toStringList();
|
||||
const QStringList labels = value("TransferListFilters/customLabels").toStringList();
|
||||
if (!labels.isEmpty()) {
|
||||
QVariantMap categories = value("BitTorrent/Session/Categories").toMap();
|
||||
foreach (const QString &label, labels) {
|
||||
for (const QString &label : labels) {
|
||||
if (!categories.contains(label))
|
||||
categories[label] = "";
|
||||
}
|
||||
|
||||
@@ -435,8 +435,8 @@ void AutoDownloader::loadRules(const QByteArray &data)
|
||||
void AutoDownloader::loadRulesLegacy()
|
||||
{
|
||||
SettingsPtr settings = Profile::instance().applicationSettings(QStringLiteral("qBittorrent-rss"));
|
||||
QVariantHash rules = settings->value(QStringLiteral("download_rules")).toHash();
|
||||
foreach (const QVariant &ruleVar, rules) {
|
||||
const QVariantHash rules = settings->value(QStringLiteral("download_rules")).toHash();
|
||||
for (const QVariant &ruleVar : rules) {
|
||||
auto rule = AutoDownloadRule::fromLegacyDict(ruleVar.toHash());
|
||||
if (!rule.name().isEmpty())
|
||||
insertRule(rule);
|
||||
@@ -451,7 +451,7 @@ void AutoDownloader::store()
|
||||
m_savingTimer.stop();
|
||||
|
||||
QJsonObject jsonObj;
|
||||
foreach (auto rule, m_rules)
|
||||
for (const auto &rule : qAsConst(m_rules))
|
||||
jsonObj.insert(rule.name(), rule.toJsonObject());
|
||||
|
||||
m_fileStorage->store(RulesFileName, QJsonDocument(jsonObj).toJson());
|
||||
@@ -473,7 +473,7 @@ void AutoDownloader::resetProcessingQueue()
|
||||
m_processingQueue.clear();
|
||||
if (!m_processingEnabled) return;
|
||||
|
||||
foreach (Article *article, Session::instance()->rootFolder()->articles()) {
|
||||
for (Article *article : copyAsConst(Session::instance()->rootFolder()->articles())) {
|
||||
if (!article->isRead() && !article->torrentUrl().isEmpty())
|
||||
addJobForArticle(article);
|
||||
}
|
||||
|
||||
@@ -442,7 +442,7 @@ AutoDownloadRule AutoDownloadRule::fromJsonObject(const QJsonObject &jsonObj, co
|
||||
QStringList feedURLs;
|
||||
if (feedsVal.isString())
|
||||
feedURLs << feedsVal.toString();
|
||||
else foreach (const QJsonValue &urlVal, feedsVal.toArray())
|
||||
else for (const QJsonValue &urlVal : copyAsConst(feedsVal.toArray()))
|
||||
feedURLs << urlVal.toString();
|
||||
rule.setFeedURLs(feedURLs);
|
||||
|
||||
@@ -452,7 +452,7 @@ AutoDownloadRule AutoDownloadRule::fromJsonObject(const QJsonObject &jsonObj, co
|
||||
previouslyMatched << previouslyMatchedVal.toString();
|
||||
}
|
||||
else {
|
||||
foreach (const QJsonValue &val, previouslyMatchedVal.toArray())
|
||||
for (const QJsonValue &val : copyAsConst(previouslyMatchedVal.toArray()))
|
||||
previouslyMatched << val.toString();
|
||||
}
|
||||
rule.setPreviouslyMatchedEpisodes(previouslyMatched);
|
||||
|
||||
@@ -109,7 +109,7 @@ QList<Article *> Feed::articles() const
|
||||
void Feed::markAsRead()
|
||||
{
|
||||
auto oldUnreadCount = m_unreadCount;
|
||||
foreach (Article *article, m_articles) {
|
||||
for (Article *article : qAsConst(m_articles)) {
|
||||
if (!article->isRead()) {
|
||||
article->disconnect(this);
|
||||
article->markAsRead();
|
||||
@@ -282,9 +282,9 @@ void Feed::loadArticles(const QByteArray &data)
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonArray jsonArr = jsonDoc.array();
|
||||
const QJsonArray jsonArr = jsonDoc.array();
|
||||
int i = -1;
|
||||
foreach (const QJsonValue &jsonVal, jsonArr) {
|
||||
for (const QJsonValue &jsonVal : jsonArr) {
|
||||
++i;
|
||||
if (!jsonVal.isObject()) {
|
||||
LogMsg(tr("Couldn't load RSS article '%1#%2'. Invalid data format.").arg(m_url).arg(i)
|
||||
@@ -304,9 +304,9 @@ void Feed::loadArticles(const QByteArray &data)
|
||||
void Feed::loadArticlesLegacy()
|
||||
{
|
||||
SettingsPtr qBTRSSFeeds = Profile::instance().applicationSettings(QStringLiteral("qBittorrent-rss-feeds"));
|
||||
QVariantHash allOldItems = qBTRSSFeeds->value("old_items").toHash();
|
||||
const QVariantHash allOldItems = qBTRSSFeeds->value("old_items").toHash();
|
||||
|
||||
foreach (const QVariant &var, allOldItems.value(m_url).toList()) {
|
||||
for (const QVariant &var : copyAsConst(allOldItems.value(m_url).toList())) {
|
||||
auto hash = var.toHash();
|
||||
// update legacy keys
|
||||
hash[Article::KeyLink] = hash.take(QLatin1String("news_link"));
|
||||
@@ -329,7 +329,7 @@ void Feed::store()
|
||||
m_savingTimer.stop();
|
||||
|
||||
QJsonArray jsonArr;
|
||||
foreach (Article *article, m_articles)
|
||||
for (Article *article :qAsConst(m_articles))
|
||||
jsonArr << article->toJsonObject();
|
||||
|
||||
m_session->dataFileStorage()->store(m_dataFileName, QJsonDocument(jsonArr).toJson());
|
||||
|
||||
@@ -47,7 +47,7 @@ Folder::~Folder()
|
||||
{
|
||||
emit aboutToBeDestroyed(this);
|
||||
|
||||
foreach (auto item, items())
|
||||
for (auto item : copyAsConst(items()))
|
||||
delete item;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ QList<Article *> Folder::articles() const
|
||||
{
|
||||
QList<Article *> news;
|
||||
|
||||
foreach (Item *item, items()) {
|
||||
for (Item *item : copyAsConst(items())) {
|
||||
int n = news.size();
|
||||
news << item->articles();
|
||||
std::inplace_merge(news.begin(), news.begin() + n, news.end()
|
||||
@@ -70,20 +70,20 @@ QList<Article *> Folder::articles() const
|
||||
int Folder::unreadCount() const
|
||||
{
|
||||
int count = 0;
|
||||
foreach (Item *item, items())
|
||||
for (Item *item : copyAsConst(items()))
|
||||
count += item->unreadCount();
|
||||
return count;
|
||||
}
|
||||
|
||||
void Folder::markAsRead()
|
||||
{
|
||||
foreach (Item *item, items())
|
||||
for (Item *item : copyAsConst(items()))
|
||||
item->markAsRead();
|
||||
}
|
||||
|
||||
void Folder::refresh()
|
||||
{
|
||||
foreach (Item *item, items())
|
||||
for (Item *item : copyAsConst(items()))
|
||||
item->refresh();
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ QList<Item *> Folder::items() const
|
||||
QJsonValue Folder::toJsonValue(bool withData) const
|
||||
{
|
||||
QJsonObject jsonObj;
|
||||
foreach (Item *item, items())
|
||||
for (Item *item : copyAsConst(items()))
|
||||
jsonObj.insert(item->name(), item->toJsonValue(withData));
|
||||
|
||||
return jsonObj;
|
||||
@@ -108,7 +108,7 @@ void Folder::handleItemUnreadCountChanged()
|
||||
|
||||
void Folder::cleanup()
|
||||
{
|
||||
foreach (Item *item, items())
|
||||
for (Item *item : copyAsConst(items()))
|
||||
item->cleanup();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <QVariantHash>
|
||||
|
||||
#include "../asyncfilestorage.h"
|
||||
#include "../global.h"
|
||||
#include "../logger.h"
|
||||
#include "../profile.h"
|
||||
#include "../settingsstorage.h"
|
||||
@@ -283,7 +284,7 @@ void Session::load()
|
||||
void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder)
|
||||
{
|
||||
bool updated = false;
|
||||
foreach (const QString &key, jsonObj.keys()) {
|
||||
for (const QString &key : copyAsConst(jsonObj.keys())) {
|
||||
const QJsonValue val {jsonObj[key]};
|
||||
if (val.isString()) {
|
||||
// previous format (reduced form) doesn't contain UID
|
||||
@@ -355,7 +356,7 @@ void Session::loadLegacy()
|
||||
const QString parentFolderPath = Item::parentPath(legacyPath);
|
||||
const QString feedUrl = Item::relativeName(legacyPath);
|
||||
|
||||
foreach (const QString &folderPath, Item::expandPath(parentFolderPath))
|
||||
for (const QString &folderPath : copyAsConst(Item::expandPath(parentFolderPath)))
|
||||
addFolder(folderPath);
|
||||
|
||||
const QString feedPath = feedAliases[i].isEmpty()
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include "bittorrent/session.h"
|
||||
#include "filesystemwatcher.h"
|
||||
#include "global.h"
|
||||
#include "preferences.h"
|
||||
#include "utils/fs.h"
|
||||
|
||||
@@ -254,7 +255,7 @@ void ScanFoldersModel::addToFSWatcher(const QStringList &watchPaths)
|
||||
if (!m_fsWatcher)
|
||||
return; // addPath() wasn't called before this
|
||||
|
||||
foreach (const QString &path, watchPaths) {
|
||||
for (const QString &path : watchPaths) {
|
||||
QDir watchDir(path);
|
||||
const QString canonicalWatchPath = watchDir.canonicalPath();
|
||||
m_fsWatcher->addPath(canonicalWatchPath);
|
||||
@@ -282,7 +283,7 @@ bool ScanFoldersModel::removePath(const QString &path, bool removeFromFSWatcher)
|
||||
|
||||
void ScanFoldersModel::removeFromFSWatcher(const QStringList &watchPaths)
|
||||
{
|
||||
foreach (const QString &path, watchPaths)
|
||||
for (const QString &path : watchPaths)
|
||||
m_fsWatcher->removePath(path);
|
||||
}
|
||||
|
||||
@@ -326,7 +327,7 @@ void ScanFoldersModel::makePersistent()
|
||||
{
|
||||
QVariantHash dirs;
|
||||
|
||||
foreach (const PathData *pathData, m_pathList) {
|
||||
for (const PathData *pathData : qAsConst(m_pathList)) {
|
||||
if (pathData->downloadType == CUSTOM_LOCATION)
|
||||
dirs.insert(Utils::Fs::fromNativePath(pathData->watchPath), Utils::Fs::fromNativePath(pathData->downloadPath));
|
||||
else
|
||||
@@ -350,7 +351,7 @@ void ScanFoldersModel::configure()
|
||||
|
||||
void ScanFoldersModel::addTorrentsToSession(const QStringList &pathList)
|
||||
{
|
||||
foreach (const QString &file, pathList) {
|
||||
for (const QString &file : pathList) {
|
||||
qDebug("File %s added", qUtf8Printable(file));
|
||||
|
||||
BitTorrent::AddTorrentParams params;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <QProcess>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../global.h"
|
||||
#include "../utils/foreignapps.h"
|
||||
#include "../utils/fs.h"
|
||||
#include "searchpluginmanager.h"
|
||||
@@ -138,7 +139,7 @@ void SearchHandler::readSearchOutput()
|
||||
m_searchResultLineTruncated = lines.takeLast().trimmed();
|
||||
|
||||
QList<SearchResult> searchResultList;
|
||||
foreach (const QByteArray &line, lines) {
|
||||
for (const QByteArray &line : qAsConst(lines)) {
|
||||
SearchResult searchResult;
|
||||
if (parseSearchResult(QString::fromUtf8(line), searchResult))
|
||||
searchResultList << searchResult;
|
||||
|
||||
@@ -133,7 +133,7 @@ QStringList SearchPluginManager::supportedCategories() const
|
||||
QStringList result;
|
||||
for (const PluginInfo *plugin : qAsConst(m_plugins)) {
|
||||
if (plugin->enabled) {
|
||||
foreach (QString cat, plugin->supportedCategories) {
|
||||
for (const QString &cat : plugin->supportedCategories) {
|
||||
if (!result.contains(cat))
|
||||
result << cat;
|
||||
}
|
||||
@@ -277,9 +277,8 @@ bool SearchPluginManager::uninstallPlugin(const QString &name)
|
||||
QDir pluginsFolder(pluginsLocation());
|
||||
QStringList filters;
|
||||
filters << name + ".*";
|
||||
QStringList files = pluginsFolder.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
QString file;
|
||||
foreach (file, files)
|
||||
const QStringList files = pluginsFolder.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
for (const QString &file : files)
|
||||
Utils::Fs::forceRemove(pluginsFolder.absoluteFilePath(file));
|
||||
// Remove it from supported engines
|
||||
delete m_plugins.take(name);
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <QFile>
|
||||
#include <QHash>
|
||||
|
||||
#include "global.h"
|
||||
#include "logger.h"
|
||||
#include "profile.h"
|
||||
#include "utils/fs.h"
|
||||
@@ -286,7 +287,7 @@ QString TransactionalSettings::deserialize(const QString &name, QVariantHash &da
|
||||
// Copy everything into memory. This means even keys inserted in the file manually
|
||||
// or that we don't touch directly in this code (eg disabled by ifdef). This ensures
|
||||
// that they will be copied over when save our settings to disk.
|
||||
foreach (const QString &key, settings->allKeys())
|
||||
for (const QString &key : copyAsConst(settings->allKeys()))
|
||||
data.insert(key, settings->value(key));
|
||||
|
||||
return settings->fileName();
|
||||
|
||||
@@ -141,7 +141,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const QString &path)
|
||||
|
||||
// remove temp files on linux (file ends with '~'), e.g. `filename~`
|
||||
QDir dir(p);
|
||||
QStringList tmpFileList = dir.entryList(QDir::Files);
|
||||
const QStringList tmpFileList = dir.entryList(QDir::Files);
|
||||
for (const QString &f : tmpFileList) {
|
||||
if (f.endsWith('~'))
|
||||
forceRemove(p + f);
|
||||
|
||||
@@ -391,7 +391,7 @@ QString Utils::Misc::getUserIDString()
|
||||
QStringList Utils::Misc::toStringList(const QList<bool> &l)
|
||||
{
|
||||
QStringList ret;
|
||||
foreach (const bool &b, l)
|
||||
for (const bool b : l)
|
||||
ret << (b ? "1" : "0");
|
||||
return ret;
|
||||
}
|
||||
@@ -399,7 +399,7 @@ QStringList Utils::Misc::toStringList(const QList<bool> &l)
|
||||
QList<int> Utils::Misc::intListfromStringList(const QStringList &l)
|
||||
{
|
||||
QList<int> ret;
|
||||
foreach (const QString &s, l)
|
||||
for (const QString &s : l)
|
||||
ret << s.toInt();
|
||||
return ret;
|
||||
}
|
||||
@@ -407,7 +407,7 @@ QList<int> Utils::Misc::intListfromStringList(const QStringList &l)
|
||||
QList<bool> Utils::Misc::boolListfromStringList(const QStringList &l)
|
||||
{
|
||||
QList<bool> ret;
|
||||
foreach (const QString &s, l)
|
||||
for (const QString &s : l)
|
||||
ret << (s == "1");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Utils
|
||||
{
|
||||
if (str.length() < 2) return str;
|
||||
|
||||
for (auto const quote : quotes) {
|
||||
for (const auto "e : quotes) {
|
||||
if (str.startsWith(quote) && str.endsWith(quote))
|
||||
return str.mid(1, str.length() - 2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user