]>
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>
46 const bool UseThumbnails
= true;
47 const int MaxLocalPreviewSize
= 5; // 5 MB
48 const int MaxRemotePreviewSize
= 0; // 0 MB
51 PreviewsSettingsPage::PreviewsSettingsPage(QWidget
* parent
) :
52 SettingsPageBase(parent
),
54 m_previewPluginsList(0),
55 m_enabledPreviewPlugins(),
56 m_localFileSizeBox(0),
57 m_remoteFileSizeBox(0)
59 kDebug() << "--------- constructing!";
60 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
61 topLayout
->setSpacing(KDialog::spacingHint());
62 topLayout
->setMargin(KDialog::marginHint());
64 QLabel
* listDescription
= new QLabel(i18nc("@label", "Show previews for:"), this);
66 m_previewPluginsList
= new QListWidget(this);
67 m_previewPluginsList
->setSortingEnabled(true);
68 m_previewPluginsList
->setSelectionMode(QAbstractItemView::NoSelection
);
69 connect(m_previewPluginsList
, SIGNAL(itemClicked(QListWidgetItem
*)),
70 this, SIGNAL(changed()));
72 QLabel
* localFileSizeLabel
= new QLabel(i18nc("@label", "Local file size maximum:"), this);
74 m_localFileSizeBox
= new KIntSpinBox(this);
75 m_localFileSizeBox
->setSingleStep(1);
76 m_localFileSizeBox
->setSuffix(QLatin1String(" MB"));
77 m_localFileSizeBox
->setRange(0, 9999); /* MB */
78 connect(m_localFileSizeBox
, SIGNAL(valueChanged(int)),
79 this, SIGNAL(changed()));
81 QLabel
* remoteFileSizeLabel
= new QLabel(i18nc("@label", "Remote file size maximum:"), this);
82 m_remoteFileSizeBox
= new KIntSpinBox(this);
83 m_remoteFileSizeBox
->setSingleStep(1);
84 m_remoteFileSizeBox
->setSuffix(QLatin1String(" MB"));
85 m_remoteFileSizeBox
->setRange(0, 9999); /* MB */
86 connect(m_remoteFileSizeBox
, SIGNAL(valueChanged(int)),
87 this, SIGNAL(changed()));
89 QGridLayout
* gridLayout
= new QGridLayout();
90 gridLayout
->addWidget(localFileSizeLabel
, 0, 0);
91 gridLayout
->addWidget(m_localFileSizeBox
, 0, 1);
92 gridLayout
->addWidget(remoteFileSizeLabel
, 1, 0);
93 gridLayout
->addWidget(m_remoteFileSizeBox
, 1, 1);
95 topLayout
->addWidget(listDescription
);
96 topLayout
->addWidget(m_previewPluginsList
);
97 topLayout
->addLayout(gridLayout
);
103 PreviewsSettingsPage::~PreviewsSettingsPage()
107 void PreviewsSettingsPage::applySettings()
109 m_enabledPreviewPlugins
.clear();
110 const int count
= m_previewPluginsList
->count();
111 for (int i
= 0; i
< count
; ++i
) {
112 const QListWidgetItem
* item
= m_previewPluginsList
->item(i
);
113 if (item
->checkState() == Qt::Checked
) {
114 const QString enabledPlugin
= item
->data(Qt::UserRole
).toString();
115 m_enabledPreviewPlugins
.append(enabledPlugin
);
119 KConfigGroup
globalConfig(KGlobal::config(), QLatin1String("PreviewSettings"));
120 globalConfig
.writeEntry("Plugins", m_enabledPreviewPlugins
);
122 globalConfig
.writeEntry("MaximumSize",
123 m_localFileSizeBox
->value() * 1024 * 1024,
124 KConfigBase::Normal
| KConfigBase::Global
);
125 globalConfig
.writeEntry("RemoteMaximumSize",
126 m_remoteFileSizeBox
->value() * 1024 * 1024,
127 KConfigBase::Normal
| KConfigBase::Global
);
131 void PreviewsSettingsPage::restoreDefaults()
133 m_localFileSizeBox
->setValue(MaxLocalPreviewSize
);
134 m_remoteFileSizeBox
->setValue(MaxRemotePreviewSize
);
137 void PreviewsSettingsPage::showEvent(QShowEvent
* event
)
139 if (!event
->spontaneous() && !m_initialized
) {
140 QMetaObject::invokeMethod(this, "loadPreviewPlugins", Qt::QueuedConnection
);
141 m_initialized
= true;
143 SettingsPageBase::showEvent(event
);
146 void PreviewsSettingsPage::loadPreviewPlugins()
148 const KService::List plugins
= KServiceTypeTrader::self()->query(QLatin1String("ThumbCreator"));
149 foreach (const KSharedPtr
<KService
>& service
, plugins
) {
150 QListWidgetItem
* item
= new QListWidgetItem(service
->name(),
151 m_previewPluginsList
);
152 item
->setData(Qt::UserRole
, service
->desktopEntryName());
153 const bool show
= m_enabledPreviewPlugins
.contains(service
->desktopEntryName());
154 item
->setCheckState(show
? Qt::Checked
: Qt::Unchecked
);
158 void PreviewsSettingsPage::loadSettings()
160 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
161 m_enabledPreviewPlugins
= globalConfig
.readEntry("Plugins", QStringList()
162 << QLatin1String("directorythumbnail")
163 << QLatin1String("imagethumbnail")
164 << QLatin1String("jpegthumbnail"));
165 kDebug() << "----------------- enabled plugins:";
166 foreach (const QString
& plugin
, m_enabledPreviewPlugins
) {
170 // TODO: The default value of 5 MB must match with the default value inside
171 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
172 // should be added for getting the default size?
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("MaximumSize", MaxRemotePreviewSize
* 1024 * 1024);
178 const int maxRemoteMByteSize
= maxRemoteByteSize
/ (1024 * 1024);
179 m_localFileSizeBox
->setValue(maxRemoteMByteSize
);
182 #include "previewssettingspage.moc"