mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +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),
|
KStandardItemListView(parent),
|
||||||
m_modelRolesUpdater(nullptr),
|
m_modelRolesUpdater(nullptr),
|
||||||
m_updateVisibleIndexRangeTimer(nullptr),
|
m_updateVisibleIndexRangeTimer(nullptr),
|
||||||
m_updateIconSizeTimer(nullptr)
|
m_updateIconSizeTimer(nullptr),
|
||||||
|
m_scanDirectories(true)
|
||||||
{
|
{
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
|
||||||
|
@ -117,6 +118,19 @@ qlonglong KFileItemListView::localFileSizePreviewLimit() const
|
||||||
return m_modelRolesUpdater ? m_modelRolesUpdater->localFileSizePreviewLimit() : 0;
|
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
|
QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const
|
||||||
{
|
{
|
||||||
if (!model()) {
|
if (!model()) {
|
||||||
|
@ -247,6 +261,7 @@ void KFileItemListView::onModelChanged(KItemModelBase* current, KItemModelBase*
|
||||||
if (current) {
|
if (current) {
|
||||||
m_modelRolesUpdater = new KFileItemModelRolesUpdater(static_cast<KFileItemModel*>(current), this);
|
m_modelRolesUpdater = new KFileItemModelRolesUpdater(static_cast<KFileItemModel*>(current), this);
|
||||||
m_modelRolesUpdater->setIconSize(availableIconSize());
|
m_modelRolesUpdater->setIconSize(availableIconSize());
|
||||||
|
m_modelRolesUpdater->setScanDirectories(scanDirectories());
|
||||||
|
|
||||||
applyRolesToModel();
|
applyRolesToModel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,13 @@ public:
|
||||||
void setLocalFileSizePreviewLimit(qlonglong size);
|
void setLocalFileSizePreviewLimit(qlonglong size);
|
||||||
qlonglong localFileSizePreviewLimit() const;
|
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;
|
QPixmap createDragPixmap(const KItemSet& indexes) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -118,6 +125,7 @@ private:
|
||||||
KFileItemModelRolesUpdater* m_modelRolesUpdater;
|
KFileItemModelRolesUpdater* m_modelRolesUpdater;
|
||||||
QTimer* m_updateVisibleIndexRangeTimer;
|
QTimer* m_updateVisibleIndexRangeTimer;
|
||||||
QTimer* m_updateIconSizeTimer;
|
QTimer* m_updateIconSizeTimer;
|
||||||
|
bool m_scanDirectories;
|
||||||
|
|
||||||
friend class KFileItemListViewTest; // For unit testing
|
friend class KFileItemListViewTest; // For unit testing
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,6 +67,7 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
|
||||||
m_resolvableRoles(),
|
m_resolvableRoles(),
|
||||||
m_enabledPlugins(),
|
m_enabledPlugins(),
|
||||||
m_localFileSizePreviewLimit(0),
|
m_localFileSizePreviewLimit(0),
|
||||||
|
m_scanDirectories(true),
|
||||||
m_pendingSortRoleItems(),
|
m_pendingSortRoleItems(),
|
||||||
m_pendingIndexes(),
|
m_pendingIndexes(),
|
||||||
m_pendingPreviewItems(),
|
m_pendingPreviewItems(),
|
||||||
|
@ -317,6 +318,16 @@ qlonglong KFileItemModelRolesUpdater::localFileSizePreviewLimit() const
|
||||||
return m_localFileSizePreviewLimit;
|
return m_localFileSizePreviewLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KFileItemModelRolesUpdater::setScanDirectories(bool enabled)
|
||||||
|
{
|
||||||
|
m_scanDirectories = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KFileItemModelRolesUpdater::scanDirectories() const
|
||||||
|
{
|
||||||
|
return m_scanDirectories;
|
||||||
|
}
|
||||||
|
|
||||||
void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRanges)
|
void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRanges)
|
||||||
{
|
{
|
||||||
QElapsedTimer timer;
|
QElapsedTimer timer;
|
||||||
|
@ -1001,7 +1012,9 @@ void KFileItemModelRolesUpdater::applySortRole(int index)
|
||||||
data.insert("type", item.mimeComment());
|
data.insert("type", item.mimeComment());
|
||||||
} else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) {
|
} else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) {
|
||||||
const QString path = item.localPath();
|
const QString path = item.localPath();
|
||||||
m_directoryContentsCounter->scanDirectory(path);
|
if (m_scanDirectories) {
|
||||||
|
m_directoryContentsCounter->scanDirectory(path);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Probably the sort role is a baloo role - just determine all roles.
|
// Probably the sort role is a baloo role - just determine all roles.
|
||||||
data = rolesData(item);
|
data = rolesData(item);
|
||||||
|
@ -1072,11 +1085,13 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte
|
||||||
const bool getIsExpandableRole = m_roles.contains("isExpandable");
|
const bool getIsExpandableRole = m_roles.contains("isExpandable");
|
||||||
|
|
||||||
if ((getSizeRole || getIsExpandableRole) && item.isDir()) {
|
if ((getSizeRole || getIsExpandableRole) && item.isDir()) {
|
||||||
if (item.isLocalFile()) {
|
if (item.isLocalFile() && !item.isSlow()) {
|
||||||
// Tell m_directoryContentsCounter that we want to count the items
|
// Tell m_directoryContentsCounter that we want to count the items
|
||||||
// inside the directory. The result will be received in slotDirectoryContentsCountReceived.
|
// inside the directory. The result will be received in slotDirectoryContentsCountReceived.
|
||||||
const QString path = item.localPath();
|
if (m_scanDirectories) {
|
||||||
m_directoryContentsCounter->scanDirectory(path);
|
const QString path = item.localPath();
|
||||||
|
m_directoryContentsCounter->scanDirectory(path);
|
||||||
|
}
|
||||||
} else if (getSizeRole) {
|
} else if (getSizeRole) {
|
||||||
data.insert("size", -1); // -1 indicates an unknown number of items
|
data.insert("size", -1); // -1 indicates an unknown number of items
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,6 +152,13 @@ public:
|
||||||
void setLocalFileSizePreviewLimit(qlonglong size);
|
void setLocalFileSizePreviewLimit(qlonglong size);
|
||||||
qlonglong localFileSizePreviewLimit() const;
|
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:
|
private slots:
|
||||||
void slotItemsInserted(const KItemRangeList& itemRanges);
|
void slotItemsInserted(const KItemRangeList& itemRanges);
|
||||||
void slotItemsRemoved(const KItemRangeList& itemRanges);
|
void slotItemsRemoved(const KItemRangeList& itemRanges);
|
||||||
|
@ -307,6 +314,7 @@ private:
|
||||||
QSet<QByteArray> m_resolvableRoles;
|
QSet<QByteArray> m_resolvableRoles;
|
||||||
QStringList m_enabledPlugins;
|
QStringList m_enabledPlugins;
|
||||||
qulonglong m_localFileSizePreviewLimit;
|
qulonglong m_localFileSizePreviewLimit;
|
||||||
|
bool m_scanDirectories;
|
||||||
|
|
||||||
// Items for which the sort role still has to be determined.
|
// Items for which the sort role still has to be determined.
|
||||||
QSet<KFileItem> m_pendingSortRoleItems;
|
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
|
// This assures that no performance and memory overhead is given when the folders panel is not
|
||||||
// used at all and stays invisible.
|
// used at all and stays invisible.
|
||||||
KFileItemListView* view = new KFileItemListView();
|
KFileItemListView* view = new KFileItemListView();
|
||||||
|
view->setScanDirectories(false);
|
||||||
view->setWidgetCreator(new KItemListWidgetCreator<FoldersItemListWidget>());
|
view->setWidgetCreator(new KItemListWidgetCreator<FoldersItemListWidget>());
|
||||||
view->setSupportsItemExpanding(true);
|
view->setSupportsItemExpanding(true);
|
||||||
// Set the opacity to 0 initially. The opacity will be increased after the loading of the initial tree
|
// Set the opacity to 0 initially. The opacity will be increased after the loading of the initial tree
|
||||||
|
|
Loading…
Reference in a new issue