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