]>
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"
30 #include <QRadioButton>
35 #include <kconfiggroup.h>
41 GeneralViewSettingsPage::GeneralViewSettingsPage(DolphinMainWindow
* mainWindow
,
44 m_mainWindow(mainWindow
),
50 const int spacing
= KDialog::spacingHint();
51 const int margin
= KDialog::marginHint();
52 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
57 QGroupBox
* propsBox
= new QGroupBox(i18n("View Properties"), this);
59 m_localProps
= new QRadioButton(i18n("Remember view properties for each folder"), propsBox
);
60 m_globalProps
= new QRadioButton(i18n("Use common view properties for all folders"), propsBox
);
62 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
63 propsBoxLayout
->addWidget(m_localProps
);
64 propsBoxLayout
->addWidget(m_globalProps
);
66 // create 'File Previews' box
67 QGroupBox
* previewBox
= new QGroupBox(i18n("File Previews"), this);
69 QLabel
* maxFileSize
= new QLabel(i18n("Maximum file size:"), previewBox
);
71 KHBox
* vBox
= new KHBox(previewBox
);
72 vBox
->setSpacing(spacing
);
73 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, vBox
);
75 m_spinBox
= new QSpinBox(vBox
);
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)));
82 QVBoxLayout
* previewBoxLayout
= new QVBoxLayout(previewBox
);
83 previewBoxLayout
->addWidget(maxFileSize
);
84 previewBoxLayout
->addWidget(vBox
);
86 // Add a dummy widget with no restriction regarding
87 // a vertical resizing. This assures that the dialog layout
88 // is not stretched vertically.
95 GeneralViewSettingsPage::~GeneralViewSettingsPage()
97 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
98 settings
->setDefaults();
103 void GeneralViewSettingsPage::applySettings()
105 const KUrl
& url
= m_mainWindow
->activeViewContainer()->url();
106 ViewProperties
props(url
); // read current view properties
108 const bool useGlobalProps
= m_globalProps
->isChecked();
110 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
111 settings
->setGlobalViewProps(useGlobalProps
);
113 if (useGlobalProps
) {
114 // Remember the global view properties by applying the current view properties.
115 // It is important that GeneralSettings::globalViewProps() is set before
116 // the class ViewProperties is used, as ViewProperties uses this setting
117 // to find the destination folder for storing the view properties.
118 ViewProperties
globalProps(url
);
119 globalProps
.setDirProperties(props
);
122 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
123 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
124 globalConfig
.writeEntry("MaximumSize",
126 KConfigBase::Normal
| KConfigBase::Global
);
130 void GeneralViewSettingsPage::restoreDefaults()
132 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
133 settings
->setDefaults();
137 void GeneralViewSettingsPage::loadSettings()
139 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
140 if (settings
->globalViewProps()) {
141 m_globalProps
->setChecked(true);
143 m_localProps
->setChecked(true);
146 const int min
= 1; // MB
147 const int max
= 100; // MB
148 m_maxPreviewSize
->setRange(min
, max
);
149 m_maxPreviewSize
->setPageStep(10);
150 m_maxPreviewSize
->setSingleStep(1);
151 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
153 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
154 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", 1024 * 1024 /* 1 MB */);
155 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
156 if (maxMByteSize
< 1) {
158 } else if (maxMByteSize
> max
) {
161 m_maxPreviewSize
->setValue(maxMByteSize
);
163 m_spinBox
->setRange(min
, max
);
164 m_spinBox
->setSingleStep(1);
165 m_spinBox
->setSuffix(" MB");
166 m_spinBox
->setValue(m_maxPreviewSize
->value());
169 #include "generalviewsettingspage.moc"