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