]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/behaviorsettingspage.cpp
Sourcecode hierarchy cleanup: Use subfolders inside the "settings" folder
[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 #include <settings/filemetadataconfigurationdialog.h>
25 #include <settings/dolphinsettings.h>
26 #include <viewproperties.h>
27
28 #include <kdialog.h>
29 #include <klocale.h>
30
31 #include <QCheckBox>
32 #include <QGroupBox>
33 #include <QHBoxLayout>
34 #include <QLabel>
35 #include <QRadioButton>
36 #include <QVBoxLayout>
37
38 const bool CONFIRM_TRASH = false;
39 const bool CONFIRM_DELETE = true;
40
41 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl& url, QWidget* parent) :
42 SettingsPageBase(parent),
43 m_url(url),
44 m_localProps(0),
45 m_globalProps(0),
46 m_confirmMoveToTrash(0),
47 m_confirmDelete(0),
48 m_renameInline(0),
49 m_showToolTips(0),
50 m_configureToolTips(0),
51 m_showSelectionToggle(0),
52 m_naturalSorting(0)
53 {
54 QVBoxLayout* topLayout = new QVBoxLayout(this);
55
56 // 'View Properties' box
57 QGroupBox* propsBox = new QGroupBox(i18nc("@title:group", "View Properties"), this);
58 propsBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
59
60 m_localProps = new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox);
61 connect(m_localProps, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
62
63 m_globalProps = new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox);
64 connect(m_globalProps, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
65
66 QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox);
67 propsBoxLayout->addWidget(m_localProps);
68 propsBoxLayout->addWidget(m_globalProps);
69
70 // 'Ask Confirmation For' box
71 QGroupBox* confirmBox = new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), this);
72 confirmBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
73 m_confirmMoveToTrash = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
74 "Moving files or folders to trash"), confirmBox);
75 connect(m_confirmMoveToTrash, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
76 m_confirmDelete = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
77 "Deleting files or folders"), confirmBox);
78 connect(m_confirmDelete, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
79 m_confirmClosingMultipleTabs = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
80 "Closing windows with multiple tabs"), confirmBox);
81 connect(m_confirmClosingMultipleTabs, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
82
83 QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox);
84 confirmBoxLayout->addWidget(m_confirmMoveToTrash);
85 confirmBoxLayout->addWidget(m_confirmDelete);
86 confirmBoxLayout->addWidget(m_confirmClosingMultipleTabs);
87
88 // 'Rename inline'
89 m_renameInline = new QCheckBox(i18nc("@option:check", "Rename inline"), this);
90 connect(m_renameInline, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
91
92 // 'Show tooltips'
93 QWidget* toolTipContainer = new QWidget(this);
94 QHBoxLayout* toolTipsLayout = new QHBoxLayout(toolTipContainer);
95 toolTipsLayout->setMargin(0);
96 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), toolTipContainer);
97 connect(m_showToolTips, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
98 connect(m_showToolTips, SIGNAL(toggled(bool)), this, SLOT(updateConfigureButton()));
99
100 m_configureToolTips = new QLabel(toolTipContainer);
101 connect(m_configureToolTips, SIGNAL(linkActivated(const QString&)),
102 this, SLOT(configureToolTips()));
103
104 toolTipsLayout->addWidget(m_showToolTips);
105 toolTipsLayout->addWidget(m_configureToolTips, 1, Qt::AlignLeft);
106
107 // 'Show selection marker'
108 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
109 connect(m_showSelectionToggle, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
110
111 // 'Natural sorting of items'
112 m_naturalSorting = new QCheckBox(i18nc("option:check", "Natural sorting of items"), this);
113 connect(m_naturalSorting, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
114
115 topLayout->addWidget(propsBox);
116 topLayout->addWidget(confirmBox);
117 topLayout->addWidget(m_renameInline);
118 topLayout->addWidget(toolTipContainer);
119 topLayout->addWidget(m_showSelectionToggle);
120 topLayout->addWidget(m_naturalSorting);
121 topLayout->addStretch();
122
123 loadSettings();
124 }
125
126 BehaviorSettingsPage::~BehaviorSettingsPage()
127 {
128 }
129
130 void BehaviorSettingsPage::applySettings()
131 {
132 ViewProperties props(m_url); // read current view properties
133
134 const bool useGlobalProps = m_globalProps->isChecked();
135
136 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
137 settings->setGlobalViewProps(useGlobalProps);
138
139 if (useGlobalProps) {
140 // Remember the global view properties by applying the current view properties.
141 // It is important that GeneralSettings::globalViewProps() is set before
142 // the class ViewProperties is used, as ViewProperties uses this setting
143 // to find the destination folder for storing the view properties.
144 ViewProperties globalProps(m_url);
145 globalProps.setDirProperties(props);
146 }
147
148 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
149 KConfigGroup confirmationGroup(kioConfig, "Confirmations");
150 confirmationGroup.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked());
151 confirmationGroup.writeEntry("ConfirmDelete", m_confirmDelete->isChecked());
152 confirmationGroup.sync();
153
154 settings->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs->isChecked());
155 settings->setRenameInline(m_renameInline->isChecked());
156 settings->setShowToolTips(m_showToolTips->isChecked());
157 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
158 settings->writeConfig();
159
160 const bool naturalSorting = m_naturalSorting->isChecked();
161 if (KGlobalSettings::naturalSorting() != naturalSorting) {
162 KConfigGroup group(KGlobal::config(), "KDE");
163 group.writeEntry("NaturalSorting", naturalSorting, KConfig::Persistent | KConfig::Global);
164 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged);
165 }
166 }
167
168 void BehaviorSettingsPage::restoreDefaults()
169 {
170 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
171 settings->useDefaults(true);
172 loadSettings();
173 settings->useDefaults(false);
174 m_confirmMoveToTrash->setChecked(CONFIRM_TRASH);
175 m_confirmDelete->setChecked(CONFIRM_DELETE);
176 }
177
178 void BehaviorSettingsPage::updateConfigureButton()
179 {
180 if (m_showToolTips->isChecked()) {
181 m_configureToolTips->setText("<a href=\"configure\">" +
182 i18nc("@action:button", "Configure...") +
183 "</a>");
184 } else {
185 m_configureToolTips->setText(QString());
186 }
187 }
188
189 void BehaviorSettingsPage::configureToolTips()
190 {
191 FileMetaDataConfigurationDialog* dialog = new FileMetaDataConfigurationDialog();
192 dialog->setDescription(i18nc("@label::textbox",
193 "Select which data should be shown in the tooltip."));
194 dialog->setAttribute(Qt::WA_DeleteOnClose);
195 dialog->show();
196 dialog->raise();
197 dialog->activateWindow();
198 }
199
200 void BehaviorSettingsPage::loadSettings()
201 {
202 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
203 if (settings->globalViewProps()) {
204 m_globalProps->setChecked(true);
205 } else {
206 m_localProps->setChecked(true);
207 }
208
209 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals);
210 const KConfigGroup confirmationGroup(kioConfig, "Confirmations");
211 m_confirmMoveToTrash->setChecked(confirmationGroup.readEntry("ConfirmTrash", CONFIRM_TRASH));
212 m_confirmDelete->setChecked(confirmationGroup.readEntry("ConfirmDelete", CONFIRM_DELETE));
213
214 m_confirmClosingMultipleTabs->setChecked(settings->confirmClosingMultipleTabs());
215 m_renameInline->setChecked(settings->renameInline());
216 m_showToolTips->setChecked(settings->showToolTips());
217 m_showSelectionToggle->setChecked(settings->showSelectionToggle());
218 m_naturalSorting->setChecked(KGlobalSettings::naturalSorting());
219
220 updateConfigureButton();
221 }
222
223 #include "behaviorsettingspage.moc"