mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Don't show a expanding-toggle in the Folders Panel if there are no subdirectories
BUG: 290745 FIXED-IN: 4.8.0
This commit is contained in:
parent
f38a70f5d0
commit
8306a0fa6c
5 changed files with 40 additions and 7 deletions
|
@ -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<int>& indexes) const
|
||||
{
|
||||
QMimeData* data = new QMimeData();
|
||||
|
|
|
@ -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<int>& indexes) const;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <QElapsedTimer>
|
||||
#include <QTimer>
|
||||
|
||||
// Required includes for subDirectoriesCount():
|
||||
// Required includes for subItemsCount():
|
||||
#ifdef Q_WS_WIN
|
||||
#include <QDir>
|
||||
#else
|
||||
|
@ -770,7 +770,7 @@ QHash<QByteArray, QVariant> 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<KFileItem>& 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);
|
||||
}
|
||||
|
|
|
@ -164,7 +164,10 @@ private:
|
|||
|
||||
KFileItemList sortedItems(const QSet<KFileItem>& 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().
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue