]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/behaviorsettingspage.cpp
Fix includes
[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 <KLocalizedString>
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_localViewProps(0),
42 m_globalViewProps(0),
43 m_showToolTips(0),
44 m_showSelectionToggle(0),
45 m_naturalSorting(0),
46 m_renameInline(0)
47 {
48 QVBoxLayout* topLayout = new QVBoxLayout(this);
49
50 // View properties
51 QGroupBox* viewPropsBox = new QGroupBox(i18nc("@title:group", "View"), this);
52 viewPropsBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
53
54 m_localViewProps = new QRadioButton(i18nc("@option:radio", "Remember properties for each folder"), viewPropsBox);
55 m_globalViewProps = new QRadioButton(i18nc("@option:radio", "Use common properties for all folders"), viewPropsBox);
56
57 QVBoxLayout* viewPropsLayout = new QVBoxLayout(viewPropsBox);
58 viewPropsLayout->addWidget(m_localViewProps);
59 viewPropsLayout->addWidget(m_globalViewProps);
60
61 // 'Show tooltips'
62 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
63
64 // 'Show selection marker'
65 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
66
67 // 'Natural sorting of items'
68 m_naturalSorting = new QCheckBox(i18nc("option:check", "Natural sorting of items"), this);
69
70 // 'Inline renaming of items'
71 m_renameInline = new QCheckBox(i18nc("option:check", "Rename inline"), this);
72
73 topLayout->addWidget(viewPropsBox);
74 topLayout->addWidget(m_showToolTips);
75 topLayout->addWidget(m_showSelectionToggle);
76 topLayout->addWidget(m_naturalSorting);
77 topLayout->addWidget(m_renameInline);
78 topLayout->addStretch();
79
80 loadSettings();
81
82 connect(m_localViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
83 connect(m_globalViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
84 connect(m_showToolTips, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
85 connect(m_showSelectionToggle, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
86 connect(m_naturalSorting, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
87 connect(m_renameInline, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
88 }
89
90 BehaviorSettingsPage::~BehaviorSettingsPage()
91 {
92 }
93
94 void BehaviorSettingsPage::applySettings()
95 {
96 GeneralSettings* settings = GeneralSettings::self();
97 ViewProperties props(m_url); // read current view properties
98
99 const bool useGlobalViewProps = m_globalViewProps->isChecked();
100 settings->setGlobalViewProps(useGlobalViewProps);
101
102 settings->setShowToolTips(m_showToolTips->isChecked());
103 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
104 settings->setRenameInline(m_renameInline->isChecked());
105 settings->writeConfig();
106
107 if (useGlobalViewProps) {
108 // Remember the global view properties by applying the current view properties.
109 // It is important that GeneralSettings::globalViewProps() is set before
110 // the class ViewProperties is used, as ViewProperties uses this setting
111 // to find the destination folder for storing the view properties.
112 ViewProperties globalProps(m_url);
113 globalProps.setDirProperties(props);
114 }
115
116 const bool naturalSorting = m_naturalSorting->isChecked();
117 if (KGlobalSettings::naturalSorting() != naturalSorting) {
118 KConfigGroup group(KSharedConfig::openConfig(), "KDE");
119 group.writeEntry("NaturalSorting", naturalSorting, KConfig::Persistent | KConfig::Global);
120 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged);
121 }
122 }
123
124 void BehaviorSettingsPage::restoreDefaults()
125 {
126 GeneralSettings* settings = GeneralSettings::self();
127 settings->useDefaults(true);
128 loadSettings();
129 settings->useDefaults(false);
130 }
131
132 void BehaviorSettingsPage::loadSettings()
133 {
134 const bool useGlobalViewProps = GeneralSettings::globalViewProps();
135 m_localViewProps->setChecked(!useGlobalViewProps);
136 m_globalViewProps->setChecked(useGlobalViewProps);
137
138 m_showToolTips->setChecked(GeneralSettings::showToolTips());
139 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle());
140 m_naturalSorting->setChecked(KGlobalSettings::naturalSorting());
141 m_renameInline->setChecked(GeneralSettings::renameInline());
142 }
143