diff options
| author | Peter Penz <[email protected]> | 2011-12-23 23:05:08 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-12-23 23:19:48 +0100 |
| commit | b2cb38214ec403dfc68e5231e0006fe59833515a (patch) | |
| tree | 77b78fd48a145d34ae0ffd911b605e3af3f9edac /src/kitemviews/kfileitemmodelrolesupdater.cpp | |
| parent | 2cafa66f00ef46c378c159d13319fea475070527 (diff) | |
Introduce "isExpandable" role
The role is used to determine whether a directory can be expanded at all. This
is e.g. not the case if a directory has 0 items or the target-URL is different
from the item-URL.
The expansion toggle will get hidden if a directory is not expandable.
CCBUG: 288521
Diffstat (limited to 'src/kitemviews/kfileitemmodelrolesupdater.cpp')
| -rw-r--r-- | src/kitemviews/kfileitemmodelrolesupdater.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index 671352cac..0ecc0e973 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -356,7 +356,8 @@ void KFileItemModelRolesUpdater::resolvePendingRoles() const bool hasSlowRoles = m_previewShown || m_roles.contains("size") - || m_roles.contains("type"); + || m_roles.contains("type") + || m_roles.contains("isExpandable"); const ResolveHint resolveHint = hasSlowRoles ? ResolveFast : ResolveAll; // Resolving the MIME type can be expensive. Assure that not more than MaxBlockTimeout ms are @@ -715,13 +716,19 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte { QHash<QByteArray, QVariant> data; - if (m_roles.contains("size")) { - if (item.isDir() && item.isLocalFile()) { - const QString path = item.localPath(); - const int count = subDirectoriesCount(path); - if (count >= 0) { + const bool getSizeRole = m_roles.contains("size"); + const bool getIsExpandableRole = m_roles.contains("isExpandable"); + + if ((getSizeRole || getIsExpandableRole) && item.isDir() && item.isLocalFile()) { + const QString path = item.localPath(); + const int count = subDirectoriesCount(path); + if (count >= 0) { + if (getSizeRole) { data.insert("size", KIO::filesize_t(count)); } + if (getIsExpandableRole) { + data.insert("isExpandable", count > 0); + } } } @@ -770,11 +777,17 @@ KFileItemList KFileItemModelRolesUpdater::sortedItems(const QSet<KFileItem>& ite return itemList; } -int KFileItemModelRolesUpdater::subDirectoriesCount(const QString& path) +int KFileItemModelRolesUpdater::subDirectoriesCount(const QString& path) const { + const bool countHiddenFiles = m_model->showHiddenFiles(); + #ifdef Q_WS_WIN QDir dir(path); - return dir.entryList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::System).count(); + QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot | QDir::System; + if (countHiddenFiles) { + filters |= QDir::Hidden; + } + return dir.entryList(filters).count(); #else // Taken from kdelibs/kio/kio/kdirmodel.cpp // Copyright (C) 2006 David Faure <[email protected]> @@ -786,8 +799,8 @@ int KFileItemModelRolesUpdater::subDirectoriesCount(const QString& path) struct dirent *dirEntry = 0; while ((dirEntry = ::readdir(dir))) { // krazy:exclude=syscalls if (dirEntry->d_name[0] == '.') { - if (dirEntry->d_name[1] == '\0') { - // Skip "." + if (dirEntry->d_name[1] == '\0' || !countHiddenFiles) { + // Skip "." or hidden files continue; } if (dirEntry->d_name[1] == '.' && dirEntry->d_name[2] == '\0') { |
