]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
Update the FSF address to 51 Franklin Street (hopefully it is the right one)
[dolphin.git] / src / generalsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "generalsettingspage.h"
22
23 #include <qlayout.h>
24 //Added by qt3to4:
25 #include <Q3VBoxLayout>
26 #include <kdialog.h>
27 #include <qlabel.h>
28 #include <qlineedit.h>
29
30 #include <q3grid.h>
31 #include <q3groupbox.h>
32 #include <klocale.h>
33 #include <qcheckbox.h>
34 #include <q3buttongroup.h>
35 #include <qpushbutton.h>
36 #include <kfiledialog.h>
37 #include <qradiobutton.h>
38 #include <kvbox.h>
39
40 #include "dolphinsettings.h"
41 #include "dolphinmainwindow.h"
42 #include "dolphinview.h"
43 #include "generalsettings.h"
44
45 GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow* mainWin,QWidget* parent) :
46 SettingsPageBase(parent),
47 m_mainWindow(mainWin),
48 m_homeUrl(0),
49 m_startSplit(0),
50 m_startEditable(0)
51 {
52 Q3VBoxLayout* topLayout = new Q3VBoxLayout(this, 2, KDialog::spacingHint());
53
54 const int spacing = KDialog::spacingHint();
55 const int margin = KDialog::marginHint();
56 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
57
58 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
59
60 KVBox* vBox = new KVBox(this);
61 vBox->setSizePolicy(sizePolicy);
62 vBox->setSpacing(spacing);
63 vBox->setMargin(margin);
64 vBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
65
66 // create 'Home Url' editor
67 Q3GroupBox* homeGroup = new Q3GroupBox(1, Qt::Horizontal, i18n("Home Url"), vBox);
68 homeGroup->setSizePolicy(sizePolicy);
69 homeGroup->setMargin(margin);
70
71 KHBox* homeUrlBox = new KHBox(homeGroup);
72 homeUrlBox->setSizePolicy(sizePolicy);
73 homeUrlBox->setSpacing(spacing);
74
75 new QLabel(i18n("Location:"), homeUrlBox);
76 m_homeUrl = new QLineEdit(settings->homeUrl(), homeUrlBox);
77
78 QPushButton* selectHomeUrlButton = new QPushButton(SmallIcon("folder"), QString::null, homeUrlBox);
79 connect(selectHomeUrlButton, SIGNAL(clicked()),
80 this, SLOT(selectHomeUrl()));
81
82 KHBox* buttonBox = new KHBox(homeGroup);
83 buttonBox->setSizePolicy(sizePolicy);
84 buttonBox->setSpacing(spacing);
85 QPushButton* useCurrentButton = new QPushButton(i18n("Use current location"), buttonBox);
86 connect(useCurrentButton, SIGNAL(clicked()),
87 this, SLOT(useCurrentLocation()));
88 QPushButton* useDefaultButton = new QPushButton(i18n("Use default location"), buttonBox);
89 connect(useDefaultButton, SIGNAL(clicked()),
90 this, SLOT(useDefaulLocation()));
91
92 // create 'Default View Mode' group
93 Q3ButtonGroup* buttonGroup = new Q3ButtonGroup(3, Qt::Vertical, i18n("Default View Mode"), vBox);
94 buttonGroup->setSizePolicy(sizePolicy);
95 buttonGroup->setMargin(margin);
96
97 m_iconsView = new QRadioButton(i18n("Icons"), buttonGroup);
98 m_detailsView = new QRadioButton(i18n("Details"), buttonGroup);
99 m_previewsView = new QRadioButton(i18n("Previews"), buttonGroup);
100
101 switch (settings->defaultViewMode()) {
102 case DolphinView::IconsView: m_iconsView->setChecked(true); break;
103 case DolphinView::DetailsView: m_detailsView->setChecked(true); break;
104 case DolphinView::PreviewsView: m_previewsView->setChecked(true); break;
105 }
106
107 // create 'Start with split view' checkbox
108 m_startSplit = new QCheckBox(i18n("Start with split view"), vBox);
109 m_startSplit->setChecked(settings->splitView());
110
111 // create 'Start with editable navigation bar' checkbox
112 m_startEditable = new QCheckBox(i18n("Start with editable navigation bar"), vBox);
113 m_startEditable->setChecked(settings->editableUrl());
114
115 // Add a dummy widget with no restriction regarding
116 // a vertical resizing. This assures that the dialog layout
117 // is not stretched vertically.
118 new QWidget(vBox);
119
120 topLayout->addWidget(vBox);
121 }
122
123
124 GeneralSettingsPage::~GeneralSettingsPage()
125 {
126 }
127
128 void GeneralSettingsPage::applySettings()
129 {
130 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
131
132 const KUrl url(m_homeUrl->text());
133 KFileItem fileItem(S_IFDIR, KFileItem::Unknown, url);
134 if (url.isValid() && fileItem.isDir()) {
135 settings->setHomeUrl(url.prettyUrl());
136 }
137
138 DolphinView::Mode viewMode = DolphinView::IconsView;
139 if (m_detailsView->isChecked()) {
140 viewMode = DolphinView::DetailsView;
141 }
142 else if (m_previewsView->isChecked()) {
143 viewMode = DolphinView::PreviewsView;
144 }
145 settings->setDefaultViewMode(viewMode);
146
147 settings->setSplitView(m_startSplit->isChecked());
148 settings->setEditableUrl(m_startEditable->isChecked());
149 }
150
151 void GeneralSettingsPage::selectHomeUrl()
152 {
153 const QString homeUrl(m_homeUrl->text());
154 KUrl url(KFileDialog::getExistingUrl(homeUrl));
155 if (!url.isEmpty()) {
156 m_homeUrl->setText(url.prettyUrl());
157 }
158 }
159
160 void GeneralSettingsPage::useCurrentLocation()
161 {
162 const DolphinView* view = m_mainWindow->activeView();
163 m_homeUrl->setText(view->url().prettyUrl());
164 }
165
166 void GeneralSettingsPage::useDefaulLocation()
167 {
168 m_homeUrl->setText("file://" + QDir::homePath());
169 }
170
171 #include "generalsettingspage.moc"