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"
30 #include <QHBoxLayout>
32 #include <QRadioButton>
33 #include <QVBoxLayout>
35 #include <views/viewproperties.h>
37 const bool CONFIRM_TRASH
= false;
38 const bool CONFIRM_DELETE
= true;
40 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl
& url
, QWidget
* parent
) :
41 SettingsPageBase(parent
),
45 m_confirmMoveToTrash(0),
49 m_showSelectionToggle(0),
52 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
54 // 'View Properties' box
55 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), this);
56 propsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
58 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
60 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
62 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
63 propsBoxLayout
->addWidget(m_localProps
);
64 propsBoxLayout
->addWidget(m_globalProps
);
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
);
76 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
77 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
78 confirmBoxLayout
->addWidget(m_confirmDelete
);
79 confirmBoxLayout
->addWidget(m_confirmClosingMultipleTabs
);
82 m_renameInline
= new QCheckBox(i18nc("@option:check", "Rename inline"), this);
85 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
87 // 'Show selection marker'
88 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
90 // 'Natural sorting of items'
91 m_naturalSorting
= new QCheckBox(i18nc("option:check", "Natural sorting of items"), this);
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();
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()));
114 BehaviorSettingsPage::~BehaviorSettingsPage()
118 void BehaviorSettingsPage::applySettings()
120 ViewProperties
props(m_url
); // read current view properties
122 const bool useGlobalProps
= m_globalProps
->isChecked();
124 GeneralSettings
* settings
= GeneralSettings::self();
125 settings
->setGlobalViewProps(useGlobalProps
);
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
);
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();
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();
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
);
156 void BehaviorSettingsPage::restoreDefaults()
158 GeneralSettings
* settings
= GeneralSettings::self();
159 settings
->useDefaults(true);
161 settings
->useDefaults(false);
162 m_confirmMoveToTrash
->setChecked(CONFIRM_TRASH
);
163 m_confirmDelete
->setChecked(CONFIRM_DELETE
);
166 void BehaviorSettingsPage::loadSettings()
168 if (GeneralSettings::globalViewProps()) {
169 m_globalProps
->setChecked(true);
171 m_localProps
->setChecked(true);
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
));
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());
186 #include "behaviorsettingspage.moc"