]> cloud.milkyroute.net Git - dolphin.git/blob - src/startupsettingspage.cpp
Make sort/descending available in dolphinpart
[dolphin.git] / src / 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 "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 <kvbox.h>
33
34 #include <QCheckBox>
35 #include <QGroupBox>
36 #include <QLabel>
37 #include <QLineEdit>
38 #include <QPushButton>
39 #include <QRadioButton>
40
41 StartupSettingsPage::StartupSettingsPage(DolphinMainWindow* mainWin, QWidget* parent) :
42 SettingsPageBase(parent),
43 m_mainWindow(mainWin),
44 m_homeUrl(0),
45 m_splitView(0),
46 m_editableUrl(0),
47 m_filterBar(0)
48 {
49 const int spacing = KDialog::spacingHint();
50
51 QVBoxLayout* topLayout = new QVBoxLayout(this);
52 KVBox* vBox = new KVBox(this);
53 vBox->setSpacing(spacing);
54
55 // create 'Home URL' editor
56 QGroupBox* homeBox = new QGroupBox(i18nc("@title:group", "Home Folder"), vBox);
57
58 KHBox* homeUrlBox = new KHBox(homeBox);
59 homeUrlBox->setSpacing(spacing);
60
61 new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox);
62 m_homeUrl = new QLineEdit(homeUrlBox);
63
64 QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder-open"), QString(), homeUrlBox);
65 connect(selectHomeUrlButton, SIGNAL(clicked()),
66 this, SLOT(selectHomeUrl()));
67
68 KHBox* buttonBox = new KHBox(homeBox);
69 buttonBox->setSpacing(spacing);
70
71 QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox);
72 connect(useCurrentButton, SIGNAL(clicked()),
73 this, SLOT(useCurrentLocation()));
74 QPushButton* useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox);
75 connect(useDefaultButton, SIGNAL(clicked()),
76 this, SLOT(useDefaultLocation()));
77
78 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
79 homeBoxLayout->addWidget(homeUrlBox);
80 homeBoxLayout->addWidget(buttonBox);
81
82 // create 'Split view', 'Editable location' and 'Filter bar' checkboxes
83 m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox);
84 m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox);
85 m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox);
86
87 // Add a dummy widget with no restriction regarding
88 // a vertical resizing. This assures that the dialog layout
89 // is not stretched vertically.
90 new QWidget(vBox);
91
92 topLayout->addWidget(vBox);
93
94 loadSettings();
95 }
96
97 StartupSettingsPage::~StartupSettingsPage()
98 {
99 }
100
101 void StartupSettingsPage::applySettings()
102 {
103 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
104
105 const KUrl url(m_homeUrl->text());
106 KFileItem fileItem(S_IFDIR, KFileItem::Unknown, url);
107 if (url.isValid() && fileItem.isDir()) {
108 settings->setHomeUrl(url.prettyUrl());
109 }
110
111 settings->setSplitView(m_splitView->isChecked());
112 settings->setEditableUrl(m_editableUrl->isChecked());
113 settings->setFilterBar(m_filterBar->isChecked());
114 }
115
116 void StartupSettingsPage::restoreDefaults()
117 {
118 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
119 settings->setDefaults();
120 loadSettings();
121 }
122
123 void StartupSettingsPage::selectHomeUrl()
124 {
125 const QString homeUrl = m_homeUrl->text();
126 KUrl url = KFileDialog::getExistingDirectoryUrl(homeUrl);
127 if (!url.isEmpty()) {
128 m_homeUrl->setText(url.prettyUrl());
129 }
130 }
131
132 void StartupSettingsPage::useCurrentLocation()
133 {
134 const DolphinView* view = m_mainWindow->activeViewContainer()->view();
135 m_homeUrl->setText(view->url().prettyUrl());
136 }
137
138 void StartupSettingsPage::useDefaultLocation()
139 {
140 m_homeUrl->setText("file://" + QDir::homePath());
141 }
142
143 void StartupSettingsPage::loadSettings()
144 {
145 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
146 m_homeUrl->setText(settings->homeUrl());
147 m_splitView->setChecked(settings->splitView());
148 m_editableUrl->setChecked(settings->editableUrl());
149 m_filterBar->setChecked(settings->filterBar());
150 }
151
152 #include "startupsettingspage.moc"