]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/configurepreviewplugindialog.cpp
15cd9266722cbcd158ebf06a69357797c48cb61d
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #include "configurepreviewplugindialog.h"
22 #include <KPluginLoader>
23 #include <KLocalizedString>
24 #include <KJobWidgets>
25 #include <KIO/JobUiDelegate>
26 #include <KIO/DeleteJob>
27 #include <KIO/ThumbCreator>
31 #include <QVBoxLayout>
32 #include <QStandardPaths>
33 #include <QDialogButtonBox>
34 #include <QPushButton>
36 ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString
& pluginName
,
37 const QString
& desktopEntryName
,
41 QSharedPointer
<ThumbCreator
> previewPlugin
;
42 const QString pluginPath
= KPluginLoader::findPlugin(desktopEntryName
);
43 if (!pluginPath
.isEmpty()) {
44 newCreator create
= (newCreator
)QLibrary::resolve(pluginPath
, "new_creator");
46 previewPlugin
.reset(dynamic_cast<ThumbCreator
*>(create()));
50 setWindowTitle(i18nc("@title:window", "Configure Preview for %1", pluginName
));
51 setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Minimum
);
54 auto layout
= new QVBoxLayout(this);
58 auto configurationWidget
= previewPlugin
->createConfigurationWidget();
59 configurationWidget
->setParent(this);
60 layout
->addWidget(configurationWidget
);
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
);
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
);
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
);
81 auto okButton
= buttonBox
->button(QDialogButtonBox::Ok
);
82 okButton
->setShortcut(Qt::CTRL
| Qt::Key_Return
);
83 okButton
->setDefault(true);