1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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"
23 #include "configurepreviewplugindialog.h"
25 #include <KConfigGroup>
30 #include <KServiceTypeTrader>
33 #include <settings/dolphinsettings.h>
34 #include <settings/serviceitemdelegate.h>
35 #include <settings/servicemodel.h>
45 #include <QSortFilterProxyModel>
46 #include <QGridLayout>
47 #include <QVBoxLayout>
51 const bool UseThumbnails
= true;
52 const int MaxLocalPreviewSize
= 5; // 5 MB
53 const int MaxRemotePreviewSize
= 0; // 0 MB
56 PreviewsSettingsPage::PreviewsSettingsPage(QWidget
* parent
) :
57 SettingsPageBase(parent
),
60 m_enabledPreviewPlugins(),
61 m_localFileSizeBox(0),
62 m_remoteFileSizeBox(0)
64 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
65 topLayout
->setSpacing(KDialog::spacingHint());
66 topLayout
->setMargin(KDialog::marginHint());
68 // Create group box "Show previews for:"
69 QGroupBox
* listBox
= new QGroupBox(i18nc("@title:group", "Show previews for"), this);
71 m_listView
= new QListView(this);
73 ServiceItemDelegate
* delegate
= new ServiceItemDelegate(m_listView
, m_listView
);
74 connect(delegate
, SIGNAL(requestServiceConfiguration(QModelIndex
)),
75 this, SLOT(configureService(QModelIndex
)));
77 ServiceModel
* serviceModel
= new ServiceModel(this);
78 QSortFilterProxyModel
* proxyModel
= new QSortFilterProxyModel(this);
79 proxyModel
->setSourceModel(serviceModel
);
80 proxyModel
->setSortRole(Qt::DisplayRole
);
82 m_listView
->setModel(proxyModel
);
83 m_listView
->setItemDelegate(delegate
);
84 m_listView
->setVerticalScrollMode(QListView::ScrollPerPixel
);
86 QVBoxLayout
* listBoxLayout
= new QVBoxLayout(listBox
);
87 listBoxLayout
->addWidget(m_listView
);
89 // Create group box "Don't create previews for"
90 QGroupBox
* fileSizeBox
= new QGroupBox(i18nc("@title:group", "Do not create previews for"), this);
92 QLabel
* localFileSizeLabel
= new QLabel(i18nc("@label Don't create previews for: <Local files above:> XX MByte",
93 "Local files above:"), this);
95 m_localFileSizeBox
= new KIntSpinBox(this);
96 m_localFileSizeBox
->setSingleStep(1);
97 m_localFileSizeBox
->setSuffix(QLatin1String(" MB"));
98 m_localFileSizeBox
->setRange(0, 9999); /* MB */
100 QLabel
* remoteFileSizeLabel
= new QLabel(i18nc("@label Don't create previews for: <Remote files above:> XX MByte",
101 "Remote files above:"), this);
103 m_remoteFileSizeBox
= new KIntSpinBox(this);
104 m_remoteFileSizeBox
->setSingleStep(1);
105 m_remoteFileSizeBox
->setSuffix(QLatin1String(" MB"));
106 m_remoteFileSizeBox
->setRange(0, 9999); /* MB */
108 QGridLayout
* fileSizeBoxLayout
= new QGridLayout(fileSizeBox
);
109 fileSizeBoxLayout
->addWidget(localFileSizeLabel
, 0, 0, Qt::AlignRight
);
110 fileSizeBoxLayout
->addWidget(m_localFileSizeBox
, 0, 1);
111 fileSizeBoxLayout
->addWidget(remoteFileSizeLabel
, 1, 0, Qt::AlignRight
);
112 fileSizeBoxLayout
->addWidget(m_remoteFileSizeBox
, 1, 1);
114 topLayout
->addWidget(listBox
);
115 topLayout
->addWidget(fileSizeBox
);
119 connect(m_listView
, SIGNAL(clicked(QModelIndex
)), this, SIGNAL(changed()));
120 connect(m_localFileSizeBox
, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
121 connect(m_remoteFileSizeBox
, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
124 PreviewsSettingsPage::~PreviewsSettingsPage()
128 void PreviewsSettingsPage::applySettings()
130 const QAbstractItemModel
* model
= m_listView
->model();
131 const int rowCount
= model
->rowCount();
133 m_enabledPreviewPlugins
.clear();
134 for (int i
= 0; i
< rowCount
; ++i
) {
135 const QModelIndex index
= model
->index(i
, 0);
136 const bool checked
= model
->data(index
, Qt::CheckStateRole
).toBool();
138 const QString enabledPlugin
= model
->data(index
, Qt::UserRole
).toString();
139 m_enabledPreviewPlugins
.append(enabledPlugin
);
144 KConfigGroup
globalConfig(KGlobal::config(), QLatin1String("PreviewSettings"));
145 globalConfig
.writeEntry("Plugins", m_enabledPreviewPlugins
);
147 globalConfig
.writeEntry("MaximumSize",
148 m_localFileSizeBox
->value() * 1024 * 1024,
149 KConfigBase::Normal
| KConfigBase::Global
);
150 globalConfig
.writeEntry("MaximumRemoteSize",
151 m_remoteFileSizeBox
->value() * 1024 * 1024,
152 KConfigBase::Normal
| KConfigBase::Global
);
156 void PreviewsSettingsPage::restoreDefaults()
158 m_localFileSizeBox
->setValue(MaxLocalPreviewSize
);
159 m_remoteFileSizeBox
->setValue(MaxRemotePreviewSize
);
162 void PreviewsSettingsPage::showEvent(QShowEvent
* event
)
164 if (!event
->spontaneous() && !m_initialized
) {
165 loadPreviewPlugins();
166 m_initialized
= true;
168 SettingsPageBase::showEvent(event
);
171 void PreviewsSettingsPage::configureService(const QModelIndex
& index
)
173 const QAbstractItemModel
* model
= index
.model();
174 const QString pluginName
= model
->data(index
).toString();
175 const QString desktopEntryName
= model
->data(index
, ServiceModel::DesktopEntryNameRole
).toString();
177 ConfigurePreviewPluginDialog
* dialog
= new ConfigurePreviewPluginDialog(pluginName
, desktopEntryName
, this);
178 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
182 void PreviewsSettingsPage::loadPreviewPlugins()
184 QAbstractItemModel
* model
= m_listView
->model();
186 const KService::List plugins
= KServiceTypeTrader::self()->query(QLatin1String("ThumbCreator"));
187 foreach (const KSharedPtr
<KService
>& service
, plugins
) {
188 const bool configurable
= service
->property("Configurable", QVariant::Bool
).toBool();
189 const bool show
= m_enabledPreviewPlugins
.contains(service
->desktopEntryName());
192 const QModelIndex index
= model
->index(0, 0);
193 model
->setData(index
, show
, Qt::CheckStateRole
);
194 model
->setData(index
, configurable
, ServiceModel::ConfigurableRole
);
195 model
->setData(index
, service
->name(), Qt::DisplayRole
);
196 model
->setData(index
, service
->desktopEntryName(), ServiceModel::DesktopEntryNameRole
);
199 model
->sort(Qt::DisplayRole
);
202 void PreviewsSettingsPage::loadSettings()
204 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
205 m_enabledPreviewPlugins
= globalConfig
.readEntry("Plugins", QStringList()
206 << QLatin1String("directorythumbnail")
207 << QLatin1String("imagethumbnail")
208 << QLatin1String("jpegthumbnail"));
210 // If the user is upgrading from KDE <= 4.6, we must check if he had the 'jpegrotatedthumbnail' plugin enabled.
211 // This plugin does not exist any more in KDE >= 4.7, so we have to replace it with the 'jpegthumbnail' plugin.
213 // Note that the upgrade to the correct plugin is done already in KFilePreviewGenerator. However, if Konqueror is
214 // opened in web browsing mode and the Settings dialog is opened, we might end up here before KFilePreviewGenerator's
215 // constructor is ever called -> the plugin replacement should be done here as well.
216 if(m_enabledPreviewPlugins
.contains(QLatin1String("jpegrotatedthumbnail"))) {
217 m_enabledPreviewPlugins
.removeAll(QLatin1String("jpegrotatedthumbnail"));
218 m_enabledPreviewPlugins
.append(QLatin1String("jpegthumbnail"));
219 globalConfig
.writeEntry("Plugins", m_enabledPreviewPlugins
);
223 const int maxLocalByteSize
= globalConfig
.readEntry("MaximumSize", MaxLocalPreviewSize
* 1024 * 1024);
224 const int maxLocalMByteSize
= maxLocalByteSize
/ (1024 * 1024);
225 m_localFileSizeBox
->setValue(maxLocalMByteSize
);
227 const int maxRemoteByteSize
= globalConfig
.readEntry("MaximumRemoteSize", MaxRemotePreviewSize
* 1024 * 1024);
228 const int maxRemoteMByteSize
= maxRemoteByteSize
/ (1024 * 1024);
229 m_remoteFileSizeBox
->setValue(maxRemoteMByteSize
);
232 #include "previewssettingspage.moc"