]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
Fix Bug 310465 - Can't switch view mode for non-writable paths
[dolphin.git] / src / settings / startup / startupsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com> *
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 "dolphinmainwindow.h"
23 #include "dolphinviewcontainer.h"
24
25 #include "dolphin_generalsettings.h"
26
27 #include <KDialog>
28 #include <KFileDialog>
29 #include <KLocale>
30 #include <KLineEdit>
31 #include <KMessageBox>
32 #include <KVBox>
33
34 #include <QCheckBox>
35 #include <QGroupBox>
36 #include <QLabel>
37 #include <QPushButton>
38 #include <QRadioButton>
39
40 #include "views/dolphinview.h"
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
91 // Add a dummy widget with no restriction regarding
92 // a vertical resizing. This assures that the dialog layout
93 // is not stretched vertically.
94 new QWidget(vBox);
95
96 topLayout->addWidget(vBox);
97
98 loadSettings();
99
100 connect(m_homeUrl, SIGNAL(textChanged(QString)), this, SLOT(slotSettingsChanged()));
101 connect(m_splitView, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
102 connect(m_editableUrl, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
103 connect(m_showFullPath, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
104 connect(m_filterBar, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
105 }
106
107 StartupSettingsPage::~StartupSettingsPage()
108 {
109 }
110
111 void StartupSettingsPage::applySettings()
112 {
113 GeneralSettings* settings = GeneralSettings::self();
114
115 const KUrl url(m_homeUrl->text());
116 KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url);
117 if (url.isValid() && fileItem.isDir()) {
118 settings->setHomeUrl(url.prettyUrl());
119 } else {
120 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
121 }
122
123 settings->setSplitView(m_splitView->isChecked());
124 settings->setEditableUrl(m_editableUrl->isChecked());
125 settings->setShowFullPath(m_showFullPath->isChecked());
126 settings->setFilterBar(m_filterBar->isChecked());
127
128 settings->writeConfig();
129 }
130
131 void StartupSettingsPage::restoreDefaults()
132 {
133 GeneralSettings* settings = GeneralSettings::self();
134 settings->useDefaults(true);
135 loadSettings();
136 settings->useDefaults(false);
137 }
138
139 void StartupSettingsPage::slotSettingsChanged()
140 {
141 // Provide a hint that the startup settings have been changed. This allows the views
142 // to apply the startup settings only if they have been explicitly changed by the user
143 // (see bug #254947).
144 GeneralSettings::setModifiedStartupSettings(true);
145 emit changed();
146 }
147
148 void StartupSettingsPage::selectHomeUrl()
149 {
150 const QString homeUrl = m_homeUrl->text();
151 KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl, this);
152 if (!url.isEmpty()) {
153 m_homeUrl->setText(url.prettyUrl());
154 slotSettingsChanged();
155 }
156 }
157
158 void StartupSettingsPage::useCurrentLocation()
159 {
160 m_homeUrl->setText(m_url.prettyUrl());
161 }
162
163 void StartupSettingsPage::useDefaultLocation()
164 {
165 KUrl url(QDir::homePath());
166 m_homeUrl->setText(url.prettyUrl());
167 }
168
169 void StartupSettingsPage::loadSettings()
170 {
171 const KUrl url(GeneralSettings::homeUrl());
172 m_homeUrl->setText(url.prettyUrl());
173 m_splitView->setChecked(GeneralSettings::splitView());
174 m_editableUrl->setChecked(GeneralSettings::editableUrl());
175 m_showFullPath->setChecked(GeneralSettings::showFullPath());
176 m_filterBar->setChecked(GeneralSettings::filterBar());
177 }
178
179 #include "startupsettingspage.moc"