mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-28 03:21:56 +00:00
FolderPanel: prevents scanning directory tree recursively
KFileItemListView contents are periodically scanned by KFileItemModelRolesUpdater. It uses then KDirectoryContentsCounter to scan directories to determine their size possibly recursively. Introduce a scanDirectories setting to disable directory scanning by KFileItemModelRolesUpdater. BUG: 426617 FIXED-IN: 20.08.3
This commit is contained in:
parent
5e9a869a39
commit
ffe01ee840
|
@ -39,7 +39,8 @@ KFileItemListView::KFileItemListView(QGraphicsWidget* parent) :
|
|||
KStandardItemListView(parent),
|
||||
m_modelRolesUpdater(nullptr),
|
||||
m_updateVisibleIndexRangeTimer(nullptr),
|
||||
m_updateIconSizeTimer(nullptr)
|
||||
m_updateIconSizeTimer(nullptr),
|
||||
m_scanDirectories(true)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
|
@ -117,6 +118,19 @@ qlonglong KFileItemListView::localFileSizePreviewLimit() const
|
|||
return m_modelRolesUpdater ? m_modelRolesUpdater->localFileSizePreviewLimit() : 0;
|
||||
}
|
||||
|
||||
void KFileItemListView::setScanDirectories(bool enabled)
|
||||
{
|
||||
m_scanDirectories = enabled;
|
||||
if (m_modelRolesUpdater) {
|
||||
m_modelRolesUpdater->setScanDirectories(m_scanDirectories);
|
||||
}
|
||||
}
|
||||
|
||||
bool KFileItemListView::scanDirectories()
|
||||
{
|
||||
return m_scanDirectories;
|
||||
}
|
||||
|
||||
QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const
|
||||
{
|
||||
if (!model()) {
|
||||
|
@ -247,6 +261,7 @@ void KFileItemListView::onModelChanged(KItemModelBase* current, KItemModelBase*
|
|||
if (current) {
|
||||
m_modelRolesUpdater = new KFileItemModelRolesUpdater(static_cast<KFileItemModel*>(current), this);
|
||||
m_modelRolesUpdater->setIconSize(availableIconSize());
|
||||
m_modelRolesUpdater->setScanDirectories(scanDirectories());
|
||||
|
||||
applyRolesToModel();
|
||||
}
|
||||
|
|
|
@ -69,6 +69,13 @@ public:
|
|||
void setLocalFileSizePreviewLimit(qlonglong size);
|
||||
qlonglong localFileSizePreviewLimit() const;
|
||||
|
||||
/**
|
||||
* If set to true, directories contents are scanned to determine their size
|
||||
* Default true
|
||||
*/
|
||||
void setScanDirectories(bool enabled);
|
||||
bool scanDirectories();
|
||||
|
||||
QPixmap createDragPixmap(const KItemSet& indexes) const override;
|
||||
|
||||
protected:
|
||||
|
@ -118,6 +125,7 @@ private:
|
|||
KFileItemModelRolesUpdater* m_modelRolesUpdater;
|
||||
QTimer* m_updateVisibleIndexRangeTimer;
|
||||
QTimer* m_updateIconSizeTimer;
|
||||
bool m_scanDirectories;
|
||||
|
||||
friend class KFileItemListViewTest; // For unit testing
|
||||
};
|
||||
|
|
|
@ -67,6 +67,7 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
|
|||
m_resolvableRoles(),
|
||||
m_enabledPlugins(),
|
||||
m_localFileSizePreviewLimit(0),
|
||||
m_scanDirectories(true),
|
||||
m_pendingSortRoleItems(),
|
||||
m_pendingIndexes(),
|
||||
m_pendingPreviewItems(),
|
||||
|
@ -317,6 +318,16 @@ qlonglong KFileItemModelRolesUpdater::localFileSizePreviewLimit() const
|
|||
return m_localFileSizePreviewLimit;
|
||||
}
|
||||
|
||||
void KFileItemModelRolesUpdater::setScanDirectories(bool enabled)
|
||||
{
|
||||
m_scanDirectories = enabled;
|
||||
}
|
||||
|
||||
bool KFileItemModelRolesUpdater::scanDirectories() const
|
||||
{
|
||||
return m_scanDirectories;
|
||||
}
|
||||
|
||||
void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRanges)
|
||||
{
|
||||
QElapsedTimer timer;
|
||||
|
@ -1001,7 +1012,9 @@ void KFileItemModelRolesUpdater::applySortRole(int index)
|
|||
data.insert("type", item.mimeComment());
|
||||
} else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) {
|
||||
const QString path = item.localPath();
|
||||
m_directoryContentsCounter->scanDirectory(path);
|
||||
if (m_scanDirectories) {
|
||||
m_directoryContentsCounter->scanDirectory(path);
|
||||
}
|
||||
} else {
|
||||
// Probably the sort role is a baloo role - just determine all roles.
|
||||
data = rolesData(item);
|
||||
|
@ -1072,11 +1085,13 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte
|
|||
const bool getIsExpandableRole = m_roles.contains("isExpandable");
|
||||
|
||||
if ((getSizeRole || getIsExpandableRole) && item.isDir()) {
|
||||
if (item.isLocalFile()) {
|
||||
if (item.isLocalFile() && !item.isSlow()) {
|
||||
// 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();
|
||||
m_directoryContentsCounter->scanDirectory(path);
|
||||
if (m_scanDirectories) {
|
||||
const QString path = item.localPath();
|
||||
m_directoryContentsCounter->scanDirectory(path);
|
||||
}
|
||||
} else if (getSizeRole) {
|
||||
data.insert("size", -1); // -1 indicates an unknown number of items
|
||||
}
|
||||
|
|
|
@ -152,6 +152,13 @@ public:
|
|||
void setLocalFileSizePreviewLimit(qlonglong size);
|
||||
qlonglong localFileSizePreviewLimit() const;
|
||||
|
||||
/**
|
||||
* If set to true, directories contents are scanned to determine their size
|
||||
* Default true
|
||||
*/
|
||||
void setScanDirectories(bool enabled);
|
||||
bool scanDirectories() const;
|
||||
|
||||
private slots:
|
||||
void slotItemsInserted(const KItemRangeList& itemRanges);
|
||||
void slotItemsRemoved(const KItemRangeList& itemRanges);
|
||||
|
@ -307,6 +314,7 @@ private:
|
|||
QSet<QByteArray> m_resolvableRoles;
|
||||
QStringList m_enabledPlugins;
|
||||
qulonglong m_localFileSizePreviewLimit;
|
||||
bool m_scanDirectories;
|
||||
|
||||
// Items for which the sort role still has to be determined.
|
||||
QSet<KFileItem> m_pendingSortRoleItems;
|
||||
|
|
|
@ -131,6 +131,7 @@ void FoldersPanel::showEvent(QShowEvent* event)
|
|||
// This assures that no performance and memory overhead is given when the folders panel is not
|
||||
// used at all and stays invisible.
|
||||
KFileItemListView* view = new KFileItemListView();
|
||||
view->setScanDirectories(false);
|
||||
view->setWidgetCreator(new KItemListWidgetCreator<FoldersItemListWidget>());
|
||||
view->setSupportsItemExpanding(true);
|
||||
// Set the opacity to 0 initially. The opacity will be increased after the loading of the initial tree
|
||||
|
|
Loading…
Reference in a new issue