Changeset View
Changeset View
Standalone View
Standalone View
containments/desktop/plugins/folder/foldermodel.cpp
Show First 20 Lines • Show All 1266 Lines • ▼ Show 20 Line(s) | 1262 | { | |||
---|---|---|---|---|---|
1267 | if (role == BlankRole) { | 1267 | if (role == BlankRole) { | ||
1268 | return m_dragIndexes.contains(index); | 1268 | return m_dragIndexes.contains(index); | ||
1269 | } else if (role == OverlaysRole) { | 1269 | } else if (role == OverlaysRole) { | ||
1270 | const KFileItem item = itemForIndex(index); | 1270 | const KFileItem item = itemForIndex(index); | ||
1271 | return item.overlays(); | 1271 | return item.overlays(); | ||
1272 | } else if (role == SelectedRole) { | 1272 | } else if (role == SelectedRole) { | ||
1273 | return m_selectionModel->isSelected(index); | 1273 | return m_selectionModel->isSelected(index); | ||
1274 | } else if (role == IsDirRole) { | 1274 | } else if (role == IsDirRole) { | ||
1275 | const QUrl &url = data(index, UrlRole).toUrl(); | | |||
1276 | | ||||
1277 | if (m_isDirCache.contains(url)) { | | |||
1278 | return m_isDirCache[url]; | | |||
1279 | } else { | | |||
1280 | return isDir(mapToSource(index), m_dirModel); | 1275 | return isDir(mapToSource(index), m_dirModel); | ||
1281 | } | | |||
1282 | } else if (role == IsLinkRole) { | 1276 | } else if (role == IsLinkRole) { | ||
1283 | const KFileItem item = itemForIndex(index); | 1277 | const KFileItem item = itemForIndex(index); | ||
1284 | return item.isLink(); | 1278 | return item.isLink(); | ||
1285 | } else if (role == IsHiddenRole) { | 1279 | } else if (role == IsHiddenRole) { | ||
1286 | const KFileItem item = itemForIndex(index); | 1280 | const KFileItem item = itemForIndex(index); | ||
1287 | return item.isHidden(); | 1281 | return item.isHidden(); | ||
1288 | } else if (role == UrlRole) { | 1282 | } else if (role == UrlRole) { | ||
1289 | return itemForIndex(index).url(); | 1283 | return itemForIndex(index).url(); | ||
Show All 36 Lines | |||||
1326 | 1320 | | |||
1327 | bool FolderModel::isDir(const QModelIndex &index, const KDirModel *dirModel) const | 1321 | bool FolderModel::isDir(const QModelIndex &index, const KDirModel *dirModel) const | ||
1328 | { | 1322 | { | ||
1329 | KFileItem item = dirModel->itemForIndex(index); | 1323 | KFileItem item = dirModel->itemForIndex(index); | ||
1330 | if (item.isDir()) { | 1324 | if (item.isDir()) { | ||
1331 | return true; | 1325 | return true; | ||
1332 | } | 1326 | } | ||
1333 | 1327 | | |||
1328 | auto it = m_isDirCache.constFind(item.url()); | ||||
1329 | if (it != m_isDirCache.constEnd()) { | ||||
1330 | return *it; | ||||
1331 | } | ||||
1332 | | ||||
1334 | if (m_parseDesktopFiles && item.isDesktopFile()) { | 1333 | if (m_parseDesktopFiles && item.isDesktopFile()) { | ||
1335 | // Check if the desktop file is a link to a directory | 1334 | // Check if the desktop file is a link to a directory | ||
1336 | KDesktopFile file(item.targetUrl().path()); | 1335 | KDesktopFile file(item.targetUrl().path()); | ||
1337 | 1336 | | |||
1338 | if (file.hasLinkType()) { | 1337 | if (!file.hasLinkType()) { | ||
1338 | return false; | ||||
1339 | } | ||||
1340 | | ||||
1339 | const QUrl url(file.readUrl()); | 1341 | const QUrl url(file.readUrl()); | ||
1340 | 1342 | | |||
1341 | if (!m_isDirCache.contains(item.url()) && KProtocolInfo::protocolClass(url.scheme()) == QStringLiteral(":local")) { | 1343 | // Check if we already have a running StatJob for this URL. | ||
1344 | if (m_isDirJobs.contains(item.url())) { | ||||
1345 | return false; | ||||
1346 | } | ||||
1347 | | ||||
1348 | if (KProtocolInfo::protocolClass(url.scheme()) != QStringLiteral(":local")) { | ||||
1349 | return false; | ||||
1350 | } | ||||
1351 | | ||||
1342 | KIO::StatJob *job = KIO::stat(url, KIO::HideProgressInfo); | 1352 | KIO::StatJob *job = KIO::stat(url, KIO::HideProgressInfo); | ||
1343 | job->setProperty("org.kde.plasma.folder_url", item.url()); | 1353 | job->setProperty("org.kde.plasma.folder_url", item.url()); | ||
1344 | job->setSide(KIO::StatJob::SourceSide); | 1354 | job->setSide(KIO::StatJob::SourceSide); | ||
1345 | job->setDetails(0); | 1355 | job->setDetails(0); | ||
1346 | connect(job, &KJob::result, this, &FolderModel::statResult); | 1356 | connect(job, &KJob::result, this, &FolderModel::statResult); | ||
1347 | } | 1357 | m_isDirJobs.insert(item.url(), job); | ||
1348 | } | | |||
1349 | } | 1358 | } | ||
1350 | 1359 | | |||
1351 | return false; | 1360 | return false; | ||
1352 | } | 1361 | } | ||
1353 | 1362 | | |||
1354 | void FolderModel::statResult(KJob *job) | 1363 | void FolderModel::statResult(KJob *job) | ||
1355 | { | 1364 | { | ||
1356 | KIO::StatJob *statJob = static_cast<KIO::StatJob*>(job); | 1365 | KIO::StatJob *statJob = static_cast<KIO::StatJob*>(job); | ||
1357 | 1366 | | |||
1358 | const QUrl &url = statJob->property("org.kde.plasma.folder_url").toUrl(); | 1367 | const QUrl &url = statJob->property("org.kde.plasma.folder_url").toUrl(); | ||
1359 | const QModelIndex &idx = index(indexForUrl(url), 0); | 1368 | const QModelIndex &idx = index(indexForUrl(url), 0); | ||
1360 | 1369 | | |||
1361 | if (idx.isValid()) { | 1370 | if (idx.isValid() && statJob->error() == KJob::NoError) { | ||
1362 | m_isDirCache[url] = statJob->statResult().isDir(); | 1371 | m_isDirCache[url] = statJob->statResult().isDir(); | ||
1363 | 1372 | | |||
1364 | emit dataChanged(idx, idx, QVector<int>() << IsDirRole); | 1373 | emit dataChanged(idx, idx, QVector<int>() << IsDirRole); | ||
1365 | } | 1374 | } | ||
1375 | | ||||
1376 | m_isDirJobs.remove(url); | ||||
1366 | } | 1377 | } | ||
1367 | 1378 | | |||
1368 | void FolderModel::evictFromIsDirCache(const KFileItemList& items) | 1379 | void FolderModel::evictFromIsDirCache(const KFileItemList& items) | ||
1369 | { | 1380 | { | ||
1370 | foreach (const KFileItem &item, items) { | 1381 | foreach (const KFileItem &item, items) { | ||
1371 | m_screenMapper->removeFromMap(item.url()); | 1382 | m_screenMapper->removeFromMap(item.url()); | ||
1372 | m_isDirCache.remove(item.url()); | 1383 | m_isDirCache.remove(item.url()); | ||
1373 | } | 1384 | } | ||
▲ Show 20 Lines • Show All 613 Lines • Show Last 20 Lines |