]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/startup/startupsettingspage.cpp
Sourcecode hierarchy cleanup: Create folder "views" and move view related sources...
[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 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()));
95
96 // Add a dummy widget with no restriction regarding
97 // a vertical resizing. This assures that the dialog layout
98 // is not stretched vertically.
99 new QWidget(vBox);
100
101 topLayout->addWidget(vBox);
102
103 loadSettings();
104
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()));
108 }
109
110 StartupSettingsPage::~StartupSettingsPage()
111 {
112 }
113
114 void StartupSettingsPage::applySettings()
115 {
116 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
117
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());
122 } else {
123 KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
124 }
125
126 settings->setSplitView(m_splitView->isChecked());
127 settings->setEditableUrl(m_editableUrl->isChecked());
128 settings->setShowFullPath(m_showFullPath->isChecked());
129 settings->setFilterBar(m_filterBar->isChecked());
130
131 settings->writeConfig();
132 }
133
134 void StartupSettingsPage::restoreDefaults()
135 {
136 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
137 settings->useDefaults(true);
138 loadSettings();
139 settings->useDefaults(false);
140 }
141
142 void StartupSettingsPage::selectHomeUrl()
143 {
144 const QString homeUrl = m_homeUrl->text();
145 KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl, this);
146 if (!url.isEmpty()) {
147 m_homeUrl->setText(url.prettyUrl());
148 emit changed();
149 }
150 }
151
152 void StartupSettingsPage::useCurrentLocation()
153 {
154 m_homeUrl->setText(m_url.prettyUrl());
155 }
156
157 void StartupSettingsPage::useDefaultLocation()
158 {
159 KUrl url(QDir::homePath());
160 m_homeUrl->setText(url.prettyUrl());
161 }
162
163 void StartupSettingsPage::loadSettings()
164 {
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());
172 }
173
174 #include "startupsettingspage.moc"