mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-06 15:04:34 +08:00
Use const where appropriate
This commit is contained in:
parent
c89e9d4354
commit
dd790d94c9
@ -114,12 +114,12 @@ namespace
|
|||||||
void applyToTorrents(const QStringList &hashes, const std::function<void (BitTorrent::TorrentHandle *torrent)> &func)
|
void applyToTorrents(const QStringList &hashes, const std::function<void (BitTorrent::TorrentHandle *torrent)> &func)
|
||||||
{
|
{
|
||||||
if ((hashes.size() == 1) && (hashes[0] == QLatin1String("all"))) {
|
if ((hashes.size() == 1) && (hashes[0] == QLatin1String("all"))) {
|
||||||
for (BitTorrent::TorrentHandle *torrent : asConst(BitTorrent::Session::instance()->torrents()))
|
for (BitTorrent::TorrentHandle *const torrent : asConst(BitTorrent::Session::instance()->torrents()))
|
||||||
func(torrent);
|
func(torrent);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (const QString &hash : hashes) {
|
for (const QString &hash : hashes) {
|
||||||
BitTorrent::TorrentHandle *torrent = BitTorrent::Session::instance()->findTorrent(hash);
|
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
|
||||||
if (torrent)
|
if (torrent)
|
||||||
func(torrent);
|
func(torrent);
|
||||||
}
|
}
|
||||||
@ -548,7 +548,7 @@ void TorrentsController::pauseAction()
|
|||||||
checkParams({"hashes"});
|
checkParams({"hashes"});
|
||||||
|
|
||||||
const QStringList hashes = params()["hashes"].split('|');
|
const QStringList hashes = params()["hashes"].split('|');
|
||||||
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *torrent) { torrent->pause(); });
|
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *const torrent) { torrent->pause(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::resumeAction()
|
void TorrentsController::resumeAction()
|
||||||
@ -556,7 +556,7 @@ void TorrentsController::resumeAction()
|
|||||||
checkParams({"hashes"});
|
checkParams({"hashes"});
|
||||||
|
|
||||||
const QStringList hashes = params()["hashes"].split('|');
|
const QStringList hashes = params()["hashes"].split('|');
|
||||||
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *torrent) { torrent->resume(); });
|
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *const torrent) { torrent->resume(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::filePrioAction()
|
void TorrentsController::filePrioAction()
|
||||||
@ -606,7 +606,7 @@ void TorrentsController::uploadLimitAction()
|
|||||||
QVariantMap map;
|
QVariantMap map;
|
||||||
for (const QString &hash : hashes) {
|
for (const QString &hash : hashes) {
|
||||||
int limit = -1;
|
int limit = -1;
|
||||||
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
|
const BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
|
||||||
if (torrent)
|
if (torrent)
|
||||||
limit = torrent->uploadLimit();
|
limit = torrent->uploadLimit();
|
||||||
map[hash] = limit;
|
map[hash] = limit;
|
||||||
@ -623,7 +623,7 @@ void TorrentsController::downloadLimitAction()
|
|||||||
QVariantMap map;
|
QVariantMap map;
|
||||||
for (const QString &hash : hashes) {
|
for (const QString &hash : hashes) {
|
||||||
int limit = -1;
|
int limit = -1;
|
||||||
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
|
const BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
|
||||||
if (torrent)
|
if (torrent)
|
||||||
limit = torrent->downloadLimit();
|
limit = torrent->downloadLimit();
|
||||||
map[hash] = limit;
|
map[hash] = limit;
|
||||||
@ -641,7 +641,7 @@ void TorrentsController::setUploadLimitAction()
|
|||||||
limit = -1;
|
limit = -1;
|
||||||
|
|
||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
applyToTorrents(hashes, [limit](BitTorrent::TorrentHandle *torrent) { torrent->setUploadLimit(limit); });
|
applyToTorrents(hashes, [limit](BitTorrent::TorrentHandle *const torrent) { torrent->setUploadLimit(limit); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::setDownloadLimitAction()
|
void TorrentsController::setDownloadLimitAction()
|
||||||
@ -653,7 +653,7 @@ void TorrentsController::setDownloadLimitAction()
|
|||||||
limit = -1;
|
limit = -1;
|
||||||
|
|
||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
applyToTorrents(hashes, [limit](BitTorrent::TorrentHandle *torrent) { torrent->setDownloadLimit(limit); });
|
applyToTorrents(hashes, [limit](BitTorrent::TorrentHandle *const torrent) { torrent->setDownloadLimit(limit); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::setShareLimitsAction()
|
void TorrentsController::setShareLimitsAction()
|
||||||
@ -664,7 +664,7 @@ void TorrentsController::setShareLimitsAction()
|
|||||||
const qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong();
|
const qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong();
|
||||||
const QStringList hashes = params()["hashes"].split('|');
|
const QStringList hashes = params()["hashes"].split('|');
|
||||||
|
|
||||||
applyToTorrents(hashes, [ratioLimit, seedingTimeLimit](BitTorrent::TorrentHandle *torrent)
|
applyToTorrents(hashes, [ratioLimit, seedingTimeLimit](BitTorrent::TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
torrent->setRatioLimit(ratioLimit);
|
torrent->setRatioLimit(ratioLimit);
|
||||||
torrent->setSeedingTimeLimit(seedingTimeLimit);
|
torrent->setSeedingTimeLimit(seedingTimeLimit);
|
||||||
@ -676,7 +676,7 @@ void TorrentsController::toggleSequentialDownloadAction()
|
|||||||
checkParams({"hashes"});
|
checkParams({"hashes"});
|
||||||
|
|
||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *torrent) { torrent->toggleSequentialDownload(); });
|
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *const torrent) { torrent->toggleSequentialDownload(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::toggleFirstLastPiecePrioAction()
|
void TorrentsController::toggleFirstLastPiecePrioAction()
|
||||||
@ -684,7 +684,7 @@ void TorrentsController::toggleFirstLastPiecePrioAction()
|
|||||||
checkParams({"hashes"});
|
checkParams({"hashes"});
|
||||||
|
|
||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *torrent) { torrent->toggleFirstLastPiecePriority(); });
|
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *const torrent) { torrent->toggleFirstLastPiecePriority(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::setSuperSeedingAction()
|
void TorrentsController::setSuperSeedingAction()
|
||||||
@ -693,7 +693,7 @@ void TorrentsController::setSuperSeedingAction()
|
|||||||
|
|
||||||
const bool value {parseBool(params()["value"], false)};
|
const bool value {parseBool(params()["value"], false)};
|
||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
applyToTorrents(hashes, [value](BitTorrent::TorrentHandle *torrent) { torrent->setSuperSeeding(value); });
|
applyToTorrents(hashes, [value](BitTorrent::TorrentHandle *const torrent) { torrent->setSuperSeeding(value); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::setForceStartAction()
|
void TorrentsController::setForceStartAction()
|
||||||
@ -702,7 +702,7 @@ void TorrentsController::setForceStartAction()
|
|||||||
|
|
||||||
const bool value {parseBool(params()["value"], false)};
|
const bool value {parseBool(params()["value"], false)};
|
||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
applyToTorrents(hashes, [value](BitTorrent::TorrentHandle *torrent) { torrent->resume(value); });
|
applyToTorrents(hashes, [value](BitTorrent::TorrentHandle *const torrent) { torrent->resume(value); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::deleteAction()
|
void TorrentsController::deleteAction()
|
||||||
@ -711,7 +711,7 @@ void TorrentsController::deleteAction()
|
|||||||
|
|
||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
const bool deleteFiles {parseBool(params()["deleteFiles"], false)};
|
const bool deleteFiles {parseBool(params()["deleteFiles"], false)};
|
||||||
applyToTorrents(hashes, [deleteFiles](BitTorrent::TorrentHandle *torrent)
|
applyToTorrents(hashes, [deleteFiles](BitTorrent::TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteFiles);
|
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteFiles);
|
||||||
});
|
});
|
||||||
@ -779,7 +779,7 @@ void TorrentsController::setLocationAction()
|
|||||||
if (!QFileInfo(newLocation).isWritable())
|
if (!QFileInfo(newLocation).isWritable())
|
||||||
throw APIError(APIErrorType::AccessDenied, tr("Cannot write to directory"));
|
throw APIError(APIErrorType::AccessDenied, tr("Cannot write to directory"));
|
||||||
|
|
||||||
applyToTorrents(hashes, [newLocation](BitTorrent::TorrentHandle *torrent)
|
applyToTorrents(hashes, [newLocation](BitTorrent::TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
LogMsg(tr("WebUI Set location: moving \"%1\", from \"%2\" to \"%3\"")
|
LogMsg(tr("WebUI Set location: moving \"%1\", from \"%2\" to \"%3\"")
|
||||||
.arg(torrent->name(), Utils::Fs::toNativePath(torrent->savePath()), Utils::Fs::toNativePath(newLocation)));
|
.arg(torrent->name(), Utils::Fs::toNativePath(torrent->savePath()), Utils::Fs::toNativePath(newLocation)));
|
||||||
@ -812,7 +812,7 @@ void TorrentsController::setAutoManagementAction()
|
|||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
const bool isEnabled {parseBool(params()["enable"], false)};
|
const bool isEnabled {parseBool(params()["enable"], false)};
|
||||||
|
|
||||||
applyToTorrents(hashes, [isEnabled](BitTorrent::TorrentHandle *torrent)
|
applyToTorrents(hashes, [isEnabled](BitTorrent::TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
torrent->setAutoTMMEnabled(isEnabled);
|
torrent->setAutoTMMEnabled(isEnabled);
|
||||||
});
|
});
|
||||||
@ -823,7 +823,7 @@ void TorrentsController::recheckAction()
|
|||||||
checkParams({"hashes"});
|
checkParams({"hashes"});
|
||||||
|
|
||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *torrent) { torrent->forceRecheck(); });
|
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *const torrent) { torrent->forceRecheck(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::reannounceAction()
|
void TorrentsController::reannounceAction()
|
||||||
@ -831,7 +831,7 @@ void TorrentsController::reannounceAction()
|
|||||||
checkParams({"hashes"});
|
checkParams({"hashes"});
|
||||||
|
|
||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *torrent) { torrent->forceReannounce(); });
|
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *const torrent) { torrent->forceReannounce(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentsController::setCategoryAction()
|
void TorrentsController::setCategoryAction()
|
||||||
@ -841,7 +841,7 @@ void TorrentsController::setCategoryAction()
|
|||||||
const QStringList hashes {params()["hashes"].split('|')};
|
const QStringList hashes {params()["hashes"].split('|')};
|
||||||
const QString category {params()["category"].trimmed()};
|
const QString category {params()["category"].trimmed()};
|
||||||
|
|
||||||
applyToTorrents(hashes, [category](BitTorrent::TorrentHandle *torrent)
|
applyToTorrents(hashes, [category](BitTorrent::TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
if (!torrent->setCategory(category))
|
if (!torrent->setCategory(category))
|
||||||
throw APIError(APIErrorType::Conflict, tr("Incorrect category name"));
|
throw APIError(APIErrorType::Conflict, tr("Incorrect category name"));
|
||||||
|
Loading…
Reference in New Issue
Block a user