From: Peter Penz Date: Fri, 10 Apr 2009 18:58:21 +0000 (+0000) Subject: Allow to configure which preview plugins should be enabled. Per default previews... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/5bd452a69dcf177090080e6d161ff7245dac8628 Allow to configure which preview plugins should be enabled. Per default previews for images and directories are enabled. svn path=/trunk/KDE/kdebase/apps/; revision=952049 --- diff --git a/src/settings/previewssettingspage.cpp b/src/settings/previewssettingspage.cpp index e0e07b64f..d5c518b00 100644 --- a/src/settings/previewssettingspage.cpp +++ b/src/settings/previewssettingspage.cpp @@ -23,8 +23,10 @@ #include "dolphin_generalsettings.h" #include +#include #include #include +#include #include #include #include @@ -35,6 +37,8 @@ #include #include #include +#include +#include #include // default settings @@ -43,17 +47,26 @@ const int MAX_PREVIEW_SIZE = 5; // 5 MB PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) : SettingsPageBase(parent), + m_initialized(false), + m_previewPluginsList(0), + m_enabledPreviewPlugins(), m_maxPreviewSize(0), m_spinBox(0), m_useFileThumbnails(0) { - KVBox* vBox = new KVBox(this); - vBox->setSpacing(KDialog::spacingHint()); - vBox->setMargin(KDialog::marginHint()); + QVBoxLayout* topLayout = new QVBoxLayout(this); + topLayout->setSpacing(KDialog::spacingHint()); + topLayout->setMargin(KDialog::marginHint()); - new QLabel("TODO: a major rewrite of this dialog will be done in 4.3", vBox); + QLabel* listDescription = new QLabel(i18nc("@label", "Show previews for:"), this); - KHBox* hBox = new KHBox(vBox); + m_previewPluginsList = new QListWidget(this); + m_previewPluginsList->setSortingEnabled(true); + m_previewPluginsList->setSelectionMode(QAbstractItemView::NoSelection); + connect(m_previewPluginsList, SIGNAL(itemClicked(QListWidgetItem*)), + this, SIGNAL(changed())); + + KHBox* hBox = new KHBox(this); hBox->setSpacing(KDialog::spacingHint()); new QLabel(i18nc("@label:slider", "Maximum file size:"), hBox); @@ -78,13 +91,13 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) : connect(m_spinBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed())); - m_useFileThumbnails = new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), vBox); + m_useFileThumbnails = new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), this); connect(m_useFileThumbnails, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - // Add a dummy widget with no restriction regarding - // a vertical resizing. This assures that the dialog layout - // is not stretched vertically. - new QWidget(vBox); + topLayout->addWidget(listDescription); + topLayout->addWidget(m_previewPluginsList); + topLayout->addWidget(hBox); + topLayout->addWidget(m_useFileThumbnails); loadSettings(); } @@ -96,7 +109,19 @@ PreviewsSettingsPage::~PreviewsSettingsPage() void PreviewsSettingsPage::applySettings() { + m_enabledPreviewPlugins.clear(); + const int count = m_previewPluginsList->count(); + 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(); + m_enabledPreviewPlugins.append(enabledPlugin); + } + } + KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings"); + globalConfig.writeEntry("Plugins", m_enabledPreviewPlugins); + const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB globalConfig.writeEntry("MaximumSize", byteCount, @@ -113,15 +138,38 @@ void PreviewsSettingsPage::restoreDefaults() m_useFileThumbnails->setChecked(USE_THUMBNAILS); } -void PreviewsSettingsPage::loadSettings() +bool PreviewsSettingsPage::event(QEvent* event) { - const int min = 1; // MB - const int max = 100; // MB + if ((event->type() == QEvent::Polish) && !m_initialized) { + // load all available plugins for previews + const KService::List plugins = KServiceTypeTrader::self()->query("ThumbCreator"); + foreach (const KSharedPtr service, plugins) { + QListWidgetItem* item = new QListWidgetItem(service->name(), + m_previewPluginsList); + item->setData(Qt::UserRole, service->desktopEntryName()); + const bool show = m_enabledPreviewPlugins.contains(service->desktopEntryName()); + item->setCheckState(show ? Qt::Checked : Qt::Unchecked); + } + + m_initialized = true; + } + return SettingsPageBase::event(event); +} +void PreviewsSettingsPage::loadSettings() +{ KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings"); + m_enabledPreviewPlugins = globalConfig.readEntry("Plugins", QStringList() + << "directorythumbnail" + << "imagethumbnail" + << "jpegthumbnail"); + // TODO: The default value of 5 MB must match with the default value inside // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob // should be added for getting the default size? + const int min = 1; // MB + const int max = 100; // MB + const int maxByteSize = globalConfig.readEntry("MaximumSize", MAX_PREVIEW_SIZE * 1024 * 1024); int maxMByteSize = maxByteSize / (1024 * 1024); if (maxMByteSize < min) { diff --git a/src/settings/previewssettingspage.h b/src/settings/previewssettingspage.h index 5833a3db5..bce1f5be5 100644 --- a/src/settings/previewssettingspage.h +++ b/src/settings/previewssettingspage.h @@ -25,6 +25,7 @@ class DolphinMainWindow; class QCheckBox; +class QListWidget; class QRadioButton; class QSlider; class QSpinBox; @@ -50,10 +51,16 @@ public: /** Restores the settings to default values. */ virtual void restoreDefaults(); +protected: + virtual bool event(QEvent* event); + private: void loadSettings(); private: + bool m_initialized; + QListWidget* m_previewPluginsList; + QStringList m_enabledPreviewPlugins; QSlider* m_maxPreviewSize; QSpinBox* m_spinBox; QCheckBox* m_useFileThumbnails;