]> cloud.milkyroute.net Git - dolphin.git/commitdiff
* Show the total size of files in the statusbar (thanks to Bram Schoenmakers for...
authorPeter Penz <peter.penz19@gmail.com>
Mon, 3 Nov 2008 08:20:41 +0000 (08:20 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 3 Nov 2008 08:20:41 +0000 (08:20 +0000)
* Changed the format of the string to be consistent with the format used when doing a selection. Maybe it would be useful adjusting KIO::itemsSummaryString() instead using a custom output format. Currently KIO::itemsSummaryString() shows "20 Items (5 Files, 15 Folders) - (200 KiB Total)", which is quite confusing IMO, as the total size is only counted for the files. Dolphin currently shows: "15 Folders, 5 Files (200 KiB)"

BUG: 161462

svn path=/trunk/KDE/kdebase/apps/; revision=879405

src/dolphinview.cpp
src/dolphinview.h

index 404000cf42d99d7c910948fcebe81595cfe7ed68..f381bf07350f5d8e8f56126a85a38d88ffb24159 100644 (file)
@@ -487,32 +487,36 @@ void DolphinView::setNameFilter(const QString& nameFilter)
     }
 }
 
     }
 }
 
-void DolphinView::calculateItemCount(int& fileCount, int& folderCount) const
+void DolphinView::calculateItemCount(int& fileCount,
+                                     int& folderCount,
+                                     KIO::filesize_t& totalFileSize) const
 {
     foreach (const KFileItem& item, m_dirLister->items()) {
         if (item.isDir()) {
             ++folderCount;
         } else {
             ++fileCount;
 {
     foreach (const KFileItem& item, m_dirLister->items()) {
         if (item.isDir()) {
             ++folderCount;
         } else {
             ++fileCount;
+            totalFileSize += item.size();
         }
     }
 }
 
 QString DolphinView::statusBarText() const
         }
     }
 }
 
 QString DolphinView::statusBarText() const
-{    
+{
+    QString text;
+    int folderCount = 0;
+    int fileCount = 0;
+    KIO::filesize_t totalFileSize = 0;
+    
     if (hasSelection()) {
         // give a summary of the status of the selected files
     if (hasSelection()) {
         // give a summary of the status of the selected files
-        QString text;
         const KFileItemList list = selectedItems();
         if (list.isEmpty()) {
             // when an item is triggered, it is temporary selected but selectedItems()
             // will return an empty list
         const KFileItemList list = selectedItems();
         if (list.isEmpty()) {
             // when an item is triggered, it is temporary selected but selectedItems()
             // will return an empty list
-            return QString();
+            return text;
         }
 
         }
 
-        int fileCount = 0;
-        int folderCount = 0;
-        KIO::filesize_t byteSize = 0;
         KFileItemList::const_iterator it = list.begin();
         const KFileItemList::const_iterator end = list.end();
         while (it != end) {
         KFileItemList::const_iterator it = list.begin();
         const KFileItemList::const_iterator end = list.end();
         while (it != end) {
@@ -521,33 +525,31 @@ QString DolphinView::statusBarText() const
                 ++folderCount;
             } else {
                 ++fileCount;
                 ++folderCount;
             } else {
                 ++fileCount;
-                byteSize += item.size();
+                totalFileSize += item.size();
             }
             ++it;
         }
             }
             ++it;
         }
-
-        if (folderCount > 0) {
-            text = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
-            if (fileCount > 0) {
-                text += ", ";
-            }
-        }
-
+    } else {
+        calculateItemCount(fileCount, folderCount, totalFileSize);
+    }
+    
+    if (folderCount > 0) {
+        text = hasSelection() ?
+               i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount) :
+               i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount);
         if (fileCount > 0) {
         if (fileCount > 0) {
-            const QString sizeText(KIO::convertSize(byteSize));
-            text += i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText);
+            text += i18nc("@info:status separator between 2 status infos", ", ");
         }
         }
-        return text;
-    } else {
-        // Give a summary of the status of the current folder.
-        int folderCount = 0;
-        int fileCount = 0;
-        calculateItemCount(fileCount, folderCount);
-        return KIO::itemsSummaryString(fileCount + folderCount,
-                                       fileCount,
-                                       folderCount,
-                                       0, false);
     }
     }
+
+    if (fileCount > 0) {
+        const QString sizeText = KIO::convertSize(totalFileSize);
+        text += hasSelection() ?
+                i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText) :
+                i18ncp("@info:status", "1 File (%2)", "%1 Files (%2)", fileCount, sizeText);
+    }    
+
+    return text;
 }
 
 void DolphinView::setUrl(const KUrl& url)
 }
 
 void DolphinView::setUrl(const KUrl& url)
index a2d5f93cff835f75f53fa468c37e4edc7795964d..955f974d85fe621085ba7c7c7fb9b3570eabcd4f 100644 (file)
@@ -302,11 +302,12 @@ public:
     /**
      * Calculates the number of currently shown files into
      * \a fileCount and the number of folders into \a folderCount.
     /**
      * Calculates the number of currently shown files into
      * \a fileCount and the number of folders into \a folderCount.
+     * The size of all files is written into \a totalFileSize.
      * It is recommend using this method instead of asking the
      * directory lister or the model directly, as it takes
      * filtering and hierarchical previews into account.
      */
      * It is recommend using this method instead of asking the
      * directory lister or the model directly, as it takes
      * filtering and hierarchical previews into account.
      */
-    void calculateItemCount(int& fileCount, int& folderCount) const;
+    void calculateItemCount(int& fileCount, int& folderCount, KIO::filesize_t& totalFileSize) const;
     
     /**
      * Returns a textual representation of the state of the current
     
     /**
      * Returns a textual representation of the state of the current