]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalsettingspage.cpp
- assure that when hovering the viewport that an empty request for item information...
[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 <kdialog.h>
24 #include <kfiledialog.h>
25 #include <klocale.h>
26 #include <kvbox.h>
27
28 #include <QtGui/QCheckBox>
29 #include <QtGui/QGroupBox>
30 #include <QtGui/QLabel>
31 #include <QtGui/QLineEdit>
32 #include <QtGui/QPushButton>
33 #include <QtGui/QRadioButton>
34
35 #include "dolphinsettings.h"
36 #include "dolphinmainwindow.h"
37 #include "dolphinview.h"
38
39 #include "dolphin_generalsettings.h"
40
41 GeneralSettingsPage::GeneralSettingsPage(DolphinMainWindow* mainWin, QWidget* parent) :
42 SettingsPageBase(parent),
43 m_mainWindow(mainWin),
44 m_homeUrl(0),
45 m_splitView(0),
46 m_editableUrl(0),
47 m_filterBar(0),
48 m_showDeleteCommand(0)
49 {
50 const int spacing = KDialog::spacingHint();
51 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
52
53 QVBoxLayout* topLayout = new QVBoxLayout(this);
54 KVBox* vBox = new KVBox(this);
55 vBox->setSpacing(spacing);
56
57 // create 'Home URL' editor
58 QGroupBox* homeBox = new QGroupBox(i18n("Home Folder"), vBox);
59
60 KHBox* homeUrlBox = new KHBox(homeBox);
61 homeUrlBox->setSpacing(spacing);
62
63 new QLabel(i18n("Location:"), homeUrlBox);
64 m_homeUrl = new QLineEdit(settings->homeUrl(), homeUrlBox);
65
66 QPushButton* selectHomeUrlButton = new QPushButton(KIcon("folder"), QString(), homeUrlBox);
67 connect(selectHomeUrlButton, SIGNAL(clicked()),
68 this, SLOT(selectHomeUrl()));
69
70 KHBox* buttonBox = new KHBox(homeBox);
71 buttonBox->setSpacing(spacing);
72
73 QPushButton* useCurrentButton = new QPushButton(i18n("Use Current Location"), buttonBox);
74 connect(useCurrentButton, SIGNAL(clicked()),
75 this, SLOT(useCurrentLocation()));
76 QPushButton* useDefaultButton = new QPushButton(i18n("Use Default Location"), buttonBox);
77 connect(useDefaultButton, SIGNAL(clicked()),
78 this, SLOT(useDefaultLocation()));
79
80 QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox);
81 homeBoxLayout->addWidget(homeUrlBox);
82 homeBoxLayout->addWidget(buttonBox);
83
84 QGroupBox* startBox = new QGroupBox(i18n("Start"), vBox);
85
86 // create 'Split view' checkbox
87 m_splitView = new QCheckBox(i18n("Split view"), startBox);
88 m_splitView->setChecked(settings->splitView());
89
90 // create 'Editable location' checkbox
91 m_editableUrl = new QCheckBox(i18n("Editable location"), startBox);
92 m_editableUrl->setChecked(settings->editableUrl());
93
94 // create 'Filter bar' checkbox
95 m_filterBar = new QCheckBox(i18n("Filter bar"),startBox);
96 m_filterBar->setChecked(settings->filterBar());
97
98 QVBoxLayout* startBoxLayout = new QVBoxLayout(startBox);
99 startBoxLayout->addWidget(m_splitView);
100 startBoxLayout->addWidget(m_editableUrl);
101 startBoxLayout->addWidget(m_filterBar);
102
103 m_showDeleteCommand = new QCheckBox(i18n("Show the command 'Delete' in context menu"), vBox);
104 const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
105 const KConfigGroup kdeConfig(globalConfig, "KDE");
106 m_showDeleteCommand->setChecked(kdeConfig.readEntry("ShowDeleteCommand", false));
107
108 // Add a dummy widget with no restriction regarding
109 // a vertical resizing. This assures that the dialog layout
110 // is not stretched vertically.
111 new QWidget(vBox);
112
113 topLayout->addWidget(vBox);
114 }
115
116
117 GeneralSettingsPage::~GeneralSettingsPage()
118 {}
119
120 void GeneralSettingsPage::applySettings()
121 {
122 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
123
124 const KUrl url(m_homeUrl->text());
125 KFileItem fileItem(S_IFDIR, KFileItem::Unknown, url);
126 if (url.isValid() && fileItem.isDir()) {
127 settings->setHomeUrl(url.prettyUrl());
128 }
129
130 settings->setSplitView(m_splitView->isChecked());
131 settings->setEditableUrl(m_editableUrl->isChecked());
132 settings->setFilterBar(m_filterBar->isChecked());
133
134 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
135 KConfigGroup kdeConfig(globalConfig, "KDE");
136 kdeConfig.writeEntry("ShowDeleteCommand", m_showDeleteCommand->isChecked());
137 kdeConfig.sync();
138 }
139
140 void GeneralSettingsPage::selectHomeUrl()
141 {
142 const QString homeUrl(m_homeUrl->text());
143 KUrl url(KFileDialog::getExistingDirectoryUrl(homeUrl));
144 if (!url.isEmpty()) {
145 m_homeUrl->setText(url.prettyUrl());
146 }
147 }
148
149 void GeneralSettingsPage::useCurrentLocation()
150 {
151 const DolphinView* view = m_mainWindow->activeView();
152 m_homeUrl->setText(view->url().prettyUrl());
153 }
154
155 void GeneralSettingsPage::useDefaultLocation()
156 {
157 m_homeUrl->setText("file://" + QDir::homePath());
158 }
159
160 #include "generalsettingspage.moc"