]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
The space info widget now inherits KCapacityBar. Two things to check:
[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_browseThroughArchives(0),
43 m_renameInline(0)
44 {
45 Q_UNUSED(mainWin);
46
47 const int spacing = KDialog::spacingHint();
48
49 QVBoxLayout* topLayout = new QVBoxLayout(this);
50 KVBox* vBox = new KVBox(this);
51 vBox->setSpacing(spacing);
52
53 // create 'Ask Confirmation For' group
54 QGroupBox* confirmBox = new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox);
55 m_confirmMoveToTrash = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
56 "Moving files or folders to trash"), confirmBox);
57 connect(m_confirmMoveToTrash, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
58 m_confirmDelete = new QCheckBox(i18nc("@option:check Ask for Confirmation When",
59 "Deleting files or folders"), confirmBox);
60 connect(m_confirmDelete, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
61
62 QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox);
63 confirmBoxLayout->addWidget(m_confirmMoveToTrash);
64 confirmBoxLayout->addWidget(m_confirmDelete);
65
66 QGroupBox* contextMenuBox = new QGroupBox(i18nc("@title:group", "Context Menu"), vBox);
67
68 // create 'Show the command 'Delete' in context menu' checkbox
69 m_showDeleteCommand = new QCheckBox(i18nc("@option:check", "Show 'Delete' command"), contextMenuBox);
70 connect(m_showDeleteCommand, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
71
72 m_showCopyMoveMenu = new QCheckBox(i18nc("@option:check", "Show 'Copy To' and 'Move To' commands"), contextMenuBox);
73 connect(m_showCopyMoveMenu, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
74
75 QVBoxLayout* contextMenuBoxLayout = new QVBoxLayout(contextMenuBox);
76 contextMenuBoxLayout->addWidget(m_showDeleteCommand);
77 contextMenuBoxLayout->addWidget(m_showCopyMoveMenu);
78
79 m_browseThroughArchives = new QCheckBox(i18nc("@option:check", "Browse through archives"), vBox);
80 connect(m_browseThroughArchives, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
81
82 m_renameInline = new QCheckBox(i18nc("@option:check", "Rename inline"), vBox);
83 connect(m_renameInline, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
84
85 // Add a dummy widget with no restriction regarding
86 // a vertical resizing. This assures that the dialog layout
87 // is not stretched vertically.
88 new QWidget(vBox);
89
90 topLayout->addWidget(vBox);
91
92 loadSettings();
93 }
94
95 GeneralSettingsPage::~GeneralSettingsPage()
96 {
97 }
98
99 void GeneralSettingsPage::applySettings()
100 {
101 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
102
103 KSharedConfig::Ptr konqConfig = KSharedConfig::openConfig("konquerorrc", KConfig::IncludeGlobals);
104 KConfigGroup trashConfig(konqConfig, "Trash");
105 trashConfig.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked());
106 trashConfig.writeEntry("ConfirmDelete", m_confirmDelete->isChecked());
107 trashConfig.sync();
108
109 KConfigGroup kdeConfig(KGlobal::config(), "KDE");
110 kdeConfig.writeEntry("ShowDeleteCommand", m_showDeleteCommand->isChecked());
111 kdeConfig.sync();
112
113 settings->setShowCopyMoveMenu(m_showCopyMoveMenu->isChecked());
114 settings->setBrowseThroughArchives(m_browseThroughArchives->isChecked());
115 settings->setRenameInline(m_renameInline->isChecked());
116 }
117
118 void GeneralSettingsPage::restoreDefaults()
119 {
120 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
121 settings->setDefaults();
122
123 // TODO: reset default settings for trash and show delete command...
124
125 loadSettings();
126 }
127
128 void GeneralSettingsPage::loadSettings()
129 {
130 KSharedConfig::Ptr konqConfig = KSharedConfig::openConfig("konquerorrc", KConfig::IncludeGlobals);
131 const KConfigGroup trashConfig(konqConfig, "Trash");
132 m_confirmMoveToTrash->setChecked(trashConfig.readEntry("ConfirmTrash", false));
133 m_confirmDelete->setChecked(trashConfig.readEntry("ConfirmDelete", true));
134
135 const KConfigGroup kdeConfig(KGlobal::config(), "KDE");
136 m_showDeleteCommand->setChecked(kdeConfig.readEntry("ShowDeleteCommand", false));
137
138 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
139 m_showCopyMoveMenu->setChecked(settings->showCopyMoveMenu());
140 m_browseThroughArchives->setChecked(settings->browseThroughArchives());
141 m_renameInline->setChecked(settings->renameInline());
142 }
143
144 #include "generalsettingspage.moc"