]>
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"
28 #include <KFileDialog>
31 #include <KMessageBox>
37 #include <QPushButton>
38 #include <QRadioButton>
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(KIcon("folder-open"), QString(), homeUrlBox
);
68 connect(selectHomeUrlButton
, SIGNAL(clicked()),
69 this, SLOT(selectHomeUrl()));
71 KHBox
* buttonBox
= new KHBox(homeBox
);
72 buttonBox
->setSpacing(spacing
);
74 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox
);
75 connect(useCurrentButton
, SIGNAL(clicked()),
76 this, SLOT(useCurrentLocation()));
77 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox
);
78 connect(useDefaultButton
, SIGNAL(clicked()),
79 this, SLOT(useDefaultLocation()));
81 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout(homeBox
);
82 homeBoxLayout
->addWidget(homeUrlBox
);
83 homeBoxLayout
->addWidget(buttonBox
);
85 // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes
86 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox
);
87 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox
);
88 m_showFullPath
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox
);
89 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox
);
91 // Add a dummy widget with no restriction regarding
92 // a vertical resizing. This assures that the dialog layout
93 // is not stretched vertically.
96 topLayout
->addWidget(vBox
);
100 connect(m_homeUrl
, SIGNAL(textChanged(QString
)), this, SLOT(slotSettingsChanged()));
101 connect(m_splitView
, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
102 connect(m_editableUrl
, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
103 connect(m_showFullPath
, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
104 connect(m_filterBar
, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
107 StartupSettingsPage::~StartupSettingsPage()
111 void StartupSettingsPage::applySettings()
113 GeneralSettings
* settings
= GeneralSettings::self();
115 const KUrl
url(m_homeUrl
->text());
116 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, url
);
117 if (url
.isValid() && fileItem
.isDir()) {
118 settings
->setHomeUrl(url
.prettyUrl());
120 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
123 settings
->setSplitView(m_splitView
->isChecked());
124 settings
->setEditableUrl(m_editableUrl
->isChecked());
125 settings
->setShowFullPath(m_showFullPath
->isChecked());
126 settings
->setFilterBar(m_filterBar
->isChecked());
128 settings
->writeConfig();
131 void StartupSettingsPage::restoreDefaults()
133 GeneralSettings
* settings
= GeneralSettings::self();
134 settings
->useDefaults(true);
136 settings
->useDefaults(false);
139 void StartupSettingsPage::slotSettingsChanged()
141 // Provide a hint that the startup settings have been changed. This allows the views
142 // to apply the startup settings only if they have been explicitly changed by the user
143 // (see bug #254947).
144 GeneralSettings::setModifiedStartupSettings(true);
148 void StartupSettingsPage::selectHomeUrl()
150 const QString homeUrl
= m_homeUrl
->text();
151 KUrl url
= KFileDialog::getExistingDirectoryUrl(homeUrl
, this);
152 if (!url
.isEmpty()) {
153 m_homeUrl
->setText(url
.prettyUrl());
154 slotSettingsChanged();
158 void StartupSettingsPage::useCurrentLocation()
160 m_homeUrl
->setText(m_url
.prettyUrl());
163 void StartupSettingsPage::useDefaultLocation()
165 KUrl
url(QDir::homePath());
166 m_homeUrl
->setText(url
.prettyUrl());
169 void StartupSettingsPage::loadSettings()
171 const KUrl
url(GeneralSettings::homeUrl());
172 m_homeUrl
->setText(url
.prettyUrl());
173 m_splitView
->setChecked(GeneralSettings::splitView());
174 m_editableUrl
->setChecked(GeneralSettings::editableUrl());
175 m_showFullPath
->setChecked(GeneralSettings::showFullPath());
176 m_filterBar
->setChecked(GeneralSettings::filterBar());
179 #include "startupsettingspage.moc"