]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/configurepreviewplugindialog.cpp
15cd9266722cbcd158ebf06a69357797c48cb61d
[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 <KPluginLoader>
23 #include <KLocalizedString>
24 #include <KJobWidgets>
25 #include <KIO/JobUiDelegate>
26 #include <KIO/DeleteJob>
27 #include <KIO/ThumbCreator>
28
29 #include <QUrl>
30 #include <QLibrary>
31 #include <QVBoxLayout>
32 #include <QStandardPaths>
33 #include <QDialogButtonBox>
34 #include <QPushButton>
35
36 ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString& pluginName,
37 const QString& desktopEntryName,
38 QWidget* parent) :
39 QDialog(parent)
40 {
41 QSharedPointer<ThumbCreator> previewPlugin;
42 const QString pluginPath = KPluginLoader::findPlugin(desktopEntryName);
43 if (!pluginPath.isEmpty()) {
44 newCreator create = (newCreator)QLibrary::resolve(pluginPath, "new_creator");
45 if (create) {
46 previewPlugin.reset(dynamic_cast<ThumbCreator*>(create()));
47 }
48 }
49
50 setWindowTitle(i18nc("@title:window", "Configure Preview for %1", pluginName));
51 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
52 setMinimumWidth(400);
53
54 auto layout = new QVBoxLayout(this);
55 setLayout(layout);
56
57 if (previewPlugin) {
58 auto configurationWidget = previewPlugin->createConfigurationWidget();
59 configurationWidget->setParent(this);
60 layout->addWidget(configurationWidget);
61
62 layout->addStretch();
63
64 connect(this, &ConfigurePreviewPluginDialog::accepted, this, [=] {
65 // TODO: It would be great having a mechanism to tell PreviewJob that only previews
66 // for a specific MIME-type should be regenerated. As this is not available yet we
67 // delete the whole thumbnails directory.
68 previewPlugin->writeConfiguration(configurationWidget);
69
70 // http://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html#DIRECTORY
71 const QString thumbnailsPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/thumbnails/");
72 KIO::del(QUrl::fromLocalFile(thumbnailsPath), KIO::HideProgressInfo);
73 });
74 }
75
76 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
77 connect(buttonBox, &QDialogButtonBox::accepted, this, &ConfigurePreviewPluginDialog::accept);
78 connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfigurePreviewPluginDialog::reject);
79 layout->addWidget(buttonBox);
80
81 auto okButton = buttonBox->button(QDialogButtonBox::Ok);
82 okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
83 okButton->setDefault(true);
84 }