Browse Source

Merge pull request #14363 from Chocobo1/queue_pos

Revise getter function for torrrent queue position
adaptive-webui-19844
Mike Tzou 4 years ago committed by GitHub
parent
commit
c8e8a44747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      src/base/bittorrent/session.cpp
  2. 4
      src/base/bittorrent/session.h
  3. 4
      src/base/bittorrent/torrentimpl.cpp
  4. 2
      src/gui/transferlistmodel.cpp
  5. 38
      src/webui/api/serialize/serialize_torrent.cpp

40
src/base/bittorrent/session.cpp

@ -1887,7 +1887,7 @@ bool Session::cancelDownloadMetadata(const InfoHash &hash) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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() @@ -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() @@ -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))

4
src/base/bittorrent/session.h

@ -632,8 +632,8 @@ namespace BitTorrent @@ -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;

4
src/base/bittorrent/torrentimpl.cpp

@ -818,9 +818,7 @@ bool TorrentImpl::hasFilteredPieces() 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

2
src/gui/transferlistmodel.cpp

@ -292,7 +292,7 @@ QString TransferListModel::displayValue(const BitTorrent::Torrent *torrent, cons @@ -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

38
src/webui/api/serialize/serialize_torrent.cpp

@ -85,8 +85,24 @@ namespace @@ -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) @@ -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) @@ -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…
Cancel
Save