+ const KLocale* locale = KGlobal::locale();
+ const unsigned int multiplier = (locale->binaryUnitDialect() == KLocale::MetricBinaryDialect)
+ ? 1000 : 1024;
+
+ QString text;
+ if (fileSize < multiplier) {
+ // Show the size in bytes
+ text = locale->formatByteSize(fileSize, 0, KLocale::DefaultBinaryDialect, KLocale::UnitByte);
+ } else if (fileSize < multiplier * multiplier) {
+ // Show the size in kilobytes and always round up. This is done
+ // for consistency with the values shown e.g. in the "Size" column
+ // of the details-view.
+ fileSize += (multiplier / 2) - 1;
+ text = locale->formatByteSize(fileSize, 0, KLocale::DefaultBinaryDialect, KLocale::UnitKiloByte);
+ } else {
+ // Show the size in the best fitting unit having one decimal
+ text = locale->formatByteSize(fileSize, 1);
+ }
+ return text;