]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
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 "settings/dolphinsettings.h"
23 #include "dolphinmainwindow.h"
24 #include "dolphinviewcontainer.h"
26 #include "dolphin_generalsettings.h"
29 #include <kfiledialog.h>
31 #include <klineedit.h>
32 #include <kmessagebox.h>
38 #include <QPushButton>
39 #include <QRadioButton>
41 #include "views/dolphinview.h"
43 StartupSettingsPage::StartupSettingsPage(const KUrl
& url
, QWidget
* parent
) :
44 SettingsPageBase(parent
),
52 const int spacing
= KDialog::spacingHint();
54 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
55 KVBox
* vBox
= new KVBox(this);
56 vBox
->setSpacing(spacing
);
58 // create 'Home URL' editor
59 QGroupBox
* homeBox
= new QGroupBox(i18nc("@title:group", "Home Folder"), vBox
);
61 KHBox
* homeUrlBox
= new KHBox(homeBox
);
62 homeUrlBox
->setSpacing(spacing
);
64 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox
);
65 m_homeUrl
= new KLineEdit(homeUrlBox
);
66 m_homeUrl
->setClearButtonShown(true);
68 QPushButton
* selectHomeUrlButton
= new QPushButton(KIcon("folder-open"), QString(), homeUrlBox
);
69 connect(selectHomeUrlButton
, SIGNAL(clicked()),
70 this, SLOT(selectHomeUrl()));
72 KHBox
* buttonBox
= new KHBox(homeBox
);
73 buttonBox
->setSpacing(spacing
);
75 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox
);
76 connect(useCurrentButton
, SIGNAL(clicked()),
77 this, SLOT(useCurrentLocation()));
78 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox
);
79 connect(useDefaultButton
, SIGNAL(clicked()),
80 this, SLOT(useDefaultLocation()));
82 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout(homeBox
);
83 homeBoxLayout
->addWidget(homeUrlBox
);
84 homeBoxLayout
->addWidget(buttonBox
);
86 // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes
87 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox
);
88 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox
);
89 m_showFullPath
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox
);
90 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox
);
92 // Add a dummy widget with no restriction regarding
93 // a vertical resizing. This assures that the dialog layout
94 // is not stretched vertically.
97 topLayout
->addWidget(vBox
);
101 // Connecting the signals must be done after loading the settings
102 connect(m_homeUrl
, SIGNAL(textChanged(const QString
&)), this, SIGNAL(changed()));
103 connect(m_splitView
, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
104 connect(m_editableUrl
, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
105 connect(m_showFullPath
, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
106 connect(m_filterBar
, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
109 StartupSettingsPage::~StartupSettingsPage()
113 void StartupSettingsPage::applySettings()
115 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
117 const KUrl
url(m_homeUrl
->text());
118 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, url
);
119 if (url
.isValid() && fileItem
.isDir()) {
120 settings
->setHomeUrl(url
.prettyUrl());
122 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
125 settings
->setSplitView(m_splitView
->isChecked());
126 settings
->setEditableUrl(m_editableUrl
->isChecked());
127 settings
->setShowFullPath(m_showFullPath
->isChecked());
128 settings
->setFilterBar(m_filterBar
->isChecked());
130 settings
->writeConfig();
133 void StartupSettingsPage::restoreDefaults()
135 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
136 settings
->useDefaults(true);
138 settings
->useDefaults(false);
141 void StartupSettingsPage::slotSettingsChanged()
143 // Provide a hint that the startup settings have been changed. This allows the views
144 // to apply the startup settings only if they have been explicitely changed by the user
145 // (see bug #254947).
146 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
147 settings
->setModifiedStartupSettings(true);
152 void StartupSettingsPage::selectHomeUrl()
154 const QString homeUrl
= m_homeUrl
->text();
155 KUrl url
= KFileDialog::getExistingDirectoryUrl(homeUrl
, this);
156 if (!url
.isEmpty()) {
157 m_homeUrl
->setText(url
.prettyUrl());
158 slotSettingsChanged();
162 void StartupSettingsPage::useCurrentLocation()
164 m_homeUrl
->setText(m_url
.prettyUrl());
167 void StartupSettingsPage::useDefaultLocation()
169 KUrl
url(QDir::homePath());
170 m_homeUrl
->setText(url
.prettyUrl());
173 void StartupSettingsPage::loadSettings()
175 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
176 KUrl
url(settings
->homeUrl());
177 m_homeUrl
->setText(url
.prettyUrl());
178 m_splitView
->setChecked(settings
->splitView());
179 m_editableUrl
->setChecked(settings
->editableUrl());
180 m_showFullPath
->setChecked(settings
->showFullPath());
181 m_filterBar
->setChecked(settings
->filterBar());
184 #include "startupsettingspage.moc"