]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
Initial step for moving to KDirModel. Large code parts have been deleted, as a step...
[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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "dolphin.h"
42 #include "dolphinview.h"
43 #include "generalsettings.h"
44
45 GeneralSettingsPage::GeneralSettingsPage(QWidget* parent) :
46 SettingsPageBase(parent),
47 m_homeUrl(0),
48 m_startSplit(0),
49 m_startEditable(0)
50 {
51 Q3VBoxLayout* topLayout = new Q3VBoxLayout(parent, 2, KDialog::spacingHint());
52
53 const int spacing = KDialog::spacingHint();
54 const int margin = KDialog::marginHint();
55 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
56
57 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
58
59 KVBox* vBox = new KVBox(parent);
60 vBox->setSizePolicy(sizePolicy);
61 vBox->setSpacing(spacing);
62 vBox->setMargin(margin);
63 vBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
64
65 // create 'Home Url' editor
66 Q3GroupBox* homeGroup = new Q3GroupBox(1, Qt::Horizontal, i18n("Home Url"), vBox);
67 homeGroup->setSizePolicy(sizePolicy);
68 homeGroup->setMargin(margin);
69
70 KHBox* homeUrlBox = new KHBox(homeGroup);
71 homeUrlBox->setSizePolicy(sizePolicy);
72 homeUrlBox->setSpacing(spacing);
73
74 new QLabel(i18n("Location:"), homeUrlBox);
75 m_homeUrl = new QLineEdit(settings->homeUrl(), homeUrlBox);
76
77 QPushButton* selectHomeUrlButton = new QPushButton(SmallIcon("folder"), QString::null, homeUrlBox);
78 connect(selectHomeUrlButton, SIGNAL(clicked()),
79 this, SLOT(selectHomeUrl()));
80
81 KHBox* buttonBox = new KHBox(homeGroup);
82 buttonBox->setSizePolicy(sizePolicy);
83 buttonBox->setSpacing(spacing);
84 QPushButton* useCurrentButton = new QPushButton(i18n("Use current location"), buttonBox);
85 connect(useCurrentButton, SIGNAL(clicked()),
86 this, SLOT(useCurrentLocation()));
87 QPushButton* useDefaultButton = new QPushButton(i18n("Use default location"), buttonBox);
88 connect(useDefaultButton, SIGNAL(clicked()),
89 this, SLOT(useDefaulLocation()));
90
91 // create 'Default View Mode' group
92 Q3ButtonGroup* buttonGroup = new Q3ButtonGroup(3, Qt::Vertical, i18n("Default View Mode"), vBox);
93 buttonGroup->setSizePolicy(sizePolicy);
94 buttonGroup->setMargin(margin);
95
96 m_iconsView = new QRadioButton(i18n("Icons"), buttonGroup);
97 m_detailsView = new QRadioButton(i18n("Details"), buttonGroup);
98 m_previewsView = new QRadioButton(i18n("Previews"), buttonGroup);
99
100 switch (settings->defaultViewMode()) {
101 case DolphinView::IconsView: m_iconsView->setChecked(true); break;
102 case DolphinView::DetailsView: m_detailsView->setChecked(true); break;
103 case DolphinView::PreviewsView: m_previewsView->setChecked(true); break;
104 }
105
106 // create 'Start with split view' checkbox
107 m_startSplit = new QCheckBox(i18n("Start with split view"), vBox);
108 m_startSplit->setChecked(settings->splitView());
109
110 // create 'Start with editable navigation bar' checkbox
111 m_startEditable = new QCheckBox(i18n("Start with editable navigation bar"), vBox);
112 m_startEditable->setChecked(settings->editableUrl());
113
114 // Add a dummy widget with no restriction regarding
115 // a vertical resizing. This assures that the dialog layout
116 // is not stretched vertically.
117 new QWidget(vBox);
118
119 topLayout->addWidget(vBox);
120 }
121
122
123 GeneralSettingsPage::~GeneralSettingsPage()
124 {
125 }
126
127 void GeneralSettingsPage::applySettings()
128 {
129 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
130
131 const KUrl url(m_homeUrl->text());
132 KFileItem fileItem(S_IFDIR, KFileItem::Unknown, url);
133 if (url.isValid() && fileItem.isDir()) {
134 settings->setHomeUrl(url.prettyUrl());
135 }
136
137 DolphinView::Mode viewMode = DolphinView::IconsView;
138 if (m_detailsView->isChecked()) {
139 viewMode = DolphinView::DetailsView;
140 }
141 else if (m_previewsView->isChecked()) {
142 viewMode = DolphinView::PreviewsView;
143 }
144 settings->setDefaultViewMode(viewMode);
145
146 settings->setSplitView(m_startSplit->isChecked());
147 settings->setEditableUrl(m_startEditable->isChecked());
148 }
149
150 void GeneralSettingsPage::selectHomeUrl()
151 {
152 const QString homeUrl(m_homeUrl->text());
153 KUrl url(KFileDialog::getExistingUrl(homeUrl));
154 if (!url.isEmpty()) {
155 m_homeUrl->setText(url.prettyUrl());
156 }
157 }
158
159 void GeneralSettingsPage::useCurrentLocation()
160 {
161 const DolphinView* view = Dolphin::mainWin().activeView();
162 m_homeUrl->setText(view->url().prettyUrl());
163 }
164
165 void GeneralSettingsPage::useDefaulLocation()
166 {
167 m_homeUrl->setText("file://" + QDir::homePath());
168 }
169
170 #include "generalsettingspage.moc"