#include "dolphin_generalsettings.h"
#include <QCheckBox>
+#include <QEvent>
#include <QGroupBox>
#include <QLabel>
+#include <QListWidget>
#include <QRadioButton>
#include <QSlider>
#include <QSpinBox>
#include <kglobal.h>
#include <klocale.h>
#include <khbox.h>
+#include <kservicetypetrader.h>
+#include <kservice.h>
#include <kvbox.h>
// default settings
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);
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();
}
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,
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<KService> 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) {