Skip to content

Commit 815bb8d

Browse files
nkreipkeMéven Car
authored and
Méven Car
committed
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:
1 parent 6791032 commit 815bb8d

10 files changed

+67
-21
lines changed

doc/index.docbook

+4-1
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,10 @@ are displayed in a tree view, where the sub items can be expanded by &LMB; click
13081308
<guiicon>&gt;</guiicon> icon and collapsed by clicking the <guiicon>v</guiicon> icon.
13091309
</para>
13101310
<para>
1311-
<guilabel>Folder size displays</guilabel> allows defining the property to use then sorting folders by their size. It is possible to sort folders by <guilabel>Number of items</guilabel> or <guilabel>Size of contents</guilabel> 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).
1311+
<guilabel>Folder size</guilabel> allows defining the property to use for sorting folders by their size.
1312+
It is possible to sort folders by number of items by choosing <guilabel>Show number of items</guilabel> or by the size of the contents by choosing <guilabel>Show size of contents</guilabel>.
1313+
The recursion level can be limited, which can be useful to constrain unneeded iterations in deep folder structures or on slow file systems.
1314+
It is also possible to disable displaying folder size by choosing <guilabel>Show no size</guilabel> (which might improve performance in rare cases, however impacts other features like sorting).
13121315
</para>
13131316
<para>
13141317
The <guilabel>Date style</guilabel> option can be used to configure the mode to display dates in &dolphin;. It is possible to choose between <guilabel>Relative</guilabel> (&eg;, <quote>Yesterday, 3:00pm</quote>) or <guilabel>Absolute</guilabel> (&eg;, <quote>2020-12-23 15:00</quote>).

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ install( FILES settings/dolphin_directoryviewpropertysettings.kcfg
600600
DESTINATION ${KDE_INSTALL_KCFGDIR} )
601601

602602
install( FILES settings/dolphin_detailsmodesettings.upd
603+
settings/dolphin_directorysizemode.upd
604+
settings/dolphin_directorysizemode.py
603605
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR} )
604606

605607
if(BUILD_TESTING)

