mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-26 19:26:59 +03:00
Remove confusing helpers from Session interface
Such helpers do not make practical sense, since they can be trivially implemented on top of the base interface, but at the same time they can lead to undesirable consequences when some calling code requires slightly different behavior than another. PR #18367. Fixes #18338.
This commit is contained in:
parent
9cdf660ddb
commit
719e4afd8c
4 changed files with 22 additions and 34 deletions
|
@ -403,9 +403,6 @@ namespace BitTorrent
|
|||
virtual Torrent *findTorrent(const InfoHash &infoHash) const = 0;
|
||||
virtual QVector<Torrent *> torrents() const = 0;
|
||||
virtual qsizetype torrentsCount() const = 0;
|
||||
virtual bool hasActiveTorrents() const = 0;
|
||||
virtual bool hasUnfinishedTorrents() const = 0;
|
||||
virtual bool hasRunningSeed() const = 0;
|
||||
virtual const SessionStatus &status() const = 0;
|
||||
virtual const CacheStatus &cacheStatus() const = 0;
|
||||
virtual bool isListening() const = 0;
|
||||
|
|
|
@ -2228,30 +2228,6 @@ Torrent *SessionImpl::findTorrent(const InfoHash &infoHash) const
|
|||
return m_torrents.value(altID);
|
||||
}
|
||||
|
||||
bool SessionImpl::hasActiveTorrents() const
|
||||
{
|
||||
return std::any_of(m_torrents.begin(), m_torrents.end(), [](TorrentImpl *torrent)
|
||||
{
|
||||
return TorrentFilter::ActiveTorrent.match(torrent);
|
||||
});
|
||||
}
|
||||
|
||||
bool SessionImpl::hasUnfinishedTorrents() const
|
||||
{
|
||||
return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentImpl *torrent)
|
||||
{
|
||||
return (!torrent->isSeed() && !torrent->isPaused() && !torrent->isErrored() && torrent->hasMetadata());
|
||||
});
|
||||
}
|
||||
|
||||
bool SessionImpl::hasRunningSeed() const
|
||||
{
|
||||
return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentImpl *torrent)
|
||||
{
|
||||
return (torrent->isSeed() && !torrent->isPaused());
|
||||
});
|
||||
}
|
||||
|
||||
void SessionImpl::banIP(const QString &ip)
|
||||
{
|
||||
if (m_bannedIPs.get().contains(ip))
|
||||
|
@ -4771,7 +4747,11 @@ void SessionImpl::handleTorrentFinished(TorrentImpl *const torrent)
|
|||
}
|
||||
}
|
||||
|
||||
if (!hasUnfinishedTorrents())
|
||||
const bool hasUnfinishedTorrents = std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent)
|
||||
{
|
||||
return !(torrent->isSeed() || torrent->isPaused() || torrent->isErrored());
|
||||
});
|
||||
if (!hasUnfinishedTorrents)
|
||||
emit allTorrentsFinished();
|
||||
}
|
||||
|
||||
|
|
|
@ -380,9 +380,6 @@ namespace BitTorrent
|
|||
Torrent *findTorrent(const InfoHash &infoHash) const override;
|
||||
QVector<Torrent *> torrents() const override;
|
||||
qsizetype torrentsCount() const override;
|
||||
bool hasActiveTorrents() const override;
|
||||
bool hasUnfinishedTorrents() const override;
|
||||
bool hasRunningSeed() const override;
|
||||
const SessionStatus &status() const override;
|
||||
const CacheStatus &cacheStatus() const override;
|
||||
bool isListening() const override;
|
||||
|
|
|
@ -1134,7 +1134,12 @@ void MainWindow::closeEvent(QCloseEvent *e)
|
|||
}
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
if (pref->confirmOnExit() && BitTorrent::Session::instance()->hasActiveTorrents())
|
||||
const QVector<BitTorrent::Torrent *> allTorrents = BitTorrent::Session::instance()->torrents();
|
||||
const bool hasActiveTorrents = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [](BitTorrent::Torrent *torrent)
|
||||
{
|
||||
return torrent->isActive();
|
||||
});
|
||||
if (pref->confirmOnExit() && hasActiveTorrents)
|
||||
{
|
||||
if (e->spontaneous() || m_forceExit)
|
||||
{
|
||||
|
@ -1898,8 +1903,17 @@ void MainWindow::on_actionAutoShutdown_toggled(bool enabled)
|
|||
|
||||
void MainWindow::updatePowerManagementState()
|
||||
{
|
||||
const bool inhibitSuspend = (Preferences::instance()->preventFromSuspendWhenDownloading() && BitTorrent::Session::instance()->hasUnfinishedTorrents())
|
||||
|| (Preferences::instance()->preventFromSuspendWhenSeeding() && BitTorrent::Session::instance()->hasRunningSeed());
|
||||
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());
|
||||
});
|
||||
const bool hasRunningSeed = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [](const BitTorrent::Torrent *torrent)
|
||||
{
|
||||
return (torrent->isSeed() && !torrent->isPaused());
|
||||
});
|
||||
const bool inhibitSuspend = (Preferences::instance()->preventFromSuspendWhenDownloading() && hasUnfinishedTorrents)
|
||||
|| (Preferences::instance()->preventFromSuspendWhenSeeding() && hasRunningSeed);
|
||||
m_pwr->setActivityState(inhibitSuspend);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue