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