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>
30 #include <QButtonGroup>
32 #include <QFileDialog>
34 #include <QPushButton>
35 #include <QRadioButton>
36 #include <QFormLayout>
37 #include <QGridLayout>
38 #include <QHBoxLayout>
40 StartupSettingsPage::StartupSettingsPage(const QUrl
& url
, QWidget
* parent
) :
41 SettingsPageBase(parent
),
44 m_homeUrlBoxLayoutContainer(nullptr),
45 m_buttonBoxLayoutContainer(nullptr),
46 m_rememberOpenedTabsRadioButton(nullptr),
47 m_homeUrlRadioButton(nullptr),
49 m_editableUrl(nullptr),
50 m_showFullPath(nullptr),
52 m_showFullPathInTitlebar(nullptr),
53 m_openExternallyCalledFolderInNewTab(nullptr)
55 QFormLayout
* topLayout
= new QFormLayout(this);
57 m_rememberOpenedTabsRadioButton
= new QRadioButton(i18nc("@option:radio Startup Settings", "Folders, tabs, and window state from last time"));
58 m_homeUrlRadioButton
= new QRadioButton();
59 // HACK: otherwise the radio button has too much spacing in a grid layout
60 m_homeUrlRadioButton
->setMaximumWidth(24);
62 QButtonGroup
* initialViewGroup
= new QButtonGroup(this);
63 initialViewGroup
->addButton(m_rememberOpenedTabsRadioButton
);
64 initialViewGroup
->addButton(m_homeUrlRadioButton
);
67 // create 'Home URL' editor
68 m_homeUrlBoxLayoutContainer
= new QWidget(this);
69 QHBoxLayout
* homeUrlBoxLayout
= new QHBoxLayout(m_homeUrlBoxLayoutContainer
);
70 homeUrlBoxLayout
->setContentsMargins(0, 0, 0, 0);
72 m_homeUrl
= new QLineEdit();
73 m_homeUrl
->setClearButtonEnabled(true);
74 homeUrlBoxLayout
->addWidget(m_homeUrl
);
76 QPushButton
* selectHomeUrlButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString());
77 homeUrlBoxLayout
->addWidget(selectHomeUrlButton
);
79 #ifndef QT_NO_ACCESSIBILITY
80 selectHomeUrlButton
->setAccessibleName(i18nc("@action:button", "Select Home Location"));
83 connect(selectHomeUrlButton
, &QPushButton::clicked
,
84 this, &StartupSettingsPage::selectHomeUrl
);
86 m_buttonBoxLayoutContainer
= new QWidget(this);
87 QHBoxLayout
* buttonBoxLayout
= new QHBoxLayout(m_buttonBoxLayoutContainer
);
88 buttonBoxLayout
->setContentsMargins(0, 0, 0, 0);
90 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"));
91 buttonBoxLayout
->addWidget(useCurrentButton
);
92 connect(useCurrentButton
, &QPushButton::clicked
,
93 this, &StartupSettingsPage::useCurrentLocation
);
94 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"));
95 buttonBoxLayout
->addWidget(useDefaultButton
);
96 connect(useDefaultButton
, &QPushButton::clicked
,
97 this, &StartupSettingsPage::useDefaultLocation
);
99 QGridLayout
* startInLocationLayout
= new QGridLayout();
100 startInLocationLayout
->setHorizontalSpacing(0);
101 startInLocationLayout
->setContentsMargins(0, 0, 0, 0);
102 startInLocationLayout
->addWidget(m_homeUrlRadioButton
, 0, 0);
103 startInLocationLayout
->addWidget(m_homeUrlBoxLayoutContainer
, 0, 1);
104 startInLocationLayout
->addWidget(m_buttonBoxLayoutContainer
, 1, 1);
106 topLayout
->addRow(i18nc("@label:textbox", "Show on startup:"), m_rememberOpenedTabsRadioButton
);
107 topLayout
->addRow(QString(), startInLocationLayout
);
110 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
112 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Begin in split view mode"));
113 topLayout
->addRow(i18n("New windows:"), m_splitView
);
114 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"));
115 topLayout
->addRow(QString(), m_filterBar
);
116 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Make location bar editable"));
117 topLayout
->addRow(QString(), m_editableUrl
);
119 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
121 m_openExternallyCalledFolderInNewTab
= new QCheckBox(i18nc("@option:check Startup Settings", "Open new folders in tabs"));
122 topLayout
->addRow(i18nc("@label:checkbox", "General:"), m_openExternallyCalledFolderInNewTab
);
123 m_showFullPath
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"));
124 topLayout
->addRow(QString(), m_showFullPath
);
125 m_showFullPathInTitlebar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path in title bar"));
126 topLayout
->addRow(QString(), m_showFullPathInTitlebar
);
130 updateInitialViewOptions();
132 connect(m_homeUrl
, &QLineEdit::textChanged
, this, &StartupSettingsPage::slotSettingsChanged
);
133 connect(m_rememberOpenedTabsRadioButton
, &QRadioButton::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
134 connect(m_homeUrlRadioButton
, &QRadioButton::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
136 connect(m_splitView
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
137 connect(m_editableUrl
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
138 connect(m_filterBar
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
140 connect(m_openExternallyCalledFolderInNewTab
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
141 connect(m_showFullPath
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
142 connect(m_showFullPathInTitlebar
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
145 StartupSettingsPage::~StartupSettingsPage()
149 void StartupSettingsPage::applySettings()
151 GeneralSettings
* settings
= GeneralSettings::self();
153 const QUrl
url(QUrl::fromUserInput(m_homeUrl
->text(), QString(), QUrl::AssumeLocalFile
));
154 KFileItem
fileItem(url
);
155 if ((url
.isValid() && fileItem
.isDir()) || (url
.scheme() == QLatin1String("timeline"))) {
156 settings
->setHomeUrl(url
.toDisplayString(QUrl::PreferLocalFile
));
158 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
161 // Remove saved state if "remember open tabs" has been turned off
162 if (!m_rememberOpenedTabsRadioButton
->isChecked()) {
163 KConfigGroup windowState
{KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "WindowState"};
164 if (windowState
.exists()) {
165 windowState
.deleteGroup();
169 settings
->setRememberOpenedTabs(m_rememberOpenedTabsRadioButton
->isChecked());
170 settings
->setSplitView(m_splitView
->isChecked());
171 settings
->setEditableUrl(m_editableUrl
->isChecked());
172 settings
->setFilterBar(m_filterBar
->isChecked());
173 settings
->setOpenExternallyCalledFolderInNewTab(m_openExternallyCalledFolderInNewTab
->isChecked());
174 settings
->setShowFullPath(m_showFullPath
->isChecked());
175 settings
->setShowFullPathInTitlebar(m_showFullPathInTitlebar
->isChecked());
179 void StartupSettingsPage::restoreDefaults()
181 GeneralSettings
* settings
= GeneralSettings::self();
182 settings
->useDefaults(true);
184 settings
->useDefaults(false);
187 void StartupSettingsPage::slotSettingsChanged()
189 // Provide a hint that the startup settings have been changed. This allows the views
190 // to apply the startup settings only if they have been explicitly changed by the user
191 // (see bug #254947).
192 GeneralSettings::setModifiedStartupSettings(true);
194 // Enable and disable home URL controls appropriately
195 updateInitialViewOptions();
199 void StartupSettingsPage::updateInitialViewOptions()
201 m_homeUrlBoxLayoutContainer
->setEnabled(m_homeUrlRadioButton
->isChecked());
202 m_buttonBoxLayoutContainer
->setEnabled(m_homeUrlRadioButton
->isChecked());
205 void StartupSettingsPage::selectHomeUrl()
207 const QUrl
homeUrl(QUrl::fromUserInput(m_homeUrl
->text(), QString(), QUrl::AssumeLocalFile
));
208 QUrl url
= QFileDialog::getExistingDirectoryUrl(this, QString(), homeUrl
);
209 if (!url
.isEmpty()) {
210 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
211 slotSettingsChanged();
215 void StartupSettingsPage::useCurrentLocation()
217 m_homeUrl
->setText(m_url
.toDisplayString(QUrl::PreferLocalFile
));
220 void StartupSettingsPage::useDefaultLocation()
222 m_homeUrl
->setText(QDir::homePath());
225 void StartupSettingsPage::loadSettings()
227 const QUrl
url(Dolphin::homeUrl());
228 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
229 m_rememberOpenedTabsRadioButton
->setChecked(GeneralSettings::rememberOpenedTabs());
230 m_homeUrlRadioButton
->setChecked(!GeneralSettings::rememberOpenedTabs());
231 m_splitView
->setChecked(GeneralSettings::splitView());
232 m_editableUrl
->setChecked(GeneralSettings::editableUrl());
233 m_showFullPath
->setChecked(GeneralSettings::showFullPath());
234 m_filterBar
->setChecked(GeneralSettings::filterBar());
235 m_showFullPathInTitlebar
->setChecked(GeneralSettings::showFullPathInTitlebar());
236 m_openExternallyCalledFolderInNewTab
->setChecked(GeneralSettings::openExternallyCalledFolderInNewTab());