]>
cloud.milkyroute.net Git - dolphin.git/blob - src/generalviewsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "generalviewsettingspage.h"
22 #include "dolphinmainwindow.h"
23 #include "dolphinsettings.h"
24 #include "dolphin_generalsettings.h"
25 #include "viewproperties.h"
31 #include <QRadioButton>
34 #include <QVBoxLayout>
36 #include <kconfiggroup.h>
42 GeneralViewSettingsPage::GeneralViewSettingsPage(DolphinMainWindow
* mainWindow
,
45 m_mainWindow(mainWindow
),
50 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
51 assert(settings
!= 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(i18n("View Properties"), this);
62 m_localProps
= new QRadioButton(i18n("Remember view properties for each folder."), propsBox
);
63 m_globalProps
= new QRadioButton(i18n("Use common view properties for all folders."), propsBox
);
64 if (settings
->globalViewProps()) {
65 m_globalProps
->setChecked(true);
68 m_localProps
->setChecked(true);
71 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
72 propsBoxLayout
->addWidget(m_localProps
);
73 propsBoxLayout
->addWidget(m_globalProps
);
75 // create 'File Previews' box
76 QGroupBox
* previewBox
= new QGroupBox(i18n("File Previews"), this);
78 QLabel
* maxFileSize
= new QLabel(i18n("Maximum file size:"), previewBox
);
80 KHBox
* vBox
= new KHBox(previewBox
);
81 vBox
->setSpacing(spacing
);
83 const int min
= 1; // MB
84 const int max
= 100; // MB
85 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, vBox
);
86 m_maxPreviewSize
->setRange(min
, max
);
87 m_maxPreviewSize
->setPageStep(10);
88 m_maxPreviewSize
->setSingleStep(1);
89 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
91 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
92 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", 1024 * 1024 /* 1 MB */);
93 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
94 if (maxMByteSize
< 1) {
97 else if (maxMByteSize
> max
) {
100 m_maxPreviewSize
->setValue(maxMByteSize
);
102 QSpinBox
* spinBox
= new QSpinBox(vBox
);
103 spinBox
->setRange(min
, max
);
104 spinBox
->setSingleStep(1);
105 spinBox
->setSuffix(" MB");
106 spinBox
->setValue(m_maxPreviewSize
->value());
108 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
109 spinBox
, SLOT(setValue(int)));
110 connect(spinBox
, SIGNAL(valueChanged(int)),
111 m_maxPreviewSize
, SLOT(setValue(int)));
113 QVBoxLayout
* previewBoxLayout
= new QVBoxLayout(previewBox
);
114 previewBoxLayout
->addWidget(maxFileSize
);
115 previewBoxLayout
->addWidget(vBox
);
117 // Add a dummy widget with no restriction regarding
118 // a vertical resizing. This assures that the dialog layout
119 // is not stretched vertically.
124 GeneralViewSettingsPage::~GeneralViewSettingsPage()
128 void GeneralViewSettingsPage::applySettings()
130 const KUrl
& url
= m_mainWindow
->activeView()->url();
131 ViewProperties
props(url
); // read current view properties
133 const bool useGlobalProps
= m_globalProps
->isChecked();
135 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
136 assert(settings
!= 0);
137 settings
->setGlobalViewProps(useGlobalProps
);
139 if (useGlobalProps
) {
140 // Remember the global view properties by applying the current view properties.
141 // It is important that GeneralSettings::globalViewProps() is set before
142 // the class ViewProperties is used, as ViewProperties uses this setting
143 // to find the destination folder for storing the view properties.
144 ViewProperties
globalProps(url
);
145 globalProps
.setDirProperties(props
);
148 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
149 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
150 globalConfig
.writeEntry("MaximumSize",
152 KConfigBase::Normal
| KConfigBase::Global
);
156 #include "generalviewsettingspage.moc"