]>
cloud.milkyroute.net Git - dolphin.git/blob - src/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 "dolphinsettings.h"
23 #include "dolphinmainwindow.h"
24 #include "dolphinview.h"
25 #include "dolphinviewcontainer.h"
27 #include "dolphin_generalsettings.h"
30 #include <kfiledialog.h>
38 #include <QPushButton>
39 #include <QRadioButton>
41 StartupSettingsPage::StartupSettingsPage(DolphinMainWindow
* mainWin
, QWidget
* parent
) :
42 SettingsPageBase(parent
),
43 m_mainWindow(mainWin
),
49 const int spacing
= KDialog::spacingHint();
51 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
52 KVBox
* vBox
= new KVBox(this);
53 vBox
->setSpacing(spacing
);
55 // create 'Home URL' editor
56 QGroupBox
* homeBox
= new QGroupBox(i18nc("@title:group", "Home Folder"), vBox
);
58 KHBox
* homeUrlBox
= new KHBox(homeBox
);
59 homeUrlBox
->setSpacing(spacing
);
61 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox
);
62 m_homeUrl
= new QLineEdit(homeUrlBox
);
64 QPushButton
* selectHomeUrlButton
= new QPushButton(KIcon("folder-open"), QString(), homeUrlBox
);
65 connect(selectHomeUrlButton
, SIGNAL(clicked()),
66 this, SLOT(selectHomeUrl()));
68 KHBox
* buttonBox
= new KHBox(homeBox
);
69 buttonBox
->setSpacing(spacing
);
71 QPushButton
* useCurrentButton
= new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox
);
72 connect(useCurrentButton
, SIGNAL(clicked()),
73 this, SLOT(useCurrentLocation()));
74 QPushButton
* useDefaultButton
= new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox
);
75 connect(useDefaultButton
, SIGNAL(clicked()),
76 this, SLOT(useDefaultLocation()));
78 QVBoxLayout
* homeBoxLayout
= new QVBoxLayout(homeBox
);
79 homeBoxLayout
->addWidget(homeUrlBox
);
80 homeBoxLayout
->addWidget(buttonBox
);
82 // create 'Split view', 'Editable location' and 'Filter bar' checkboxes
83 m_splitView
= new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox
);
84 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox
);
85 m_filterBar
= new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox
);
87 // Add a dummy widget with no restriction regarding
88 // a vertical resizing. This assures that the dialog layout
89 // is not stretched vertically.
92 topLayout
->addWidget(vBox
);
97 StartupSettingsPage::~StartupSettingsPage()
101 void StartupSettingsPage::applySettings()
103 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
105 const KUrl
url(m_homeUrl
->text());
106 KFileItem
fileItem(S_IFDIR
, KFileItem::Unknown
, url
);
107 if (url
.isValid() && fileItem
.isDir()) {
108 settings
->setHomeUrl(url
.prettyUrl());
111 settings
->setSplitView(m_splitView
->isChecked());
112 settings
->setEditableUrl(m_editableUrl
->isChecked());
113 settings
->setFilterBar(m_filterBar
->isChecked());
116 void StartupSettingsPage::restoreDefaults()
118 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
119 settings
->setDefaults();
123 void StartupSettingsPage::selectHomeUrl()
125 const QString homeUrl
= m_homeUrl
->text();
126 KUrl url
= KFileDialog::getExistingDirectoryUrl(homeUrl
);
127 if (!url
.isEmpty()) {
128 m_homeUrl
->setText(url
.prettyUrl());
132 void StartupSettingsPage::useCurrentLocation()
134 const DolphinView
* view
= m_mainWindow
->activeViewContainer()->view();
135 m_homeUrl
->setText(view
->url().prettyUrl());
138 void StartupSettingsPage::useDefaultLocation()
140 m_homeUrl
->setText("file://" + QDir::homePath());
143 void StartupSettingsPage::loadSettings()
145 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
146 m_homeUrl
->setText(settings
->homeUrl());
147 m_splitView
->setChecked(settings
->splitView());
148 m_editableUrl
->setChecked(settings
->editableUrl());
149 m_filterBar
->setChecked(settings
->filterBar());
152 #include "startupsettingspage.moc"