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