diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index 3941bc28e..e9f089918 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -323,11 +323,11 @@ bool Utils::Misc::isPreviewable(const QString &extension) return multimediaExtensions.contains(extension.toUpper()); } -// Take a number of seconds and return an user-friendly -// time duration like "1d 2h 10m". -QString Utils::Misc::userFriendlyDuration(const qlonglong seconds) +QString Utils::Misc::userFriendlyDuration(const qlonglong seconds, const qlonglong maxCap) { - if ((seconds < 0) || (seconds >= MAX_ETA)) + if (seconds < 0) + return QString::fromUtf8(C_INFINITY); + if ((maxCap >= 0) && (seconds >= maxCap)) return QString::fromUtf8(C_INFINITY); if (seconds == 0) @@ -336,21 +336,25 @@ QString Utils::Misc::userFriendlyDuration(const qlonglong seconds) if (seconds < 60) return QCoreApplication::translate("misc", "< 1m", "< 1 minute"); - qlonglong minutes = seconds / 60; + qlonglong minutes = (seconds / 60); if (minutes < 60) return QCoreApplication::translate("misc", "%1m", "e.g: 10minutes").arg(QString::number(minutes)); - qlonglong hours = minutes / 60; - minutes -= hours * 60; - if (hours < 24) + qlonglong hours = (minutes / 60); + if (hours < 24) { + minutes -= (hours * 60); return QCoreApplication::translate("misc", "%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours), QString::number(minutes)); + } - qlonglong days = hours / 24; - hours -= days * 24; - if (days < 100) + qlonglong days = (hours / 24); + if (days < 365) { + hours -= (days * 24); return QCoreApplication::translate("misc", "%1d %2h", "e.g: 2days 10hours").arg(QString::number(days), QString::number(hours)); + } - return QString::fromUtf8(C_INFINITY); + qlonglong years = (days / 365); + days -= (years * 365); + return QCoreApplication::translate("misc", "%1y %2d", "e.g: 2years 10days").arg(QString::number(years), QString::number(days)); } QString Utils::Misc::getUserIDString() diff --git a/src/base/utils/misc.h b/src/base/utils/misc.h index c83918ed0..31e6fb3a7 100644 --- a/src/base/utils/misc.h +++ b/src/base/utils/misc.h @@ -84,7 +84,7 @@ namespace Utils // Take a number of seconds and return a user-friendly // time duration like "1d 2h 10m". - QString userFriendlyDuration(qlonglong seconds); + QString userFriendlyDuration(qlonglong seconds, qlonglong maxCap = -1); QString getUserIDString(); #ifdef Q_OS_WIN diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 196d2fa68..229eaf444 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -420,7 +420,7 @@ void PropertiesWidget::loadDynamicData() .arg(m_torrent->connectionsCount()) .arg(m_torrent->connectionsLimit() < 0 ? QString::fromUtf8(C_INFINITY) : QString::number(m_torrent->connectionsLimit()))); - m_ui->labelETAVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->eta())); + m_ui->labelETAVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->eta(), MAX_ETA)); // Update next announce time m_ui->labelReannounceInVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->nextAnnounce())); diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index cfd0550c0..1ece77805 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -82,7 +82,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem & break; case TransferListModel::TR_ETA: { opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong())); + QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong(), MAX_ETA)); break; } case TransferListModel::TR_SEEDS: