From: Nico Kreipke Date: Sat, 2 Mar 2024 16:44:41 +0000 (+0100) Subject: Add option to completely disable directory size counting X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/815bb8d514d70d79ef5f3fd7fffa95850f761d55?ds=sidebyside Add option to completely disable directory size counting Dolphin shows the size of directories by listing their contents, which for some users might cause unwanted load on the file system. Depending on the size of the subdirectories in question and how the storage is accessed, this might cause noticeable delays and even freezing. This commit adds a new option under "View -> Content Display" that enables users to set "Folder size:" to "No size", completely disabling directory size counting. Directory size counting is still enabled by default. As a third option for "Folder size" is added, the DirectorySizeCount boolean setting is replaced with a DirectorySizeMode enum setting. The old setting is migrated using a kconf_update script. FEATURE: 477187 GUI: --- diff --git a/doc/index.docbook b/doc/index.docbook index a337c14a8..43ee0db44 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -1308,7 +1308,10 @@ are displayed in a tree view, where the sub items can be expanded by &LMB; click > icon and collapsed by clicking the v icon. -Folder size displays allows defining the property to use then sorting folders by their size. It is possible to sort folders by Number of items or Size of contents and choose a limit to the recursive level (can be useful to constrain unneeded iterations in the deep folder structures or on the slow file systems). +Folder size allows defining the property to use for sorting folders by their size. +It is possible to sort folders by number of items by choosing Show number of items or by the size of the contents by choosing Show size of contents. +The recursion level can be limited, which can be useful to constrain unneeded iterations in deep folder structures or on slow file systems. +It is also possible to disable displaying folder size by choosing Show no size (which might improve performance in rare cases, however impacts other features like sorting). The Date style option can be used to configure the mode to display dates in &dolphin;. It is possible to choose between Relative (⪚, Yesterday, 3:00pm) or Absolute (⪚, 2020-12-23 15:00). diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 18494fc8d..5c49612ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -600,6 +600,8 @@ install( FILES settings/dolphin_directoryviewpropertysettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR} ) install( FILES settings/dolphin_detailsmodesettings.upd + settings/dolphin_directorysizemode.upd + settings/dolphin_directorysizemode.py DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR} ) if(BUILD_TESTING) diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp index d94117e4c..fcfc9d7b1 100644 --- a/src/kitemviews/kfileitemlistwidget.cpp +++ b/src/kitemviews/kfileitemlistwidget.cpp @@ -67,7 +67,8 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray &role, const QHa if (values.value("isDir").toBool()) { if (!roleValue.isNull() && roleValue != -1) { // The item represents a directory. - if (ContentDisplaySettings::directorySizeCount() || roleValue == -2 /* size is invalid */) { + if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount + || roleValue == -2 /* size is invalid */) { // Show the number of sub directories instead of the file size of the directory. const int count = values.value("count").toInt(); text = i18ncp("@item:intable", "%1 item", "%1 items", count); diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 99a3d163f..9ef66d6b8 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -2019,7 +2019,8 @@ bool KFileItemModel::lessThan(const ItemData *a, const ItemData *b, const QColla } } - if (m_sortDirsFirst || (ContentDisplaySettings::directorySizeCount() && m_sortRole == SizeRole)) { + if (m_sortDirsFirst + || (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && m_sortRole == SizeRole)) { const bool isDirA = a->item.isDir(); const bool isDirB = b->item.isDir(); if (isDirA && !isDirB) { @@ -2071,7 +2072,7 @@ int KFileItemModel::sortRoleCompare(const ItemData *a, const ItemData *b, const break; case SizeRole: { - if (ContentDisplaySettings::directorySizeCount() && itemA.isDir()) { + if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && itemA.isDir()) { // folders first then // items A and B are folders thanks to lessThan checks auto valueA = a->values.value("count"); @@ -2331,7 +2332,7 @@ QList> KFileItemModel::sizeRoleGroups() const KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U; QString newGroupValue; if (!item.isNull() && item.isDir()) { - if (ContentDisplaySettings::directorySizeCount() || m_sortDirsFirst) { + if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount || m_sortDirsFirst) { newGroupValue = i18nc("@title:group Size", "Folders"); } else { fileSize = m_itemData.at(i)->values.value("size").toULongLong(); diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index 2a3a8eeb3..0ff431ac9 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -1288,11 +1288,11 @@ bool KFileItemModelRolesUpdater::applyResolvedRoles(int index, ResolveHint hint) void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &item, int index) { - if (!item.isLocalFile()) { + if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::None || !item.isLocalFile()) { return; } - if (ContentDisplaySettings::directorySizeCount() || item.isSlow()) { + if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount || item.isSlow()) { // fastpath no recursion necessary auto data = m_model->data(index); diff --git a/src/settings/dolphin_contentdisplaysettings.kcfg b/src/settings/dolphin_contentdisplaysettings.kcfg index 36895b869..31c6f75df 100644 --- a/src/settings/dolphin_contentdisplaysettings.kcfg +++ b/src/settings/dolphin_contentdisplaysettings.kcfg @@ -6,9 +6,20 @@ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd"> - - - true + + + + + + + + + + + + + + ContentCount diff --git a/src/settings/dolphin_directorysizemode.py b/src/settings/dolphin_directorysizemode.py new file mode 100644 index 000000000..6d58a062c --- /dev/null +++ b/src/settings/dolphin_directorysizemode.py @@ -0,0 +1,10 @@ +import fileinput + +for line in fileinput.input(): + if line.startswith("DirectorySizeCount=true"): + print("DirectorySizeMode=ContentCount") + if line.startswith("DirectorySizeCount=false"): + print("DirectorySizeMode=ContentSize") + +print("# DELETE DirectorySizeCount") + diff --git a/src/settings/dolphin_directorysizemode.upd b/src/settings/dolphin_directorysizemode.upd new file mode 100644 index 000000000..2bab4e01b --- /dev/null +++ b/src/settings/dolphin_directorysizemode.upd @@ -0,0 +1,9 @@ +#Configuration update for Dolphin +Version=5 + +#Convert DirectorySizeCount to enum DirectorySizeMode +Id=convert-directorysizecount-to-directorysizemode +File=dolphinrc +Group=ContentDisplay +Script=dolphin_directorysizemode.py,python3 + diff --git a/src/settings/viewmodes/contentdisplaytab.cpp b/src/settings/viewmodes/contentdisplaytab.cpp index f674e194e..2d817277c 100644 --- a/src/settings/viewmodes/contentdisplaytab.cpp +++ b/src/settings/viewmodes/contentdisplaytab.cpp @@ -24,6 +24,7 @@ ContentDisplayTab::ContentDisplayTab(QWidget *parent) , m_caseInsensitiveSorting(nullptr) , m_numberOfItems(nullptr) , m_sizeOfContents(nullptr) + , m_noDirectorySize(nullptr) , m_recursiveDirectorySizeLimit(nullptr) , m_useRelatetiveDates(nullptr) , m_useShortDates(nullptr) @@ -48,12 +49,14 @@ ContentDisplayTab::ContentDisplayTab(QWidget *parent) #ifndef Q_OS_WIN // Sorting properties - m_numberOfItems = new QRadioButton(i18nc("option:radio", "Number of items")); - m_sizeOfContents = new QRadioButton(i18nc("option:radio", "Size of contents, up to ")); + m_numberOfItems = new QRadioButton(i18nc("option:radio", "Show number of items")); + m_sizeOfContents = new QRadioButton(i18nc("option:radio", "Show size of contents, up to ")); + m_noDirectorySize = new QRadioButton(i18nc("option:radio", "Show no size")); QButtonGroup *sortingModeGroup = new QButtonGroup(this); sortingModeGroup->addButton(m_numberOfItems); sortingModeGroup->addButton(m_sizeOfContents); + sortingModeGroup->addButton(m_noDirectorySize); m_recursiveDirectorySizeLimit = new QSpinBox(); connect(m_recursiveDirectorySizeLimit, &QSpinBox::valueChanged, this, [this](int value) { @@ -66,8 +69,9 @@ ContentDisplayTab::ContentDisplayTab(QWidget *parent) contentsSizeLayout->addWidget(m_sizeOfContents); contentsSizeLayout->addWidget(m_recursiveDirectorySizeLimit); - topLayout->addRow(i18nc("@title:group", "Folder size displays:"), m_numberOfItems); + topLayout->addRow(i18nc("@title:group", "Folder size:"), m_numberOfItems); topLayout->addRow(QString(), contentsSizeLayout); + topLayout->addRow(QString(), m_noDirectorySize); #endif QDateTime thirtyMinutesAgo = QDateTime::currentDateTime().addSecs(-30 * 60); @@ -105,6 +109,7 @@ ContentDisplayTab::ContentDisplayTab(QWidget *parent) connect(m_sizeOfContents, &QRadioButton::toggled, this, [=]() { m_recursiveDirectorySizeLimit->setEnabled(m_sizeOfContents->isChecked()); }); + connect(m_noDirectorySize, &QRadioButton::toggled, this, &SettingsPageBase::changed); #endif connect(m_useRelatetiveDates, &QRadioButton::toggled, this, &SettingsPageBase::changed); @@ -123,7 +128,14 @@ void ContentDisplayTab::applySettings() { auto settings = ContentDisplaySettings::self(); #ifndef Q_OS_WIN - settings->setDirectorySizeCount(m_numberOfItems->isChecked()); + if (m_numberOfItems->isChecked()) { + settings->setDirectorySizeMode(ContentDisplaySettings::EnumDirectorySizeMode::ContentCount); + } else if (m_sizeOfContents->isChecked()) { + settings->setDirectorySizeMode(ContentDisplaySettings::EnumDirectorySizeMode::ContentSize); + } else if (m_noDirectorySize->isChecked()) { + settings->setDirectorySizeMode(ContentDisplaySettings::EnumDirectorySizeMode::None); + } + settings->setRecursiveDirectorySizeLimit(m_recursiveDirectorySizeLimit->value()); #endif setSortingChoiceValue(); @@ -143,13 +155,9 @@ void ContentDisplayTab::loadSettings() { auto settings = ContentDisplaySettings::self(); #ifndef Q_OS_WIN - if (settings->directorySizeCount()) { - m_numberOfItems->setChecked(true); - m_recursiveDirectorySizeLimit->setEnabled(false); - } else { - m_sizeOfContents->setChecked(true); - m_recursiveDirectorySizeLimit->setEnabled(true); - } + m_numberOfItems->setChecked(settings->directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount); + m_sizeOfContents->setChecked(settings->directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentSize); + m_noDirectorySize->setChecked(settings->directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::None); m_recursiveDirectorySizeLimit->setValue(settings->recursiveDirectorySizeLimit()); #endif m_useRelatetiveDates->setChecked(settings->useShortRelativeDates()); diff --git a/src/settings/viewmodes/contentdisplaytab.h b/src/settings/viewmodes/contentdisplaytab.h index 3550569fd..05e8414e1 100644 --- a/src/settings/viewmodes/contentdisplaytab.h +++ b/src/settings/viewmodes/contentdisplaytab.h @@ -36,6 +36,7 @@ private: QRadioButton *m_numberOfItems; QRadioButton *m_sizeOfContents; + QRadioButton *m_noDirectorySize; QSpinBox *m_recursiveDirectorySizeLimit; QRadioButton *m_useRelatetiveDates; QRadioButton *m_useShortDates;