Browse Source

Support year unit in userFriendlyDuration()

adaptive-webui-19844
Chocobo1 6 years ago
parent
commit
516c968373
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 28
      src/base/utils/misc.cpp
  2. 2
      src/base/utils/misc.h
  3. 2
      src/gui/properties/propertieswidget.cpp
  4. 2
      src/gui/transferlistdelegate.cpp

28
src/base/utils/misc.cpp

@ -323,11 +323,11 @@ bool Utils::Misc::isPreviewable(const QString &extension)
return multimediaExtensions.contains(extension.toUpper()); return multimediaExtensions.contains(extension.toUpper());
} }
// Take a number of seconds and return an user-friendly QString Utils::Misc::userFriendlyDuration(const qlonglong seconds, const qlonglong maxCap)
// time duration like "1d 2h 10m".
QString Utils::Misc::userFriendlyDuration(const qlonglong seconds)
{ {
if ((seconds < 0) || (seconds >= MAX_ETA)) if (seconds < 0)
return QString::fromUtf8(C_INFINITY);
if ((maxCap >= 0) && (seconds >= maxCap))
return QString::fromUtf8(C_INFINITY); return QString::fromUtf8(C_INFINITY);
if (seconds == 0) if (seconds == 0)
@ -336,21 +336,25 @@ QString Utils::Misc::userFriendlyDuration(const qlonglong seconds)
if (seconds < 60) if (seconds < 60)
return QCoreApplication::translate("misc", "< 1m", "< 1 minute"); return QCoreApplication::translate("misc", "< 1m", "< 1 minute");
qlonglong minutes = seconds / 60; qlonglong minutes = (seconds / 60);
if (minutes < 60) if (minutes < 60)
return QCoreApplication::translate("misc", "%1m", "e.g: 10minutes").arg(QString::number(minutes)); return QCoreApplication::translate("misc", "%1m", "e.g: 10minutes").arg(QString::number(minutes));
qlonglong hours = minutes / 60; qlonglong hours = (minutes / 60);
minutes -= hours * 60; if (hours < 24) {
if (hours < 24) minutes -= (hours * 60);
return QCoreApplication::translate("misc", "%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours), QString::number(minutes)); return QCoreApplication::translate("misc", "%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours), QString::number(minutes));
}
qlonglong days = hours / 24; qlonglong days = (hours / 24);
hours -= days * 24; if (days < 365) {
if (days < 100) hours -= (days * 24);
return QCoreApplication::translate("misc", "%1d %2h", "e.g: 2days 10hours").arg(QString::number(days), QString::number(hours)); 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() QString Utils::Misc::getUserIDString()

2
src/base/utils/misc.h

@ -84,7 +84,7 @@ namespace Utils
// Take a number of seconds and return a user-friendly // Take a number of seconds and return a user-friendly
// time duration like "1d 2h 10m". // time duration like "1d 2h 10m".
QString userFriendlyDuration(qlonglong seconds); QString userFriendlyDuration(qlonglong seconds, qlonglong maxCap = -1);
QString getUserIDString(); QString getUserIDString();
#ifdef Q_OS_WIN #ifdef Q_OS_WIN

2
src/gui/properties/propertieswidget.cpp

@ -420,7 +420,7 @@ void PropertiesWidget::loadDynamicData()
.arg(m_torrent->connectionsCount()) .arg(m_torrent->connectionsCount())
.arg(m_torrent->connectionsLimit() < 0 ? QString::fromUtf8(C_INFINITY) : QString::number(m_torrent->connectionsLimit()))); .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 // Update next announce time
m_ui->labelReannounceInVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->nextAnnounce())); m_ui->labelReannounceInVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->nextAnnounce()));

2
src/gui/transferlistdelegate.cpp

@ -82,7 +82,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
break; break;
case TransferListModel::TR_ETA: { case TransferListModel::TR_ETA: {
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; 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; break;
} }
case TransferListModel::TR_SEEDS: case TransferListModel::TR_SEEDS:

Loading…
Cancel
Save