]>
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"
28 #include <QRadioButton>
31 #include <QVBoxLayout>
33 #include <kconfiggroup.h>
39 GeneralViewSettingsPage::GeneralViewSettingsPage(DolphinMainWindow
* mainWindow
,
42 m_mainWindow(mainWindow
),
47 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
48 Q_ASSERT(settings
!= 0);
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
);
61 if (settings
->globalViewProps()) {
62 m_globalProps
->setChecked(true);
65 m_localProps
->setChecked(true);
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(i18n("File Previews"), this);
75 QLabel
* maxFileSize
= new QLabel(i18n("Maximum file size:"), previewBox
);
77 KHBox
* vBox
= new KHBox(previewBox
);
78 vBox
->setSpacing(spacing
);
80 const int min
= 1; // MB
81 const int max
= 100; // MB
82 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, vBox
);
83 m_maxPreviewSize
->setRange(min
, max
);
84 m_maxPreviewSize
->setPageStep(10);
85 m_maxPreviewSize
->setSingleStep(1);
86 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
88 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
89 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", 1024 * 1024 /* 1 MB */);
90 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
91 if (maxMByteSize
< 1) {
94 else if (maxMByteSize
> max
) {
97 m_maxPreviewSize
->setValue(maxMByteSize
);
99 QSpinBox
* spinBox
= new QSpinBox(vBox
);
100 spinBox
->setRange(min
, max
);
101 spinBox
->setSingleStep(1);
102 spinBox
->setSuffix(" MB");
103 spinBox
->setValue(m_maxPreviewSize
->value());
105 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
106 spinBox
, SLOT(setValue(int)));
107 connect(spinBox
, SIGNAL(valueChanged(int)),
108 m_maxPreviewSize
, SLOT(setValue(int)));
110 QVBoxLayout
* previewBoxLayout
= new QVBoxLayout(previewBox
);
111 previewBoxLayout
->addWidget(maxFileSize
);
112 previewBoxLayout
->addWidget(vBox
);
114 // Add a dummy widget with no restriction regarding
115 // a vertical resizing. This assures that the dialog layout
116 // is not stretched vertically.
121 GeneralViewSettingsPage::~GeneralViewSettingsPage()
125 void GeneralViewSettingsPage::applySettings()
127 const KUrl
& url
= m_mainWindow
->activeView()->url();
128 ViewProperties
props(url
); // read current view properties
130 const bool useGlobalProps
= m_globalProps
->isChecked();
132 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
133 Q_ASSERT(settings
!= 0);
134 settings
->setGlobalViewProps(useGlobalProps
);
136 if (useGlobalProps
) {
137 // Remember the global view properties by applying the current view properties.
138 // It is important that GeneralSettings::globalViewProps() is set before
139 // the class ViewProperties is used, as ViewProperties uses this setting
140 // to find the destination folder for storing the view properties.
141 ViewProperties
globalProps(url
);
142 globalProps
.setDirProperties(props
);
145 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
146 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
147 globalConfig
.writeEntry("MaximumSize",
149 KConfigBase::Normal
| KConfigBase::Global
);
153 #include "generalviewsettingspage.moc"