]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/previewssettingspage.cpp
1059e854770bcd3413137e012464199ef0fa9e23
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"
22 #include "dolphin_generalsettings.h"
24 #include <kconfiggroup.h>
29 #include <kservicetypetrader.h>
32 #include <settings/dolphinsettings.h>
37 #include <QListWidget>
38 #include <QRadioButton>
41 #include <QGridLayout>
45 const bool UseThumbnails
= true;
46 const int MaxLocalPreviewSize
= 5; // 5 MB
47 const int MaxRemotePreviewSize
= 0; // 0 MB
50 PreviewsSettingsPage::PreviewsSettingsPage(QWidget
* parent
) :
51 SettingsPageBase(parent
),
53 m_previewPluginsList(0),
54 m_enabledPreviewPlugins(),
55 m_localFileSizeBox(0),
56 m_remoteFileSizeBox(0)
58 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
59 topLayout
->setSpacing(KDialog::spacingHint());
60 topLayout
->setMargin(KDialog::marginHint());
62 // Create group box "Show previews for:"
63 QGroupBox
* listBox
= new QGroupBox(i18nc("@title:group", "Show previews for"), this);
65 m_previewPluginsList
= new QListWidget(this);
66 m_previewPluginsList
->setSortingEnabled(true);
67 m_previewPluginsList
->setSelectionMode(QAbstractItemView::NoSelection
);
68 connect(m_previewPluginsList
, SIGNAL(itemClicked(QListWidgetItem
*)),
69 this, SIGNAL(changed()));
71 QVBoxLayout
* listBoxLayout
= new QVBoxLayout(listBox
);
72 listBoxLayout
->addWidget(m_previewPluginsList
);
74 // Create group box "Don't create previews for"
75 QGroupBox
* fileSizeBox
= new QGroupBox(i18nc("@title:group", "Do not create previews for"), this);
77 QLabel
* localFileSizeLabel
= new QLabel(i18nc("@label Don't create previews for: <Local files above:> XX MByte",
78 "Local files above:"), this);
80 m_localFileSizeBox
= new KIntSpinBox(this);
81 m_localFileSizeBox
->setSingleStep(1);
82 m_localFileSizeBox
->setSuffix(QLatin1String(" MB"));
83 m_localFileSizeBox
->setRange(0, 9999); /* MB */
84 connect(m_localFileSizeBox
, SIGNAL(valueChanged(int)),
85 this, SIGNAL(changed()));
87 QLabel
* remoteFileSizeLabel
= new QLabel(i18nc("@label Don't create previews for: <Remote files above:> XX MByte",
88 "Remote files above:"), this);
90 m_remoteFileSizeBox
= new KIntSpinBox(this);
91 m_remoteFileSizeBox
->setSingleStep(1);
92 m_remoteFileSizeBox
->setSuffix(QLatin1String(" MB"));
93 m_remoteFileSizeBox
->setRange(0, 9999); /* MB */
94 connect(m_remoteFileSizeBox
, SIGNAL(valueChanged(int)),
95 this, SIGNAL(changed()));
97 QGridLayout
* fileSizeBoxLayout
= new QGridLayout(fileSizeBox
);
98 fileSizeBoxLayout
->addWidget(localFileSizeLabel
, 0, 0, Qt::AlignRight
);
99 fileSizeBoxLayout
->addWidget(m_localFileSizeBox
, 0, 1);
100 fileSizeBoxLayout
->addWidget(remoteFileSizeLabel
, 1, 0, Qt::AlignRight
);
101 fileSizeBoxLayout
->addWidget(m_remoteFileSizeBox
, 1, 1);
103 topLayout
->addWidget(listBox
);
104 topLayout
->addWidget(fileSizeBox
);
110 PreviewsSettingsPage::~PreviewsSettingsPage()
114 void PreviewsSettingsPage::applySettings()
116 m_enabledPreviewPlugins
.clear();
117 const int count
= m_previewPluginsList
->count();
118 for (int i
= 0; i
< count
; ++i
) {
119 const QListWidgetItem
* item
= m_previewPluginsList
->item(i
);
120 if (item
->checkState() == Qt::Checked
) {
121 const QString enabledPlugin
= item
->data(Qt::UserRole
).toString();
122 m_enabledPreviewPlugins
.append(enabledPlugin
);
126 KConfigGroup
globalConfig(KGlobal::config(), QLatin1String("PreviewSettings"));
127 globalConfig
.writeEntry("Plugins", m_enabledPreviewPlugins
);
129 globalConfig
.writeEntry("MaximumSize",
130 m_localFileSizeBox
->value() * 1024 * 1024,
131 KConfigBase::Normal
| KConfigBase::Global
);
132 globalConfig
.writeEntry("MaximumRemoteSize",
133 m_remoteFileSizeBox
->value() * 1024 * 1024,
134 KConfigBase::Normal
| KConfigBase::Global
);
138 void PreviewsSettingsPage::restoreDefaults()
140 m_localFileSizeBox
->setValue(MaxLocalPreviewSize
);
141 m_remoteFileSizeBox
->setValue(MaxRemotePreviewSize
);
144 void PreviewsSettingsPage::showEvent(QShowEvent
* event
)
146 if (!event
->spontaneous() && !m_initialized
) {
147 QMetaObject::invokeMethod(this, "loadPreviewPlugins", Qt::QueuedConnection
);
148 m_initialized
= true;
150 SettingsPageBase::showEvent(event
);
153 void PreviewsSettingsPage::loadPreviewPlugins()
155 const KService::List plugins
= KServiceTypeTrader::self()->query(QLatin1String("ThumbCreator"));
156 foreach (const KSharedPtr
<KService
>& service
, plugins
) {
157 QListWidgetItem
* item
= new QListWidgetItem(service
->name(),
158 m_previewPluginsList
);
159 item
->setData(Qt::UserRole
, service
->desktopEntryName());
160 const bool show
= m_enabledPreviewPlugins
.contains(service
->desktopEntryName());
161 item
->setCheckState(show
? Qt::Checked
: Qt::Unchecked
);
165 void PreviewsSettingsPage::loadSettings()
167 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
168 m_enabledPreviewPlugins
= globalConfig
.readEntry("Plugins", QStringList()
169 << QLatin1String("directorythumbnail")
170 << QLatin1String("imagethumbnail")
171 << QLatin1String("jpegthumbnail"));
173 const int maxLocalByteSize
= globalConfig
.readEntry("MaximumSize", MaxLocalPreviewSize
* 1024 * 1024);
174 const int maxLocalMByteSize
= maxLocalByteSize
/ (1024 * 1024);
175 m_localFileSizeBox
->setValue(maxLocalMByteSize
);
177 const int maxRemoteByteSize
= globalConfig
.readEntry("MaximumRemoteSize", MaxRemotePreviewSize
* 1024 * 1024);
178 const int maxRemoteMByteSize
= maxRemoteByteSize
/ (1024 * 1024);
179 m_remoteFileSizeBox
->setValue(maxRemoteMByteSize
);
182 #include "previewssettingspage.moc"