]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/previewssettingspage.cpp
We were calling methods within loadSettings() which should have been moved to inside...
[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
61 m_spinBox = new QSpinBox(hBox);
62 m_spinBox->setSingleStep(1);
63 m_spinBox->setSuffix(" MB");
64
65 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
66 m_spinBox, SLOT(setValue(int)));
67 connect(m_spinBox, SIGNAL(valueChanged(int)),
68 m_maxPreviewSize, SLOT(setValue(int)));
69
70 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
71 this, SIGNAL(changed()));
72 connect(m_spinBox, SIGNAL(valueChanged(int)),
73 this, SIGNAL(changed()));
74
75 m_useFileThumbnails = new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), vBox);
76 connect(m_useFileThumbnails, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
77
78 // Add a dummy widget with no restriction regarding
79 // a vertical resizing. This assures that the dialog layout
80 // is not stretched vertically.
81 new QWidget(vBox);
82
83 loadSettings();
84 }
85
86
87 PreviewsSettingsPage::~PreviewsSettingsPage()
88 {
89 }
90
91 void PreviewsSettingsPage::applySettings()
92 {
93 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
94 const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB
95 globalConfig.writeEntry("MaximumSize",
96 byteCount,
97 KConfigBase::Normal | KConfigBase::Global);
98 globalConfig.writeEntry("UseFileThumbnails",
99 m_useFileThumbnails->isChecked(),
100 KConfigBase::Normal | KConfigBase::Global);
101 globalConfig.sync();
102 }
103
104 void PreviewsSettingsPage::restoreDefaults()
105 {
106 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
107 settings->useDefaults(true);
108 loadSettings();
109 settings->useDefaults(false);
110 }
111
112 void PreviewsSettingsPage::loadSettings()
113 {
114 const int min = 1; // MB
115 const int max = 100; // MB
116 m_maxPreviewSize->setRange(min, max);
117
118 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
119 // TODO: The default value of 5 MB must match with the default value inside
120 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
121 // should be added for getting the default size?
122 const int maxByteSize = globalConfig.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */);
123 int maxMByteSize = maxByteSize / (1024 * 1024);
124 if (maxMByteSize < 1) {
125 maxMByteSize = 1;
126 } else if (maxMByteSize > max) {
127 maxMByteSize = max;
128 }
129 m_spinBox->setRange(min, max);
130
131 m_maxPreviewSize->setValue(maxMByteSize);
132 m_spinBox->setValue(m_maxPreviewSize->value());
133
134 const bool useFileThumbnails = globalConfig.readEntry("UseFileThumbnails", true);
135 m_useFileThumbnails->setChecked(useFileThumbnails);
136 }
137
138 #include "previewssettingspage.moc"