]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/configurepreviewplugindialog.cpp
bc3cca706803c3c1d6494306086f085812ae4f38
[dolphin.git] / src / settings / general / configurepreviewplugindialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "configurepreviewplugindialog.h"
21
22 #include <KIO/DeleteJob>
23 #include <KIO/JobUiDelegate>
24 #include <KIO/ThumbCreator>
25 #include <KJobWidgets>
26 #include <KLocalizedString>
27 #include <KPluginLoader>
28
29 #include <QDialogButtonBox>
30 #include <QPushButton>
31 #include <QStandardPaths>
32 #include <QUrl>
33 #include <QVBoxLayout>
34
35 ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString& pluginName,
36 const QString& desktopEntryName,
37 QWidget* parent) :
38 QDialog(parent)
39 {
40 QSharedPointer<ThumbCreator> previewPlugin;
41 const QString pluginPath = KPluginLoader::findPlugin(desktopEntryName);
42 if (!pluginPath.isEmpty()) {
43 newCreator create = (newCreator)QLibrary::resolve(pluginPath, "new_creator");
44 if (create) {
45 previewPlugin.reset(dynamic_cast<ThumbCreator*>(create()));
46 }
47 }
48
49 setWindowTitle(i18nc("@title:window", "Configure Preview for %1", pluginName));
50 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
51 setMinimumWidth(400);
52
53 auto layout = new QVBoxLayout(this);
54 setLayout(layout);
55
56 if (previewPlugin) {
57 auto configurationWidget = previewPlugin->createConfigurationWidget();
58 configurationWidget->setParent(this);
59 layout->addWidget(configurationWidget);
60
61 layout->addStretch();
62
63 connect(this, &ConfigurePreviewPluginDialog::accepted, this, [=] {
64 // TODO: It would be great having a mechanism to tell PreviewJob that only previews
65 // for a specific MIME-type should be regenerated. As this is not available yet we
66 // delete the whole thumbnails directory.
67 previewPlugin->writeConfiguration(configurationWidget);
68
69 // https://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html#DIRECTORY
70 const QString thumbnailsPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/thumbnails/");
71 KIO::del(QUrl::fromLocalFile(thumbnailsPath), KIO::HideProgressInfo);
72 });
73 }
74
75 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
76 connect(buttonBox, &QDialogButtonBox::accepted, this, &ConfigurePreviewPluginDialog::accept);
77 connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfigurePreviewPluginDialog::reject);
78 layout->addWidget(buttonBox);
79
80 auto okButton = buttonBox->button(QDialogButtonBox::Ok);
81 okButton->setShortcut(Qt::CTRL + Qt::Key_Return);
82 okButton->setDefault(true);
83 }