]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/behaviorsettingspage.cpp
Fixed regression when refactoring the Information Panel: Don't forget to give a visua...
[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 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()));
84
85 QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox);
86 confirmBoxLayout->addWidget(m_confirmMoveToTrash);
87 confirmBoxLayout->addWidget(m_confirmDelete);
88 confirmBoxLayout->addWidget(m_confirmClosingMultipleTabs);
89
90 m_renameInline = new QCheckBox(i18nc("@option:check", "Rename inline"), vBox);
91 connect(m_renameInline, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
92
93 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"), vBox);
94 connect(m_showToolTips, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
95
96 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"), vBox);
97 connect(m_showSelectionToggle, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
98
99 // Add a dummy widget with no restriction regarding
100 // a vertical resizing. This assures that the dialog layout
101 // is not stretched vertically.
102 new QWidget(vBox);
103
104 topLayout->addWidget(vBox);
105
106 loadSettings();
107 }
108
109 BehaviorSettingsPage::~BehaviorSettingsPage()
110 {
111 }
112
113 void BehaviorSettingsPage::applySettings()
114 {
115 ViewProperties props(m_url); // read current view properties
116
117 const bool useGlobalProps = m_globalProps->isChecked();
118
119 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
120 settings->setGlobalViewProps(useGlobalProps);
121
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);
129 }
130
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();
136
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();
142 }
143
144 void BehaviorSettingsPage::restoreDefaults()
145 {
146 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
147 settings->useDefaults(true);
148 loadSettings();
149 settings->useDefaults(false);
150 m_confirmMoveToTrash->setChecked(CONFIRM_TRASH);
151 m_confirmDelete->setChecked(CONFIRM_DELETE);
152 }
153
154 void BehaviorSettingsPage::loadSettings()
155 {
156 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
157 if (settings->globalViewProps()) {
158 m_globalProps->setChecked(true);
159 } else {
160 m_localProps->setChecked(true);
161 }
162
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));
167
168 m_confirmClosingMultipleTabs->setChecked(settings->confirmClosingMultipleTabs());
169 m_renameInline->setChecked(settings->renameInline());
170 m_showToolTips->setChecked(settings->showToolTips());
171 m_showSelectionToggle->setChecked(settings->showSelectionToggle());
172 }
173
174 #include "behaviorsettingspage.moc"