]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
2c436b541718d1ceb612227c4fe5b083a0322b3c
[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 "dolphinmainwindow.h"
23 #include "dolphinviewcontainer.h"
24
25 #include "dolphin_generalsettings.h"
26
27 #include <KDialog>
28 #include <KFileDialog>
29 #include <KLocalizedString>
30 #include <KLineEdit>
31 #include <KMessageBox>
32 #include <KVBox>
33
34 #include <QVBoxLayout>
35 #include <QCheckBox>
36 #include <QGroupBox>
37 #include <QLabel>
38 #include <QPushButton>
39
40 #include "views/dolphinview.h"
41
42 StartupSettingsPage::StartupSettingsPage(const KUrl& url, QWidget* parent) :
43 SettingsPageBase(parent),
44 m_url(url),
45 m_homeUrl(0),
46 m_splitView(0),
47 m_editableUrl(0),
48 m_showFullPath(0),
49 m_filterBar(0)
50 {
51 const int spacing = KDialog::spacingHint();
52
53 QVBoxLayout* topLayout = new QVBoxLayout(this);
54 KVBox* vBox = new KVBox(this);
55 vBox->setSpacing(spacing);
56
57 // create 'Home URL' editor
58 QGroupBox* homeBox = new QGroupBox(i18nc("@title:group", "Home Folder"), vBox);
59
60 KHBox* homeUrlBox = new KHBox(homeBox);
61 homeUrlBox->setSpacing(spacing);
62
63 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox);
64 m_homeUrl = new KLineEdit(homeUrlBox);
65 m_homeUrl->setClearButtonShown(true);
66
67 QPushButton* selectHomeUrlButton = new QPushButton(QIcon::fromTheme("folder-open"), QString(), homeUrlBox);
68
69 #ifndef QT_NO_ACCESSIBILITY
70 selectHomeUrlButton->setAccessibleName(i18nc("@action:button", "Select Home Location"));
71 #endif
72
73 connect(selectHomeUrlButton, &QPushButton::clicked,
74 this, &StartupSettingsPage::selectHomeUrl);
75
76 KHBox* buttonBox = new KHBox(homeBox);
77 buttonBox->setSpacing(spacing);
78
79 QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox);
80 connect(useCurrentButton, &QPushButton::clicked,
81 this, &StartupSettingsPage::useCurrentLocation);
82 QPushButton* useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox);
83 connect(useDefaultButton, &QPushButton::clicked,
84 this, &StartupSettingsPage::useDefaultLocation);
85
86 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
87 homeBoxLayout->addWidget(homeUrlBox);
88 homeBoxLayout->addWidget(buttonBox);
89
90 // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes
91 m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox);
92 m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox);
93 m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox);
94 m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox);
95
96 // Add a dummy widget with no restriction regarding
97 // a vertical resizing. This assures that the dialog layout
98 // is not stretched vertically.
99 new QWidget(vBox);
100
101 topLayout->addWidget(vBox);
102
103 loadSettings();
104
105 connect(m_homeUrl, &KLineEdit::textChanged, this, &StartupSettingsPage::slotSettingsChanged);
106 connect(m_splitView, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged);
107 connect(m_editableUrl, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged);
108 connect(m_showFullPath, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged);
109 connect(m_filterBar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged);
110 }
111
112 StartupSettingsPage::~StartupSettingsPage()
113 {
114 }
115
116 void StartupSettingsPage::applySettings()
117 {
118 GeneralSettings* settings = GeneralSettings::self();
119
120 const KUrl url(m_homeUrl->text());
121 KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url);
122 if ((url.isValid() && fileItem.isDir()) || (url.protocol() == QLatin1String("timeline"))) {
123 settings->setHomeUrl(url.prettyUrl());
124 } else {
125 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
126 }
127
128 settings->setSplitView(m_splitView->isChecked());
129 settings->setEditableUrl(m_editableUrl->isChecked());
130 settings->setShowFullPath(m_showFullPath->isChecked());
131 settings->setFilterBar(m_filterBar->isChecked());
132
133 settings->writeConfig();
134 }
135
136 void StartupSettingsPage::restoreDefaults()
137 {
138 GeneralSettings* settings = GeneralSettings::self();
139 settings->useDefaults(true);
140 loadSettings();
141 settings->useDefaults(false);
142 }
143
144 void StartupSettingsPage::slotSettingsChanged()
145 {
146 // Provide a hint that the startup settings have been changed. This allows the views
147 // to apply the startup settings only if they have been explicitly changed by the user
148 // (see bug #254947).
149 GeneralSettings::setModifiedStartupSettings(true);
150 emit changed();
151 }
152
153 void StartupSettingsPage::selectHomeUrl()
154 {
155 const QString homeUrl = m_homeUrl->text();
156 KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl, this);
157 if (!url.isEmpty()) {
158 m_homeUrl->setText(url.prettyUrl());
159 slotSettingsChanged();
160 }
161 }
162
163 void StartupSettingsPage::useCurrentLocation()
164 {
165 m_homeUrl->setText(m_url.prettyUrl());
166 }
167
168 void StartupSettingsPage::useDefaultLocation()
169 {
170 KUrl url(QDir::homePath());
171 m_homeUrl->setText(url.prettyUrl());
172 }
173
174 void StartupSettingsPage::loadSettings()
175 {
176 const KUrl url(GeneralSettings::homeUrl());
177 m_homeUrl->setText(url.prettyUrl());
178 m_splitView->setChecked(GeneralSettings::splitView());
179 m_editableUrl->setChecked(GeneralSettings::editableUrl());
180 m_showFullPath->setChecked(GeneralSettings::showFullPath());
181 m_filterBar->setChecked(GeneralSettings::filterBar());
182 }
183