src/kitemviews/kfileitemlistwidget.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray &role, const QHa
6767
if (values.value("isDir").toBool()) {
6868
if (!roleValue.isNull() && roleValue != -1) {
6969
// The item represents a directory.
70-
if (ContentDisplaySettings::directorySizeCount() || roleValue == -2 /* size is invalid */) {
70+
if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount
71+
|| roleValue == -2 /* size is invalid */) {
7172
// Show the number of sub directories instead of the file size of the directory.
7273
const int count = values.value("count").toInt();
7374
text = i18ncp("@item:intable", "%1 item", "%1 items", count);

src/kitemviews/kfileitemmodel.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,8 @@ bool KFileItemModel::lessThan(const ItemData *a, const ItemData *b, const QColla
20192019
}
20202020
}
20212021

2022-
if (m_sortDirsFirst || (ContentDisplaySettings::directorySizeCount() && m_sortRole == SizeRole)) {
2022+
if (m_sortDirsFirst
2023+
|| (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && m_sortRole == SizeRole)) {
20232024
const bool isDirA = a->item.isDir();
20242025
const bool isDirB = b->item.isDir();
20252026
if (isDirA && !isDirB) {
@@ -2071,7 +2072,7 @@ int KFileItemModel::sortRoleCompare(const ItemData *a, const ItemData *b, const
20712072
break;
20722073

20732074
case SizeRole: {
2074-
if (ContentDisplaySettings::directorySizeCount() && itemA.isDir()) {
2075+
if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount && itemA.isDir()) {
20752076
// folders first then
20762077
// items A and B are folders thanks to lessThan checks
20772078
auto valueA = a->values.value("count");
@@ -2331,7 +2332,7 @@ QList<QPair<int, QVariant>> KFileItemModel::sizeRoleGroups() const
23312332
KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U;
23322333
QString newGroupValue;
23332334
if (!item.isNull() && item.isDir()) {
2334-
if (ContentDisplaySettings::directorySizeCount() || m_sortDirsFirst) {
2335+
if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount || m_sortDirsFirst) {
23352336
newGroupValue = i18nc("@title:group Size", "Folders");
23362337
} else {
23372338
fileSize = m_itemData.at(i)->values.value("size").toULongLong();

src/kitemviews/kfileitemmodelrolesupdater.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1288,11 +1288,11 @@ bool KFileItemModelRolesUpdater::applyResolvedRoles(int index, ResolveHint hint)
12881288

12891289
void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &item, int index)
12901290
{
1291-
if (!item.isLocalFile()) {
1291+
if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::None || !item.isLocalFile()) {
12921292
return;
12931293
}
12941294

1295-
if (ContentDisplaySettings::directorySizeCount() || item.isSlow()) {
1295+
if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount || item.isSlow()) {
12961296
// fastpath no recursion necessary
12971297

12981298
auto data = m_model->data(index);

src/settings/dolphin_contentdisplaysettings.kcfg

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@
66
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
77
<kcfgfile name="dolphinrc"/>
88
<group name="ContentDisplay">
9-
<entry name="DirectorySizeCount" type="Bool">
10-
<label>Whether or not content count is used as directory size</label>
11-
<default>true</default>
9+
<entry name="DirectorySizeMode" type="Enum">
10+
<label>How we display the size of directories</label>
11+
<choices>
12+
<choice name="ContentCount">
13+
<label>Show the content count</label>
14+
</choice>
15+
<choice name="ContentSize">
16+
<label>Show the content size</label>
17+
</choice>
18+
<choice name="None">
19+
<label>Do not show any directory size</label>
20+
</choice>
21+
</choices>
22+
<default>ContentCount</default>
1223
</entry>
1324
<entry name="RecursiveDirectorySizeLimit" type="UInt">
1425
<label>Recursive directory size limit</label>
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import fileinput
2+
3+
for line in fileinput.input():
4+
if line.startswith("DirectorySizeCount=true"):
5+
print("DirectorySizeMode=ContentCount")
6+
if line.startswith("DirectorySizeCount=false"):
7+
print("DirectorySizeMode=ContentSize")
8+
9+
print("# DELETE DirectorySizeCount")
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Configuration update for Dolphin
2+
Version=5
3+
4+
#Convert DirectorySizeCount to enum DirectorySizeMode
5+
Id=convert-directorysizecount-to-directorysizemode
6+
File=dolphinrc
7+
Group=ContentDisplay
8+
Script=dolphin_directorysizemode.py,python3
9+

src/settings/viewmodes/contentdisplaytab.cpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ContentDisplayTab::ContentDisplayTab(QWidget *parent)
2424
, m_caseInsensitiveSorting(nullptr)
2525
, m_numberOfItems(nullptr)
2626
, m_sizeOfContents(nullptr)
27+
, m_noDirectorySize(nullptr)
2728
, m_recursiveDirectorySizeLimit(nullptr)
2829
, m_useRelatetiveDates(nullptr)
2930
, m_useShortDates(nullptr)
@@ -48,12 +49,14 @@ ContentDisplayTab::ContentDisplayTab(QWidget *parent)
4849

4950
#ifndef Q_OS_WIN
5051
// Sorting properties
51-
m_numberOfItems = new QRadioButton(i18nc("option:radio", "Number of items"));
52-
m_sizeOfContents = new QRadioButton(i18nc("option:radio", "Size of contents, up to "));
52+
m_numberOfItems = new QRadioButton(i18nc("option:radio", "Show number of items"));
53+
m_sizeOfContents = new QRadioButton(i18nc("option:radio", "Show size of contents, up to "));
54+
m_noDirectorySize = new QRadioButton(i18nc("option:radio", "Show no size"));
5355

5456
QButtonGroup *sortingModeGroup = new QButtonGroup(this);
5557
sortingModeGroup->addButton(m_numberOfItems);
5658
sortingModeGroup->addButton(m_sizeOfContents);
59+
sortingModeGroup->addButton(m_noDirectorySize);
5760

5861
m_recursiveDirectorySizeLimit = new QSpinBox();
5962
connect(m_recursiveDirectorySizeLimit, &QSpinBox::valueChanged, this, [this](int value) {
@@ -66,8 +69,9 @@ ContentDisplayTab::ContentDisplayTab(QWidget *parent)
6669
contentsSizeLayout->addWidget(m_sizeOfContents);
6770
contentsSizeLayout->addWidget(m_recursiveDirectorySizeLimit);
6871

69-
topLayout->addRow(i18nc("@title:group", "Folder size displays:"), m_numberOfItems);
72+
topLayout->addRow(i18nc("@title:group", "Folder size:"), m_numberOfItems);
7073
topLayout->addRow(QString(), contentsSizeLayout);
74+
topLayout->addRow(QString(), m_noDirectorySize);
7175
#endif
7276

7377
QDateTime thirtyMinutesAgo = QDateTime::currentDateTime().addSecs(-30 * 60);
@@ -105,6 +109,7 @@ ContentDisplayTab::ContentDisplayTab(QWidget *parent)
105109
connect(m_sizeOfContents, &QRadioButton::toggled, this, [=]() {
106110
m_recursiveDirectorySizeLimit->setEnabled(m_sizeOfContents->isChecked());
107111
});
112+
connect(m_noDirectorySize, &QRadioButton::toggled, this, &SettingsPageBase::changed);
108113
#endif
109114

110115
connect(m_useRelatetiveDates, &QRadioButton::toggled, this, &SettingsPageBase::changed);
@@ -123,7 +128,14 @@ void ContentDisplayTab::applySettings()
123128
{
124129
auto settings = ContentDisplaySettings::self();
125130
#ifndef Q_OS_WIN
126-
settings->setDirectorySizeCount(m_numberOfItems->isChecked());
131+
if (m_numberOfItems->isChecked()) {
132+
settings->setDirectorySizeMode(ContentDisplaySettings::EnumDirectorySizeMode::ContentCount);
133+
} else if (m_sizeOfContents->isChecked()) {
134+
settings->setDirectorySizeMode(ContentDisplaySettings::EnumDirectorySizeMode::ContentSize);
135+
} else if (m_noDirectorySize->isChecked()) {
136+
settings->setDirectorySizeMode(ContentDisplaySettings::EnumDirectorySizeMode::None);
137+
}
138+
127139
settings->setRecursiveDirectorySizeLimit(m_recursiveDirectorySizeLimit->value());
128140
#endif
129141
setSortingChoiceValue();
@@ -143,13 +155,9 @@ void ContentDisplayTab::loadSettings()
143155
{
144156
auto settings = ContentDisplaySettings::self();
145157
#ifndef Q_OS_WIN
146-
if (settings->directorySizeCount()) {
147-
m_numberOfItems->setChecked(true);
148-
m_recursiveDirectorySizeLimit->setEnabled(false);
149-
} else {
150-
m_sizeOfContents->setChecked(true);
151-
m_recursiveDirectorySizeLimit->setEnabled(true);
152-
}
158+
m_numberOfItems->setChecked(settings->directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount);
159+
m_sizeOfContents->setChecked(settings->directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentSize);
160+
m_noDirectorySize->setChecked(settings->directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::None);
153161
m_recursiveDirectorySizeLimit->setValue(settings->recursiveDirectorySizeLimit());
154162
#endif
155163
m_useRelatetiveDates->setChecked(settings->useShortRelativeDates());

src/settings/viewmodes/contentdisplaytab.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ContentDisplayTab : public SettingsPageBase
3636

3737
QRadioButton *m_numberOfItems;
3838
QRadioButton *m_sizeOfContents;
39+
QRadioButton *m_noDirectorySize;
3940
QSpinBox *m_recursiveDirectorySizeLimit;
4041
QRadioButton *m_useRelatetiveDates;
4142
QRadioButton *m_useShortDates;

0 commit comments

Comments
 (0)