summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <peter.penz19@gmail.com>2012-02-03 22:07:33 (GMT)
committerPeter Penz <peter.penz19@gmail.com>2012-02-03 22:11:27 (GMT)
commitd9bc83e626dc2c789ad71c61f367495eaa2830d7 (patch)
tree6cca123849a63beb363360dabb7fd40d58f18ed8
parent73e4324c25813486568c122a8ba9068350262774 (diff)
Show the value "Unknown" for the item-count only after it has been verified
During determining the item-count for directories just show an empty string until either the item-count has been calculated or if the item-count is unknown. Thanks to Nikita Skovoroda for the initial proof-of-concept patch. BUG: 291823 FIXED-IN: 4.8.1
-rw-r--r--dolphin/src/kitemviews/kfileitemlistwidget.cpp12
-rw-r--r--dolphin/src/kitemviews/kfileitemmodel.cpp23
-rw-r--r--dolphin/src/kitemviews/kfileitemmodel.h6
-rw-r--r--dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp12
4 files changed, 24 insertions, 29 deletions
diff --git a/dolphin/src/kitemviews/kfileitemlistwidget.cpp b/dolphin/src/kitemviews/kfileitemlistwidget.cpp
index 7e28c5d..d93e434 100644
--- a/dolphin/src/kitemviews/kfileitemlistwidget.cpp
+++ b/dolphin/src/kitemviews/kfileitemlistwidget.cpp
@@ -231,11 +231,13 @@ 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()) {
- 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);
+ if (!roleValue.isNull()) {
+ const int count = roleValue.toInt();
+ if (count < 0) {
+ text = i18nc("@item:intable", "Unknown");
+ } else {
+ text = i18ncp("@item:intable", "%1 item", "%1 items", count);
+ }
}
} else {
// Show the size in kilobytes (always round up)
diff --git a/dolphin/src/kitemviews/kfileitemmodel.cpp b/dolphin/src/kitemviews/kfileitemmodel.cpp
index 95c960b..db9b711 100644
--- a/dolphin/src/kitemviews/kfileitemmodel.cpp
+++ b/dolphin/src/kitemviews/kfileitemmodel.cpp
@@ -1313,12 +1313,20 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b) const
} else if (valueB.isNull()) {
result = +1;
} else {
- result = fileSizeCompare(valueA.value<KIO::filesize_t>(), valueB.value<KIO::filesize_t>());
+ result = valueA.toInt() - valueB.toInt();
}
} else {
// See "if (m_sortFoldersFirst || m_sortRole == SizeRole)" in KFileItemModel::lessThan():
Q_ASSERT(!itemB.isDir());
- result = fileSizeCompare(itemA.size(), itemB.size());
+ 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;
+ } else {
+ result = 0;
+ }
}
break;
}
@@ -1943,15 +1951,4 @@ KFileItemList KFileItemModel::childItems(const KFileItem& item) const
return items;
}
-int KFileItemModel::fileSizeCompare(KIO::filesize_t a, KIO::filesize_t b)
-{
- if (a > b) {
- return +1;
- } else if (a < b) {
- return -1;
- } else {
- return 0;
- }
-}
-
#include "kfileitemmodel.moc"
diff --git a/dolphin/src/kitemviews/kfileitemmodel.h b/dolphin/src/kitemviews/kfileitemmodel.h
index d819c37..ff816c8 100644
--- a/dolphin/src/kitemviews/kfileitemmodel.h
+++ b/dolphin/src/kitemviews/kfileitemmodel.h
@@ -330,12 +330,6 @@ private:
*/
KFileItemList childItems(const KFileItem& item) const;
- /**
- * Helper method for sortRoleCompare().
- * @return 0 if both sizes are equal, +1 if a > b and -1 if a < b.
- */
- static int fileSizeCompare(KIO::filesize_t a, KIO::filesize_t b);
-
private:
QWeakPointer<KDirLister> m_dirLister;
diff --git a/dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp b/dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp
index 14e7f00..7050d21 100644
--- a/dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp
+++ b/dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp
@@ -743,16 +743,18 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte
const bool getSizeRole = m_roles.contains("size");
const bool getIsExpandableRole = m_roles.contains("isExpandable");
- if ((getSizeRole || getIsExpandableRole) && item.isDir() && item.isLocalFile()) {
- const QString path = item.localPath();
- const int count = subItemsCount(path);
- if (count >= 0) {
+ if ((getSizeRole || getIsExpandableRole) && item.isDir()) {
+ if (item.isLocalFile()) {
+ const QString path = item.localPath();
+ const int count = subItemsCount(path);
if (getSizeRole) {
- data.insert("size", KIO::filesize_t(count));
+ data.insert("size", count);
}
if (getIsExpandableRole) {
data.insert("isExpandable", count > 0);
}
+ } else if (getSizeRole) {
+ data.insert("size", -1); // -1 indicates an unknown number of items
}
}