mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-21 17:30:15 +00:00
Port ConfigurePreviewPluginDialog away from KLibrary, KIO::NetAccess::del and ThumbCreatorV2
This commit is contained in:
parent
088b516057
commit
617e1b378b
|
@ -19,28 +19,29 @@
|
||||||
|
|
||||||
#include "configurepreviewplugindialog.h"
|
#include "configurepreviewplugindialog.h"
|
||||||
|
|
||||||
#include <KLibrary>
|
#include <KPluginLoader>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KIO/NetAccess>
|
#include <KJobWidgets>
|
||||||
#include <kio/thumbcreator.h>
|
#include <KIO/JobUiDelegate>
|
||||||
|
#include <KIO/DeleteJob>
|
||||||
|
#include <KIO/ThumbCreator>
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QLibrary>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString& pluginName,
|
ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString& pluginName,
|
||||||
const QString& desktopEntryName,
|
const QString& desktopEntryName,
|
||||||
QWidget* parent) :
|
QWidget* parent) :
|
||||||
KDialog(parent),
|
KDialog(parent)
|
||||||
m_configurationWidget(0),
|
|
||||||
m_previewPlugin(0)
|
|
||||||
{
|
{
|
||||||
KLibrary library(desktopEntryName);
|
QSharedPointer<ThumbCreator> previewPlugin;
|
||||||
if (library.load()) {
|
const QString pluginPath = KPluginLoader::findPlugin(desktopEntryName);
|
||||||
newCreator create = (newCreator)library.resolveFunction("new_creator");
|
if (!pluginPath.isEmpty()) {
|
||||||
|
newCreator create = (newCreator)QLibrary::resolve(pluginPath, "new_creator");
|
||||||
if (create) {
|
if (create) {
|
||||||
m_previewPlugin = dynamic_cast<ThumbCreatorV2*>(create());
|
previewPlugin.reset(dynamic_cast<ThumbCreator*>(create()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,31 +50,27 @@ ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString& plugin
|
||||||
setButtons(Ok | Cancel);
|
setButtons(Ok | Cancel);
|
||||||
setDefaultButton(Ok);
|
setDefaultButton(Ok);
|
||||||
|
|
||||||
QWidget* mainWidget = new QWidget(this);
|
if (previewPlugin) {
|
||||||
mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
|
auto mainWidget = new QWidget(this);
|
||||||
QVBoxLayout* layout = new QVBoxLayout(mainWidget);
|
mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
|
||||||
if (m_previewPlugin) {
|
setMainWidget(mainWidget);
|
||||||
m_configurationWidget = m_previewPlugin->createConfigurationWidget();
|
|
||||||
layout->addWidget(m_configurationWidget);
|
auto configurationWidget = previewPlugin->createConfigurationWidget();
|
||||||
|
configurationWidget->setParent(mainWidget);
|
||||||
|
|
||||||
|
auto layout = new QVBoxLayout(mainWidget);
|
||||||
|
layout->addWidget(configurationWidget);
|
||||||
|
layout->addStretch();
|
||||||
|
|
||||||
|
connect(this, &ConfigurePreviewPluginDialog::okClicked, 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);
|
||||||
|
|
||||||
|
// http://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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
layout->addStretch(1);
|
}
|
||||||
|
|
||||||
setMainWidget(mainWidget);
|
|
||||||
|
|
||||||
connect(this, &ConfigurePreviewPluginDialog::okClicked, this, &ConfigurePreviewPluginDialog::slotOk);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigurePreviewPluginDialog::~ConfigurePreviewPluginDialog()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigurePreviewPluginDialog::slotOk()
|
|
||||||
{
|
|
||||||
m_previewPlugin->writeConfiguration(m_configurationWidget);
|
|
||||||
// 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.
|
|
||||||
QApplication::changeOverrideCursor(Qt::BusyCursor);
|
|
||||||
KIO::NetAccess::del(QUrl::fromLocalFile(QDir::homePath() + "/.thumbnails/"), this);
|
|
||||||
QApplication::restoreOverrideCursor();
|
|
||||||
}
|
|
|
@ -22,8 +22,6 @@
|
||||||
|
|
||||||
#include <KDialog>
|
#include <KDialog>
|
||||||
|
|
||||||
class ThumbCreatorV2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Dialog for configuring preview-plugins.
|
* @brief Dialog for configuring preview-plugins.
|
||||||
*/
|
*/
|
||||||
|
@ -39,17 +37,10 @@ public:
|
||||||
* widget.
|
* widget.
|
||||||
* @param parent Parent widget.
|
* @param parent Parent widget.
|
||||||
*/
|
*/
|
||||||
explicit ConfigurePreviewPluginDialog(const QString& pluginName,
|
ConfigurePreviewPluginDialog(const QString& pluginName,
|
||||||
const QString& desktopEntryName,
|
const QString& desktopEntryName,
|
||||||
QWidget* parent = 0);
|
QWidget* parent);
|
||||||
virtual ~ConfigurePreviewPluginDialog();
|
virtual ~ConfigurePreviewPluginDialog() = default;
|
||||||
|
|
||||||
private slots:
|
|
||||||
void slotOk();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QWidget* m_configurationWidget;
|
|
||||||
ThumbCreatorV2* m_previewPlugin;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue