mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-24 10:16:00 +03:00
Merge pull request #14363 from Chocobo1/queue_pos
Revise getter function for torrrent queue position
This commit is contained in:
commit
c8e8a44747
5 changed files with 46 additions and 42 deletions
|
@ -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))
|
||||
|
|
|
@ -632,8 +632,8 @@ namespace BitTorrent
|
|||
void createTorrent(const lt::torrent_handle &nativeHandle);
|
||||
|
||||
void saveResumeData();
|
||||
void saveTorrentsQueue();
|
||||
void removeTorrentsQueue();
|
||||
void saveTorrentsQueue() const;
|
||||
void removeTorrentsQueue() const;
|
||||
|
||||
std::vector<lt::alert *> getPendingAlerts(lt::time_duration time = lt::time_duration::zero()) const;
|
||||
|
||||
|
|
|
@ -818,9 +818,7 @@ bool TorrentImpl::hasFilteredPieces() const
|
|||
|
||||
int TorrentImpl::queuePosition() const
|
||||
{
|
||||
if (m_nativeStatus.queue_position < lt::queue_position_t {0}) return 0;
|
||||
|
||||
return static_cast<int>(m_nativeStatus.queue_position) + 1;
|
||||
return static_cast<int>(m_nativeStatus.queue_position);
|
||||
}
|
||||
|
||||
QString TorrentImpl::error() const
|
||||
|
|
|
@ -292,7 +292,7 @@ QString TransferListModel::displayValue(const BitTorrent::Torrent *torrent, cons
|
|||
|
||||
const auto queuePositionString = [](const qint64 value) -> QString
|
||||
{
|
||||
return (value > 0) ? QString::number(value) : QLatin1String("*");
|
||||
return (value >= 0) ? QString::number(value + 1) : QLatin1String("*");
|
||||
};
|
||||
|
||||
const auto lastActivityString = [hideValues](qint64 value) -> QString
|
||||
|
|
|
@ -85,8 +85,24 @@ namespace
|
|||
|
||||
QVariantMap serialize(const BitTorrent::Torrent &torrent)
|
||||
{
|
||||
QVariantMap ret =
|
||||
const auto adjustQueuePosition = [](const int position) -> int
|
||||
{
|
||||
return (position < 0) ? 0 : (position + 1);
|
||||
};
|
||||
|
||||
const auto adjustRatio = [](const qreal ratio) -> qreal
|
||||
{
|
||||
return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
|
||||
};
|
||||
|
||||
const auto adjustLastActivity = [&torrent](const qlonglong value) -> qlonglong
|
||||
{
|
||||
return (torrent.isPaused() || torrent.isChecking())
|
||||
? 0
|
||||
: (QDateTime::currentDateTime().toSecsSinceEpoch() - value);
|
||||
};
|
||||
|
||||
return {
|
||||
{KEY_TORRENT_HASH, QString(torrent.hash())},
|
||||
{KEY_TORRENT_NAME, torrent.name()},
|
||||
{KEY_TORRENT_MAGNET_URI, torrent.createMagnetURI()},
|
||||
|
@ -94,7 +110,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
|
|||
{KEY_TORRENT_PROGRESS, torrent.progress()},
|
||||
{KEY_TORRENT_DLSPEED, torrent.downloadPayloadRate()},
|
||||
{KEY_TORRENT_UPSPEED, torrent.uploadPayloadRate()},
|
||||
{KEY_TORRENT_QUEUE_POSITION, torrent.queuePosition()},
|
||||
{KEY_TORRENT_QUEUE_POSITION, adjustQueuePosition(torrent.queuePosition())},
|
||||
{KEY_TORRENT_SEEDS, torrent.seedsCount()},
|
||||
{KEY_TORRENT_NUM_COMPLETE, torrent.totalSeedsCount()},
|
||||
{KEY_TORRENT_LEECHS, torrent.leechsCount()},
|
||||
|
@ -125,29 +141,15 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
|
|||
{KEY_TORRENT_AMOUNT_COMPLETED, torrent.completedSize()},
|
||||
{KEY_TORRENT_MAX_RATIO, torrent.maxRatio()},
|
||||
{KEY_TORRENT_MAX_SEEDING_TIME, torrent.maxSeedingTime()},
|
||||
{KEY_TORRENT_RATIO, adjustRatio(torrent.realRatio())},
|
||||
{KEY_TORRENT_RATIO_LIMIT, torrent.ratioLimit()},
|
||||
{KEY_TORRENT_SEEDING_TIME_LIMIT, torrent.seedingTimeLimit()},
|
||||
{KEY_TORRENT_LAST_SEEN_COMPLETE_TIME, torrent.lastSeenComplete().toSecsSinceEpoch()},
|
||||
{KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()},
|
||||
{KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},
|
||||
{KEY_TORRENT_LAST_ACTIVITY_TIME, adjustLastActivity(torrent.timeSinceActivity())},
|
||||
{KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()},
|
||||
|
||||
{KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}
|
||||
};
|
||||
|
||||
const qreal ratio = torrent.realRatio();
|
||||
ret[KEY_TORRENT_RATIO] = (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
|
||||
|
||||
if (torrent.isPaused() || torrent.isChecking())
|
||||
{
|
||||
ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
const qint64 dt = (QDateTime::currentDateTime().toSecsSinceEpoch()
|
||||
- torrent.timeSinceActivity());
|
||||
ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = dt;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue