]>
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"
29 #include <QListWidget>
30 #include <QRadioButton>
35 #include <kconfiggroup.h>
40 #include <kservicetypetrader.h>
45 const bool USE_THUMBNAILS
= true;
46 const int MAX_PREVIEW_SIZE
= 5; // 5 MB
48 PreviewsSettingsPage::PreviewsSettingsPage(QWidget
* parent
) :
49 SettingsPageBase(parent
),
51 m_previewPluginsList(0),
52 m_enabledPreviewPlugins(),
55 m_useFileThumbnails(0)
57 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
58 topLayout
->setSpacing(KDialog::spacingHint());
59 topLayout
->setMargin(KDialog::marginHint());
61 QLabel
* listDescription
= new QLabel(i18nc("@label", "Show previews for:"), this);
63 m_previewPluginsList
= new QListWidget(this);
64 m_previewPluginsList
->setSortingEnabled(true);
65 m_previewPluginsList
->setSelectionMode(QAbstractItemView::NoSelection
);
66 connect(m_previewPluginsList
, SIGNAL(itemClicked(QListWidgetItem
*)),
67 this, SIGNAL(changed()));
69 KHBox
* hBox
= new KHBox(this);
70 hBox
->setSpacing(KDialog::spacingHint());
72 new QLabel(i18nc("@label:slider", "Maximum file size:"), hBox
);
73 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, hBox
);
74 m_maxPreviewSize
->setPageStep(10);
75 m_maxPreviewSize
->setSingleStep(1);
76 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
77 m_maxPreviewSize
->setRange(1, 100); /* MB */
79 m_spinBox
= new QSpinBox(hBox
);
80 m_spinBox
->setSingleStep(1);
81 m_spinBox
->setSuffix(" MB");
82 m_spinBox
->setRange(1, 100); /* MB */
84 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
85 m_spinBox
, SLOT(setValue(int)));
86 connect(m_spinBox
, SIGNAL(valueChanged(int)),
87 m_maxPreviewSize
, SLOT(setValue(int)));
89 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
90 this, SIGNAL(changed()));
91 connect(m_spinBox
, SIGNAL(valueChanged(int)),
92 this, SIGNAL(changed()));
94 m_useFileThumbnails
= new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), this);
95 connect(m_useFileThumbnails
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
97 topLayout
->addWidget(listDescription
);
98 topLayout
->addWidget(m_previewPluginsList
);
99 topLayout
->addWidget(hBox
);
100 topLayout
->addWidget(m_useFileThumbnails
);
106 PreviewsSettingsPage::~PreviewsSettingsPage()
110 void PreviewsSettingsPage::applySettings()
112 m_enabledPreviewPlugins
.clear();
113 const int count
= m_previewPluginsList
->count();
114 for (int i
= 0; i
< count
; ++i
) {
115 const QListWidgetItem
* item
= m_previewPluginsList
->item(i
);
116 if (item
->checkState() == Qt::Checked
) {
117 const QString enabledPlugin
= item
->data(Qt::UserRole
).toString();
118 m_enabledPreviewPlugins
.append(enabledPlugin
);
122 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
123 globalConfig
.writeEntry("Plugins", m_enabledPreviewPlugins
);
125 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
126 globalConfig
.writeEntry("MaximumSize",
128 KConfigBase::Normal
| KConfigBase::Global
);
129 globalConfig
.writeEntry("UseFileThumbnails",
130 m_useFileThumbnails
->isChecked(),
131 KConfigBase::Normal
| KConfigBase::Global
);
135 void PreviewsSettingsPage::restoreDefaults()
137 m_maxPreviewSize
->setValue(MAX_PREVIEW_SIZE
);
138 m_useFileThumbnails
->setChecked(USE_THUMBNAILS
);
141 bool PreviewsSettingsPage::event(QEvent
* event
)
143 if ((event
->type() == QEvent::Polish
) && !m_initialized
) {
144 // load all available plugins for previews
145 const KService::List plugins
= KServiceTypeTrader::self()->query("ThumbCreator");
146 foreach (const KSharedPtr
<KService
> service
, plugins
) {
147 QListWidgetItem
* item
= new QListWidgetItem(service
->name(),
148 m_previewPluginsList
);
149 item
->setData(Qt::UserRole
, service
->desktopEntryName());
150 const bool show
= m_enabledPreviewPlugins
.contains(service
->desktopEntryName());
151 item
->setCheckState(show
? Qt::Checked
: Qt::Unchecked
);
154 m_initialized
= true;
156 return SettingsPageBase::event(event
);
159 void PreviewsSettingsPage::loadSettings()
161 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
162 m_enabledPreviewPlugins
= globalConfig
.readEntry("Plugins", QStringList()
163 << "directorythumbnail"
167 // TODO: The default value of 5 MB must match with the default value inside
168 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
169 // should be added for getting the default size?
170 const int min
= 1; // MB
171 const int max
= 100; // MB
173 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", MAX_PREVIEW_SIZE
* 1024 * 1024);
174 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
175 if (maxMByteSize
< min
) {
177 } else if (maxMByteSize
> max
) {
180 m_maxPreviewSize
->setValue(maxMByteSize
);
182 const bool useFileThumbnails
= globalConfig
.readEntry("UseFileThumbnails", USE_THUMBNAILS
);
183 m_useFileThumbnails
->setChecked(useFileThumbnails
);
186 #include "previewssettingspage.moc"