Use Start/Stop instead of Resume/Pause

PR #20532.

---------

Co-authored-by: Vladimir Golovnev (Glassez) <glassez@yandex.ru>
This commit is contained in:
thalieht
2024-03-25 18:11:04 +02:00
committed by GitHub
parent f2d6129db3
commit 5d1c249606
70 changed files with 413 additions and 391 deletions

View File

@@ -116,7 +116,7 @@ BitTorrent::AddTorrentParams BitTorrent::parseAddTorrentParams(const QJsonObject
.downloadPath = Path(jsonObj.value(PARAM_DOWNLOADPATH).toString()),
.addForced = (getEnum<TorrentOperatingMode>(jsonObj, PARAM_OPERATINGMODE) == TorrentOperatingMode::Forced),
.addToQueueTop = getOptionalBool(jsonObj, PARAM_QUEUETOP),
.addPaused = getOptionalBool(jsonObj, PARAM_STOPPED),
.addStopped = getOptionalBool(jsonObj, PARAM_STOPPED),
.stopCondition = getOptionalEnum<Torrent::StopCondition>(jsonObj, PARAM_STOPCONDITION),
.filePaths = {},
.filePriorities = {},
@@ -163,8 +163,8 @@ QJsonObject BitTorrent::serializeAddTorrentParams(const AddTorrentParams &params
if (params.addToQueueTop)
jsonObj[PARAM_QUEUETOP] = *params.addToQueueTop;
if (params.addPaused)
jsonObj[PARAM_STOPPED] = *params.addPaused;
if (params.addStopped)
jsonObj[PARAM_STOPPED] = *params.addStopped;
if (params.stopCondition)
jsonObj[PARAM_STOPCONDITION] = Utils::String::fromEnum(*params.stopCondition);
if (params.contentLayout)

View File

@@ -59,7 +59,7 @@ namespace BitTorrent
bool firstLastPiecePriority = false;
bool addForced = false;
std::optional<bool> addToQueueTop;
std::optional<bool> addPaused;
std::optional<bool> addStopped;
std::optional<Torrent::StopCondition> stopCondition;
PathList filePaths; // used if TorrentInfo is set
QVector<DownloadPriority> filePriorities; // used if TorrentInfo is set

View File

@@ -213,8 +213,8 @@ namespace BitTorrent
virtual void setPeXEnabled(bool enabled) = 0;
virtual bool isAddTorrentToQueueTop() const = 0;
virtual void setAddTorrentToQueueTop(bool value) = 0;
virtual bool isAddTorrentPaused() const = 0;
virtual void setAddTorrentPaused(bool value) = 0;
virtual bool isAddTorrentStopped() const = 0;
virtual void setAddTorrentStopped(bool value) = 0;
virtual Torrent::StopCondition torrentStopCondition() const = 0;
virtual void setTorrentStopCondition(Torrent::StopCondition stopCondition) = 0;
virtual TorrentContentLayout torrentContentLayout() const = 0;
@@ -476,8 +476,8 @@ namespace BitTorrent
void torrentFinished(Torrent *torrent);
void torrentFinishedChecking(Torrent *torrent);
void torrentMetadataReceived(Torrent *torrent);
void torrentPaused(Torrent *torrent);
void torrentResumed(Torrent *torrent);
void torrentStopped(Torrent *torrent);
void torrentStarted(Torrent *torrent);
void torrentSavePathChanged(Torrent *torrent);
void torrentSavingModeChanged(Torrent *torrent);
void torrentsLoaded(const QVector<Torrent *> &torrents);

View File

@@ -461,7 +461,7 @@ SessionImpl::SessionImpl(QObject *parent)
, m_globalMaxSeedingMinutes(BITTORRENT_SESSION_KEY(u"GlobalMaxSeedingMinutes"_s), -1, lowerLimited(-1))
, m_globalMaxInactiveSeedingMinutes(BITTORRENT_SESSION_KEY(u"GlobalMaxInactiveSeedingMinutes"_s), -1, lowerLimited(-1))
, m_isAddTorrentToQueueTop(BITTORRENT_SESSION_KEY(u"AddTorrentToTopOfQueue"_s), false)
, m_isAddTorrentPaused(BITTORRENT_SESSION_KEY(u"AddTorrentPaused"_s), false)
, m_isAddTorrentStopped(BITTORRENT_SESSION_KEY(u"AddTorrentStopped"_s), false)
, m_torrentStopCondition(BITTORRENT_SESSION_KEY(u"TorrentStopCondition"_s), Torrent::StopCondition::None)
, m_torrentContentLayout(BITTORRENT_SESSION_KEY(u"TorrentContentLayout"_s), TorrentContentLayout::Original)
, m_isAppendExtensionEnabled(BITTORRENT_SESSION_KEY(u"AddExtensionToIncompleteFiles"_s), false)
@@ -1114,14 +1114,14 @@ void SessionImpl::setAddTorrentToQueueTop(bool value)
m_isAddTorrentToQueueTop = value;
}
bool SessionImpl::isAddTorrentPaused() const
bool SessionImpl::isAddTorrentStopped() const
{
return m_isAddTorrentPaused;
return m_isAddTorrentStopped;
}
void SessionImpl::setAddTorrentPaused(const bool value)
void SessionImpl::setAddTorrentStopped(const bool value)
{
m_isAddTorrentPaused = value;
m_isAddTorrentStopped = value;
}
Torrent::StopCondition SessionImpl::torrentStopCondition() const
@@ -2274,12 +2274,12 @@ void SessionImpl::processShareLimits()
LogMsg(u"%1 %2 %3"_s.arg(description, tr("Removing torrent and deleting its content."), torrentName));
deleteTorrent(torrentID, DeleteTorrentAndFiles);
}
else if ((shareLimitAction == ShareLimitAction::Stop) && !torrent->isPaused())
else if ((shareLimitAction == ShareLimitAction::Stop) && !torrent->isStopped())
{
torrent->pause();
LogMsg(u"%1 %2 %3"_s.arg(description, tr("Torrent paused."), torrentName));
torrent->stop();
LogMsg(u"%1 %2 %3"_s.arg(description, tr("Torrent stopped."), torrentName));
}
else if ((shareLimitAction == ShareLimitAction::EnableSuperSeeding) && !torrent->isPaused() && !torrent->superSeeding())
else if ((shareLimitAction == ShareLimitAction::EnableSuperSeeding) && !torrent->isStopped() && !torrent->superSeeding())
{
torrent->setSuperSeeding(true);
LogMsg(u"%1 %2 %3"_s.arg(description, tr("Super seeding enabled."), torrentName));
@@ -2596,7 +2596,7 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
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());
loadTorrentParams.stopped = addTorrentParams.addStopped.value_or(isAddTorrentStopped());
loadTorrentParams.stopCondition = addTorrentParams.stopCondition.value_or(torrentStopCondition());
loadTorrentParams.addToQueueTop = addTorrentParams.addToQueueTop.value_or(isAddTorrentToQueueTop());
loadTorrentParams.ratioLimit = addTorrentParams.ratioLimit;
@@ -4896,7 +4896,7 @@ void SessionImpl::handleTorrentMetadataReceived(TorrentImpl *const torrent)
emit torrentMetadataReceived(torrent);
}
void SessionImpl::handleTorrentPaused(TorrentImpl *const torrent)
void SessionImpl::handleTorrentStopped(TorrentImpl *const torrent)
{
torrent->resetTrackerEntries();
@@ -4907,14 +4907,14 @@ void SessionImpl::handleTorrentPaused(TorrentImpl *const torrent)
updatedTrackerEntries.emplace(trackerEntry.url, trackerEntry);
emit trackerEntriesUpdated(torrent, updatedTrackerEntries);
LogMsg(tr("Torrent paused. Torrent: \"%1\"").arg(torrent->name()));
emit torrentPaused(torrent);
LogMsg(tr("Torrent stopped. Torrent: \"%1\"").arg(torrent->name()));
emit torrentStopped(torrent);
}
void SessionImpl::handleTorrentResumed(TorrentImpl *const torrent)
void SessionImpl::handleTorrentStarted(TorrentImpl *const torrent)
{
LogMsg(tr("Torrent resumed. Torrent: \"%1\"").arg(torrent->name()));
emit torrentResumed(torrent);
emit torrentStarted(torrent);
}
void SessionImpl::handleTorrentChecked(TorrentImpl *const torrent)
@@ -4932,7 +4932,7 @@ void SessionImpl::handleTorrentFinished(TorrentImpl *const torrent)
const bool hasUnfinishedTorrents = std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent)
{
return !(torrent->isFinished() || torrent->isPaused() || torrent->isErrored());
return !(torrent->isFinished() || torrent->isStopped() || torrent->isErrored());
});
if (!hasUnfinishedTorrents)
emit allTorrentsFinished();
@@ -6151,7 +6151,7 @@ void SessionImpl::updateTrackerEntries(lt::torrent_handle torrentHandle, QHash<s
, updatedTrackers = std::move(updatedTrackers)]
{
TorrentImpl *torrent = m_torrents.value(torrentHandle.info_hash());
if (!torrent || torrent->isPaused())
if (!torrent || torrent->isStopped())
return;
QHash<QString, TrackerEntry> updatedTrackerEntries;

View File

@@ -189,8 +189,8 @@ namespace BitTorrent
void setPeXEnabled(bool enabled) override;
bool isAddTorrentToQueueTop() const override;
void setAddTorrentToQueueTop(bool value) override;
bool isAddTorrentPaused() const override;
void setAddTorrentPaused(bool value) override;
bool isAddTorrentStopped() const override;
void setAddTorrentStopped(bool value) override;
Torrent::StopCondition torrentStopCondition() const override;
void setTorrentStopCondition(Torrent::StopCondition stopCondition) override;
TorrentContentLayout torrentContentLayout() const override;
@@ -439,8 +439,8 @@ namespace BitTorrent
void handleTorrentTagRemoved(TorrentImpl *torrent, const Tag &tag);
void handleTorrentSavingModeChanged(TorrentImpl *torrent);
void handleTorrentMetadataReceived(TorrentImpl *torrent);
void handleTorrentPaused(TorrentImpl *torrent);
void handleTorrentResumed(TorrentImpl *torrent);
void handleTorrentStopped(TorrentImpl *torrent);
void handleTorrentStarted(TorrentImpl *torrent);
void handleTorrentChecked(TorrentImpl *torrent);
void handleTorrentFinished(TorrentImpl *torrent);
void handleTorrentTrackersAdded(TorrentImpl *torrent, const QVector<TrackerEntry> &newTrackers);
@@ -663,7 +663,7 @@ namespace BitTorrent
CachedSettingValue<int> m_globalMaxSeedingMinutes;
CachedSettingValue<int> m_globalMaxInactiveSeedingMinutes;
CachedSettingValue<bool> m_isAddTorrentToQueueTop;
CachedSettingValue<bool> m_isAddTorrentPaused;
CachedSettingValue<bool> m_isAddTorrentStopped;
CachedSettingValue<Torrent::StopCondition> m_torrentStopCondition;
CachedSettingValue<TorrentContentLayout> m_torrentContentLayout;
CachedSettingValue<bool> m_isAppendExtensionEnabled;

View File

@@ -60,9 +60,9 @@ namespace BitTorrent
return infoHash().toTorrentID();
}
bool Torrent::isResumed() const
bool Torrent::isRunning() const
{
return !isPaused();
return !isStopped();
}
qlonglong Torrent::remainingSize() const

