]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/previewssettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 ***************************************************************************/
20 #include "previewssettingspage.h"
21 #include "dolphinsettings.h"
23 #include "dolphin_generalsettings.h"
25 #include <kconfiggroup.h>
31 #include <kservicetypetrader.h>
37 #include <QListWidget>
38 #include <QRadioButton>
44 const bool USE_THUMBNAILS
= true;
45 const int MAX_PREVIEW_SIZE
= 5; // 5 MB
47 PreviewsSettingsPage::PreviewsSettingsPage(QWidget
* parent
) :
48 SettingsPageBase(parent
),
50 m_previewPluginsList(0),
51 m_enabledPreviewPlugins(),
54 m_useFileThumbnails(0)
56 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
57 topLayout
->setSpacing(KDialog::spacingHint());
58 topLayout
->setMargin(KDialog::marginHint());
60 QLabel
* listDescription
= new QLabel(i18nc("@label", "Show previews for:"), this);
62 m_previewPluginsList
= new QListWidget(this);
63 m_previewPluginsList
->setSortingEnabled(true);
64 m_previewPluginsList
->setSelectionMode(QAbstractItemView::NoSelection
);
65 connect(m_previewPluginsList
, SIGNAL(itemClicked(QListWidgetItem
*)),
66 this, SIGNAL(changed()));
68 KHBox
* hBox
= new KHBox(this);
69 hBox
->setSpacing(KDialog::spacingHint());
71 new QLabel(i18nc("@label:slider", "Maximum file size:"), hBox
);
72 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, hBox
);
73 m_maxPreviewSize
->setPageStep(10);
74 m_maxPreviewSize
->setSingleStep(1);
75 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
76 m_maxPreviewSize
->setRange(1, 100); /* MB */
78 m_spinBox
= new KIntSpinBox(hBox
);
79 m_spinBox
->setSingleStep(1);
80 m_spinBox
->setSuffix(" MB");
81 m_spinBox
->setRange(1, 100); /* MB */
83 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
84 m_spinBox
, SLOT(setValue(int)));
85 connect(m_spinBox
, SIGNAL(valueChanged(int)),
86 m_maxPreviewSize
, SLOT(setValue(int)));
88 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
89 this, SIGNAL(changed()));
90 connect(m_spinBox
, SIGNAL(valueChanged(int)),
91 this, SIGNAL(changed()));
93 m_useFileThumbnails
= new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), this);
94 connect(m_useFileThumbnails
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
96 topLayout
->addWidget(listDescription
);
97 topLayout
->addWidget(m_previewPluginsList
);
98 topLayout
->addWidget(hBox
);
99 topLayout
->addWidget(m_useFileThumbnails
);
105 PreviewsSettingsPage::~PreviewsSettingsPage()
109 void PreviewsSettingsPage::applySettings()
111 m_enabledPreviewPlugins
.clear();
112 const int count
= m_previewPluginsList
->count();
113 for (int i
= 0; i
< count
; ++i
) {
114 const QListWidgetItem
* item
= m_previewPluginsList
->item(i
);
115 if (item
->checkState() == Qt::Checked
) {
116 const QString enabledPlugin
= item
->data(Qt::UserRole
).toString();
117 m_enabledPreviewPlugins
.append(enabledPlugin
);
121 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
122 globalConfig
.writeEntry("Plugins", m_enabledPreviewPlugins
);
124 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
125 globalConfig
.writeEntry("MaximumSize",
127 KConfigBase::Normal
| KConfigBase::Global
);
128 globalConfig
.writeEntry("UseFileThumbnails",
129 m_useFileThumbnails
->isChecked(),
130 KConfigBase::Normal
| KConfigBase::Global
);
134 void PreviewsSettingsPage::restoreDefaults()
136 m_maxPreviewSize
->setValue(MAX_PREVIEW_SIZE
);
137 m_useFileThumbnails
->setChecked(USE_THUMBNAILS
);
140 void PreviewsSettingsPage::showEvent(QShowEvent
* event
)
142 if (!event
->spontaneous() && !m_initialized
) {
143 QMetaObject::invokeMethod(this, "loadPreviewPlugins", Qt::QueuedConnection
);
144 m_initialized
= true;
146 SettingsPageBase::showEvent(event
);
149 void PreviewsSettingsPage::loadPreviewPlugins()
151 const KService::List plugins
= KServiceTypeTrader::self()->query("ThumbCreator");
152 foreach (const KSharedPtr
<KService
>& service
, plugins
) {
153 QListWidgetItem
* item
= new QListWidgetItem(service
->name(),
154 m_previewPluginsList
);
155 item
->setData(Qt::UserRole
, service
->desktopEntryName());
156 const bool show
= m_enabledPreviewPlugins
.contains(service
->desktopEntryName());
157 item
->setCheckState(show
? Qt::Checked
: Qt::Unchecked
);
161 void PreviewsSettingsPage::loadSettings()
163 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
164 m_enabledPreviewPlugins
= globalConfig
.readEntry("Plugins", QStringList()
165 << "directorythumbnail"
169 // TODO: The default value of 5 MB must match with the default value inside
170 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
171 // should be added for getting the default size?
172 const int min
= 1; // MB
173 const int max
= 100; // MB
175 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", MAX_PREVIEW_SIZE
* 1024 * 1024);
176 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
177 if (maxMByteSize
< min
) {
179 } else if (maxMByteSize
> max
) {
182 m_maxPreviewSize
->setValue(maxMByteSize
);
184 const bool useFileThumbnails
= globalConfig
.readEntry("UseFileThumbnails", USE_THUMBNAILS
);
185 m_useFileThumbnails
->setChecked(useFileThumbnails
);
188 #include "previewssettingspage.moc"