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"
25 #include "filemetadataconfigurationdialog.h"
27 #include <viewproperties.h>
35 #include <QHBoxLayout>
37 #include <QRadioButton>
38 #include <QVBoxLayout>
40 const bool CONFIRM_TRASH
= false;
41 const bool CONFIRM_DELETE
= true;
43 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl
& url
, QWidget
* parent
) :
44 SettingsPageBase(parent
),
48 m_confirmMoveToTrash(0),
52 m_configureToolTips(0),
53 m_showSelectionToggle(0),
56 const int spacing
= KDialog::spacingHint();
58 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
59 KVBox
* vBox
= new KVBox(this);
60 vBox
->setSpacing(spacing
);
62 // 'View Properties' box
63 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), vBox
);
64 propsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
66 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
67 connect(m_localProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
69 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
70 connect(m_globalProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
72 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
73 propsBoxLayout
->addWidget(m_localProps
);
74 propsBoxLayout
->addWidget(m_globalProps
);
76 // 'Ask Confirmation For' box
77 QGroupBox
* confirmBox
= new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox
);
78 confirmBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
79 m_confirmMoveToTrash
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
80 "Moving files or folders to trash"), confirmBox
);
81 connect(m_confirmMoveToTrash
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
82 m_confirmDelete
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
83 "Deleting files or folders"), confirmBox
);
84 connect(m_confirmDelete
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
85 m_confirmClosingMultipleTabs
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
86 "Closing windows with multiple tabs"), confirmBox
);
87 connect(m_confirmClosingMultipleTabs
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
89 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
90 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
91 confirmBoxLayout
->addWidget(m_confirmDelete
);
92 confirmBoxLayout
->addWidget(m_confirmClosingMultipleTabs
);
95 m_renameInline
= new QCheckBox(i18nc("@option:check", "Rename inline"), vBox
);
96 connect(m_renameInline
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
99 QWidget
* toolTipContainer
= new QWidget(vBox
);
100 QHBoxLayout
* toolTipsLayout
= new QHBoxLayout(toolTipContainer
);
101 toolTipsLayout
->setMargin(0);
102 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), toolTipContainer
);
103 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
104 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SLOT(updateConfigureButton()));
106 m_configureToolTips
= new QLabel(toolTipContainer
);
107 connect(m_configureToolTips
, SIGNAL(linkActivated(const QString
&)),
108 this, SLOT(configureToolTips()));
110 toolTipsLayout
->addWidget(m_showToolTips
);
111 toolTipsLayout
->addWidget(m_configureToolTips
, 1, Qt::AlignLeft
);
113 // 'Show selection marker'
114 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), vBox
);
115 connect(m_showSelectionToggle
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
117 // 'Natural sorting of items'
118 m_naturalSorting
= new QCheckBox(i18nc("option:check", "Natural sorting of items"), vBox
);
119 connect(m_naturalSorting
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
121 // Add a dummy widget with no restriction regarding
122 // a vertical resizing. This assures that the dialog layout
123 // is not stretched vertically.
126 topLayout
->addWidget(vBox
);
131 BehaviorSettingsPage::~BehaviorSettingsPage()
135 void BehaviorSettingsPage::applySettings()
137 ViewProperties
props(m_url
); // read current view properties
139 const bool useGlobalProps
= m_globalProps
->isChecked();
141 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
142 settings
->setGlobalViewProps(useGlobalProps
);
144 if (useGlobalProps
) {
145 // Remember the global view properties by applying the current view properties.
146 // It is important that GeneralSettings::globalViewProps() is set before
147 // the class ViewProperties is used, as ViewProperties uses this setting
148 // to find the destination folder for storing the view properties.
149 ViewProperties
globalProps(m_url
);
150 globalProps
.setDirProperties(props
);
153 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::NoGlobals
);
154 KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
155 confirmationGroup
.writeEntry("ConfirmTrash", m_confirmMoveToTrash
->isChecked());
156 confirmationGroup
.writeEntry("ConfirmDelete", m_confirmDelete
->isChecked());
157 confirmationGroup
.sync();
159 settings
->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs
->isChecked());
160 settings
->setRenameInline(m_renameInline
->isChecked());
161 settings
->setShowToolTips(m_showToolTips
->isChecked());
162 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
163 settings
->writeConfig();
165 const bool naturalSorting
= m_naturalSorting
->isChecked();
166 if (KGlobalSettings::naturalSorting() != naturalSorting
) {
167 KConfigGroup
group(KGlobal::config(), "KDE");
168 group
.writeEntry("NaturalSorting", naturalSorting
, KConfig::Persistent
| KConfig::Global
);
169 KGlobalSettings::emitChange(KGlobalSettings::NaturalSortingChanged
);
173 void BehaviorSettingsPage::restoreDefaults()
175 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
176 settings
->useDefaults(true);
178 settings
->useDefaults(false);
179 m_confirmMoveToTrash
->setChecked(CONFIRM_TRASH
);
180 m_confirmDelete
->setChecked(CONFIRM_DELETE
);
183 void BehaviorSettingsPage::updateConfigureButton()
185 if (m_showToolTips
->isChecked()) {
186 m_configureToolTips
->setText("<a href=\"configure\">" +
187 i18nc("@action:button", "Configure...") +
190 m_configureToolTips
->setText(QString());
194 void BehaviorSettingsPage::configureToolTips()
196 FileMetaDataConfigurationDialog
* dialog
= new FileMetaDataConfigurationDialog();
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"