1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #include "startupsettingspage.h"
22 #include "dolphin_generalsettings.h"
23 #include "dolphinmainwindow.h"
24 #include "dolphinviewcontainer.h"
27 #include <KLocalizedString>
28 #include <KMessageBox>
31 #include <QFileDialog>
33 #include <QPushButton>
34 #include <QFormLayout>
35 #include <QHBoxLayout>
36 #include <QVBoxLayout>
38 StartupSettingsPage::StartupSettingsPage(const QUrl
& url
, QWidget
* parent
) :
39 SettingsPageBase(parent
),
43 m_editableUrl(nullptr),
44 m_showFullPath(nullptr),
46 m_showFullPathInTitlebar(nullptr),
47 m_openExternallyCalledFolderInNewTab(nullptr)
49 QFormLayout
* topLayout
= new QFormLayout(this);
52 // create 'Home URL' editor
53 QHBoxLayout
* homeUrlBoxLayout
= new QHBoxLayout();
54 homeUrlBoxLayout
->setContentsMargins(0, 0, 0, 0);
56 m_homeUrl
= new QLineEdit();
57 m_homeUrl
->setClearButtonEnabled(true);
58 homeUrlBoxLayout
->addWidget(m_homeUrl
);
60 QPushButton
* selectHomeUrlButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString());
61 homeUrlBoxLayout
->addWidget(selectHomeUrlButton
);
63 #ifndef QT_NO_ACCESSIBILITY
64 selectHomeUrlButton
->setAccessibleName(i18nc("@action:button", "Select Home Location"));
67 connect(selectHomeUrlButton
, &QPushButton::clicked
,
68 this, &StartupSettingsPage::selectHomeUrl
);
70 QHBoxLayout
* buttonBoxLayout
= new QHBoxLayout();
71 buttonBoxLayout
->setContentsMargins(0, 0, 0, 0);
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
);
82 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout();
83 homeBoxLayout
->setContentsMargins(0, 0, 0, 0);
84 homeBoxLayout
->addLayout(homeUrlBoxLayout
);
85 homeBoxLayout
->addLayout(buttonBoxLayout
);
87 topLayout
->addRow(i18nc("@label:textbox", "Start in:"), homeBoxLayout
);
90 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
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
);
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
);
119 StartupSettingsPage::~StartupSettingsPage()
123 void StartupSettingsPage::applySettings()
125 GeneralSettings
* settings
= GeneralSettings::self();
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
));
132 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
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());
144 void StartupSettingsPage::restoreDefaults()
146 GeneralSettings
* settings
= GeneralSettings::self();
147 settings
->useDefaults(true);
149 settings
->useDefaults(false);
152 void StartupSettingsPage::slotSettingsChanged()
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);
161 void StartupSettingsPage::selectHomeUrl()
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();
171 void StartupSettingsPage::useCurrentLocation()
173 m_homeUrl
->setText(m_url
.toDisplayString(QUrl::PreferLocalFile
));
176 void StartupSettingsPage::useDefaultLocation()
178 m_homeUrl
->setText(QDir::homePath());
181 void StartupSettingsPage::loadSettings()
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());