1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
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. *
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. *
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 ***************************************************************************/
21 #include "behaviorsettingspage.h"
23 #include "dolphin_generalsettings.h"
24 #include <settings/dolphinsettings.h>
31 #include <QHBoxLayout>
33 #include <QRadioButton>
34 #include <QVBoxLayout>
36 #include <views/viewproperties.h>
38 const bool CONFIRM_TRASH
= false;
39 const bool CONFIRM_DELETE
= true;
41 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl
& url
, QWidget
* parent
) :
42 SettingsPageBase(parent
),
46 m_confirmMoveToTrash(0),
50 m_showSelectionToggle(0),
53 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
55 // 'View Properties' box
56 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), this);
57 propsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
59 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
61 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
63 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
64 propsBoxLayout
->addWidget(m_localProps
);
65 propsBoxLayout
->addWidget(m_globalProps
);
67 // 'Ask Confirmation For' box
68 QGroupBox
* confirmBox
= new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), this);
69 confirmBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
70 m_confirmMoveToTrash
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
71 "Moving files or folders to trash"), confirmBox
);
72 m_confirmDelete
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
73 "Deleting files or folders"), confirmBox
);
74 m_confirmClosingMultipleTabs
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
75 "Closing windows with multiple tabs"), confirmBox
);
77 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
78 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
79 confirmBoxLayout
->addWidget(m_confirmDelete
);
80 confirmBoxLayout
->addWidget(m_confirmClosingMultipleTabs
);
83 m_renameInline
= new QCheckBox(i18nc("@option:check", "Rename inline"), this);
86 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
88 // 'Show selection marker'
89 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
91 // 'Natural sorting of items'
92 m_naturalSorting
= new QCheckBox(i18nc("option:check", "Natural sorting of items"), this);
94 topLayout
->addWidget(propsBox
);
95 topLayout
->addWidget(confirmBox
);
96 topLayout
->addWidget(m_renameInline
);
97 topLayout
->addWidget(m_showToolTips
);
98 topLayout
->addWidget(m_showSelectionToggle
);
99 topLayout
->addWidget(m_naturalSorting
);
100 topLayout
->addStretch();
104 connect(m_localProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
105 connect(m_globalProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
106 connect(m_confirmMoveToTrash
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
107 connect(m_confirmDelete
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
108 connect(m_confirmClosingMultipleTabs
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
109 connect(m_renameInline
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
110 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
111 connect(m_showSelectionToggle
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
112 connect(m_naturalSorting
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
115 BehaviorSettingsPage::~BehaviorSettingsPage()
119 void BehaviorSettingsPage::applySettings()
121 ViewProperties
props(m_url
); // read current view properties
123 const bool useGlobalProps
= m_globalProps
->isChecked();
125 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
126 settings
->setGlobalViewProps(useGlobalProps
);
128 if (useGlobalProps
) {
129 // Remember the global view properties by applying the current view properties.
130 // It is important that GeneralSettings::globalViewProps() is set before
131 // the class ViewProperties is used, as ViewProperties uses this setting
132 // to find the destination folder for storing the view properties.
133 ViewProperties
globalProps(m_url
);
134 globalProps
.setDirProperties(props
);
137 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::NoGlobals
);
138 KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
139 confirmationGroup
.writeEntry("ConfirmTrash", m_confirmMoveToTrash
->isChecked());
140 confirmationGroup
.writeEntry("ConfirmDelete", m_confirmDelete
->isChecked());
141 confirmationGroup
.sync();
143 settings
->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs
->isChecked());
144 settings
->setRenameInline(m_renameInline
->isChecked());
145 settings
->setShowToolTips(m_showToolTips
->isChecked());
146 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
147 settings
->writeConfig();
149 const bool naturalSorting
= m_naturalSorting
->isChecked();
150 if (KGlobalSettings::naturalSorting() != naturalSorting
) {
151 KConfigGroup
group(KGlobal::config(), "KDE");
152 group
.writeEntry("NaturalSorting", naturalSorting
, KConfig::Persistent
| KConfig::Global
);
153 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged
);
157 void BehaviorSettingsPage::restoreDefaults()
159 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
160 settings
->useDefaults(true);
162 settings
->useDefaults(false);
163 m_confirmMoveToTrash
->setChecked(CONFIRM_TRASH
);
164 m_confirmDelete
->setChecked(CONFIRM_DELETE
);
167 void BehaviorSettingsPage::loadSettings()
169 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
170 if (settings
->globalViewProps()) {
171 m_globalProps
->setChecked(true);
173 m_localProps
->setChecked(true);
176 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals
);
177 const KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
178 m_confirmMoveToTrash
->setChecked(confirmationGroup
.readEntry("ConfirmTrash", CONFIRM_TRASH
));
179 m_confirmDelete
->setChecked(confirmationGroup
.readEntry("ConfirmDelete", CONFIRM_DELETE
));
181 m_confirmClosingMultipleTabs
->setChecked(settings
->confirmClosingMultipleTabs());
182 m_renameInline
->setChecked(settings
->renameInline());
183 m_showToolTips
->setChecked(settings
->showToolTips());
184 m_showSelectionToggle
->setChecked(settings
->showSelectionToggle());
185 m_naturalSorting
->setChecked(KGlobalSettings::naturalSorting());
188 #include "behaviorsettingspage.moc"