roles.insert("isDir");
if (m_itemLayout == DetailsLayout) {
roles.insert("isExpanded");
+ roles.insert("isExpandable");
roles.insert("expansionLevel");
}
KItemListWidget(parent),
m_isCut(false),
m_isHidden(false),
- m_isDir(false),
+ m_isExpandable(false),
m_dirtyLayout(true),
m_dirtyContent(true),
m_dirtyContentRoles(),
KItemListWidget::paint(painter, option, widget);
// Draw expansion toggle '>' or 'V'
- if (m_isDir && !m_expansionArea.isEmpty()) {
+ if (m_isExpandable) {
QStyleOption arrowOption;
arrowOption.rect = m_expansionArea.toRect();
const QStyle::PrimitiveElement arrow = data()["isExpanded"].toBool()
QRectF KFileItemListWidget::expansionToggleRect() const
{
const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
- return m_isDir ? m_expansionArea : QRectF();
+ return m_isExpandable ? m_expansionArea : QRectF();
}
QRectF KFileItemListWidget::selectionToggleRect() const
refreshCache();
const QHash<QByteArray, QVariant> values = data();
- m_isDir = values["isDir"].toBool();
+ m_isExpandable = values["isExpandable"].toBool();
m_isHidden = values["name"].toString().startsWith(QLatin1Char('.'));
updateExpansionArea();
private:
bool m_isCut;
bool m_isHidden;
- bool m_isDir;
+ bool m_isExpandable;
bool m_dirtyLayout;
bool m_dirtyContent;
m_roles = roles;
if (count() > 0) {
- const bool supportedExpanding = m_requestRole[IsExpandedRole] && m_requestRole[ExpansionLevelRole];
- const bool willSupportExpanding = roles.contains("isExpanded") && roles.contains("expansionLevel");
+ const bool supportedExpanding = m_requestRole[ExpansionLevelRole];
+ const bool willSupportExpanding = roles.contains("expansionLevel");
if (supportedExpanding && !willSupportExpanding) {
// No expanding is supported anymore. Take care to delete all items that have an expansion level
// that is not 0 (and hence are part of an expanded item).
bool KFileItemModel::setExpanded(int index, bool expanded)
{
- if (isExpanded(index) == expanded || index < 0 || index >= count()) {
+ if (!isExpandable(index) || isExpanded(index) == expanded) {
return false;
}
bool KFileItemModel::isExpandable(int index) const
{
if (index >= 0 && index < count()) {
- return m_itemData.at(index)->item.isDir();
+ return m_itemData.at(index)->values.value("isExpandable").toBool();
}
return false;
}
void KFileItemModel::setExpanded(const QSet<KUrl>& urls)
{
-
const KDirLister* dirLister = m_dirLister.data();
if (!dirLister) {
return;
rolesHash.insert("rating", RatingRole);
rolesHash.insert("isDir", IsDirRole);
rolesHash.insert("isExpanded", IsExpandedRole);
+ rolesHash.insert("isExpandable", IsExpandableRole);
rolesHash.insert("expansionLevel", ExpansionLevelRole);
}
return rolesHash.value(role, NoRole);
data.insert("isExpanded", false);
}
+ if (m_requestRole[IsExpandableRole]) {
+ data.insert("isExpandable", item.isDir() && item.url() == item.targetUrl());
+ }
+
if (m_requestRole[ExpansionLevelRole]) {
if (m_rootExpansionLevel == UninitializedRootExpansionLevel && m_dirLister.data()) {
const KUrl rootUrl = m_dirLister.data()->url();
RatingRole,
IsDirRole,
IsExpandedRole,
+ IsExpandableRole,
ExpansionLevelRole,
RolesCount // Mandatory last entry
};
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
{
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);
+ }
}
}
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 <faure@kde.org>
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') {
KFileItemList sortedItems(const QSet<KFileItem>& items) const;
- static int subDirectoriesCount(const QString& path);
+ int subDirectoriesCount(const QString& path) const;
private:
// Property for setPaused()/isPaused().
// yields the correct result for "a/a/1" and "a/a-1/", whis is non-trivial because they share the
// first three characters.
QSet<QByteArray> modelRoles = m_model->roles();
- modelRoles << "isExpanded" << "expansionLevel";
+ modelRoles << "isExpanded" << "isExpandable" << "expansionLevel";
m_model->setRoles(modelRoles);
QStringList files;