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 "dolphinsettings.h"
24 #include "dolphin_generalsettings.h"
26 #include <viewproperties.h>
35 #include <QRadioButton>
36 #include <QVBoxLayout>
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 const int spacing
= KDialog::spacingHint();
55 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
56 KVBox
* vBox
= new KVBox(this);
57 vBox
->setSpacing(spacing
);
59 // 'View Properties' box
60 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), vBox
);
61 propsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
63 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
64 connect(m_localProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
66 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
67 connect(m_globalProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
69 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
70 propsBoxLayout
->addWidget(m_localProps
);
71 propsBoxLayout
->addWidget(m_globalProps
);
73 // 'Ask Confirmation For' box
74 QGroupBox
* confirmBox
= new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox
);
75 confirmBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
76 m_confirmMoveToTrash
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
77 "Moving files or folders to trash"), confirmBox
);
78 connect(m_confirmMoveToTrash
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
79 m_confirmDelete
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
80 "Deleting files or folders"), confirmBox
);
81 connect(m_confirmDelete
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
82 m_confirmClosingMultipleTabs
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
83 "Closing windows with multiple tabs"), confirmBox
);
84 connect(m_confirmClosingMultipleTabs
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
86 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
87 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
88 confirmBoxLayout
->addWidget(m_confirmDelete
);
89 confirmBoxLayout
->addWidget(m_confirmClosingMultipleTabs
);
91 m_renameInline
= new QCheckBox(i18nc("@option:check", "Rename inline"), vBox
);
92 connect(m_renameInline
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
94 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), vBox
);
95 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
97 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), vBox
);
98 connect(m_showSelectionToggle
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
100 m_naturalSorting
= new QCheckBox(i18nc("option:check", "Natural sorting of items"), vBox
);
101 connect(m_naturalSorting
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
103 // Add a dummy widget with no restriction regarding
104 // a vertical resizing. This assures that the dialog layout
105 // is not stretched vertically.
108 topLayout
->addWidget(vBox
);
113 BehaviorSettingsPage::~BehaviorSettingsPage()
117 void BehaviorSettingsPage::applySettings()
119 ViewProperties
props(m_url
); // read current view properties
121 const bool useGlobalProps
= m_globalProps
->isChecked();
123 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
124 settings
->setGlobalViewProps(useGlobalProps
);
126 if (useGlobalProps
) {
127 // Remember the global view properties by applying the current view properties.
128 // It is important that GeneralSettings::globalViewProps() is set before
129 // the class ViewProperties is used, as ViewProperties uses this setting
130 // to find the destination folder for storing the view properties.
131 ViewProperties
globalProps(m_url
);
132 globalProps
.setDirProperties(props
);
135 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::NoGlobals
);
136 KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
137 confirmationGroup
.writeEntry("ConfirmTrash", m_confirmMoveToTrash
->isChecked());
138 confirmationGroup
.writeEntry("ConfirmDelete", m_confirmDelete
->isChecked());
139 confirmationGroup
.sync();
141 settings
->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs
->isChecked());
142 settings
->setRenameInline(m_renameInline
->isChecked());
143 settings
->setShowToolTips(m_showToolTips
->isChecked());
144 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
145 settings
->writeConfig();
147 const bool naturalSorting
= m_naturalSorting
->isChecked();
148 if (KGlobalSettings::naturalSorting() != naturalSorting
) {
149 KConfigGroup
group(KGlobal::config(), "KDE");
150 group
.writeEntry("NaturalSorting", naturalSorting
, KConfig::Persistent
| KConfig::Global
);
151 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged
);
155 void BehaviorSettingsPage::restoreDefaults()
157 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
158 settings
->useDefaults(true);
160 settings
->useDefaults(false);
161 m_confirmMoveToTrash
->setChecked(CONFIRM_TRASH
);
162 m_confirmDelete
->setChecked(CONFIRM_DELETE
);
165 void BehaviorSettingsPage::loadSettings()
167 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
168 if (settings
->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(settings
->confirmClosingMultipleTabs());
180 m_renameInline
->setChecked(settings
->renameInline());
181 m_showToolTips
->setChecked(settings
->showToolTips());
182 m_showSelectionToggle
->setChecked(settings
->showSelectionToggle());
183 m_naturalSorting
->setChecked(KGlobalSettings::naturalSorting());
186 #include "behaviorsettingspage.moc"