diff --git a/containments/desktop/plugins/folder/foldermodel.h b/containments/desktop/plugins/folder/foldermodel.h --- a/containments/desktop/plugins/folder/foldermodel.h +++ b/containments/desktop/plugins/folder/foldermodel.h @@ -55,6 +55,7 @@ namespace KIO { class DropJob; + class StatJob; } class ScreenMapper; @@ -315,6 +316,7 @@ KDirWatch *m_dirWatch; QString m_url; QHash m_isDirCache; + mutable QHash m_isDirJobs; QItemSelectionModel *m_selectionModel; QItemSelection m_pinnedSelection; QModelIndexList m_dragIndexes; diff --git a/containments/desktop/plugins/folder/foldermodel.cpp b/containments/desktop/plugins/folder/foldermodel.cpp --- a/containments/desktop/plugins/folder/foldermodel.cpp +++ b/containments/desktop/plugins/folder/foldermodel.cpp @@ -1272,13 +1272,7 @@ } else if (role == SelectedRole) { return m_selectionModel->isSelected(index); } else if (role == IsDirRole) { - const QUrl &url = data(index, UrlRole).toUrl(); - - if (m_isDirCache.contains(url)) { - return m_isDirCache[url]; - } else { - return isDir(mapToSource(index), m_dirModel); - } + return isDir(mapToSource(index), m_dirModel); } else if (role == IsLinkRole) { const KFileItem item = itemForIndex(index); return item.isLink(); @@ -1331,21 +1325,36 @@ return true; } + auto it = m_isDirCache.constFind(item.url()); + if (it != m_isDirCache.constEnd()) { + return *it; + } + if (m_parseDesktopFiles && item.isDesktopFile()) { // Check if the desktop file is a link to a directory KDesktopFile file(item.targetUrl().path()); - if (file.hasLinkType()) { - const QUrl url(file.readUrl()); - - if (!m_isDirCache.contains(item.url()) && KProtocolInfo::protocolClass(url.scheme()) == QStringLiteral(":local")) { - KIO::StatJob *job = KIO::stat(url, KIO::HideProgressInfo); - job->setProperty("org.kde.plasma.folder_url", item.url()); - job->setSide(KIO::StatJob::SourceSide); - job->setDetails(0); - connect(job, &KJob::result, this, &FolderModel::statResult); - } + if (!file.hasLinkType()) { + return false; } + + const QUrl url(file.readUrl()); + + // Check if we already have a running StatJob for this URL. + if (m_isDirJobs.contains(item.url())) { + return false; + } + + if (KProtocolInfo::protocolClass(url.scheme()) != QStringLiteral(":local")) { + return false; + } + + KIO::StatJob *job = KIO::stat(url, KIO::HideProgressInfo); + job->setProperty("org.kde.plasma.folder_url", item.url()); + job->setSide(KIO::StatJob::SourceSide); + job->setDetails(0); + connect(job, &KJob::result, this, &FolderModel::statResult); + m_isDirJobs.insert(item.url(), job); } return false; @@ -1363,6 +1372,8 @@ emit dataChanged(idx, idx, QVector() << IsDirRole); } + + m_isDirJobs.remove(url); } void FolderModel::evictFromIsDirCache(const KFileItemList& items)