]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
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)
48 QFormLayout
* topLayout
= new QFormLayout(this);
51 // create 'Home URL' editor
52 QHBoxLayout
* homeUrlBoxLayout
= new QHBoxLayout();
53 homeUrlBoxLayout
->setMargin(0);
55 m_homeUrl
= new QLineEdit();
56 m_homeUrl
->setClearButtonEnabled(true);
57 homeUrlBoxLayout
->addWidget(m_homeUrl
);
59 QPushButton
* selectHomeUrlButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString());
60 homeUrlBoxLayout
->addWidget(selectHomeUrlButton
);
62 #ifndef QT_NO_ACCESSIBILITY
63 selectHomeUrlButton
->setAccessibleName(i18nc("@action:button", "Select Home Location"));
66 connect(selectHomeUrlButton
, &QPushButton::clicked
,
67 this, &StartupSettingsPage::selectHomeUrl
);
69 QHBoxLayout
* buttonBoxLayout
= new QHBoxLayout();
70 buttonBoxLayout
->setMargin(0);
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
);
81 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout();
82 homeBoxLayout
->setMargin(0);
83 homeBoxLayout
->addLayout(homeUrlBoxLayout
);
84 homeBoxLayout
->addLayout(buttonBoxLayout
);
86 topLayout
->addRow(i18nc("@label:textbox", "Start in:"), homeBoxLayout
);
89 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
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
);
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
);
115 StartupSettingsPage::~StartupSettingsPage()
119 void StartupSettingsPage::applySettings()
121 GeneralSettings
* settings
= GeneralSettings::self();
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
));
128 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
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());
140 void StartupSettingsPage::restoreDefaults()
142 GeneralSettings
* settings
= GeneralSettings::self();
143 settings
->useDefaults(true);
145 settings
->useDefaults(false);
148 void StartupSettingsPage::slotSettingsChanged()
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);
157 void StartupSettingsPage::selectHomeUrl()
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();
167 void StartupSettingsPage::useCurrentLocation()
169 m_homeUrl
->setText(m_url
.toDisplayString(QUrl::PreferLocalFile
));
172 void StartupSettingsPage::useDefaultLocation()
174 m_homeUrl
->setText(QDir::homePath());
177 void StartupSettingsPage::loadSettings()
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());