UI: Format traffic bytes and speed per locale

This commit is contained in:
Nodir Temirkhodjaev 2024-08-19 14:42:56 +05:00
parent ac68ac211c
commit 819d65a0a8
6 changed files with 9 additions and 29 deletions

View File

@ -33,7 +33,7 @@ const std::array quotaValues = { 10, 0, 100, 500, 1024, 8 * 1024, 10 * 1024, 30
QString formatQuota(int mbytes)
{
return NetUtil::formatDataSize1(qint64(mbytes) * 1024 * 1024);
return NetUtil::formatDataSize(qint64(mbytes) * 1024 * 1024, /*precision=*/0);
}
}

View File

@ -212,7 +212,7 @@ QString TrafListModel::formatTrafUnit(qint64 bytes) const
const qint64 unitMult = unitMults.at(unit());
return QLocale::c().toString(qreal(bytes) / unitMult, 'f', trafPrec);
return QLocale().toString(qreal(bytes) / unitMult, 'f', trafPrec);
}
QString TrafListModel::formatTrafTime(qint32 trafTime) const

View File

@ -3,8 +3,6 @@
#include <QLocale>
#include <QTimeZone>
DateUtil::DateUtil(QObject *parent) : QObject(parent) { }
QDateTime DateUtil::now()
{
return QDateTime::currentDateTime();

View File

@ -6,13 +6,9 @@
#include <QObject>
#include <QString>
class DateUtil : public QObject
class DateUtil
{
Q_OBJECT
public:
explicit DateUtil(QObject *parent = nullptr);
static QDateTime now();
static QDateTime startOfDayUTC(const QDate &date);
@ -35,13 +31,13 @@ public:
static QString formatPeriod(const QString &from, const QString &to);
Q_INVOKABLE static QString formatTime(quint8 hour, quint8 minute);
static QString formatTime(quint8 hour, quint8 minute);
static QString reformatTime(const QString &time);
static void parseTime(const QString &time, quint8 &hour, quint8 &minute);
Q_INVOKABLE static quint8 parseTimeHour(const QString &period);
Q_INVOKABLE static quint8 parseTimeMinute(const QString &period);
static quint8 parseTimeHour(const QString &period);
static quint8 parseTimeMinute(const QString &period);
static QString localeDateTime(
const QDateTime &dateTime, QLocale::FormatType format = QLocale::ShortFormat);

View File

@ -128,27 +128,14 @@ const ip6_addr_t &NetUtil::rawArrayToIp6(const QByteArray &buf)
QString NetUtil::formatDataSize(qint64 bytes, int precision)
{
return QLocale::c().formattedDataSize(bytes, precision, QLocale::DataSizeTraditionalFormat);
}
QString NetUtil::formatDataSize1(qint64 bytes)
{
QString text = formatDataSize(bytes, 1);
text.remove(QLatin1String(".0"));
return text;
return QLocale().formattedDataSize(bytes, precision, QLocale::DataSizeTraditionalFormat);
}
QString NetUtil::formatSpeed(quint32 bitsPerSecond)
{
QString text = formatDataSize1(bitsPerSecond);
const QString text = formatDataSize(bitsPerSecond, /*precision=*/0);
if (bitsPerSecond < 1024) {
text.replace("bytes", "b");
} else {
text.replace('B', 'b');
}
return text + QLatin1String("ps");
return text + QObject::tr("ps");
}
QString NetUtil::getHostName(const QString &address)

View File

@ -35,7 +35,6 @@ public:
static const ip6_addr_t &rawArrayToIp6(const QByteArray &buf);
static QString formatDataSize(qint64 bytes, int precision = 2);
static QString formatDataSize1(qint64 bytes);
static QString formatSpeed(quint32 bitsPerSecond);
static QString getHostName(const QString &address);