]>
cloud.milkyroute.net Git - dolphin.git/blob - src/viewpropertiesdialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "viewpropertiesdialog.h"
22 #include "viewpropsprogressinfo.h"
25 #include <kiconloader.h>
26 #include <kmessagebox.h>
31 #include <QGridLayout>
34 #include <QRadioButton>
35 #include <QVBoxLayout>
37 #include "viewproperties.h"
38 #include "dolphinview.h"
40 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView
* dolphinView
) :
43 m_dolphinView(dolphinView
),
50 m_applyToSubFolders(0),
53 assert(dolphinView
!= 0);
55 setCaption(i18n("View Properties"));
56 setButtons(KDialog::Ok
| KDialog::Cancel
| KDialog::Apply
);
58 const KUrl
& url
= dolphinView
->url();
59 m_viewProps
= new ViewProperties(url
);
60 m_viewProps
->setAutoSaveEnabled(false);
62 QWidget
* main
= new QWidget();
63 QVBoxLayout
* topLayout
= new QVBoxLayout();
65 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
66 QGroupBox
* propsBox
= new QGroupBox(i18n("Properties"), main
);
68 QLabel
* viewModeLabel
= new QLabel(i18n("View mode:"), propsBox
);
69 m_viewMode
= new QComboBox(propsBox
);
70 m_viewMode
->addItem(SmallIcon("view_icon"), i18n("Icons"));
71 m_viewMode
->addItem(SmallIcon("view_text"), i18n("Details"));
72 const int index
= static_cast<int>(m_viewProps
->viewMode());
73 m_viewMode
->setCurrentIndex(index
);
75 QLabel
* sortingLabel
= new QLabel(i18n("Sorting:"), propsBox
);
76 m_sorting
= new QComboBox(propsBox
);
77 m_sorting
->addItem("By Name");
78 m_sorting
->addItem("By Size");
79 m_sorting
->addItem("By Date");
81 switch (m_viewProps
->sorting()) {
82 case DolphinView::SortByName
: sortingIdx
= 0; break;
83 case DolphinView::SortBySize
: sortingIdx
= 1; break;
84 case DolphinView::SortByDate
: sortingIdx
= 2; break;
87 m_sorting
->setCurrentIndex(sortingIdx
);
89 QLabel
* sortOrderLabel
= new QLabel(i18n("Sort order:"), propsBox
);
90 m_sortOrder
= new QComboBox(propsBox
);
91 m_sortOrder
->addItem(i18n("Ascending"));
92 m_sortOrder
->addItem(i18n("Descending"));
93 const int sortOrderIdx
= (m_viewProps
->sortOrder() == Qt::Ascending
) ? 0 : 1;
94 m_sortOrder
->setCurrentIndex(sortOrderIdx
);
96 m_showPreview
= new QCheckBox(i18n("Show preview"), propsBox
);
97 m_showPreview
->setChecked(m_viewProps
->showPreview());
99 m_showHiddenFiles
= new QCheckBox(i18n("Show hidden files"), propsBox
);
100 m_showHiddenFiles
->setChecked(m_viewProps
->showHiddenFiles());
102 QGridLayout
* propsBoxLayout
= new QGridLayout(propsBox
);
103 propsBoxLayout
->addWidget(viewModeLabel
, 0, 0);
104 propsBoxLayout
->addWidget(m_viewMode
, 0, 1);
105 propsBoxLayout
->addWidget(m_sorting
, 1, 1);
106 propsBoxLayout
->addWidget(sortingLabel
, 1, 0);
107 propsBoxLayout
->addWidget(m_sorting
, 1, 1);
108 propsBoxLayout
->addWidget(sortOrderLabel
, 2, 0);
109 propsBoxLayout
->addWidget(m_sortOrder
, 2, 1);
110 propsBoxLayout
->addWidget(m_showPreview
, 3, 0);
111 propsBoxLayout
->addWidget(m_showHiddenFiles
, 4, 0);
113 m_applyToSubFolders
= new QCheckBox(i18n("Apply changes to all sub folders"), main
);
114 m_useAsDefault
= new QCheckBox(i18n("Use as default"), main
);
116 topLayout
->addWidget(propsBox
);
117 topLayout
->addWidget(m_applyToSubFolders
);
118 topLayout
->addWidget(m_useAsDefault
);
120 connect(m_viewMode
, SIGNAL(activated(int)),
121 this, SLOT(slotViewModeChanged(int)));
122 connect(m_sorting
, SIGNAL(activated(int)),
123 this, SLOT(slotSortingChanged(int)));
124 connect(m_sortOrder
, SIGNAL(activated(int)),
125 this, SLOT(slotSortOrderChanged(int)));
126 connect(m_showPreview
, SIGNAL(clicked()),
127 this, SLOT(slotShowPreviewChanged()));
128 connect(m_showHiddenFiles
, SIGNAL(clicked()),
129 this, SLOT(slotShowHiddenFilesChanged()));
131 connect(m_applyToSubFolders
, SIGNAL(clicked()),
132 this, SLOT(markAsDirty()));
133 connect(m_applyToSubFolders
, SIGNAL(clicked()),
134 this, SLOT(markAsDirty()));
136 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
137 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
139 main
->setLayout(topLayout
);
143 ViewPropertiesDialog::~ViewPropertiesDialog()
150 void ViewPropertiesDialog::slotOk()
152 applyViewProperties();
156 void ViewPropertiesDialog::slotApply()
158 applyViewProperties();
161 void ViewPropertiesDialog::slotViewModeChanged(int index
)
163 assert((index
>= 0) && (index
<= 2));
164 m_viewProps
->setViewMode(static_cast<DolphinView::Mode
>(index
));
168 void ViewPropertiesDialog::slotSortingChanged(int index
)
170 DolphinView::Sorting sorting
= DolphinView::SortByName
;
172 case 1: sorting
= DolphinView::SortBySize
; break;
173 case 2: sorting
= DolphinView::SortByDate
; break;
176 m_viewProps
->setSorting(sorting
);
180 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
182 Qt::SortOrder sortOrder
= (index
== 0) ? Qt::Ascending
: Qt::Descending
;
183 m_viewProps
->setSortOrder(sortOrder
);
187 void ViewPropertiesDialog::slotShowPreviewChanged()
189 const bool show
= m_showPreview
->isChecked();
190 m_viewProps
->setShowPreview(show
);
194 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
196 const bool show
= m_showHiddenFiles
->isChecked();
197 m_viewProps
->setShowHiddenFiles(show
);
201 void ViewPropertiesDialog::markAsDirty()
206 void ViewPropertiesDialog::applyViewProperties()
208 if (m_applyToSubFolders
->isChecked() && m_isDirty
) {
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
) {
214 ViewPropsProgressInfo
* info
= new ViewPropsProgressInfo(m_dolphinView
,
215 m_dolphinView
->url(),
217 info
->setWindowModality(Qt::NonModal
);
222 m_dolphinView
->setViewProperties(*m_viewProps
);
225 // TODO: handle m_useAsDefault setting
228 #include "viewpropertiesdialog.moc"