2 * SPDX-FileCopyrightText: 2008 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "startupsettingspage.h"
9 #include "dolphin_generalsettings.h"
10 #include "dolphinmainwindow.h"
11 #include "dolphinviewcontainer.h"
14 #include <KLocalizedString>
15 #include <KMessageBox>
17 #include <QButtonGroup>
19 #include <QFileDialog>
21 #include <QPushButton>
22 #include <QRadioButton>
23 #include <QFormLayout>
24 #include <QGridLayout>
25 #include <QHBoxLayout>
27 StartupSettingsPage::StartupSettingsPage(const QUrl
& url
, QWidget
* parent
) :
28 SettingsPageBase(parent
),
31 m_homeUrlBoxLayoutContainer(nullptr),
32 m_buttonBoxLayoutContainer(nullptr),
33 m_rememberOpenedTabsRadioButton(nullptr),
34 m_homeUrlRadioButton(nullptr),
36 m_editableUrl(nullptr),
37 m_showFullPath(nullptr),
39 m_showFullPathInTitlebar(nullptr),
40 m_openExternallyCalledFolderInNewTab(nullptr)
42 QFormLayout
* topLayout
= new QFormLayout(this);
44 m_rememberOpenedTabsRadioButton
= new QRadioButton(i18nc("@option:radio Startup Settings", "Folders, tabs, and window state from last time"));
45 m_homeUrlRadioButton
= new QRadioButton();
46 // HACK: otherwise the radio button has too much spacing in a grid layout
47 m_homeUrlRadioButton
->setMaximumWidth(24);
49 QButtonGroup
* initialViewGroup
= new QButtonGroup(this);
50 initialViewGroup
->addButton(m_rememberOpenedTabsRadioButton
);
51 initialViewGroup
->addButton(m_homeUrlRadioButton
);
54 // create 'Home URL' editor
55 m_homeUrlBoxLayoutContainer
= new QWidget(this);
56 QHBoxLayout
* homeUrlBoxLayout
= new QHBoxLayout(m_homeUrlBoxLayoutContainer
);
57 homeUrlBoxLayout
->setContentsMargins(0, 0, 0, 0);
59 m_homeUrl
= new QLineEdit();
60 m_homeUrl
->setClearButtonEnabled(true);
61 homeUrlBoxLayout
->addWidget(m_homeUrl
);
63 QPushButton
* selectHomeUrlButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString());
64 homeUrlBoxLayout
->addWidget(selectHomeUrlButton
);
66 #ifndef QT_NO_ACCESSIBILITY
67 selectHomeUrlButton
->setAccessibleName(i18nc("@action:button", "Select Home Location"));
70 connect(selectHomeUrlButton
, &QPushButton::clicked
,
71 this, &StartupSettingsPage::selectHomeUrl
);
73 m_buttonBoxLayoutContainer
= new QWidget(this);
74 QHBoxLayout
* buttonBoxLayout
= new QHBoxLayout(m_buttonBoxLayoutContainer
);
75 buttonBoxLayout
->setContentsMargins(0, 0, 0, 0);
77 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"));
78 buttonBoxLayout
->addWidget(useCurrentButton
);
79 connect(useCurrentButton
, &QPushButton::clicked
,
80 this, &StartupSettingsPage::useCurrentLocation
);
81 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"));
82 buttonBoxLayout
->addWidget(useDefaultButton
);
83 connect(useDefaultButton
, &QPushButton::clicked
,
84 this, &StartupSettingsPage::useDefaultLocation
);
86 QGridLayout
* startInLocationLayout
= new QGridLayout();
87 startInLocationLayout
->setHorizontalSpacing(0);
88 startInLocationLayout
->setContentsMargins(0, 0, 0, 0);
89 startInLocationLayout
->addWidget(m_homeUrlRadioButton
, 0, 0);
90 startInLocationLayout
->addWidget(m_homeUrlBoxLayoutContainer
, 0, 1);
91 startInLocationLayout
->addWidget(m_buttonBoxLayoutContainer
, 1, 1);
93 topLayout
->addRow(i18nc("@label:textbox", "Show on startup:"), m_rememberOpenedTabsRadioButton
);
94 topLayout
->addRow(QString(), startInLocationLayout
);
97 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
99 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Begin in split view mode"));
100 topLayout
->addRow(i18n("New windows:"), m_splitView
);
101 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"));
102 topLayout
->addRow(QString(), m_filterBar
);
103 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Make location bar editable"));
104 topLayout
->addRow(QString(), m_editableUrl
);
106 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
108 m_openExternallyCalledFolderInNewTab
= new QCheckBox(i18nc("@option:check Startup Settings", "Open new folders in tabs"));
109 topLayout
->addRow(i18nc("@label:checkbox", "General:"), m_openExternallyCalledFolderInNewTab
);
110 m_showFullPath
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"));
111 topLayout
->addRow(QString(), m_showFullPath
);
112 m_showFullPathInTitlebar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path in title bar"));
113 topLayout
->addRow(QString(), m_showFullPathInTitlebar
);
117 updateInitialViewOptions();
119 connect(m_homeUrl
, &QLineEdit::textChanged
, this, &StartupSettingsPage::slotSettingsChanged
);
120 connect(m_rememberOpenedTabsRadioButton
, &QRadioButton::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
121 connect(m_homeUrlRadioButton
, &QRadioButton::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
123 connect(m_splitView
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
124 connect(m_editableUrl
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
125 connect(m_filterBar
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
127 connect(m_openExternallyCalledFolderInNewTab
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
128 connect(m_showFullPath
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
129 connect(m_showFullPathInTitlebar
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
132 StartupSettingsPage::~StartupSettingsPage()
136 void StartupSettingsPage::applySettings()
138 GeneralSettings
* settings
= GeneralSettings::self();
140 const QUrl
url(QUrl::fromUserInput(m_homeUrl
->text(), QString(), QUrl::AssumeLocalFile
));
141 KFileItem
fileItem(url
);
142 if ((url
.isValid() && fileItem
.isDir()) || (url
.scheme() == QLatin1String("timeline"))) {
143 settings
->setHomeUrl(url
.toDisplayString(QUrl::PreferLocalFile
));
145 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
148 // Remove saved state if "remember open tabs" has been turned off
149 if (!m_rememberOpenedTabsRadioButton
->isChecked()) {
150 KConfigGroup windowState
{KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "WindowState"};
151 if (windowState
.exists()) {
152 windowState
.deleteGroup();
156 settings
->setRememberOpenedTabs(m_rememberOpenedTabsRadioButton
->isChecked());
157 settings
->setSplitView(m_splitView
->isChecked());
158 settings
->setEditableUrl(m_editableUrl
->isChecked());
159 settings
->setFilterBar(m_filterBar
->isChecked());
160 settings
->setOpenExternallyCalledFolderInNewTab(m_openExternallyCalledFolderInNewTab
->isChecked());
161 settings
->setShowFullPath(m_showFullPath
->isChecked());
162 settings
->setShowFullPathInTitlebar(m_showFullPathInTitlebar
->isChecked());
166 void StartupSettingsPage::restoreDefaults()
168 GeneralSettings
* settings
= GeneralSettings::self();
169 settings
->useDefaults(true);
171 settings
->useDefaults(false);
174 void StartupSettingsPage::slotSettingsChanged()
176 // Provide a hint that the startup settings have been changed. This allows the views
177 // to apply the startup settings only if they have been explicitly changed by the user
178 // (see bug #254947).
179 GeneralSettings::setModifiedStartupSettings(true);
181 // Enable and disable home URL controls appropriately
182 updateInitialViewOptions();
186 void StartupSettingsPage::updateInitialViewOptions()
188 m_homeUrlBoxLayoutContainer
->setEnabled(m_homeUrlRadioButton
->isChecked());
189 m_buttonBoxLayoutContainer
->setEnabled(m_homeUrlRadioButton
->isChecked());
192 void StartupSettingsPage::selectHomeUrl()
194 const QUrl
homeUrl(QUrl::fromUserInput(m_homeUrl
->text(), QString(), QUrl::AssumeLocalFile
));
195 QUrl url
= QFileDialog::getExistingDirectoryUrl(this, QString(), homeUrl
);
196 if (!url
.isEmpty()) {
197 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
198 slotSettingsChanged();
202 void StartupSettingsPage::useCurrentLocation()
204 m_homeUrl
->setText(m_url
.toDisplayString(QUrl::PreferLocalFile
));
207 void StartupSettingsPage::useDefaultLocation()
209 m_homeUrl
->setText(QDir::homePath());
212 void StartupSettingsPage::loadSettings()
214 const QUrl
url(Dolphin::homeUrl());
215 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
216 m_rememberOpenedTabsRadioButton
->setChecked(GeneralSettings::rememberOpenedTabs());
217 m_homeUrlRadioButton
->setChecked(!GeneralSettings::rememberOpenedTabs());
218 m_splitView
->setChecked(GeneralSettings::splitView());
219 m_editableUrl
->setChecked(GeneralSettings::editableUrl());
220 m_showFullPath
->setChecked(GeneralSettings::showFullPath());
221 m_filterBar
->setChecked(GeneralSettings::filterBar());
222 m_showFullPathInTitlebar
->setChecked(GeneralSettings::showFullPathInTitlebar());
223 m_openExternallyCalledFolderInNewTab
->setChecked(GeneralSettings::openExternallyCalledFolderInNewTab());