]>
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 "dolphin_generalsettings.h"
24 #include "viewproperties.h"
26 #include <QtGui/QLabel>
27 #include <QtGui/QGroupBox>
28 #include <QtGui/QRadioButton>
29 #include <QtGui/QSlider>
30 #include <QtGui/QSpinBox>
31 #include <QtGui/QBoxLayout>
33 #include <kconfiggroup.h>
39 GeneralViewSettingsPage::GeneralViewSettingsPage(DolphinMainWindow
* mainWindow
,
42 m_mainWindow(mainWindow
),
48 const int spacing
= KDialog::spacingHint();
49 const int margin
= KDialog::marginHint();
50 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
55 QGroupBox
* propsBox
= new QGroupBox(i18n("View Properties"), this);
57 m_localProps
= new QRadioButton(i18n("Remember view properties for each folder"), propsBox
);
58 m_globalProps
= new QRadioButton(i18n("Use common view properties for all folders"), propsBox
);
60 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
61 propsBoxLayout
->addWidget(m_localProps
);
62 propsBoxLayout
->addWidget(m_globalProps
);
64 // create 'File Previews' box
65 QGroupBox
* previewBox
= new QGroupBox(i18n("File Previews"), this);
67 QLabel
* maxFileSize
= new QLabel(i18n("Maximum file size:"), previewBox
);
69 KHBox
* vBox
= new KHBox(previewBox
);
70 vBox
->setSpacing(spacing
);
71 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, vBox
);
73 m_spinBox
= new QSpinBox(vBox
);
75 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
76 m_spinBox
, SLOT(setValue(int)));
77 connect(m_spinBox
, SIGNAL(valueChanged(int)),
78 m_maxPreviewSize
, SLOT(setValue(int)));
80 QVBoxLayout
* previewBoxLayout
= new QVBoxLayout(previewBox
);
81 previewBoxLayout
->addWidget(maxFileSize
);
82 previewBoxLayout
->addWidget(vBox
);
84 // Add a dummy widget with no restriction regarding
85 // a vertical resizing. This assures that the dialog layout
86 // is not stretched vertically.
93 GeneralViewSettingsPage::~GeneralViewSettingsPage()
95 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
96 settings
->setDefaults();
101 void GeneralViewSettingsPage::applySettings()
103 const KUrl
& url
= m_mainWindow
->activeView()->url();
104 ViewProperties
props(url
); // read current view properties
106 const bool useGlobalProps
= m_globalProps
->isChecked();
108 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
109 settings
->setGlobalViewProps(useGlobalProps
);
111 if (useGlobalProps
) {
112 // Remember the global view properties by applying the current view properties.
113 // It is important that GeneralSettings::globalViewProps() is set before
114 // the class ViewProperties is used, as ViewProperties uses this setting
115 // to find the destination folder for storing the view properties.
116 ViewProperties
globalProps(url
);
117 globalProps
.setDirProperties(props
);
120 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
121 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
122 globalConfig
.writeEntry("MaximumSize",
124 KConfigBase::Normal
| KConfigBase::Global
);
128 void GeneralViewSettingsPage::restoreDefaults()
130 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
131 settings
->setDefaults();
135 void GeneralViewSettingsPage::loadSettings()
137 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
138 if (settings
->globalViewProps()) {
139 m_globalProps
->setChecked(true);
141 m_localProps
->setChecked(true);
144 const int min
= 1; // MB
145 const int max
= 100; // MB
146 m_maxPreviewSize
->setRange(min
, max
);
147 m_maxPreviewSize
->setPageStep(10);
148 m_maxPreviewSize
->setSingleStep(1);
149 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
151 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
152 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", 1024 * 1024 /* 1 MB */);
153 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
154 if (maxMByteSize
< 1) {
156 } else if (maxMByteSize
> max
) {
159 m_maxPreviewSize
->setValue(maxMByteSize
);
161 m_spinBox
->setRange(min
, max
);
162 m_spinBox
->setSingleStep(1);
163 m_spinBox
->setSuffix(" MB");
164 m_spinBox
->setValue(m_maxPreviewSize
->value());
167 #include "generalviewsettingspage.moc"