]>
cloud.milkyroute.net Git - dolphin.git/blob - src/generalviewsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 ***************************************************************************/
20 #include "generalviewsettingspage.h"
21 #include "dolphinmainwindow.h"
22 #include "dolphinsettings.h"
23 #include "dolphinviewcontainer.h"
24 #include "viewproperties.h"
26 #include "dolphin_generalsettings.h"
31 #include <QRadioButton>
36 #include <kconfiggroup.h>
42 GeneralViewSettingsPage::GeneralViewSettingsPage(const KUrl
& url
,
44 ViewSettingsPageBase(parent
),
50 m_useFileThumbnails(0),
51 m_showSelectionToggle(0)
53 const int spacing
= KDialog::spacingHint();
54 const int margin
= KDialog::marginHint();
55 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
60 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), this);
62 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
63 connect(m_localProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
65 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
66 connect(m_globalProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
68 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
69 propsBoxLayout
->addWidget(m_localProps
);
70 propsBoxLayout
->addWidget(m_globalProps
);
72 // create 'File Previews' box
73 QGroupBox
* previewBox
= new QGroupBox(i18nc("@title:group", "File Previews"), this);
75 KHBox
* vBox
= new KHBox(previewBox
);
76 vBox
->setSpacing(spacing
);
78 new QLabel(i18nc("@label:slider", "Maximum file size:"), vBox
);
79 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, vBox
);
81 m_spinBox
= new QSpinBox(vBox
);
83 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
84 m_spinBox
, SLOT(setValue(int)));
85 connect(m_spinBox
, SIGNAL(valueChanged(int)),
86 m_maxPreviewSize
, SLOT(setValue(int)));
88 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
89 this, SIGNAL(changed()));
90 connect(m_spinBox
, SIGNAL(valueChanged(int)),
91 this, SIGNAL(changed()));
93 m_useFileThumbnails
= new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), previewBox
);
94 connect(m_useFileThumbnails
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
96 QVBoxLayout
* previewBoxLayout
= new QVBoxLayout(previewBox
);
97 previewBoxLayout
->addWidget(vBox
);
98 previewBoxLayout
->addWidget(m_useFileThumbnails
);
100 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection toggle"), this);
101 connect(m_showSelectionToggle
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
103 // Add a dummy widget with no restriction regarding
104 // a vertical resizing. This assures that the dialog layout
105 // is not stretched vertically.
112 GeneralViewSettingsPage::~GeneralViewSettingsPage()
116 void GeneralViewSettingsPage::applySettings()
118 ViewProperties
props(m_url
); // read current view properties
120 const bool useGlobalProps
= m_globalProps
->isChecked();
122 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
123 settings
->setGlobalViewProps(useGlobalProps
);
125 if (useGlobalProps
) {
126 // Remember the global view properties by applying the current view properties.
127 // It is important that GeneralSettings::globalViewProps() is set before
128 // the class ViewProperties is used, as ViewProperties uses this setting
129 // to find the destination folder for storing the view properties.
130 ViewProperties
globalProps(m_url
);
131 globalProps
.setDirProperties(props
);
134 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
135 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
136 globalConfig
.writeEntry("MaximumSize",
138 KConfigBase::Normal
| KConfigBase::Global
);
139 globalConfig
.writeEntry("UseFileThumbnails",
140 m_useFileThumbnails
->isChecked(),
141 KConfigBase::Normal
| KConfigBase::Global
);
144 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
147 void GeneralViewSettingsPage::restoreDefaults()
149 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
150 settings
->setDefaults();
154 void GeneralViewSettingsPage::loadSettings()
156 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
157 if (settings
->globalViewProps()) {
158 m_globalProps
->setChecked(true);
160 m_localProps
->setChecked(true);
163 const int min
= 1; // MB
164 const int max
= 100; // MB
165 m_maxPreviewSize
->setRange(min
, max
);
166 m_maxPreviewSize
->setPageStep(10);
167 m_maxPreviewSize
->setSingleStep(1);
168 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
170 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
171 // TODO: The default value of 5 MB must match with the default value inside
172 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
173 // should be added for getting the default size?
174 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */);
175 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
176 if (maxMByteSize
< 1) {
178 } else if (maxMByteSize
> max
) {
182 m_spinBox
->setRange(min
, max
);
183 m_spinBox
->setSingleStep(1);
184 m_spinBox
->setSuffix(" MB");
186 m_maxPreviewSize
->setValue(maxMByteSize
);
187 m_spinBox
->setValue(m_maxPreviewSize
->value());
189 const bool useFileThumbnails
= globalConfig
.readEntry("UseFileThumbnails", true);
190 m_useFileThumbnails
->setChecked(useFileThumbnails
);
192 m_showSelectionToggle
->setChecked(settings
->showSelectionToggle());
195 #include "generalviewsettingspage.moc"