mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-17 22:18:05 -06:00
Utilize algorithms from std::ranges
The result is shorter code and improves readability. Note that `asConst()` is still required for non-const containers, otherwise the container will detach. PR #23342.
This commit is contained in:
@@ -87,7 +87,7 @@ namespace
|
||||
void normalExitHandler(const int signum)
|
||||
{
|
||||
const char *msgs[] = {"Catching signal: ", sysSigName[signum], "\nExiting cleanly\n"};
|
||||
std::for_each(std::begin(msgs), std::end(msgs), safePrint);
|
||||
std::ranges::for_each(msgs, safePrint);
|
||||
signal(signum, SIG_DFL);
|
||||
QMetaObject::invokeMethod(qApp, [] { QCoreApplication::exit(); }, Qt::QueuedConnection); // unsafe, but exit anyway
|
||||
}
|
||||
@@ -103,7 +103,7 @@ namespace
|
||||
const std::string stacktrace = getStacktrace();
|
||||
|
||||
const char *msgs[] = {msg, sigName, "\n```\n", stacktrace.c_str(), "```\n\n"};
|
||||
std::for_each(std::begin(msgs), std::end(msgs), safePrint);
|
||||
std::ranges::for_each(msgs, safePrint);
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
StacktraceDialog dlg; // unsafe
|
||||
|
||||
@@ -2495,7 +2495,7 @@ bool SessionImpl::removeTorrent(const TorrentID &id, const TorrentRemoveOption d
|
||||
m_removingTorrents[torrentID] = {torrentName, torrent->actualStorageLocation(), {}, deleteOption};
|
||||
|
||||
const lt::torrent_handle nativeHandle {torrent->nativeHandle()};
|
||||
const auto iter = std::find_if(m_moveStorageQueue.cbegin(), m_moveStorageQueue.cend()
|
||||
const auto iter = std::ranges::find_if(asConst(m_moveStorageQueue)
|
||||
, [&nativeHandle](const MoveStorageJob &job)
|
||||
{
|
||||
return job.torrentHandle == nativeHandle;
|
||||
@@ -2520,7 +2520,7 @@ bool SessionImpl::removeTorrent(const TorrentID &id, const TorrentRemoveOption d
|
||||
{
|
||||
// Delete "move storage job" for the deleted torrent
|
||||
// (note: we shouldn't delete active job)
|
||||
const auto iter = std::find_if((m_moveStorageQueue.cbegin() + 1), m_moveStorageQueue.cend()
|
||||
const auto iter = std::ranges::find_if(std::views::drop(asConst(m_moveStorageQueue), 1)
|
||||
, [torrent](const MoveStorageJob &job)
|
||||
{
|
||||
return job.torrentHandle == torrent->nativeHandle();
|
||||
@@ -2581,7 +2581,7 @@ void SessionImpl::decreaseTorrentsQueuePos(const QList<TorrentID> &ids)
|
||||
const QList<TorrentImpl *> queuedTorrents = getQueuedTorrentsByID(ids);
|
||||
|
||||
// Decrease torrents queue position (starting with the one in the lowest queue position)
|
||||
for (TorrentImpl *torrent : (queuedTorrents | std::views::reverse))
|
||||
for (const TorrentImpl *torrent : std::views::reverse(queuedTorrents))
|
||||
torrentQueuePositionDown(torrent->nativeHandle());
|
||||
|
||||
for (const lt::torrent_handle &torrentHandle : asConst(m_downloadedMetadata))
|
||||
@@ -2595,7 +2595,7 @@ void SessionImpl::topTorrentsQueuePos(const QList<TorrentID> &ids)
|
||||
const QList<TorrentImpl *> queuedTorrents = getQueuedTorrentsByID(ids);
|
||||
|
||||
// Top torrents queue position (starting with the one in the lowest queue position)
|
||||
for (TorrentImpl *torrent : (queuedTorrents | std::views::reverse))
|
||||
for (const TorrentImpl *torrent : std::views::reverse(queuedTorrents))
|
||||
torrentQueuePositionTop(torrent->nativeHandle());
|
||||
|
||||
m_torrentsQueueChanged = true;
|
||||
@@ -2857,7 +2857,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
|
||||
|
||||
if (isAddTrackersEnabled() && !(hasMetadata && p.ti->priv()))
|
||||
{
|
||||
const auto maxTierIter = std::max_element(p.tracker_tiers.cbegin(), p.tracker_tiers.cend());
|
||||
const auto maxTierIter = std::ranges::max_element(asConst(p.tracker_tiers));
|
||||
const int baseTier = (maxTierIter != p.tracker_tiers.cend()) ? (*maxTierIter + 1) : 0;
|
||||
|
||||
p.trackers.reserve(p.trackers.size() + static_cast<std::size_t>(m_additionalTrackerEntries.size()));
|
||||
@@ -2872,7 +2872,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
|
||||
|
||||
if (isAddTrackersFromURLEnabled() && !(hasMetadata && p.ti->priv()))
|
||||
{
|
||||
const auto maxTierIter = std::max_element(p.tracker_tiers.cbegin(), p.tracker_tiers.cend());
|
||||
const auto maxTierIter = std::ranges::max_element(asConst(p.tracker_tiers));
|
||||
const int baseTier = (maxTierIter != p.tracker_tiers.cend()) ? (*maxTierIter + 1) : 0;
|
||||
|
||||
p.trackers.reserve(p.trackers.size() + static_cast<std::size_t>(m_additionalTrackerEntriesFromURL.size()));
|
||||
@@ -3094,7 +3094,7 @@ bool SessionImpl::downloadMetadata(const TorrentDescriptor &torrentDescr)
|
||||
{
|
||||
// Use "additional trackers" when metadata retrieving (this can help when the DHT nodes are few)
|
||||
|
||||
const auto maxTierIter = std::max_element(p.tracker_tiers.cbegin(), p.tracker_tiers.cend());
|
||||
const auto maxTierIter = std::ranges::max_element(asConst(p.tracker_tiers));
|
||||
const int baseTier = (maxTierIter != p.tracker_tiers.cend()) ? (*maxTierIter + 1) : 0;
|
||||
|
||||
p.trackers.reserve(p.trackers.size() + static_cast<std::size_t>(m_additionalTrackerEntries.size()));
|
||||
@@ -4132,7 +4132,7 @@ void SessionImpl::applyFilenameFilter(const PathList &files, QList<DownloadPrior
|
||||
|
||||
const auto isFilenameExcluded = [patterns = m_excludedFileNamesRegExpList](const Path &fileName)
|
||||
{
|
||||
return std::any_of(patterns.begin(), patterns.end(), [&fileName](const QRegularExpression &re)
|
||||
return std::ranges::any_of(patterns, [&fileName](const QRegularExpression &re)
|
||||
{
|
||||
Path path = fileName;
|
||||
while (!re.match(path.filename()).hasMatch())
|
||||
@@ -5377,13 +5377,13 @@ bool SessionImpl::addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &new
|
||||
|
||||
if (m_moveStorageQueue.size() > 1)
|
||||
{
|
||||
auto iter = std::find_if((m_moveStorageQueue.cbegin() + 1), m_moveStorageQueue.cend()
|
||||
const auto iter = std::ranges::find_if(std::views::drop(asConst(m_moveStorageQueue), 1)
|
||||
, [&torrentHandle](const MoveStorageJob &job)
|
||||
{
|
||||
return job.torrentHandle == torrentHandle;
|
||||
});
|
||||
|
||||
if (iter != m_moveStorageQueue.end())
|
||||
if (iter != m_moveStorageQueue.cend())
|
||||
{
|
||||
// remove existing inactive job
|
||||
torrent->handleMoveStorageJobFinished(currentLocation, iter->context, torrentHasActiveJob);
|
||||
@@ -5453,7 +5453,7 @@ void SessionImpl::handleMoveTorrentStorageJobFinished(const Path &newPath)
|
||||
if (!m_moveStorageQueue.isEmpty())
|
||||
moveTorrentStorage(m_moveStorageQueue.constFirst());
|
||||
|
||||
const auto iter = std::find_if(m_moveStorageQueue.cbegin(), m_moveStorageQueue.cend()
|
||||
const auto iter = std::ranges::find_if(asConst(m_moveStorageQueue)
|
||||
, [&finishedJob](const MoveStorageJob &job)
|
||||
{
|
||||
return job.torrentHandle == finishedJob.torrentHandle;
|
||||
@@ -5495,7 +5495,7 @@ void SessionImpl::processPendingFinishedTorrents()
|
||||
|
||||
m_pendingFinishedTorrents.clear();
|
||||
|
||||
const bool hasUnfinishedTorrents = std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent)
|
||||
const bool hasUnfinishedTorrents = std::ranges::any_of(asConst(m_torrents), [](const TorrentImpl *torrent)
|
||||
{
|
||||
return !(torrent->isFinished() || torrent->isStopped() || torrent->isErrored());
|
||||
});
|
||||
@@ -5588,7 +5588,7 @@ void SessionImpl::loadCategories()
|
||||
|
||||
bool SessionImpl::hasPerTorrentRatioLimit() const
|
||||
{
|
||||
return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent)
|
||||
return std::ranges::any_of(asConst(m_torrents), [](const TorrentImpl *torrent)
|
||||
{
|
||||
return (torrent->ratioLimit() >= 0);
|
||||
});
|
||||
@@ -5596,7 +5596,7 @@ bool SessionImpl::hasPerTorrentRatioLimit() const
|
||||
|
||||
bool SessionImpl::hasPerTorrentSeedingTimeLimit() const
|
||||
{
|
||||
return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent)
|
||||
return std::ranges::any_of(asConst(m_torrents), [](const TorrentImpl *torrent)
|
||||
{
|
||||
return (torrent->seedingTimeLimit() >= 0);
|
||||
});
|
||||
@@ -5604,7 +5604,7 @@ bool SessionImpl::hasPerTorrentSeedingTimeLimit() const
|
||||
|
||||
bool SessionImpl::hasPerTorrentInactiveSeedingTimeLimit() const
|
||||
{
|
||||
return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent)
|
||||
return std::ranges::any_of(asConst(m_torrents), [](const TorrentImpl *torrent)
|
||||
{
|
||||
return (torrent->inactiveSeedingTimeLimit() >= 0);
|
||||
});
|
||||
|
||||
@@ -139,7 +139,7 @@ void TorrentCreator::run()
|
||||
const QString dirPath = dirInfo.filePath();
|
||||
dirs.append(dirPath);
|
||||
}
|
||||
std::sort(dirs.begin(), dirs.end(), naturalLessThan);
|
||||
std::ranges::sort(dirs, naturalLessThan);
|
||||
|
||||
QStringList fileNames;
|
||||
QHash<QString, qint64> fileSizeMap;
|
||||
@@ -173,7 +173,7 @@ void TorrentCreator::run()
|
||||
fileSizeMap[tmpNames.last()] = fileSize;
|
||||
}
|
||||
|
||||
std::sort(tmpNames.begin(), tmpNames.end(), naturalLessThan);
|
||||
std::ranges::sort(tmpNames, naturalLessThan);
|
||||
fileNames += tmpNames;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace
|
||||
// remove outdated endpoints
|
||||
trackerEntryStatus.endpoints.removeIf([&nativeEntry](const QHash<std::pair<QString, int>, TrackerEndpointStatus>::iterator &iter)
|
||||
{
|
||||
return std::none_of(nativeEntry.endpoints.cbegin(), nativeEntry.endpoints.cend()
|
||||
return std::ranges::none_of(nativeEntry.endpoints
|
||||
, [&endpointName = std::get<0>(iter.key())](const auto &existingEndpoint)
|
||||
{
|
||||
return (endpointName == toString(existingEndpoint.local_endpoint));
|
||||
@@ -676,7 +676,7 @@ void TorrentImpl::addTrackers(QList<TrackerEntry> trackers)
|
||||
m_nativeHandle.add_tracker(makeNativeAnnounceEntry(tracker.url, tracker.tier));
|
||||
m_trackerEntryStatuses.append({tracker.url, tracker.tier});
|
||||
}
|
||||
std::sort(m_trackerEntryStatuses.begin(), m_trackerEntryStatuses.end()
|
||||
std::ranges::sort(m_trackerEntryStatuses
|
||||
, [](const TrackerEntryStatus &left, const TrackerEntryStatus &right) { return left.tier < right.tier; });
|
||||
|
||||
deferredRequestResumeData();
|
||||
@@ -713,7 +713,7 @@ void TorrentImpl::replaceTrackers(QList<TrackerEntry> trackers)
|
||||
// Filter out duplicate trackers
|
||||
const auto uniqueTrackers = QSet<TrackerEntry>(trackers.cbegin(), trackers.cend());
|
||||
trackers = QList<TrackerEntry>(uniqueTrackers.cbegin(), uniqueTrackers.cend());
|
||||
std::sort(trackers.begin(), trackers.end()
|
||||
std::ranges::sort(trackers
|
||||
, [](const TrackerEntry &left, const TrackerEntry &right) { return left.tier < right.tier; });
|
||||
|
||||
std::vector<lt::announce_entry> nativeTrackers;
|
||||
@@ -1739,7 +1739,7 @@ void TorrentImpl::applyFirstLastPiecePriority(const bool enabled)
|
||||
|
||||
TrackerEntryStatus TorrentImpl::updateTrackerEntryStatus(const lt::announce_entry &announceEntry, const QHash<lt::tcp::endpoint, QMap<int, int>> &updateInfo)
|
||||
{
|
||||
const auto it = std::find_if(m_trackerEntryStatuses.begin(), m_trackerEntryStatuses.end()
|
||||
const auto it = std::ranges::find_if(m_trackerEntryStatuses
|
||||
, [&announceEntry](const TrackerEntryStatus &trackerEntryStatus)
|
||||
{
|
||||
return (trackerEntryStatus.url == QString::fromStdString(announceEntry.url));
|
||||
|
||||
@@ -197,8 +197,8 @@ PathList TorrentInfo::filesForPiece(const int pieceIndex) const
|
||||
|
||||
PathList res;
|
||||
res.reserve(fileIndices.size());
|
||||
std::transform(fileIndices.begin(), fileIndices.end(), std::back_inserter(res)
|
||||
, [this](int i) { return filePath(i); });
|
||||
for (const int i : fileIndices)
|
||||
res.push_back(filePath(i));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ bool RequestParser::parsePostMessage(const QByteArrayView data)
|
||||
const QByteArray endDelimiter = QByteArray("--") + delimiter + QByteArray("--") + CRLF;
|
||||
multipart.push_back(viewWithoutEndingWith(multipart.takeLast(), endDelimiter));
|
||||
|
||||
return std::all_of(multipart.cbegin(), multipart.cend(), [this](const QByteArrayView &part)
|
||||
return std::ranges::all_of(asConst(multipart), [this](const QByteArrayView &part)
|
||||
{
|
||||
return this->parseFormData(part);
|
||||
});
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace
|
||||
u"ECDHE-ECDSA-AES128-SHA"_s, u"ECDHE-RSA-AES128-SHA"_s, u"DHE-RSA-AES128-SHA"_s};
|
||||
const QList<QSslCipher> allCiphers {QSslConfiguration::supportedCiphers()};
|
||||
QList<QSslCipher> safeCiphers;
|
||||
std::copy_if(allCiphers.cbegin(), allCiphers.cend(), std::back_inserter(safeCiphers),
|
||||
std::ranges::copy_if(allCiphers, std::back_inserter(safeCiphers),
|
||||
[&badCiphers, &badRSAShorthandSuites, &badAESShorthandSuites](const QSslCipher &cipher)
|
||||
{
|
||||
const QString name = cipher.name();
|
||||
@@ -87,7 +87,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::none_of(badCiphers.cbegin(), badCiphers.cend(), [&cipher](const QString &badCipher)
|
||||
return std::ranges::none_of(badCiphers, [&cipher](const QString &badCipher)
|
||||
{
|
||||
return cipher.name().contains(badCipher, Qt::CaseInsensitive);
|
||||
});
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "logger.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QList>
|
||||
@@ -40,7 +41,7 @@ namespace
|
||||
{
|
||||
QList<T> ret;
|
||||
ret.reserve(static_cast<typename decltype(ret)::size_type>(src.size()) - offset);
|
||||
std::copy((src.begin() + offset), src.end(), std::back_inserter(ret));
|
||||
std::ranges::copy(std::views::drop(src, offset), std::back_inserter(ret));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ bool Net::DownloadManager::deleteCookie(const QNetworkCookie &cookie)
|
||||
bool Net::DownloadManager::hasSupportedScheme(const QString &url)
|
||||
{
|
||||
const QStringList schemes = QNetworkAccessManager().supportedSchemes();
|
||||
return std::any_of(schemes.cbegin(), schemes.cend(), [&url](const QString &scheme)
|
||||
return std::ranges::any_of(schemes, [&url](const QString &scheme)
|
||||
{
|
||||
return url.startsWith((scheme + u':'), Qt::CaseInsensitive);
|
||||
});
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace
|
||||
|
||||
bool canEncodeAsLatin1(const QStringView string)
|
||||
{
|
||||
return std::none_of(string.cbegin(), string.cend(), [](const QChar &ch)
|
||||
return std::ranges::none_of(string, [](const QChar &ch)
|
||||
{
|
||||
return ch > QChar(0xff);
|
||||
});
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace
|
||||
{
|
||||
QString cleanPath(const QString &path)
|
||||
{
|
||||
const bool hasSeparator = std::any_of(path.cbegin(), path.cend(), [](const QChar c)
|
||||
const bool hasSeparator = std::ranges::any_of(path, [](const QChar c)
|
||||
{
|
||||
return (c == u'/') || (c == u'\\');
|
||||
});
|
||||
|
||||
@@ -120,7 +120,7 @@ QList<QVariantHash> RSS::Private::FeedSerializer::loadArticles(const QByteArray
|
||||
result.push_back(varHash);
|
||||
}
|
||||
|
||||
std::sort(result.begin(), result.end(), [](const QVariantHash &left, const QVariantHash &right)
|
||||
std::ranges::sort(result, [](const QVariantHash &left, const QVariantHash &right)
|
||||
{
|
||||
return (left.value(Article::KeyDate).toDateTime() > right.value(Article::KeyDate).toDateTime());
|
||||
});
|
||||
|
||||
@@ -447,7 +447,7 @@ void AutoDownloader::setRule_impl(const AutoDownloadRule &rule)
|
||||
|
||||
void AutoDownloader::sortRules()
|
||||
{
|
||||
std::sort(m_rules.begin(), m_rules.end(), [](const AutoDownloadRule &lhs, const AutoDownloadRule &rhs)
|
||||
std::ranges::sort(m_rules, [](const AutoDownloadRule &lhs, const AutoDownloadRule &rhs)
|
||||
{
|
||||
return (lhs.priority() < rhs.priority());
|
||||
});
|
||||
|
||||
@@ -255,7 +255,7 @@ bool AutoDownloadRule::matchesMustContainExpression(const QString &articleTitle)
|
||||
|
||||
// Each expression is either a regex, or a set of wildcards separated by whitespace.
|
||||
// Accept if any complete expression matches.
|
||||
return std::any_of(m_dataPtr->mustContain.cbegin(), m_dataPtr->mustContain.cend(), [this, &articleTitle](const QString &expression)
|
||||
return std::ranges::any_of(asConst(m_dataPtr->mustContain), [this, &articleTitle](const QString &expression)
|
||||
{
|
||||
// A regex of the form "expr|" will always match, so do the same for wildcards
|
||||
return matchesExpression(articleTitle, expression);
|
||||
@@ -269,7 +269,7 @@ bool AutoDownloadRule::matchesMustNotContainExpression(const QString &articleTit
|
||||
|
||||
// Each expression is either a regex, or a set of wildcards separated by whitespace.
|
||||
// Reject if any complete expression matches.
|
||||
return std::none_of(m_dataPtr->mustNotContain.cbegin(), m_dataPtr->mustNotContain.cend(), [this, &articleTitle](const QString &expression)
|
||||
return std::ranges::none_of(asConst(m_dataPtr->mustNotContain), [this, &articleTitle](const QString &expression)
|
||||
{
|
||||
// A regex of the form "expr|" will always match, so do the same for wildcards
|
||||
return matchesExpression(articleTitle, expression);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "rss_feed.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -426,20 +427,13 @@ int Feed::updateArticles(const QList<QVariantHash> &loadedArticles)
|
||||
std::vector<ArticleSortAdaptor> sortData;
|
||||
const QList<Article *> existingArticles = articles();
|
||||
sortData.reserve(existingArticles.size() + newArticles.size());
|
||||
std::transform(existingArticles.begin(), existingArticles.end(), std::back_inserter(sortData)
|
||||
, [](const Article *article)
|
||||
{
|
||||
return std::make_pair(article->date(), nullptr);
|
||||
});
|
||||
std::transform(newArticles.begin(), newArticles.end(), std::back_inserter(sortData)
|
||||
, [](const QVariantHash &article)
|
||||
{
|
||||
return std::make_pair(article[Article::KeyDate].toDateTime(), &article);
|
||||
});
|
||||
for (const Article *article : existingArticles)
|
||||
sortData.push_back(std::make_pair(article->date(), nullptr));
|
||||
for (const QVariantHash &article : asConst(newArticles))
|
||||
sortData.push_back(std::make_pair(article[Article::KeyDate].toDateTime(), &article));
|
||||
|
||||
// Sort article list in reverse chronological order
|
||||
std::sort(sortData.begin(), sortData.end()
|
||||
, [](const ArticleSortAdaptor &a1, const ArticleSortAdaptor &a2)
|
||||
std::ranges::sort(sortData, [](const ArticleSortAdaptor &a1, const ArticleSortAdaptor &a2)
|
||||
{
|
||||
return (a1.first > a2.first);
|
||||
});
|
||||
@@ -448,14 +442,14 @@ int Feed::updateArticles(const QList<QVariantHash> &loadedArticles)
|
||||
sortData.resize(m_session->maxArticlesPerFeed());
|
||||
|
||||
int newArticlesCount = 0;
|
||||
std::for_each(sortData.crbegin(), sortData.crend(), [this, &newArticlesCount](const ArticleSortAdaptor &a)
|
||||
for (const ArticleSortAdaptor &a : std::views::reverse(sortData))
|
||||
{
|
||||
if (a.second)
|
||||
{
|
||||
addArticle(*a.second);
|
||||
++newArticlesCount;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return newArticlesCount;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace
|
||||
PathList versions = getRegSubkeys(hkPythonCore);
|
||||
// ordinary sort won't suffice, it needs to sort ["3.9", "3.10"] correctly
|
||||
const Utils::Compare::NaturalCompare<Qt::CaseInsensitive> comparator;
|
||||
std::sort(versions.begin(), versions.end(), [&comparator](const Path &left, const Path &right)
|
||||
std::ranges::sort(versions, [&comparator](const Path &left, const Path &right)
|
||||
{
|
||||
return comparator(left.data(), right.data());
|
||||
});
|
||||
|
||||
@@ -93,8 +93,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const Path &path)
|
||||
while (iter.hasNext())
|
||||
dirList << iter.next() + u'/';
|
||||
// sort descending by directory depth
|
||||
std::sort(dirList.begin(), dirList.end()
|
||||
, [](const QString &l, const QString &r) { return l.count(u'/') > r.count(u'/'); });
|
||||
std::ranges::sort(dirList, [](const QString &l, const QString &r) { return l.count(u'/') > r.count(u'/'); });
|
||||
|
||||
for (const QString &p : asConst(dirList))
|
||||
{
|
||||
@@ -108,7 +107,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const Path &path)
|
||||
|
||||
// deleteFilesList contains unwanted files, usually created by the OS
|
||||
// temp files on linux usually end with '~', e.g. `filename~`
|
||||
const bool hasOtherFiles = std::any_of(tmpFileList.cbegin(), tmpFileList.cend(), [&deleteFilesList](const QString &f)
|
||||
const bool hasOtherFiles = std::ranges::any_of(tmpFileList, [&deleteFilesList](const QString &f)
|
||||
{
|
||||
return (!f.endsWith(u'~') && !deleteFilesList.contains(f, Qt::CaseInsensitive));
|
||||
});
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace Utils
|
||||
protocolEquivalentAddress = QHostAddress(addr.toIPv4Address(&addrConversionOk));
|
||||
}
|
||||
|
||||
return std::any_of(subnets.begin(), subnets.end(), [&](const Subnet &subnet)
|
||||
return std::ranges::any_of(subnets, [&](const Subnet &subnet)
|
||||
{
|
||||
return addr.isInSubnet(subnet)
|
||||
|| (addrConversionOk && protocolEquivalentAddress.isInSubnet(subnet));
|
||||
@@ -117,7 +117,7 @@ namespace Utils
|
||||
QList<QSslCertificate> loadSSLCertificate(const QByteArray &data)
|
||||
{
|
||||
const QList<QSslCertificate> certs {QSslCertificate::fromData(data)};
|
||||
const bool hasInvalidCerts = std::any_of(certs.cbegin(), certs.cend(), [](const QSslCertificate &cert)
|
||||
const bool hasInvalidCerts = std::ranges::any_of(certs, [](const QSslCertificate &cert)
|
||||
{
|
||||
return cert.isNull();
|
||||
});
|
||||
|
||||
@@ -460,7 +460,7 @@ void AddNewTorrentDialog::setCurrentContext(const std::shared_ptr<Context> conte
|
||||
|
||||
// Load categories
|
||||
QStringList categories = session->categories();
|
||||
std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
std::ranges::sort(categories, Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
const QString defaultCategory = m_storeDefaultCategory;
|
||||
|
||||
if (!addTorrentParams.category.isEmpty())
|
||||
|
||||
@@ -167,7 +167,7 @@ void AddTorrentParamsWidget::populate()
|
||||
m_ui->categoryComboBox->disconnect(this);
|
||||
m_ui->categoryComboBox->clear();
|
||||
QStringList categories = BitTorrent::Session::instance()->categories();
|
||||
std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
std::ranges::sort(categories, Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
if (!m_addTorrentParams.category.isEmpty())
|
||||
m_ui->categoryComboBox->addItem(m_addTorrentParams.category);
|
||||
m_ui->categoryComboBox->addItem(u""_s);
|
||||
|
||||
@@ -120,7 +120,7 @@ void BanListOptionsDialog::on_buttonBanIP_clicked()
|
||||
void BanListOptionsDialog::on_buttonDeleteIP_clicked()
|
||||
{
|
||||
QModelIndexList selection = m_ui->bannedIPList->selectionModel()->selectedIndexes();
|
||||
std::sort(selection.begin(), selection.end(), [](const QModelIndex &left, const QModelIndex &right)
|
||||
std::ranges::sort(selection, [](const QModelIndex &left, const QModelIndex &right)
|
||||
{
|
||||
return (left.row() > right.row());
|
||||
});
|
||||
|
||||
@@ -100,12 +100,10 @@ void CookiesDialog::onButtonDeleteClicked()
|
||||
QModelIndexList idxs = m_ui->treeView->selectionModel()->selectedRows();
|
||||
|
||||
// sort in descending order
|
||||
std::sort(idxs.begin(), idxs.end(),
|
||||
[](const QModelIndex &l, const QModelIndex &r)
|
||||
std::ranges::sort(idxs, [](const QModelIndex &l, const QModelIndex &r)
|
||||
{
|
||||
return (l.row() > r.row());
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
for (const QModelIndex &idx : asConst(idxs))
|
||||
m_cookiesModel->removeRow(idx.row());
|
||||
|
||||
@@ -1184,7 +1184,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
const QList<BitTorrent::Torrent *> allTorrents = BitTorrent::Session::instance()->torrents();
|
||||
const bool hasActiveTorrents = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [](BitTorrent::Torrent *torrent)
|
||||
const bool hasActiveTorrents = std::ranges::any_of(allTorrents, [](const BitTorrent::Torrent *torrent)
|
||||
{
|
||||
return torrent->isActive();
|
||||
});
|
||||
@@ -1259,7 +1259,7 @@ bool MainWindow::event(QEvent *e)
|
||||
qDebug() << "Has active window:" << (qApp->activeWindow() != nullptr);
|
||||
// Check if there is a modal window
|
||||
const QWidgetList allWidgets = QApplication::allWidgets();
|
||||
const bool hasModalWindow = std::any_of(allWidgets.cbegin(), allWidgets.cend()
|
||||
const bool hasModalWindow = std::ranges::any_of(allWidgets
|
||||
, [](const QWidget *widget) { return widget->isModal(); });
|
||||
// Iconify if there is no modal window
|
||||
if (!hasModalWindow)
|
||||
@@ -1821,7 +1821,7 @@ void MainWindow::updatePowerManagementState() const
|
||||
const bool preventFromSuspendWhenSeeding = pref->preventFromSuspendWhenSeeding();
|
||||
|
||||
const QList<BitTorrent::Torrent *> allTorrents = BitTorrent::Session::instance()->torrents();
|
||||
const bool inhibitSuspend = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [&](const BitTorrent::Torrent *torrent)
|
||||
const bool inhibitSuspend = std::ranges::any_of(allTorrents, [&](const BitTorrent::Torrent *torrent)
|
||||
{
|
||||
if (preventFromSuspendWhenDownloading && (!torrent->isFinished() && !torrent->isStopped() && !torrent->isErrored() && torrent->hasMetadata()))
|
||||
return true;
|
||||
|
||||
@@ -1762,7 +1762,7 @@ void OptionsDialog::initializeStyleCombo()
|
||||
m_ui->comboStyle->insertSeparator(1);
|
||||
|
||||
QStringList styleNames = QStyleFactory::keys();
|
||||
std::sort(styleNames.begin(), styleNames.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
std::ranges::sort(styleNames, Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
for (const QString &styleName : asConst(styleNames))
|
||||
m_ui->comboStyle->addItem(styleName, styleName);
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ void PeerListWidget::showPeerListMenu()
|
||||
, this, [this, torrent]()
|
||||
{
|
||||
const QList<BitTorrent::PeerAddress> peersList = PeersAdditionDialog::askForPeers(this);
|
||||
const int peerCount = std::count_if(peersList.cbegin(), peersList.cend(), [torrent](const BitTorrent::PeerAddress &peer)
|
||||
const int peerCount = std::ranges::count_if(peersList, [torrent](const BitTorrent::PeerAddress &peer)
|
||||
{
|
||||
return torrent->connectPeer(peer);
|
||||
});
|
||||
|
||||
@@ -48,11 +48,11 @@ QList<float> PieceAvailabilityBar::intToFloatVector(const QList<int> &vecin, int
|
||||
|
||||
const float ratio = static_cast<float>(vecin.size()) / reqSize;
|
||||
|
||||
const int maxElement = *std::max_element(vecin.begin(), vecin.end());
|
||||
const int maxElement = *std::ranges::max_element(vecin);
|
||||
|
||||
// std::max because in normalization we don't want divide by 0
|
||||
// if maxElement == 0 check will be disabled please enable this line:
|
||||
// const int maxElement = std::max(*std::max_element(avail.begin(), avail.end()), 1);
|
||||
// const int maxElement = std::max(*std::ranges::max_element(avail), 1);
|
||||
|
||||
if (maxElement == 0)
|
||||
return result;
|
||||
|
||||
@@ -564,7 +564,7 @@ void SearchWidget::fillCatCombobox()
|
||||
const auto selectedPlugin = m_ui->selectPlugin->itemData(m_ui->selectPlugin->currentIndex()).toString();
|
||||
for (const QString &cat : asConst(SearchPluginManager::instance()->getPluginCategories(selectedPlugin)))
|
||||
tmpList << std::make_pair(SearchPluginManager::categoryFullName(cat), cat);
|
||||
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); });
|
||||
std::ranges::sort(tmpList, [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); });
|
||||
|
||||
for (const QStrPair &p : asConst(tmpList))
|
||||
{
|
||||
@@ -587,7 +587,7 @@ void SearchWidget::fillPluginComboBox()
|
||||
QList<QStrPair> tmpList;
|
||||
for (const QString &name : asConst(SearchPluginManager::instance()->enabledPlugins()))
|
||||
tmpList << std::make_pair(SearchPluginManager::instance()->pluginFullName(name), name);
|
||||
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } );
|
||||
std::ranges::sort(tmpList, [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); });
|
||||
|
||||
for (const QStrPair &p : asConst(tmpList))
|
||||
m_ui->selectPlugin->addItem(p.first, p.second);
|
||||
|
||||
@@ -401,7 +401,7 @@ QVariant TorrentContentModel::data(const QModelIndex &index, const int role) con
|
||||
|
||||
const auto *folder = static_cast<TorrentContentModelFolder *>(item);
|
||||
const auto childItems = folder->children();
|
||||
const bool hasIgnored = std::any_of(childItems.cbegin(), childItems.cend()
|
||||
const bool hasIgnored = std::ranges::any_of(childItems
|
||||
, [](const TorrentContentModelItem *childItem)
|
||||
{
|
||||
const auto prio = childItem->priority();
|
||||
@@ -583,8 +583,7 @@ void TorrentContentModel::populate()
|
||||
QList<QStringView> pathFolders = QStringView(path).split(u'/', Qt::SkipEmptyParts);
|
||||
const QString fileName = pathFolders.takeLast().toString();
|
||||
|
||||
if (!std::equal(lastParentPath.begin(), lastParentPath.end()
|
||||
, pathFolders.begin(), pathFolders.end()))
|
||||
if (!std::ranges::equal(asConst(lastParentPath), asConst(pathFolders)))
|
||||
{
|
||||
lastParentPath.clear();
|
||||
lastParentPath.reserve(pathFolders.size());
|
||||
|
||||
@@ -231,7 +231,7 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QList<BitTorre
|
||||
m_ui->comboCategory->addItem(QString());
|
||||
|
||||
m_categories = session->categories();
|
||||
std::sort(m_categories.begin(), m_categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
std::ranges::sort(m_categories, Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
for (const QString &category : asConst(m_categories))
|
||||
{
|
||||
if (m_allSameCategory && (category == firstTorrentCategory))
|
||||
|
||||
@@ -434,8 +434,8 @@ void CategoryFilterModel::populate()
|
||||
|
||||
// Uncategorized torrents
|
||||
using Torrent = BitTorrent::Torrent;
|
||||
const int torrentsCount = std::count_if(torrents.begin(), torrents.end()
|
||||
, [](Torrent *torrent) { return torrent->category().isEmpty(); });
|
||||
const int torrentsCount = std::ranges::count_if(torrents
|
||||
, [](const Torrent *torrent) { return torrent->category().isEmpty(); });
|
||||
m_rootItem->addChild(CategoryModelItem::UID_UNCATEGORIZED
|
||||
, new CategoryModelItem(nullptr, tr("Uncategorized"), torrentsCount));
|
||||
|
||||
@@ -450,8 +450,8 @@ void CategoryFilterModel::populate()
|
||||
const QString subcatName = shortName(subcat);
|
||||
if (!parent->hasChild(subcatName))
|
||||
{
|
||||
const int torrentsCount = std::count_if(torrents.cbegin(), torrents.cend()
|
||||
, [subcat](Torrent *torrent) { return torrent->category() == subcat; });
|
||||
const int torrentsCount = std::ranges::count_if(torrents
|
||||
, [&subcat](const Torrent *torrent) { return torrent->category() == subcat; });
|
||||
new CategoryModelItem(parent, subcatName, torrentsCount);
|
||||
}
|
||||
parent = parent->child(subcatName);
|
||||
@@ -462,8 +462,8 @@ void CategoryFilterModel::populate()
|
||||
{
|
||||
for (const QString &categoryName : asConst(session->categories()))
|
||||
{
|
||||
const int torrentsCount = std::count_if(torrents.begin(), torrents.end()
|
||||
, [categoryName](Torrent *torrent) { return torrent->belongsToCategory(categoryName); });
|
||||
const int torrentsCount = std::ranges::count_if(torrents
|
||||
, [&categoryName](const Torrent *torrent) { return torrent->belongsToCategory(categoryName); });
|
||||
new CategoryModelItem(m_rootItem, categoryName, torrentsCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,14 +294,14 @@ void TagFilterModel::populate()
|
||||
// All torrents
|
||||
addToModel(Tag(), torrents.count());
|
||||
|
||||
const int untaggedCount = std::count_if(torrents.cbegin(), torrents.cend()
|
||||
, [](Torrent *torrent) { return torrent->tags().isEmpty(); });
|
||||
const int untaggedCount = std::ranges::count_if(torrents
|
||||
, [](const Torrent *torrent) { return torrent->tags().isEmpty(); });
|
||||
addToModel(Tag(), untaggedCount);
|
||||
|
||||
for (const Tag &tag : asConst(session->tags()))
|
||||
{
|
||||
const int count = std::count_if(torrents.cbegin(), torrents.cend()
|
||||
, [tag](Torrent *torrent) { return torrent->hasTag(tag); });
|
||||
const int count = std::ranges::count_if(torrents
|
||||
, [&tag](const Torrent *torrent) { return torrent->hasTag(tag); });
|
||||
addToModel(tag, count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ void TrackersFilterWidget::handleTrackerStatusesUpdated(const BitTorrent::Torren
|
||||
if (trackerErrorHashesIt != m_trackerErrors.end())
|
||||
trackerErrorHashesIt->remove(trackerEntryStatus.url);
|
||||
|
||||
const bool hasNoWarningMessages = std::all_of(trackerEntryStatus.endpoints.cbegin(), trackerEntryStatus.endpoints.cend()
|
||||
const bool hasNoWarningMessages = std::ranges::all_of(trackerEntryStatus.endpoints
|
||||
, [](const BitTorrent::TrackerEndpointStatus &endpointEntry)
|
||||
{
|
||||
return endpointEntry.message.isEmpty() || (endpointEntry.state != BitTorrent::TrackerEndpointState::Working);
|
||||
|
||||
@@ -582,7 +582,7 @@ void TransferListWidget::copySelectedComments() const
|
||||
torrentComments << torrent->comment();
|
||||
}
|
||||
|
||||
qApp->clipboard()->setText(torrentComments.join(u"\n---------\n"_s));
|
||||
qApp->clipboard()->setText(torrentComments.join(u"\n---------\n"));
|
||||
}
|
||||
|
||||
void TransferListWidget::hideQueuePosColumn(bool hide)
|
||||
@@ -793,9 +793,10 @@ void TransferListWidget::editTorrentTrackers()
|
||||
for (const BitTorrent::TrackerEntryStatus &status : asConst(torrent->trackers()))
|
||||
trackerSet.insert({.url = status.url, .tier = status.tier});
|
||||
|
||||
commonTrackers.erase(std::remove_if(commonTrackers.begin(), commonTrackers.end()
|
||||
, [&trackerSet](const BitTorrent::TrackerEntry &entry) { return !trackerSet.contains(entry); })
|
||||
, commonTrackers.end());
|
||||
commonTrackers.removeIf([&trackerSet](const BitTorrent::TrackerEntry &entry)
|
||||
{
|
||||
return !trackerSet.contains(entry);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1170,7 +1171,7 @@ void TransferListWidget::displayListMenu()
|
||||
|
||||
// Category Menu
|
||||
QStringList categories = BitTorrent::Session::instance()->categories();
|
||||
std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
std::ranges::sort(categories, Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
|
||||
QMenu *categoryMenu = listMenu->addMenu(UIThemeManager::instance()->getIcon(u"view-categories"_s), tr("Categor&y"));
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ void APIController::requireParams(const QList<QString> &requiredParams) const
|
||||
}
|
||||
|
||||
if (!missingParams.isEmpty())
|
||||
throw APIError(APIErrorType::BadParams, tr("Missing required parameters: %1").arg(missingParams.join(u", "_s)));
|
||||
throw APIError(APIErrorType::BadParams, tr("Missing required parameters: %1").arg(missingParams.join(u", ")));
|
||||
}
|
||||
|
||||
void APIController::setResult(const QString &result)
|
||||
|
||||
@@ -980,7 +980,7 @@ void AppController::setPreferencesAction()
|
||||
const QString ifaceValue {it.value().toString()};
|
||||
|
||||
const QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
|
||||
const auto ifacesIter = std::find_if(ifaces.cbegin(), ifaces.cend(), [&ifaceValue](const QNetworkInterface &iface)
|
||||
const auto ifacesIter = std::ranges::find_if(ifaces, [&ifaceValue](const QNetworkInterface &iface)
|
||||
{
|
||||
return (!iface.addressEntries().isEmpty()) && (iface.name() == ifaceValue);
|
||||
});
|
||||
|
||||
@@ -628,7 +628,7 @@ void TorrentsController::infoAction()
|
||||
return false;
|
||||
};
|
||||
|
||||
std::sort(torrentList.begin(), torrentList.end()
|
||||
std::ranges::sort(torrentList
|
||||
, [reverse, &sortedColumn, &lessThan](const QVariant &torrent1, const QVariant &torrent2)
|
||||
{
|
||||
const QVariant value1 {torrent1.toMap().value(sortedColumn)};
|
||||
@@ -931,8 +931,7 @@ void TorrentsController::filesAction()
|
||||
const int filesCount = torrent->filesCount();
|
||||
const QStringList indexStrings = idxIt.value().split(u'|');
|
||||
fileIndexes.reserve(indexStrings.size());
|
||||
std::transform(indexStrings.cbegin(), indexStrings.cend(), std::back_inserter(fileIndexes)
|
||||
, [&filesCount](const QString &indexString) -> int
|
||||
for (const QString &indexString : indexStrings)
|
||||
{
|
||||
bool ok = false;
|
||||
const int index = indexString.toInt(&ok);
|
||||
@@ -940,8 +939,8 @@ void TorrentsController::filesAction()
|
||||
throw APIError(APIErrorType::Conflict, tr("\"%1\" is not a valid file index.").arg(indexString));
|
||||
if (index >= filesCount)
|
||||
throw APIError(APIErrorType::Conflict, tr("Index %1 is out of bounds.").arg(indexString));
|
||||
return index;
|
||||
});
|
||||
fileIndexes.push_back(index);
|
||||
}
|
||||
}
|
||||
|
||||
QJsonArray fileList = getFiles(torrent, fileIndexes);
|
||||
@@ -1348,7 +1347,7 @@ void TorrentsController::addPeersAction()
|
||||
|
||||
applyToTorrents(hashes, [peers, peerList, &results](BitTorrent::Torrent *const torrent)
|
||||
{
|
||||
const int peersAdded = std::count_if(peerList.cbegin(), peerList.cend(), [torrent](const BitTorrent::PeerAddress &peer)
|
||||
const int peersAdded = std::ranges::count_if(peerList, [torrent](const BitTorrent::PeerAddress &peer)
|
||||
{
|
||||
return torrent->connectPeer(peer);
|
||||
});
|
||||
|
||||
@@ -446,7 +446,8 @@ void WebApplication::configure()
|
||||
m_sessionCookieName = SESSION_COOKIE_NAME_PREFIX + QString::number(pref->getWebUIPort());
|
||||
|
||||
m_domainList = pref->getServerDomains().split(u';', Qt::SkipEmptyParts);
|
||||
std::for_each(m_domainList.begin(), m_domainList.end(), [](QString &entry) { entry = entry.trimmed(); });
|
||||
for (QString &entry : m_domainList)
|
||||
entry = entry.trimmed();
|
||||
|
||||
m_isCSRFProtectionEnabled = pref->isWebUICSRFProtectionEnabled();
|
||||
m_isSecureCookieEnabled = pref->isWebUISecureCookieEnabled();
|
||||
|
||||
Reference in New Issue
Block a user