]>
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
);
100 switch (settings
->defaultViewMode()) {
101 case DolphinView::IconsView
: m_iconsView
->setChecked(true); break;
102 case DolphinView::DetailsView
: m_detailsView
->setChecked(true); break;
105 // create 'Start with split view' checkbox
106 m_startSplit
= new QCheckBox(i18n("Start with split view"), vBox
);
107 m_startSplit
->setChecked(settings
->splitView());
109 // create 'Start with editable navigation bar' checkbox
110 m_startEditable
= new QCheckBox(i18n("Start with editable navigation bar"), vBox
);
111 m_startEditable
->setChecked(settings
->editableUrl());
113 // Add a dummy widget with no restriction regarding
114 // a vertical resizing. This assures that the dialog layout
115 // is not stretched vertically.
118 topLayout
->addWidget(vBox
);
122 GeneralSettingsPage::~GeneralSettingsPage()
126 void GeneralSettingsPage::applySettings()
128 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
130 const KUrl
url(m_homeUrl
->text());
131 KFileItem
fileItem(S_IFDIR
, KFileItem::Unknown
, url
);
132 if (url
.isValid() && fileItem
.isDir()) {
133 settings
->setHomeUrl(url
.prettyUrl());
136 const DolphinView::Mode viewMode
= m_detailsView
->isChecked() ?
137 DolphinView::DetailsView
:
138 DolphinView::IconsView
;
139 settings
->setDefaultViewMode(viewMode
);
141 settings
->setSplitView(m_startSplit
->isChecked());
142 settings
->setEditableUrl(m_startEditable
->isChecked());
145 void GeneralSettingsPage::selectHomeUrl()
147 const QString
homeUrl(m_homeUrl
->text());
148 KUrl
url(KFileDialog::getExistingUrl(homeUrl
));
149 if (!url
.isEmpty()) {
150 m_homeUrl
->setText(url
.prettyUrl());
154 void GeneralSettingsPage::useCurrentLocation()
156 const DolphinView
* view
= m_mainWindow
->activeView();
157 m_homeUrl
->setText(view
->url().prettyUrl());
160 void GeneralSettingsPage::useDefaulLocation()
162 m_homeUrl
->setText("file://" + QDir::homePath());
165 #include "generalsettingspage.moc"