]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/configurepreviewplugindialog.cpp
Fix includes
[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 <KLibrary>
23 #include <KLocalizedString>
24 #include <KIO/NetAccess>
25 #include <kio/thumbcreator.h>
26
27 #include <QApplication>
28 #include <QDir>
29 #include <QVBoxLayout>
30 #include <QUrl>
31
32 ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString& pluginName,
33 const QString& desktopEntryName,
34 QWidget* parent) :
35 KDialog(parent),
36 m_configurationWidget(0),
37 m_previewPlugin(0)
38 {
39 KLibrary library(desktopEntryName);
40 if (library.load()) {
41 newCreator create = (newCreator)library.resolveFunction("new_creator");
42 if (create) {
43 m_previewPlugin = dynamic_cast<ThumbCreatorV2*>(create());
44 }
45 }
46
47 setCaption(i18nc("@title:window", "Configure Preview for %1", pluginName));
48 setMinimumWidth(400);
49 setButtons(Ok | Cancel);
50 setDefaultButton(Ok);
51
52 QWidget* mainWidget = new QWidget(this);
53 mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
54 QVBoxLayout* layout = new QVBoxLayout(mainWidget);
55 if (m_previewPlugin) {
56 m_configurationWidget = m_previewPlugin->createConfigurationWidget();
57 layout->addWidget(m_configurationWidget);
58 }
59 layout->addStretch(1);
60
61 setMainWidget(mainWidget);
62
63 connect(this, &ConfigurePreviewPluginDialog::okClicked, this, &ConfigurePreviewPluginDialog::slotOk);
64 }
65
66 ConfigurePreviewPluginDialog::~ConfigurePreviewPluginDialog()
67 {
68 }
69
70 void ConfigurePreviewPluginDialog::slotOk()
71 {
72 m_previewPlugin->writeConfiguration(m_configurationWidget);
73 // TODO: It would be great having a mechanism to tell PreviewJob that only previews
74 // for a specific MIME-type should be regenerated. As this is not available yet we
75 // delete the whole thumbnails directory.
76 QApplication::changeOverrideCursor(Qt::BusyCursor);
77 KIO::NetAccess::del(QUrl::fromLocalFile(QDir::homePath() + "/.thumbnails/"), this);
78 QApplication::restoreOverrideCursor();
79
80 }
81