]>
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
);
91 connect(m_splitView
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
92 connect(m_editableUrl
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
93 connect(m_showFullPath
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
94 connect(m_filterBar
, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
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 // it's important connecting 'textChanged' after loadSettings(), as loadSettings()
106 // invokes m_homeUrl->setText()
107 connect(m_homeUrl
, SIGNAL(textChanged(const QString
&)), this, SIGNAL(changed()));
110 StartupSettingsPage::~StartupSettingsPage()
114 void StartupSettingsPage::applySettings()
116 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
118 const KUrl
url(m_homeUrl
->text());
119 KFileItem
fileItem(KFileItem::Unknown
, KFileItem::Unknown
, url
);
120 if (url
.isValid() && fileItem
.isDir()) {
121 settings
->setHomeUrl(url
.prettyUrl());
123 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
126 settings
->setSplitView(m_splitView
->isChecked());
127 settings
->setEditableUrl(m_editableUrl
->isChecked());
128 settings
->setShowFullPath(m_showFullPath
->isChecked());
129 settings
->setFilterBar(m_filterBar
->isChecked());
131 settings
->writeConfig();
134 void StartupSettingsPage::restoreDefaults()
136 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
137 settings
->useDefaults(true);
139 settings
->useDefaults(false);
142 void StartupSettingsPage::selectHomeUrl()
144 const QString homeUrl
= m_homeUrl
->text();
145 KUrl url
= KFileDialog::getExistingDirectoryUrl(homeUrl
, this);
146 if (!url
.isEmpty()) {
147 m_homeUrl
->setText(url
.prettyUrl());
152 void StartupSettingsPage::useCurrentLocation()
154 m_homeUrl
->setText(m_url
.prettyUrl());
157 void StartupSettingsPage::useDefaultLocation()
159 KUrl
url(QDir::homePath());
160 m_homeUrl
->setText(url
.prettyUrl());
163 void StartupSettingsPage::loadSettings()
165 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
166 KUrl
url(settings
->homeUrl());
167 m_homeUrl
->setText(url
.prettyUrl());
168 m_splitView
->setChecked(settings
->splitView());
169 m_editableUrl
->setChecked(settings
->editableUrl());
170 m_showFullPath
->setChecked(settings
->showFullPath());
171 m_filterBar
->setChecked(settings
->filterBar());
174 #include "startupsettingspage.moc"