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