]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
Merge branch 'master' into frameworks
[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 <KFileDialog>
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 <QHBoxLayout>
38 #include <QVBoxLayout>
39
40 #include "views/dolphinview.h"
41
42 StartupSettingsPage::StartupSettingsPage(const QUrl& 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 QVBoxLayout* topLayout = new QVBoxLayout(this);
52 QWidget* vBox = new QWidget(this);
53 QVBoxLayout *vBoxLayout = new QVBoxLayout(vBox);
54 vBoxLayout->setMargin(0);
55 vBoxLayout->setAlignment(Qt::AlignTop);
56
57 // create 'Home URL' editor
58 QGroupBox* homeBox = new QGroupBox(i18nc("@title:group", "Home Folder"), vBox);
59 vBoxLayout->addWidget(homeBox);
60
61 QWidget* homeUrlBox = new QWidget(homeBox);
62 QHBoxLayout *homeUrlBoxLayout = new QHBoxLayout(homeUrlBox);
63 homeUrlBoxLayout->setMargin(0);
64
65 QLabel* homeUrlLabel = new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox);
66 homeUrlBoxLayout->addWidget(homeUrlLabel);
67 m_homeUrl = new QLineEdit(homeUrlBox);
68 homeUrlBoxLayout->addWidget(m_homeUrl);
69 m_homeUrl->setClearButtonEnabled(true);
70
71 QPushButton* selectHomeUrlButton = new QPushButton(QIcon::fromTheme("folder-open"), QString(), homeUrlBox);
72 homeUrlBoxLayout->addWidget(selectHomeUrlButton);
73
74 #ifndef QT_NO_ACCESSIBILITY
75 selectHomeUrlButton->setAccessibleName(i18nc("@action:button", "Select Home Location"));
76 #endif
77
78 connect(selectHomeUrlButton, &QPushButton::clicked,
79 this, &StartupSettingsPage::selectHomeUrl);
80
81 QWidget* buttonBox = new QWidget(homeBox);
82 QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
83 buttonBoxLayout->setMargin(0);
84
85 QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox);
86 buttonBoxLayout->addWidget(useCurrentButton);
87 connect(useCurrentButton, &QPushButton::clicked,
88 this, &StartupSettingsPage::useCurrentLocation);
89 QPushButton* useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox);
90 buttonBoxLayout->addWidget(useDefaultButton);
91 connect(useDefaultButton, &QPushButton::clicked,
92 this, &StartupSettingsPage::useDefaultLocation);
93
94 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
95 homeBoxLayout->addWidget(homeUrlBox);
96 homeBoxLayout->addWidget(buttonBox);
97
98 // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes
99 m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox);
100 vBoxLayout->addWidget(m_splitView);
101 m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox);
102 vBoxLayout->addWidget(m_editableUrl);
103 m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox);
104 vBoxLayout->addWidget(m_showFullPath);
105 m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox);
106 vBoxLayout->addWidget(m_filterBar);
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 }
123
124 StartupSettingsPage::~StartupSettingsPage()
125 {
126 }
127
128 void StartupSettingsPage::applySettings()
129 {
130 GeneralSettings* settings = GeneralSettings::self();
131
132 const QUrl url(QUrl::fromLocalFile(m_homeUrl->text()));
133 KFileItem fileItem(url);
134 if ((url.isValid() && fileItem.isDir()) || (url.scheme() == QLatin1String("timeline"))) {
135 settings->setHomeUrl(url.toDisplayString(QUrl::PreferLocalFile));
136 } else {
137 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
138 }
139
140 settings->setSplitView(m_splitView->isChecked());
141 settings->setEditableUrl(m_editableUrl->isChecked());
142 settings->setShowFullPath(m_showFullPath->isChecked());
143 settings->setFilterBar(m_filterBar->isChecked());
144
145 settings->save();
146 }
147
148 void StartupSettingsPage::restoreDefaults()
149 {
150 GeneralSettings* settings = GeneralSettings::self();
151 settings->useDefaults(true);
152 loadSettings();
153 settings->useDefaults(false);
154 }
155
156 void StartupSettingsPage::slotSettingsChanged()
157 {
158 // Provide a hint that the startup settings have been changed. This allows the views
159 // to apply the startup settings only if they have been explicitly changed by the user
160 // (see bug #254947).
161 GeneralSettings::setModifiedStartupSettings(true);
162 emit changed();
163 }
164
165 void StartupSettingsPage::selectHomeUrl()
166 {
167 const QString homeUrl = m_homeUrl->text();
168 QUrl url = KFileDialog::getExistingDirectoryUrl(QUrl::fromLocalFile(homeUrl), this);
169 if (!url.isEmpty()) {
170 m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile));
171 slotSettingsChanged();
172 }
173 }
174
175 void StartupSettingsPage::useCurrentLocation()
176 {
177 m_homeUrl->setText(m_url.toDisplayString(QUrl::PreferLocalFile));
178 }
179
180 void StartupSettingsPage::useDefaultLocation()
181 {
182 m_homeUrl->setText(QDir::homePath());
183 }
184
185 void StartupSettingsPage::loadSettings()
186 {
187 const QUrl url(QUrl::fromLocalFile(GeneralSettings::homeUrl()));
188 m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile));
189 m_splitView->setChecked(GeneralSettings::splitView());
190 m_editableUrl->setChecked(GeneralSettings::editableUrl());
191 m_showFullPath->setChecked(GeneralSettings::showFullPath());
192 m_filterBar->setChecked(GeneralSettings::filterBar());
193 }