]>
cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
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. *
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. *
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 ***************************************************************************/
21 #include "generalsettingspage.h"
25 #include <Q3VBoxLayout>
28 #include <qlineedit.h>
31 #include <q3groupbox.h>
33 #include <qcheckbox.h>
34 #include <q3buttongroup.h>
35 #include <qpushbutton.h>
36 #include <kfiledialog.h>
37 #include <qradiobutton.h>
40 #include "dolphinsettings.h"
41 #include "dolphinmainwindow.h"
42 #include "dolphinview.h"
43 #include "generalsettings.h"
45 GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow
* mainWin
,QWidget
* parent
) :
46 SettingsPageBase(parent
),
47 m_mainWindow(mainWin
),
52 Q3VBoxLayout
* topLayout
= new Q3VBoxLayout(this, 2, KDialog::spacingHint());
54 const int spacing
= KDialog::spacingHint();
55 const int margin
= KDialog::marginHint();
56 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
58 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
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
);
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
);
71 KHBox
* homeUrlBox
= new KHBox(homeGroup
);
72 homeUrlBox
->setSizePolicy(sizePolicy
);
73 homeUrlBox
->setSpacing(spacing
);
75 new QLabel(i18n("Location:"), homeUrlBox
);
76 m_homeUrl
= new QLineEdit(settings
->homeUrl(), homeUrlBox
);
78 QPushButton
* selectHomeUrlButton
= new QPushButton(SmallIcon("folder"), QString::null
, homeUrlBox
);
79 connect(selectHomeUrlButton
, SIGNAL(clicked()),
80 this, SLOT(selectHomeUrl()));
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()));
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
);
97 m_iconsView
= new QRadioButton(i18n("Icons"), buttonGroup
);
98 m_detailsView
= new QRadioButton(i18n("Details"), buttonGroup
);
99 m_previewsView
= new QRadioButton(i18n("Previews"), buttonGroup
);
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;
107 // create 'Start with split view' checkbox
108 m_startSplit
= new QCheckBox(i18n("Start with split view"), vBox
);
109 m_startSplit
->setChecked(settings
->splitView());
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());
115 // Add a dummy widget with no restriction regarding
116 // a vertical resizing. This assures that the dialog layout
117 // is not stretched vertically.
120 topLayout
->addWidget(vBox
);
124 GeneralSettingsPage::~GeneralSettingsPage()
128 void GeneralSettingsPage::applySettings()
130 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
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());
138 DolphinView::Mode viewMode
= DolphinView::IconsView
;
139 if (m_detailsView
->isChecked()) {
140 viewMode
= DolphinView::DetailsView
;
142 else if (m_previewsView
->isChecked()) {
143 viewMode
= DolphinView::PreviewsView
;
145 settings
->setDefaultViewMode(viewMode
);
147 settings
->setSplitView(m_startSplit
->isChecked());
148 settings
->setEditableUrl(m_startEditable
->isChecked());
151 void GeneralSettingsPage::selectHomeUrl()
153 const QString
homeUrl(m_homeUrl
->text());
154 KUrl
url(KFileDialog::getExistingUrl(homeUrl
));
155 if (!url
.isEmpty()) {
156 m_homeUrl
->setText(url
.prettyUrl());
160 void GeneralSettingsPage::useCurrentLocation()
162 const DolphinView
* view
= m_mainWindow
->activeView();
163 m_homeUrl
->setText(view
->url().prettyUrl());
166 void GeneralSettingsPage::useDefaulLocation()
168 m_homeUrl
->setText("file://" + QDir::homePath());
171 #include "generalsettingspage.moc"