]>
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 <QFileDialog>
39 #include "views/dolphinview.h"
41 StartupSettingsPage::StartupSettingsPage(const QUrl
& url
, QWidget
* parent
) :
42 SettingsPageBase(parent
),
50 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
51 QWidget
* vBox
= new QWidget(this);
52 QVBoxLayout
*vBoxLayout
= new QVBoxLayout(vBox
);
53 vBoxLayout
->setMargin(0);
54 vBoxLayout
->setAlignment(Qt::AlignTop
);
56 // create 'Home URL' editor
57 QGroupBox
* homeBox
= new QGroupBox(i18nc("@title:group", "Home Folder"), vBox
);
58 vBoxLayout
->addWidget(homeBox
);
60 QWidget
* homeUrlBox
= new QWidget(homeBox
);
61 QHBoxLayout
*homeUrlBoxLayout
= new QHBoxLayout(homeUrlBox
);
62 homeUrlBoxLayout
->setMargin(0);
64 QLabel
* homeUrlLabel
= new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox
);
65 homeUrlBoxLayout
->addWidget(homeUrlLabel
);
66 m_homeUrl
= new QLineEdit(homeUrlBox
);
67 homeUrlBoxLayout
->addWidget(m_homeUrl
);
68 m_homeUrl
->setClearButtonEnabled(true);
70 QPushButton
* selectHomeUrlButton
= new QPushButton(QIcon::fromTheme("folder-open"), QString(), homeUrlBox
);
71 homeUrlBoxLayout
->addWidget(selectHomeUrlButton
);
73 #ifndef QT_NO_ACCESSIBILITY
74 selectHomeUrlButton
->setAccessibleName(i18nc("@action:button", "Select Home Location"));
77 connect(selectHomeUrlButton
, &QPushButton::clicked
,
78 this, &StartupSettingsPage::selectHomeUrl
);
80 QWidget
* buttonBox
= new QWidget(homeBox
);
81 QHBoxLayout
*buttonBoxLayout
= new QHBoxLayout(buttonBox
);
82 buttonBoxLayout
->setMargin(0);
84 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox
);
85 buttonBoxLayout
->addWidget(useCurrentButton
);
86 connect(useCurrentButton
, &QPushButton::clicked
,
87 this, &StartupSettingsPage::useCurrentLocation
);
88 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox
);
89 buttonBoxLayout
->addWidget(useDefaultButton
);
90 connect(useDefaultButton
, &QPushButton::clicked
,
91 this, &StartupSettingsPage::useDefaultLocation
);
93 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout(homeBox
);
94 homeBoxLayout
->addWidget(homeUrlBox
);
95 homeBoxLayout
->addWidget(buttonBox
);
97 // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes
98 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox
);
99 vBoxLayout
->addWidget(m_splitView
);
100 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox
);
101 vBoxLayout
->addWidget(m_editableUrl
);
102 m_showFullPath
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox
);
103 vBoxLayout
->addWidget(m_showFullPath
);
104 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox
);
105 vBoxLayout
->addWidget(m_filterBar
);
107 // Add a dummy widget with no restriction regarding
108 // a vertical resizing. This assures that the dialog layout
109 // is not stretched vertically.
112 topLayout
->addWidget(vBox
);
116 connect(m_homeUrl
, &QLineEdit::textChanged
, this, &StartupSettingsPage::slotSettingsChanged
);
117 connect(m_splitView
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
118 connect(m_editableUrl
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
119 connect(m_showFullPath
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
120 connect(m_filterBar
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
123 StartupSettingsPage::~StartupSettingsPage()
127 void StartupSettingsPage::applySettings()
129 GeneralSettings
* settings
= GeneralSettings::self();
131 const QUrl
url(QUrl::fromLocalFile(m_homeUrl
->text()));
132 KFileItem
fileItem(url
);
133 if ((url
.isValid() && fileItem
.isDir()) || (url
.scheme() == QLatin1String("timeline"))) {
134 settings
->setHomeUrl(url
.toDisplayString(QUrl::PreferLocalFile
));
136 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
139 settings
->setSplitView(m_splitView
->isChecked());
140 settings
->setEditableUrl(m_editableUrl
->isChecked());
141 settings
->setShowFullPath(m_showFullPath
->isChecked());
142 settings
->setFilterBar(m_filterBar
->isChecked());
147 void StartupSettingsPage::restoreDefaults()
149 GeneralSettings
* settings
= GeneralSettings::self();
150 settings
->useDefaults(true);
152 settings
->useDefaults(false);
155 void StartupSettingsPage::slotSettingsChanged()
157 // Provide a hint that the startup settings have been changed. This allows the views
158 // to apply the startup settings only if they have been explicitly changed by the user
159 // (see bug #254947).
160 GeneralSettings::setModifiedStartupSettings(true);
164 void StartupSettingsPage::selectHomeUrl()
166 const QString homeUrl
= m_homeUrl
->text();
167 QUrl url
= QFileDialog::getExistingDirectoryUrl(this, QString(), QUrl::fromLocalFile(homeUrl
));
168 if (!url
.isEmpty()) {
169 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
170 slotSettingsChanged();
174 void StartupSettingsPage::useCurrentLocation()
176 m_homeUrl
->setText(m_url
.toDisplayString(QUrl::PreferLocalFile
));
179 void StartupSettingsPage::useDefaultLocation()
181 m_homeUrl
->setText(QDir::homePath());
184 void StartupSettingsPage::loadSettings()
186 const QUrl
url(QUrl::fromLocalFile(GeneralSettings::homeUrl()));
187 m_homeUrl
->setText(url
.toDisplayString(QUrl::PreferLocalFile
));
188 m_splitView
->setChecked(GeneralSettings::splitView());
189 m_editableUrl
->setChecked(GeneralSettings::editableUrl());
190 m_showFullPath
->setChecked(GeneralSettings::showFullPath());
191 m_filterBar
->setChecked(GeneralSettings::filterBar());