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"
27 // #include "nepomuk/metadataconfigurationdialog.h"
29 #include <viewproperties.h>
37 #include <QHBoxLayout>
39 #include <QRadioButton>
40 #include <QVBoxLayout>
42 const bool CONFIRM_TRASH
= false;
43 const bool CONFIRM_DELETE
= true;
45 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl
& url
, QWidget
* parent
) :
46 SettingsPageBase(parent
),
50 m_confirmMoveToTrash(0),
54 m_configureToolTips(0),
55 m_showSelectionToggle(0),
58 const int spacing
= KDialog::spacingHint();
60 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
61 KVBox
* vBox
= new KVBox(this);
62 vBox
->setSpacing(spacing
);
64 // 'View Properties' box
65 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), vBox
);
66 propsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
68 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
69 connect(m_localProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
71 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
72 connect(m_globalProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
74 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
75 propsBoxLayout
->addWidget(m_localProps
);
76 propsBoxLayout
->addWidget(m_globalProps
);
78 // 'Ask Confirmation For' box
79 QGroupBox
* confirmBox
= new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox
);
80 confirmBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
81 m_confirmMoveToTrash
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
82 "Moving files or folders to trash"), confirmBox
);
83 connect(m_confirmMoveToTrash
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
84 m_confirmDelete
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
85 "Deleting files or folders"), confirmBox
);
86 connect(m_confirmDelete
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
87 m_confirmClosingMultipleTabs
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
88 "Closing windows with multiple tabs"), confirmBox
);
89 connect(m_confirmClosingMultipleTabs
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
91 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
92 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
93 confirmBoxLayout
->addWidget(m_confirmDelete
);
94 confirmBoxLayout
->addWidget(m_confirmClosingMultipleTabs
);
97 m_renameInline
= new QCheckBox(i18nc("@option:check", "Rename inline"), vBox
);
98 connect(m_renameInline
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
101 QWidget
* toolTipContainer
= new QWidget(vBox
);
102 QHBoxLayout
* toolTipsLayout
= new QHBoxLayout(toolTipContainer
);
103 toolTipsLayout
->setMargin(0);
104 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), toolTipContainer
);
105 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
106 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SLOT(updateConfigureButton()));
108 m_configureToolTips
= new QLabel(toolTipContainer
);
109 connect(m_configureToolTips
, SIGNAL(linkActivated(const QString
&)),
110 this, SLOT(configureToolTips(const QString
&)));
112 toolTipsLayout
->addWidget(m_showToolTips
);
113 toolTipsLayout
->addWidget(m_configureToolTips
, 1, Qt::AlignLeft
);
115 // 'Show selection marker'
116 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), vBox
);
117 connect(m_showSelectionToggle
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
119 // 'Natural sorting of items'
120 m_naturalSorting
= new QCheckBox(i18nc("option:check", "Natural sorting of items"), vBox
);
121 connect(m_naturalSorting
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
123 // Add a dummy widget with no restriction regarding
124 // a vertical resizing. This assures that the dialog layout
125 // is not stretched vertically.
128 topLayout
->addWidget(vBox
);
133 BehaviorSettingsPage::~BehaviorSettingsPage()
137 void BehaviorSettingsPage::applySettings()
139 ViewProperties
props(m_url
); // read current view properties
141 const bool useGlobalProps
= m_globalProps
->isChecked();
143 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
144 settings
->setGlobalViewProps(useGlobalProps
);
146 if (useGlobalProps
) {
147 // Remember the global view properties by applying the current view properties.
148 // It is important that GeneralSettings::globalViewProps() is set before
149 // the class ViewProperties is used, as ViewProperties uses this setting
150 // to find the destination folder for storing the view properties.
151 ViewProperties
globalProps(m_url
);
152 globalProps
.setDirProperties(props
);
155 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::NoGlobals
);
156 KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
157 confirmationGroup
.writeEntry("ConfirmTrash", m_confirmMoveToTrash
->isChecked());
158 confirmationGroup
.writeEntry("ConfirmDelete", m_confirmDelete
->isChecked());
159 confirmationGroup
.sync();
161 settings
->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs
->isChecked());
162 settings
->setRenameInline(m_renameInline
->isChecked());
163 settings
->setShowToolTips(m_showToolTips
->isChecked());
164 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
165 settings
->writeConfig();
167 const bool naturalSorting
= m_naturalSorting
->isChecked();
168 if (KGlobalSettings::naturalSorting() != naturalSorting
) {
169 KConfigGroup
group(KGlobal::config(), "KDE");
170 group
.writeEntry("NaturalSorting", naturalSorting
, KConfig::Persistent
| KConfig::Global
);
171 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged
);
175 void BehaviorSettingsPage::restoreDefaults()
177 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
178 settings
->useDefaults(true);
180 settings
->useDefaults(false);
181 m_confirmMoveToTrash
->setChecked(CONFIRM_TRASH
);
182 m_confirmDelete
->setChecked(CONFIRM_DELETE
);
185 void BehaviorSettingsPage::updateConfigureButton()
187 if (m_showToolTips
->isChecked()) {
188 m_configureToolTips
->setText("<a href=\"configure\">" +
189 i18nc("@action:button", "Configure...") +
192 m_configureToolTips
->setText(QString());
196 void BehaviorSettingsPage::configureToolTips()
199 //MetaDataConfigurationDialog dialog(KUrl(), this, Qt::Dialog);
203 void BehaviorSettingsPage::loadSettings()
205 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
206 if (settings
->globalViewProps()) {
207 m_globalProps
->setChecked(true);
209 m_localProps
->setChecked(true);
212 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals
);
213 const KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
214 m_confirmMoveToTrash
->setChecked(confirmationGroup
.readEntry("ConfirmTrash", CONFIRM_TRASH
));
215 m_confirmDelete
->setChecked(confirmationGroup
.readEntry("ConfirmDelete", CONFIRM_DELETE
));
217 m_confirmClosingMultipleTabs
->setChecked(settings
->confirmClosingMultipleTabs());
218 m_renameInline
->setChecked(settings
->renameInline());
219 m_showToolTips
->setChecked(settings
->showToolTips());
220 m_showSelectionToggle
->setChecked(settings
->showSelectionToggle());
221 m_naturalSorting
->setChecked(KGlobalSettings::naturalSorting());
223 updateConfigureButton();
226 #include "behaviorsettingspage.moc"