Port away from deprecated ThumbCreator API

Configurability of individual preview plugins has been deprecated since KIO
5.87.
This commit is contained in:
Ahmad Samir 2022-05-05 22:07:03 +02:00
parent 5cbe6b5302
commit e58f0c085c
4 changed files with 25 additions and 3 deletions

View file

@ -6,6 +6,8 @@
#include "configurepreviewplugindialog.h" #include "configurepreviewplugindialog.h"
#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87)
#include <KIO/DeleteJob> #include <KIO/DeleteJob>
#include <KIO/JobUiDelegate> #include <KIO/JobUiDelegate>
#include <KIO/ThumbCreator> #include <KIO/ThumbCreator>
@ -67,3 +69,5 @@ ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString& plugin
okButton->setShortcut(Qt::CTRL | Qt::Key_Return); okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
okButton->setDefault(true); okButton->setDefault(true);
} }
#endif // KIO_VERSION

View file

@ -7,6 +7,11 @@
#ifndef CONFIGUREPREVIEWPLUGINDIALOG_H #ifndef CONFIGUREPREVIEWPLUGINDIALOG_H
#define CONFIGUREPREVIEWPLUGINDIALOG_H #define CONFIGUREPREVIEWPLUGINDIALOG_H
#include <QtGlobal>
#include <kiowidgets_export.h>
#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87)
#include <QDialog> #include <QDialog>
/** /**
@ -29,5 +34,6 @@ public:
QWidget* parent); QWidget* parent);
~ConfigurePreviewPluginDialog() override = default; ~ConfigurePreviewPluginDialog() override = default;
}; };
#endif // KIOWIDGETS_BUILD_DEPRECATED_SINCE
#endif #endif

View file

@ -45,9 +45,12 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
m_listView = new QListView(this); m_listView = new QListView(this);
QScroller::grabGesture(m_listView->viewport(), QScroller::TouchGesture); QScroller::grabGesture(m_listView->viewport(), QScroller::TouchGesture);
#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87)
ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView); ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView);
connect(delegate, &ServiceItemDelegate::requestServiceConfiguration, connect(delegate, &ServiceItemDelegate::requestServiceConfiguration,
this, &PreviewsSettingsPage::configureService); this, &PreviewsSettingsPage::configureService);
m_listView->setItemDelegate(delegate);
#endif
ServiceModel* serviceModel = new ServiceModel(this); ServiceModel* serviceModel = new ServiceModel(this);
QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this); QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this);
@ -56,7 +59,6 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
m_listView->setModel(proxyModel); m_listView->setModel(proxyModel);
m_listView->setItemDelegate(delegate);
m_listView->setVerticalScrollMode(QListView::ScrollPerPixel); m_listView->setVerticalScrollMode(QListView::ScrollPerPixel);
m_listView->setUniformItemSizes(true); m_listView->setUniformItemSizes(true);
@ -153,6 +155,7 @@ void PreviewsSettingsPage::showEvent(QShowEvent* event)
SettingsPageBase::showEvent(event); SettingsPageBase::showEvent(event);
} }
#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87)
void PreviewsSettingsPage::configureService(const QModelIndex& index) void PreviewsSettingsPage::configureService(const QModelIndex& index)
{ {
const QAbstractItemModel* model = index.model(); const QAbstractItemModel* model = index.model();
@ -163,6 +166,7 @@ void PreviewsSettingsPage::configureService(const QModelIndex& index)
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show(); dialog->show();
} }
#endif
void PreviewsSettingsPage::loadPreviewPlugins() void PreviewsSettingsPage::loadPreviewPlugins()
{ {
@ -170,15 +174,18 @@ void PreviewsSettingsPage::loadPreviewPlugins()
const QVector<KPluginMetaData> plugins = KIO::PreviewJob::availableThumbnailerPlugins(); const QVector<KPluginMetaData> plugins = KIO::PreviewJob::availableThumbnailerPlugins();
for (const KPluginMetaData &plugin : plugins) { for (const KPluginMetaData &plugin : plugins) {
const bool configurable = plugin.value(QStringLiteral("Configurable"), false);
const bool show = m_enabledPreviewPlugins.contains(plugin.pluginId()); const bool show = m_enabledPreviewPlugins.contains(plugin.pluginId());
model->insertRow(0); model->insertRow(0);
const QModelIndex index = model->index(0, 0); const QModelIndex index = model->index(0, 0);
model->setData(index, show, Qt::CheckStateRole); model->setData(index, show, Qt::CheckStateRole);
model->setData(index, configurable, ServiceModel::ConfigurableRole);
model->setData(index, plugin.name(), Qt::DisplayRole); model->setData(index, plugin.name(), Qt::DisplayRole);
model->setData(index, plugin.pluginId(), ServiceModel::DesktopEntryNameRole); model->setData(index, plugin.pluginId(), ServiceModel::DesktopEntryNameRole);
#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87)
const bool configurable = plugin.value(QStringLiteral("Configurable"), false);
model->setData(index, configurable, ServiceModel::ConfigurableRole);
#endif
} }
model->sort(Qt::DisplayRole); model->sort(Qt::DisplayRole);

View file

@ -7,6 +7,9 @@
#ifndef PREVIEWSSETTINGSPAGE_H #ifndef PREVIEWSSETTINGSPAGE_H
#define PREVIEWSSETTINGSPAGE_H #define PREVIEWSSETTINGSPAGE_H
#include <kiowidgets_export.h>
#include "settings/settingspagebase.h" #include "settings/settingspagebase.h"
class QSpinBox; class QSpinBox;
@ -38,7 +41,9 @@ protected:
void showEvent(QShowEvent* event) override; void showEvent(QShowEvent* event) override;
private Q_SLOTS: private Q_SLOTS:
#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87)
void configureService(const QModelIndex& index); void configureService(const QModelIndex& index);
#endif
private: private:
void loadPreviewPlugins(); void loadPreviewPlugins();