]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
Add libkmetadata detection and minor fixes
[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 "dolphin_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 Folder"), 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(), 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 QGroupBox* startBox = new QGroupBox(i18n("Start"), vBox);
93
94 // create 'Start with split view' checkbox
95 m_startSplit = new QCheckBox(i18n("Start with split view"), startBox);
96 m_startSplit->setChecked(settings->splitView());
97
98 // create 'Start with editable navigation bar' checkbox
99 m_startEditable = new QCheckBox(i18n("Start with editable navigation bar"), startBox);
100 m_startEditable->setChecked(settings->editableUrl());
101
102 QVBoxLayout* startBoxLayout = new QVBoxLayout(startBox);
103 startBoxLayout->addWidget(m_startSplit);
104 startBoxLayout->addWidget(m_startEditable);
105
106 // Add a dummy widget with no restriction regarding
107 // a vertical resizing. This assures that the dialog layout
108 // is not stretched vertically.
109 new QWidget(vBox);
110
111 topLayout->addWidget(vBox);
112 }
113
114
115 GeneralSettingsPage::~GeneralSettingsPage()
116 {
117 }
118
119 void GeneralSettingsPage::applySettings()
120 {
121 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
122
123 const KUrl url(m_homeUrl->text());
124 KFileItem fileItem(S_IFDIR, KFileItem::Unknown, url);
125 if (url.isValid() && fileItem.isDir()) {
126 settings->setHomeUrl(url.prettyUrl());
127 }
128
129 settings->setSplitView(m_startSplit->isChecked());
130 settings->setEditableUrl(m_startEditable->isChecked());
131 }
132
133 void GeneralSettingsPage::selectHomeUrl()
134 {
135 const QString homeUrl(m_homeUrl->text());
136 KUrl url(KFileDialog::getExistingUrl(homeUrl));
137 if (!url.isEmpty()) {
138 m_homeUrl->setText(url.prettyUrl());
139 }
140 }
141
142 void GeneralSettingsPage::useCurrentLocation()
143 {
144 const DolphinView* view = m_mainWindow->activeView();
145 m_homeUrl->setText(view->url().prettyUrl());
146 }
147
148 void GeneralSettingsPage::useDefaulLocation()
149 {
150 m_homeUrl->setText("file://" + QDir::homePath());
151 }
152
153 #include "generalsettingspage.moc"