]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
3bf922dfe4deeb8c4aa34716ef3a84760ae6e293
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 "dolphinmainwindow.h"
23 #include "dolphinviewcontainer.h"
25 #include "dolphin_generalsettings.h"
28 #include <KFileDialog>
29 #include <KLocalizedString>
31 #include <KMessageBox>
33 #include <QVBoxLayout>
37 #include <QPushButton>
38 #include <QHBoxLayout>
39 #include <QVBoxLayout>
41 #include "views/dolphinview.h"
43 StartupSettingsPage::StartupSettingsPage(const QUrl
& url
, QWidget
* parent
) :
44 SettingsPageBase(parent
),
52 const int spacing
= KDialog::spacingHint();
54 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
55 QWidget
* vBox
= new QWidget(this);
56 QVBoxLayout
*vBoxLayout
= new QVBoxLayout(vBox
);
57 vBoxLayout
->setMargin(0);
58 vBoxLayout
->setSpacing(spacing
);
59 vBoxLayout
->setAlignment(Qt::AlignTop
);
61 // create 'Home URL' editor
62 QGroupBox
* homeBox
= new QGroupBox(i18nc("@title:group", "Home Folder"), vBox
);
63 vBoxLayout
->addWidget(homeBox
);
65 QWidget
* homeUrlBox
= new QWidget(homeBox
);
66 QHBoxLayout
*homeUrlBoxLayout
= new QHBoxLayout(homeUrlBox
);
67 homeUrlBoxLayout
->setMargin(0);
68 homeUrlBoxLayout
->setSpacing(spacing
);
70 QLabel
* homeUrlLabel
= new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox
);
71 homeUrlBoxLayout
->addWidget(homeUrlLabel
);
72 m_homeUrl
= new QLineEdit(homeUrlBox
);
73 homeUrlBoxLayout
->addWidget(m_homeUrl
);
74 m_homeUrl
->setClearButtonEnabled(true);
76 QPushButton
* selectHomeUrlButton
= new QPushButton(QIcon::fromTheme("folder-open"), QString(), homeUrlBox
);
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 QWidget
* buttonBox
= new QWidget(homeBox
);
87 QHBoxLayout
*buttonBoxLayout
= new QHBoxLayout(buttonBox
);
88 buttonBoxLayout
->setMargin(0);
89 buttonBoxLayout
->setSpacing(spacing
);
91 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox
);
92 buttonBoxLayout
->addWidget(useCurrentButton
);
93 connect(useCurrentButton
, &QPushButton::clicked
,
94 this, &StartupSettingsPage::useCurrentLocation
);
95 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox
);
96 buttonBoxLayout
->addWidget(useDefaultButton
);
97 connect(useDefaultButton
, &QPushButton::clicked
,
98 this, &StartupSettingsPage::useDefaultLocation
);
100 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout(homeBox
);
101 homeBoxLayout
->addWidget(homeUrlBox
);
102 homeBoxLayout
->addWidget(buttonBox
);
104 // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes
105 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox
);
106 vBoxLayout
->addWidget(m_splitView
);
107 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox
);
108 vBoxLayout
->addWidget(m_editableUrl
);
109 m_showFullPath
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox
);
110 vBoxLayout
->addWidget(m_showFullPath
);
111 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox
);
112 vBoxLayout
->addWidget(m_filterBar
);
114 // Add a dummy widget with no restriction regarding
115 // a vertical resizing. This assures that the dialog layout
116 // is not stretched vertically.
119 topLayout
->addWidget(vBox
);
123 connect(m_homeUrl
, &QLineEdit::textChanged
, this, &StartupSettingsPage::slotSettingsChanged
);
124 connect(m_splitView
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
125 connect(m_editableUrl
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
126 connect(m_showFullPath
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
127 connect(m_filterBar
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
130 StartupSettingsPage::~StartupSettingsPage()
134 void StartupSettingsPage::applySettings()
136 GeneralSettings
* settings
= GeneralSettings::self();
138 const QUrl
url(QUrl::fromLocalFile(m_homeUrl
->text()));
139 KFileItem
fileItem(url
);
140 if ((url
.isValid() && fileItem
.isDir()) || (url
.scheme() == QLatin1String("timeline"))) {
141 settings
->setHomeUrl(url
.toDisplayString(QUrl::PreferLocalFile
));
143 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
146 settings
->setSplitView(m_splitView
->isChecked());
147 settings
->setEditableUrl(m_editableUrl
->isChecked());
148 settings
->setShowFullPath(m_showFullPath
->isChecked());
149 settings
->setFilterBar(m_filterBar
->isChecked());
151 settings
->writeConfig();
154 void StartupSettingsPage::restoreDefaults()
156 GeneralSettings
* settings
= GeneralSettings::self();
157 settings
->useDefaults(true);
159 settings
->useDefaults(false);
162 void StartupSettingsPage::slotSettingsChanged()
164 // Provide a hint that the startup settings have been changed. This allows the views
165 // to apply the startup settings only if they have been explicitly changed by the user
166 // (see bug #254947).
167 GeneralSettings::setModifiedStartupSettings(true);
171 void StartupSettingsPage::selectHomeUrl()
173 const QString homeUrl
= m_homeUrl
->text();
174 QUrl url
= KFileDialog::getExistingDirectoryUrl(QUrl::fromLocalFile(homeUrl
), this);
175 if (!url
.isEmpty()) {
176 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
177 slotSettingsChanged();
181 void StartupSettingsPage::useCurrentLocation()
183 m_homeUrl
->setText(m_url
.toDisplayString(QUrl::PreferLocalFile
));
186 void StartupSettingsPage::useDefaultLocation()
188 m_homeUrl
->setText(QDir::homePath());
191 void StartupSettingsPage::loadSettings()
193 const QUrl
url(QUrl::fromLocalFile(GeneralSettings::homeUrl()));
194 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
195 m_splitView
->setChecked(GeneralSettings::splitView());
196 m_editableUrl
->setChecked(GeneralSettings::editableUrl());
197 m_showFullPath
->setChecked(GeneralSettings::showFullPath());
198 m_filterBar
->setChecked(GeneralSettings::filterBar());