]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
Add missing separators to the "Help" sub-menu of Dolphin's menubar replacement like...
[dolphin.git] / src / settings / startup / startupsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "startupsettingspage.h"
21
22 #include "settings/dolphinsettings.h"
23 #include "dolphinmainwindow.h"
24 #include "dolphinviewcontainer.h"
25
26 #include "dolphin_generalsettings.h"
27
28 #include <KDialog>
29 #include <KFileDialog>
30 #include <KLocale>
31 #include <KLineEdit>
32 #include <KMessageBox>
33 #include <KVBox>
34
35 #include <QCheckBox>
36 #include <QGroupBox>
37 #include <QLabel>
38 #include <QPushButton>
39 #include <QRadioButton>
40
41 #include "views/dolphinview.h"
42
43 StartupSettingsPage::StartupSettingsPage(const KUrl& url, QWidget* parent) :
44 SettingsPageBase(parent),
45 m_url(url),
46 m_homeUrl(0),
47 m_splitView(0),
48 m_editableUrl(0),
49 m_showFullPath(0),
50 m_filterBar(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(i18nc("@title:group", "Home Folder"), vBox);
60
61 KHBox* homeUrlBox = new KHBox(homeBox);
62 homeUrlBox->setSpacing(spacing);
63
64 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox);
65 m_homeUrl = new KLineEdit(homeUrlBox);
66 m_homeUrl->setClearButtonShown(true);
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 // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes
87 m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox);
88 m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox);
89 m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox);
90 m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox);
91
92 // Add a dummy widget with no restriction regarding
93 // a vertical resizing. This assures that the dialog layout
94 // is not stretched vertically.
95 new QWidget(vBox);
96
97 topLayout->addWidget(vBox);
98
99 loadSettings();
100
101 connect(m_homeUrl, SIGNAL(textChanged(QString)), this, SLOT(slotSettingsChanged()));
102 connect(m_splitView, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
103 connect(m_editableUrl, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
104 connect(m_showFullPath, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
105 connect(m_filterBar, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
106 }
107
108 StartupSettingsPage::~StartupSettingsPage()
109 {
110 }
111
112 void StartupSettingsPage::applySettings()
113 {
114 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
115
116 const KUrl url(m_homeUrl->text());
117 KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url);
118 if (url.isValid() && fileItem.isDir()) {
119 settings->setHomeUrl(url.prettyUrl());
120 } else {
121 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
122 }
123
124 settings->setSplitView(m_splitView->isChecked());
125 settings->setEditableUrl(m_editableUrl->isChecked());
126 settings->setShowFullPath(m_showFullPath->isChecked());
127 settings->setFilterBar(m_filterBar->isChecked());
128
129 settings->writeConfig();
130 }
131
132 void StartupSettingsPage::restoreDefaults()
133 {
134 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
135 settings->useDefaults(true);
136 loadSettings();
137 settings->useDefaults(false);
138 }
139
140 void StartupSettingsPage::slotSettingsChanged()
141 {
142 // Provide a hint that the startup settings have been changed. This allows the views
143 // to apply the startup settings only if they have been explicitly changed by the user
144 // (see bug #254947).
145 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
146 settings->setModifiedStartupSettings(true);
147
148 emit changed();
149 }
150
151 void StartupSettingsPage::selectHomeUrl()
152 {
153 const QString homeUrl = m_homeUrl->text();
154 KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl, this);
155 if (!url.isEmpty()) {
156 m_homeUrl->setText(url.prettyUrl());
157 slotSettingsChanged();
158 }
159 }
160
161 void StartupSettingsPage::useCurrentLocation()
162 {
163 m_homeUrl->setText(m_url.prettyUrl());
164 }
165
166 void StartupSettingsPage::useDefaultLocation()
167 {
168 KUrl url(QDir::homePath());
169 m_homeUrl->setText(url.prettyUrl());
170 }
171
172 void StartupSettingsPage::loadSettings()
173 {
174 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
175 KUrl url(settings->homeUrl());
176 m_homeUrl->setText(url.prettyUrl());
177 m_splitView->setChecked(settings->splitView());
178 m_editableUrl->setChecked(settings->editableUrl());
179 m_showFullPath->setChecked(settings->showFullPath());
180 m_filterBar->setChecked(settings->filterBar());
181 }
182
183 #include "startupsettingspage.moc"