mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 16:58:06 -06:00
Merge pull request #10220 from thalieht/const
Add const to many vars and arguments
This commit is contained in:
@@ -299,7 +299,7 @@ QString TorrentHandle::rootPath(bool actual) const
|
||||
if ((filesCount() > 1) && !hasRootFolder())
|
||||
return QString();
|
||||
|
||||
QString firstFilePath = filePath(0);
|
||||
const QString firstFilePath = filePath(0);
|
||||
const int slashIndex = firstFilePath.indexOf('/');
|
||||
if (slashIndex >= 0)
|
||||
return QDir(savePath(actual)).absoluteFilePath(firstFilePath.left(slashIndex));
|
||||
@@ -462,10 +462,10 @@ bool TorrentHandle::removeUrlSeed(const QUrl &urlSeed)
|
||||
bool TorrentHandle::connectPeer(const PeerAddress &peerAddress)
|
||||
{
|
||||
libt::error_code ec;
|
||||
libt::address addr = libt::address::from_string(peerAddress.ip.toString().toStdString(), ec);
|
||||
const libt::address addr = libt::address::from_string(peerAddress.ip.toString().toStdString(), ec);
|
||||
if (ec) return false;
|
||||
|
||||
boost::asio::ip::tcp::endpoint ep(addr, peerAddress.port);
|
||||
const boost::asio::ip::tcp::endpoint ep(addr, peerAddress.port);
|
||||
m_nativeHandle.connect_peer(ep);
|
||||
return true;
|
||||
}
|
||||
@@ -504,7 +504,7 @@ qreal TorrentHandle::progress() const
|
||||
if (m_nativeStatus.total_wanted_done == m_nativeStatus.total_wanted)
|
||||
return 1.;
|
||||
|
||||
qreal progress = static_cast<qreal>(m_nativeStatus.total_wanted_done) / m_nativeStatus.total_wanted;
|
||||
const qreal progress = static_cast<qreal>(m_nativeStatus.total_wanted_done) / m_nativeStatus.total_wanted;
|
||||
Q_ASSERT((progress >= 0.f) && (progress <= 1.f));
|
||||
return progress;
|
||||
}
|
||||
@@ -608,7 +608,7 @@ QStringList TorrentHandle::absoluteFilePaths() const
|
||||
{
|
||||
if (!hasMetadata()) return QStringList();
|
||||
|
||||
QDir saveDir(savePath(true));
|
||||
const QDir saveDir(savePath(true));
|
||||
QStringList res;
|
||||
for (int i = 0; i < filesCount(); ++i)
|
||||
res << Utils::Fs::expandPathAbs(saveDir.absoluteFilePath(filePath(i)));
|
||||
@@ -619,12 +619,11 @@ QStringList TorrentHandle::absoluteFilePathsUnwanted() const
|
||||
{
|
||||
if (!hasMetadata()) return QStringList();
|
||||
|
||||
QDir saveDir(savePath(true));
|
||||
const QDir saveDir(savePath(true));
|
||||
QStringList res;
|
||||
std::vector<int> fp;
|
||||
fp = m_nativeHandle.file_priorities();
|
||||
const std::vector<int> fp = m_nativeHandle.file_priorities();
|
||||
|
||||
int count = static_cast<int>(fp.size());
|
||||
const int count = static_cast<int>(fp.size());
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (fp[i] == 0) {
|
||||
const QString path = Utils::Fs::expandPathAbs(saveDir.absoluteFilePath(filePath(i)));
|
||||
@@ -638,8 +637,7 @@ QStringList TorrentHandle::absoluteFilePathsUnwanted() const
|
||||
|
||||
QVector<int> TorrentHandle::filePriorities() const
|
||||
{
|
||||
std::vector<int> fp;
|
||||
fp = m_nativeHandle.file_priorities();
|
||||
const std::vector<int> fp = m_nativeHandle.file_priorities();
|
||||
|
||||
return QVector<int>::fromStdVector(fp);
|
||||
}
|
||||
@@ -891,8 +889,8 @@ qulonglong TorrentHandle::eta() const
|
||||
const SpeedSampleAvg speedAverage = m_speedMonitor.average();
|
||||
|
||||
if (isSeed()) {
|
||||
qreal maxRatioValue = maxRatio();
|
||||
int maxSeedingTimeValue = maxSeedingTime();
|
||||
const qreal maxRatioValue = maxRatio();
|
||||
const int maxSeedingTimeValue = maxSeedingTime();
|
||||
if ((maxRatioValue < 0) && (maxSeedingTimeValue < 0)) return MAX_ETA;
|
||||
|
||||
qlonglong ratioEta = MAX_ETA;
|
||||
@@ -963,7 +961,7 @@ int TorrentHandle::totalSeedsCount() const
|
||||
|
||||
int TorrentHandle::totalPeersCount() const
|
||||
{
|
||||
int peers = m_nativeStatus.num_complete + m_nativeStatus.num_incomplete;
|
||||
const int peers = m_nativeStatus.num_complete + m_nativeStatus.num_incomplete;
|
||||
return (peers > 0) ? peers : m_nativeStatus.list_peers;
|
||||
}
|
||||
|
||||
@@ -1101,14 +1099,14 @@ int TorrentHandle::maxSeedingTime() const
|
||||
|
||||
qreal TorrentHandle::realRatio() const
|
||||
{
|
||||
boost::int64_t upload = m_nativeStatus.all_time_upload;
|
||||
const boost::int64_t upload = m_nativeStatus.all_time_upload;
|
||||
// special case for a seeder who lost its stats, also assume nobody will import a 99% done torrent
|
||||
boost::int64_t download = (m_nativeStatus.all_time_download < m_nativeStatus.total_done * 0.01) ? m_nativeStatus.total_done : m_nativeStatus.all_time_download;
|
||||
const boost::int64_t download = (m_nativeStatus.all_time_download < m_nativeStatus.total_done * 0.01) ? m_nativeStatus.total_done : m_nativeStatus.all_time_download;
|
||||
|
||||
if (download == 0)
|
||||
return (upload == 0) ? 0.0 : MAX_RATIO;
|
||||
|
||||
qreal ratio = upload / static_cast<qreal>(download);
|
||||
const qreal ratio = upload / static_cast<qreal>(download);
|
||||
Q_ASSERT(ratio >= 0.0);
|
||||
return (ratio > MAX_RATIO) ? MAX_RATIO : ratio;
|
||||
}
|
||||
@@ -1162,7 +1160,7 @@ bool TorrentHandle::setCategory(const QString &category)
|
||||
if (!category.isEmpty() && !m_session->categories().contains(category))
|
||||
return false;
|
||||
|
||||
QString oldCategory = m_category;
|
||||
const QString oldCategory = m_category;
|
||||
m_category = category;
|
||||
m_session->handleTorrentCategoryChanged(this, oldCategory);
|
||||
|
||||
@@ -1228,7 +1226,7 @@ void TorrentHandle::forceRecheck()
|
||||
}
|
||||
}
|
||||
|
||||
void TorrentHandle::setSequentialDownload(bool b)
|
||||
void TorrentHandle::setSequentialDownload(const bool b)
|
||||
{
|
||||
if (b != isSequentialDownload()) {
|
||||
m_nativeHandle.set_sequential_download(b);
|
||||
@@ -1352,8 +1350,8 @@ bool TorrentHandle::saveTorrentFile(const QString &path)
|
||||
{
|
||||
if (!m_torrentInfo.isValid()) return false;
|
||||
|
||||
libt::create_torrent torrentCreator = libt::create_torrent(*(m_torrentInfo.nativeInfo()), true);
|
||||
libt::entry torrentEntry = torrentCreator.generate();
|
||||
const libt::create_torrent torrentCreator = libt::create_torrent(*(m_torrentInfo.nativeInfo()), true);
|
||||
const libt::entry torrentEntry = torrentCreator.generate();
|
||||
|
||||
QVector<char> out;
|
||||
libt::bencode(std::back_inserter(out), torrentEntry);
|
||||
@@ -1434,7 +1432,7 @@ void TorrentHandle::handleStorageMovedFailedAlert(const libtorrent::storage_move
|
||||
|
||||
void TorrentHandle::handleTrackerReplyAlert(const libtorrent::tracker_reply_alert *p)
|
||||
{
|
||||
QString trackerUrl(p->tracker_url());
|
||||
const QString trackerUrl(p->tracker_url());
|
||||
qDebug("Received a tracker reply from %s (Num_peers = %d)", qUtf8Printable(trackerUrl), p->num_peers);
|
||||
// Connection was successful now. Remove possible old errors
|
||||
m_trackerInfos[trackerUrl].lastMessage.clear(); // Reset error/warning message
|
||||
@@ -1563,7 +1561,7 @@ void TorrentHandle::handleSaveResumeDataAlert(const libtorrent::save_resume_data
|
||||
resumeData["qBt-sequential"] = isSequentialDownload();
|
||||
}
|
||||
else {
|
||||
auto savePath = resumeData.find_key("save_path")->string();
|
||||
const auto savePath = resumeData.find_key("save_path")->string();
|
||||
resumeData["save_path"] = Profile::instance().toPortablePath(QString::fromStdString(savePath)).toStdString();
|
||||
}
|
||||
resumeData["qBt-savePath"] = m_useAutoTMM ? "" : Profile::instance().toPortablePath(m_savePath).toStdString();
|
||||
@@ -1605,7 +1603,7 @@ void TorrentHandle::handleFastResumeRejectedAlert(const libtorrent::fastresume_r
|
||||
|
||||
void TorrentHandle::handleFileRenamedAlert(const libtorrent::file_renamed_alert *p)
|
||||
{
|
||||
QString newName = Utils::Fs::fromNativePath(p->new_name());
|
||||
const QString newName = Utils::Fs::fromNativePath(p->new_name());
|
||||
|
||||
// TODO: Check this!
|
||||
if (filesCount() > 1) {
|
||||
@@ -1615,7 +1613,7 @@ void TorrentHandle::handleFileRenamedAlert(const libtorrent::file_renamed_alert
|
||||
QString oldPath = oldPathParts.join('/');
|
||||
QStringList newPathParts = newName.split('/');
|
||||
newPathParts.removeLast();
|
||||
QString newPath = newPathParts.join('/');
|
||||
const QString newPath = newPathParts.join('/');
|
||||
if (!newPathParts.isEmpty() && (oldPath != newPath)) {
|
||||
qDebug("oldPath(%s) != newPath(%s)", qUtf8Printable(oldPath), qUtf8Printable(newPath));
|
||||
oldPath = QString("%1/%2").arg(savePath(true), oldPath);
|
||||
@@ -1663,7 +1661,7 @@ void TorrentHandle::handleFileCompletedAlert(const libtorrent::file_completed_al
|
||||
void TorrentHandle::handleStatsAlert(const libtorrent::stats_alert *p)
|
||||
{
|
||||
Q_ASSERT(p->interval >= 1000);
|
||||
SpeedSample transferred(p->transferred[libt::stats_alert::download_payload] * 1000LL / p->interval,
|
||||
const SpeedSample transferred(p->transferred[libt::stats_alert::download_payload] * 1000LL / p->interval,
|
||||
p->transferred[libt::stats_alert::upload_payload] * 1000LL / p->interval);
|
||||
m_speedMonitor.addSample(transferred);
|
||||
}
|
||||
@@ -1714,59 +1712,59 @@ void TorrentHandle::handleAppendExtensionToggled()
|
||||
manageIncompleteFiles();
|
||||
}
|
||||
|
||||
void TorrentHandle::handleAlert(libtorrent::alert *a)
|
||||
void TorrentHandle::handleAlert(const libtorrent::alert *a)
|
||||
{
|
||||
switch (a->type()) {
|
||||
case libt::stats_alert::alert_type:
|
||||
handleStatsAlert(static_cast<libt::stats_alert*>(a));
|
||||
handleStatsAlert(static_cast<const libt::stats_alert*>(a));
|
||||
break;
|
||||
case libt::file_renamed_alert::alert_type:
|
||||
handleFileRenamedAlert(static_cast<libt::file_renamed_alert*>(a));
|
||||
handleFileRenamedAlert(static_cast<const libt::file_renamed_alert*>(a));
|
||||
break;
|
||||
case libt::file_rename_failed_alert::alert_type:
|
||||
handleFileRenameFailedAlert(static_cast<libt::file_rename_failed_alert*>(a));
|
||||
handleFileRenameFailedAlert(static_cast<const libt::file_rename_failed_alert*>(a));
|
||||
break;
|
||||
case libt::file_completed_alert::alert_type:
|
||||
handleFileCompletedAlert(static_cast<libt::file_completed_alert*>(a));
|
||||
handleFileCompletedAlert(static_cast<const libt::file_completed_alert*>(a));
|
||||
break;
|
||||
case libt::torrent_finished_alert::alert_type:
|
||||
handleTorrentFinishedAlert(static_cast<libt::torrent_finished_alert*>(a));
|
||||
handleTorrentFinishedAlert(static_cast<const libt::torrent_finished_alert*>(a));
|
||||
break;
|
||||
case libt::save_resume_data_alert::alert_type:
|
||||
handleSaveResumeDataAlert(static_cast<libt::save_resume_data_alert*>(a));
|
||||
handleSaveResumeDataAlert(static_cast<const libt::save_resume_data_alert*>(a));
|
||||
break;
|
||||
case libt::save_resume_data_failed_alert::alert_type:
|
||||
handleSaveResumeDataFailedAlert(static_cast<libt::save_resume_data_failed_alert*>(a));
|
||||
handleSaveResumeDataFailedAlert(static_cast<const libt::save_resume_data_failed_alert*>(a));
|
||||
break;
|
||||
case libt::storage_moved_alert::alert_type:
|
||||
handleStorageMovedAlert(static_cast<libt::storage_moved_alert*>(a));
|
||||
handleStorageMovedAlert(static_cast<const libt::storage_moved_alert*>(a));
|
||||
break;
|
||||
case libt::storage_moved_failed_alert::alert_type:
|
||||
handleStorageMovedFailedAlert(static_cast<libt::storage_moved_failed_alert*>(a));
|
||||
handleStorageMovedFailedAlert(static_cast<const libt::storage_moved_failed_alert*>(a));
|
||||
break;
|
||||
case libt::torrent_paused_alert::alert_type:
|
||||
handleTorrentPausedAlert(static_cast<libt::torrent_paused_alert*>(a));
|
||||
handleTorrentPausedAlert(static_cast<const libt::torrent_paused_alert*>(a));
|
||||
break;
|
||||
case libt::torrent_resumed_alert::alert_type:
|
||||
handleTorrentResumedAlert(static_cast<libt::torrent_resumed_alert*>(a));
|
||||
handleTorrentResumedAlert(static_cast<const libt::torrent_resumed_alert*>(a));
|
||||
break;
|
||||
case libt::tracker_error_alert::alert_type:
|
||||
handleTrackerErrorAlert(static_cast<libt::tracker_error_alert*>(a));
|
||||
handleTrackerErrorAlert(static_cast<const libt::tracker_error_alert*>(a));
|
||||
break;
|
||||
case libt::tracker_reply_alert::alert_type:
|
||||
handleTrackerReplyAlert(static_cast<libt::tracker_reply_alert*>(a));
|
||||
handleTrackerReplyAlert(static_cast<const libt::tracker_reply_alert*>(a));
|
||||
break;
|
||||
case libt::tracker_warning_alert::alert_type:
|
||||
handleTrackerWarningAlert(static_cast<libt::tracker_warning_alert*>(a));
|
||||
handleTrackerWarningAlert(static_cast<const libt::tracker_warning_alert*>(a));
|
||||
break;
|
||||
case libt::metadata_received_alert::alert_type:
|
||||
handleMetadataReceivedAlert(static_cast<libt::metadata_received_alert*>(a));
|
||||
handleMetadataReceivedAlert(static_cast<const libt::metadata_received_alert*>(a));
|
||||
break;
|
||||
case libt::fastresume_rejected_alert::alert_type:
|
||||
handleFastResumeRejectedAlert(static_cast<libt::fastresume_rejected_alert*>(a));
|
||||
handleFastResumeRejectedAlert(static_cast<const libt::fastresume_rejected_alert*>(a));
|
||||
break;
|
||||
case libt::torrent_checked_alert::alert_type:
|
||||
handleTorrentCheckedAlert(static_cast<libt::torrent_checked_alert*>(a));
|
||||
handleTorrentCheckedAlert(static_cast<const libt::torrent_checked_alert*>(a));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1774,7 +1772,7 @@ void TorrentHandle::handleAlert(libtorrent::alert *a)
|
||||
void TorrentHandle::manageIncompleteFiles()
|
||||
{
|
||||
const bool isAppendExtensionEnabled = m_session->isAppendExtensionEnabled();
|
||||
QVector<qreal> fp = filesProgress();
|
||||
const QVector<qreal> fp = filesProgress();
|
||||
if (fp.size() != filesCount()) {
|
||||
qDebug() << "skip manageIncompleteFiles because of invalid torrent meta-data or empty file-progress";
|
||||
return;
|
||||
@@ -1893,17 +1891,17 @@ void TorrentHandle::setSeedingTimeLimit(int limit)
|
||||
}
|
||||
}
|
||||
|
||||
void TorrentHandle::setUploadLimit(int limit)
|
||||
void TorrentHandle::setUploadLimit(const int limit)
|
||||
{
|
||||
m_nativeHandle.set_upload_limit(limit);
|
||||
}
|
||||
|
||||
void TorrentHandle::setDownloadLimit(int limit)
|
||||
void TorrentHandle::setDownloadLimit(const int limit)
|
||||
{
|
||||
m_nativeHandle.set_download_limit(limit);
|
||||
}
|
||||
|
||||
void TorrentHandle::setSuperSeeding(bool enable)
|
||||
void TorrentHandle::setSuperSeeding(const bool enable)
|
||||
{
|
||||
m_nativeHandle.super_seeding(enable);
|
||||
}
|
||||
@@ -1928,8 +1926,8 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)
|
||||
|
||||
// Reset 'm_hasSeedStatus' if needed in order to react again to
|
||||
// 'torrent_finished_alert' and eg show tray notifications
|
||||
QVector<qreal> progress = filesProgress();
|
||||
QVector<int> oldPriorities = filePriorities();
|
||||
const QVector<qreal> progress = filesProgress();
|
||||
const QVector<int> oldPriorities = filePriorities();
|
||||
for (int i = 0; i < oldPriorities.size(); ++i) {
|
||||
if ((oldPriorities[i] == 0) && (priorities[i] > 0) && (progress[i] < 1.0)) {
|
||||
m_hasSeedStatus = false;
|
||||
@@ -1941,24 +1939,24 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)
|
||||
m_nativeHandle.prioritize_files(priorities.toStdVector());
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Moving unwanted files to .unwanted folder and conversely...";
|
||||
QString spath = savePath(true);
|
||||
const QString spath = savePath(true);
|
||||
for (int i = 0; i < priorities.size(); ++i) {
|
||||
QString filepath = filePath(i);
|
||||
const QString filepath = filePath(i);
|
||||
// Move unwanted files to a .unwanted subfolder
|
||||
if (priorities[i] == 0) {
|
||||
QString oldAbsPath = QDir(spath).absoluteFilePath(filepath);
|
||||
QString parentAbsPath = Utils::Fs::branchPath(oldAbsPath);
|
||||
const QString oldAbsPath = QDir(spath).absoluteFilePath(filepath);
|
||||
const QString parentAbsPath = Utils::Fs::branchPath(oldAbsPath);
|
||||
// Make sure the file does not already exists
|
||||
if (QDir(parentAbsPath).dirName() != ".unwanted") {
|
||||
QString unwantedAbsPath = parentAbsPath + "/.unwanted";
|
||||
QString newAbsPath = unwantedAbsPath + '/' + Utils::Fs::fileName(filepath);
|
||||
const QString unwantedAbsPath = parentAbsPath + "/.unwanted";
|
||||
const QString newAbsPath = unwantedAbsPath + '/' + Utils::Fs::fileName(filepath);
|
||||
qDebug() << "Unwanted path is" << unwantedAbsPath;
|
||||
if (QFile::exists(newAbsPath)) {
|
||||
qWarning() << "File" << newAbsPath << "already exists at destination.";
|
||||
continue;
|
||||
}
|
||||
|
||||
bool created = QDir().mkpath(unwantedAbsPath);
|
||||
const bool created = QDir().mkpath(unwantedAbsPath);
|
||||
qDebug() << "unwanted folder was created:" << created;
|
||||
#ifdef Q_OS_WIN
|
||||
if (created) {
|
||||
@@ -1979,10 +1977,10 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)
|
||||
|
||||
// Move wanted files back to their original folder
|
||||
if (priorities[i] > 0) {
|
||||
QString parentRelPath = Utils::Fs::branchPath(filepath);
|
||||
const QString parentRelPath = Utils::Fs::branchPath(filepath);
|
||||
if (QDir(parentRelPath).dirName() == ".unwanted") {
|
||||
QString oldName = Utils::Fs::fileName(filepath);
|
||||
QString newRelPath = Utils::Fs::branchPath(parentRelPath);
|
||||
const QString oldName = Utils::Fs::fileName(filepath);
|
||||
const QString newRelPath = Utils::Fs::branchPath(parentRelPath);
|
||||
if (newRelPath.isEmpty())
|
||||
renameFile(i, oldName);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user