┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dolphinviewcontainer.cpp8
-rw-r--r--src/kitemviews/kfileitemlistwidget.cpp11
-rw-r--r--src/kitemviews/kfileitemmodel.cpp22
-rw-r--r--src/views/dolphinview.cpp84
-rw-r--r--src/views/dolphinview.h6
5 files changed, 85 insertions, 46 deletions
diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp
index f3c536b52..47195bbca 100644
--- a/src/dolphinviewcontainer.cpp
+++ b/src/dolphinviewcontainer.cpp
@@ -427,7 +427,13 @@ void DolphinViewContainer::showItemInfo(const KFileItem& item)
m_statusBar->clear();
}
} else {
- m_statusBar->setMessage(item.getStatusBarInfo(), DolphinStatusBar::Default);
+ QString message;
+ if (item.isDir()) {
+ message = item.name();
+ } else {
+ message = i18nc("@info:status filename (type)", "%1 (%2)", item.name(), item.mimeComment());
+ }
+ m_statusBar->setMessage(message, DolphinStatusBar::Default);
}
}
diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp
index 5f659a1f6..d6b892658 100644
--- a/src/kitemviews/kfileitemlistwidget.cpp
+++ b/src/kitemviews/kfileitemlistwidget.cpp
@@ -192,13 +192,18 @@ QString KFileItemListWidget::roleText(const QByteArray& role, const QHash<QByteA
if (values.value("isDir").toBool()) {
// The item represents a directory. Show the number of sub directories
// instead of the file size of the directory.
- if (!roleValue.isNull()) {
+ if (roleValue.isNull()) {
+ text = i18nc("@item:intable", "Unknown");
+ } else {
const KIO::filesize_t size = roleValue.value<KIO::filesize_t>();
text = i18ncp("@item:intable", "%1 item", "%1 items", size);
}
} else {
- const KIO::filesize_t size = roleValue.value<KIO::filesize_t>();
- text = KIO::convertSize(size);
+ // Show the size in kilobytes (always round up)
+ const KLocale* locale = KGlobal::locale();
+ const int roundInc = (locale->binaryUnitDialect() == KLocale::MetricBinaryDialect) ? 499 : 511;
+ const KIO::filesize_t size = roleValue.value<KIO::filesize_t>() + roundInc;
+ text = locale->formatByteSize(size, 0, KLocale::DefaultBinaryDialect, KLocale::UnitKiloByte);
}
break;
}
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index 4b026fea3..afc6decee 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -1032,12 +1032,22 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b) const
}
case SizeRole: {
- const KIO::filesize_t sizeA = itemA.size();
- const KIO::filesize_t sizeB = itemB.size();
- if (sizeA < sizeB) {
- result = -1;
- } else if (sizeA > sizeB) {
- result = +1;
+ if (itemA.isDir()) {
+ Q_ASSERT(itemB.isDir()); // see "if (m_sortFoldersFirst || m_sortRole == SizeRole)" above
+
+ const QVariant valueA = a->values.value("size");
+ const QVariant valueB = b->values.value("size");
+
+ if (valueA.isNull()) {
+ result = -1;
+ } else if (valueB.isNull()) {
+ result = +1;
+ } else {
+ result = valueA.value<KIO::filesize_t>() - valueB.value<KIO::filesize_t>();
+ }
+ } else {
+ Q_ASSERT(!itemB.isDir()); // see "if (m_sortFoldersFirst || m_sortRole == SizeRole)" above
+ result = itemA.size() - itemB.size();
}
break;
}
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 961651b69..6312d27cf 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -362,6 +362,11 @@ void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
m_selectedUrls = urls;
}
+void DolphinView::markUrlAsCurrent(const KUrl& url)
+{
+ m_currentItemUrl = url;
+}
+
void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled)
{
const KItemListSelectionManager::SelectionMode mode = enabled
@@ -515,61 +520,50 @@ void DolphinView::calculateItemCount(int& fileCount,
QString DolphinView::statusBarText() const
{
- QString text;
+ QString summary;
+ QString foldersText;
+ QString filesText;
+
int folderCount = 0;
int fileCount = 0;
KIO::filesize_t totalFileSize = 0;
if (hasSelection()) {
- // give a summary of the status of the selected files
+ // Give a summary of the status of the selected files
const KFileItemList list = selectedItems();
- if (list.isEmpty()) {
- // when an item is triggered, it is temporary selected but selectedItems()
- // will return an empty list
- return text;
- }
-
- KFileItemList::const_iterator it = list.begin();
- const KFileItemList::const_iterator end = list.end();
- while (it != end) {
- const KFileItem& item = *it;
+ foreach (const KFileItem& item, list) {
if (item.isDir()) {
++folderCount;
} else {
++fileCount;
totalFileSize += item.size();
}
- ++it;
}
if (folderCount + fileCount == 1) {
- // if only one item is selected, show the filename
- const QString name = list.first().text();
- text = (folderCount == 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name) :
- i18nc("@info:status", "<filename>%1</filename> selected (%2)",
- name, KIO::convertSize(totalFileSize));
+ // If only one item is selected, show the filename
+ filesText = i18nc("@info:status", "<filename>%1</filename> selected", list.first().text());
} else {
- // at least 2 items are selected
- const QString foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
- const QString filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount);
- if ((folderCount > 0) && (fileCount > 0)) {
- text = i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
- foldersText, filesText, KIO::convertSize(totalFileSize));
- } else if (fileCount > 0) {
- text = i18nc("@info:status files (size)", "%1 (%2)", filesText, KIO::convertSize(totalFileSize));
- } else {
- Q_ASSERT(folderCount > 0);
- text = foldersText;
- }
+ // At least 2 items are selected
+ foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
+ filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount);
}
} else {
calculateItemCount(fileCount, folderCount, totalFileSize);
- text = KIO::itemsSummaryString(fileCount + folderCount,
- fileCount, folderCount,
- totalFileSize, true);
+ foldersText = i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount);
+ filesText = i18ncp("@info:status", "1 File", "%1 Files", fileCount);
}
- return text;
+ if (fileCount > 0 && folderCount > 0) {
+ summary = i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
+ foldersText, filesText, fileSizeText(totalFileSize));
+ } else if (fileCount > 0) {
+ summary = i18nc("@info:status files (size)", "%1 (%2)", filesText, fileSizeText(totalFileSize));
+ } else if (folderCount > 0) {
+ summary = foldersText;
+ }
+
+ return summary;
}
QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) const
@@ -1365,9 +1359,27 @@ DolphinView::Sorting DolphinView::sortingForSortRole(const QByteArray& sortRole)
return sortHash.value(sortRole);
}
-void DolphinView::markUrlAsCurrent(const KUrl& url)
+QString DolphinView::fileSizeText(KIO::filesize_t fileSize)
{
- m_currentItemUrl = url;
+ 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;
}
#include "dolphinview.moc"
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index c681737c6..2bbdf2b71 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -732,6 +732,12 @@ private:
QByteArray sortRoleForSorting(Sorting sorting) const;
Sorting sortingForSortRole(const QByteArray& sortRole) const;
+ /**
+ * Returns the text for the filesize by converting it to the best fitting
+ * unit.
+ */
+ static QString fileSizeText(KIO::filesize_t fileSize);
+
private:
bool m_active : 1;
bool m_tabsForFiles : 1;