]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
66426b5c6a23fcbe2183a781f8865516e745b5c0
[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 <QCheckBox>
29 #include <QGroupBox>
30 #include <QLabel>
31 #include <QLineEdit>
32 #include <QPushButton>
33 #include <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_startSplit(0),
46 m_startEditable(0),
47 m_showDeleteCommand(0)
48 {
49 const int spacing = KDialog::spacingHint();
50 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
51
52 QVBoxLayout* topLayout = new QVBoxLayout(this);
53 KVBox* vBox = new KVBox(this);
54 vBox->setSpacing(spacing);
55
56 // create 'Home URL' editor
57 QGroupBox* homeBox = new QGroupBox(i18n("Home Folder"), vBox);
58
59 KHBox* homeUrlBox = new KHBox(homeBox);
60 homeUrlBox->setSpacing(spacing);
61
62 new QLabel(i18n("Location:"), homeUrlBox);
63 m_homeUrl = new QLineEdit(settings->homeUrl(), homeUrlBox);
64
65 QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder"), QString(), homeUrlBox);
66 connect(selectHomeUrlButton, SIGNAL(clicked()),
67 this, SLOT(selectHomeUrl()));
68
69 KHBox* buttonBox = new KHBox(homeBox);
70 buttonBox->setSpacing(spacing);
71
72 QPushButton* useCurrentButton = new QPushButton(i18n("Use Current Location"), buttonBox);
73 connect(useCurrentButton, SIGNAL(clicked()),
74 this, SLOT(useCurrentLocation()));
75 QPushButton* useDefaultButton = new QPushButton(i18n("Use Default Location"), buttonBox);
76 connect(useDefaultButton, SIGNAL(clicked()),
77 this, SLOT(useDefaultLocation()));
78
79 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
80 homeBoxLayout->addWidget(homeUrlBox);
81 homeBoxLayout->addWidget(buttonBox);
82
83 QGroupBox* startBox = new QGroupBox(i18n("Start"), vBox);
84
85 // create 'Start with split view' checkbox
86 m_startSplit = new QCheckBox(i18n("Start with split view"), startBox);
87 m_startSplit->setChecked(settings->splitView());
88
89 // create 'Start with editable navigation bar' checkbox
90 m_startEditable = new QCheckBox(i18n("Start with editable navigation bar"), startBox);
91 m_startEditable->setChecked(settings->editableUrl());
92
93 QVBoxLayout* startBoxLayout = new QVBoxLayout(startBox);
94 startBoxLayout->addWidget(m_startSplit);
95 startBoxLayout->addWidget(m_startEditable);
96
97 m_showDeleteCommand = new QCheckBox(i18n("Show the command 'Delete' in context menu"), vBox);
98 const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
99 const KConfigGroup kdeConfig(globalConfig, "KDE");
100 m_showDeleteCommand->setChecked(kdeConfig.readEntry("ShowDeleteCommand", false));
101
102 // Add a dummy widget with no restriction regarding
103 // a vertical resizing. This assures that the dialog layout
104 // is not stretched vertically.
105 new QWidget(vBox);
106
107 topLayout->addWidget(vBox);
108 }
109
110
111 GeneralSettingsPage::~GeneralSettingsPage()
112 {}
113
114 void GeneralSettingsPage::applySettings()
115 {
116 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
117
118 const KUrl url(m_homeUrl->text());
119 KFileItem fileItem(S_IFDIR, KFileItem::Unknown, url);
120 if (url.isValid() && fileItem.isDir()) {
121 settings->setHomeUrl(url.prettyUrl());
122 }
123
124 settings->setSplitView(m_startSplit->isChecked());
125 settings->setEditableUrl(m_startEditable->isChecked());
126
127 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
128 KConfigGroup kdeConfig(globalConfig, "KDE");
129 kdeConfig.writeEntry("ShowDeleteCommand", m_showDeleteCommand->isChecked());
130 kdeConfig.sync();
131 }
132
133 void GeneralSettingsPage::selectHomeUrl()
134 {
135 const QString homeUrl(m_homeUrl->text());
136 KUrl url(KFileDialog::getExistingDirectoryUrl(homeUrl));
137 if (!url.isEmpty()) {
138 m_homeUrl->setText(url.prettyUrl());
139 }
140 }
141
142 void GeneralSettingsPage::useCurrentLocation()
143 {
144 const DolphinView* view = m_mainWindow->activeView();
145 m_homeUrl->setText(view->url().prettyUrl());
146 }
147
148 void GeneralSettingsPage::useDefaultLocation()
149 {
150 m_homeUrl->setText("file://" + QDir::homePath());
151 }
152
153 #include "generalsettingspage.moc"