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>
34 #include <QHBoxLayout>
36 #include <QRadioButton>
37 #include <QVBoxLayout>
39 const bool CONFIRM_TRASH
= false;
40 const bool CONFIRM_DELETE
= true;
42 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl
& url
, QWidget
* parent
) :
43 SettingsPageBase(parent
),
47 m_confirmMoveToTrash(0),
51 m_configureToolTips(0),
52 m_showSelectionToggle(0),
55 const int spacing
= KDialog::spacingHint();
57 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
58 KVBox
* vBox
= new KVBox(this);
59 vBox
->setSpacing(spacing
);
61 // 'View Properties' box
62 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), vBox
);
63 propsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
65 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
66 connect(m_localProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
68 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
69 connect(m_globalProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
71 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
72 propsBoxLayout
->addWidget(m_localProps
);
73 propsBoxLayout
->addWidget(m_globalProps
);
75 // 'Ask Confirmation For' box
76 QGroupBox
* confirmBox
= new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox
);
77 confirmBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
78 m_confirmMoveToTrash
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
79 "Moving files or folders to trash"), confirmBox
);
80 connect(m_confirmMoveToTrash
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
81 m_confirmDelete
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
82 "Deleting files or folders"), confirmBox
);
83 connect(m_confirmDelete
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
84 m_confirmClosingMultipleTabs
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
85 "Closing windows with multiple tabs"), confirmBox
);
86 connect(m_confirmClosingMultipleTabs
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
88 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
89 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
90 confirmBoxLayout
->addWidget(m_confirmDelete
);
91 confirmBoxLayout
->addWidget(m_confirmClosingMultipleTabs
);
94 m_renameInline
= new QCheckBox(i18nc("@option:check", "Rename inline"), vBox
);
95 connect(m_renameInline
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
98 QWidget
* toolTipContainer
= new QWidget(vBox
);
99 QHBoxLayout
* toolTipsLayout
= new QHBoxLayout(toolTipContainer
);
100 toolTipsLayout
->setMargin(0);
101 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), toolTipContainer
);
102 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
103 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SLOT(updateConfigureButton()));
105 m_configureToolTips
= new QLabel(toolTipContainer
);
106 connect(m_configureToolTips
, SIGNAL(linkActivated(const QString
&)),
107 this, SLOT(configureToolTips()));
109 toolTipsLayout
->addWidget(m_showToolTips
);
110 toolTipsLayout
->addWidget(m_configureToolTips
, 1, Qt::AlignLeft
);
112 // 'Show selection marker'
113 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), vBox
);
114 connect(m_showSelectionToggle
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
116 // 'Natural sorting of items'
117 m_naturalSorting
= new QCheckBox(i18nc("option:check", "Natural sorting of items"), vBox
);
118 connect(m_naturalSorting
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
120 // Add a dummy widget with no restriction regarding
121 // a vertical resizing. This assures that the dialog layout
122 // is not stretched vertically.
125 topLayout
->addWidget(vBox
);
130 BehaviorSettingsPage::~BehaviorSettingsPage()
134 void BehaviorSettingsPage::applySettings()
136 ViewProperties
props(m_url
); // read current view properties
138 const bool useGlobalProps
= m_globalProps
->isChecked();
140 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
141 settings
->setGlobalViewProps(useGlobalProps
);
143 if (useGlobalProps
) {
144 // Remember the global view properties by applying the current view properties.
145 // It is important that GeneralSettings::globalViewProps() is set before
146 // the class ViewProperties is used, as ViewProperties uses this setting
147 // to find the destination folder for storing the view properties.
148 ViewProperties
globalProps(m_url
);
149 globalProps
.setDirProperties(props
);
152 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::NoGlobals
);
153 KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
154 confirmationGroup
.writeEntry("ConfirmTrash", m_confirmMoveToTrash
->isChecked());
155 confirmationGroup
.writeEntry("ConfirmDelete", m_confirmDelete
->isChecked());
156 confirmationGroup
.sync();
158 settings
->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs
->isChecked());
159 settings
->setRenameInline(m_renameInline
->isChecked());
160 settings
->setShowToolTips(m_showToolTips
->isChecked());
161 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
162 settings
->writeConfig();
164 const bool naturalSorting
= m_naturalSorting
->isChecked();
165 if (KGlobalSettings::naturalSorting() != naturalSorting
) {
166 KConfigGroup
group(KGlobal::config(), "KDE");
167 group
.writeEntry("NaturalSorting", naturalSorting
, KConfig::Persistent
| KConfig::Global
);
168 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged
);
172 void BehaviorSettingsPage::restoreDefaults()
174 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
175 settings
->useDefaults(true);
177 settings
->useDefaults(false);
178 m_confirmMoveToTrash
->setChecked(CONFIRM_TRASH
);
179 m_confirmDelete
->setChecked(CONFIRM_DELETE
);
182 void BehaviorSettingsPage::updateConfigureButton()
184 if (m_showToolTips
->isChecked()) {
185 m_configureToolTips
->setText("<a href=\"configure\">" +
186 i18nc("@action:button", "Configure...") +
189 m_configureToolTips
->setText(QString());
193 void BehaviorSettingsPage::configureToolTips()
196 //KFileMetaDataConfigurationDialog* dialog = new KFileMetaDataConfigurationDialog();
197 //dialog->setDescription(i18nc("@label::textbox",
198 // "Configure which data should be shown in the tooltip."));
199 //dialog->setAttribute(Qt::WA_DeleteOnClose);
202 //dialog->activateWindow();
205 void BehaviorSettingsPage::loadSettings()
207 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
208 if (settings
->globalViewProps()) {
209 m_globalProps
->setChecked(true);
211 m_localProps
->setChecked(true);
214 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals
);
215 const KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
216 m_confirmMoveToTrash
->setChecked(confirmationGroup
.readEntry("ConfirmTrash", CONFIRM_TRASH
));
217 m_confirmDelete
->setChecked(confirmationGroup
.readEntry("ConfirmDelete", CONFIRM_DELETE
));
219 m_confirmClosingMultipleTabs
->setChecked(settings
->confirmClosingMultipleTabs());
220 m_renameInline
->setChecked(settings
->renameInline());
221 m_showToolTips
->setChecked(settings
->showToolTips());
222 m_showSelectionToggle
->setChecked(settings
->showSelectionToggle());
223 m_naturalSorting
->setChecked(KGlobalSettings::naturalSorting());
225 updateConfigureButton();
228 #include "behaviorsettingspage.moc"