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 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl
& url
, QWidget
* parent
) :
39 SettingsPageBase(parent
),
43 m_confirmMoveToTrash(0),
47 m_showSelectionToggle(0)
49 const int spacing
= KDialog::spacingHint();
51 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
52 KVBox
* vBox
= new KVBox(this);
53 vBox
->setSpacing(spacing
);
55 // 'View Properties' box
56 QGroupBox
* propsBox
= new QGroupBox(i18nc("@title:group", "View Properties"), vBox
);
58 m_localProps
= new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox
);
59 connect(m_localProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
61 m_globalProps
= new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox
);
62 connect(m_globalProps
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
64 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
65 propsBoxLayout
->addWidget(m_localProps
);
66 propsBoxLayout
->addWidget(m_globalProps
);
68 // 'Ask Confirmation For' box
69 QGroupBox
* confirmBox
= new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox
);
70 m_confirmMoveToTrash
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
71 "Moving files or folders to trash"), confirmBox
);
72 connect(m_confirmMoveToTrash
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
73 m_confirmDelete
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
74 "Deleting files or folders"), confirmBox
);
75 connect(m_confirmDelete
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
77 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
78 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
79 confirmBoxLayout
->addWidget(m_confirmDelete
);
81 m_renameInline
= new QCheckBox(i18nc("@option:check", "Rename inline"), vBox
);
82 connect(m_renameInline
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
84 m_showToolTips
= new QCheckBox(i18nc("@option:check", "Show tooltips"), vBox
);
85 connect(m_showToolTips
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
87 m_showSelectionToggle
= new QCheckBox(i18nc("@option:check", "Show selection marker"), vBox
);
88 connect(m_showSelectionToggle
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
90 // Add a dummy widget with no restriction regarding
91 // a vertical resizing. This assures that the dialog layout
92 // is not stretched vertically.
95 topLayout
->addWidget(vBox
);
100 BehaviorSettingsPage::~BehaviorSettingsPage()
104 void BehaviorSettingsPage::applySettings()
106 ViewProperties
props(m_url
); // read current view properties
108 const bool useGlobalProps
= m_globalProps
->isChecked();
110 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
111 settings
->setGlobalViewProps(useGlobalProps
);
113 if (useGlobalProps
) {
114 // Remember the global view properties by applying the current view properties.
115 // It is important that GeneralSettings::globalViewProps() is set before
116 // the class ViewProperties is used, as ViewProperties uses this setting
117 // to find the destination folder for storing the view properties.
118 ViewProperties
globalProps(m_url
);
119 globalProps
.setDirProperties(props
);
122 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::NoGlobals
);
123 KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
124 confirmationGroup
.writeEntry("ConfirmTrash", m_confirmMoveToTrash
->isChecked());
125 confirmationGroup
.writeEntry("ConfirmDelete", m_confirmDelete
->isChecked());
126 confirmationGroup
.sync();
128 settings
->setRenameInline(m_renameInline
->isChecked());
129 settings
->setShowToolTips(m_showToolTips
->isChecked());
130 settings
->setShowSelectionToggle(m_showSelectionToggle
->isChecked());
133 void BehaviorSettingsPage::restoreDefaults()
135 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
136 settings
->setDefaults();
138 // TODO: reset default settings for trash and show delete command...
143 void BehaviorSettingsPage::loadSettings()
145 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
146 if (settings
->globalViewProps()) {
147 m_globalProps
->setChecked(true);
149 m_localProps
->setChecked(true);
152 KSharedConfig::Ptr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals
);
153 const KConfigGroup
confirmationGroup(kioConfig
, "Confirmations");
154 m_confirmMoveToTrash
->setChecked(confirmationGroup
.readEntry("ConfirmTrash", false));
155 m_confirmDelete
->setChecked(confirmationGroup
.readEntry("ConfirmDelete", true));
157 m_renameInline
->setChecked(settings
->renameInline());
158 m_showToolTips
->setChecked(settings
->showToolTips());
159 m_showSelectionToggle
->setChecked(settings
->showSelectionToggle());
162 #include "behaviorsettingspage.moc"