mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-07 16:12:30 -06:00
Add ability to pause/resume entire BitTorrent session
PR #20757. Closes #18993.
This commit is contained in:
committed by
GitHub
parent
05416458db
commit
8ef7d3ec9a
@@ -430,9 +430,15 @@ namespace BitTorrent
|
||||
virtual void setResumeDataStorageType(ResumeDataStorageType type) = 0;
|
||||
virtual bool isMergeTrackersEnabled() const = 0;
|
||||
virtual void setMergeTrackersEnabled(bool enabled) = 0;
|
||||
virtual bool isStartPaused() const = 0;
|
||||
virtual void setStartPaused(bool value) = 0;
|
||||
|
||||
virtual bool isRestored() const = 0;
|
||||
|
||||
virtual bool isPaused() const = 0;
|
||||
virtual void pause() = 0;
|
||||
virtual void resume() = 0;
|
||||
|
||||
virtual Torrent *getTorrent(const TorrentID &id) const = 0;
|
||||
virtual Torrent *findTorrent(const InfoHash &infoHash) const = 0;
|
||||
virtual QVector<Torrent *> torrents() const = 0;
|
||||
@@ -466,6 +472,8 @@ namespace BitTorrent
|
||||
void loadTorrentFailed(const QString &error);
|
||||
void metadataDownloaded(const TorrentInfo &info);
|
||||
void restored();
|
||||
void paused();
|
||||
void resumed();
|
||||
void speedLimitModeChanged(bool alternative);
|
||||
void statsUpdated();
|
||||
void subcategoriesSupportChanged();
|
||||
|
||||
@@ -523,6 +523,7 @@ SessionImpl::SessionImpl(QObject *parent)
|
||||
, m_I2POutboundQuantity {BITTORRENT_SESSION_KEY(u"I2P/OutboundQuantity"_s), 3}
|
||||
, m_I2PInboundLength {BITTORRENT_SESSION_KEY(u"I2P/InboundLength"_s), 3}
|
||||
, m_I2POutboundLength {BITTORRENT_SESSION_KEY(u"I2P/OutboundLength"_s), 3}
|
||||
, m_startPaused {BITTORRENT_SESSION_KEY(u"StartPaused"_s)}
|
||||
, m_seedingLimitTimer {new QTimer(this)}
|
||||
, m_resumeDataTimer {new QTimer(this)}
|
||||
, m_ioThread {new QThread}
|
||||
@@ -1541,7 +1542,9 @@ void SessionImpl::endStartup(ResumeSessionContext *context)
|
||||
context->deleteLater();
|
||||
connect(context, &QObject::destroyed, this, [this]
|
||||
{
|
||||
m_nativeSession->resume();
|
||||
if (!m_isPaused)
|
||||
m_nativeSession->resume();
|
||||
|
||||
if (m_refreshEnqueued)
|
||||
m_refreshEnqueued = false;
|
||||
else
|
||||
@@ -3913,6 +3916,16 @@ void SessionImpl::setMergeTrackersEnabled(const bool enabled)
|
||||
m_isMergeTrackersEnabled = enabled;
|
||||
}
|
||||
|
||||
bool SessionImpl::isStartPaused() const
|
||||
{
|
||||
return m_startPaused.get(false);
|
||||
}
|
||||
|
||||
void SessionImpl::setStartPaused(const bool value)
|
||||
{
|
||||
m_startPaused = value;
|
||||
}
|
||||
|
||||
QStringList SessionImpl::bannedIPs() const
|
||||
{
|
||||
return m_bannedIPs;
|
||||
@@ -3923,6 +3936,35 @@ bool SessionImpl::isRestored() const
|
||||
return m_isRestored;
|
||||
}
|
||||
|
||||
bool SessionImpl::isPaused() const
|
||||
{
|
||||
return m_isPaused;
|
||||
}
|
||||
|
||||
void SessionImpl::pause()
|
||||
{
|
||||
if (!m_isPaused)
|
||||
{
|
||||
if (isRestored())
|
||||
m_nativeSession->pause();
|
||||
|
||||
m_isPaused = true;
|
||||
emit paused();
|
||||
}
|
||||
}
|
||||
|
||||
void SessionImpl::resume()
|
||||
{
|
||||
if (m_isPaused)
|
||||
{
|
||||
if (isRestored())
|
||||
m_nativeSession->resume();
|
||||
|
||||
m_isPaused = false;
|
||||
emit resumed();
|
||||
}
|
||||
}
|
||||
|
||||
int SessionImpl::maxConnectionsPerTorrent() const
|
||||
{
|
||||
return m_maxConnectionsPerTorrent;
|
||||
@@ -4370,6 +4412,9 @@ void SessionImpl::setQueueingSystemEnabled(const bool enabled)
|
||||
m_torrentsQueueChanged = true;
|
||||
else
|
||||
removeTorrentsQueue();
|
||||
|
||||
for (TorrentImpl *torrent : asConst(m_torrents))
|
||||
torrent->handleQueueingModeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -407,9 +407,15 @@ namespace BitTorrent
|
||||
void setResumeDataStorageType(ResumeDataStorageType type) override;
|
||||
bool isMergeTrackersEnabled() const override;
|
||||
void setMergeTrackersEnabled(bool enabled) override;
|
||||
bool isStartPaused() const override;
|
||||
void setStartPaused(bool value) override;
|
||||
|
||||
bool isRestored() const override;
|
||||
|
||||
bool isPaused() const override;
|
||||
void pause() override;
|
||||
void resume() override;
|
||||
|
||||
Torrent *getTorrent(const TorrentID &id) const override;
|
||||
Torrent *findTorrent(const InfoHash &infoHash) const override;
|
||||
QVector<Torrent *> torrents() const override;
|
||||
@@ -722,8 +728,10 @@ namespace BitTorrent
|
||||
CachedSettingValue<int> m_I2POutboundQuantity;
|
||||
CachedSettingValue<int> m_I2PInboundLength;
|
||||
CachedSettingValue<int> m_I2POutboundLength;
|
||||
SettingValue<bool> m_startPaused;
|
||||
|
||||
bool m_isRestored = false;
|
||||
bool m_isPaused = isStartPaused();
|
||||
|
||||
// Order is important. This needs to be declared after its CachedSettingsValue
|
||||
// counterpart, because it uses it for initialization in the constructor
|
||||
|
||||
@@ -999,6 +999,9 @@ bool TorrentImpl::isStopped() const
|
||||
|
||||
bool TorrentImpl::isQueued() const
|
||||
{
|
||||
if (!m_session->isQueueingSystemEnabled())
|
||||
return false;
|
||||
|
||||
// Torrent is Queued if it isn't in Stopped state but paused internally
|
||||
return (!isStopped()
|
||||
&& (m_nativeStatus.flags & lt::torrent_flags::auto_managed)
|
||||
@@ -1153,7 +1156,7 @@ void TorrentImpl::updateState()
|
||||
{
|
||||
if (isStopped())
|
||||
m_state = TorrentState::StoppedDownloading;
|
||||
else if (m_session->isQueueingSystemEnabled() && isQueued())
|
||||
else if (isQueued())
|
||||
m_state = TorrentState::QueuedDownloading;
|
||||
else
|
||||
m_state = isForced() ? TorrentState::ForcedDownloadingMetadata : TorrentState::DownloadingMetadata;
|
||||
@@ -1167,7 +1170,7 @@ void TorrentImpl::updateState()
|
||||
{
|
||||
if (isStopped())
|
||||
m_state = TorrentState::StoppedUploading;
|
||||
else if (m_session->isQueueingSystemEnabled() && isQueued())
|
||||
else if (isQueued())
|
||||
m_state = TorrentState::QueuedUploading;
|
||||
else if (isForced())
|
||||
m_state = TorrentState::ForcedUploading;
|
||||
@@ -1180,7 +1183,7 @@ void TorrentImpl::updateState()
|
||||
{
|
||||
if (isStopped())
|
||||
m_state = TorrentState::StoppedDownloading;
|
||||
else if (m_session->isQueueingSystemEnabled() && isQueued())
|
||||
else if (isQueued())
|
||||
m_state = TorrentState::QueuedDownloading;
|
||||
else if (isForced())
|
||||
m_state = TorrentState::ForcedDownloading;
|
||||
@@ -1963,6 +1966,11 @@ void TorrentImpl::handleStateUpdate(const lt::torrent_status &nativeStatus)
|
||||
updateStatus(nativeStatus);
|
||||
}
|
||||
|
||||
void TorrentImpl::handleQueueingModeChanged()
|
||||
{
|
||||
updateState();
|
||||
}
|
||||
|
||||
void TorrentImpl::handleMoveStorageJobFinished(const Path &path, const MoveStorageContext context, const bool hasOutstandingJob)
|
||||
{
|
||||
if (context == MoveStorageContext::ChangeSavePath)
|
||||
|
||||
@@ -269,6 +269,7 @@ namespace BitTorrent
|
||||
|
||||
void handleAlert(const lt::alert *a);
|
||||
void handleStateUpdate(const lt::torrent_status &nativeStatus);
|
||||
void handleQueueingModeChanged();
|
||||
void handleCategoryOptionsChanged();
|
||||
void handleAppendExtensionToggled();
|
||||
void handleUnwantedFolderToggled();
|
||||
|
||||
@@ -1397,19 +1397,6 @@ void Preferences::setConfirmRemoveAllTags(const bool enabled)
|
||||
setValue(u"Preferences/Advanced/confirmRemoveAllTags"_s, enabled);
|
||||
}
|
||||
|
||||
bool Preferences::confirmPauseAndResumeAll() const
|
||||
{
|
||||
return value(u"GUI/ConfirmActions/PauseAndResumeAllTorrents"_s, true);
|
||||
}
|
||||
|
||||
void Preferences::setConfirmPauseAndResumeAll(const bool enabled)
|
||||
{
|
||||
if (enabled == confirmPauseAndResumeAll())
|
||||
return;
|
||||
|
||||
setValue(u"GUI/ConfirmActions/PauseAndResumeAllTorrents"_s, enabled);
|
||||
}
|
||||
|
||||
bool Preferences::confirmMergeTrackers() const
|
||||
{
|
||||
return value(u"GUI/ConfirmActions/MergeTrackers"_s, true);
|
||||
|
||||
@@ -305,8 +305,6 @@ public:
|
||||
void setConfirmTorrentRecheck(bool enabled);
|
||||
bool confirmRemoveAllTags() const;
|
||||
void setConfirmRemoveAllTags(bool enabled);
|
||||
bool confirmPauseAndResumeAll() const;
|
||||
void setConfirmPauseAndResumeAll(bool enabled);
|
||||
bool confirmMergeTrackers() const;
|
||||
void setConfirmMergeTrackers(bool enabled);
|
||||
bool confirmRemoveTrackerFromAllTorrents() const;
|
||||
|
||||
Reference in New Issue
Block a user