]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/behaviorsettingspage.cpp
Delete obsolete class DolphinSettings
[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 <KDialog>
26 #include <KLocale>
27
28 #include <QCheckBox>
29 #include <QGroupBox>
30 #include <QHBoxLayout>
31 #include <QLabel>
32 #include <QRadioButton>
33 #include <QVBoxLayout>
34
35 #include <views/viewproperties.h>
36
37 const bool CONFIRM_TRASH = false;
38 const bool CONFIRM_DELETE = true;
39
40 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl& url, QWidget* parent) :
41 SettingsPageBase(parent),
42 m_url(url),
43 m_localProps(0),
44 m_globalProps(0),
45 m_confirmMoveToTrash(0),
46 m_confirmDelete(0),
47 m_renameInline(0),
48 m_showToolTips(0),
49 m_showSelectionToggle(0),
50 m_naturalSorting(0)
51 {
52 QVBoxLayout* topLayout = new QVBoxLayout(this);
53
54 // 'View Properties' box
55 QGroupBox* propsBox = new QGroupBox(i18nc("@title:group", "View Properties"), this);
56 propsBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
57
58 m_localProps = new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox);
59
60 m_globalProps = new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox);
61
62 QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox);
63 propsBoxLayout->addWidget(m_localProps);
64 propsBoxLayout->addWidget(m_globalProps);
65
66 // 'Ask Confirmation For' box
67 QGroupBox* confirmBox = new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), this);
68 confirmBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
69 m_confirmMoveToTrash = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
70 "Moving files or folders to trash"), confirmBox);
71 m_confirmDelete = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
72 "Deleting files or folders"), confirmBox);
73 m_confirmClosingMultipleTabs = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
74 "Closing windows with multiple tabs"), confirmBox);
75
76 QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox);
77 confirmBoxLayout->addWidget(m_confirmMoveToTrash);
78 confirmBoxLayout->addWidget(m_confirmDelete);
79 confirmBoxLayout->addWidget(m_confirmClosingMultipleTabs);
80
81 // 'Rename inline'
82 m_renameInline = new QCheckBox(i18nc("@option:check", "Rename inline"), this);
83
84 // 'Show tooltips'
85 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
86
87 // 'Show selection marker'
88 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
89
90 // 'Natural sorting of items'
91 m_naturalSorting = new QCheckBox(i18nc("option:check", "Natural sorting of items"), this);
92
93 topLayout->addWidget(propsBox);
94 topLayout->addWidget(confirmBox);
95 topLayout->addWidget(m_renameInline);
96 topLayout->addWidget(m_showToolTips);
97 topLayout->addWidget(m_showSelectionToggle);
98 topLayout->addWidget(m_naturalSorting);
99 topLayout->addStretch();
100
101 loadSettings();
102
103 connect(m_localProps, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
104 connect(m_globalProps, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
105 connect(m_confirmMoveToTrash, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
106 connect(m_confirmDelete, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
107 connect(m_confirmClosingMultipleTabs, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
108 connect(m_renameInline, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
109 connect(m_showToolTips, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
110 connect(m_showSelectionToggle, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
111 connect(m_naturalSorting, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
112 }
113
114 BehaviorSettingsPage::~BehaviorSettingsPage()
115 {
116 }
117
118 void BehaviorSettingsPage::applySettings()
119 {
120 ViewProperties props(m_url); // read current view properties
121
122 const bool useGlobalProps = m_globalProps->isChecked();
123
124 GeneralSettings* settings = GeneralSettings::self();
125 settings->setGlobalViewProps(useGlobalProps);
126
127 if (useGlobalProps) {
128 // Remember the global view properties by applying the current view properties.
129 // It is important that GeneralSettings::globalViewProps() is set before
130 // the class ViewProperties is used, as ViewProperties uses this setting
131 // to find the destination folder for storing the view properties.
132 ViewProperties globalProps(m_url);
133 globalProps.setDirProperties(props);
134 }
135
136 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
137 KConfigGroup confirmationGroup(kioConfig, "Confirmations");
138 confirmationGroup.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked());
139 confirmationGroup.writeEntry("ConfirmDelete", m_confirmDelete->isChecked());
140 confirmationGroup.sync();
141
142 settings->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs->isChecked());
143 settings->setRenameInline(m_renameInline->isChecked());
144 settings->setShowToolTips(m_showToolTips->isChecked());
145 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
146 settings->writeConfig();
147
148 const bool naturalSorting = m_naturalSorting->isChecked();
149 if (KGlobalSettings::naturalSorting() != naturalSorting) {
150 KConfigGroup group(KGlobal::config(), "KDE");
151 group.writeEntry("NaturalSorting", naturalSorting, KConfig::Persistent | KConfig::Global);
152 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged);
153 }
154 }
155
156 void BehaviorSettingsPage::restoreDefaults()
157 {
158 GeneralSettings* settings = GeneralSettings::self();
159 settings->useDefaults(true);
160 loadSettings();
161 settings->useDefaults(false);
162 m_confirmMoveToTrash->setChecked(CONFIRM_TRASH);
163 m_confirmDelete->setChecked(CONFIRM_DELETE);
164 }
165
166 void BehaviorSettingsPage::loadSettings()
167 {
168 if (GeneralSettings::globalViewProps()) {
169 m_globalProps->setChecked(true);
170 } else {
171 m_localProps->setChecked(true);
172 }
173
174 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals);
175 const KConfigGroup confirmationGroup(kioConfig, "Confirmations");
176 m_confirmMoveToTrash->setChecked(confirmationGroup.readEntry("ConfirmTrash", CONFIRM_TRASH));
177 m_confirmDelete->setChecked(confirmationGroup.readEntry("ConfirmDelete", CONFIRM_DELETE));
178
179 m_confirmClosingMultipleTabs->setChecked(GeneralSettings::confirmClosingMultipleTabs());
180 m_renameInline->setChecked(GeneralSettings::renameInline());
181 m_showToolTips->setChecked(GeneralSettings::showToolTips());
182 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle());
183 m_naturalSorting->setChecked(KGlobalSettings::naturalSorting());
184 }
185
186 #include "behaviorsettingspage.moc"