diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 63cbaa6ddc..97bc770d7b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -288,6 +288,7 @@ target_sources(dolphinstatic PRIVATE selectionmode/bottombarcontentscontainer.cpp selectionmode/topbar.cpp settings/general/behaviorsettingspage.cpp + settings/general/configurepreviewplugindialog.cpp settings/general/confirmationssettingspage.cpp settings/general/generalsettingspage.cpp settings/general/previewssettingspage.cpp @@ -346,6 +347,7 @@ target_sources(dolphinstatic PRIVATE selectionmode/bottombarcontentscontainer.h selectionmode/topbar.h settings/general/behaviorsettingspage.h + settings/general/configurepreviewplugindialog.h settings/general/confirmationssettingspage.h settings/general/generalsettingspage.h settings/general/previewssettingspage.h @@ -522,6 +524,7 @@ if(NOT WIN32) settings/kcm/kcmdolphingeneral.cpp settings/general/behaviorsettingspage.cpp settings/general/previewssettingspage.cpp + settings/general/configurepreviewplugindialog.cpp settings/general/confirmationssettingspage.cpp settings/settingspagebase.cpp settings/serviceitemdelegate.cpp @@ -529,6 +532,7 @@ if(NOT WIN32) settings/kcm/kcmdolphingeneral.h settings/general/behaviorsettingspage.h settings/general/previewssettingspage.h + settings/general/configurepreviewplugindialog.h settings/general/confirmationssettingspage.h settings/settingspagebase.h settings/serviceitemdelegate.h diff --git a/src/settings/general/configurepreviewplugindialog.cpp b/src/settings/general/configurepreviewplugindialog.cpp new file mode 100644 index 0000000000..a391812dfd --- /dev/null +++ b/src/settings/general/configurepreviewplugindialog.cpp @@ -0,0 +1,71 @@ +/* + * SPDX-FileCopyrightText: 2011 Peter Penz + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "configurepreviewplugindialog.h" + +#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87) + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString &pluginName, const QString &desktopEntryName, QWidget *parent) + : QDialog(parent) +{ + QSharedPointer previewPlugin; + const QString pluginPath = QPluginLoader(desktopEntryName).fileName(); + if (!pluginPath.isEmpty()) { + newCreator create = (newCreator)QLibrary::resolve(pluginPath, "new_creator"); + if (create) { + previewPlugin.reset(dynamic_cast(create())); + } + } + + setWindowTitle(i18nc("@title:window", "Configure Preview for %1", pluginName)); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); + setMinimumWidth(400); + + auto layout = new QVBoxLayout(this); + + if (previewPlugin) { + auto configurationWidget = previewPlugin->createConfigurationWidget(); + configurationWidget->setParent(this); + layout->addWidget(configurationWidget); + + layout->addStretch(); + + connect(this, &ConfigurePreviewPluginDialog::accepted, this, [=] { + // TODO: It would be great having a mechanism to tell PreviewJob that only previews + // for a specific MIME-type should be regenerated. As this is not available yet we + // delete the whole thumbnails directory. + previewPlugin->writeConfiguration(configurationWidget); + + // https://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html#DIRECTORY + const QString thumbnailsPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/thumbnails/"); + KIO::del(QUrl::fromLocalFile(thumbnailsPath), KIO::HideProgressInfo); + }); + } + + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); + connect(buttonBox, &QDialogButtonBox::accepted, this, &ConfigurePreviewPluginDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfigurePreviewPluginDialog::reject); + layout->addWidget(buttonBox); + + auto okButton = buttonBox->button(QDialogButtonBox::Ok); + okButton->setShortcut(Qt::CTRL | Qt::Key_Return); + okButton->setDefault(true); +} + +#endif // KIO_VERSION diff --git a/src/settings/general/configurepreviewplugindialog.h b/src/settings/general/configurepreviewplugindialog.h new file mode 100644 index 0000000000..66504cce2e --- /dev/null +++ b/src/settings/general/configurepreviewplugindialog.h @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: 2011 Peter Penz + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef CONFIGUREPREVIEWPLUGINDIALOG_H +#define CONFIGUREPREVIEWPLUGINDIALOG_H + +#include + +#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87) + +#include + +/** + * @brief Dialog for configuring preview-plugins. + */ +class ConfigurePreviewPluginDialog : public QDialog +{ + Q_OBJECT + +public: + /** + * @param pluginName User visible name of the plugin + * @param desktopEntryName The name of the plugin that is noted in the desktopentry. + * Is used to instantiate the plugin to get the configuration + * widget. + * @param parent Parent widget. + */ + ConfigurePreviewPluginDialog(const QString &pluginName, const QString &desktopEntryName, QWidget *parent); + ~ConfigurePreviewPluginDialog() override = default; +}; +#endif // KIOWIDGETS_BUILD_DEPRECATED_SINCE + +#endif diff --git a/src/settings/general/previewssettingspage.cpp b/src/settings/general/previewssettingspage.cpp index fa715237a4..358798f58e 100644 --- a/src/settings/general/previewssettingspage.cpp +++ b/src/settings/general/previewssettingspage.cpp @@ -6,6 +6,7 @@ #include "previewssettingspage.h" +#include "configurepreviewplugindialog.h" #include "dolphin_generalsettings.h" #include "settings/serviceitemdelegate.h" #include "settings/servicemodel.h" @@ -44,6 +45,12 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget *parent) m_listView = new QListView(this); QScroller::grabGesture(m_listView->viewport(), QScroller::TouchGesture); +#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87) + ServiceItemDelegate *delegate = new ServiceItemDelegate(m_listView, m_listView); + connect(delegate, &ServiceItemDelegate::requestServiceConfiguration, this, &PreviewsSettingsPage::configureService); + m_listView->setItemDelegate(delegate); +#endif + ServiceModel *serviceModel = new ServiceModel(this); QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); proxyModel->setSourceModel(serviceModel); @@ -143,6 +150,19 @@ void PreviewsSettingsPage::showEvent(QShowEvent *event) SettingsPageBase::showEvent(event); } +#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87) +void PreviewsSettingsPage::configureService(const QModelIndex &index) +{ + const QAbstractItemModel *model = index.model(); + const QString pluginName = model->data(index).toString(); + const QString desktopEntryName = model->data(index, ServiceModel::DesktopEntryNameRole).toString(); + + ConfigurePreviewPluginDialog *dialog = new ConfigurePreviewPluginDialog(pluginName, desktopEntryName, this); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); +} +#endif + void PreviewsSettingsPage::loadPreviewPlugins() { QAbstractItemModel *model = m_listView->model(); @@ -156,6 +176,11 @@ void PreviewsSettingsPage::loadPreviewPlugins() model->setData(index, show, Qt::CheckStateRole); model->setData(index, plugin.name(), Qt::DisplayRole); 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); diff --git a/src/settings/general/previewssettingspage.h b/src/settings/general/previewssettingspage.h index d6d22ae218..2c3e4dfeff 100644 --- a/src/settings/general/previewssettingspage.h +++ b/src/settings/general/previewssettingspage.h @@ -40,6 +40,9 @@ protected: void showEvent(QShowEvent *event) override; private Q_SLOTS: +#if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 87) + void configureService(const QModelIndex &index); +#endif private: void loadPreviewPlugins();