]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalviewsettingspage.cpp
prevent that the user can open more than one instance of the settings dialog
[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 <QCheckBox>
29 #include <QGroupBox>
30 #include <QLabel>
31 #include <QRadioButton>
32 #include <QSlider>
33 #include <QSpinBox>
34 #include <QBoxLayout>
35
36 #include <kconfiggroup.h>
37 #include <kdialog.h>
38 #include <kglobal.h>
39 #include <klocale.h>
40 #include <khbox.h>
41
42 GeneralViewSettingsPage::GeneralViewSettingsPage(const KUrl& url,
43 QWidget* parent) :
44 ViewSettingsPageBase(parent),
45 m_url(url),
46 m_localProps(0),
47 m_globalProps(0),
48 m_maxPreviewSize(0),
49 m_spinBox(0),
50 m_useFileThumbnails(0),
51 m_showSelectionToggle(0),
52 m_showToolTips(0)
53 {
54 const int spacing = KDialog::spacingHint();
55 const int margin = KDialog::marginHint();
56 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
57
58 setSpacing(spacing);
59 setMargin(margin);
60
61 QGroupBox* propsBox = new QGroupBox(i18nc("@title:group", "View Properties"), this);
62
63 m_localProps = new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox);
64 connect(m_localProps, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
65
66 m_globalProps = new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox);
67 connect(m_globalProps, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
68
69 QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox);
70 propsBoxLayout->addWidget(m_localProps);
71 propsBoxLayout->addWidget(m_globalProps);
72
73 // create 'File Previews' box
74 QGroupBox* previewBox = new QGroupBox(i18nc("@title:group", "File Previews"), this);
75
76 KHBox* vBox = new KHBox(previewBox);
77 vBox->setSpacing(spacing);
78
79 new QLabel(i18nc("@label:slider", "Maximum file size:"), vBox);
80 m_maxPreviewSize = new QSlider(Qt::Horizontal, vBox);
81
82 m_spinBox = new QSpinBox(vBox);
83
84 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
85 m_spinBox, SLOT(setValue(int)));
86 connect(m_spinBox, SIGNAL(valueChanged(int)),
87 m_maxPreviewSize, SLOT(setValue(int)));
88
89 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
90 this, SIGNAL(changed()));
91 connect(m_spinBox, SIGNAL(valueChanged(int)),
92 this, SIGNAL(changed()));
93
94 m_useFileThumbnails = new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), previewBox);
95 connect(m_useFileThumbnails, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
96
97 QVBoxLayout* previewBoxLayout = new QVBoxLayout(previewBox);
98 previewBoxLayout->addWidget(vBox);
99 previewBoxLayout->addWidget(m_useFileThumbnails);
100
101 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
102 connect(m_showSelectionToggle, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
103
104 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
105 connect(m_showToolTips, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
106
107 // Add a dummy widget with no restriction regarding
108 // a vertical resizing. This assures that the dialog layout
109 // is not stretched vertically.
110 new QWidget(this);
111
112 loadSettings();
113 }
114
115
116 GeneralViewSettingsPage::~GeneralViewSettingsPage()
117 {
118 }
119
120 void GeneralViewSettingsPage::applySettings()
121 {
122 ViewProperties props(m_url); // read current view properties
123
124 const bool useGlobalProps = m_globalProps->isChecked();
125
126 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
127 settings->setGlobalViewProps(useGlobalProps);
128
129 if (useGlobalProps) {
130 // Remember the global view properties by applying the current view properties.
131 // It is important that GeneralSettings::globalViewProps() is set before
132 // the class ViewProperties is used, as ViewProperties uses this setting
133 // to find the destination folder for storing the view properties.
134 ViewProperties globalProps(m_url);
135 globalProps.setDirProperties(props);
136 }
137
138 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
139 const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB
140 globalConfig.writeEntry("MaximumSize",
141 byteCount,
142 KConfigBase::Normal | KConfigBase::Global);
143 globalConfig.writeEntry("UseFileThumbnails",
144 m_useFileThumbnails->isChecked(),
145 KConfigBase::Normal | KConfigBase::Global);
146 globalConfig.sync();
147
148 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
149 settings->setShowToolTips(m_showToolTips->isChecked());
150 }
151
152 void GeneralViewSettingsPage::restoreDefaults()
153 {
154 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
155 settings->setDefaults();
156 loadSettings();
157 }
158
159 void GeneralViewSettingsPage::loadSettings()
160 {
161 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
162 if (settings->globalViewProps()) {
163 m_globalProps->setChecked(true);
164 } else {
165 m_localProps->setChecked(true);
166 }
167
168 const int min = 1; // MB
169 const int max = 100; // MB
170 m_maxPreviewSize->setRange(min, max);
171 m_maxPreviewSize->setPageStep(10);
172 m_maxPreviewSize->setSingleStep(1);
173 m_maxPreviewSize->setTickPosition(QSlider::TicksBelow);
174
175 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
176 // TODO: The default value of 5 MB must match with the default value inside
177 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
178 // should be added for getting the default size?
179 const int maxByteSize = globalConfig.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */);
180 int maxMByteSize = maxByteSize / (1024 * 1024);
181 if (maxMByteSize < 1) {
182 maxMByteSize = 1;
183 } else if (maxMByteSize > max) {
184 maxMByteSize = max;
185 }
186
187 m_spinBox->setRange(min, max);
188 m_spinBox->setSingleStep(1);
189 m_spinBox->setSuffix(" MB");
190
191 m_maxPreviewSize->setValue(maxMByteSize);
192 m_spinBox->setValue(m_maxPreviewSize->value());
193
194 const bool useFileThumbnails = globalConfig.readEntry("UseFileThumbnails", true);
195 m_useFileThumbnails->setChecked(useFileThumbnails);
196
197 m_showSelectionToggle->setChecked(settings->showSelectionToggle());
198 m_showToolTips->setChecked(settings->showToolTips());
199 }
200
201 #include "generalviewsettingspage.moc"