mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-28 12:45:20 +00:00
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:
This commit is contained in:
parent
67910325b5
commit
815bb8d514
|
@ -1308,7 +1308,10 @@ are displayed in a tree view, where the sub items can be expanded by &LMB; click
|
|||
<guiicon>></guiicon> icon and collapsed by clicking the <guiicon>v</guiicon> icon.
|
||||
</para>
|
||||
<para>
|
||||
<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).
|
||||
<guilabel>Folder size</guilabel> allows defining the property to use for sorting folders by their size.
|
||||
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>.
|
||||
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 <guilabel>Show no size</guilabel> (which might improve performance in rare cases, however impacts other features like sorting).
|
||||
</para>
|
||||
<para>
|
||||
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> (⪚, <quote>Yesterday, 3:00pm</quote>) or <guilabel>Absolute</guilabel> (⪚, <quote>2020-12-23 15:00</quote>).
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<QPair<int, QVariant>> 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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -6,9 +6,20 @@
|
|||
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
|
||||
<kcfgfile name="dolphinrc"/>
|
||||
<group name="ContentDisplay">
|
||||
<entry name="DirectorySizeCount" type="Bool">
|
||||
<label>Whether or not content count is used as directory size</label>
|
||||
<default>true</default>
|
||||
<entry name="DirectorySizeMode" type="Enum">
|
||||
<label>How we display the size of directories</label>
|
||||
<choices>
|
||||
<choice name="ContentCount">
|
||||
<label>Show the content count</label>
|
||||
</choice>
|
||||
<choice name="ContentSize">
|
||||
<label>Show the content size</label>
|
||||
</choice>
|
||||
<choice name="None">
|
||||
<label>Do not show any directory size</label>
|
||||
</choice>
|
||||
</choices>
|
||||
<default>ContentCount</default>
|
||||
</entry>
|
||||
<entry name="RecursiveDirectorySizeLimit" type="UInt">
|
||||
<label>Recursive directory size limit</label>
|
||||
|
|
10
src/settings/dolphin_directorysizemode.py
Normal file
10
src/settings/dolphin_directorysizemode.py
Normal file
|
@ -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")
|
||||
|
9
src/settings/dolphin_directorysizemode.upd
Normal file
9
src/settings/dolphin_directorysizemode.upd
Normal file
|
@ -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
|
||||
|
|
@ -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());
|
||||
|
|
|
@ -36,6 +36,7 @@ private:
|
|||
|
||||
QRadioButton *m_numberOfItems;
|
||||
QRadioButton *m_sizeOfContents;
|
||||
QRadioButton *m_noDirectorySize;
|
||||
QSpinBox *m_recursiveDirectorySizeLimit;
|
||||
QRadioButton *m_useRelatetiveDates;
|
||||
QRadioButton *m_useShortDates;
|
||||
|
|
Loading…
Reference in a new issue