]> cloud.milkyroute.net Git - dolphin.git/blob - src/viewpropertiesdialog.cpp
Additionally to sorting by name, size and date it is now possible to sort by permissi...
[dolphin.git] / src / viewpropertiesdialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
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 "viewpropertiesdialog.h"
22 #include "viewpropsprogressinfo.h"
23 #include "dolphinview.h"
24 #include "dolphinsettings.h"
25 #include "dolphinsortfilterproxymodel.h"
26 #include "generalsettings.h"
27 #include "viewproperties.h"
28
29 #include <klocale.h>
30 #include <kiconloader.h>
31 #include <kmessagebox.h>
32 #include <assert.h>
33
34 #include <QCheckBox>
35 #include <QComboBox>
36 #include <QGridLayout>
37 #include <QGroupBox>
38 #include <QLabel>
39 #include <QRadioButton>
40 #include <QVBoxLayout>
41
42 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
43 KDialog(dolphinView),
44 m_isDirty(false),
45 m_dolphinView(dolphinView),
46 m_viewProps(0),
47 m_viewMode(0),
48 m_sorting(0),
49 m_sortOrder(0),
50 m_showPreview(0),
51 m_showHiddenFiles(0),
52 m_applyToSubFolders(0),
53 m_useAsDefault(0)
54 {
55 assert(dolphinView != 0);
56
57 setCaption(i18n("View Properties"));
58 setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
59
60 const KUrl& url = dolphinView->url();
61 m_viewProps = new ViewProperties(url);
62 m_viewProps->setAutoSaveEnabled(false);
63
64 QWidget* main = new QWidget();
65 QVBoxLayout* topLayout = new QVBoxLayout();
66
67 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
68 QGroupBox* propsBox = new QGroupBox(i18n("Properties"), main);
69
70 QLabel* viewModeLabel = new QLabel(i18n("View mode:"), propsBox);
71 m_viewMode = new QComboBox(propsBox);
72 m_viewMode->addItem(SmallIcon("view_icon"), i18n("Icons"));
73 m_viewMode->addItem(SmallIcon("view_text"), i18n("Details"));
74 const int index = static_cast<int>(m_viewProps->viewMode());
75 m_viewMode->setCurrentIndex(index);
76
77 QLabel* sortingLabel = new QLabel(i18n("Sorting:"), propsBox);
78 m_sorting = new QComboBox(propsBox);
79 m_sorting->addItem("By Name");
80 m_sorting->addItem("By Size");
81 m_sorting->addItem("By Date");
82 m_sorting->addItem("By Permissions");
83 m_sorting->addItem("By Owner");
84 m_sorting->addItem("By Group");
85 m_sorting->setCurrentIndex(m_viewProps->sorting());
86
87 QLabel* sortOrderLabel = new QLabel(i18n("Sort order:"), propsBox);
88 m_sortOrder = new QComboBox(propsBox);
89 m_sortOrder->addItem(i18n("Ascending"));
90 m_sortOrder->addItem(i18n("Descending"));
91 const int sortOrderIdx = (m_viewProps->sortOrder() == Qt::Ascending) ? 0 : 1;
92 m_sortOrder->setCurrentIndex(sortOrderIdx);
93
94 m_showPreview = new QCheckBox(i18n("Show preview"), propsBox);
95 m_showPreview->setChecked(m_viewProps->showPreview());
96
97 m_showHiddenFiles = new QCheckBox(i18n("Show hidden files"), propsBox);
98 m_showHiddenFiles->setChecked(m_viewProps->showHiddenFiles());
99
100 QGridLayout* propsBoxLayout = new QGridLayout(propsBox);
101 propsBoxLayout->addWidget(viewModeLabel, 0, 0);
102 propsBoxLayout->addWidget(m_viewMode, 0, 1);
103 propsBoxLayout->addWidget(m_sorting, 1, 1);
104 propsBoxLayout->addWidget(sortingLabel, 1, 0);
105 propsBoxLayout->addWidget(m_sorting, 1, 1);
106 propsBoxLayout->addWidget(sortOrderLabel, 2, 0);
107 propsBoxLayout->addWidget(m_sortOrder, 2, 1);
108 propsBoxLayout->addWidget(m_showPreview, 3, 0);
109 propsBoxLayout->addWidget(m_showHiddenFiles, 4, 0);
110
111 topLayout->addWidget(propsBox);
112
113 connect(m_viewMode, SIGNAL(activated(int)),
114 this, SLOT(slotViewModeChanged(int)));
115 connect(m_sorting, SIGNAL(activated(int)),
116 this, SLOT(slotSortingChanged(int)));
117 connect(m_sortOrder, SIGNAL(activated(int)),
118 this, SLOT(slotSortOrderChanged(int)));
119 connect(m_showPreview, SIGNAL(clicked()),
120 this, SLOT(slotShowPreviewChanged()));
121 connect(m_showHiddenFiles, SIGNAL(clicked()),
122 this, SLOT(slotShowHiddenFilesChanged()));
123
124 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
125 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
126
127 // Only show the following settings if the view properties are remembered
128 // for each directory:
129 if (!DolphinSettings::instance().generalSettings()->globalViewProps()) {
130 m_applyToSubFolders = new QCheckBox(i18n("Apply changes to all sub folders"), main);
131 m_useAsDefault = new QCheckBox(i18n("Use as default"), main);
132 topLayout->addWidget(m_applyToSubFolders);
133 topLayout->addWidget(m_useAsDefault);
134
135 connect(m_applyToSubFolders, SIGNAL(clicked()),
136 this, SLOT(markAsDirty()));
137 connect(m_useAsDefault, SIGNAL(clicked()),
138 this, SLOT(markAsDirty()));
139 }
140
141 main->setLayout(topLayout);
142 setMainWidget(main);
143 }
144
145 ViewPropertiesDialog::~ViewPropertiesDialog()
146 {
147 m_isDirty = false;
148 delete m_viewProps;
149 m_viewProps = 0;
150 }
151
152 void ViewPropertiesDialog::slotOk()
153 {
154 applyViewProperties();
155 accept();
156 }
157
158 void ViewPropertiesDialog::slotApply()
159 {
160 applyViewProperties();
161 }
162
163 void ViewPropertiesDialog::slotViewModeChanged(int index)
164 {
165 assert((index >= 0) && (index <= 2));
166 m_viewProps->setViewMode(static_cast<DolphinView::Mode>(index));
167 m_isDirty = true;
168 }
169
170 void ViewPropertiesDialog::slotSortingChanged(int index)
171 {
172 const DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(index);
173 m_viewProps->setSorting(sorting);
174 m_isDirty = true;
175 }
176
177 void ViewPropertiesDialog::slotSortOrderChanged(int index)
178 {
179 Qt::SortOrder sortOrder = (index == 0) ? Qt::Ascending : Qt::Descending;
180 m_viewProps->setSortOrder(sortOrder);
181 m_isDirty = true;
182 }
183
184 void ViewPropertiesDialog::slotShowPreviewChanged()
185 {
186 const bool show = m_showPreview->isChecked();
187 m_viewProps->setShowPreview(show);
188 m_isDirty = true;
189 }
190
191 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
192 {
193 const bool show = m_showHiddenFiles->isChecked();
194 m_viewProps->setShowHiddenFiles(show);
195 m_isDirty = true;
196 }
197
198 void ViewPropertiesDialog::markAsDirty()
199 {
200 m_isDirty = true;
201 }
202
203 void ViewPropertiesDialog::applyViewProperties()
204 {
205 const bool applyToSubFolders = m_isDirty &&
206 (m_applyToSubFolders != 0) &&
207 m_applyToSubFolders->isChecked();
208 if (applyToSubFolders) {
209 const QString text(i18n("The view properties of all sub folders will be changed. Do you want to continue?"));
210 if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) {
211 return;
212 }
213
214 ViewPropsProgressInfo* info = new ViewPropsProgressInfo(m_dolphinView,
215 m_dolphinView->url(),
216 *m_viewProps);
217 info->setWindowModality(Qt::NonModal);
218 info->show();
219 }
220
221 m_viewProps->save();
222
223 m_dolphinView->setMode(m_viewProps->viewMode());
224 m_dolphinView->setSorting(m_viewProps->sorting());
225 m_dolphinView->setSortOrder(m_viewProps->sortOrder());
226 m_dolphinView->setShowPreview(m_viewProps->showPreview());
227 m_dolphinView->setShowHiddenFiles(m_viewProps->showHiddenFiles());
228
229 m_isDirty = false;
230
231 // TODO: handle m_useAsDefault setting
232 }
233
234 #include "viewpropertiesdialog.moc"