]>
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"
31 #include <QRadioButton>
36 #include <kconfiggroup.h>
42 GeneralViewSettingsPage::GeneralViewSettingsPage(DolphinMainWindow
* mainWindow
,
45 m_mainWindow(mainWindow
),
50 m_useFileThumbnails(0)
52 const int spacing
= KDialog::spacingHint();
53 const int margin
= KDialog::marginHint();
54 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
59 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), this);
61 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
62 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
64 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
65 propsBoxLayout
->addWidget(m_localProps
);
66 propsBoxLayout
->addWidget(m_globalProps
);
68 // create 'File Previews' box
69 QGroupBox
* previewBox
= new QGroupBox(i18nc("@title:group", "File Previews"), this);
71 KHBox
* vBox
= new KHBox(previewBox
);
72 vBox
->setSpacing(spacing
);
74 QLabel
* maxFileSize
= new QLabel(i18nc("@label:slider", "Maximum file size:"), vBox
);
75 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, vBox
);
77 m_spinBox
= new QSpinBox(vBox
);
79 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
80 m_spinBox
, SLOT(setValue(int)));
81 connect(m_spinBox
, SIGNAL(valueChanged(int)),
82 m_maxPreviewSize
, SLOT(setValue(int)));
84 m_useFileThumbnails
= new QCheckBox(i18n("Use thumbnails embedded in files"), previewBox
);
86 QVBoxLayout
* previewBoxLayout
= new QVBoxLayout(previewBox
);
87 previewBoxLayout
->addWidget(vBox
);
88 previewBoxLayout
->addWidget(m_useFileThumbnails
);
90 // Add a dummy widget with no restriction regarding
91 // a vertical resizing. This assures that the dialog layout
92 // is not stretched vertically.
99 GeneralViewSettingsPage::~GeneralViewSettingsPage()
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
);
127 globalConfig
.writeEntry("UseFileThumbnails",
128 m_useFileThumbnails
->isChecked(),
129 KConfigBase::Normal
| KConfigBase::Global
);
133 void GeneralViewSettingsPage::restoreDefaults()
135 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
136 settings
->setDefaults();
140 void GeneralViewSettingsPage::loadSettings()
142 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
143 if (settings
->globalViewProps()) {
144 m_globalProps
->setChecked(true);
146 m_localProps
->setChecked(true);
149 const int min
= 1; // MB
150 const int max
= 100; // MB
151 m_maxPreviewSize
->setRange(min
, max
);
152 m_maxPreviewSize
->setPageStep(10);
153 m_maxPreviewSize
->setSingleStep(1);
154 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
156 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
157 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */);
158 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
159 if (maxMByteSize
< 1) {
161 } else if (maxMByteSize
> max
) {
165 m_spinBox
->setRange(min
, max
);
166 m_spinBox
->setSingleStep(1);
167 m_spinBox
->setSuffix(" MB");
169 m_maxPreviewSize
->setValue(maxMByteSize
);
170 m_spinBox
->setValue(m_maxPreviewSize
->value());
172 const bool useFileThumbnails
= globalConfig
.readEntry("UseFileThumbnails", true);
173 m_useFileThumbnails
->setChecked(useFileThumbnails
);
176 #include "generalviewsettingspage.moc"