]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
- Fix crash found while investigating https://bugs.kde.org/show_bug.cgi?id=170927
[dolphin.git] / src / generalsettingspage.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 "generalsettingspage.h"
22
23 #include "dolphinsettings.h"
24
25 #include "dolphin_generalsettings.h"
26
27 #include <kdialog.h>
28 #include <klocale.h>
29 #include <kvbox.h>
30
31 #include <QCheckBox>
32 #include <QGroupBox>
33 #include <QLabel>
34 #include <QVBoxLayout>
35
36 GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow* mainWin, QWidget* parent) :
37 SettingsPageBase(parent),
38 m_confirmMoveToTrash(0),
39 m_confirmDelete(0),
40 m_showDeleteCommand(0),
41 m_showCopyMoveMenu(0),
42 m_showZoomSlider(0),
43 m_showSpaceInfo(0),
44 m_browseThroughArchives(0),
45 m_renameInline(0)
46 {
47 Q_UNUSED(mainWin);
48
49 const int spacing = KDialog::spacingHint();
50
51 QVBoxLayout* topLayout = new QVBoxLayout(this);
52 KVBox* vBox = new KVBox(this);
53 vBox->setSpacing(spacing);
54
55 // create 'Ask Confirmation For' group
56 QGroupBox* confirmBox = new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox);
57 m_confirmMoveToTrash = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
58 "Moving files or folders to trash"), confirmBox);
59 connect(m_confirmMoveToTrash, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
60 m_confirmDelete = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
61 "Deleting files or folders"), confirmBox);
62 connect(m_confirmDelete, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
63
64 QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox);
65 confirmBoxLayout->addWidget(m_confirmMoveToTrash);
66 confirmBoxLayout->addWidget(m_confirmDelete);
67
68 QGroupBox* contextMenuBox = new QGroupBox(i18nc("@title:group", "Context Menu"), vBox);
69
70 // create 'Show the command 'Delete' in context menu' checkbox
71 m_showDeleteCommand = new QCheckBox(i18nc("@option:check", "Show 'Delete' command"), contextMenuBox);
72 connect(m_showDeleteCommand, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
73
74 m_showCopyMoveMenu = new QCheckBox(i18nc("@option:check", "Show 'Copy To' and 'Move To' commands"), contextMenuBox);
75 connect(m_showCopyMoveMenu, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
76
77 QVBoxLayout* contextMenuBoxLayout = new QVBoxLayout(contextMenuBox);
78 contextMenuBoxLayout->addWidget(m_showDeleteCommand);
79 contextMenuBoxLayout->addWidget(m_showCopyMoveMenu);
80
81 QGroupBox* statusBarBox = new QGroupBox(i18nc("@title:group", "Status Bar"), vBox);
82
83 m_showZoomSlider = new QCheckBox(i18nc("@option:check", "Show zoom slider"), statusBarBox);
84 connect(m_showZoomSlider, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
85
86 m_showSpaceInfo = new QCheckBox(i18nc("@option:check", "Show space information"), statusBarBox);
87 connect(m_showSpaceInfo, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
88
89 QVBoxLayout* statusBarBoxLayout = new QVBoxLayout(statusBarBox);
90 statusBarBoxLayout->addWidget(m_showZoomSlider);
91 statusBarBoxLayout->addWidget(m_showSpaceInfo);
92
93 m_browseThroughArchives = new QCheckBox(i18nc("@option:check", "Browse through archives"), vBox);
94 connect(m_browseThroughArchives, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
95
96 m_renameInline = new QCheckBox(i18nc("@option:check", "Rename inline"), vBox);
97 connect(m_renameInline, 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 GeneralSettingsPage::~GeneralSettingsPage()
110 {
111 }
112
113 void GeneralSettingsPage::applySettings()
114 {
115 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
116
117 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
118 KConfigGroup confirmationGroup(kioConfig, "Confirmations");
119 confirmationGroup.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked());
120 confirmationGroup.writeEntry("ConfirmDelete", m_confirmDelete->isChecked());
121 confirmationGroup.sync();
122
123 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
124 KConfigGroup configGroup(globalConfig, "KDE");
125 configGroup.writeEntry("ShowDeleteCommand", m_showDeleteCommand->isChecked());
126 configGroup.sync();
127
128 settings->setShowCopyMoveMenu(m_showCopyMoveMenu->isChecked());
129 settings->setShowZoomSlider(m_showZoomSlider->isChecked());
130 settings->setShowSpaceInfo(m_showSpaceInfo->isChecked());
131 settings->setBrowseThroughArchives(m_browseThroughArchives->isChecked());
132 settings->setRenameInline(m_renameInline->isChecked());
133 }
134
135 void GeneralSettingsPage::restoreDefaults()
136 {
137 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
138 settings->setDefaults();
139
140 // TODO: reset default settings for trash and show delete command...
141
142 loadSettings();
143 }
144
145 void GeneralSettingsPage::loadSettings()
146 {
147 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::IncludeGlobals);
148 const KConfigGroup confirmationGroup(kioConfig, "Confirmations");
149 m_confirmMoveToTrash->setChecked(confirmationGroup.readEntry("ConfirmTrash", false));
150 m_confirmDelete->setChecked(confirmationGroup.readEntry("ConfirmDelete", true));
151
152 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
153 KConfigGroup configGroup(globalConfig, "KDE");
154 m_showDeleteCommand->setChecked(configGroup.readEntry("ShowDeleteCommand", false));
155
156 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
157 m_showCopyMoveMenu->setChecked(settings->showCopyMoveMenu());
158 m_showZoomSlider->setChecked(settings->showZoomSlider());
159 m_showSpaceInfo->setChecked(settings->showSpaceInfo());
160 m_browseThroughArchives->setChecked(settings->browseThroughArchives());
161 m_renameInline->setChecked(settings->renameInline());
162 }
163
164 #include "generalsettingspage.moc"