delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / dolphin / src / settings / startupsettingspage.cpp
blob9ea5291329cddc6dd4e233d351057c110da5a3d8
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 ***************************************************************************/
20 #include "startupsettingspage.h"
22 #include "settings/dolphinsettings.h"
23 #include "dolphinmainwindow.h"
24 #include "dolphinview.h"
25 #include "dolphinviewcontainer.h"
27 #include "dolphin_generalsettings.h"
29 #include <kdialog.h>
30 #include <kfiledialog.h>
31 #include <klocale.h>
32 #include <klineedit.h>
33 #include <kmessagebox.h>
34 #include <kvbox.h>
36 #include <QCheckBox>
37 #include <QGroupBox>
38 #include <QLabel>
39 #include <QPushButton>
40 #include <QRadioButton>
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)
51 const int spacing = KDialog::spacingHint();
53 QVBoxLayout* topLayout = new QVBoxLayout(this);
54 KVBox* vBox = new KVBox(this);
55 vBox->setSpacing(spacing);
57 // create 'Home URL' editor
58 QGroupBox* homeBox = new QGroupBox(i18nc("@title:group", "Home Folder"), vBox);
60 KHBox* homeUrlBox = new KHBox(homeBox);
61 homeUrlBox->setSpacing(spacing);
63 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox);
64 m_homeUrl = new KLineEdit(homeUrlBox);
65 m_homeUrl->setClearButtonShown(true);
67 QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder-open"), QString(), homeUrlBox);
68 connect(selectHomeUrlButton, SIGNAL(clicked()),
69 this, SLOT(selectHomeUrl()));
71 KHBox* buttonBox = new KHBox(homeBox);
72 buttonBox->setSpacing(spacing);
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()));
81 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
82 homeBoxLayout->addWidget(homeUrlBox);
83 homeBoxLayout->addWidget(buttonBox);
85 // create 'Split view', '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()));
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);
100 topLayout->addWidget(vBox);
102 loadSettings();
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()));
109 StartupSettingsPage::~StartupSettingsPage()
113 void StartupSettingsPage::applySettings()
115 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
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 and will not be applied."));
125 settings->setSplitView(m_splitView->isChecked());
126 settings->setEditableUrl(m_editableUrl->isChecked());
127 settings->setShowFullPath(m_showFullPath->isChecked());
128 settings->setFilterBar(m_filterBar->isChecked());
131 void StartupSettingsPage::restoreDefaults()
133 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
134 settings->setDefaults();
135 loadSettings();
138 void StartupSettingsPage::selectHomeUrl()
140 const QString homeUrl = m_homeUrl->text();
141 KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl, this);
142 if (!url.isEmpty()) {
143 m_homeUrl->setText(url.prettyUrl());
144 emit changed();
148 void StartupSettingsPage::useCurrentLocation()
150 m_homeUrl->setText(m_url.prettyUrl());
153 void StartupSettingsPage::useDefaultLocation()
155 m_homeUrl->setText(QDir::homePath());
158 void StartupSettingsPage::loadSettings()
160 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
161 m_homeUrl->setText(settings->homeUrl());
162 m_splitView->setChecked(settings->splitView());
163 m_editableUrl->setChecked(settings->editableUrl());
164 m_showFullPath->setChecked(settings->showFullPath());
165 m_filterBar->setChecked(settings->filterBar());
168 #include "startupsettingspage.moc"