+DolphinView::Sorting DolphinView::sortingForSortRole(const QByteArray& sortRole) const
+{
+ static QHash<QByteArray, DolphinView::Sorting> sortHash;
+ if (sortHash.isEmpty()) {
+ sortHash.insert("name", SortByName);
+ sortHash.insert("size", SortBySize);
+ sortHash.insert("date", SortByDate);
+ sortHash.insert("permissions", SortByPermissions);
+ sortHash.insert("owner", SortByOwner);
+ sortHash.insert("group", SortByGroup);
+ sortHash.insert("type", SortByType);
+ sortHash.insert("destination", SortByDestination);
+ sortHash.insert("path", SortByPath);
+ }
+ return sortHash.value(sortRole);
+}
+
+QString DolphinView::fileSizeText(KIO::filesize_t fileSize)
+{
+ 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;
+}
+