libshared: Change string_for_rate to use KiB/s instead of Kbps.
string_for_size uses KiB, etc., and so when the two are combined (e.g. pkgman's progress display), it looked especially strange to have two different units.
This commit is contained in:
@@ -11,8 +11,7 @@
|
|||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
const char* string_for_rate(double rate, char* string, size_t stringSize,
|
const char* string_for_rate(double rate, char* string, size_t stringSize);
|
||||||
double base = 1000.0f);
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012 Haiku Inc. All rights reserved.
|
* Copyright 2012-2018, Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <StringFormat.h>
|
||||||
#include <SystemCatalog.h>
|
#include <SystemCatalog.h>
|
||||||
|
|
||||||
using BPrivate::gSystemCatalog;
|
using BPrivate::gSystemCatalog;
|
||||||
@@ -20,42 +21,46 @@ namespace BPrivate {
|
|||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
string_for_rate(double rate, char* string, size_t stringSize, double base)
|
string_for_rate(double rate, char* string, size_t stringSize)
|
||||||
{
|
{
|
||||||
double kbps = rate / base;
|
double kib = rate / 1024.0;
|
||||||
if (kbps < 10.0) {
|
if (kib < 1.0) {
|
||||||
const char* trKey = B_TRANSLATE_MARK("%d bps");
|
BString tmp;
|
||||||
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
BStringFormat format(
|
||||||
B_TRANSLATION_CONTEXT), (int)rate);
|
gSystemCatalog.GetString(B_TRANSLATE_MARK(
|
||||||
return string;
|
"{0, plural, one{# byte/s} other{# bytes/s}}"),
|
||||||
}
|
B_TRANSLATION_CONTEXT, "bytes per second"));
|
||||||
double mbps = kbps / base;
|
format.Format(tmp, (int)rate);
|
||||||
if (mbps < 10.0) {
|
|
||||||
const char* trKey = B_TRANSLATE_MARK("%.0f Kbps");
|
|
||||||
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
|
||||||
B_TRANSLATION_CONTEXT), kbps);
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
double gbps = mbps / base;
|
|
||||||
if (gbps < 10.0) {
|
|
||||||
const char* trKey = B_TRANSLATE_MARK("%.0f Mbps");
|
|
||||||
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
|
||||||
B_TRANSLATION_CONTEXT), mbps);
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
double tbps = gbps / base;
|
|
||||||
if (tbps < 10.0) {
|
|
||||||
const char* trKey = B_TRANSLATE_MARK("%.0f Gbps");
|
|
||||||
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
|
||||||
B_TRANSLATION_CONTEXT), gbps);
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
const char* trKey = B_TRANSLATE_MARK("%.0f Tbps");
|
|
||||||
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
|
||||||
B_TRANSLATION_CONTEXT), tbps);
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
strlcpy(string, tmp.String(), stringSize);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
double mib = kib / 1024.0;
|
||||||
|
if (mib < 1.0) {
|
||||||
|
const char* trKey = B_TRANSLATE_MARK("%3.2f KiB/s");
|
||||||
|
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||||
|
B_TRANSLATION_CONTEXT, "KiB per second"), kib);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
double gib = mib / 1024.0;
|
||||||
|
if (gib < 1.0) {
|
||||||
|
const char* trKey = B_TRANSLATE_MARK("%3.2f MiB/s");
|
||||||
|
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||||
|
B_TRANSLATION_CONTEXT, "MiB per second"), mib);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
double tib = gib / 1024.0;
|
||||||
|
if (tib < 1.0) {
|
||||||
|
const char* trKey = B_TRANSLATE_MARK("%3.2f GiB/s");
|
||||||
|
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||||
|
B_TRANSLATION_CONTEXT, "GiB per second"), gib);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
const char* trKey = B_TRANSLATE_MARK("%.2f TiB/s");
|
||||||
|
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||||
|
B_TRANSLATION_CONTEXT, "TiB per second"), tib);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user