]> cloud.milkyroute.net Git - dolphin.git/blob - src/viewpropertiesdialog.cpp
Use a QLinkedList instead of Q3PtrList
[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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "viewpropertiesdialog.h"
22 #include "viewpropsprogressinfo.h"
23
24 #include <klocale.h>
25 #include <kiconloader.h>
26 #include <kmessagebox.h>
27 #include <assert.h>
28
29 #include <QCheckBox>
30 #include <QComboBox>
31 #include <QGridLayout>
32 #include <QGroupBox>
33 #include <QLabel>
34 #include <QRadioButton>
35 #include <QVBoxLayout>
36
37 #include "viewproperties.h"
38 #include "dolphinview.h"
39
40 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
41 KDialog(dolphinView),
42 m_isDirty(false),
43 m_dolphinView(dolphinView)
44 {
45 assert(dolphinView != 0);
46
47 setCaption(i18n("View Properties"));
48 setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
49
50 const KUrl& url = dolphinView->url();
51 m_viewProps = new ViewProperties(url);
52 m_viewProps->setAutoSaveEnabled(false);
53
54 QWidget* main = new QWidget();
55 QVBoxLayout* topLayout = new QVBoxLayout();
56
57 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
58 QGroupBox* propsBox = new QGroupBox(i18n("Properties"), main);
59
60 QLabel* viewModeLabel = new QLabel(i18n("View mode:"), propsBox);
61 m_viewMode = new QComboBox(propsBox);
62 m_viewMode->addItem(SmallIcon("view_icon"), i18n("Icons"));
63 m_viewMode->addItem(SmallIcon("view_text"), i18n("Details"));
64 m_viewMode->addItem(SmallIcon("gvdirpart"), i18n("Previews"));
65 const int index = static_cast<int>(m_viewProps->viewMode());
66 m_viewMode->setCurrentIndex(index);
67
68 QLabel* sortingLabel = new QLabel(i18n("Sorting:"), propsBox);
69 m_sorting = new QComboBox(propsBox);
70 m_sorting->addItem("By Name");
71 m_sorting->addItem("By Size");
72 m_sorting->addItem("By Date");
73 int sortingIdx = 0;
74 switch (m_viewProps->sorting()) {
75 case DolphinView::SortByName: sortingIdx = 0; break;
76 case DolphinView::SortBySize: sortingIdx = 1; break;
77 case DolphinView::SortByDate: sortingIdx = 2; break;
78 default: break;
79 }
80 m_sorting->setCurrentIndex(sortingIdx);
81
82 QLabel* sortOrderLabel = new QLabel(i18n("Sort order:"), propsBox);
83 m_sortOrder = new QComboBox(propsBox);
84 m_sortOrder->addItem(i18n("Ascending"));
85 m_sortOrder->addItem(i18n("Descending"));
86 const int sortOrderIdx = (m_viewProps->sortOrder() == Qt::Ascending) ? 0 : 1;
87 m_sortOrder->setCurrentIndex(sortOrderIdx);
88
89 m_showHiddenFiles = new QCheckBox(i18n("Show hidden files"), propsBox);
90 m_showHiddenFiles->setChecked(m_viewProps->isShowHiddenFilesEnabled());
91
92 QGridLayout* propsBoxLayout = new QGridLayout(propsBox);
93 propsBoxLayout->addWidget(viewModeLabel, 0, 0);
94 propsBoxLayout->addWidget(m_viewMode, 0, 1);
95 propsBoxLayout->addWidget(m_sorting, 1, 1);
96 propsBoxLayout->addWidget(sortingLabel, 1, 0);
97 propsBoxLayout->addWidget(m_sorting, 1, 1);
98 propsBoxLayout->addWidget(sortOrderLabel, 2, 0);
99 propsBoxLayout->addWidget(m_sortOrder, 2, 1);
100 propsBoxLayout->addWidget(m_showHiddenFiles, 3, 0);
101
102 m_applyToSubFolders = new QCheckBox(i18n("Apply changes to all sub folders"), main);
103 topLayout->addWidget(propsBox);
104 topLayout->addWidget(m_applyToSubFolders);
105
106 connect(m_viewMode, SIGNAL(activated(int)),
107 this, SLOT(slotViewModeChanged(int)));
108 connect(m_sorting, SIGNAL(activated(int)),
109 this, SLOT(slotSortingChanged(int)));
110 connect(m_sortOrder, SIGNAL(activated(int)),
111 this, SLOT(slotSortOrderChanged(int)));
112 connect(m_showHiddenFiles, SIGNAL(clicked()),
113 this, SLOT(slotShowHiddenFilesChanged()));
114
115 connect(m_applyToSubFolders, SIGNAL(clicked()),
116 this, SLOT(markAsDirty()));
117
118 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
119 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
120
121 main->setLayout(topLayout);
122 setMainWidget(main);
123 }
124
125 ViewPropertiesDialog::~ViewPropertiesDialog()
126 {
127 m_isDirty = false;
128 delete m_viewProps;
129 m_viewProps = 0;
130 }
131
132 void ViewPropertiesDialog::slotOk()
133 {
134 applyViewProperties();
135 accept();
136 }
137
138 void ViewPropertiesDialog::slotApply()
139 {
140 applyViewProperties();
141 }
142
143 void ViewPropertiesDialog::slotViewModeChanged(int index)
144 {
145 assert((index >= 0) && (index <= 2));
146 m_viewProps->setViewMode(static_cast<DolphinView::Mode>(index));
147 m_isDirty = true;
148 }
149
150 void ViewPropertiesDialog::slotSortingChanged(int index)
151 {
152 DolphinView::Sorting sorting = DolphinView::SortByName;
153 switch (index) {
154 case 1: sorting = DolphinView::SortBySize; break;
155 case 2: sorting = DolphinView::SortByDate; break;
156 default: break;
157 }
158 m_viewProps->setSorting(sorting);
159 m_isDirty = true;
160 }
161
162 void ViewPropertiesDialog::slotSortOrderChanged(int index)
163 {
164 Qt::SortOrder sortOrder = (index == 0) ? Qt::Ascending : Qt::Descending;
165 m_viewProps->setSortOrder(sortOrder);
166 m_isDirty = true;
167 }
168
169 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
170 {
171 const bool show = m_showHiddenFiles->isChecked();
172 m_viewProps->setShowHiddenFilesEnabled(show);
173 m_isDirty = true;
174 }
175
176 void ViewPropertiesDialog::markAsDirty()
177 {
178 m_isDirty = true;
179 }
180
181 void ViewPropertiesDialog::applyViewProperties()
182 {
183 if (m_applyToSubFolders->isChecked() && m_isDirty) {
184 const QString text(i18n("The view properties of all sub folders will be changed. Do you want to continue?"));
185 if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) {
186 return;
187 }
188
189 ViewPropsProgressInfo* info = new ViewPropsProgressInfo(m_dolphinView,
190 m_dolphinView->url(),
191 *m_viewProps);
192 info->setWindowModality(Qt::NonModal);
193 info->show();
194 }
195
196 m_viewProps->save();
197 m_dolphinView->setViewProperties(*m_viewProps);
198 m_isDirty = false;
199 }
200
201 #include "viewpropertiesdialog.moc"