]>
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>
30 #include <kservicetypetrader.h>
36 #include <QListWidget>
37 #include <QRadioButton>
40 #include <QGridLayout>
44 const bool UseThumbnails
= true;
45 const int MaxLocalPreviewSize
= 5; // 5 MB
46 const int MaxRemotePreviewSize
= 0; // 0 MB
49 PreviewsSettingsPage::PreviewsSettingsPage(QWidget
* parent
) :
50 SettingsPageBase(parent
),
52 m_previewPluginsList(0),
53 m_enabledPreviewPlugins(),
54 m_localFileSizeBox(0),
55 m_remoteFileSizeBox(0)
57 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
58 topLayout
->setSpacing(KDialog::spacingHint());
59 topLayout
->setMargin(KDialog::marginHint());
61 // Create group box "Show previews for:"
62 QGroupBox
* listBox
= new QGroupBox(i18nc("@title:group", "Show previews for"), this);
64 m_previewPluginsList
= new QListWidget(this);
65 m_previewPluginsList
->setSortingEnabled(true);
66 m_previewPluginsList
->setSelectionMode(QAbstractItemView::NoSelection
);
67 connect(m_previewPluginsList
, SIGNAL(itemClicked(QListWidgetItem
*)),
68 this, SIGNAL(changed()));
70 QVBoxLayout
* listBoxLayout
= new QVBoxLayout(listBox
);
71 listBoxLayout
->addWidget(m_previewPluginsList
);
73 // Create group box "Don't create previews for"
74 QGroupBox
* fileSizeBox
= new QGroupBox(i18nc("@title:group", "Do not create previews for"), this);
76 QLabel
* localFileSizeLabel
= new QLabel(i18nc("@label Don't create previews for: <Local files above:> XX MByte",
77 "Local files above:"), this);
79 m_localFileSizeBox
= new KIntSpinBox(this);
80 m_localFileSizeBox
->setSingleStep(1);
81 m_localFileSizeBox
->setSuffix(QLatin1String(" MB"));
82 m_localFileSizeBox
->setRange(0, 9999); /* MB */
83 connect(m_localFileSizeBox
, SIGNAL(valueChanged(int)),
84 this, SIGNAL(changed()));
86 QLabel
* remoteFileSizeLabel
= new QLabel(i18nc("@label Don't create previews for: <Remote files above:> XX MByte",
87 "Remote files above:"), this);
89 m_remoteFileSizeBox
= new KIntSpinBox(this);
90 m_remoteFileSizeBox
->setSingleStep(1);
91 m_remoteFileSizeBox
->setSuffix(QLatin1String(" MB"));
92 m_remoteFileSizeBox
->setRange(0, 9999); /* MB */
93 connect(m_remoteFileSizeBox
, SIGNAL(valueChanged(int)),
94 this, SIGNAL(changed()));
96 QGridLayout
* fileSizeBoxLayout
= new QGridLayout(fileSizeBox
);
97 fileSizeBoxLayout
->addWidget(localFileSizeLabel
, 0, 0, Qt::AlignRight
);
98 fileSizeBoxLayout
->addWidget(m_localFileSizeBox
, 0, 1);
99 fileSizeBoxLayout
->addWidget(remoteFileSizeLabel
, 1, 0, Qt::AlignRight
);
100 fileSizeBoxLayout
->addWidget(m_remoteFileSizeBox
, 1, 1);
102 topLayout
->addWidget(listBox
);
103 topLayout
->addWidget(fileSizeBox
);
109 PreviewsSettingsPage::~PreviewsSettingsPage()
113 void PreviewsSettingsPage::applySettings()
115 m_enabledPreviewPlugins
.clear();
116 const int count
= m_previewPluginsList
->count();
117 for (int i
= 0; i
< count
; ++i
) {
118 const QListWidgetItem
* item
= m_previewPluginsList
->item(i
);
119 if (item
->checkState() == Qt::Checked
) {
120 const QString enabledPlugin
= item
->data(Qt::UserRole
).toString();
121 m_enabledPreviewPlugins
.append(enabledPlugin
);
125 KConfigGroup
globalConfig(KGlobal::config(), QLatin1String("PreviewSettings"));
126 globalConfig
.writeEntry("Plugins", m_enabledPreviewPlugins
);
128 globalConfig
.writeEntry("MaximumSize",
129 m_localFileSizeBox
->value() * 1024 * 1024,
130 KConfigBase::Normal
| KConfigBase::Global
);
131 globalConfig
.writeEntry("MaximumRemoteSize",
132 m_remoteFileSizeBox
->value() * 1024 * 1024,
133 KConfigBase::Normal
| KConfigBase::Global
);
137 void PreviewsSettingsPage::restoreDefaults()
139 m_localFileSizeBox
->setValue(MaxLocalPreviewSize
);
140 m_remoteFileSizeBox
->setValue(MaxRemotePreviewSize
);
143 void PreviewsSettingsPage::showEvent(QShowEvent
* event
)
145 if (!event
->spontaneous() && !m_initialized
) {
146 QMetaObject::invokeMethod(this, "loadPreviewPlugins", Qt::QueuedConnection
);
147 m_initialized
= true;
149 SettingsPageBase::showEvent(event
);
152 void PreviewsSettingsPage::loadPreviewPlugins()
154 const KService::List plugins
= KServiceTypeTrader::self()->query(QLatin1String("ThumbCreator"));
155 foreach (const KSharedPtr
<KService
>& service
, plugins
) {
156 QListWidgetItem
* item
= new QListWidgetItem(service
->name(),
157 m_previewPluginsList
);
158 item
->setData(Qt::UserRole
, service
->desktopEntryName());
159 const bool show
= m_enabledPreviewPlugins
.contains(service
->desktopEntryName());
160 item
->setCheckState(show
? Qt::Checked
: Qt::Unchecked
);
164 void PreviewsSettingsPage::loadSettings()
166 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
167 m_enabledPreviewPlugins
= globalConfig
.readEntry("Plugins", QStringList()
168 << QLatin1String("directorythumbnail")
169 << QLatin1String("imagethumbnail")
170 << QLatin1String("jpegthumbnail"));
172 const int maxLocalByteSize
= globalConfig
.readEntry("MaximumSize", MaxLocalPreviewSize
* 1024 * 1024);
173 const int maxLocalMByteSize
= maxLocalByteSize
/ (1024 * 1024);
174 m_localFileSizeBox
->setValue(maxLocalMByteSize
);
176 const int maxRemoteByteSize
= globalConfig
.readEntry("MaximumRemoteSize", MaxRemotePreviewSize
* 1024 * 1024);
177 const int maxRemoteMByteSize
= maxRemoteByteSize
/ (1024 * 1024);
178 m_remoteFileSizeBox
->setValue(maxRemoteMByteSize
);
181 #include "previewssettingspage.moc"