]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Show the value "Unknown" for the item-count only after it has been verified
authorPeter Penz <peter.penz19@gmail.com>
Fri, 3 Feb 2012 22:07:33 +0000 (23:07 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 3 Feb 2012 22:12:12 +0000 (23:12 +0100)
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

src/kitemviews/kfileitemlistwidget.cpp
src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/kitemviews/kfileitemmodelrolesupdater.cpp

index 7e28c5d371ef02d59274c12e6b3a7e59ec507c5d..d93e434da16a1bb84af4ca7588787f69a13ce2d6 100644 (file)
@@ -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)
index 95c960b3da1a70b55a74a00d17faa5f4051857e9..db9b71189beaf648c7be093c43413c2294be0f0d 100644 (file)
@@ -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"
index d819c373496f84dea19993362a63ae14e94a68bb..ff816c85ca0e5ce5835b427df9424cc8d6a4fc6b 100644 (file)
@@ -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;
 
index 14e7f00ff7290c136471e92556054ca3ca81a22b..7050d21c95f012eba7f6c2349a68b6856c404799 100644 (file)
@@ -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
         }
     }