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