diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index d81ddd9655..b1a5fec422 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -183,6 +183,20 @@ bool KFileItemModel::showHiddenFiles() const return dirLister ? dirLister->showingDotFiles() : false; } +void KFileItemModel::setShowFoldersOnly(bool enabled) +{ + KDirLister* dirLister = m_dirLister.data(); + if (dirLister) { + dirLister->setDirOnlyMode(enabled); + } +} + +bool KFileItemModel::showFoldersOnly() const +{ + KDirLister* dirLister = m_dirLister.data(); + return dirLister ? dirLister->dirOnlyMode() : false; +} + QMimeData* KFileItemModel::createMimeData(const QSet& indexes) const { QMimeData* data = new QMimeData(); diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index 07634655ca..acb3eb1532 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -73,6 +73,13 @@ public: void setShowHiddenFiles(bool show); bool showHiddenFiles() const; + /** + * If set to true, only folders are shown as items of the model. Files + * are ignored. + */ + void setShowFoldersOnly(bool enabled); + bool showFoldersOnly() const; + /** @reimp */ virtual QMimeData* createMimeData(const QSet& indexes) const; diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index 098c844aba..a974094d58 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -33,7 +33,7 @@ #include #include -// Required includes for subDirectoriesCount(): +// Required includes for subItemsCount(): #ifdef Q_WS_WIN #include #else @@ -770,7 +770,7 @@ QHash KFileItemModelRolesUpdater::rolesData(const KFileIte if ((getSizeRole || getIsExpandableRole) && item.isDir() && item.isLocalFile()) { const QString path = item.localPath(); - const int count = subDirectoriesCount(path); + const int count = subItemsCount(path); if (count >= 0) { if (getSizeRole) { data.insert("size", KIO::filesize_t(count)); @@ -826,16 +826,22 @@ KFileItemList KFileItemModelRolesUpdater::sortedItems(const QSet& ite return itemList; } -int KFileItemModelRolesUpdater::subDirectoriesCount(const QString& path) const +int KFileItemModelRolesUpdater::subItemsCount(const QString& path) const { const bool countHiddenFiles = m_model->showHiddenFiles(); + const bool showFoldersOnly = m_model->showFoldersOnly(); #ifdef Q_WS_WIN QDir dir(path); - QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot | QDir::System; + QDir::Filters filters = QDir::NoDotAndDotDot | QDir::System; if (countHiddenFiles) { filters |= QDir::Hidden; } + if (showFoldersOnly) { + filters |= QDir::Dirs; + } else { + filters |= QDir::AllEntries; + } return dir.entryList(filters).count(); #else // Taken from kdelibs/kio/kio/kdirmodel.cpp @@ -857,7 +863,10 @@ int KFileItemModelRolesUpdater::subDirectoriesCount(const QString& path) const continue; } } - ++count; + + if (!showFoldersOnly || dirEntry->d_type == DT_DIR) { + ++count; + } } ::closedir(dir); } diff --git a/src/kitemviews/kfileitemmodelrolesupdater.h b/src/kitemviews/kfileitemmodelrolesupdater.h index 5ed45a6ec6..b3945d14de 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.h +++ b/src/kitemviews/kfileitemmodelrolesupdater.h @@ -164,7 +164,10 @@ private: KFileItemList sortedItems(const QSet& items) const; - int subDirectoriesCount(const QString& path) const; + /** + * @return The number of items of the path \a path. + */ + int subItemsCount(const QString& path) const; private: // Property for setPaused()/isPaused(). diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 86a1c0ccd6..d9c8f71dcb 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -140,7 +140,6 @@ void FoldersPanel::showEvent(QShowEvent* event) // This assures that no performance and memory overhead is given when the TreeView is not // used at all (see FoldersPanel::setUrl()). m_dirLister = new KDirLister(); - m_dirLister->setDirOnlyMode(true); m_dirLister->setAutoUpdate(true); m_dirLister->setMainWindow(window()); m_dirLister->setDelayedMimeTypes(true); @@ -163,6 +162,7 @@ void FoldersPanel::showEvent(QShowEvent* event) view->setOpacity(0); KFileItemModel* model = new KFileItemModel(m_dirLister, this); + model->setShowFoldersOnly(true); model->setShowHiddenFiles(FoldersPanelSettings::hiddenFilesShown()); // Use a QueuedConnection to give the view the possibility to react first on the // finished loading.