]>
cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
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. *
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. *
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 ***************************************************************************/
21 #include "generalsettingspage.h"
23 #include "dolphinsettings.h"
24 #include "dolphinmainwindow.h"
25 #include "dolphinview.h"
26 #include "dolphinviewcontainer.h"
28 #include "dolphin_generalsettings.h"
31 #include <kfiledialog.h>
39 #include <QPushButton>
40 #include <QRadioButton>
42 GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow
* mainWin
, QWidget
* parent
) :
43 SettingsPageBase(parent
),
44 m_mainWindow(mainWin
),
49 m_showDeleteCommand(0),
50 m_confirmMoveToTrash(0),
52 m_browseThroughArchives(0)
54 const int spacing
= KDialog::spacingHint();
56 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
57 KVBox
* vBox
= new KVBox(this);
58 vBox
->setSpacing(spacing
);
60 // create 'Home URL' editor
61 QGroupBox
* homeBox
= new QGroupBox(i18nc("@title:group", "Home Folder"), vBox
);
63 KHBox
* homeUrlBox
= new KHBox(homeBox
);
64 homeUrlBox
->setSpacing(spacing
);
66 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox
);
67 m_homeUrl
= new QLineEdit(homeUrlBox
);
69 QPushButton
* selectHomeUrlButton
= new QPushButton(KIcon("folder-open"), QString(), homeUrlBox
);
70 connect(selectHomeUrlButton
, SIGNAL(clicked()),
71 this, SLOT(selectHomeUrl()));
73 KHBox
* buttonBox
= new KHBox(homeBox
);
74 buttonBox
->setSpacing(spacing
);
76 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox
);
77 connect(useCurrentButton
, SIGNAL(clicked()),
78 this, SLOT(useCurrentLocation()));
79 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox
);
80 connect(useDefaultButton
, SIGNAL(clicked()),
81 this, SLOT(useDefaultLocation()));
83 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout(homeBox
);
84 homeBoxLayout
->addWidget(homeUrlBox
);
85 homeBoxLayout
->addWidget(buttonBox
);
87 QGroupBox
* startBox
= new QGroupBox(i18nc("@title:group", "Startup Settings"), vBox
);
89 // create 'Split view', 'Editable location' and 'Filter bar' checkboxes
90 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), startBox
);
91 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), startBox
);
92 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"),startBox
);
94 QVBoxLayout
* startBoxLayout
= new QVBoxLayout(startBox
);
95 startBoxLayout
->addWidget(m_splitView
);
96 startBoxLayout
->addWidget(m_editableUrl
);
97 startBoxLayout
->addWidget(m_filterBar
);
99 // create 'Ask Confirmation For' group
100 QGroupBox
* confirmBox
= new QGroupBox(i18nc("@title:group", "Ask For Confirmation When"), vBox
);
101 m_confirmMoveToTrash
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
102 "Moving files or folders to trash"), confirmBox
);
103 m_confirmDelete
= new QCheckBox(i18nc("@option:check Ask for Confirmation When",
104 "Deleting files or folders"), confirmBox
);
106 QVBoxLayout
* confirmBoxLayout
= new QVBoxLayout(confirmBox
);
107 confirmBoxLayout
->addWidget(m_confirmMoveToTrash
);
108 confirmBoxLayout
->addWidget(m_confirmDelete
);
110 // create 'Show the command 'Delete' in context menu' checkbox
111 m_showDeleteCommand
= new QCheckBox(i18nc("@option:check", "Show 'Delete' command in context menu"), vBox
);
113 m_browseThroughArchives
= new QCheckBox(i18nc("option:check", "Browse through archives"), vBox
);
115 // Add a dummy widget with no restriction regarding
116 // a vertical resizing. This assures that the dialog layout
117 // is not stretched vertically.
120 topLayout
->addWidget(vBox
);
125 GeneralSettingsPage::~GeneralSettingsPage()
129 void GeneralSettingsPage::applySettings()
131 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
133 const KUrl
url(m_homeUrl
->text());
134 KFileItem
fileItem(S_IFDIR
, KFileItem::Unknown
, url
);
135 if (url
.isValid() && fileItem
.isDir()) {
136 settings
->setHomeUrl(url
.prettyUrl());
139 settings
->setSplitView(m_splitView
->isChecked());
140 settings
->setEditableUrl(m_editableUrl
->isChecked());
141 settings
->setFilterBar(m_filterBar
->isChecked());
143 KSharedConfig::Ptr konqConfig
= KSharedConfig::openConfig("konquerorrc", KConfig::IncludeGlobals
);
144 KConfigGroup
trashConfig(konqConfig
, "Trash");
145 trashConfig
.writeEntry("ConfirmTrash", m_confirmMoveToTrash
->isChecked());
146 trashConfig
.writeEntry("ConfirmDelete", m_confirmDelete
->isChecked());
149 KConfigGroup
kdeConfig(KGlobal::config(), "KDE");
150 kdeConfig
.writeEntry("ShowDeleteCommand", m_showDeleteCommand
->isChecked());
153 settings
->setBrowseThroughArchives(m_browseThroughArchives
->isChecked());
156 void GeneralSettingsPage::restoreDefaults()
158 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
159 settings
->setDefaults();
161 // TODO: reset default settings for trash and show delete command...
166 void GeneralSettingsPage::selectHomeUrl()
168 const QString
homeUrl(m_homeUrl
->text());
169 KUrl
url(KFileDialog::getExistingDirectoryUrl(homeUrl
));
170 if (!url
.isEmpty()) {
171 m_homeUrl
->setText(url
.prettyUrl());
175 void GeneralSettingsPage::useCurrentLocation()
177 const DolphinView
* view
= m_mainWindow
->activeViewContainer()->view();
178 m_homeUrl
->setText(view
->url().prettyUrl());
181 void GeneralSettingsPage::useDefaultLocation()
183 m_homeUrl
->setText("file://" + QDir::homePath());
186 void GeneralSettingsPage::loadSettings()
188 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
189 m_homeUrl
->setText(settings
->homeUrl());
190 m_splitView
->setChecked(settings
->splitView());
191 m_editableUrl
->setChecked(settings
->editableUrl());
192 m_filterBar
->setChecked(settings
->filterBar());
194 KSharedConfig::Ptr konqConfig
= KSharedConfig::openConfig("konquerorrc", KConfig::IncludeGlobals
);
195 const KConfigGroup
trashConfig(konqConfig
, "Trash");
196 m_confirmMoveToTrash
->setChecked(trashConfig
.readEntry("ConfirmTrash", false));
197 m_confirmDelete
->setChecked(trashConfig
.readEntry("ConfirmDelete", true));
199 const KConfigGroup
kdeConfig(KGlobal::config(), "KDE");
200 m_showDeleteCommand
->setChecked(kdeConfig
.readEntry("ShowDeleteCommand", false));
202 m_browseThroughArchives
->setChecked(settings
->browseThroughArchives());
205 #include "generalsettingspage.moc"