diff --git a/src/kitemviews/kfileitemmodelrolesupdater.h b/src/kitemviews/kfileitemmodelrolesupdater.h --- a/src/kitemviews/kfileitemmodelrolesupdater.h +++ b/src/kitemviews/kfileitemmodelrolesupdater.h @@ -313,6 +313,7 @@ QSet m_roles; QSet m_resolvableRoles; QStringList m_enabledPlugins; + bool m_localFileSizeLimit; // Items for which the sort role still has to be determined. QSet m_pendingSortRoleItems; diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -95,6 +95,7 @@ const KConfigGroup globalConfig(KSharedConfig::openConfig(), "PreviewSettings"); m_enabledPlugins = globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins()); + m_localFileSizeLimit = globalConfig.readEntry("LimitLocalFiles", false); connect(m_model, &KFileItemModel::itemsInserted, this, &KFileItemModelRolesUpdater::slotItemsInserted); @@ -900,7 +901,7 @@ KIO::PreviewJob* job = new KIO::PreviewJob(itemSubSet, cacheSize, &m_enabledPlugins); - job->setIgnoreMaximumSize(itemSubSet.first().isLocalFile()); + job->setIgnoreMaximumSize(!m_localFileSizeLimit); if (job->uiDelegate()) { KJobWidgets::setWindow(job, qApp->activeWindow()); } diff --git a/src/settings/general/previewssettingspage.h b/src/settings/general/previewssettingspage.h --- a/src/settings/general/previewssettingspage.h +++ b/src/settings/general/previewssettingspage.h @@ -20,6 +20,7 @@ #ifndef PREVIEWSSETTINGSPAGE_H #define PREVIEWSSETTINGSPAGE_H +#include #include "settings/settingspagebase.h" class QSpinBox; @@ -56,11 +57,14 @@ private: void loadPreviewPlugins(); void loadSettings(); + void useTypeChanged(); private: bool m_initialized; QListView *m_listView; QStringList m_enabledPreviewPlugins; + QCheckBox *m_localFileSizeLimit; + QSpinBox* m_localFileSizeBox; QSpinBox* m_remoteFileSizeBox; }; diff --git a/src/settings/general/previewssettingspage.cpp b/src/settings/general/previewssettingspage.cpp --- a/src/settings/general/previewssettingspage.cpp +++ b/src/settings/general/previewssettingspage.cpp @@ -38,14 +38,17 @@ // default settings namespace { - const int MaxRemotePreviewSize = 0; // 0 MB + const bool LimitLocalFilesPreview = false; + const int DefaultMaxLocalPreviewSize = 50; // 50 MB + const int DefaultMaxRemotePreviewSize = 0; // 0 MB } PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) : SettingsPageBase(parent), m_initialized(false), m_listView(nullptr), m_enabledPreviewPlugins(), + m_localFileSizeBox(nullptr), m_remoteFileSizeBox(nullptr) { QVBoxLayout* topLayout = new QVBoxLayout(this); @@ -68,24 +71,41 @@ m_listView->setItemDelegate(delegate); m_listView->setVerticalScrollMode(QListView::ScrollPerPixel); + m_localFileSizeLimit = new QCheckBox(i18n("Skip previews for local files above:"), this); + + m_localFileSizeBox = new QSpinBox(this); + m_localFileSizeBox->setSingleStep(1); + m_localFileSizeBox->setSuffix(QStringLiteral(" MB")); + m_localFileSizeBox->setRange(1, 9999999); /* MB */ + + QHBoxLayout* localFileSizeBoxLayout = new QHBoxLayout(); + localFileSizeBoxLayout->addWidget(m_localFileSizeLimit); + localFileSizeBoxLayout->addStretch(0); + localFileSizeBoxLayout->addWidget(m_localFileSizeBox); + QLabel* remoteFileSizeLabel = new QLabel(i18nc("@label", "Skip previews for remote files above:"), this); m_remoteFileSizeBox = new QSpinBox(this); m_remoteFileSizeBox->setSingleStep(1); m_remoteFileSizeBox->setSuffix(QStringLiteral(" MB")); m_remoteFileSizeBox->setRange(0, 9999999); /* MB */ - QHBoxLayout* fileSizeBoxLayout = new QHBoxLayout(); - fileSizeBoxLayout->addWidget(remoteFileSizeLabel, 0, Qt::AlignRight); - fileSizeBoxLayout->addWidget(m_remoteFileSizeBox); + QHBoxLayout* remoteFileSizeBoxLayout = new QHBoxLayout(); + remoteFileSizeBoxLayout->addWidget(remoteFileSizeLabel); + remoteFileSizeBoxLayout->addStretch(0); + remoteFileSizeBoxLayout->addWidget(m_remoteFileSizeBox); topLayout->addWidget(showPreviewsLabel); topLayout->addWidget(m_listView); - topLayout->addLayout(fileSizeBoxLayout); + topLayout->addLayout(localFileSizeBoxLayout); + topLayout->addLayout(remoteFileSizeBoxLayout); loadSettings(); connect(m_listView, &QListView::clicked, this, &PreviewsSettingsPage::changed); + connect(m_localFileSizeBox, QOverload::of(&QSpinBox::valueChanged), this, &PreviewsSettingsPage::changed); + connect(m_localFileSizeLimit, &QAbstractButton::toggled, this, &PreviewsSettingsPage::useTypeChanged); + connect(m_localFileSizeLimit, &QAbstractButton::toggled, this, &PreviewsSettingsPage::changed); connect(m_remoteFileSizeBox, QOverload::of(&QSpinBox::valueChanged), this, &PreviewsSettingsPage::changed); } @@ -112,6 +132,15 @@ KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); globalConfig.writeEntry("Plugins", m_enabledPreviewPlugins); + globalConfig.writeEntry("LimitLocalFiles", + m_localFileSizeLimit->isChecked(), + KConfigBase::Normal | KConfigBase::Global); + + const qulonglong maximumLocalSize = static_cast(m_localFileSizeBox->value()) * 1024 * 1024; + globalConfig.writeEntry("MaximumSize", + maximumLocalSize, + KConfigBase::Normal | KConfigBase::Global); + const qulonglong maximumRemoteSize = static_cast(m_remoteFileSizeBox->value()) * 1024 * 1024; globalConfig.writeEntry("MaximumRemoteSize", maximumRemoteSize, @@ -121,7 +150,9 @@ void PreviewsSettingsPage::restoreDefaults() { - m_remoteFileSizeBox->setValue(MaxRemotePreviewSize); + m_localFileSizeLimit->setChecked(LimitLocalFilesPreview); + m_localFileSizeBox->setValue(DefaultMaxLocalPreviewSize); + m_remoteFileSizeBox->setValue(DefaultMaxRemotePreviewSize); } void PreviewsSettingsPage::showEvent(QShowEvent* event) @@ -169,9 +200,22 @@ const KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); m_enabledPreviewPlugins = globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins()); - const qulonglong defaultRemotePreview = static_cast(MaxRemotePreviewSize) * 1024 * 1024; + const bool limitLocalPreviews = globalConfig.readEntry("LimitLocalFiles", LimitLocalFilesPreview); + m_localFileSizeLimit->setChecked(limitLocalPreviews); + + const qulonglong defaultLocalPreview = static_cast(DefaultMaxLocalPreviewSize) * 1024 * 1024; + const qulonglong maxLocalByteSize = globalConfig.readEntry("MaximumSize", defaultLocalPreview); + const int maxLocalMByteSize = maxLocalByteSize / (1024 * 1024); + m_localFileSizeBox->setValue(maxLocalMByteSize); + m_localFileSizeBox->setEnabled(m_localFileSizeLimit->isChecked()); + + const qulonglong defaultRemotePreview = static_cast(DefaultMaxRemotePreviewSize) * 1024 * 1024; const qulonglong maxRemoteByteSize = globalConfig.readEntry("MaximumRemoteSize", defaultRemotePreview); const int maxRemoteMByteSize = maxRemoteByteSize / (1024 * 1024); m_remoteFileSizeBox->setValue(maxRemoteMByteSize); } +void PreviewsSettingsPage::useTypeChanged() +{ + m_localFileSizeBox->setEnabled(m_localFileSizeLimit->isChecked()); +}