View File

@@ -94,8 +94,8 @@ namespace BitTorrent
CheckingUploading,
CheckingDownloading,
PausedDownloading,
PausedUploading,
StoppedDownloading,
StoppedUploading,
Moving,
@@ -228,7 +228,7 @@ namespace BitTorrent
virtual TorrentInfo info() const = 0;
virtual bool isFinished() const = 0;
virtual bool isPaused() const = 0;
virtual bool isStopped() const = 0;
virtual bool isQueued() const = 0;
virtual bool isForced() const = 0;
virtual bool isChecking() const = 0;
@@ -290,8 +290,8 @@ namespace BitTorrent
virtual void setName(const QString &name) = 0;
virtual void setSequentialDownload(bool enable) = 0;
virtual void setFirstLastPiecePriority(bool enabled) = 0;
virtual void pause() = 0;
virtual void resume(TorrentOperatingMode mode = TorrentOperatingMode::AutoManaged) = 0;
virtual void stop() = 0;
virtual void start(TorrentOperatingMode mode = TorrentOperatingMode::AutoManaged) = 0;
virtual void forceReannounce(int index = -1) = 0;
virtual void forceDHTAnnounce() = 0;
virtual void forceRecheck() = 0;
@@ -325,7 +325,7 @@ namespace BitTorrent
virtual void fetchDownloadingPieces(std::function<void (QBitArray)> resultHandler) const = 0;
TorrentID id() const;
bool isResumed() const;
bool isRunning() const;
qlonglong remainingSize() const;
void toggleSequentialDownload();

