]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
Allow to configure whether an asking for confirmation should be done for the 'Move...
[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 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
54
55 QVBoxLayout* topLayout = new QVBoxLayout(this);
56 KVBox* vBox = new KVBox(this);
57 vBox->setSpacing(spacing);
58
59 // create 'Home URL' editor
60 QGroupBox* homeBox = new QGroupBox(i18n("Home Folder"), vBox);
61
62 KHBox* homeUrlBox = new KHBox(homeBox);
63 homeUrlBox->setSpacing(spacing);
64
65 new QLabel(i18n("Location:"), homeUrlBox);
66 m_homeUrl = new QLineEdit(settings->homeUrl(), homeUrlBox);
67
68 QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder-open"), QString(), homeUrlBox);
69 connect(selectHomeUrlButton, SIGNAL(clicked()),
70 this, SLOT(selectHomeUrl()));
71
72 KHBox* buttonBox = new KHBox(homeBox);
73 buttonBox->setSpacing(spacing);
74
75 QPushButton* useCurrentButton = new QPushButton(i18n("Use Current Location"), buttonBox);
76 connect(useCurrentButton, SIGNAL(clicked()),
77 this, SLOT(useCurrentLocation()));
78 QPushButton* useDefaultButton = new QPushButton(i18n("Use Default Location"), buttonBox);
79 connect(useDefaultButton, SIGNAL(clicked()),
80 this, SLOT(useDefaultLocation()));
81
82 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
83 homeBoxLayout->addWidget(homeUrlBox);
84 homeBoxLayout->addWidget(buttonBox);
85
86 QGroupBox* startBox = new QGroupBox(i18n("Start"), vBox);
87
88 // create 'Split view' checkbox
89 m_splitView = new QCheckBox(i18n("Split view"), startBox);
90 m_splitView->setChecked(settings->splitView());
91
92 // create 'Editable location' checkbox
93 m_editableUrl = new QCheckBox(i18n("Editable location"), startBox);
94 m_editableUrl->setChecked(settings->editableUrl());
95
96 // create 'Filter bar' checkbox
97 m_filterBar = new QCheckBox(i18n("Filter bar"),startBox);
98 m_filterBar->setChecked(settings->filterBar());
99
100 QVBoxLayout* startBoxLayout = new QVBoxLayout(startBox);
101 startBoxLayout->addWidget(m_splitView);
102 startBoxLayout->addWidget(m_editableUrl);
103 startBoxLayout->addWidget(m_filterBar);
104
105 // create 'Ask Confirmation For' group
106 KSharedConfig::Ptr konqConfig = KSharedConfig::openConfig("konquerorrc", KConfig::IncludeGlobals);
107 const KConfigGroup trashConfig(konqConfig, "Trash");
108
109 QGroupBox* confirmBox = new QGroupBox(i18n("Ask Confirmation For"), vBox);
110
111 m_confirmMoveToTrash = new QCheckBox(i18n("Move to trash"), confirmBox);
112 m_confirmMoveToTrash->setChecked(trashConfig.readEntry("ConfirmTrash", false));
113
114 m_confirmDelete = new QCheckBox(i18n("Delete"), confirmBox);
115 m_confirmDelete->setChecked(trashConfig.readEntry("ConfirmDelete", true));
116
117 QVBoxLayout* confirmBoxLayout = new QVBoxLayout(confirmBox);
118 confirmBoxLayout->addWidget(m_confirmMoveToTrash);
119 confirmBoxLayout->addWidget(m_confirmDelete);
120
121 // create 'Show the command 'Delete' in context menu' checkbox
122 m_showDeleteCommand = new QCheckBox(i18n("Show the command 'Delete' in context menu"), vBox);
123 const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
124 const KConfigGroup kdeConfig(globalConfig, "KDE");
125 m_showDeleteCommand->setChecked(kdeConfig.readEntry("ShowDeleteCommand", false));
126
127 // Add a dummy widget with no restriction regarding
128 // a vertical resizing. This assures that the dialog layout
129 // is not stretched vertically.
130 new QWidget(vBox);
131
132 topLayout->addWidget(vBox);
133 }
134
135 GeneralSettingsPage::~GeneralSettingsPage()
136 {
137 }
138
139 void GeneralSettingsPage::applySettings()
140 {
141 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
142
143 const KUrl url(m_homeUrl->text());
144 KFileItem fileItem(S_IFDIR, KFileItem::Unknown, url);
145 if (url.isValid() && fileItem.isDir()) {
146 settings->setHomeUrl(url.prettyUrl());
147 }
148
149 settings->setSplitView(m_splitView->isChecked());
150 settings->setEditableUrl(m_editableUrl->isChecked());
151 settings->setFilterBar(m_filterBar->isChecked());
152
153 KSharedConfig::Ptr konqConfig = KSharedConfig::openConfig("konquerorrc", KConfig::IncludeGlobals);
154 KConfigGroup trashConfig(konqConfig, "Trash");
155 trashConfig.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked());
156 trashConfig.writeEntry("ConfirmDelete", m_confirmDelete->isChecked());
157
158 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
159 KConfigGroup kdeConfig(globalConfig, "KDE");
160 kdeConfig.writeEntry("ShowDeleteCommand", m_showDeleteCommand->isChecked());
161 kdeConfig.sync();
162 }
163
164 void GeneralSettingsPage::selectHomeUrl()
165 {
166 const QString homeUrl(m_homeUrl->text());
167 KUrl url(KFileDialog::getExistingDirectoryUrl(homeUrl));
168 if (!url.isEmpty()) {
169 m_homeUrl->setText(url.prettyUrl());
170 }
171 }
172
173 void GeneralSettingsPage::useCurrentLocation()
174 {
175 const DolphinView* view = m_mainWindow->activeView();
176 m_homeUrl->setText(view->url().prettyUrl());
177 }
178
179 void GeneralSettingsPage::useDefaultLocation()
180 {
181 m_homeUrl->setText("file://" + QDir::homePath());
182 }
183
184 #include "generalsettingspage.moc"