]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
2c436b541718d1ceb612227c4fe5b083a0322b3c
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>
34 #include <QVBoxLayout>
38 #include <QPushButton>
40 #include "views/dolphinview.h"
42 StartupSettingsPage::StartupSettingsPage(const KUrl
& url
, QWidget
* parent
) :
43 SettingsPageBase(parent
),
51 const int spacing
= KDialog::spacingHint();
53 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
54 KVBox
* vBox
= new KVBox(this);
55 vBox
->setSpacing(spacing
);
57 // create 'Home URL' editor
58 QGroupBox
* homeBox
= new QGroupBox(i18nc("@title:group", "Home Folder"), vBox
);
60 KHBox
* homeUrlBox
= new KHBox(homeBox
);
61 homeUrlBox
->setSpacing(spacing
);
63 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox
);
64 m_homeUrl
= new KLineEdit(homeUrlBox
);
65 m_homeUrl
->setClearButtonShown(true);
67 QPushButton
* selectHomeUrlButton
= new QPushButton(QIcon::fromTheme("folder-open"), QString(), homeUrlBox
);
69 #ifndef QT_NO_ACCESSIBILITY
70 selectHomeUrlButton
->setAccessibleName(i18nc("@action:button", "Select Home Location"));
73 connect(selectHomeUrlButton
, &QPushButton::clicked
,
74 this, &StartupSettingsPage::selectHomeUrl
);
76 KHBox
* buttonBox
= new KHBox(homeBox
);
77 buttonBox
->setSpacing(spacing
);
79 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox
);
80 connect(useCurrentButton
, &QPushButton::clicked
,
81 this, &StartupSettingsPage::useCurrentLocation
);
82 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox
);
83 connect(useDefaultButton
, &QPushButton::clicked
,
84 this, &StartupSettingsPage::useDefaultLocation
);
86 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout(homeBox
);
87 homeBoxLayout
->addWidget(homeUrlBox
);
88 homeBoxLayout
->addWidget(buttonBox
);
90 // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes
91 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox
);
92 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox
);
93 m_showFullPath
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox
);
94 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox
);
96 // Add a dummy widget with no restriction regarding
97 // a vertical resizing. This assures that the dialog layout
98 // is not stretched vertically.
101 topLayout
->addWidget(vBox
);
105 connect(m_homeUrl
, &KLineEdit::textChanged
, this, &StartupSettingsPage::slotSettingsChanged
);
106 connect(m_splitView
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
107 connect(m_editableUrl
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
108 connect(m_showFullPath
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
109 connect(m_filterBar
, &QCheckBox::toggled
, this, &StartupSettingsPage::slotSettingsChanged
);
112 StartupSettingsPage::~StartupSettingsPage()
116 void StartupSettingsPage::applySettings()
118 GeneralSettings
* settings
= GeneralSettings::self();
120 const KUrl
url(m_homeUrl
->text());
121 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, url
);
122 if ((url
.isValid() && fileItem
.isDir()) || (url
.protocol() == QLatin1String("timeline"))) {
123 settings
->setHomeUrl(url
.prettyUrl());
125 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
128 settings
->setSplitView(m_splitView
->isChecked());
129 settings
->setEditableUrl(m_editableUrl
->isChecked());
130 settings
->setShowFullPath(m_showFullPath
->isChecked());
131 settings
->setFilterBar(m_filterBar
->isChecked());
133 settings
->writeConfig();
136 void StartupSettingsPage::restoreDefaults()
138 GeneralSettings
* settings
= GeneralSettings::self();
139 settings
->useDefaults(true);
141 settings
->useDefaults(false);
144 void StartupSettingsPage::slotSettingsChanged()
146 // Provide a hint that the startup settings have been changed. This allows the views
147 // to apply the startup settings only if they have been explicitly changed by the user
148 // (see bug #254947).
149 GeneralSettings::setModifiedStartupSettings(true);
153 void StartupSettingsPage::selectHomeUrl()
155 const QString homeUrl
= m_homeUrl
->text();
156 KUrl url
= KFileDialog::getExistingDirectoryUrl(homeUrl
, this);
157 if (!url
.isEmpty()) {
158 m_homeUrl
->setText(url
.prettyUrl());
159 slotSettingsChanged();
163 void StartupSettingsPage::useCurrentLocation()
165 m_homeUrl
->setText(m_url
.prettyUrl());
168 void StartupSettingsPage::useDefaultLocation()
170 KUrl
url(QDir::homePath());
171 m_homeUrl
->setText(url
.prettyUrl());
174 void StartupSettingsPage::loadSettings()
176 const KUrl
url(GeneralSettings::homeUrl());
177 m_homeUrl
->setText(url
.prettyUrl());
178 m_splitView
->setChecked(GeneralSettings::splitView());
179 m_editableUrl
->setChecked(GeneralSettings::editableUrl());
180 m_showFullPath
->setChecked(GeneralSettings::showFullPath());
181 m_filterBar
->setChecked(GeneralSettings::filterBar());