┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/settings/general
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-02-25 20:39:18 +0100
committerPeter Penz <[email protected]>2011-02-27 20:38:35 +0100
commit1b2b63eb3a01025e03ff964f187adda52c62bcb3 (patch)
tree9cd88bac9980ffda772878adada70e7a62cbddce /src/settings/general
parent96c0153e96917e994b5a188a01bb021fc4832707 (diff)
Allow to configure thumbnail-plugins
Adjust the preview-settings to allow users to configure thumbnail-plugins. For consistency also the service-settings have been adjusted to use the ServiceModel and ServiceItemDelegate.
Diffstat (limited to 'src/settings/general')
-rw-r--r--src/settings/general/configurepreviewplugindialog.cpp81
-rw-r--r--src/settings/general/configurepreviewplugindialog.h55
-rw-r--r--src/settings/general/previewssettingspage.cpp91
-rw-r--r--src/settings/general/previewssettingspage.h8
4 files changed, 211 insertions, 24 deletions
diff --git a/src/settings/general/configurepreviewplugindialog.cpp b/src/settings/general/configurepreviewplugindialog.cpp
new file mode 100644
index 000000000..c1a507a65
--- /dev/null
+++ b/src/settings/general/configurepreviewplugindialog.cpp
@@ -0,0 +1,81 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "configurepreviewplugindialog.h"
+
+#include <KLibrary>
+#include <KLocale>
+#include <KIO/NetAccess>
+#include <kio/thumbcreator.h>
+
+#include <QApplication>
+#include <QDir>
+#include <QVBoxLayout>
+
+ConfigurePreviewPluginDialog::ConfigurePreviewPluginDialog(const QString& pluginName,
+ const QString& desktopEntryName,
+ QWidget* parent) :
+ KDialog(parent),
+ m_configurationWidget(0),
+ m_previewPlugin(0)
+{
+ KLibrary library(desktopEntryName);
+ if (library.load()) {
+ newCreator create = (newCreator)library.resolveFunction("new_creator");
+ if (create) {
+ m_previewPlugin = dynamic_cast<ThumbCreatorV2*>(create());
+ }
+ }
+
+ setCaption(i18nc("@title:window", "Configure Preview for %1", pluginName));
+ setMinimumWidth(400);
+ setButtons(Ok | Cancel);
+ setDefaultButton(Ok);
+
+ QWidget* mainWidget = new QWidget(this);
+ mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
+ QVBoxLayout* layout = new QVBoxLayout(mainWidget);
+ if (m_previewPlugin) {
+ m_configurationWidget = m_previewPlugin->createConfigurationWidget();
+ layout->addWidget(m_configurationWidget);
+ }
+ layout->addStretch(1);
+
+ setMainWidget(mainWidget);
+
+ connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
+}
+
+ConfigurePreviewPluginDialog::~ConfigurePreviewPluginDialog()
+{
+}
+
+void ConfigurePreviewPluginDialog::slotOk()
+{
+ m_previewPlugin->writeConfiguration(m_configurationWidget);
+ // TODO: It would be great having a mechanism to tell PreviewJob that only previews
+ // for a specific MIME-type should be regenerated. As this is not available yet we
+ // delete the whole thumbnails directory.
+ QApplication::changeOverrideCursor(Qt::BusyCursor);
+ KIO::NetAccess::del(QDir::homePath() + "/.thumbnails/", this);
+ QApplication::restoreOverrideCursor();
+
+}
+
+#include "configurepreviewplugindialog.moc"
diff --git a/src/settings/general/configurepreviewplugindialog.h b/src/settings/general/configurepreviewplugindialog.h
new file mode 100644
index 000000000..5a3f5354a
--- /dev/null
+++ b/src/settings/general/configurepreviewplugindialog.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef CONFIGUREPREVIEWPLUGINDIALOG_H
+#define CONFIGUREPREVIEWPLUGINDIALOG_H
+
+#include <KDialog>
+
+class ThumbCreatorV2;
+
+/**
+ * @brief Dialog for configuring preview-plugins.
+ */
+class ConfigurePreviewPluginDialog : public KDialog
+{
+ Q_OBJECT
+
+public:
+ /**
+ * @param pluginName User visible name of the plugin
+ * @param desktopEntryName The name of the plugin that is noted in the desktopentry.
+ * Is used to instantiate the plugin to get the configuration
+ * widget.
+ * @param parent Parent widget.
+ */
+ explicit ConfigurePreviewPluginDialog(const QString& pluginName,
+ const QString& desktopEntryName,
+ QWidget* parent = 0);
+ virtual ~ConfigurePreviewPluginDialog();
+
+private slots:
+ void slotOk();
+
+private:
+ QWidget* m_configurationWidget;
+ ThumbCreatorV2* m_previewPlugin;
+};
+
+#endif
diff --git a/src/settings/general/previewssettingspage.cpp b/src/settings/general/previewssettingspage.cpp
index 0836aef33..679494c67 100644
--- a/src/settings/general/previewssettingspage.cpp
+++ b/src/settings/general/previewssettingspage.cpp
@@ -20,6 +20,7 @@
#include "previewssettingspage.h"
#include "dolphin_generalsettings.h"
+#include "configurepreviewplugindialog.h"
#include <KConfigGroup>
#include <KDialog>
@@ -30,15 +31,20 @@
#include <KService>
#include <settings/dolphinsettings.h>
+#include <settings/serviceitemdelegate.h>
+#include <settings/servicemodel.h>
#include <QCheckBox>
#include <QGroupBox>
#include <QLabel>
-#include <QListWidget>
-#include <QRadioButton>
+#include <QListView>
+#include <QPainter>
+#include <QScrollBar>
#include <QShowEvent>
#include <QSlider>
+#include <QSortFilterProxyModel>
#include <QGridLayout>
+#include <QVBoxLayout>
// default settings
namespace {
@@ -50,7 +56,7 @@ namespace {
PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
SettingsPageBase(parent),
m_initialized(false),
- m_previewPluginsList(0),
+ m_listView(0),
m_enabledPreviewPlugins(),
m_localFileSizeBox(0),
m_remoteFileSizeBox(0)
@@ -62,12 +68,23 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
// Create group box "Show previews for:"
QGroupBox* listBox = new QGroupBox(i18nc("@title:group", "Show previews for"), this);
- m_previewPluginsList = new QListWidget(this);
- m_previewPluginsList->setSortingEnabled(true);
- m_previewPluginsList->setSelectionMode(QAbstractItemView::NoSelection);
+ m_listView = new QListView(this);
+
+ ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView);
+ connect(delegate, SIGNAL(requestServiceConfiguration(QModelIndex)),
+ this, SLOT(configureService(QModelIndex)));
+
+ ServiceModel* serviceModel = new ServiceModel(this);
+ QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this);
+ proxyModel->setSourceModel(serviceModel);
+ proxyModel->setSortRole(Qt::DisplayRole);
+
+ m_listView->setModel(proxyModel);
+ m_listView->setItemDelegate(delegate);
+ m_listView->setVerticalScrollMode(QListView::ScrollPerPixel);
QVBoxLayout* listBoxLayout = new QVBoxLayout(listBox);
- listBoxLayout->addWidget(m_previewPluginsList);
+ listBoxLayout->addWidget(m_listView);
// Create group box "Don't create previews for"
QGroupBox* fileSizeBox = new QGroupBox(i18nc("@title:group", "Do not create previews for"), this);
@@ -99,25 +116,26 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
loadSettings();
- connect(m_previewPluginsList, SIGNAL(itemClicked(QListWidgetItem*)), this, SIGNAL(changed()));
+ connect(m_listView, SIGNAL(clicked(QModelIndex)), this, SIGNAL(changed()));
connect(m_localFileSizeBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
connect(m_remoteFileSizeBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
}
-
PreviewsSettingsPage::~PreviewsSettingsPage()
{
}
void PreviewsSettingsPage::applySettings()
{
- const int count = m_previewPluginsList->count();
- if (count > 0) {
+ const QAbstractItemModel* model = m_listView->model();
+ const int rowCount = model->rowCount();
+ if (rowCount > 0) {
m_enabledPreviewPlugins.clear();
- for (int i = 0; i < count; ++i) {
- const QListWidgetItem* item = m_previewPluginsList->item(i);
- if (item->checkState() == Qt::Checked) {
- const QString enabledPlugin = item->data(Qt::UserRole).toString();
+ for (int i = 0; i < rowCount; ++i) {
+ const QModelIndex index = model->index(i, 0);
+ const bool checked = model->data(index, Qt::CheckStateRole).toBool();
+ if (checked) {
+ const QString enabledPlugin = model->data(index, Qt::UserRole).toString();
m_enabledPreviewPlugins.append(enabledPlugin);
}
}
@@ -144,22 +162,53 @@ void PreviewsSettingsPage::restoreDefaults()
void PreviewsSettingsPage::showEvent(QShowEvent* event)
{
if (!event->spontaneous() && !m_initialized) {
- QMetaObject::invokeMethod(this, "loadPreviewPlugins", Qt::QueuedConnection);
+ loadPreviewPlugins();
m_initialized = true;
}
SettingsPageBase::showEvent(event);
}
+void PreviewsSettingsPage::configureService(const QModelIndex& index)
+{
+ const QAbstractItemModel* model = index.model();
+ const QString pluginName = model->data(index).toString();
+ const QString desktopEntryName = model->data(index, ServiceModel::DesktopEntryNameRole).toString();
+
+ ConfigurePreviewPluginDialog* dialog = new ConfigurePreviewPluginDialog(pluginName, desktopEntryName, this);
+ dialog->setAttribute(Qt::WA_DeleteOnClose);
+ dialog->show();
+}
+
void PreviewsSettingsPage::loadPreviewPlugins()
{
+ QAbstractItemModel* model = m_listView->model();
+
const KService::List plugins = KServiceTypeTrader::self()->query(QLatin1String("ThumbCreator"));
foreach (const KSharedPtr<KService>& service, plugins) {
- QListWidgetItem* item = new QListWidgetItem(service->name(),
- m_previewPluginsList);
- item->setData(Qt::UserRole, service->desktopEntryName());
+ const bool configurable = service->property("Configurable", QVariant::Bool).toBool();
const bool show = m_enabledPreviewPlugins.contains(service->desktopEntryName());
- item->setCheckState(show ? Qt::Checked : Qt::Unchecked);
+ if (service->desktopEntryName() == QLatin1String("jpegrotatedthumbnail")) {
+ // Before KDE SC 4.7 thumbnail plugins where not configurable and in addition to
+ // the jpegthumbnail-plugin a jpegrotatedthumbnail-plugin was offered. Make this
+ // plugin obsolete for users that updated from a previous KDE SC version:
+ if (show) {
+ m_enabledPreviewPlugins.removeOne(service->desktopEntryName());
+ KConfigGroup globalConfig(KGlobal::config(), QLatin1String("PreviewSettings"));
+ globalConfig.writeEntry("Plugins", m_enabledPreviewPlugins);
+ globalConfig.sync();
+ }
+ continue;
+ }
+
+ model->insertRow(0);
+ const QModelIndex index = model->index(0, 0);
+ model->setData(index, show, Qt::CheckStateRole);
+ model->setData(index, configurable, ServiceModel::ConfigurableRole);
+ model->setData(index, service->name(), Qt::DisplayRole);
+ model->setData(index, service->desktopEntryName(), ServiceModel::DesktopEntryNameRole);
}
+
+ model->sort(Qt::DisplayRole);
}
void PreviewsSettingsPage::loadSettings()
@@ -168,7 +217,7 @@ void PreviewsSettingsPage::loadSettings()
m_enabledPreviewPlugins = globalConfig.readEntry("Plugins", QStringList()
<< QLatin1String("directorythumbnail")
<< QLatin1String("imagethumbnail")
- << QLatin1String("jpegrotatedthumbnail"));
+ << QLatin1String("jpegthumbnail"));
const int maxLocalByteSize = globalConfig.readEntry("MaximumSize", MaxLocalPreviewSize * 1024 * 1024);
const int maxLocalMByteSize = maxLocalByteSize / (1024 * 1024);
diff --git a/src/settings/general/previewssettingspage.h b/src/settings/general/previewssettingspage.h
index b14aa7ab4..ef3ad267e 100644
--- a/src/settings/general/previewssettingspage.h
+++ b/src/settings/general/previewssettingspage.h
@@ -22,8 +22,9 @@
#include <settings/settingspagebase.h>
-class QListWidget;
class KIntSpinBox;
+class QListView;
+class QModelIndex;
/**
* @brief Allows the configuration of file previews.
@@ -50,14 +51,15 @@ protected:
virtual void showEvent(QShowEvent* event);
private slots:
- void loadPreviewPlugins();
+ void configureService(const QModelIndex& index);
private:
+ void loadPreviewPlugins();
void loadSettings();
private:
bool m_initialized;
- QListWidget* m_previewPluginsList;
+ QListView *m_listView;
QStringList m_enabledPreviewPlugins;
KIntSpinBox* m_localFileSizeBox;
KIntSpinBox* m_remoteFileSizeBox;