]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
If the user has changed the startup settings, they should also get applied to the...
[dolphin.git] / src / settings / startup / 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 "dolphinviewcontainer.h"
25
26 #include "dolphin_generalsettings.h"
27
28 #include <kdialog.h>
29 #include <kfiledialog.h>
30 #include <klocale.h>
31 #include <klineedit.h>
32 #include <kmessagebox.h>
33 #include <kvbox.h>
34
35 #include <QCheckBox>
36 #include <QGroupBox>
37 #include <QLabel>
38 #include <QPushButton>
39 #include <QRadioButton>
40
41 #include "views/dolphinview.h"
42
43 StartupSettingsPage::StartupSettingsPage(const KUrl& url, QWidget* parent) :
44 SettingsPageBase(parent),
45 m_url(url),
46 m_homeUrl(0),
47 m_splitView(0),
48 m_editableUrl(0),
49 m_showFullPath(0),
50 m_filterBar(0)
51 {
52 const int spacing = KDialog::spacingHint();
53
54 QVBoxLayout* topLayout = new QVBoxLayout(this);
55 KVBox* vBox = new KVBox(this);
56 vBox->setSpacing(spacing);
57
58 // create 'Home URL' editor
59 QGroupBox* homeBox = new QGroupBox(i18nc("@title:group", "Home Folder"), vBox);
60
61 KHBox* homeUrlBox = new KHBox(homeBox);
62 homeUrlBox->setSpacing(spacing);
63
64 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox);
65 m_homeUrl = new KLineEdit(homeUrlBox);
66 m_homeUrl->setClearButtonShown(true);
67
68 QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder-open"), QString(), homeUrlBox);
69 connect(selectHomeUrlButton, SIGNAL(clicked()),
70 this, SLOT(selectHomeUrl()));
71
72 KHBox* buttonBox = new KHBox(homeBox);
73 buttonBox->setSpacing(spacing);
74
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()));
81
82 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
83 homeBoxLayout->addWidget(homeUrlBox);
84 homeBoxLayout->addWidget(buttonBox);
85
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
92 // Add a dummy widget with no restriction regarding
93 // a vertical resizing. This assures that the dialog layout
94 // is not stretched vertically.
95 new QWidget(vBox);
96
97 topLayout->addWidget(vBox);
98
99 loadSettings();
100
101 // Connecting the signals must be done after loading the settings
102 connect(m_homeUrl, SIGNAL(textChanged(const QString&)), this, SIGNAL(changed()));
103 connect(m_splitView, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
104 connect(m_editableUrl, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
105 connect(m_showFullPath, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
106 connect(m_filterBar, SIGNAL(toggled(bool)), this, SLOT(slotSettingsChanged()));
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::slotSettingsChanged()
142 {
143 // Provide a hint that the startup settings have been changed. This allows the views
144 // to apply the startup settings only if they have been explicitely changed by the user
145 // (see bug #254947).
146 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
147 settings->setModifiedStartupSettings(true);
148
149 emit changed();
150 }
151
152 void StartupSettingsPage::selectHomeUrl()
153 {
154 const QString homeUrl = m_homeUrl->text();
155 KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl, this);
156 if (!url.isEmpty()) {
157 m_homeUrl->setText(url.prettyUrl());
158 slotSettingsChanged();
159 }
160 }
161
162 void StartupSettingsPage::useCurrentLocation()
163 {
164 m_homeUrl->setText(m_url.prettyUrl());
165 }
166
167 void StartupSettingsPage::useDefaultLocation()
168 {
169 KUrl url(QDir::homePath());
170 m_homeUrl->setText(url.prettyUrl());
171 }
172
173 void StartupSettingsPage::loadSettings()
174 {
175 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
176 KUrl url(settings->homeUrl());
177 m_homeUrl->setText(url.prettyUrl());
178 m_splitView->setChecked(settings->splitView());
179 m_editableUrl->setChecked(settings->editableUrl());
180 m_showFullPath->setChecked(settings->showFullPath());
181 m_filterBar->setChecked(settings->filterBar());
182 }
183
184 #include "startupsettingspage.moc"