]>
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(const KUrl
& url
,
44 ViewSettingsPageBase(parent
),
50 m_useFileThumbnails(0),
51 m_showSelectionToggle(0),
54 const int spacing
= KDialog::spacingHint();
55 const int margin
= KDialog::marginHint();
56 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
61 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), this);
63 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
64 connect(m_localProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
66 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
67 connect(m_globalProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
69 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
70 propsBoxLayout
->addWidget(m_localProps
);
71 propsBoxLayout
->addWidget(m_globalProps
);
73 // create 'File Previews' box
74 QGroupBox
* previewBox
= new QGroupBox(i18nc("@title:group", "File Previews"), this);
76 KHBox
* vBox
= new KHBox(previewBox
);
77 vBox
->setSpacing(spacing
);
79 new QLabel(i18nc("@label:slider", "Maximum file size:"), vBox
);
80 m_maxPreviewSize
= new QSlider(Qt::Horizontal
, vBox
);
82 m_spinBox
= new QSpinBox(vBox
);
84 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
85 m_spinBox
, SLOT(setValue(int)));
86 connect(m_spinBox
, SIGNAL(valueChanged(int)),
87 m_maxPreviewSize
, SLOT(setValue(int)));
89 connect(m_maxPreviewSize
, SIGNAL(valueChanged(int)),
90 this, SIGNAL(changed()));
91 connect(m_spinBox
, SIGNAL(valueChanged(int)),
92 this, SIGNAL(changed()));
94 m_useFileThumbnails
= new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), previewBox
);
95 connect(m_useFileThumbnails
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
97 QVBoxLayout
* previewBoxLayout
= new QVBoxLayout(previewBox
);
98 previewBoxLayout
->addWidget(vBox
);
99 previewBoxLayout
->addWidget(m_useFileThumbnails
);
101 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
102 connect(m_showSelectionToggle
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
104 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
105 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
107 // Add a dummy widget with no restriction regarding
108 // a vertical resizing. This assures that the dialog layout
109 // is not stretched vertically.
116 GeneralViewSettingsPage::~GeneralViewSettingsPage()
120 void GeneralViewSettingsPage::applySettings()
122 ViewProperties
props(m_url
); // read current view properties
124 const bool useGlobalProps
= m_globalProps
->isChecked();
126 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
127 settings
->setGlobalViewProps(useGlobalProps
);
129 if (useGlobalProps
) {
130 // Remember the global view properties by applying the current view properties.
131 // It is important that GeneralSettings::globalViewProps() is set before
132 // the class ViewProperties is used, as ViewProperties uses this setting
133 // to find the destination folder for storing the view properties.
134 ViewProperties
globalProps(m_url
);
135 globalProps
.setDirProperties(props
);
138 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
139 const int byteCount
= m_maxPreviewSize
->value() * 1024 * 1024; // value() returns size in MB
140 globalConfig
.writeEntry("MaximumSize",
142 KConfigBase::Normal
| KConfigBase::Global
);
143 globalConfig
.writeEntry("UseFileThumbnails",
144 m_useFileThumbnails
->isChecked(),
145 KConfigBase::Normal
| KConfigBase::Global
);
148 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
149 settings
->setShowToolTips(m_showToolTips
->isChecked());
152 void GeneralViewSettingsPage::restoreDefaults()
154 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
155 settings
->setDefaults();
159 void GeneralViewSettingsPage::loadSettings()
161 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
162 if (settings
->globalViewProps()) {
163 m_globalProps
->setChecked(true);
165 m_localProps
->setChecked(true);
168 const int min
= 1; // MB
169 const int max
= 100; // MB
170 m_maxPreviewSize
->setRange(min
, max
);
171 m_maxPreviewSize
->setPageStep(10);
172 m_maxPreviewSize
->setSingleStep(1);
173 m_maxPreviewSize
->setTickPosition(QSlider::TicksBelow
);
175 KConfigGroup
globalConfig(KGlobal::config(), "PreviewSettings");
176 // TODO: The default value of 5 MB must match with the default value inside
177 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
178 // should be added for getting the default size?
179 const int maxByteSize
= globalConfig
.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */);
180 int maxMByteSize
= maxByteSize
/ (1024 * 1024);
181 if (maxMByteSize
< 1) {
183 } else if (maxMByteSize
> max
) {
187 m_spinBox
->setRange(min
, max
);
188 m_spinBox
->setSingleStep(1);
189 m_spinBox
->setSuffix(" MB");
191 m_maxPreviewSize
->setValue(maxMByteSize
);
192 m_spinBox
->setValue(m_maxPreviewSize
->value());
194 const bool useFileThumbnails
= globalConfig
.readEntry("UseFileThumbnails", true);
195 m_useFileThumbnails
->setChecked(useFileThumbnails
);
197 m_showSelectionToggle
->setChecked(settings
->showSelectionToggle());
198 m_showToolTips
->setChecked(settings
->showToolTips());
201 #include "generalviewsettingspage.moc"