]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/configurepreviewplugindialog.cpp
eb9ad010c039673bc47a624c07b0554f64b21057
[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
34 ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString& pluginName,
35 const QString& desktopEntryName,
36 QWidget* parent) :
37 KDialog(parent)
38 {
39 QSharedPointer<ThumbCreator> previewPlugin;
40 const QString pluginPath = KPluginLoader::findPlugin(desktopEntryName);
41 if (!pluginPath.isEmpty()) {
42 newCreator create = (newCreator)QLibrary::resolve(pluginPath, "new_creator");
43 if (create) {
44 previewPlugin.reset(dynamic_cast<ThumbCreator*>(create()));
45 }
46 }
47
48 setCaption(i18nc("@title:window", "Configure Preview for %1", pluginName));
49 setMinimumWidth(400);
50 setButtons(Ok | Cancel);
51 setDefaultButton(Ok);
52
53 if (previewPlugin) {
54 auto mainWidget = new QWidget(this);
55 mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
56 setMainWidget(mainWidget);
57
58 auto configurationWidget = previewPlugin->createConfigurationWidget();
59 configurationWidget->setParent(mainWidget);
60
61 auto layout = new QVBoxLayout(mainWidget);
62 layout->addWidget(configurationWidget);
63 layout->addStretch();
64
65 connect(this, &ConfigurePreviewPluginDialog::okClicked, this, [=] {
66 // TODO: It would be great having a mechanism to tell PreviewJob that only previews
67 // for a specific MIME-type should be regenerated. As this is not available yet we
68 // delete the whole thumbnails directory.
69 previewPlugin->writeConfiguration(configurationWidget);
70
71 // http://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html#DIRECTORY
72 const QString thumbnailsPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/thumbnails/");
73 KIO::del(QUrl::fromLocalFile(thumbnailsPath), KIO::HideProgressInfo);
74 });
75 }
76 }