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