View File

@@ -981,15 +981,15 @@ TorrentInfo TorrentImpl::info() const
return m_torrentInfo;
}
bool TorrentImpl::isPaused() const
bool TorrentImpl::isStopped() const
{
return m_isStopped;
}
bool TorrentImpl::isQueued() const
{
// Torrent is Queued if it isn't in Paused state but paused internally
return (!isPaused()
// Torrent is Queued if it isn't in Stopped state but paused internally
return (!isStopped()
&& (m_nativeStatus.flags & lt::torrent_flags::auto_managed)
&& (m_nativeStatus.flags & lt::torrent_flags::paused));
}
@@ -1009,7 +1009,7 @@ bool TorrentImpl::isDownloading() const
case TorrentState::ForcedDownloadingMetadata:
case TorrentState::StalledDownloading:
case TorrentState::CheckingDownloading:
case TorrentState::PausedDownloading:
case TorrentState::StoppedDownloading:
case TorrentState::QueuedDownloading:
case TorrentState::ForcedDownloading:
return true;
@@ -1049,7 +1049,7 @@ bool TorrentImpl::isCompleted() const
case TorrentState::Uploading:
case TorrentState::StalledUploading:
case TorrentState::CheckingUploading:
case TorrentState::PausedUploading:
case TorrentState::StoppedUploading:
case TorrentState::QueuedUploading:
case TorrentState::ForcedUploading:
return true;
@@ -1102,7 +1102,7 @@ bool TorrentImpl::isFinished() const
bool TorrentImpl::isForced() const
{
return (!isPaused() && (m_operatingMode == TorrentOperatingMode::Forced));
return (!isStopped() && (m_operatingMode == TorrentOperatingMode::Forced));
}
bool TorrentImpl::isSequentialDownload() const
@@ -1140,22 +1140,22 @@ void TorrentImpl::updateState()
}
else if (!hasMetadata())
{
if (isPaused())
m_state = TorrentState::PausedDownloading;
if (isStopped())
m_state = TorrentState::StoppedDownloading;
else if (m_session->isQueueingSystemEnabled() && isQueued())
m_state = TorrentState::QueuedDownloading;
else
m_state = isForced() ? TorrentState::ForcedDownloadingMetadata : TorrentState::DownloadingMetadata;
}
else if ((m_nativeStatus.state == lt::torrent_status::checking_files) && !isPaused())
else if ((m_nativeStatus.state == lt::torrent_status::checking_files) && !isStopped())
{
// If the torrent is not just in the "checking" state, but is being actually checked
m_state = m_hasFinishedStatus ? TorrentState::CheckingUploading : TorrentState::CheckingDownloading;
}
else if (isFinished())
{
if (isPaused())
m_state = TorrentState::PausedUploading;
if (isStopped())
m_state = TorrentState::StoppedUploading;
else if (m_session->isQueueingSystemEnabled() && isQueued())
m_state = TorrentState::QueuedUploading;
else if (isForced())
@@ -1167,8 +1167,8 @@ void TorrentImpl::updateState()
}
else
{
if (isPaused())
m_state = TorrentState::PausedDownloading;
if (isStopped())
m_state = TorrentState::StoppedDownloading;
else if (m_session->isQueueingSystemEnabled() && isQueued())
m_state = TorrentState::QueuedDownloading;
else if (isForced())
@@ -1236,7 +1236,7 @@ qlonglong TorrentImpl::finishedTime() const
qlonglong TorrentImpl::eta() const
{
if (isPaused()) return MAX_ETA;
if (isStopped()) return MAX_ETA;
const SpeedSampleAvg speedAverage = m_payloadRateMonitor.average();
@@ -1499,14 +1499,14 @@ qreal TorrentImpl::realRatio() const
int TorrentImpl::uploadPayloadRate() const
{
// workaround: suppress the speed for paused state
return isPaused() ? 0 : m_nativeStatus.upload_payload_rate;
// workaround: suppress the speed for Stopped state
return isStopped() ? 0 : m_nativeStatus.upload_payload_rate;
}
int TorrentImpl::downloadPayloadRate() const
{
// workaround: suppress the speed for paused state
return isPaused() ? 0 : m_nativeStatus.download_payload_rate;
// workaround: suppress the speed for Stopped state
return isStopped() ? 0 : m_nativeStatus.download_payload_rate;
}
qlonglong TorrentImpl::totalPayloadUpload() const
@@ -1597,10 +1597,10 @@ void TorrentImpl::forceRecheck()
m_nativeStatus.pieces.clear_all();
m_nativeStatus.num_pieces = 0;
if (isPaused())
if (isStopped())
{
// When "force recheck" is applied on paused torrent, we temporarily resume it
resume();
// When "force recheck" is applied on Stopped torrent, we start them to perform checking
start();
m_stopCondition = StopCondition::FilesChecked;
}
}
@@ -1768,7 +1768,7 @@ void TorrentImpl::endReceivedMetadataHandling(const Path &savePath, const PathLi
p.flags |= lt::torrent_flags::paused;
p.flags &= ~lt::torrent_flags::auto_managed;
m_session->handleTorrentPaused(this);
m_session->handleTorrentStopped(this);
}
reload();
@@ -1836,14 +1836,14 @@ void TorrentImpl::reload()
}
}
void TorrentImpl::pause()
void TorrentImpl::stop()
{
if (!m_isStopped)
{
m_stopCondition = StopCondition::None;
m_isStopped = true;
deferredRequestResumeData();
m_session->handleTorrentPaused(this);
m_session->handleTorrentStopped(this);
}
if (m_maintenanceJob == MaintenanceJob::None)
@@ -1855,7 +1855,7 @@ void TorrentImpl::pause()
}
}
void TorrentImpl::resume(const TorrentOperatingMode mode)
void TorrentImpl::start(const TorrentOperatingMode mode)
{
if (hasError())
{
@@ -1878,7 +1878,7 @@ void TorrentImpl::resume(const TorrentOperatingMode mode)
{
m_isStopped = false;
deferredRequestResumeData();
m_session->handleTorrentResumed(this);
m_session->handleTorrentStarted(this);
}
if (m_maintenanceJob == MaintenanceJob::None)
@@ -1967,7 +1967,7 @@ void TorrentImpl::handleTorrentCheckedAlert([[maybe_unused]] const lt::torrent_c
}
if (stopCondition() == StopCondition::FilesChecked)
pause();
stop();
m_statusUpdatedTriggers.enqueue([this]()
{
@@ -1983,7 +1983,7 @@ void TorrentImpl::handleTorrentCheckedAlert([[maybe_unused]] const lt::torrent_c
adjustStorageLocation();
manageActualFilePaths();
if (!isPaused())
if (!isStopped())
{
// torrent is internally paused using NativeTorrentExtension after files checked
// so we need to resume it if there is no corresponding "stop condition" set
@@ -2468,7 +2468,7 @@ void TorrentImpl::setStopCondition(const StopCondition stopCondition)
if (stopCondition == m_stopCondition)
return;
if (isPaused())
if (isStopped())
return;
if ((stopCondition == StopCondition::MetadataReceived) && hasMetadata())

View File

@@ -157,7 +157,7 @@ namespace BitTorrent
TorrentInfo info() const override;
bool isFinished() const override;
bool isPaused() const override;
bool isStopped() const override;
bool isQueued() const override;
bool isForced() const override;
bool isChecking() const override;
@@ -222,8 +222,8 @@ namespace BitTorrent
void setName(const QString &name) override;
void setSequentialDownload(bool enable) override;
void setFirstLastPiecePriority(bool enabled) override;
void pause() override;
void resume(TorrentOperatingMode mode = TorrentOperatingMode::AutoManaged) override;
void stop() override;
void start(TorrentOperatingMode mode = TorrentOperatingMode::AutoManaged) override;
void forceReannounce(int index = -1) override;
void forceDHTAnnounce() override;
void forceRecheck() override;