mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-09 17:12:31 -06:00
committed by
GitHub
parent
02892d1250
commit
2631692cff
@@ -33,7 +33,7 @@
|
|||||||
#include <concepts>
|
#include <concepts>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <queue>
|
#include <ranges>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
@@ -2569,52 +2569,20 @@ bool SessionImpl::cancelDownloadMetadata(const TorrentID &id)
|
|||||||
|
|
||||||
void SessionImpl::increaseTorrentsQueuePos(const QList<TorrentID> &ids)
|
void SessionImpl::increaseTorrentsQueuePos(const QList<TorrentID> &ids)
|
||||||
{
|
{
|
||||||
using ElementType = std::pair<int, const TorrentImpl *>;
|
|
||||||
std::priority_queue<ElementType
|
|
||||||
, std::vector<ElementType>
|
|
||||||
, std::greater<ElementType>> torrentQueue;
|
|
||||||
|
|
||||||
// Sort torrents by queue position
|
|
||||||
for (const TorrentID &id : ids)
|
|
||||||
{
|
|
||||||
const TorrentImpl *torrent = m_torrents.value(id);
|
|
||||||
if (!torrent) continue;
|
|
||||||
if (const int position = torrent->queuePosition(); position >= 0)
|
|
||||||
torrentQueue.emplace(position, torrent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increase torrents queue position (starting with the one in the highest queue position)
|
// Increase torrents queue position (starting with the one in the highest queue position)
|
||||||
while (!torrentQueue.empty())
|
for (TorrentImpl *torrent : asConst(getQueuedTorrentsByID(ids)))
|
||||||
{
|
|
||||||
const TorrentImpl *torrent = torrentQueue.top().second;
|
|
||||||
torrentQueuePositionUp(torrent->nativeHandle());
|
torrentQueuePositionUp(torrent->nativeHandle());
|
||||||
torrentQueue.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_torrentsQueueChanged = true;
|
m_torrentsQueueChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionImpl::decreaseTorrentsQueuePos(const QList<TorrentID> &ids)
|
void SessionImpl::decreaseTorrentsQueuePos(const QList<TorrentID> &ids)
|
||||||
{
|
{
|
||||||
using ElementType = std::pair<int, const TorrentImpl *>;
|
const QList<TorrentImpl *> queuedTorrents = getQueuedTorrentsByID(ids);
|
||||||
std::priority_queue<ElementType> torrentQueue;
|
|
||||||
|
|
||||||
// Sort torrents by queue position
|
|
||||||
for (const TorrentID &id : ids)
|
|
||||||
{
|
|
||||||
const TorrentImpl *torrent = m_torrents.value(id);
|
|
||||||
if (!torrent) continue;
|
|
||||||
if (const int position = torrent->queuePosition(); position >= 0)
|
|
||||||
torrentQueue.emplace(position, torrent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decrease torrents queue position (starting with the one in the lowest queue position)
|
// Decrease torrents queue position (starting with the one in the lowest queue position)
|
||||||
while (!torrentQueue.empty())
|
for (TorrentImpl *torrent : (queuedTorrents | std::views::reverse))
|
||||||
{
|
|
||||||
const TorrentImpl *torrent = torrentQueue.top().second;
|
|
||||||
torrentQueuePositionDown(torrent->nativeHandle());
|
torrentQueuePositionDown(torrent->nativeHandle());
|
||||||
torrentQueue.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const lt::torrent_handle &torrentHandle : asConst(m_downloadedMetadata))
|
for (const lt::torrent_handle &torrentHandle : asConst(m_downloadedMetadata))
|
||||||
torrentQueuePositionBottom(torrentHandle);
|
torrentQueuePositionBottom(torrentHandle);
|
||||||
@@ -2624,52 +2592,20 @@ void SessionImpl::decreaseTorrentsQueuePos(const QList<TorrentID> &ids)
|
|||||||
|
|
||||||
void SessionImpl::topTorrentsQueuePos(const QList<TorrentID> &ids)
|
void SessionImpl::topTorrentsQueuePos(const QList<TorrentID> &ids)
|
||||||
{
|
{
|
||||||
using ElementType = std::pair<int, const TorrentImpl *>;
|
const QList<TorrentImpl *> queuedTorrents = getQueuedTorrentsByID(ids);
|
||||||
std::priority_queue<ElementType> torrentQueue;
|
|
||||||
|
|
||||||
// Sort torrents by queue position
|
|
||||||
for (const TorrentID &id : ids)
|
|
||||||
{
|
|
||||||
const TorrentImpl *torrent = m_torrents.value(id);
|
|
||||||
if (!torrent) continue;
|
|
||||||
if (const int position = torrent->queuePosition(); position >= 0)
|
|
||||||
torrentQueue.emplace(position, torrent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Top torrents queue position (starting with the one in the lowest queue position)
|
// Top torrents queue position (starting with the one in the lowest queue position)
|
||||||
while (!torrentQueue.empty())
|
for (TorrentImpl *torrent : (queuedTorrents | std::views::reverse))
|
||||||
{
|
|
||||||
const TorrentImpl *torrent = torrentQueue.top().second;
|
|
||||||
torrentQueuePositionTop(torrent->nativeHandle());
|
torrentQueuePositionTop(torrent->nativeHandle());
|
||||||
torrentQueue.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_torrentsQueueChanged = true;
|
m_torrentsQueueChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionImpl::bottomTorrentsQueuePos(const QList<TorrentID> &ids)
|
void SessionImpl::bottomTorrentsQueuePos(const QList<TorrentID> &ids)
|
||||||
{
|
{
|
||||||
using ElementType = std::pair<int, const TorrentImpl *>;
|
|
||||||
std::priority_queue<ElementType
|
|
||||||
, std::vector<ElementType>
|
|
||||||
, std::greater<ElementType>> torrentQueue;
|
|
||||||
|
|
||||||
// Sort torrents by queue position
|
|
||||||
for (const TorrentID &id : ids)
|
|
||||||
{
|
|
||||||
const TorrentImpl *torrent = m_torrents.value(id);
|
|
||||||
if (!torrent) continue;
|
|
||||||
if (const int position = torrent->queuePosition(); position >= 0)
|
|
||||||
torrentQueue.emplace(position, torrent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bottom torrents queue position (starting with the one in the highest queue position)
|
// Bottom torrents queue position (starting with the one in the highest queue position)
|
||||||
while (!torrentQueue.empty())
|
for (TorrentImpl *torrent : asConst(getQueuedTorrentsByID(ids)))
|
||||||
{
|
|
||||||
const TorrentImpl *torrent = torrentQueue.top().second;
|
|
||||||
torrentQueuePositionBottom(torrent->nativeHandle());
|
torrentQueuePositionBottom(torrent->nativeHandle());
|
||||||
torrentQueue.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const lt::torrent_handle &torrentHandle : asConst(m_downloadedMetadata))
|
for (const lt::torrent_handle &torrentHandle : asConst(m_downloadedMetadata))
|
||||||
torrentQueuePositionBottom(torrentHandle);
|
torrentQueuePositionBottom(torrentHandle);
|
||||||
@@ -5985,6 +5921,17 @@ TorrentImpl *SessionImpl::getTorrent(const lt::torrent_handle &nativeHandle) con
|
|||||||
return m_torrents.value(getInfoHash(nativeHandle).toTorrentID());
|
return m_torrents.value(getInfoHash(nativeHandle).toTorrentID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<TorrentImpl *> SessionImpl::getQueuedTorrentsByID(const QList<TorrentID> &torrentIDs) const
|
||||||
|
{
|
||||||
|
auto torrents = torrentIDs
|
||||||
|
| std::views::transform([this](const TorrentID &torrentID) { return m_torrents.value(torrentID); })
|
||||||
|
| std::views::filter([](const TorrentImpl *torrent) { return torrent && (torrent->queuePosition() >= 0); });
|
||||||
|
|
||||||
|
QList<TorrentImpl *> queuedTorrents = {torrents.begin(), torrents.end()};
|
||||||
|
std::ranges::sort(queuedTorrents, std::less<>(), &TorrentImpl::queuePosition);
|
||||||
|
return queuedTorrents;
|
||||||
|
}
|
||||||
|
|
||||||
void SessionImpl::handleTorrentRemovedAlert(const lt::torrent_removed_alert */*alert*/)
|
void SessionImpl::handleTorrentRemovedAlert(const lt::torrent_removed_alert */*alert*/)
|
||||||
{
|
{
|
||||||
// We cannot consider `torrent_removed_alert` as a starting point for removing content,
|
// We cannot consider `torrent_removed_alert` as a starting point for removing content,
|
||||||
|
|||||||
@@ -619,6 +619,7 @@ namespace BitTorrent
|
|||||||
|
|
||||||
TorrentImpl *createTorrent(const lt::torrent_handle &nativeHandle, LoadTorrentParams params);
|
TorrentImpl *createTorrent(const lt::torrent_handle &nativeHandle, LoadTorrentParams params);
|
||||||
TorrentImpl *getTorrent(const lt::torrent_handle &nativeHandle) const;
|
TorrentImpl *getTorrent(const lt::torrent_handle &nativeHandle) const;
|
||||||
|
QList<TorrentImpl *> getQueuedTorrentsByID(const QList<TorrentID> &torrentIDs) const;
|
||||||
|
|
||||||
void saveResumeData();
|
void saveResumeData();
|
||||||
void saveTorrentsQueue();
|
void saveTorrentsQueue();
|
||||||
|
|||||||
Reference in New Issue
Block a user