Rename isSeed to isFinished to correctly represent its meaning

PR #18580.
This commit is contained in:
Vladimir Golovnev 2023-02-17 07:08:00 +03:00 committed by GitHub
parent 4c0ebc0e0f
commit 1e913f46f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 47 additions and 45 deletions

View file

@ -206,7 +206,7 @@ BitTorrent::LoadResumeDataResult BitTorrent::BencodeResumeDataStorage::loadTorre
LoadTorrentParams torrentParams;
torrentParams.category = fromLTString(resumeDataRoot.dict_find_string_value("qBt-category"));
torrentParams.name = fromLTString(resumeDataRoot.dict_find_string_value("qBt-name"));
torrentParams.hasSeedStatus = resumeDataRoot.dict_find_int_value("qBt-seedStatus");
torrentParams.hasFinishedStatus = resumeDataRoot.dict_find_int_value("qBt-seedStatus");
torrentParams.firstLastPiecePriority = resumeDataRoot.dict_find_int_value("qBt-firstLastPiecePriority");
torrentParams.seedingTimeLimit = resumeDataRoot.dict_find_int_value("qBt-seedingTimeLimit", Torrent::USE_GLOBAL_SEEDING_TIME);
@ -380,7 +380,7 @@ void BitTorrent::BencodeResumeDataStorage::Worker::store(const TorrentID &id, co
data["qBt-category"] = resumeData.category.toStdString();
data["qBt-tags"] = setToEntryList(resumeData.tags);
data["qBt-name"] = resumeData.name.toStdString();
data["qBt-seedStatus"] = resumeData.hasSeedStatus;
data["qBt-seedStatus"] = resumeData.hasFinishedStatus;
data["qBt-contentLayout"] = Utils::String::fromEnum(resumeData.contentLayout).toStdString();
data["qBt-firstLastPiecePriority"] = resumeData.firstLastPiecePriority;
data["qBt-stopCondition"] = Utils::String::fromEnum(resumeData.stopCondition).toStdString();

View file

@ -204,7 +204,7 @@ namespace BitTorrent
const QStringList tagList = tagsData.split(u',');
resumeData.tags.insert(tagList.cbegin(), tagList.cend());
}
resumeData.hasSeedStatus = query.value(DB_COLUMN_HAS_SEED_STATUS.name).toBool();
resumeData.hasFinishedStatus = query.value(DB_COLUMN_HAS_SEED_STATUS.name).toBool();
resumeData.firstLastPiecePriority = query.value(DB_COLUMN_HAS_OUTER_PIECES_PRIORITY.name).toBool();
resumeData.ratioLimit = query.value(DB_COLUMN_RATIO_LIMIT.name).toInt() / 1000.0;
resumeData.seedingTimeLimit = query.value(DB_COLUMN_SEEDING_TIME_LIMIT.name).toInt();
@ -704,7 +704,7 @@ void BitTorrent::DBResumeDataStorage::Worker::store(const TorrentID &id, const L
query.bindValue(DB_COLUMN_RATIO_LIMIT.placeholder, static_cast<int>(resumeData.ratioLimit * 1000));
query.bindValue(DB_COLUMN_SEEDING_TIME_LIMIT.placeholder, resumeData.seedingTimeLimit);
query.bindValue(DB_COLUMN_HAS_OUTER_PIECES_PRIORITY.placeholder, resumeData.firstLastPiecePriority);
query.bindValue(DB_COLUMN_HAS_SEED_STATUS.placeholder, resumeData.hasSeedStatus);
query.bindValue(DB_COLUMN_HAS_SEED_STATUS.placeholder, resumeData.hasFinishedStatus);
query.bindValue(DB_COLUMN_OPERATING_MODE.placeholder, Utils::String::fromEnum(resumeData.operatingMode));
query.bindValue(DB_COLUMN_STOPPED.placeholder, resumeData.stopped);
query.bindValue(DB_COLUMN_STOP_CONDITION.placeholder, Utils::String::fromEnum(resumeData.stopCondition));

View file

@ -52,7 +52,7 @@ namespace BitTorrent
TorrentOperatingMode operatingMode = TorrentOperatingMode::AutoManaged;
bool useAutoTMM = false;
bool firstLastPiecePriority = false;
bool hasSeedStatus = false;
bool hasFinishedStatus = false;
bool stopped = false;
Torrent::StopCondition stopCondition;

View file

@ -2061,7 +2061,7 @@ void SessionImpl::processShareLimits()
const QHash<TorrentID, TorrentImpl *> torrents {m_torrents};
for (TorrentImpl *const torrent : torrents)
{
if (torrent->isSeed() && !torrent->isForced())
if (torrent->isFinished() && !torrent->isForced())
{
if (torrent->ratioLimit() != Torrent::NO_RATIO_LIMIT)
{
@ -2541,7 +2541,7 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
loadTorrentParams.name = addTorrentParams.name;
loadTorrentParams.useAutoTMM = addTorrentParams.useAutoTMM.value_or(!isAutoTMMDisabledByDefault());
loadTorrentParams.firstLastPiecePriority = addTorrentParams.firstLastPiecePriority;
loadTorrentParams.hasSeedStatus = addTorrentParams.skipChecking; // do not react on 'torrent_finished_alert' when skipping
loadTorrentParams.hasFinishedStatus = addTorrentParams.skipChecking; // do not react on 'torrent_finished_alert' when skipping
loadTorrentParams.contentLayout = addTorrentParams.contentLayout.value_or(torrentContentLayout());
loadTorrentParams.operatingMode = (addTorrentParams.addForced ? TorrentOperatingMode::Forced : TorrentOperatingMode::AutoManaged);
loadTorrentParams.stopped = addTorrentParams.addPaused.value_or(isAddTorrentPaused());
@ -2674,7 +2674,7 @@ bool SessionImpl::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &so
loadTorrentParams.name = contentName;
}
if (!loadTorrentParams.hasSeedStatus)
if (!loadTorrentParams.hasFinishedStatus)
{
const Path actualDownloadPath = useAutoTMM
? categoryDownloadPath(loadTorrentParams.category) : loadTorrentParams.downloadPath;
@ -4736,7 +4736,7 @@ void SessionImpl::handleTorrentFinished(TorrentImpl *const torrent)
const bool hasUnfinishedTorrents = std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent)
{
return !(torrent->isSeed() || torrent->isPaused() || torrent->isErrored());
return !(torrent->isFinished() || torrent->isPaused() || torrent->isErrored());
});
if (!hasUnfinishedTorrents)
emit allTorrentsFinished();

View file

@ -217,7 +217,7 @@ namespace BitTorrent
virtual QVector<DownloadPriority> filePriorities() const = 0;
virtual TorrentInfo info() const = 0;
virtual bool isSeed() const = 0;
virtual bool isFinished() const = 0;
virtual bool isPaused() const = 0;
virtual bool isQueued() const = 0;
virtual bool isForced() const = 0;

View file

@ -254,7 +254,7 @@ TorrentImpl::TorrentImpl(SessionImpl *session, lt::session *nativeSession
, m_seedingTimeLimit(params.seedingTimeLimit)
, m_operatingMode(params.operatingMode)
, m_contentLayout(params.contentLayout)
, m_hasSeedStatus(params.hasSeedStatus)
, m_hasFinishedStatus(params.hasFinishedStatus)
, m_hasFirstLastPiecePriority(params.firstLastPiecePriority)
, m_useAutoTMM(params.useAutoTMM)
, m_isStopped(params.stopped)
@ -431,8 +431,7 @@ void TorrentImpl::setSavePath(const Path &path)
m_session->handleTorrentNeedSaveResumeData(this);
const bool isFinished = isSeed() || m_hasSeedStatus;
if (isFinished || downloadPath().isEmpty())
if (isFinished() || m_hasFinishedStatus || downloadPath().isEmpty())
moveStorage(savePath(), MoveStorageMode::KeepExistingFiles);
}
@ -455,8 +454,8 @@ void TorrentImpl::setDownloadPath(const Path &path)
m_session->handleTorrentNeedSaveResumeData(this);
const bool isFinished = isSeed() || m_hasSeedStatus;
if (!isFinished)
const bool isIncomplete = !(isFinished() || m_hasFinishedStatus);
if (isIncomplete)
moveStorage((m_downloadPath.isEmpty() ? savePath() : m_downloadPath), MoveStorageMode::KeepExistingFiles);
}
@ -999,7 +998,7 @@ bool TorrentImpl::isErrored() const
|| (m_state == TorrentState::Error));
}
bool TorrentImpl::isSeed() const
bool TorrentImpl::isFinished() const
{
return ((m_nativeStatus.state == lt::torrent_status::finished)
|| (m_nativeStatus.state == lt::torrent_status::seeding));
@ -1055,9 +1054,9 @@ void TorrentImpl::updateState()
else if ((m_nativeStatus.state == lt::torrent_status::checking_files) && !isPaused())
{
// If the torrent is not just in the "checking" state, but is being actually checked
m_state = m_hasSeedStatus ? TorrentState::CheckingUploading : TorrentState::CheckingDownloading;
m_state = m_hasFinishedStatus ? TorrentState::CheckingUploading : TorrentState::CheckingDownloading;
}
else if (isSeed())
else if (isFinished())
{
if (isPaused())
m_state = TorrentState::PausedUploading;
@ -1145,7 +1144,7 @@ qlonglong TorrentImpl::eta() const
const SpeedSampleAvg speedAverage = m_payloadRateMonitor.average();
if (isSeed())
if (isFinished())
{
const qreal maxRatioValue = maxRatio();
const int maxSeedingTimeValue = maxSeedingTime();
@ -1816,9 +1815,9 @@ void TorrentImpl::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p)
if (!m_hasMissingFiles)
{
if ((progress() < 1.0) && (wantedSize() > 0))
m_hasSeedStatus = false;
m_hasFinishedStatus = false;
else if (progress() == 1.0)
m_hasSeedStatus = true;
m_hasFinishedStatus = true;
adjustStorageLocation();
manageIncompleteFiles();
@ -1845,12 +1844,12 @@ void TorrentImpl::handleTorrentFinishedAlert(const lt::torrent_finished_alert *p
Q_UNUSED(p);
m_hasMissingFiles = false;
if (m_hasSeedStatus)
if (m_hasFinishedStatus)
return;
m_statusUpdatedTriggers.enqueue([this]()
{
m_hasSeedStatus = true;
m_hasFinishedStatus = true;
adjustStorageLocation();
manageIncompleteFiles();
@ -1977,7 +1976,7 @@ void TorrentImpl::prepareResumeData(const lt::add_torrent_params &params)
resumeData.ratioLimit = m_ratioLimit;
resumeData.seedingTimeLimit = m_seedingTimeLimit;
resumeData.firstLastPiecePriority = m_hasFirstLastPiecePriority;
resumeData.hasSeedStatus = m_hasSeedStatus;
resumeData.hasFinishedStatus = m_hasFinishedStatus;
resumeData.stopped = m_isStopped;
resumeData.stopCondition = m_stopCondition;
resumeData.operatingMode = m_operatingMode;
@ -2203,8 +2202,7 @@ void TorrentImpl::manageIncompleteFiles()
void TorrentImpl::adjustStorageLocation()
{
const Path downloadPath = this->downloadPath();
const bool isFinished = isSeed() || m_hasSeedStatus;
const Path targetPath = ((isFinished || downloadPath.isEmpty()) ? savePath() : downloadPath);
const Path targetPath = ((isFinished() || m_hasFinishedStatus || downloadPath.isEmpty()) ? savePath() : downloadPath);
if ((targetPath != actualStorageLocation()) || isMoveInProgress())
moveStorage(targetPath, MoveStorageMode::Overwrite);
@ -2677,7 +2675,7 @@ void TorrentImpl::prioritizeFiles(const QVector<DownloadPriority> &priorities)
&& (priorities[i] > DownloadPriority::Ignored)
&& !m_completedFiles.at(i))
{
m_hasSeedStatus = false;
m_hasFinishedStatus = false;
break;
}
}

View file

@ -139,7 +139,7 @@ namespace BitTorrent
QVector<DownloadPriority> filePriorities() const override;
TorrentInfo info() const override;
bool isSeed() const override;
bool isFinished() const override;
bool isPaused() const override;
bool isQueued() const override;
bool isForced() const override;
@ -340,7 +340,7 @@ namespace BitTorrent
int m_seedingTimeLimit;
TorrentOperatingMode m_operatingMode;
TorrentContentLayout m_contentLayout;
bool m_hasSeedStatus;
bool m_hasFinishedStatus;
bool m_hasMissingFiles = false;
bool m_hasFirstLastPiecePriority = false;
bool m_useAutoTMM;

View file

@ -1906,11 +1906,11 @@ void MainWindow::updatePowerManagementState()
const QVector<BitTorrent::Torrent *> allTorrents = BitTorrent::Session::instance()->torrents();
const bool hasUnfinishedTorrents = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [](const BitTorrent::Torrent *torrent)
{
return (!torrent->isSeed() && !torrent->isPaused() && !torrent->isErrored() && torrent->hasMetadata());
return (!torrent->isFinished() && !torrent->isPaused() && !torrent->isErrored() && torrent->hasMetadata());
});
const bool hasRunningSeed = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [](const BitTorrent::Torrent *torrent)
{
return (torrent->isSeed() && !torrent->isPaused());
return (torrent->isFinished() && !torrent->isPaused());
});
const bool inhibitSuspend = (Preferences::instance()->preventFromSuspendWhenDownloading() && hasUnfinishedTorrents)
|| (Preferences::instance()->preventFromSuspendWhenSeeding() && hasRunningSeed);

View file

@ -378,12 +378,16 @@ void PropertiesWidget::loadDynamicData()
m_ui->labelDlLimitVal->setText(m_torrent->downloadLimit() <= 0 ? C_INFINITY : Utils::Misc::friendlyUnit(m_torrent->downloadLimit(), true));
QString elapsedString;
if (m_torrent->isSeed())
if (m_torrent->isFinished())
{
elapsedString = tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)")
.arg(Utils::Misc::userFriendlyDuration(m_torrent->activeTime())
, Utils::Misc::userFriendlyDuration(m_torrent->finishedTime()));
.arg(Utils::Misc::userFriendlyDuration(m_torrent->activeTime())
, Utils::Misc::userFriendlyDuration(m_torrent->finishedTime()));
}
else
{
elapsedString = Utils::Misc::userFriendlyDuration(m_torrent->activeTime());
}
m_ui->labelElapsedVal->setText(elapsedString);
m_ui->labelConnectionsVal->setText(tr("%1 (%2 max)", "%1 and %2 are numbers, e.g. 3 (10 max)")
@ -429,7 +433,7 @@ void PropertiesWidget::loadDynamicData()
m_ui->labelTotalPiecesVal->setText(tr("%1 x %2 (have %3)", "(torrent pieces) eg 152 x 4MB (have 25)").arg(m_torrent->piecesCount()).arg(Utils::Misc::friendlyUnit(m_torrent->pieceLength())).arg(m_torrent->piecesHave()));
if (!m_torrent->isSeed() && !m_torrent->isPaused() && !m_torrent->isQueued() && !m_torrent->isChecking())
if (!m_torrent->isFinished() && !m_torrent->isPaused() && !m_torrent->isQueued() && !m_torrent->isChecking())
{
// Pieces availability
showPiecesAvailability(true);

View file

@ -271,7 +271,7 @@ void TransferListWidget::torrentDoubleClicked()
if (!torrent) return;
int action;
if (torrent->isSeed())
if (torrent->isFinished())
action = Preferences::instance()->getActionOnDblClOnTorrentFn();
else
action = Preferences::instance()->getActionOnDblClOnTorrentDl();
@ -991,7 +991,7 @@ void TransferListWidget::displayListMenu()
bool superSeedingMode = false;
bool allSameSequentialDownloadMode = true, allSamePrioFirstlast = true;
bool sequentialDownloadMode = false, prioritizeFirstLast = false;
bool oneHasMetadata = false, oneNotSeed = false;
bool oneHasMetadata = false, oneNotFinished = false;
bool allSameCategory = true;
bool allSameAutoTMM = true;
bool firstAutoTMM = false;
@ -1032,9 +1032,9 @@ void TransferListWidget::displayListMenu()
if (torrent->hasMetadata())
oneHasMetadata = true;
if (!torrent->isSeed())
if (!torrent->isFinished())
{
oneNotSeed = true;
oneNotFinished = true;
if (first)
{
sequentialDownloadMode = torrent->isSequentialDownload();
@ -1050,7 +1050,7 @@ void TransferListWidget::displayListMenu()
}
else
{
if (!oneNotSeed && allSameSuperSeeding && torrent->hasMetadata())
if (!oneNotFinished && allSameSuperSeeding && torrent->hasMetadata())
{
if (first)
superSeedingMode = torrent->superSeeding();
@ -1100,7 +1100,7 @@ void TransferListWidget::displayListMenu()
if (!isPaused && !rechecking && !queued)
oneCanForceReannounce = true;
if (oneHasMetadata && oneNotSeed && !allSameSequentialDownloadMode
if (oneHasMetadata && oneNotFinished && !allSameSequentialDownloadMode
&& !allSamePrioFirstlast && !allSameSuperSeeding && !allSameCategory
&& needsStart && needsForce && needsPause && needsPreview && !allSameAutoTMM
&& hasInfohashV1 && hasInfohashV2 && oneCanForceReannounce)
@ -1193,7 +1193,7 @@ void TransferListWidget::displayListMenu()
listMenu->addSeparator();
listMenu->addAction(actionTorrentOptions);
if (!oneNotSeed && oneHasMetadata)
if (!oneNotFinished && oneHasMetadata)
{
actionSuperSeedingMode->setCheckState(allSameSuperSeeding
? (superSeedingMode ? Qt::Checked : Qt::Unchecked)
@ -1207,7 +1207,7 @@ void TransferListWidget::displayListMenu()
listMenu->addAction(actionPreviewFile);
addedPreviewAction = true;
}
if (oneNotSeed)
if (oneNotFinished)
{
actionSequentialDownload->setCheckState(allSameSequentialDownloadMode
? (sequentialDownloadMode ? Qt::Checked : Qt::Unchecked)
@ -1234,7 +1234,7 @@ void TransferListWidget::displayListMenu()
actionForceReannounce->setToolTip(tr("Can not force reannounce if torrent is Paused/Queued/Errored/Checking"));
listMenu->addSeparator();
listMenu->addAction(actionOpenDestinationFolder);
if (BitTorrent::Session::instance()->isQueueingSystemEnabled() && oneNotSeed)
if (BitTorrent::Session::instance()->isQueueingSystemEnabled() && oneNotFinished)
{
listMenu->addSeparator();
QMenu *queueMenu = listMenu->addMenu(

View file

@ -593,7 +593,7 @@ void TorrentsController::filesAction()
fileDict[KEY_FILE_PIECE_RANGE] = QJsonArray {idx.first(), idx.last()};
if (index == 0)
fileDict[KEY_FILE_IS_SEED] = torrent->isSeed();
fileDict[KEY_FILE_IS_SEED] = torrent->isFinished();
fileList.append(fileDict);
}