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),
48 m_showSelectionToggle(0),
51 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
53 // 'View Properties' box
54 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), this);
55 propsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
57 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
59 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
61 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
62 propsBoxLayout
->addWidget(m_localProps
);
63 propsBoxLayout
->addWidget(m_globalProps
);
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
);
75 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
76 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
77 confirmBoxLayout
->addWidget(m_confirmDelete
);
78 confirmBoxLayout
->addWidget(m_confirmClosingMultipleTabs
);
81 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), this);
83 // 'Show selection marker'
84 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), this);
86 // 'Natural sorting of items'
87 m_naturalSorting
= new QCheckBox(i18nc("option:check", "Natural sorting of items"), this);
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();
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()));
108 BehaviorSettingsPage::~BehaviorSettingsPage()
112 void BehaviorSettingsPage::applySettings()
114 ViewProperties
props(m_url
); // read current view properties
116 const bool useGlobalProps
= m_globalProps
->isChecked();
118 GeneralSettings
* settings
= GeneralSettings::self();
119 settings
->setGlobalViewProps(useGlobalProps
);
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
);
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();
136 settings
->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs
->isChecked());
137 settings
->setShowToolTips(m_showToolTips
->isChecked());
138 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
139 settings
->writeConfig();
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
);
149 void BehaviorSettingsPage::restoreDefaults()
151 GeneralSettings
* settings
= GeneralSettings::self();
152 settings
->useDefaults(true);
154 settings
->useDefaults(false);
155 m_confirmMoveToTrash
->setChecked(CONFIRM_TRASH
);
156 m_confirmDelete
->setChecked(CONFIRM_DELETE
);
159 void BehaviorSettingsPage::loadSettings()
161 if (GeneralSettings::globalViewProps()) {
162 m_globalProps
->setChecked(true);
164 m_localProps
->setChecked(true);
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
));
172 m_confirmClosingMultipleTabs
->setChecked(GeneralSettings::confirmClosingMultipleTabs());
173 m_showToolTips
->setChecked(GeneralSettings::showToolTips());
174 m_showSelectionToggle
->setChecked(GeneralSettings::showSelectionToggle());
175 m_naturalSorting
->setChecked(KGlobalSettings::naturalSorting());
178 #include "behaviorsettingspage.moc"