]>
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 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 QLabel
* localFileSizeLabel
= new QLabel(i18nc("@label", "Local file size maximum:"), this);
71 m_localFileSizeBox
= new KIntSpinBox(this);
72 m_localFileSizeBox
->setSingleStep(1);
73 m_localFileSizeBox
->setSuffix(QLatin1String(" MB"));
74 m_localFileSizeBox
->setRange(0, 9999); /* MB */
75 connect(m_localFileSizeBox
, SIGNAL(valueChanged(int)),
76 this, SIGNAL(changed()));
78 QLabel
* remoteFileSizeLabel
= new QLabel(i18nc("@label", "Remote file size maximum:"), this);
79 m_remoteFileSizeBox
= new KIntSpinBox(this);
80 m_remoteFileSizeBox
->setSingleStep(1);
81 m_remoteFileSizeBox
->setSuffix(QLatin1String(" MB"));
82 m_remoteFileSizeBox
->setRange(0, 9999); /* MB */
83 connect(m_remoteFileSizeBox
, SIGNAL(valueChanged(int)),
84 this, SIGNAL(changed()));
86 QGridLayout
* gridLayout
= new QGridLayout();
87 gridLayout
->addWidget(localFileSizeLabel
, 0, 0);
88 gridLayout
->addWidget(m_localFileSizeBox
, 0, 1);
89 gridLayout
->addWidget(remoteFileSizeLabel
, 1, 0);
90 gridLayout
->addWidget(m_remoteFileSizeBox
, 1, 1);
92 topLayout
->addWidget(listDescription
);
93 topLayout
->addWidget(m_previewPluginsList
);
94 topLayout
->addLayout(gridLayout
);
100 PreviewsSettingsPage::~PreviewsSettingsPage()
104 void PreviewsSettingsPage::applySettings()
106 m_enabledPreviewPlugins
.clear();
107 const int count
= m_previewPluginsList
->count();
108 for (int i
= 0; i
< count
; ++i
) {
109 const QListWidgetItem
* item
= m_previewPluginsList
->item(i
);
110 if (item
->checkState() == Qt::Checked
) {
111 const QString enabledPlugin
= item
->data(Qt::UserRole
).toString();
112 m_enabledPreviewPlugins
.append(enabledPlugin
);
116 KConfigGroup
globalConfig(KGlobal::config(), QLatin1String("PreviewSettings"));
117 globalConfig
.writeEntry("Plugins", m_enabledPreviewPlugins
);
119 globalConfig
.writeEntry("MaximumSize",
120 m_localFileSizeBox
->value() * 1024 * 1024,
121 KConfigBase::Normal
| KConfigBase::Global
);
122 globalConfig
.writeEntry("RemoteMaximumSize",
123 m_remoteFileSizeBox
->value() * 1024 * 1024,
124 KConfigBase::Normal
| KConfigBase::Global
);
128 void PreviewsSettingsPage::restoreDefaults()
130 m_localFileSizeBox
->setValue(MaxLocalPreviewSize
);
131 m_remoteFileSizeBox
->setValue(MaxRemotePreviewSize
);
134 void PreviewsSettingsPage::showEvent(QShowEvent
* event
)
136 if (!event
->spontaneous() && !m_initialized
) {
137 QMetaObject::invokeMethod(this, "loadPreviewPlugins", Qt::QueuedConnection
);
138 m_initialized
= true;
140 SettingsPageBase::showEvent(event
);
143 void PreviewsSettingsPage::loadPreviewPlugins()
145 const KService::List plugins
= KServiceTypeTrader::self()->query(QLatin1String("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
);
155 void PreviewsSettingsPage::loadSettings()
157 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
158 m_enabledPreviewPlugins
= globalConfig
.readEntry("Plugins", QStringList()
159 << QLatin1String("directorythumbnail")
160 << QLatin1String("imagethumbnail")
161 << QLatin1String("jpegthumbnail"));
163 // TODO: The default value of 5 MB must match with the default value inside
164 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
165 // should be added for getting the default size?
166 const int maxLocalByteSize
= globalConfig
.readEntry("MaximumSize", MaxLocalPreviewSize
* 1024 * 1024);
167 const int maxLocalMByteSize
= maxLocalByteSize
/ (1024 * 1024);
168 m_localFileSizeBox
->setValue(maxLocalMByteSize
);
170 const int maxRemoteByteSize
= globalConfig
.readEntry("MaximumSize", MaxRemotePreviewSize
* 1024 * 1024);
171 const int maxRemoteMByteSize
= maxRemoteByteSize
/ (1024 * 1024);
172 m_localFileSizeBox
->setValue(maxRemoteMByteSize
);
175 #include "previewssettingspage.moc"