diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dolphinview.cpp | 58 | ||||
| -rw-r--r-- | src/dolphinview.h | 3 |
2 files changed, 32 insertions, 29 deletions
diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 404000cf4..f381bf073 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -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; + totalFileSize += item.size(); } } } 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 - 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 - 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) { @@ -521,33 +525,31 @@ QString DolphinView::statusBarText() const ++folderCount; } else { ++fileCount; - byteSize += item.size(); + totalFileSize += item.size(); } ++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) { - 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) diff --git a/src/dolphinview.h b/src/dolphinview.h index a2d5f93cf..955f974d8 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -302,11 +302,12 @@ public: /** * 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. */ - 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 |
