]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewpropertiesdialog.cpp
c5002ff9f2ac682e7d296d2de203b43e5f32a291
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"
23 #include "additionalinfodialog.h"
24 #include "kitemviews/kfileitemmodel.h"
25 #include "views/dolphinview.h"
26 #include "dolphin_generalsettings.h"
27 #include "dolphin_iconsmodesettings.h"
28 #include "viewpropsprogressinfo.h"
30 #include <config-nepomuk.h>
32 #include <Nepomuk2/ResourceManager>
35 #include <KComponentData>
37 #include <KIconLoader>
38 #include <KIO/NetAccess>
39 #include <KMessageBox>
40 #include <KStandardDirs>
45 #include <QButtonGroup>
47 #include <QGridLayout>
51 #include <QPushButton>
52 #include <QRadioButton>
55 #include <views/viewproperties.h>
57 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView
* dolphinView
) :
60 m_dolphinView(dolphinView
),
65 m_sortFoldersFirst(0),
70 m_applyToCurrentFolder(0),
71 m_applyToSubFolders(0),
72 m_applyToAllFolders(0),
75 Q_ASSERT(dolphinView
);
76 const bool useGlobalViewProps
= GeneralSettings::globalViewProps();
78 setCaption(i18nc("@title:window", "View Properties"));
79 setButtons(KDialog::Ok
| KDialog::Cancel
| KDialog::Apply
);
81 const KUrl
& url
= dolphinView
->url();
82 m_viewProps
= new ViewProperties(url
);
83 m_viewProps
->setAutoSaveEnabled(false);
85 QWidget
* main
= new QWidget();
86 QVBoxLayout
* topLayout
= new QVBoxLayout();
88 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
89 QWidget
* propsBox
= main
;
90 if (!useGlobalViewProps
) {
91 propsBox
= new QGroupBox(i18nc("@title:group", "Properties"), main
);
94 QWidget
* propsGrid
= new QWidget();
96 QLabel
* viewModeLabel
= new QLabel(i18nc("@label:listbox", "View mode:"), propsGrid
);
97 m_viewMode
= new KComboBox(propsGrid
);
98 m_viewMode
->addItem(KIcon("view-list-icons"), i18nc("@item:inlistbox", "Icons"), DolphinView::IconsView
);
99 m_viewMode
->addItem(KIcon("view-list-details"), i18nc("@item:inlistbox", "Compact"), DolphinView::CompactView
);
100 m_viewMode
->addItem(KIcon("view-list-tree"), i18nc("@item:inlistbox", "Details"), DolphinView::DetailsView
);
102 QLabel
* sortingLabel
= new QLabel(i18nc("@label:listbox", "Sorting:"), propsGrid
);
103 QWidget
* sortingBox
= new QWidget(propsGrid
);
105 m_sortOrder
= new KComboBox(sortingBox
);
106 m_sortOrder
->addItem(i18nc("@item:inlistbox Sort", "Ascending"));
107 m_sortOrder
->addItem(i18nc("@item:inlistbox Sort", "Descending"));
109 m_sorting
= new KComboBox(sortingBox
);
110 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
111 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
112 m_sorting
->addItem(info
.translation
, info
.role
);
115 m_sortFoldersFirst
= new QCheckBox(i18nc("@option:check", "Show folders first"));
116 m_previewsShown
= new QCheckBox(i18nc("@option:check", "Show preview"));
117 m_showInGroups
= new QCheckBox(i18nc("@option:check", "Show in groups"));
118 m_showHiddenFiles
= new QCheckBox(i18nc("@option:check", "Show hidden files"));
120 m_additionalInfo
= new QPushButton(i18nc("@action:button", "Additional Information"));
122 QHBoxLayout
* sortingLayout
= new QHBoxLayout();
123 sortingLayout
->setMargin(0);
124 sortingLayout
->addWidget(m_sortOrder
);
125 sortingLayout
->addWidget(m_sorting
);
126 sortingBox
->setLayout(sortingLayout
);
128 QGridLayout
* propsGridLayout
= new QGridLayout(propsGrid
);
129 propsGridLayout
->addWidget(viewModeLabel
, 0, 0, Qt::AlignRight
);
130 propsGridLayout
->addWidget(m_viewMode
, 0, 1);
131 propsGridLayout
->addWidget(sortingLabel
, 1, 0, Qt::AlignRight
);
132 propsGridLayout
->addWidget(sortingBox
, 1, 1);
134 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
135 propsBoxLayout
->addWidget(propsGrid
);
136 propsBoxLayout
->addWidget(m_sortFoldersFirst
);
137 propsBoxLayout
->addWidget(m_previewsShown
);
138 propsBoxLayout
->addWidget(m_showInGroups
);
139 propsBoxLayout
->addWidget(m_showHiddenFiles
);
140 propsBoxLayout
->addWidget(m_additionalInfo
);
142 topLayout
->addWidget(propsBox
);
144 connect(m_viewMode
, SIGNAL(currentIndexChanged(int)),
145 this, SLOT(slotViewModeChanged(int)));
146 connect(m_sorting
, SIGNAL(currentIndexChanged(int)),
147 this, SLOT(slotSortingChanged(int)));
148 connect(m_sortOrder
, SIGNAL(currentIndexChanged(int)),
149 this, SLOT(slotSortOrderChanged(int)));
150 connect(m_additionalInfo
, SIGNAL(clicked()),
151 this, SLOT(configureAdditionalInfo()));
152 connect(m_sortFoldersFirst
, SIGNAL(clicked()),
153 this, SLOT(slotSortFoldersFirstChanged()));
154 connect(m_previewsShown
, SIGNAL(clicked()),
155 this, SLOT(slotShowPreviewChanged()));
156 connect(m_showInGroups
, SIGNAL(clicked()),
157 this, SLOT(slotGroupedSortingChanged()));
158 connect(m_showHiddenFiles
, SIGNAL(clicked()),
159 this, SLOT(slotShowHiddenFilesChanged()));
161 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
162 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
164 // Only show the following settings if the view properties are remembered
165 // for each directory:
166 if (!useGlobalViewProps
) {
167 // create 'Apply View Properties To' group
168 QGroupBox
* applyBox
= new QGroupBox(i18nc("@title:group", "Apply View Properties To"), main
);
170 m_applyToCurrentFolder
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
171 "Current folder"), applyBox
);
172 m_applyToCurrentFolder
->setChecked(true);
173 m_applyToSubFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
174 "Current folder including all sub-folders"), applyBox
);
175 m_applyToAllFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
176 "All folders"), applyBox
);
178 QButtonGroup
* applyGroup
= new QButtonGroup(this);
179 applyGroup
->addButton(m_applyToCurrentFolder
);
180 applyGroup
->addButton(m_applyToSubFolders
);
181 applyGroup
->addButton(m_applyToAllFolders
);
183 QVBoxLayout
* applyBoxLayout
= new QVBoxLayout(applyBox
);
184 applyBoxLayout
->addWidget(m_applyToCurrentFolder
);
185 applyBoxLayout
->addWidget(m_applyToSubFolders
);
186 applyBoxLayout
->addWidget(m_applyToAllFolders
);
188 m_useAsDefault
= new QCheckBox(i18nc("@option:check", "Use these view properties as default"), main
);
190 topLayout
->addWidget(applyBox
);
191 topLayout
->addWidget(m_useAsDefault
);
193 connect(m_applyToCurrentFolder
, SIGNAL(clicked(bool)),
194 this, SLOT(markAsDirty(bool)));
195 connect(m_applyToSubFolders
, SIGNAL(clicked(bool)),
196 this, SLOT(markAsDirty(bool)));
197 connect(m_applyToAllFolders
, SIGNAL(clicked(bool)),
198 this, SLOT(markAsDirty(bool)));
199 connect(m_useAsDefault
, SIGNAL(clicked(bool)),
200 this, SLOT(markAsDirty(bool)));
203 main
->setLayout(topLayout
);
206 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
207 "ViewPropertiesDialog");
208 restoreDialogSize(dialogConfig
);
213 ViewPropertiesDialog::~ViewPropertiesDialog()
219 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
220 "ViewPropertiesDialog");
221 saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
224 void ViewPropertiesDialog::slotOk()
226 applyViewProperties();
230 void ViewPropertiesDialog::slotApply()
232 applyViewProperties();
236 void ViewPropertiesDialog::slotViewModeChanged(int index
)
238 const QVariant itemData
= m_viewMode
->itemData(index
);
239 const DolphinView::Mode viewMode
= static_cast<DolphinView::Mode
>(itemData
.toInt());
240 m_viewProps
->setViewMode(viewMode
);
244 void ViewPropertiesDialog::slotSortingChanged(int index
)
246 const QByteArray role
= m_sorting
->itemData(index
).toByteArray();
247 m_viewProps
->setSortRole(role
);
251 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
253 const Qt::SortOrder sortOrder
= (index
== 0) ? Qt::AscendingOrder
: Qt::DescendingOrder
;
254 m_viewProps
->setSortOrder(sortOrder
);
258 void ViewPropertiesDialog::slotGroupedSortingChanged()
260 m_viewProps
->setGroupedSorting(m_showInGroups
->isChecked());
264 void ViewPropertiesDialog::slotSortFoldersFirstChanged()
266 const bool foldersFirst
= m_sortFoldersFirst
->isChecked();
267 m_viewProps
->setSortFoldersFirst(foldersFirst
);
271 void ViewPropertiesDialog::slotShowPreviewChanged()
273 const bool show
= m_previewsShown
->isChecked();
274 m_viewProps
->setPreviewsShown(show
);
278 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
280 const bool show
= m_showHiddenFiles
->isChecked();
281 m_viewProps
->setHiddenFilesShown(show
);
285 void ViewPropertiesDialog::markAsDirty(bool isDirty
)
288 enableButtonApply(isDirty
);
291 void ViewPropertiesDialog::configureAdditionalInfo()
293 QList
<QByteArray
> visibleRoles
= m_viewProps
->visibleRoles();
294 const bool useDefaultRoles
= (m_viewProps
->viewMode() == DolphinView::DetailsView
) && visibleRoles
.isEmpty();
295 if (useDefaultRoles
) {
296 // Using the details view without any additional information (-> additional column)
297 // makes no sense and leads to a usability problem as no viewport area is available
298 // anymore. Hence as fallback provide at least a size and date column.
299 visibleRoles
.clear();
300 visibleRoles
.append("text");
301 visibleRoles
.append("size");
302 visibleRoles
.append("date");
303 m_viewProps
->setVisibleRoles(visibleRoles
);
306 QPointer
<AdditionalInfoDialog
> dialog
= new AdditionalInfoDialog(this, visibleRoles
);
307 if (dialog
->exec() == QDialog::Accepted
) {
308 m_viewProps
->setVisibleRoles(dialog
->visibleRoles());
314 void ViewPropertiesDialog::applyViewProperties()
316 // if nothing changed in the dialog, we have nothing to apply
321 const bool applyToSubFolders
= m_applyToSubFolders
&& m_applyToSubFolders
->isChecked();
322 if (applyToSubFolders
) {
323 const QString
text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?"));
324 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
328 ViewPropsProgressInfo
* info
= new ViewPropsProgressInfo(m_dolphinView
,
329 m_dolphinView
->url(),
331 info
->setAttribute(Qt::WA_DeleteOnClose
);
332 info
->setWindowModality(Qt::NonModal
);
336 const bool applyToAllFolders
= m_applyToAllFolders
&& m_applyToAllFolders
->isChecked();
338 // If the user selected 'Apply To All Folders' the view properties implicitely
339 // are also used as default for new folders.
340 const bool useAsDefault
= applyToAllFolders
|| (m_useAsDefault
&& m_useAsDefault
->isChecked());
342 // For directories where no .directory file is available, the .directory
343 // file stored for the global view properties is used as fallback. To update
344 // this file we temporary turn on the global view properties mode.
345 Q_ASSERT(!GeneralSettings::globalViewProps());
347 GeneralSettings::setGlobalViewProps(true);
348 ViewProperties
defaultProps(m_dolphinView
->url());
349 defaultProps
.setDirProperties(*m_viewProps
);
351 GeneralSettings::setGlobalViewProps(false);
354 if (applyToAllFolders
) {
355 const QString
text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?"));
356 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
360 // Updating the global view properties time stamp in the general settings makes
361 // all existing viewproperties invalid, as they have a smaller time stamp.
362 GeneralSettings
* settings
= GeneralSettings::self();
363 settings
->setViewPropsTimestamp(QDateTime::currentDateTime());
364 settings
->writeConfig();
367 m_dolphinView
->setMode(m_viewProps
->viewMode());
368 m_dolphinView
->setSortRole(m_viewProps
->sortRole());
369 m_dolphinView
->setSortOrder(m_viewProps
->sortOrder());
370 m_dolphinView
->setSortFoldersFirst(m_viewProps
->sortFoldersFirst());
371 m_dolphinView
->setGroupedSorting(m_viewProps
->groupedSorting());
372 m_dolphinView
->setVisibleRoles(m_viewProps
->visibleRoles());
373 m_dolphinView
->setPreviewsShown(m_viewProps
->previewsShown());
374 m_dolphinView
->setHiddenFilesShown(m_viewProps
->hiddenFilesShown());
381 void ViewPropertiesDialog::loadSettings()
384 switch (m_viewProps
->viewMode()) {
385 case DolphinView::IconsView
: m_viewMode
->setCurrentIndex(0); break;
386 case DolphinView::CompactView
: m_viewMode
->setCurrentIndex(1); break;
387 case DolphinView::DetailsView
: m_viewMode
->setCurrentIndex(2); break;
391 // Load sort order and sorting
392 const int sortOrderIndex
= (m_viewProps
->sortOrder() == Qt::AscendingOrder
) ? 0 : 1;
393 m_sortOrder
->setCurrentIndex(sortOrderIndex
);
395 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
396 int sortRoleIndex
= 0;
397 for (int i
= 0; i
< rolesInfo
.count(); ++i
) {
398 if (rolesInfo
[i
].role
== m_viewProps
->sortRole()) {
403 m_sorting
->setCurrentIndex(sortRoleIndex
);
405 m_sortFoldersFirst
->setChecked(m_viewProps
->sortFoldersFirst());
407 // Load show preview, show in groups and show hidden files settings
408 m_previewsShown
->setChecked(m_viewProps
->previewsShown());
409 m_showInGroups
->setChecked(m_viewProps
->groupedSorting());
410 m_showHiddenFiles
->setChecked(m_viewProps
->hiddenFilesShown());
414 #include "viewpropertiesdialog.moc"