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 "dolphinsettings.h"
23 #include "dolphinmainwindow.h"
24 #include "dolphinview.h"
25 #include "dolphinviewcontainer.h"
27 #include "dolphin_generalsettings.h"
30 #include <kfiledialog.h>
32 #include <kmessagebox.h>
39 #include <QPushButton>
40 #include <QRadioButton>
42 StartupSettingsPage::StartupSettingsPage(DolphinMainWindow
* mainWin
, QWidget
* parent
) :
43 SettingsPageBase(parent
),
44 m_mainWindow(mainWin
),
50 const int spacing
= KDialog::spacingHint();
52 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
53 KVBox
* vBox
= new KVBox(this);
54 vBox
->setSpacing(spacing
);
56 // create 'Home URL' editor
57 QGroupBox
* homeBox
= new QGroupBox(i18nc("@title:group", "Home Folder"), vBox
);
59 KHBox
* homeUrlBox
= new KHBox(homeBox
);
60 homeUrlBox
->setSpacing(spacing
);
62 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox
);
63 m_homeUrl
= new QLineEdit(homeUrlBox
);
65 QPushButton
* selectHomeUrlButton
= new QPushButton(KIcon("folder-open"), QString(), homeUrlBox
);
66 connect(selectHomeUrlButton
, SIGNAL(clicked()),
67 this, SLOT(selectHomeUrl()));
69 KHBox
* buttonBox
= new KHBox(homeBox
);
70 buttonBox
->setSpacing(spacing
);
72 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox
);
73 connect(useCurrentButton
, SIGNAL(clicked()),
74 this, SLOT(useCurrentLocation()));
75 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox
);
76 connect(useDefaultButton
, SIGNAL(clicked()),
77 this, SLOT(useDefaultLocation()));
79 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout(homeBox
);
80 homeBoxLayout
->addWidget(homeUrlBox
);
81 homeBoxLayout
->addWidget(buttonBox
);
83 // create 'Split view', 'Editable location' and 'Filter bar' checkboxes
84 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox
);
85 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox
);
86 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox
);
88 // Add a dummy widget with no restriction regarding
89 // a vertical resizing. This assures that the dialog layout
90 // is not stretched vertically.
93 topLayout
->addWidget(vBox
);
98 StartupSettingsPage::~StartupSettingsPage()
102 void StartupSettingsPage::applySettings()
104 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
106 const KUrl
url(m_homeUrl
->text());
107 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, url
);
108 if (url
.isValid() && fileItem
.isDir()) {
109 settings
->setHomeUrl(url
.prettyUrl());
111 KMessageBox::error(this, i18n("The location for the home folder is invalid and will not get applied."));
114 settings
->setSplitView(m_splitView
->isChecked());
115 settings
->setEditableUrl(m_editableUrl
->isChecked());
116 settings
->setFilterBar(m_filterBar
->isChecked());
119 void StartupSettingsPage::restoreDefaults()
121 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
122 settings
->setDefaults();
126 void StartupSettingsPage::selectHomeUrl()
128 const QString homeUrl
= m_homeUrl
->text();
129 KUrl url
= KFileDialog::getExistingDirectoryUrl(homeUrl
);
130 if (!url
.isEmpty()) {
131 m_homeUrl
->setText(url
.prettyUrl());
135 void StartupSettingsPage::useCurrentLocation()
137 const DolphinView
* view
= m_mainWindow
->activeViewContainer()->view();
138 m_homeUrl
->setText(view
->url().prettyUrl());
141 void StartupSettingsPage::useDefaultLocation()
143 m_homeUrl
->setText(QDir::homePath());
146 void StartupSettingsPage::loadSettings()
148 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
149 m_homeUrl
->setText(settings
->homeUrl());
150 m_splitView
->setChecked(settings
->splitView());
151 m_editableUrl
->setChecked(settings
->editableUrl());
152 m_filterBar
->setChecked(settings
->filterBar());
155 #include "startupsettingspage.moc"