Commit d4839a25 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Folder View] Use KIO::PreviewJob::defaultPlugins() for default plugins

Rather than a hardcoded list of only two thumbnailers.
All of this is done under the hood so the QML part doesn't need to be changed.
This is the same behavior as Dolphin uses, when the list of thumbnailers is empty, the default set (which includes all thumbnailers
except textthumbs) is used.

CHANGELOG: Folder View now enables previews for most file types by default

Differential Revision: https://phabricator.kde.org/D15268
parent 95c0c3bc
......@@ -91,8 +91,8 @@
<default>true</default>
</entry>
<entry name="previewPlugins" type="StringList">
<label>List of id's of the thumbnail preview plugins to use in Folder View.</label>
<default>imagethumbnail,jpegthumbnail</default>
<label>List of ids of the thumbnail preview plugins to use in Folder View. If empty, uses a default set of thumbnailers (cf. KIO::PreviewJob::defaultPlugins)</label>
<default></default>
</entry>
<entry name="viewMode" type="Int">
<label>The Folder View view mode (used only by the widget full represntation): 0 = Grid, 1 = List</label>
......
......@@ -70,6 +70,7 @@
#include <KDirModel>
#include <KIO/CopyJob>
#include <KIO/Job>
#include <KIO/PreviewJob>
#include <KProtocolInfo>
#include <KRun>
......@@ -513,7 +514,7 @@ void FolderModel::setViewAdapter(QObject* adapter)
if (m_viewAdapter && !m_previewGenerator) {
m_previewGenerator = new KFilePreviewGenerator(abstractViewAdapter, this);
m_previewGenerator->setPreviewShown(m_previews);
m_previewGenerator->setEnabledPlugins(m_previewPlugins);
m_previewGenerator->setEnabledPlugins(m_effectivePreviewPlugins);
}
emit viewAdapterChanged();
......@@ -545,15 +546,23 @@ QStringList FolderModel::previewPlugins() const
void FolderModel::setPreviewPlugins(const QStringList& previewPlugins)
{
if (m_previewPlugins != previewPlugins) {
m_previewPlugins = previewPlugins;
QStringList effectivePlugins = previewPlugins;
if (effectivePlugins.isEmpty()) {
effectivePlugins = KIO::PreviewJob::defaultPlugins();
}
if (m_effectivePreviewPlugins != effectivePlugins) {
m_effectivePreviewPlugins = effectivePlugins;
if (m_previewGenerator) {
m_previewGenerator->setPreviewShown(false);
m_previewGenerator->setEnabledPlugins(m_previewPlugins);
m_previewGenerator->setEnabledPlugins(m_effectivePreviewPlugins);
m_previewGenerator->setPreviewShown(true);
}
}
if (m_previewPlugins != previewPlugins) {
m_previewPlugins = previewPlugins;
emit previewPluginsChanged();
}
}
......
......@@ -343,7 +343,11 @@ class FOLDERPLUGIN_TESTS_EXPORT FolderModel : public QSortFilterProxyModel, publ
bool m_sortDirsFirst;
bool m_parseDesktopFiles;
bool m_previews;
// An empty previewPlugin list means use default.
// We don't want to leak that fact to the QML side, however, so the property stays empty
// and internally we operate on effectivePreviewPlugins instead.
QStringList m_previewPlugins;
QStringList m_effectivePreviewPlugins;
FilterMode m_filterMode;
QString m_filterPattern;
bool m_filterPatternMatchAll;
......
......@@ -22,6 +22,10 @@
#include <KServiceTypeTrader>
#include <KIO/PreviewJob>
#include <algorithm>
static bool lessThan(const KService::Ptr &a, const KService::Ptr &b)
{
return QString::localeAwareCompare(a->name(), b->name()) < 0;
......@@ -92,9 +96,14 @@ int PreviewPluginsModel::indexOfPlugin(const QString &name) const
void PreviewPluginsModel::setCheckedPlugins(const QStringList &list)
{
QStringList plugins = list;
if (plugins.isEmpty()) {
plugins = KIO::PreviewJob::defaultPlugins();
}
m_checkedRows = QVector<bool>(m_plugins.size(), false);
foreach (const QString &name, list) {
for (const QString &name : plugins) {
const int row = indexOfPlugin(name);
if (row != -1) {
m_checkedRows[row] = true;
......@@ -114,5 +123,15 @@ QStringList PreviewPluginsModel::checkedPlugins() const
list.append(m_plugins.at(i)->desktopEntryName());
}
}
const QStringList defaultPlugins = KIO::PreviewJob::defaultPlugins();
// If the list of checked plugins is the default set, return an empty list
// which denotes the default set.
// This ensures newly installed thumbnails are always automatically enabled.
if (std::is_permutation(list.constBegin(), list.constEnd(), defaultPlugins.begin())) {
return QStringList();
}
return list;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment