#include <KConfig>
#include <KConfigGroup>
#include <KDebug>
-#include <KDirWatch>
#include <KFileItem>
#include <KGlobal>
#include <KIO/JobUiDelegate>
#include <KIO/PreviewJob>
#include "private/kpixmapmodifier.h"
+#include "private/kdirectorycontentscounter.h"
#include <QApplication>
#include <QPainter>
#ifdef HAVE_NEPOMUK
#include "private/knepomukrolesprovider.h"
#include <Nepomuk2/ResourceWatcher>
-#endif
-
-// Required includes for subItemsCount():
-#ifdef Q_WS_WIN
- #include <QDir>
-#else
- #include <dirent.h>
- #include <QFile>
+ #include <Nepomuk2/ResourceManager>
#endif
// #define KFILEITEMMODELROLESUPDATER_DEBUG
m_resolvableRoles(),
m_enabledPlugins(),
m_pendingSortRoleItems(),
- m_pendingSortRoleIndexes(),
m_pendingIndexes(),
m_pendingPreviewItems(),
m_previewJob(),
m_recentlyChangedItemsTimer(0),
m_recentlyChangedItems(),
m_changedItems(),
- m_dirWatcher(0),
- m_watchedDirs()
+ m_directoryContentsCounter(0)
#ifdef HAVE_NEPOMUK
, m_nepomukResourceWatcher(0),
m_nepomukUriItems()
m_resolvableRoles += KNepomukRolesProvider::instance().roles();
#endif
- // When folders are expandable or the item-count is shown for folders, it is necessary
- // to watch the number of items of the sub-folder to be able to react on changes.
- m_dirWatcher = new KDirWatch(this);
- connect(m_dirWatcher, SIGNAL(dirty(QString)), this, SLOT(slotDirWatchDirty(QString)));
+ m_directoryContentsCounter = new KDirectoryContentsCounter(m_model, this);
+ connect(m_directoryContentsCounter, SIGNAL(result(QString,int)),
+ this, SLOT(slotDirectoryContentsCountReceived(QString,int)));
}
KFileItemModelRolesUpdater::~KFileItemModelRolesUpdater()
resolveNextSortRole();
} else {
m_state = Idle;
- startUpdating();
}
+
+ startUpdating();
}
}
m_roles = roles;
#ifdef HAVE_NEPOMUK
- // Check whether there is at least one role that must be resolved
- // with the help of Nepomuk. If this is the case, a (quite expensive)
- // resolving will be done in KFileItemModelRolesUpdater::rolesData() and
- // the role gets watched for changes.
- const KNepomukRolesProvider& rolesProvider = KNepomukRolesProvider::instance();
- bool hasNepomukRole = false;
- QSetIterator<QByteArray> it(roles);
- while (it.hasNext()) {
- const QByteArray& role = it.next();
- if (rolesProvider.roles().contains(role)) {
- hasNepomukRole = true;
- break;
+ if (Nepomuk2::ResourceManager::instance()->initialized()) {
+ // Check whether there is at least one role that must be resolved
+ // with the help of Nepomuk. If this is the case, a (quite expensive)
+ // resolving will be done in KFileItemModelRolesUpdater::rolesData() and
+ // the role gets watched for changes.
+ const KNepomukRolesProvider& rolesProvider = KNepomukRolesProvider::instance();
+ bool hasNepomukRole = false;
+ QSetIterator<QByteArray> it(roles);
+ while (it.hasNext()) {
+ const QByteArray& role = it.next();
+ if (rolesProvider.roles().contains(role)) {
+ hasNepomukRole = true;
+ break;
+ }
}
- }
- if (hasNepomukRole && !m_nepomukResourceWatcher) {
- Q_ASSERT(m_nepomukUriItems.isEmpty());
+ if (hasNepomukRole && !m_nepomukResourceWatcher) {
+ Q_ASSERT(m_nepomukUriItems.isEmpty());
- m_nepomukResourceWatcher = new Nepomuk2::ResourceWatcher(this);
- connect(m_nepomukResourceWatcher, SIGNAL(propertyChanged(Nepomuk2::Resource,Nepomuk2::Types::Property,QVariantList,QVariantList)),
- this, SLOT(applyChangedNepomukRoles(Nepomuk2::Resource)));
- } else if (!hasNepomukRole && m_nepomukResourceWatcher) {
- delete m_nepomukResourceWatcher;
- m_nepomukResourceWatcher = 0;
- m_nepomukUriItems.clear();
+ m_nepomukResourceWatcher = new Nepomuk2::ResourceWatcher(this);
+ connect(m_nepomukResourceWatcher, SIGNAL(propertyChanged(Nepomuk2::Resource,Nepomuk2::Types::Property,QVariantList,QVariantList)),
+ this, SLOT(applyChangedNepomukRoles(Nepomuk2::Resource,Nepomuk2::Types::Property)));
+ } else if (!hasNepomukRole && m_nepomukResourceWatcher) {
+ delete m_nepomukResourceWatcher;
+ m_nepomukResourceWatcher = 0;
+ m_nepomukUriItems.clear();
+ }
}
#endif
applySortProgressToModel();
- // If there are still items whose sort role is unknown, return
- // and handle them asynchronously.
- if (!m_pendingSortRoleItems.isEmpty()) {
- if (m_state != ResolvingSortRole) {
- // Trigger the asynchronous determination of the sort role.
- killPreviewJob();
- m_state = ResolvingSortRole;
- resolveNextSortRole();
- }
- return;
+ // If there are still items whose sort role is unknown, check if the
+ // asynchronous determination of the sort role is already in progress,
+ // and start it if that is not the case.
+ if (!m_pendingSortRoleItems.isEmpty() && m_state != ResolvingSortRole) {
+ killPreviewJob();
+ m_state = ResolvingSortRole;
+ resolveNextSortRole();
}
}
const bool allItemsRemoved = (m_model->count() == 0);
- if (!m_watchedDirs.isEmpty()) {
- // Don't let KDirWatch watch for removed items
- if (allItemsRemoved) {
- foreach (const QString& path, m_watchedDirs) {
- m_dirWatcher->removeDir(path);
- }
- m_watchedDirs.clear();
- } else {
- QMutableSetIterator<QString> it(m_watchedDirs);
- while (it.hasNext()) {
- const QString& path = it.next();
- if (m_model->index(KUrl(path)) < 0) {
- m_dirWatcher->removeDir(path);
- it.remove();
- }
- }
- }
- }
-
#ifdef HAVE_NEPOMUK
if (m_nepomukResourceWatcher) {
// Don't let the ResourceWatcher watch for removed items
m_finishedItems.clear();
m_pendingSortRoleItems.clear();
- m_pendingSortRoleIndexes.clear();
m_pendingIndexes.clear();
m_pendingPreviewItems.clear();
m_recentlyChangedItems.clear();
Q_UNUSED(itemRange);
Q_UNUSED(movedToIndexes);
- // The indexes of the items with missing sort role are not valid any more.
- m_pendingSortRoleIndexes.clear();
-
// The visible items might have changed.
startUpdating();
}
if (m_resolvableRoles.contains(current)) {
m_pendingSortRoleItems.clear();
- m_pendingSortRoleIndexes.clear();
m_finishedItems.clear();
const int count = m_model->count();
} else {
m_state = Idle;
m_pendingSortRoleItems.clear();
- m_pendingSortRoleIndexes.clear();
applySortProgressToModel();
}
}
}
QHash<QByteArray, QVariant> data = rolesData(item);
+
+ const QStringList overlays = data["iconOverlays"].toStringList();
+ // Strangely KFileItem::overlays() returns empty string-values, so
+ // we need to check first whether an overlay must be drawn at all.
+ // It is more efficient to do it here, as KIconLoader::drawOverlays()
+ // assumes that an overlay will be drawn and has some additional
+ // setup time.
+ foreach (const QString& overlay, overlays) {
+ if (!overlay.isEmpty()) {
+ // There is at least one overlay, draw all overlays above m_pixmap
+ // and cancel the check
+ KIconLoader::global()->drawOverlays(overlays, scaledPixmap, KIconLoader::Desktop);
+ break;
+ }
+ }
+
data.insert("iconPixmap", scaledPixmap);
disconnect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
}
}
-void KFileItemModelRolesUpdater::slotPreviewJobFinished(KJob* job)
+void KFileItemModelRolesUpdater::slotPreviewJobFinished()
{
- Q_UNUSED(job);
-
m_previewJob = 0;
if (m_state != PreviewJobRunning) {
m_state = Idle;
if (!m_pendingPreviewItems.isEmpty()) {
- startPreviewJob(m_pendingPreviewItems);
+ startPreviewJob();
} else {
if (!m_changedItems.isEmpty()) {
updateChangedItems();
return;
}
- if (m_pendingSortRoleItems.count() != m_pendingSortRoleIndexes.count()) {
- // The indexes with missing sort role have to be updated.
- m_pendingSortRoleIndexes.clear();
- foreach (const KFileItem& item, m_pendingSortRoleItems) {
- const int index = m_model->index(item);
- if (index < 0) {
- m_pendingSortRoleItems.remove(item);
- } else {
- m_pendingSortRoleIndexes.append(index);
- }
- }
-
- std::sort(m_pendingSortRoleIndexes.begin(), m_pendingSortRoleIndexes.end());
- }
-
- // Try to update an item in the visible range.
- QList<int>::iterator it = std::lower_bound(m_pendingSortRoleIndexes.begin(),
- m_pendingSortRoleIndexes.end(),
- m_firstVisibleIndex);
-
- // It seems that there is no such item. Start with the first item in the list.
- if (it == m_pendingSortRoleIndexes.end()) {
- it = m_pendingSortRoleIndexes.begin();
- }
-
- while (it != m_pendingSortRoleIndexes.end()) {
- // TODO: Note that removing an index from the list m_pendingSortRoleIndexes
- // at a random position is O(N). We might need a better solution
- // to make sure that this does not harm the performance if
- // many items have to be sorted.
- const int index = *it;
- const KFileItem item = m_model->fileItem(index);
+ QSet<KFileItem>::iterator it = m_pendingSortRoleItems.begin();
+ while (it != m_pendingSortRoleItems.end()) {
+ const KFileItem item = *it;
+ const int index = m_model->index(item);
// Continue if the sort role has already been determined for the
// item, and the item has not been changed recently.
if (!m_changedItems.contains(item) && m_model->data(index).contains(m_model->sortRole())) {
- m_pendingSortRoleItems.remove(item);
- m_pendingSortRoleIndexes.erase(it);
-
- // Check if we are at the end of the list (note that the list's end has changed).
- if (it != m_pendingSortRoleIndexes.end()) {
- ++it;
- }
+ it = m_pendingSortRoleItems.erase(it);
continue;
}
applySortRole(index);
- m_pendingSortRoleItems.remove(item);
- m_pendingSortRoleIndexes.erase(it);
+ m_pendingSortRoleItems.erase(it);
break;
}
void KFileItemModelRolesUpdater::resolveNextPendingRoles()
{
- if (m_state != ResolvingAllRoles && m_state != PreviewJobRunning) {
+ if (m_state != ResolvingAllRoles) {
return;
}
continue;
}
- if (m_previewShown) {
- // Only determine the icon. The other roles are resolved when the preview is received.
- applyResolvedRoles(item, ResolveFast);
- } else {
- applyResolvedRoles(item, ResolveAll);
- m_finishedItems.insert(item);
- m_changedItems.remove(item);
- }
-
+ applyResolvedRoles(item, ResolveAll);
+ m_finishedItems.insert(item);
+ m_changedItems.remove(item);
break;
}
if (!m_pendingIndexes.isEmpty()) {
QTimer::singleShot(0, this, SLOT(resolveNextPendingRoles()));
- } else if (m_state != PreviewJobRunning) {
+ } else {
m_state = Idle;
if (m_clearPreviews) {
updateChangedItems();
}
-void KFileItemModelRolesUpdater::applyChangedNepomukRoles(const Nepomuk2::Resource& resource)
+void KFileItemModelRolesUpdater::applyChangedNepomukRoles(const Nepomuk2::Resource& resource, const Nepomuk2::Types::Property& property)
{
#ifdef HAVE_NEPOMUK
+ if (!Nepomuk2::ResourceManager::instance()->initialized()) {
+ return;
+ }
+
const KUrl itemUrl = m_nepomukUriItems.value(resource.uri());
const KFileItem item = m_model->fileItem(itemUrl);
QHash<QByteArray, QVariant> data = rolesData(item);
const KNepomukRolesProvider& rolesProvider = KNepomukRolesProvider::instance();
+ const QByteArray role = rolesProvider.roleForPropertyUri(property.uri());
+ if (!role.isEmpty() && m_roles.contains(role)) {
+ // Overwrite the changed role value with an empty QVariant, because the roles
+ // provider doesn't overwrite it when the property value list is empty.
+ // See bug 322348
+ data.insert(role, QVariant());
+ }
+
QHashIterator<QByteArray, QVariant> it(rolesProvider.roleValues(resource, m_roles));
while (it.hasNext()) {
it.next();
#endif
}
-void KFileItemModelRolesUpdater::slotDirWatchDirty(const QString& path)
+void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QString& path, int count)
{
const bool getSizeRole = m_roles.contains("size");
const bool getIsExpandableRole = m_roles.contains("isExpandable");
if (getSizeRole || getIsExpandableRole) {
const int index = m_model->index(KUrl(path));
if (index >= 0) {
- if (!m_model->fileItem(index).isDir()) {
- // If INotify is used, KDirWatch issues the dirty() signal
- // also for changed files inside the directory, even if we
- // don't enable this behavior explicitly (see bug 309740).
- return;
- }
QHash<QByteArray, QVariant> data;
- const int count = subItemsCount(path);
if (getSizeRole) {
data.insert("size", count);
}
data.insert("isExpandable", count > 0);
}
- // Note that we do not block the itemsChanged signal here.
- // This ensures that a new preview will be generated.
+ disconnect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
+ this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
m_model->setData(index, data);
+ connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
+ this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
}
}
}
void KFileItemModelRolesUpdater::startUpdating()
{
- // Updating the items in and near the visible area makes sense only
- // if sorting is finished.
- if (m_state == ResolvingSortRole || m_state == Paused) {
+ if (m_state == Paused) {
return;
}
return;
}
- int lastVisibleIndex = m_lastVisibleIndex;
- if (lastVisibleIndex <= 0) {
- // Guess a reasonable value for the last visible index if the view
- // has not told us about the real value yet.
- lastVisibleIndex = qMin(m_firstVisibleIndex + m_maximumVisibleItems, m_model->count() - 1);
- if (lastVisibleIndex <= 0) {
- lastVisibleIndex = qMin(200, m_model->count() - 1);
- }
- }
-
// Terminate all updates that are currently active.
killPreviewJob();
m_pendingIndexes.clear();
timer.start();
// Determine the icons for the visible items synchronously.
- int index;
- for (index = m_firstVisibleIndex; index <= lastVisibleIndex && timer.elapsed() < MaxBlockTimeout; ++index) {
- const KFileItem item = m_model->fileItem(index);
- applyResolvedRoles(item, ResolveFast);
+ updateVisibleIcons();
+
+ // A detailed update of the items in and near the visible area
+ // only makes sense if sorting is finished.
+ if (m_state == ResolvingSortRole) {
+ return;
}
- const int firstIndexWithoutIcon = index;
// Start the preview job or the asynchronous resolving of all roles.
QList<int> indexes = indexesToResolve();
if (m_previewShown) {
- KFileItemList itemsToResolve;
+ m_pendingPreviewItems.clear();
+ m_pendingPreviewItems.reserve(indexes.count());
+
foreach (int index, indexes) {
const KFileItem item = m_model->fileItem(index);
if (!m_finishedItems.contains(item)) {
- itemsToResolve.append(m_model->fileItem(index));
-
- // Remember the items which have no icon yet. A fast
- // asynchronous resolving will be done to make sure
- // that icons are loaded as quickly as possible, i.e.,
- // before the previews arrive.
- if (index < m_firstVisibleIndex || index >= firstIndexWithoutIcon) {
- m_pendingIndexes.append(index);
- }
+ m_pendingPreviewItems.append(item);
}
}
- startPreviewJob(itemsToResolve);
-
- // Determine the icons asynchronously as fast as possible.
- QTimer::singleShot(0, this, SLOT(resolveNextPendingRoles()));
+ startPreviewJob();
} else {
m_pendingIndexes = indexes;
// Trigger the asynchronous resolving of all roles.
}
}
-void KFileItemModelRolesUpdater::startPreviewJob(const KFileItemList items)
+void KFileItemModelRolesUpdater::updateVisibleIcons()
+{
+ int lastVisibleIndex = m_lastVisibleIndex;
+ if (lastVisibleIndex <= 0) {
+ // Guess a reasonable value for the last visible index if the view
+ // has not told us about the real value yet.
+ lastVisibleIndex = qMin(m_firstVisibleIndex + m_maximumVisibleItems, m_model->count() - 1);
+ if (lastVisibleIndex <= 0) {
+ lastVisibleIndex = qMin(200, m_model->count() - 1);
+ }
+ }
+
+ QElapsedTimer timer;
+ timer.start();
+
+ // Try to determine the final icons for all visible items.
+ int index;
+ for (index = m_firstVisibleIndex; index <= lastVisibleIndex && timer.elapsed() < MaxBlockTimeout; ++index) {
+ const KFileItem item = m_model->fileItem(index);
+ applyResolvedRoles(item, ResolveFast);
+ }
+
+ // KFileItemListView::initializeItemListWidget(KItemListWidget*) will load
+ // preliminary icons (i.e., without mime type determination) for the
+ // remaining items.
+}
+
+void KFileItemModelRolesUpdater::startPreviewJob()
{
m_state = PreviewJobRunning;
- if (items.isEmpty()) {
- QMetaObject::invokeMethod(this, "slotPreviewJobFinished", Qt::QueuedConnection, Q_ARG(KJob*, 0));
+ if (m_pendingPreviewItems.isEmpty()) {
+ QTimer::singleShot(0, this, SLOT(slotPreviewJobFinished()));
return;
}
// KIO::filePreview() will request the MIME-type of all passed items, which (in the
// worst case) might block the application for several seconds. To prevent such
- // a blocking, we only pass items with known mime type to the preview job
- // (if the icon has already been determined for an item in startUpdating()
- // or resolveNextPendingRoles(), the type is known).
- // This also prevents that repeated expensive mime type determinations are
- // triggered here if a huge folder is loaded, and startUpdating() is called
- // repeatedly.
- //
- // Note that we always pass at least one item to the preview job to prevent
- // that we get an endless startPreviewJob()/slotPreviewJobFinished() loop
- // if there are no items with known mime types yet for some reason.
- const int count = items.count();
- int previewJobItemCount = 1;
-
- // TODO: This will start a job with one item only if this function is
- // called from slotPreviewJobFinished(), and resolveNextPendingRoles()
- // has not reached the items yet. This can happen if the previous preview
- // job has finished very fast because generating previews failed for all
- // items.
- //
- // Idea to improve this: if the mime type of the first item is unknown,
- // determine mime types synchronously for a while.
- while (previewJobItemCount < qMin(count, m_maximumVisibleItems) &&
- items.at(previewJobItemCount).isMimeTypeKnown()) {
- ++previewJobItemCount;
- }
-
+ // a blocking, we only pass items with known mime type to the preview job.
+ const int count = m_pendingPreviewItems.count();
KFileItemList itemSubSet;
- itemSubSet.reserve(previewJobItemCount);
- m_pendingPreviewItems.clear();
- m_pendingPreviewItems.reserve(count - previewJobItemCount);
-
- for (int i = 0; i < previewJobItemCount; ++i) {
- itemSubSet.append(items.at(i));
- }
+ itemSubSet.reserve(count);
+
+ if (m_pendingPreviewItems.first().isMimeTypeKnown()) {
+ // Some mime types are known already, probably because they were
+ // determined when loading the icons for the visible items. Start
+ // a preview job for all items at the beginning of the list which
+ // have a known mime type.
+ do {
+ itemSubSet.append(m_pendingPreviewItems.takeFirst());
+ } while (!m_pendingPreviewItems.isEmpty() && m_pendingPreviewItems.first().isMimeTypeKnown());
+ } else {
+ // Determine mime types for MaxBlockTimeout ms, and start a preview
+ // job for the corresponding items.
+ QElapsedTimer timer;
+ timer.start();
- for (int i = previewJobItemCount; i < count; ++i) {
- m_pendingPreviewItems.append(items.at(i));
+ do {
+ const KFileItem item = m_pendingPreviewItems.takeFirst();
+ item.determineMimeType();
+ itemSubSet.append(item);
+ } while (!m_pendingPreviewItems.isEmpty() && timer.elapsed() < MaxBlockTimeout);
}
KIO::PreviewJob* job = new KIO::PreviewJob(itemSubSet, cacheSize, &m_enabledPlugins);
connect(job, SIGNAL(failed(KFileItem)),
this, SLOT(slotPreviewFailed(KFileItem)));
connect(job, SIGNAL(finished(KJob*)),
- this, SLOT(slotPreviewJobFinished(KJob*)));
+ this, SLOT(slotPreviewJobFinished()));
m_previewJob = job;
}
std::sort(visibleChangedIndexes.begin(), visibleChangedIndexes.end());
if (m_previewShown) {
- KFileItemList visibleChangedItems;
- KFileItemList invisibleChangedItems;
-
foreach (int index, visibleChangedIndexes) {
- visibleChangedItems.append(m_model->fileItem(index));
+ m_pendingPreviewItems.append(m_model->fileItem(index));
}
foreach (int index, invisibleChangedIndexes) {
- invisibleChangedItems.append(m_model->fileItem(index));
+ m_pendingPreviewItems.append(m_model->fileItem(index));
}
- if (m_previewJob) {
- m_pendingPreviewItems += visibleChangedItems + invisibleChangedItems;
- } else {
- startPreviewJob(visibleChangedItems + invisibleChangedItems);
+ if (!m_previewJob) {
+ startPreviewJob();
}
} else {
const bool resolvingInProgress = !m_pendingIndexes.isEmpty();
QHash<QByteArray, QVariant> data;
const KFileItem item = m_model->fileItem(index);
- if (index >= m_firstVisibleIndex && index <= m_lastVisibleIndex) {
- // Determine the icon.
- applyResolvedRoles(item, ResolveFast);
- }
-
if (m_model->sortRole() == "type") {
if (!item.isMimeTypeKnown()) {
item.determineMimeType();
data.insert("type", item.mimeComment());
} else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) {
const QString path = item.localPath();
- data.insert("size", subItemsCount(path));
+ data.insert("size", m_directoryContentsCounter->countDirectoryContentsSynchronously(path));
} else {
// Probably the sort role is a Nepomuk role - just determine all roles.
data = rolesData(item);
if (!item.isMimeTypeKnown() || !item.isFinalIconKnown()) {
item.determineMimeType();
iconChanged = true;
- } else if (m_state == ResolvingSortRole || m_state == PreviewJobRunning) {
- // We are currently performing a fast determination of all icons
- // in the visible area.
+ } else {
const int index = m_model->index(item);
if (!m_model->data(index).contains("iconName")) {
iconChanged = true;
return false;
}
-QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileItem& item) const
+QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileItem& item)
{
QHash<QByteArray, QVariant> data;
if ((getSizeRole || getIsExpandableRole) && item.isDir()) {
if (item.isLocalFile()) {
+ // Tell m_directoryContentsCounter that we want to count the items
+ // inside the directory. The result will be received in slotDirectoryContentsCountReceived.
const QString path = item.localPath();
- const int count = subItemsCount(path);
- if (getSizeRole) {
- data.insert("size", count);
- }
- if (getIsExpandableRole) {
- data.insert("isExpandable", count > 0);
- }
-
- if (!m_dirWatcher->contains(path)) {
- m_dirWatcher->addDir(path);
- m_watchedDirs.insert(path);
- }
+ m_directoryContentsCounter->addDirectory(path);
} else if (getSizeRole) {
data.insert("size", -1); // -1 indicates an unknown number of items
}
return data;
}
-int KFileItemModelRolesUpdater::subItemsCount(const QString& path) const
-{
- const bool countHiddenFiles = m_model->showHiddenFiles();
- const bool showFoldersOnly = m_model->showDirectoriesOnly();
-
-#ifdef Q_WS_WIN
- QDir dir(path);
- 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
- // Copyright (C) 2006 David Faure <faure@kde.org>
-
- int count = -1;
- DIR* dir = ::opendir(QFile::encodeName(path));
- if (dir) { // krazy:exclude=syscalls
- count = 0;
- struct dirent *dirEntry = 0;
- while ((dirEntry = ::readdir(dir))) {
- if (dirEntry->d_name[0] == '.') {
- if (dirEntry->d_name[1] == '\0' || !countHiddenFiles) {
- // Skip "." or hidden files
- continue;
- }
- if (dirEntry->d_name[1] == '.' && dirEntry->d_name[2] == '\0') {
- // Skip ".."
- continue;
- }
- }
-
- // If only directories are counted, consider an unknown file type and links also
- // as directory instead of trying to do an expensive stat()
- // (see bugs 292642 and 299997).
- const bool countEntry = !showFoldersOnly ||
- dirEntry->d_type == DT_DIR ||
- dirEntry->d_type == DT_LNK ||
- dirEntry->d_type == DT_UNKNOWN;
- if (countEntry) {
- ++count;
- }
- }
- ::closedir(dir);
- }
- return count;
-#endif
-}
-
void KFileItemModelRolesUpdater::updateAllPreviews()
{
if (m_state == Paused) {
disconnect(m_previewJob, SIGNAL(failed(KFileItem)),
this, SLOT(slotPreviewFailed(KFileItem)));
disconnect(m_previewJob, SIGNAL(finished(KJob*)),
- this, SLOT(slotPreviewJobFinished(KJob*)));
+ this, SLOT(slotPreviewJobFinished()));
m_previewJob->kill();
m_previewJob = 0;
m_pendingPreviewItems.clear();