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)
52 const int spacing
= KDialog::spacingHint();
54 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
55 KVBox
* vBox
= new KVBox(this);
56 vBox
->setSpacing(spacing
);
58 // 'View Properties' box
59 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), vBox
);
60 propsBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
62 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
63 connect(m_localProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
65 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
66 connect(m_globalProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
68 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
69 propsBoxLayout
->addWidget(m_localProps
);
70 propsBoxLayout
->addWidget(m_globalProps
);
72 // 'Ask Confirmation For' box
73 QGroupBox
* confirmBox
= new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox
);
74 confirmBox
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Maximum
);
75 m_confirmMoveToTrash
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
76 "Moving files or folders to trash"), confirmBox
);
77 connect(m_confirmMoveToTrash
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
78 m_confirmDelete
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
79 "Deleting files or folders"), confirmBox
);
80 connect(m_confirmDelete
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
81 m_confirmClosingMultipleTabs
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
82 "Closing windows with multiple tabs"), confirmBox
);
83 connect(m_confirmClosingMultipleTabs
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
85 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
86 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
87 confirmBoxLayout
->addWidget(m_confirmDelete
);
88 confirmBoxLayout
->addWidget(m_confirmClosingMultipleTabs
);
90 m_renameInline
= new QCheckBox(i18nc("@option:check", "Rename inline"), vBox
);
91 connect(m_renameInline
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
93 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), vBox
);
94 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
96 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), vBox
);
97 connect(m_showSelectionToggle
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
99 // Add a dummy widget with no restriction regarding
100 // a vertical resizing. This assures that the dialog layout
101 // is not stretched vertically.
104 topLayout
->addWidget(vBox
);
109 BehaviorSettingsPage::~BehaviorSettingsPage()
113 void BehaviorSettingsPage::applySettings()
115 ViewProperties
props(m_url
); // read current view properties
117 const bool useGlobalProps
= m_globalProps
->isChecked();
119 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
120 settings
->setGlobalViewProps(useGlobalProps
);
122 if (useGlobalProps
) {
123 // Remember the global view properties by applying the current view properties.
124 // It is important that GeneralSettings::globalViewProps() is set before
125 // the class ViewProperties is used, as ViewProperties uses this setting
126 // to find the destination folder for storing the view properties.
127 ViewProperties
globalProps(m_url
);
128 globalProps
.setDirProperties(props
);
131 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::NoGlobals
);
132 KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
133 confirmationGroup
.writeEntry("ConfirmTrash", m_confirmMoveToTrash
->isChecked());
134 confirmationGroup
.writeEntry("ConfirmDelete", m_confirmDelete
->isChecked());
135 confirmationGroup
.sync();
137 settings
->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs
->isChecked());
138 settings
->setRenameInline(m_renameInline
->isChecked());
139 settings
->setShowToolTips(m_showToolTips
->isChecked());
140 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
141 settings
->writeConfig();
144 void BehaviorSettingsPage::restoreDefaults()
146 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
147 settings
->useDefaults(true);
149 settings
->useDefaults(false);
150 m_confirmMoveToTrash
->setChecked(CONFIRM_TRASH
);
151 m_confirmDelete
->setChecked(CONFIRM_DELETE
);
154 void BehaviorSettingsPage::loadSettings()
156 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
157 if (settings
->globalViewProps()) {
158 m_globalProps
->setChecked(true);
160 m_localProps
->setChecked(true);
163 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals
);
164 const KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
165 m_confirmMoveToTrash
->setChecked(confirmationGroup
.readEntry("ConfirmTrash", CONFIRM_TRASH
));
166 m_confirmDelete
->setChecked(confirmationGroup
.readEntry("ConfirmDelete", CONFIRM_DELETE
));
168 m_confirmClosingMultipleTabs
->setChecked(settings
->confirmClosingMultipleTabs());
169 m_renameInline
->setChecked(settings
->renameInline());
170 m_showToolTips
->setChecked(settings
->showToolTips());
171 m_showSelectionToggle
->setChecked(settings
->showSelectionToggle());
174 #include "behaviorsettingspage.moc"