]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startupsettingspage.cpp
Fix temporary regression of sorting introduced by SVN commit 1126410
[dolphin.git] / src / settings / startupsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "startupsettingspage.h"
21
22 #include "settings/dolphinsettings.h"
23 #include "dolphinmainwindow.h"
24 #include "dolphinview.h"
25 #include "dolphinviewcontainer.h"
26
27 #include "dolphin_generalsettings.h"
28
29 #include <kdialog.h>
30 #include <kfiledialog.h>
31 #include <klocale.h>
32 #include <klineedit.h>
33 #include <kmessagebox.h>
34 #include <kvbox.h>
35
36 #include <QCheckBox>
37 #include <QGroupBox>
38 #include <QLabel>
39 #include <QPushButton>
40 #include <QRadioButton>
41
42 StartupSettingsPage::StartupSettingsPage(const KUrl& url, QWidget* parent) :
43 SettingsPageBase(parent),
44 m_url(url),
45 m_homeUrl(0),
46 m_splitView(0),
47 m_editableUrl(0),
48 m_showFullPath(0),
49 m_filterBar(0)
50 {
51 const int spacing = KDialog::spacingHint();
52
53 QVBoxLayout* topLayout = new QVBoxLayout(this);
54 KVBox* vBox = new KVBox(this);
55 vBox->setSpacing(spacing);
56
57 // create 'Home URL' editor
58 QGroupBox* homeBox = new QGroupBox(i18nc("@title:group", "Home Folder"), vBox);
59
60 KHBox* homeUrlBox = new KHBox(homeBox);
61 homeUrlBox->setSpacing(spacing);
62
63 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox);
64 m_homeUrl = new KLineEdit(homeUrlBox);
65 m_homeUrl->setClearButtonShown(true);
66
67 QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder-open"), QString(), homeUrlBox);
68 connect(selectHomeUrlButton, SIGNAL(clicked()),
69 this, SLOT(selectHomeUrl()));
70
71 KHBox* buttonBox = new KHBox(homeBox);
72 buttonBox->setSpacing(spacing);
73
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()));
80
81 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
82 homeBoxLayout->addWidget(homeUrlBox);
83 homeBoxLayout->addWidget(buttonBox);
84
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);
90 connect(m_splitView, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
91 connect(m_editableUrl, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
92 connect(m_showFullPath, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
93 connect(m_filterBar, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
94
95 // Add a dummy widget with no restriction regarding
96 // a vertical resizing. This assures that the dialog layout
97 // is not stretched vertically.
98 new QWidget(vBox);
99
100 topLayout->addWidget(vBox);
101
102 loadSettings();
103
104 // it's important connecting 'textChanged' after loadSettings(), as loadSettings()
105 // invokes m_homeUrl->setText()
106 connect(m_homeUrl, SIGNAL(textChanged(const QString&)), this, SIGNAL(changed()));
107 }
108
109 StartupSettingsPage::~StartupSettingsPage()
110 {
111 }
112
113 void StartupSettingsPage::applySettings()
114 {
115 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
116
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());
121 } else {
122 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
123 }
124
125 settings->setSplitView(m_splitView->isChecked());
126 settings->setEditableUrl(m_editableUrl->isChecked());
127 settings->setShowFullPath(m_showFullPath->isChecked());
128 settings->setFilterBar(m_filterBar->isChecked());
129
130 settings->writeConfig();
131 }
132
133 void StartupSettingsPage::restoreDefaults()
134 {
135 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
136 settings->useDefaults(true);
137 loadSettings();
138 settings->useDefaults(false);
139 }
140
141 void StartupSettingsPage::selectHomeUrl()
142 {
143 const QString homeUrl = m_homeUrl->text();
144 KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl, this);
145 if (!url.isEmpty()) {
146 m_homeUrl->setText(url.prettyUrl());
147 emit changed();
148 }
149 }
150
151 void StartupSettingsPage::useCurrentLocation()
152 {
153 m_homeUrl->setText(m_url.prettyUrl());
154 }
155
156 void StartupSettingsPage::useDefaultLocation()
157 {
158 KUrl url(QDir::homePath());
159 m_homeUrl->setText(url.prettyUrl());
160 }
161
162 void StartupSettingsPage::loadSettings()
163 {
164 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
165 KUrl url(settings->homeUrl());
166 m_homeUrl->setText(url.prettyUrl());
167 m_splitView->setChecked(settings->splitView());
168 m_editableUrl->setChecked(settings->editableUrl());
169 m_showFullPath->setChecked(settings->showFullPath());
170 m_filterBar->setChecked(settings->filterBar());
171 }
172
173 #include "startupsettingspage.moc"