]>
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
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"
32 #include <kiconloader.h>
33 #include <kmessagebox.h>
35 #include <QButtonGroup>
38 #include <QGridLayout>
41 #include <QRadioButton>
42 #include <QVBoxLayout>
44 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView
* dolphinView
) :
47 m_dolphinView(dolphinView
),
54 m_applyToCurrentFolder(0),
55 m_applyToSubFolders(0),
58 assert(dolphinView
!= 0);
60 setCaption(i18n("View Properties"));
61 setButtons(KDialog::Ok
| KDialog::Cancel
| KDialog::Apply
);
63 const KUrl
& url
= dolphinView
->url();
64 m_viewProps
= new ViewProperties(url
);
65 m_viewProps
->setAutoSaveEnabled(false);
67 QWidget
* main
= new QWidget();
68 QVBoxLayout
* topLayout
= new QVBoxLayout();
70 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
71 QGroupBox
* propsBox
= new QGroupBox(i18n("Properties"), main
);
73 QLabel
* viewModeLabel
= new QLabel(i18n("View mode:"), propsBox
);
74 m_viewMode
= new QComboBox(propsBox
);
75 m_viewMode
->addItem(SmallIcon("view_icon"), i18n("Icons"));
76 m_viewMode
->addItem(SmallIcon("view_text"), i18n("Details"));
77 const int index
= static_cast<int>(m_viewProps
->viewMode());
78 m_viewMode
->setCurrentIndex(index
);
80 QLabel
* sortingLabel
= new QLabel(i18n("Sorting:"), propsBox
);
81 m_sorting
= new QComboBox(propsBox
);
82 m_sorting
->addItem("By Name");
83 m_sorting
->addItem("By Size");
84 m_sorting
->addItem("By Date");
85 m_sorting
->addItem("By Permissions");
86 m_sorting
->addItem("By Owner");
87 m_sorting
->addItem("By Group");
88 m_sorting
->setCurrentIndex(m_viewProps
->sorting());
90 QLabel
* sortOrderLabel
= new QLabel(i18n("Sort order:"), propsBox
);
91 m_sortOrder
= new QComboBox(propsBox
);
92 m_sortOrder
->addItem(i18n("Ascending"));
93 m_sortOrder
->addItem(i18n("Descending"));
94 const int sortOrderIdx
= (m_viewProps
->sortOrder() == Qt::Ascending
) ? 0 : 1;
95 m_sortOrder
->setCurrentIndex(sortOrderIdx
);
97 m_showPreview
= new QCheckBox(i18n("Show preview"), propsBox
);
98 m_showPreview
->setChecked(m_viewProps
->showPreview());
100 m_showHiddenFiles
= new QCheckBox(i18n("Show hidden files"), propsBox
);
101 m_showHiddenFiles
->setChecked(m_viewProps
->showHiddenFiles());
103 QGridLayout
* propsBoxLayout
= new QGridLayout(propsBox
);
104 propsBoxLayout
->addWidget(viewModeLabel
, 0, 0);
105 propsBoxLayout
->addWidget(m_viewMode
, 0, 1);
106 propsBoxLayout
->addWidget(m_sorting
, 1, 1);
107 propsBoxLayout
->addWidget(sortingLabel
, 1, 0);
108 propsBoxLayout
->addWidget(m_sorting
, 1, 1);
109 propsBoxLayout
->addWidget(sortOrderLabel
, 2, 0);
110 propsBoxLayout
->addWidget(m_sortOrder
, 2, 1);
111 propsBoxLayout
->addWidget(m_showPreview
, 3, 0);
112 propsBoxLayout
->addWidget(m_showHiddenFiles
, 4, 0);
114 topLayout
->addWidget(propsBox
);
116 connect(m_viewMode
, SIGNAL(activated(int)),
117 this, SLOT(slotViewModeChanged(int)));
118 connect(m_sorting
, SIGNAL(activated(int)),
119 this, SLOT(slotSortingChanged(int)));
120 connect(m_sortOrder
, SIGNAL(activated(int)),
121 this, SLOT(slotSortOrderChanged(int)));
122 connect(m_showPreview
, SIGNAL(clicked()),
123 this, SLOT(slotShowPreviewChanged()));
124 connect(m_showHiddenFiles
, SIGNAL(clicked()),
125 this, SLOT(slotShowHiddenFilesChanged()));
127 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
128 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
130 // Only show the following settings if the view properties are remembered
131 // for each directory:
132 if (!DolphinSettings::instance().generalSettings()->globalViewProps()) {
133 // create 'Apply view properties to:' group
134 QGroupBox
* applyBox
= new QGroupBox(i18n("Apply view properties to:"), main
);
136 m_applyToCurrentFolder
= new QRadioButton(i18n("Current folder"), applyBox
);
137 m_applyToCurrentFolder
->setChecked(true);
138 m_applyToSubFolders
= new QRadioButton(i18n("Current folder including all sub folders"), applyBox
);
140 QButtonGroup
* applyGroup
= new QButtonGroup(this);
141 applyGroup
->addButton(m_applyToCurrentFolder
);
142 applyGroup
->addButton(m_applyToSubFolders
);
144 QVBoxLayout
* applyBoxLayout
= new QVBoxLayout(applyBox
);
145 applyBoxLayout
->addWidget(m_applyToCurrentFolder
);
146 applyBoxLayout
->addWidget(m_applyToSubFolders
);
148 m_useAsDefault
= new QCheckBox(i18n("Use as default for new folders"), main
);
150 topLayout
->addWidget(applyBox
);
151 topLayout
->addWidget(m_useAsDefault
);
153 connect(m_applyToCurrentFolder
, SIGNAL(clicked()),
154 this, SLOT(markAsDirty()));
155 connect(m_applyToSubFolders
, SIGNAL(clicked()),
156 this, SLOT(markAsDirty()));
157 connect(m_useAsDefault
, SIGNAL(clicked()),
158 this, SLOT(markAsDirty()));
161 main
->setLayout(topLayout
);
165 ViewPropertiesDialog::~ViewPropertiesDialog()
172 void ViewPropertiesDialog::slotOk()
174 applyViewProperties();
178 void ViewPropertiesDialog::slotApply()
180 applyViewProperties();
183 void ViewPropertiesDialog::slotViewModeChanged(int index
)
185 assert((index
>= 0) && (index
<= 2));
186 m_viewProps
->setViewMode(static_cast<DolphinView::Mode
>(index
));
190 void ViewPropertiesDialog::slotSortingChanged(int index
)
192 const DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(index
);
193 m_viewProps
->setSorting(sorting
);
197 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
199 Qt::SortOrder sortOrder
= (index
== 0) ? Qt::Ascending
: Qt::Descending
;
200 m_viewProps
->setSortOrder(sortOrder
);
204 void ViewPropertiesDialog::slotShowPreviewChanged()
206 const bool show
= m_showPreview
->isChecked();
207 m_viewProps
->setShowPreview(show
);
211 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
213 const bool show
= m_showHiddenFiles
->isChecked();
214 m_viewProps
->setShowHiddenFiles(show
);
218 void ViewPropertiesDialog::markAsDirty()
223 void ViewPropertiesDialog::applyViewProperties()
225 const bool applyToSubFolders
= m_isDirty
&&
226 (m_applyToSubFolders
!= 0) &&
227 m_applyToSubFolders
->isChecked();
228 if (applyToSubFolders
) {
229 const QString
text(i18n("The view properties of all sub folders will be changed. Do you want to continue?"));
230 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
234 ViewPropsProgressInfo
* info
= new ViewPropsProgressInfo(m_dolphinView
,
235 m_dolphinView
->url(),
237 info
->setWindowModality(Qt::NonModal
);
243 m_dolphinView
->setMode(m_viewProps
->viewMode());
244 m_dolphinView
->setSorting(m_viewProps
->sorting());
245 m_dolphinView
->setSortOrder(m_viewProps
->sortOrder());
246 m_dolphinView
->setShowPreview(m_viewProps
->showPreview());
247 m_dolphinView
->setShowHiddenFiles(m_viewProps
->showHiddenFiles());
251 // TODO: handle m_useAsDefault setting
254 #include "viewpropertiesdialog.moc"