]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
Removed some unnecessary includes
[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 <kdialog.h>
24 #include <kfiledialog.h>
25 #include <klocale.h>
26 #include <kvbox.h>
27
28 #include <QtGui/QCheckBox>
29 #include <QtGui/QGroupBox>
30 #include <QtGui/QLabel>
31 #include <QtGui/QLineEdit>
32 #include <QtGui/QPushButton>
33 #include <QtGui/QRadioButton>
34
35 #include "dolphinsettings.h"
36 #include "dolphinmainwindow.h"
37 #include "dolphinview.h"
38
39 #include "dolphin_generalsettings.h"
40
41 GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow* mainWin, QWidget* parent) :
42 SettingsPageBase(parent),
43 m_mainWindow(mainWin),
44 m_homeUrl(0),
45 m_splitView(0),
46 m_editableUrl(0),
47 m_filterBar(0),
48 m_showDeleteCommand(0),
49 m_confirmMoveToTrash(0),
50 m_confirmDelete(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 // create 'Home URL' editor
59 QGroupBox* homeBox = new QGroupBox(i18n("Home Folder"), vBox);
60
61 KHBox* homeUrlBox = new KHBox(homeBox);
62 homeUrlBox->setSpacing(spacing);
63
64 new QLabel(i18n("Location:"), homeUrlBox);
65 m_homeUrl = new QLineEdit(homeUrlBox);
66
67 QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder-open"), QString(), homeUrlBox);
68 connect(selectHomeUrlButton, SIGNAL(clicked()),
69 this, SLOT(selectHomeUrl()));
70
71 KHBox* buttonBox = new KHBox(homeBox);
72 buttonBox->setSpacing(spacing);
73
74 QPushButton* useCurrentButton = new QPushButton(i18n("Use Current Location"), buttonBox);
75 connect(useCurrentButton, SIGNAL(clicked()),
76 this, SLOT(useCurrentLocation()));
77 QPushButton* useDefaultButton = new QPushButton(i18n("Use Default Location"), buttonBox);
78 connect(useDefaultButton, SIGNAL(clicked()),
79 this, SLOT(useDefaultLocation()));
80
81 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
82 homeBoxLayout->addWidget(homeUrlBox);
83 homeBoxLayout->addWidget(buttonBox);
84
85 QGroupBox* startBox = new QGroupBox(i18n("Startup Settings"), vBox);
86
87 // create 'Split view', 'Editable location' and 'Filter bar' checkboxes
88 m_splitView = new QCheckBox(i18n("Split view mode"), startBox);
89 m_editableUrl = new QCheckBox(i18n("Editable location bar"), startBox);
90 m_filterBar = new QCheckBox(i18n("Show filter bar"),startBox);
91
92 QVBoxLayout* startBoxLayout = new QVBoxLayout(startBox);
93 startBoxLayout->addWidget(m_splitView);
94 startBoxLayout->addWidget(m_editableUrl);
95 startBoxLayout->addWidget(m_filterBar);
96
97 // create 'Ask Confirmation For' group
98 KSharedConfig::Ptr konqConfig = KSharedConfig::openConfig("konquerorrc", KConfig::IncludeGlobals);
99 const KConfigGroup trashConfig(konqConfig, "Trash");
100
101 QGroupBox* confirmBox = new QGroupBox(i18n("Ask For Confirmation When"), vBox);
102
103 m_confirmMoveToTrash = new QCheckBox(i18n("Moving files or folders to trash"), confirmBox);
104 m_confirmMoveToTrash->setChecked(trashConfig.readEntry("ConfirmTrash", false));
105
106 m_confirmDelete = new QCheckBox(i18n("Deleting files or folders"), confirmBox);
107 m_confirmDelete->setChecked(trashConfig.readEntry("ConfirmDelete", true));
108
109 QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox);
110 confirmBoxLayout->addWidget(m_confirmMoveToTrash);
111 confirmBoxLayout->addWidget(m_confirmDelete);
112
113 // create 'Show the command 'Delete' in context menu' checkbox
114 m_showDeleteCommand = new QCheckBox(i18n("Show 'Delete' command in context menu"), vBox);
115 const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
116 const KConfigGroup kdeConfig(globalConfig, "KDE");
117 m_showDeleteCommand->setChecked(kdeConfig.readEntry("ShowDeleteCommand", false));
118
119 // Add a dummy widget with no restriction regarding
120 // a vertical resizing. This assures that the dialog layout
121 // is not stretched vertically.
122 new QWidget(vBox);
123
124 topLayout->addWidget(vBox);
125
126 loadSettings();
127 }
128
129 GeneralSettingsPage::~GeneralSettingsPage()
130 {
131 }
132
133 void GeneralSettingsPage::applySettings()
134 {
135 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
136
137 const KUrl url(m_homeUrl->text());
138 KFileItem fileItem(S_IFDIR, KFileItem::Unknown, url);
139 if (url.isValid() && fileItem.isDir()) {
140 settings->setHomeUrl(url.prettyUrl());
141 }
142
143 settings->setSplitView(m_splitView->isChecked());
144 settings->setEditableUrl(m_editableUrl->isChecked());
145 settings->setFilterBar(m_filterBar->isChecked());
146
147 KSharedConfig::Ptr konqConfig = KSharedConfig::openConfig("konquerorrc", KConfig::IncludeGlobals);
148 KConfigGroup trashConfig(konqConfig, "Trash");
149 trashConfig.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked());
150 trashConfig.writeEntry("ConfirmDelete", m_confirmDelete->isChecked());
151
152 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
153 KConfigGroup kdeConfig(globalConfig, "KDE");
154 kdeConfig.writeEntry("ShowDeleteCommand", m_showDeleteCommand->isChecked());
155 kdeConfig.sync();
156 }
157
158 void GeneralSettingsPage::restoreDefaults()
159 {
160 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
161 settings->setDefaults();
162
163 // TODO: reset default settings for trash and show delete command...
164 //KSharedConfig::Ptr konqConfig = KSharedConfig::openConfig("konquerorrc", KConfig::IncludeGlobals);
165 //KConfigGroup trashConfig(konqConfig, "Trash");
166 //KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
167 //KConfigGroup kdeConfig(globalConfig, "KDE");
168
169 loadSettings();
170 }
171
172 void GeneralSettingsPage::selectHomeUrl()
173 {
174 const QString homeUrl(m_homeUrl->text());
175 KUrl url(KFileDialog::getExistingDirectoryUrl(homeUrl));
176 if (!url.isEmpty()) {
177 m_homeUrl->setText(url.prettyUrl());
178 }
179 }
180
181 void GeneralSettingsPage::useCurrentLocation()
182 {
183 const DolphinView* view = m_mainWindow->activeView();
184 m_homeUrl->setText(view->url().prettyUrl());
185 }
186
187 void GeneralSettingsPage::useDefaultLocation()
188 {
189 m_homeUrl->setText("file://" + QDir::homePath());
190 }
191
192 void GeneralSettingsPage::loadSettings()
193 {
194 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
195 m_homeUrl->setText(settings->homeUrl());
196 m_splitView->setChecked(settings->splitView());
197 m_editableUrl->setChecked(settings->editableUrl());
198 m_filterBar->setChecked(settings->filterBar());
199 }
200
201 #include "generalsettingspage.moc"