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"
28 #include <QRadioButton>
33 #include <kconfiggroup.h>
40 PreviewsSettingsPage::PreviewsSettingsPage(QWidget
* parent
) :
41 SettingsPageBase(parent
),
44 m_useFileThumbnails(0)
46 KVBox
* vBox
= new KVBox(this);
47 vBox
->setSpacing(KDialog::spacingHint());
48 vBox
->setMargin(KDialog::marginHint());
50 new QLabel("TODO: a major rewrite of this dialog will be done in 4.3", vBox
);
52 KHBox
* hBox
= new KHBox(vBox
);
53 hBox
->setSpacing(KDialog::spacingHint());
55 new QLabel(i18nc("@label:slider", "Maximum file size:"), hBox
);
56 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, hBox
);
58 m_spinBox
= new QSpinBox(hBox
);
60 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
61 m_spinBox
, SLOT(setValue(int)));
62 connect(m_spinBox
, SIGNAL(valueChanged(int)),
63 m_maxPreviewSize
, SLOT(setValue(int)));
65 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
66 this, SIGNAL(changed()));
67 connect(m_spinBox
, SIGNAL(valueChanged(int)),
68 this, SIGNAL(changed()));
70 m_useFileThumbnails
= new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), vBox
);
71 connect(m_useFileThumbnails
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
73 // Add a dummy widget with no restriction regarding
74 // a vertical resizing. This assures that the dialog layout
75 // is not stretched vertically.
82 PreviewsSettingsPage::~PreviewsSettingsPage()
86 void PreviewsSettingsPage::applySettings()
88 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
89 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
90 globalConfig
.writeEntry("MaximumSize",
92 KConfigBase::Normal
| KConfigBase::Global
);
93 globalConfig
.writeEntry("UseFileThumbnails",
94 m_useFileThumbnails
->isChecked(),
95 KConfigBase::Normal
| KConfigBase::Global
);
99 void PreviewsSettingsPage::restoreDefaults()
101 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
102 settings
->setDefaults();
106 void PreviewsSettingsPage::loadSettings()
108 const int min
= 1; // MB
109 const int max
= 100; // MB
110 m_maxPreviewSize
->setRange(min
, max
);
111 m_maxPreviewSize
->setPageStep(10);
112 m_maxPreviewSize
->setSingleStep(1);
113 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
115 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
116 // TODO: The default value of 5 MB must match with the default value inside
117 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
118 // should be added for getting the default size?
119 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */);
120 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
121 if (maxMByteSize
< 1) {
123 } else if (maxMByteSize
> max
) {
127 m_spinBox
->setRange(min
, max
);
128 m_spinBox
->setSingleStep(1);
129 m_spinBox
->setSuffix(" MB");
131 m_maxPreviewSize
->setValue(maxMByteSize
);
132 m_spinBox
->setValue(m_maxPreviewSize
->value());
134 const bool useFileThumbnails
= globalConfig
.readEntry("UseFileThumbnails", true);
135 m_useFileThumbnails
->setChecked(useFileThumbnails
);
138 #include "previewssettingspage.moc"