]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/generalsettingspage.cpp
Group classes into folders, Dolphin is too big in the meantime for having a flat...
[dolphin.git] / src / settings / 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 "settings/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 m_autoExpandFolders(0)
47 {
48 Q_UNUSED(mainWin);
49
50 const int spacing = KDialog::spacingHint();
51
52 QVBoxLayout* topLayout = new QVBoxLayout(this);
53 KVBox* vBox = new KVBox(this);
54 vBox->setSpacing(spacing);
55
56 // create 'Ask Confirmation For' group
57 QGroupBox* confirmBox = new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox);
58 m_confirmMoveToTrash = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
59 "Moving files or folders to trash"), confirmBox);
60 connect(m_confirmMoveToTrash, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
61 m_confirmDelete = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
62 "Deleting files or folders"), confirmBox);
63 connect(m_confirmDelete, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
64
65 QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox);
66 confirmBoxLayout->addWidget(m_confirmMoveToTrash);
67 confirmBoxLayout->addWidget(m_confirmDelete);
68
69 QGroupBox* contextMenuBox = new QGroupBox(i18nc("@title:group", "Context Menu"), vBox);
70
71 // create 'Show the command 'Delete' in context menu' checkbox
72 m_showDeleteCommand = new QCheckBox(i18nc("@option:check", "Show 'Delete' command"), contextMenuBox);
73 connect(m_showDeleteCommand, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
74
75 m_showCopyMoveMenu = new QCheckBox(i18nc("@option:check", "Show 'Copy To' and 'Move To' commands"), contextMenuBox);
76 connect(m_showCopyMoveMenu, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
77
78 QVBoxLayout* contextMenuBoxLayout = new QVBoxLayout(contextMenuBox);
79 contextMenuBoxLayout->addWidget(m_showDeleteCommand);
80 contextMenuBoxLayout->addWidget(m_showCopyMoveMenu);
81
82 QGroupBox* statusBarBox = new QGroupBox(i18nc("@title:group", "Status Bar"), vBox);
83
84 m_showZoomSlider = new QCheckBox(i18nc("@option:check", "Show zoom slider"), statusBarBox);
85 connect(m_showZoomSlider, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
86
87 m_showSpaceInfo = new QCheckBox(i18nc("@option:check", "Show space information"), statusBarBox);
88 connect(m_showSpaceInfo, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
89
90 QVBoxLayout* statusBarBoxLayout = new QVBoxLayout(statusBarBox);
91 statusBarBoxLayout->addWidget(m_showZoomSlider);
92 statusBarBoxLayout->addWidget(m_showSpaceInfo);
93
94 m_browseThroughArchives = new QCheckBox(i18nc("@option:check", "Browse through archives"), vBox);
95 connect(m_browseThroughArchives, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
96
97 m_renameInline = new QCheckBox(i18nc("@option:check", "Rename inline"), vBox);
98 connect(m_renameInline, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
99
100 m_autoExpandFolders = new QCheckBox(i18nc("option:check", "Open folders during drag operations"), vBox);
101 connect(m_autoExpandFolders, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
102
103 // Add a dummy widget with no restriction regarding
104 // a vertical resizing. This assures that the dialog layout
105 // is not stretched vertically.
106 new QWidget(vBox);
107
108 topLayout->addWidget(vBox);
109
110 loadSettings();
111 }
112
113 GeneralSettingsPage::~GeneralSettingsPage()
114 {
115 }
116
117 void GeneralSettingsPage::applySettings()
118 {
119 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
120
121 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
122 KConfigGroup confirmationGroup(kioConfig, "Confirmations");
123 confirmationGroup.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked());
124 confirmationGroup.writeEntry("ConfirmDelete", m_confirmDelete->isChecked());
125 confirmationGroup.sync();
126
127 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
128 KConfigGroup configGroup(globalConfig, "KDE");
129 configGroup.writeEntry("ShowDeleteCommand", m_showDeleteCommand->isChecked());
130 configGroup.sync();
131
132 settings->setShowCopyMoveMenu(m_showCopyMoveMenu->isChecked());
133 settings->setShowZoomSlider(m_showZoomSlider->isChecked());
134 settings->setShowSpaceInfo(m_showSpaceInfo->isChecked());
135 settings->setBrowseThroughArchives(m_browseThroughArchives->isChecked());
136 settings->setRenameInline(m_renameInline->isChecked());
137 settings->setAutoExpandFolders(m_autoExpandFolders->isChecked());
138 }
139
140 void GeneralSettingsPage::restoreDefaults()
141 {
142 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
143 settings->setDefaults();
144
145 // TODO: reset default settings for trash and show delete command...
146
147 loadSettings();
148 }
149
150 void GeneralSettingsPage::loadSettings()
151 {
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));
156
157 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
158 KConfigGroup configGroup(globalConfig, "KDE");
159 m_showDeleteCommand->setChecked(configGroup.readEntry("ShowDeleteCommand", false));
160
161 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
162 m_showCopyMoveMenu->setChecked(settings->showCopyMoveMenu());
163 m_showZoomSlider->setChecked(settings->showZoomSlider());
164 m_showSpaceInfo->setChecked(settings->showSpaceInfo());
165 m_browseThroughArchives->setChecked(settings->browseThroughArchives());
166 m_renameInline->setChecked(settings->renameInline());
167 m_autoExpandFolders->setChecked(settings->autoExpandFolders());
168 }
169
170 #include "generalsettingspage.moc"