]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/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"
23 #include "additionalinfodialog.h"
24 #include "views/rolesaccessor.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 <Nepomuk/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 RolesAccessor
& rolesAccessor
= RolesAccessor::instance();
111 const QList
<QByteArray
> roles
= rolesAccessor
.roles();
112 foreach (const QByteArray
& role
, roles
) {
113 m_sorting
->addItem(rolesAccessor
.translation(role
), role
);
116 m_sortFoldersFirst
= new QCheckBox(i18nc("@option:check", "Show folders first"));
117 m_previewsShown
= new QCheckBox(i18nc("@option:check", "Show preview"));
118 m_showInGroups
= new QCheckBox(i18nc("@option:check", "Show in groups"));
119 m_showHiddenFiles
= new QCheckBox(i18nc("@option:check", "Show hidden files"));
121 m_additionalInfo
= new QPushButton(i18nc("@action:button", "Additional Information"));
123 QHBoxLayout
* sortingLayout
= new QHBoxLayout();
124 sortingLayout
->setMargin(0);
125 sortingLayout
->addWidget(m_sortOrder
);
126 sortingLayout
->addWidget(m_sorting
);
127 sortingBox
->setLayout(sortingLayout
);
129 QGridLayout
* propsGridLayout
= new QGridLayout(propsGrid
);
130 propsGridLayout
->addWidget(viewModeLabel
, 0, 0, Qt::AlignRight
);
131 propsGridLayout
->addWidget(m_viewMode
, 0, 1);
132 propsGridLayout
->addWidget(sortingLabel
, 1, 0, Qt::AlignRight
);
133 propsGridLayout
->addWidget(sortingBox
, 1, 1);
135 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
136 propsBoxLayout
->addWidget(propsGrid
);
137 propsBoxLayout
->addWidget(m_sortFoldersFirst
);
138 propsBoxLayout
->addWidget(m_previewsShown
);
139 propsBoxLayout
->addWidget(m_showInGroups
);
140 propsBoxLayout
->addWidget(m_showHiddenFiles
);
141 propsBoxLayout
->addWidget(m_additionalInfo
);
143 topLayout
->addWidget(propsBox
);
145 connect(m_viewMode
, SIGNAL(currentIndexChanged(int)),
146 this, SLOT(slotViewModeChanged(int)));
147 connect(m_sorting
, SIGNAL(currentIndexChanged(int)),
148 this, SLOT(slotSortingChanged(int)));
149 connect(m_sortOrder
, SIGNAL(currentIndexChanged(int)),
150 this, SLOT(slotSortOrderChanged(int)));
151 connect(m_additionalInfo
, SIGNAL(clicked()),
152 this, SLOT(configureAdditionalInfo()));
153 connect(m_sortFoldersFirst
, SIGNAL(clicked()),
154 this, SLOT(slotSortFoldersFirstChanged()));
155 connect(m_previewsShown
, SIGNAL(clicked()),
156 this, SLOT(slotShowPreviewChanged()));
157 connect(m_showInGroups
, SIGNAL(clicked()),
158 this, SLOT(slotGroupedSortingChanged()));
159 connect(m_showHiddenFiles
, SIGNAL(clicked()),
160 this, SLOT(slotShowHiddenFilesChanged()));
162 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
163 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
165 // Only show the following settings if the view properties are remembered
166 // for each directory:
167 if (!useGlobalViewProps
) {
168 // create 'Apply View Properties To' group
169 QGroupBox
* applyBox
= new QGroupBox(i18nc("@title:group", "Apply View Properties To"), main
);
171 m_applyToCurrentFolder
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
172 "Current folder"), applyBox
);
173 m_applyToCurrentFolder
->setChecked(true);
174 m_applyToSubFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
175 "Current folder including all sub-folders"), applyBox
);
176 m_applyToAllFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
177 "All folders"), applyBox
);
179 QButtonGroup
* applyGroup
= new QButtonGroup(this);
180 applyGroup
->addButton(m_applyToCurrentFolder
);
181 applyGroup
->addButton(m_applyToSubFolders
);
182 applyGroup
->addButton(m_applyToAllFolders
);
184 QVBoxLayout
* applyBoxLayout
= new QVBoxLayout(applyBox
);
185 applyBoxLayout
->addWidget(m_applyToCurrentFolder
);
186 applyBoxLayout
->addWidget(m_applyToSubFolders
);
187 applyBoxLayout
->addWidget(m_applyToAllFolders
);
189 m_useAsDefault
= new QCheckBox(i18nc("@option:check", "Use these view properties as default"), main
);
191 topLayout
->addWidget(applyBox
);
192 topLayout
->addWidget(m_useAsDefault
);
194 connect(m_applyToCurrentFolder
, SIGNAL(clicked(bool)),
195 this, SLOT(markAsDirty(bool)));
196 connect(m_applyToSubFolders
, SIGNAL(clicked(bool)),
197 this, SLOT(markAsDirty(bool)));
198 connect(m_applyToAllFolders
, SIGNAL(clicked(bool)),
199 this, SLOT(markAsDirty(bool)));
200 connect(m_useAsDefault
, SIGNAL(clicked(bool)),
201 this, SLOT(markAsDirty(bool)));
204 main
->setLayout(topLayout
);
207 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
208 "ViewPropertiesDialog");
209 restoreDialogSize(dialogConfig
);
214 ViewPropertiesDialog::~ViewPropertiesDialog()
220 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
221 "ViewPropertiesDialog");
222 saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
225 void ViewPropertiesDialog::slotOk()
227 applyViewProperties();
231 void ViewPropertiesDialog::slotApply()
233 applyViewProperties();
237 void ViewPropertiesDialog::slotViewModeChanged(int index
)
239 const QVariant itemData
= m_viewMode
->itemData(index
);
240 const DolphinView::Mode viewMode
= static_cast<DolphinView::Mode
>(itemData
.toInt());
241 m_viewProps
->setViewMode(viewMode
);
245 void ViewPropertiesDialog::slotSortingChanged(int index
)
247 const QByteArray role
= m_sorting
->itemData(index
).toByteArray();
248 m_viewProps
->setSortRole(role
);
252 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
254 const Qt::SortOrder sortOrder
= (index
== 0) ? Qt::AscendingOrder
: Qt::DescendingOrder
;
255 m_viewProps
->setSortOrder(sortOrder
);
259 void ViewPropertiesDialog::slotGroupedSortingChanged()
261 m_viewProps
->setGroupedSorting(m_showInGroups
->isChecked());
265 void ViewPropertiesDialog::slotSortFoldersFirstChanged()
267 const bool foldersFirst
= m_sortFoldersFirst
->isChecked();
268 m_viewProps
->setSortFoldersFirst(foldersFirst
);
272 void ViewPropertiesDialog::slotShowPreviewChanged()
274 const bool show
= m_previewsShown
->isChecked();
275 m_viewProps
->setPreviewsShown(show
);
279 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
281 const bool show
= m_showHiddenFiles
->isChecked();
282 m_viewProps
->setHiddenFilesShown(show
);
286 void ViewPropertiesDialog::markAsDirty(bool isDirty
)
289 enableButtonApply(isDirty
);
292 void ViewPropertiesDialog::configureAdditionalInfo()
294 QList
<QByteArray
> visibleRoles
= m_viewProps
->visibleRoles();
295 const bool useDefaultRoles
= (m_viewProps
->viewMode() == DolphinView::DetailsView
) && visibleRoles
.isEmpty();
296 if (useDefaultRoles
) {
297 // Using the details view without any additional information (-> additional column)
298 // makes no sense and leads to a usability problem as no viewport area is available
299 // anymore. Hence as fallback provide at least a size and date column.
300 visibleRoles
.clear();
301 visibleRoles
.append("name");
302 visibleRoles
.append("size");
303 visibleRoles
.append("date");
304 m_viewProps
->setVisibleRoles(visibleRoles
);
307 QPointer
<AdditionalInfoDialog
> dialog
= new AdditionalInfoDialog(this, visibleRoles
);
308 if (dialog
->exec() == QDialog::Accepted
) {
309 m_viewProps
->setVisibleRoles(dialog
->visibleRoles());
315 void ViewPropertiesDialog::applyViewProperties()
317 // if nothing changed in the dialog, we have nothing to apply
322 const bool applyToSubFolders
= m_applyToSubFolders
&& m_applyToSubFolders
->isChecked();
323 if (applyToSubFolders
) {
324 const QString
text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?"));
325 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
329 ViewPropsProgressInfo
* info
= new ViewPropsProgressInfo(m_dolphinView
,
330 m_dolphinView
->url(),
332 info
->setAttribute(Qt::WA_DeleteOnClose
);
333 info
->setWindowModality(Qt::NonModal
);
337 const bool applyToAllFolders
= m_applyToAllFolders
&& m_applyToAllFolders
->isChecked();
339 // If the user selected 'Apply To All Folders' the view properties implicitely
340 // are also used as default for new folders.
341 const bool useAsDefault
= applyToAllFolders
|| (m_useAsDefault
&& m_useAsDefault
->isChecked());
343 // For directories where no .directory file is available, the .directory
344 // file stored for the global view properties is used as fallback. To update
345 // this file we temporary turn on the global view properties mode.
346 Q_ASSERT(!GeneralSettings::globalViewProps());
348 GeneralSettings::setGlobalViewProps(true);
349 ViewProperties
defaultProps(m_dolphinView
->url());
350 defaultProps
.setDirProperties(*m_viewProps
);
352 GeneralSettings::setGlobalViewProps(false);
355 if (applyToAllFolders
) {
356 const QString
text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?"));
357 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
361 // Updating the global view properties time stamp in the general settings makes
362 // all existing viewproperties invalid, as they have a smaller time stamp.
363 GeneralSettings
* settings
= GeneralSettings::self();
364 settings
->setViewPropsTimestamp(QDateTime::currentDateTime());
365 settings
->writeConfig();
368 m_dolphinView
->setMode(m_viewProps
->viewMode());
369 m_dolphinView
->setSortRole(m_viewProps
->sortRole());
370 m_dolphinView
->setSortOrder(m_viewProps
->sortOrder());
371 m_dolphinView
->setSortFoldersFirst(m_viewProps
->sortFoldersFirst());
372 m_dolphinView
->setGroupedSorting(m_viewProps
->groupedSorting());
373 m_dolphinView
->setVisibleRoles(m_viewProps
->visibleRoles());
374 m_dolphinView
->setPreviewsShown(m_viewProps
->previewsShown());
375 m_dolphinView
->setHiddenFilesShown(m_viewProps
->hiddenFilesShown());
382 void ViewPropertiesDialog::loadSettings()
385 switch (m_viewProps
->viewMode()) {
386 case DolphinView::IconsView
: m_viewMode
->setCurrentIndex(0); break;
387 case DolphinView::CompactView
: m_viewMode
->setCurrentIndex(1); break;
388 case DolphinView::DetailsView
: m_viewMode
->setCurrentIndex(2); break;
392 // Load sort order and sorting
393 const int sortOrderIndex
= (m_viewProps
->sortOrder() == Qt::AscendingOrder
) ? 0 : 1;
394 m_sortOrder
->setCurrentIndex(sortOrderIndex
);
396 const QList
<QByteArray
> roles
= RolesAccessor::instance().roles();
397 const int sortRoleIndex
= roles
.indexOf(m_viewProps
->sortRole());
398 m_sorting
->setCurrentIndex(sortRoleIndex
);
400 m_sortFoldersFirst
->setChecked(m_viewProps
->sortFoldersFirst());
402 // Load show preview, show in groups and show hidden files settings
403 m_previewsShown
->setChecked(m_viewProps
->previewsShown());
404 m_showInGroups
->setChecked(m_viewProps
->groupedSorting());
405 m_showHiddenFiles
->setChecked(m_viewProps
->hiddenFilesShown());
409 #include "viewpropertiesdialog.moc"