]> cloud.milkyroute.net Git - dolphin.git/commitdiff
fix display of folder sizes for empty folders
authorIlia Kats <ilia-kats@gmx.net>
Tue, 15 Dec 2020 21:20:51 +0000 (22:20 +0100)
committerIlia Kats <ilia-kats@gmx.net>
Thu, 17 Dec 2020 12:04:01 +0000 (13:04 +0100)
also fixes 1 byte error in size calculation for all folders

src/kitemviews/kfileitemlistwidget.cpp
src/kitemviews/kfileitemmodelrolesupdater.cpp
src/kitemviews/private/kdirectorycontentscounterworker.cpp

index 69a40ddf3641d8626e498c504fc7ea334fbcae37..66fcafaf628f6d2d56880131cbf8fc301a5d0203 100644 (file)
@@ -53,20 +53,16 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray& role,
 
     if (role == "size") {
         if (values.value("isDir").toBool()) {
-            // The item represents a directory.
-            if (!roleValue.isNull()) {
-                const int count = values.value("count").toInt();
-                if (count > 0) {
-                    if (DetailsModeSettings::directorySizeCount()) {
-                        //  Show the number of sub directories instead of the file size of the directory.
-                        text = i18ncp("@item:intable", "%1 item", "%1 items", count);
-                    } else {
-                        // if we have directory size available
-                        if (roleValue != -1) {
-                            const KIO::filesize_t size = roleValue.value<KIO::filesize_t>();
-                            text = KFormat().formatByteSize(size);
-                        }
-                    }
+            if (!roleValue.isNull() && roleValue != -1) {
+                // The item represents a directory.
+                if (DetailsModeSettings::directorySizeCount()) {
+                    //  Show the number of sub directories instead of the file size of the directory.
+                    const int count = values.value("count").toInt();
+                    text = i18ncp("@item:intable", "%1 item", "%1 items", count);
+                } else {
+                    // if we have directory size available
+                    const KIO::filesize_t size = roleValue.value<KIO::filesize_t>();
+                    text = KFormat().formatByteSize(size);
                 }
             }
         } else {
index 075ec888a320483ddbf47188af93be7af66ff4f0..3bd6d977dab74fd9d46daf0bb65a7de4cb2dce35 100644 (file)
@@ -776,9 +776,7 @@ void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QStrin
 
             if (getSizeRole) {
                 data.insert("count", count);
-                if (size != -1) {
-                    data.insert("size", QVariant::fromValue(size));
-                }
+                data.insert("size", QVariant::fromValue(size));
             }
             if (getIsExpandableRole) {
                 data.insert("isExpandable", count > 0);
index 1e3b7ff9f0b182bf3525e19a023ba16dc67b87de..73799e739678863657d98ada5fdba5d61d1db03f 100644 (file)
@@ -35,6 +35,7 @@ KDirectoryContentsCounterWorker::CountResult walkDir(const QString &dirPath,
     auto dir = QT_OPENDIR(QFile::encodeName(dirPath));
     if (dir) {
         count = 0;
+        size = 0;
         QT_STATBUF buf;
 
         while ((dirEntry = QT_READDIR(dir))) {