]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/previewssettingspage.cpp
A few more fixes...mostly cleanups.
[dolphin.git] / src / settings / previewssettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "previewssettingspage.h"
21 #include "dolphinsettings.h"
22
23 #include "dolphin_generalsettings.h"
24
25 #include <QCheckBox>
26 #include <QGroupBox>
27 #include <QLabel>
28 #include <QRadioButton>
29 #include <QSlider>
30 #include <QSpinBox>
31 #include <QBoxLayout>
32
33 #include <kconfiggroup.h>
34 #include <kdialog.h>
35 #include <kglobal.h>
36 #include <klocale.h>
37 #include <khbox.h>
38 #include <kvbox.h>
39
40 PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
41 SettingsPageBase(parent),
42 m_maxPreviewSize(0),
43 m_spinBox(0),
44 m_useFileThumbnails(0)
45 {
46 KVBox* vBox = new KVBox(this);
47 vBox->setSpacing(KDialog::spacingHint());
48 vBox->setMargin(KDialog::marginHint());
49
50 new QLabel("TODO: a major rewrite of this dialog will be done in 4.3", vBox);
51
52 KHBox* hBox = new KHBox(vBox);
53 hBox->setSpacing(KDialog::spacingHint());
54
55 new QLabel(i18nc("@label:slider", "Maximum file size:"), hBox);
56 m_maxPreviewSize = new QSlider(Qt::Horizontal, hBox);
57 m_maxPreviewSize->setPageStep(10);
58 m_maxPreviewSize->setSingleStep(1);
59 m_maxPreviewSize->setTickPosition(QSlider::TicksBelow);
60 m_maxPreviewSize->setRange(1, 100); /* MB */
61
62 m_spinBox = new QSpinBox(hBox);
63 m_spinBox->setSingleStep(1);
64 m_spinBox->setSuffix(" MB");
65 m_spinBox->setRange(1, 100); /* MB */
66
67 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
68 m_spinBox, SLOT(setValue(int)));
69 connect(m_spinBox, SIGNAL(valueChanged(int)),
70 m_maxPreviewSize, SLOT(setValue(int)));
71
72 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
73 this, SIGNAL(changed()));
74 connect(m_spinBox, SIGNAL(valueChanged(int)),
75 this, SIGNAL(changed()));
76
77 m_useFileThumbnails = new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), vBox);
78 connect(m_useFileThumbnails, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
79
80 // Add a dummy widget with no restriction regarding
81 // a vertical resizing. This assures that the dialog layout
82 // is not stretched vertically.
83 new QWidget(vBox);
84
85 loadSettings();
86 }
87
88
89 PreviewsSettingsPage::~PreviewsSettingsPage()
90 {
91 }
92
93 void PreviewsSettingsPage::applySettings()
94 {
95 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
96 const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB
97 globalConfig.writeEntry("MaximumSize",
98 byteCount,
99 KConfigBase::Normal | KConfigBase::Global);
100 globalConfig.writeEntry("UseFileThumbnails",
101 m_useFileThumbnails->isChecked(),
102 KConfigBase::Normal | KConfigBase::Global);
103 globalConfig.sync();
104 }
105
106 void PreviewsSettingsPage::restoreDefaults()
107 {
108 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
109 settings->useDefaults(true);
110 loadSettings();
111 settings->useDefaults(false);
112 }
113
114 void PreviewsSettingsPage::loadSettings()
115 {
116 const int min = 1; // MB
117 const int max = 100; // MB
118
119 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
120 // TODO: The default value of 5 MB must match with the default value inside
121 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
122 // should be added for getting the default size?
123 const int maxByteSize = globalConfig.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */);
124 int maxMByteSize = maxByteSize / (1024 * 1024);
125 if (maxMByteSize < min) {
126 maxMByteSize = min;
127 } else if (maxMByteSize > max) {
128 maxMByteSize = max;
129 }
130 m_maxPreviewSize->setValue(maxMByteSize);
131
132 const bool useFileThumbnails = globalConfig.readEntry("UseFileThumbnails", true);
133 m_useFileThumbnails->setChecked(useFileThumbnails);
134 }
135
136 #include "previewssettingspage.moc"