]>
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
)
45 assert(dolphinView
!= 0);
47 setCaption(i18n("View Properties"));
48 setButtons(KDialog::Ok
| KDialog::Cancel
| KDialog::Apply
);
50 const KUrl
& url
= dolphinView
->url();
51 m_viewProps
= new ViewProperties(url
);
52 m_viewProps
->setAutoSaveEnabled(false);
54 QWidget
* main
= new QWidget();
55 QVBoxLayout
* topLayout
= new QVBoxLayout();
57 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
58 QGroupBox
* propsBox
= new QGroupBox(i18n("Properties"), main
);
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
);
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");
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;
80 m_sorting
->setCurrentIndex(sortingIdx
);
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
);
89 m_showHiddenFiles
= new QCheckBox(i18n("Show hidden files"), propsBox
);
90 m_showHiddenFiles
->setChecked(m_viewProps
->isShowHiddenFilesEnabled());
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);
102 // create 'Apply view properties to:' group
103 QGroupBox
* buttonBox
= new QGroupBox(i18n("Apply view properties to:"), main
);
104 m_applyToCurrentFolder
= new QRadioButton(i18n("Current folder"), buttonBox
);
105 m_applyToSubFolders
= new QRadioButton(i18n("Current folder including all sub folders"), buttonBox
);
106 m_applyToAllFolders
= new QRadioButton(i18n("All folders"), buttonBox
);
108 QVBoxLayout
* buttonBoxLayout
= new QVBoxLayout();
109 buttonBoxLayout
->addWidget(m_applyToCurrentFolder
);
110 buttonBoxLayout
->addWidget(m_applyToSubFolders
);
111 buttonBoxLayout
->addWidget(m_applyToAllFolders
);
112 buttonBox
->setLayout(buttonBoxLayout
);
114 m_applyToCurrentFolder
->setChecked(true);
116 topLayout
->addWidget(propsBox
);
117 topLayout
->addWidget(buttonBox
);
119 connect(m_viewMode
, SIGNAL(activated(int)),
120 this, SLOT(slotViewModeChanged(int)));
121 connect(m_sorting
, SIGNAL(activated(int)),
122 this, SLOT(slotSortingChanged(int)));
123 connect(m_sortOrder
, SIGNAL(activated(int)),
124 this, SLOT(slotSortOrderChanged(int)));
125 connect(m_showHiddenFiles
, SIGNAL(clicked()),
126 this, SLOT(slotShowHiddenFilesChanged()));
127 connect(m_applyToCurrentFolder
, SIGNAL(clicked()),
128 this, SLOT(slotApplyToCurrentFolder()));
129 connect(m_applyToSubFolders
, SIGNAL(clicked()),
130 this, SLOT(slotApplyToSubFolders()));
131 connect(m_applyToAllFolders
, SIGNAL(clicked()),
132 this, SLOT(slotApplyToAllFolders()));
134 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
135 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
137 main
->setLayout(topLayout
);
141 ViewPropertiesDialog::~ViewPropertiesDialog()
148 void ViewPropertiesDialog::slotOk()
150 applyViewProperties();
154 void ViewPropertiesDialog::slotApply()
156 applyViewProperties();
159 void ViewPropertiesDialog::slotViewModeChanged(int index
)
161 assert((index
>= 0) && (index
<= 2));
162 m_viewProps
->setViewMode(static_cast<DolphinView::Mode
>(index
));
166 void ViewPropertiesDialog::slotSortingChanged(int index
)
168 DolphinView::Sorting sorting
= DolphinView::SortByName
;
170 case 1: sorting
= DolphinView::SortBySize
; break;
171 case 2: sorting
= DolphinView::SortByDate
; break;
174 m_viewProps
->setSorting(sorting
);
178 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
180 Qt::SortOrder sortOrder
= (index
== 0) ? Qt::Ascending
: Qt::Descending
;
181 m_viewProps
->setSortOrder(sortOrder
);
185 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
187 const bool show
= m_showHiddenFiles
->isChecked();
188 m_viewProps
->setShowHiddenFilesEnabled(show
);
192 void ViewPropertiesDialog::slotApplyToCurrentFolder()
197 void ViewPropertiesDialog::slotApplyToSubFolders()
199 //m_viewProps->setValidForSubDirs(true);
203 void ViewPropertiesDialog::slotApplyToAllFolders()
208 void ViewPropertiesDialog::applyViewProperties()
210 if (m_applyToAllFolders
->isChecked()) {
212 const QString
text(i18n("The view properties of all folders will be replaced. Do you want to continue?"));
213 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
218 //ViewProperties props(QDir::homePath());
219 //props.setViewMode(m_viewProps->viewMode());
220 //props.setSorting(m_viewProps->sorting());
221 //props.setSortOrder(m_viewProps->sortOrder());
222 //props.setShowHiddenFilesEnabled(m_viewProps->isShowHiddenFilesEnabled());
223 //props.setValidForSubDirs(true);
225 else if (m_applyToSubFolders
->isChecked() && m_isDirty
) {
226 const QString
text(i18n("The view properties of all sub folders will be replaced. Do you want to continue?"));
227 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
231 ViewPropsProgressInfo
dlg(this, m_dolphinView
->url(), m_viewProps
);
236 m_dolphinView
->setViewProperties(*m_viewProps
);
240 #include "viewpropertiesdialog.moc"