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