Revise getter function for torrrent queue position

This addresses https://github.com/qbittorrent/qBittorrent/pull/14335#issuecomment-774667836

The WebAPI is not affected as a workaround is added.
This commit is contained in:
Chocobo1 2021-02-07 21:59:47 +08:00
parent e6033c952e
commit e46c88580a
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
5 changed files with 46 additions and 42 deletions

View file

@ -1887,7 +1887,7 @@ bool Session::cancelDownloadMetadata(const InfoHash &hash)
void Session::increaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
{
using ElementType = std::pair<int, TorrentImpl *>;
using ElementType = std::pair<int, const TorrentImpl *>;
std::priority_queue<ElementType
, std::vector<ElementType>
, std::greater<ElementType>> torrentQueue;
@ -1895,9 +1895,10 @@ void Session::increaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
// Sort torrents by queue position
for (const InfoHash &infoHash : hashes)
{
TorrentImpl *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed())
torrentQueue.emplace(torrent->queuePosition(), torrent);
const TorrentImpl *torrent = m_torrents.value(infoHash);
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)
@ -1913,15 +1914,16 @@ void Session::increaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
void Session::decreaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
{
using ElementType = std::pair<int, TorrentImpl *>;
using ElementType = std::pair<int, const TorrentImpl *>;
std::priority_queue<ElementType> torrentQueue;
// Sort torrents by queue position
for (const InfoHash &infoHash : hashes)
{
TorrentImpl *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed())
torrentQueue.emplace(torrent->queuePosition(), torrent);
const TorrentImpl *torrent = m_torrents.value(infoHash);
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)
@ -1940,15 +1942,16 @@ void Session::decreaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
void Session::topTorrentsQueuePos(const QVector<InfoHash> &hashes)
{
using ElementType = std::pair<int, TorrentImpl *>;
using ElementType = std::pair<int, const TorrentImpl *>;
std::priority_queue<ElementType> torrentQueue;
// Sort torrents by queue position
for (const InfoHash &infoHash : hashes)
{
TorrentImpl *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed())
torrentQueue.emplace(torrent->queuePosition(), torrent);
const TorrentImpl *torrent = m_torrents.value(infoHash);
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)
@ -1964,7 +1967,7 @@ void Session::topTorrentsQueuePos(const QVector<InfoHash> &hashes)
void Session::bottomTorrentsQueuePos(const QVector<InfoHash> &hashes)
{
using ElementType = std::pair<int, TorrentImpl *>;
using ElementType = std::pair<int, const TorrentImpl *>;
std::priority_queue<ElementType
, std::vector<ElementType>
, std::greater<ElementType>> torrentQueue;
@ -1972,9 +1975,10 @@ void Session::bottomTorrentsQueuePos(const QVector<InfoHash> &hashes)
// Sort torrents by queue position
for (const InfoHash &infoHash : hashes)
{
TorrentImpl *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed())
torrentQueue.emplace(torrent->queuePosition(), torrent);
const TorrentImpl *torrent = m_torrents.value(infoHash);
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)
@ -2363,7 +2367,7 @@ void Session::saveResumeData()
}
}
void Session::saveTorrentsQueue()
void Session::saveTorrentsQueue() const
{
// store hash in textual representation
QMap<int, QString> queue; // Use QMap since it should be ordered by key
@ -2390,7 +2394,7 @@ void Session::saveTorrentsQueue()
#endif
}
void Session::removeTorrentsQueue()
void Session::removeTorrentsQueue() const
{
const QString filename = QLatin1String {"queue"};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))