]>
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);
64 m_localProps
->setChecked(true);
67 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
68 propsBoxLayout
->addWidget(m_localProps
);
69 propsBoxLayout
->addWidget(m_globalProps
);
71 // create 'File Previews' box
72 QGroupBox
* previewBox
= new QGroupBox(i18n("File Previews"), this);
74 QLabel
* maxFileSize
= new QLabel(i18n("Maximum file size:"), previewBox
);
76 KHBox
* vBox
= new KHBox(previewBox
);
77 vBox
->setSpacing(spacing
);
79 const int min
= 1; // MB
80 const int max
= 100; // MB
81 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, vBox
);
82 m_maxPreviewSize
->setRange(min
, max
);
83 m_maxPreviewSize
->setPageStep(10);
84 m_maxPreviewSize
->setSingleStep(1);
85 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
87 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
88 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", 1024 * 1024 /* 1 MB */);
89 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
90 if (maxMByteSize
< 1) {
92 } else if (maxMByteSize
> max
) {
95 m_maxPreviewSize
->setValue(maxMByteSize
);
97 QSpinBox
* spinBox
= new QSpinBox(vBox
);
98 spinBox
->setRange(min
, max
);
99 spinBox
->setSingleStep(1);
100 spinBox
->setSuffix(" MB");
101 spinBox
->setValue(m_maxPreviewSize
->value());
103 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
104 spinBox
, SLOT(setValue(int)));
105 connect(spinBox
, SIGNAL(valueChanged(int)),
106 m_maxPreviewSize
, SLOT(setValue(int)));
108 QVBoxLayout
* previewBoxLayout
= new QVBoxLayout(previewBox
);
109 previewBoxLayout
->addWidget(maxFileSize
);
110 previewBoxLayout
->addWidget(vBox
);
112 // Add a dummy widget with no restriction regarding
113 // a vertical resizing. This assures that the dialog layout
114 // is not stretched vertically.
119 GeneralViewSettingsPage::~GeneralViewSettingsPage()
122 void GeneralViewSettingsPage::applySettings()
124 const KUrl
& url
= m_mainWindow
->activeView()->url();
125 ViewProperties
props(url
); // read current view properties
127 const bool useGlobalProps
= m_globalProps
->isChecked();
129 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
130 Q_ASSERT(settings
!= 0);
131 settings
->setGlobalViewProps(useGlobalProps
);
133 if (useGlobalProps
) {
134 // Remember the global view properties by applying the current view properties.
135 // It is important that GeneralSettings::globalViewProps() is set before
136 // the class ViewProperties is used, as ViewProperties uses this setting
137 // to find the destination folder for storing the view properties.
138 ViewProperties
globalProps(url
);
139 globalProps
.setDirProperties(props
);
142 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
143 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
144 globalConfig
.writeEntry("MaximumSize",
146 KConfigBase::Normal
| KConfigBase::Global
);
150 #include "generalviewsettingspage.moc"