// Shared human-readable formatting. Lane GUI. // // Pulled out once three places (the table model, the main window status bar, the // progress dialog) all wanted the same "bytes / rate / eta" strings. #pragma once #include #include #include namespace velox::gui::fmt { inline QString bytes(qint64 n) { if (n < 0) { return QStringLiteral("—"); } return QLocale().formattedDataSize(n, 2, QLocale::DataSizeIecFormat); } inline QString rate(qint64 bytesPerSec) { if (bytesPerSec <= 0) { return QCoreApplication::translate("velox::gui::fmt", "0 B/s"); } return QCoreApplication::translate("velox::gui::fmt", "%1/s") .arg(QLocale().formattedDataSize(bytesPerSec, 1, QLocale::DataSizeIecFormat)); } /// HH:MM:SS, or empty for a negative (unknown) eta. inline QString eta(qint64 secs) { if (secs < 0) { return QString(); } const qint64 h = secs / 3600; const qint64 m = (secs % 3600) / 60; const qint64 s = secs % 60; return QStringLiteral("%1:%2:%3") .arg(h, 2, 10, QLatin1Char('0')) .arg(m, 2, 10, QLatin1Char('0')) .arg(s, 2, 10, QLatin1Char('0')); } } // namespace velox::gui::fmt