]>
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 "dolphinmainwindow.h"
23 #include "dolphinviewcontainer.h"
25 #include "dolphin_generalsettings.h"
27 #include <KLocalizedString>
29 #include <KMessageBox>
31 #include <QVBoxLayout>
35 #include <QPushButton>
36 #include <QHBoxLayout>
37 #include <QVBoxLayout>
38 #include <QFileDialog>
40 #include "views/dolphinview.h"
42 StartupSettingsPage::StartupSettingsPage(const QUrl
& url
, QWidget
* parent
) :
43 SettingsPageBase(parent
),
51 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
52 QWidget
* vBox
= new QWidget(this);
53 QVBoxLayout
*vBoxLayout
= new QVBoxLayout(vBox
);
54 vBoxLayout
->setMargin(0);
55 vBoxLayout
->setAlignment(Qt::AlignTop
);
57 // create 'Home URL' editor
58 QGroupBox
* homeBox
= new QGroupBox(i18nc("@title:group", "Home Folder"), vBox
);
59 vBoxLayout
->addWidget(homeBox
);
61 QWidget
* homeUrlBox
= new QWidget(homeBox
);
62 QHBoxLayout
*homeUrlBoxLayout
= new QHBoxLayout(homeUrlBox
);
63 homeUrlBoxLayout
->setMargin(0);
65 QLabel
* homeUrlLabel
= new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox
);
66 homeUrlBoxLayout
->addWidget(homeUrlLabel
);
67 m_homeUrl
= new QLineEdit(homeUrlBox
);
68 homeUrlBoxLayout
->addWidget(m_homeUrl
);
69 m_homeUrl
->setClearButtonEnabled(true);
71 QPushButton
* selectHomeUrlButton
= new QPushButton(QIcon::fromTheme("folder-open"), QString(), homeUrlBox
);
72 homeUrlBoxLayout
->addWidget(selectHomeUrlButton
);
74 #ifndef QT_NO_ACCESSIBILITY
75 selectHomeUrlButton
->setAccessibleName(i18nc("@action:button", "Select Home Location"));
78 connect(selectHomeUrlButton
, &QPushButton::clicked
,
79 this, &StartupSettingsPage::selectHomeUrl
);
81 QWidget
* buttonBox
= new QWidget(homeBox
);
82 QHBoxLayout
*buttonBoxLayout
= new QHBoxLayout(buttonBox
);
83 buttonBoxLayout
->setMargin(0);
85 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox
);
86 buttonBoxLayout
->addWidget(useCurrentButton
);
87 connect(useCurrentButton
, &QPushButton::clicked
,
88 this, &StartupSettingsPage::useCurrentLocation
);
89 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox
);
90 buttonBoxLayout
->addWidget(useDefaultButton
);
91 connect(useDefaultButton
, &QPushButton::clicked
,
92 this, &StartupSettingsPage::useDefaultLocation
);
94 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout(homeBox
);
95 homeBoxLayout
->addWidget(homeUrlBox
);
96 homeBoxLayout
->addWidget(buttonBox
);
98 // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes
99 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox
);
100 vBoxLayout
->addWidget(m_splitView
);
101 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox
);
102 vBoxLayout
->addWidget(m_editableUrl
);
103 m_showFullPath
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox
);
104 vBoxLayout
->addWidget(m_showFullPath
);
105 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox
);
106 vBoxLayout
->addWidget(m_filterBar
);
108 // Add a dummy widget with no restriction regarding
109 // a vertical resizing. This assures that the dialog layout
110 // is not stretched vertically.
113 topLayout
->addWidget(vBox
);
117 connect(m_homeUrl
, &QLineEdit::textChanged
, this, &StartupSettingsPage::slotSettingsChanged
);
118 connect(m_splitView
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
119 connect(m_editableUrl
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
120 connect(m_showFullPath
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
121 connect(m_filterBar
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
124 StartupSettingsPage::~StartupSettingsPage()
128 void StartupSettingsPage::applySettings()
130 GeneralSettings
* settings
= GeneralSettings::self();
132 const QUrl
url(QUrl::fromLocalFile(m_homeUrl
->text()));
133 KFileItem
fileItem(url
);
134 if ((url
.isValid() && fileItem
.isDir()) || (url
.scheme() == QLatin1String("timeline"))) {
135 settings
->setHomeUrl(url
.toDisplayString(QUrl::PreferLocalFile
));
137 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
140 settings
->setSplitView(m_splitView
->isChecked());
141 settings
->setEditableUrl(m_editableUrl
->isChecked());
142 settings
->setShowFullPath(m_showFullPath
->isChecked());
143 settings
->setFilterBar(m_filterBar
->isChecked());
148 void StartupSettingsPage::restoreDefaults()
150 GeneralSettings
* settings
= GeneralSettings::self();
151 settings
->useDefaults(true);
153 settings
->useDefaults(false);
156 void StartupSettingsPage::slotSettingsChanged()
158 // Provide a hint that the startup settings have been changed. This allows the views
159 // to apply the startup settings only if they have been explicitly changed by the user
160 // (see bug #254947).
161 GeneralSettings::setModifiedStartupSettings(true);
165 void StartupSettingsPage::selectHomeUrl()
167 const QString homeUrl
= m_homeUrl
->text();
168 QUrl url
= QFileDialog::getExistingDirectoryUrl(this, QString(), QUrl::fromLocalFile(homeUrl
));
169 if (!url
.isEmpty()) {
170 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
171 slotSettingsChanged();
175 void StartupSettingsPage::useCurrentLocation()
177 m_homeUrl
->setText(m_url
.toDisplayString(QUrl::PreferLocalFile
));
180 void StartupSettingsPage::useDefaultLocation()
182 m_homeUrl
->setText(QDir::homePath());
185 void StartupSettingsPage::loadSettings()
187 const QUrl
url(QUrl::fromLocalFile(GeneralSettings::homeUrl()));
188 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
189 m_splitView
->setChecked(GeneralSettings::splitView());
190 m_editableUrl
->setChecked(GeneralSettings::editableUrl());
191 m_showFullPath
->setChecked(GeneralSettings::showFullPath());
192 m_filterBar
->setChecked(GeneralSettings::filterBar());