]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/behaviorsettingspage.cpp
ยง$%$ revert last commit, this does not compile (sorry!)
[dolphin.git] / src / settings / behaviorsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20
21 #include "behaviorsettingspage.h"
22
23 #include "dolphinsettings.h"
24 #include "dolphin_generalsettings.h"
25
26 #include <viewproperties.h>
27
28 #include <kdialog.h>
29 #include <klocale.h>
30 #include <kvbox.h>
31
32 #include <QCheckBox>
33 #include <QGroupBox>
34 #include <QLabel>
35 #include <QRadioButton>
36 #include <QVBoxLayout>
37
38 const bool CONFIRM_TRASH = false;
39 const bool CONFIRM_DELETE = true;
40
41 BehaviorSettingsPage::BehaviorSettingsPage(const KUrl& url, QWidget* parent) :
42 SettingsPageBase(parent),
43 m_url(url),
44 m_localProps(0),
45 m_globalProps(0),
46 m_confirmMoveToTrash(0),
47 m_confirmDelete(0),
48 m_renameInline(0),
49 m_showToolTips(0),
50 m_showSelectionToggle(0)
51 {
52 const int spacing = KDialog::spacingHint();
53
54 QVBoxLayout* topLayout = new QVBoxLayout(this);
55 KVBox* vBox = new KVBox(this);
56 vBox->setSpacing(spacing);
57
58 // 'View Properties' box
59 QGroupBox* propsBox = new QGroupBox(i18nc("@title:group", "View Properties"), vBox);
60 propsBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
61
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()));
64
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()));
67
68 QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox);
69 propsBoxLayout->addWidget(m_localProps);
70 propsBoxLayout->addWidget(m_globalProps);
71
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
82 QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox);
83 confirmBoxLayout->addWidget(m_confirmMoveToTrash);
84 confirmBoxLayout->addWidget(m_confirmDelete);
85
86 m_renameInline = new QCheckBox(i18nc("@option:check", "Rename inline"), vBox);
87 connect(m_renameInline, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
88
89 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), vBox);
90 connect(m_showToolTips, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
91
92 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), vBox);
93 connect(m_showSelectionToggle, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
94
95 // Add a dummy widget with no restriction regarding
96 // a vertical resizing. This assures that the dialog layout
97 // is not stretched vertically.
98 new QWidget(vBox);
99
100 topLayout->addWidget(vBox);
101
102 loadSettings();
103 }
104
105 BehaviorSettingsPage::~BehaviorSettingsPage()
106 {
107 }
108
109 void BehaviorSettingsPage::applySettings()
110 {
111 ViewProperties props(m_url); // read current view properties
112
113 const bool useGlobalProps = m_globalProps->isChecked();
114
115 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
116 settings->setGlobalViewProps(useGlobalProps);
117
118 if (useGlobalProps) {
119 // Remember the global view properties by applying the current view properties.
120 // It is important that GeneralSettings::globalViewProps() is set before
121 // the class ViewProperties is used, as ViewProperties uses this setting
122 // to find the destination folder for storing the view properties.
123 ViewProperties globalProps(m_url);
124 globalProps.setDirProperties(props);
125 }
126
127 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
128 KConfigGroup confirmationGroup(kioConfig, "Confirmations");
129 confirmationGroup.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked());
130 confirmationGroup.writeEntry("ConfirmDelete", m_confirmDelete->isChecked());
131 confirmationGroup.sync();
132
133 settings->setRenameInline(m_renameInline->isChecked());
134 settings->setShowToolTips(m_showToolTips->isChecked());
135 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
136 }
137
138 void BehaviorSettingsPage::restoreDefaults()
139 {
140 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
141 settings->useDefaults(true);
142 loadSettings();
143 settings->useDefaults(false);
144 m_confirmMoveToTrash->setChecked(CONFIRM_TRASH);
145 m_confirmDelete->setChecked(CONFIRM_DELETE);
146 }
147
148 void BehaviorSettingsPage::loadSettings()
149 {
150 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
151 if (settings->globalViewProps()) {
152 m_globalProps->setChecked(true);
153 } else {
154 m_localProps->setChecked(true);
155 }
156
157 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals);
158 const KConfigGroup confirmationGroup(kioConfig, "Confirmations");
159 m_confirmMoveToTrash->setChecked(confirmationGroup.readEntry("ConfirmTrash", CONFIRM_TRASH));
160 m_confirmDelete->setChecked(confirmationGroup.readEntry("ConfirmDelete", CONFIRM_DELETE));
161
162 m_renameInline->setChecked(settings->renameInline());
163 m_showToolTips->setChecked(settings->showToolTips());
164 m_showSelectionToggle->setChecked(settings->showSelectionToggle());
165 }
166
167 #include "behaviorsettingspage.moc"