]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/behaviorsettingspage.cpp
Layout improvements for settings
[dolphin.git] / src / settings / general / behaviorsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20
21 #include "behaviorsettingspage.h"
22
23 #include "dolphin_generalsettings.h"
24
25 #include <KComboBox>
26 #include <KDialog>
27 #include <KLocale>
28
29 #include <QCheckBox>
30 #include <QGroupBox>
31 #include <QHBoxLayout>
32 #include <QLabel>
33 #include <QRadioButton>
34 #include <QVBoxLayout>
35
36 #include <views/viewproperties.h>
37
38 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl& url, QWidget* parent) :
39 SettingsPageBase(parent),
40 m_url(url),
41 m_viewProps(0),
42 m_showToolTips(0),
43 m_showSelectionToggle(0),
44 m_naturalSorting(0)
45 {
46 QVBoxLayout* topLayout = new QVBoxLayout(this);
47
48 // View properties
49 QLabel* viewPropsLabel = new QLabel(i18nc("@label", "View properties:"), this);
50
51 m_viewProps = new KComboBox(this);
52 const bool useGlobalProps = true;
53 m_viewProps->addItem(i18nc("@option:radio", "Remember view properties for each folder"), !useGlobalProps);
54 m_viewProps->addItem(i18nc("@option:radio", "Use common view properties for all folders"), useGlobalProps);
55
56 QHBoxLayout* viewPropsLayout = new QHBoxLayout(this);
57 viewPropsLayout->addWidget(viewPropsLabel, 0, Qt::AlignRight);
58 viewPropsLayout->addWidget(m_viewProps);
59
60 // 'Show tooltips'
61 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
62
63 // 'Show selection marker'
64 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
65
66 // 'Natural sorting of items'
67 m_naturalSorting = new QCheckBox(i18nc("option:check", "Natural sorting of items"), this);
68
69 topLayout->addSpacing(KDialog::spacingHint());
70 topLayout->addLayout(viewPropsLayout);
71 topLayout->addSpacing(KDialog::spacingHint());
72 topLayout->addWidget(m_showToolTips);
73 topLayout->addWidget(m_showSelectionToggle);
74 topLayout->addWidget(m_naturalSorting);
75 topLayout->addStretch();
76
77 loadSettings();
78
79 connect(m_viewProps, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
80 connect(m_showToolTips, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
81 connect(m_showSelectionToggle, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
82 connect(m_naturalSorting, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
83 }
84
85 BehaviorSettingsPage::~BehaviorSettingsPage()
86 {
87 }
88
89 void BehaviorSettingsPage::applySettings()
90 {
91 GeneralSettings* settings = GeneralSettings::self();
92 ViewProperties props(m_url); // read current view properties
93
94 const int index = m_viewProps->currentIndex();
95 const bool useGlobalProps = m_viewProps->itemData(index).toBool();
96 settings->setGlobalViewProps(useGlobalProps);
97
98 settings->setShowToolTips(m_showToolTips->isChecked());
99 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
100 settings->writeConfig();
101
102 if (useGlobalProps) {
103 // Remember the global view properties by applying the current view properties.
104 // It is important that GeneralSettings::globalViewProps() is set before
105 // the class ViewProperties is used, as ViewProperties uses this setting
106 // to find the destination folder for storing the view properties.
107 ViewProperties globalProps(m_url);
108 globalProps.setDirProperties(props);
109 }
110
111 const bool naturalSorting = m_naturalSorting->isChecked();
112 if (KGlobalSettings::naturalSorting() != naturalSorting) {
113 KConfigGroup group(KGlobal::config(), "KDE");
114 group.writeEntry("NaturalSorting", naturalSorting, KConfig::Persistent | KConfig::Global);
115 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged);
116 }
117 }
118
119 void BehaviorSettingsPage::restoreDefaults()
120 {
121 GeneralSettings* settings = GeneralSettings::self();
122 settings->useDefaults(true);
123 loadSettings();
124 settings->useDefaults(false);
125 }
126
127 void BehaviorSettingsPage::loadSettings()
128 {
129 const int index = (m_viewProps->itemData(0).toBool() == GeneralSettings::globalViewProps()) ? 0 : 1;
130 m_viewProps->setCurrentIndex(index);
131
132 m_showToolTips->setChecked(GeneralSettings::showToolTips());
133 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle());
134 m_naturalSorting->setChecked(KGlobalSettings::naturalSorting());
135 }
136
137 #include "behaviorsettingspage.moc"