From 62493c672de36a908b2bc11e128b0273aad60798 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 22 Sep 2017 12:42:24 +0800 Subject: [PATCH] Fix last activity calculation. Closes #7461 `time_since_upload` & `time_since_download` can be -1, so filter them out --- src/base/bittorrent/torrenthandle.cpp | 8 ++++---- src/gui/transferlistdelegate.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 04c78806c..8616c8a27 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -27,6 +27,7 @@ * exception statement from your version. */ +#include #include #include @@ -1108,10 +1109,9 @@ int TorrentHandle::timeSinceDownload() const int TorrentHandle::timeSinceActivity() const { - if (m_nativeStatus.time_since_upload < m_nativeStatus.time_since_download) - return m_nativeStatus.time_since_upload; - else - return m_nativeStatus.time_since_download; + return ((m_nativeStatus.time_since_upload < 0) != (m_nativeStatus.time_since_download < 0)) + ? std::max(m_nativeStatus.time_since_upload, m_nativeStatus.time_since_download) + : std::min(m_nativeStatus.time_since_upload, m_nativeStatus.time_since_download); } int TorrentHandle::downloadLimit() const diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index 6187cc245..5275380fc 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -181,14 +181,14 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem if (hideValues && ((elapsed < 0) || (elapsed >= MAX_ETA))) break; - QString elapsedString; + // Show '< 1m ago' when elapsed time is 0 if (elapsed == 0) - // Show '< 1m ago' when elapsed time is 0 elapsed = 1; - else if (elapsed < 0) - elapsedString = Utils::Misc::userFriendlyDuration(elapsed); - else - elapsedString = tr("%1 ago", "e.g.: 1h 20m ago").arg(Utils::Misc::userFriendlyDuration(elapsed)); + + QString elapsedString = (elapsed >= 0) + ? tr("%1 ago", "e.g.: 1h 20m ago").arg(Utils::Misc::userFriendlyDuration(elapsed)) + : Utils::Misc::userFriendlyDuration(elapsed); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, elapsedString); break;