]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalviewsettingspage.cpp
Init the range before a value is set (via the signal valueChanged)
[dolphin.git] / src / generalviewsettingspage.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 "generalviewsettingspage.h"
21 #include "dolphinmainwindow.h"
22 #include "dolphinsettings.h"
23 #include "dolphinviewcontainer.h"
24 #include "viewproperties.h"
25
26 #include "dolphin_generalsettings.h"
27
28 #include <QLabel>
29 #include <QGroupBox>
30 #include <QRadioButton>
31 #include <QSlider>
32 #include <QSpinBox>
33 #include <QBoxLayout>
34
35 #include <kconfiggroup.h>
36 #include <kdialog.h>
37 #include <kglobal.h>
38 #include <klocale.h>
39 #include <khbox.h>
40
41 GeneralViewSettingsPage::GeneralViewSettingsPage(DolphinMainWindow* mainWindow,
42 QWidget* parent) :
43 KVBox(parent),
44 m_mainWindow(mainWindow),
45 m_localProps(0),
46 m_globalProps(0),
47 m_maxPreviewSize(0),
48 m_spinBox(0)
49 {
50 const int spacing = KDialog::spacingHint();
51 const int margin = KDialog::marginHint();
52 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
53
54 setSpacing(spacing);
55 setMargin(margin);
56
57 QGroupBox* propsBox = new QGroupBox(i18nc("@title:group", "View Properties"), this);
58
59 m_localProps = new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox);
60 m_globalProps = new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox);
61
62 QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox);
63 propsBoxLayout->addWidget(m_localProps);
64 propsBoxLayout->addWidget(m_globalProps);
65
66 // create 'File Previews' box
67 QGroupBox* previewBox = new QGroupBox(i18nc("@title:group", "File Previews"), this);
68
69 QLabel* maxFileSize = new QLabel(i18nc("@label:slider", "Maximum file size:"), previewBox);
70
71 KHBox* vBox = new KHBox(previewBox);
72 vBox->setSpacing(spacing);
73 m_maxPreviewSize = new QSlider(Qt::Horizontal, vBox);
74
75 m_spinBox = new QSpinBox(vBox);
76
77 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
78 m_spinBox, SLOT(setValue(int)));
79 connect(m_spinBox, SIGNAL(valueChanged(int)),
80 m_maxPreviewSize, SLOT(setValue(int)));
81
82 QVBoxLayout* previewBoxLayout = new QVBoxLayout(previewBox);
83 previewBoxLayout->addWidget(maxFileSize);
84 previewBoxLayout->addWidget(vBox);
85
86 // Add a dummy widget with no restriction regarding
87 // a vertical resizing. This assures that the dialog layout
88 // is not stretched vertically.
89 new QWidget(this);
90
91 loadSettings();
92 }
93
94
95 GeneralViewSettingsPage::~GeneralViewSettingsPage()
96 {
97 }
98
99 void GeneralViewSettingsPage::applySettings()
100 {
101 const KUrl& url = m_mainWindow->activeViewContainer()->url();
102 ViewProperties props(url); // read current view properties
103
104 const bool useGlobalProps = m_globalProps->isChecked();
105
106 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
107 settings->setGlobalViewProps(useGlobalProps);
108
109 if (useGlobalProps) {
110 // Remember the global view properties by applying the current view properties.
111 // It is important that GeneralSettings::globalViewProps() is set before
112 // the class ViewProperties is used, as ViewProperties uses this setting
113 // to find the destination folder for storing the view properties.
114 ViewProperties globalProps(url);
115 globalProps.setDirProperties(props);
116 }
117
118 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
119 const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB
120 globalConfig.writeEntry("MaximumSize",
121 byteCount,
122 KConfigBase::Normal | KConfigBase::Global);
123 globalConfig.sync();
124 }
125
126 void GeneralViewSettingsPage::restoreDefaults()
127 {
128 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
129 settings->setDefaults();
130 loadSettings();
131 }
132
133 void GeneralViewSettingsPage::loadSettings()
134 {
135 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
136 if (settings->globalViewProps()) {
137 m_globalProps->setChecked(true);
138 } else {
139 m_localProps->setChecked(true);
140 }
141
142 const int min = 1; // MB
143 const int max = 100; // MB
144 m_maxPreviewSize->setRange(min, max);
145 m_maxPreviewSize->setPageStep(10);
146 m_maxPreviewSize->setSingleStep(1);
147 m_maxPreviewSize->setTickPosition(QSlider::TicksBelow);
148
149 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
150 const int maxByteSize = globalConfig.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */);
151 int maxMByteSize = maxByteSize / (1024 * 1024);
152 if (maxMByteSize < 1) {
153 maxMByteSize = 1;
154 } else if (maxMByteSize > max) {
155 maxMByteSize = max;
156 }
157
158 m_spinBox->setRange(min, max);
159 m_spinBox->setSingleStep(1);
160 m_spinBox->setSuffix(" MB");
161
162 m_maxPreviewSize->setValue(maxMByteSize);
163 m_spinBox->setValue(m_maxPreviewSize->value());
164 }
165
166 #include "generalviewsettingspage.moc"