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