Changeset View
Changeset View
Standalone View
Standalone View
src/settings/viewpropertiesdialog.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2006 by Peter Penz * | 2 | * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> * | ||
3 | * peter.penz@gmx.at * | 3 | * Copyright (C) 2018 by Elvis Angelaccio <elvis.angelaccio@kde.org> * | ||
4 | * * | 4 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | 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 * | 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 * | 7 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | 8 | * (at your option) any later version. * | ||
9 | * * | 9 | * * | ||
10 | * This program is distributed in the hope that it will be useful, * | 10 | * This program is distributed in the hope that it will be useful, * | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
13 | * GNU General Public License for more details. * | 13 | * GNU General Public License for more details. * | ||
14 | * * | 14 | * * | ||
15 | * You should have received a copy of the GNU General Public License * | 15 | * You should have received a copy of the GNU General Public License * | ||
16 | * along with this program; if not, write to the * | 16 | * along with this program; if not, write to the * | ||
17 | * Free Software Foundation, Inc., * | 17 | * Free Software Foundation, Inc., * | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||
19 | ***************************************************************************/ | 19 | ***************************************************************************/ | ||
20 | 20 | | |||
21 | #include "viewpropertiesdialog.h" | 21 | #include "viewpropertiesdialog.h" | ||
22 | 22 | | |||
23 | #include "additionalinfodialog.h" | | |||
24 | #include "dolphin_generalsettings.h" | 23 | #include "dolphin_generalsettings.h" | ||
25 | #include "dolphin_iconsmodesettings.h" | 24 | #include "dolphin_iconsmodesettings.h" | ||
26 | #include "kitemviews/kfileitemmodel.h" | 25 | #include "kitemviews/kfileitemmodel.h" | ||
27 | #include "viewpropsprogressinfo.h" | 26 | #include "viewpropsprogressinfo.h" | ||
28 | #include "views/dolphinview.h" | 27 | #include "views/dolphinview.h" | ||
29 | 28 | | |||
29 | #include <KCollapsibleGroupBox> | ||||
30 | #include <KComboBox> | 30 | #include <KComboBox> | ||
31 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | #include <KMessageBox> | 32 | #include <KMessageBox> | ||
33 | #include <KWindowConfig> | 33 | #include <KWindowConfig> | ||
34 | 34 | | |||
35 | #ifdef HAVE_BALOO | ||||
36 | #include <Baloo/IndexerConfig> | ||||
37 | #endif | ||||
38 | | ||||
35 | #include <QButtonGroup> | 39 | #include <QButtonGroup> | ||
36 | #include <QCheckBox> | 40 | #include <QCheckBox> | ||
37 | #include <QGridLayout> | 41 | #include <QGridLayout> | ||
38 | #include <QGroupBox> | 42 | #include <QGroupBox> | ||
39 | #include <QLabel> | 43 | #include <QLabel> | ||
44 | #include <QListWidget> | ||||
40 | #include <QPushButton> | 45 | #include <QPushButton> | ||
41 | #include <QRadioButton> | 46 | #include <QRadioButton> | ||
42 | 47 | | |||
43 | #include <views/viewproperties.h> | 48 | #include <views/viewproperties.h> | ||
44 | 49 | | |||
45 | ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : | 50 | ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : | ||
46 | QDialog(dolphinView), | 51 | QDialog(dolphinView), | ||
47 | m_isDirty(false), | 52 | m_isDirty(false), | ||
48 | m_dolphinView(dolphinView), | 53 | m_dolphinView(dolphinView), | ||
49 | m_viewProps(nullptr), | 54 | m_viewProps(nullptr), | ||
50 | m_viewMode(nullptr), | 55 | m_viewMode(nullptr), | ||
51 | m_sortOrder(nullptr), | 56 | m_sortOrder(nullptr), | ||
52 | m_sorting(nullptr), | 57 | m_sorting(nullptr), | ||
53 | m_sortFoldersFirst(nullptr), | 58 | m_sortFoldersFirst(nullptr), | ||
54 | m_previewsShown(nullptr), | 59 | m_previewsShown(nullptr), | ||
55 | m_showInGroups(nullptr), | 60 | m_showInGroups(nullptr), | ||
56 | m_showHiddenFiles(nullptr), | 61 | m_showHiddenFiles(nullptr), | ||
57 | m_additionalInfo(nullptr), | | |||
58 | m_applyToCurrentFolder(nullptr), | 62 | m_applyToCurrentFolder(nullptr), | ||
59 | m_applyToSubFolders(nullptr), | 63 | m_applyToSubFolders(nullptr), | ||
60 | m_applyToAllFolders(nullptr), | 64 | m_applyToAllFolders(nullptr), | ||
61 | m_useAsDefault(nullptr) | 65 | m_useAsDefault(nullptr) | ||
62 | { | 66 | { | ||
63 | Q_ASSERT(dolphinView); | 67 | Q_ASSERT(dolphinView); | ||
64 | const bool useGlobalViewProps = GeneralSettings::globalViewProps(); | 68 | const bool useGlobalViewProps = GeneralSettings::globalViewProps(); | ||
65 | 69 | | |||
66 | setWindowTitle(i18nc("@title:window", "View Properties")); | 70 | setWindowTitle(i18nc("@title:window", "View Properties")); | ||
67 | setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); | | |||
68 | 71 | | |||
69 | const QUrl& url = dolphinView->url(); | 72 | const QUrl& url = dolphinView->url(); | ||
70 | m_viewProps = new ViewProperties(url); | 73 | m_viewProps = new ViewProperties(url); | ||
71 | m_viewProps->setAutoSaveEnabled(false); | 74 | m_viewProps->setAutoSaveEnabled(false); | ||
72 | 75 | | |||
73 | auto layout = new QVBoxLayout(this); | 76 | auto layout = new QVBoxLayout(this); | ||
77 | // Otherwise the dialog won't resize when we collapse the KCollapsibleGroupBox. | ||||
78 | layout->setSizeConstraint(QLayout::SetFixedSize); | ||||
74 | setLayout(layout); | 79 | setLayout(layout); | ||
75 | 80 | | |||
76 | auto propsGrid = new QWidget(this); | 81 | auto propsGrid = new QWidget(this); | ||
77 | layout->addWidget(propsGrid); | 82 | layout->addWidget(propsGrid); | ||
78 | 83 | | |||
79 | // create 'Properties' group containing view mode, sorting, sort order and show hidden files | 84 | // create 'Properties' group containing view mode, sorting, sort order and show hidden files | ||
80 | QWidget* propsBox = this; | 85 | QWidget* propsBox = this; | ||
81 | if (!useGlobalViewProps) { | 86 | if (!useGlobalViewProps) { | ||
Show All 20 Lines | 106 | foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { | |||
102 | m_sorting->addItem(info.translation, info.role); | 107 | m_sorting->addItem(info.translation, info.role); | ||
103 | } | 108 | } | ||
104 | 109 | | |||
105 | m_sortFoldersFirst = new QCheckBox(i18nc("@option:check", "Show folders first")); | 110 | m_sortFoldersFirst = new QCheckBox(i18nc("@option:check", "Show folders first")); | ||
106 | m_previewsShown = new QCheckBox(i18nc("@option:check", "Show preview")); | 111 | m_previewsShown = new QCheckBox(i18nc("@option:check", "Show preview")); | ||
107 | m_showInGroups = new QCheckBox(i18nc("@option:check", "Show in groups")); | 112 | m_showInGroups = new QCheckBox(i18nc("@option:check", "Show in groups")); | ||
108 | m_showHiddenFiles = new QCheckBox(i18nc("@option:check", "Show hidden files")); | 113 | m_showHiddenFiles = new QCheckBox(i18nc("@option:check", "Show hidden files")); | ||
109 | 114 | | |||
110 | m_additionalInfo = new QPushButton(i18nc("@action:button", "Additional Information")); | 115 | auto additionalInfoBox = new KCollapsibleGroupBox(); | ||
116 | additionalInfoBox->setTitle(i18nc("@title:group", "Additional Information Shown")); | ||||
117 | auto innerLayout = new QVBoxLayout(); | ||||
118 | | ||||
119 | { | ||||
120 | QList<QByteArray> visibleRoles = m_viewProps->visibleRoles(); | ||||
121 | const bool useDefaultRoles = (m_viewProps->viewMode() == DolphinView::DetailsView) && visibleRoles.isEmpty(); | ||||
122 | if (useDefaultRoles) { | ||||
123 | // Using the details view without any additional information (-> additional column) | ||||
124 | // makes no sense and leads to a usability problem as no viewport area is available | ||||
125 | // anymore. Hence as fallback provide at least a size and date column. | ||||
126 | visibleRoles.clear(); | ||||
127 | visibleRoles.append("text"); | ||||
128 | visibleRoles.append("size"); | ||||
129 | visibleRoles.append("modificationtime"); | ||||
130 | m_viewProps->setVisibleRoles(visibleRoles); | ||||
131 | } | ||||
132 | | ||||
133 | // Add checkboxes | ||||
134 | bool indexingEnabled = false; | ||||
135 | #ifdef HAVE_BALOO | ||||
136 | Baloo::IndexerConfig config; | ||||
137 | indexingEnabled = config.fileIndexingEnabled(); | ||||
138 | #endif | ||||
139 | | ||||
140 | m_listWidget = new QListWidget(); | ||||
141 | connect(m_listWidget, &QListWidget::itemChanged, this, &ViewPropertiesDialog::slotItemChanged); | ||||
142 | m_listWidget->setSelectionMode(QAbstractItemView::NoSelection); | ||||
143 | const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation(); | ||||
144 | foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { | ||||
145 | QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget); | ||||
146 | item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked); | ||||
147 | | ||||
148 | const bool enable = ((!info.requiresBaloo && !info.requiresIndexer) || | ||||
149 | (info.requiresBaloo) || | ||||
150 | (info.requiresIndexer && indexingEnabled)) && info.role != "text"; | ||||
151 | | ||||
152 | if (!enable) { | ||||
153 | item->setFlags(item->flags() & ~Qt::ItemIsEnabled); | ||||
154 | } | ||||
155 | } | ||||
156 | innerLayout->addWidget(m_listWidget); | ||||
157 | } | ||||
158 | | ||||
159 | additionalInfoBox->setLayout(innerLayout); | ||||
111 | 160 | | |||
112 | QHBoxLayout* sortingLayout = new QHBoxLayout(); | 161 | QHBoxLayout* sortingLayout = new QHBoxLayout(); | ||
113 | sortingLayout->setMargin(0); | 162 | sortingLayout->setMargin(0); | ||
114 | sortingLayout->addWidget(m_sortOrder); | 163 | sortingLayout->addWidget(m_sortOrder); | ||
115 | sortingLayout->addWidget(m_sorting); | 164 | sortingLayout->addWidget(m_sorting); | ||
116 | sortingBox->setLayout(sortingLayout); | 165 | sortingBox->setLayout(sortingLayout); | ||
117 | 166 | | |||
118 | QGridLayout* propsGridLayout = new QGridLayout(propsGrid); | 167 | QGridLayout* propsGridLayout = new QGridLayout(propsGrid); | ||
119 | propsGridLayout->addWidget(viewModeLabel, 0, 0, Qt::AlignRight); | 168 | propsGridLayout->addWidget(viewModeLabel, 0, 0, Qt::AlignRight); | ||
120 | propsGridLayout->addWidget(m_viewMode, 0, 1); | 169 | propsGridLayout->addWidget(m_viewMode, 0, 1); | ||
121 | propsGridLayout->addWidget(sortingLabel, 1, 0, Qt::AlignRight); | 170 | propsGridLayout->addWidget(sortingLabel, 1, 0, Qt::AlignRight); | ||
122 | propsGridLayout->addWidget(sortingBox, 1, 1); | 171 | propsGridLayout->addWidget(sortingBox, 1, 1); | ||
123 | 172 | | |||
124 | QVBoxLayout* propsBoxLayout = propsBox == this ? layout : new QVBoxLayout(propsBox); | 173 | QVBoxLayout* propsBoxLayout = propsBox == this ? layout : new QVBoxLayout(propsBox); | ||
125 | propsBoxLayout->addWidget(propsGrid); | 174 | propsBoxLayout->addWidget(propsGrid); | ||
126 | propsBoxLayout->addWidget(m_sortFoldersFirst); | 175 | propsBoxLayout->addWidget(m_sortFoldersFirst); | ||
127 | propsBoxLayout->addWidget(m_previewsShown); | 176 | propsBoxLayout->addWidget(m_previewsShown); | ||
128 | propsBoxLayout->addWidget(m_showInGroups); | 177 | propsBoxLayout->addWidget(m_showInGroups); | ||
129 | propsBoxLayout->addWidget(m_showHiddenFiles); | 178 | propsBoxLayout->addWidget(m_showHiddenFiles); | ||
130 | propsBoxLayout->addWidget(m_additionalInfo); | 179 | propsBoxLayout->addWidget(additionalInfoBox); | ||
131 | 180 | | |||
132 | connect(m_viewMode, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged), | 181 | connect(m_viewMode, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged), | ||
133 | this, &ViewPropertiesDialog::slotViewModeChanged); | 182 | this, &ViewPropertiesDialog::slotViewModeChanged); | ||
134 | connect(m_sorting, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged), | 183 | connect(m_sorting, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged), | ||
135 | this, &ViewPropertiesDialog::slotSortingChanged); | 184 | this, &ViewPropertiesDialog::slotSortingChanged); | ||
136 | connect(m_sortOrder, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged), | 185 | connect(m_sortOrder, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged), | ||
137 | this, &ViewPropertiesDialog::slotSortOrderChanged); | 186 | this, &ViewPropertiesDialog::slotSortOrderChanged); | ||
138 | connect(m_additionalInfo, &QPushButton::clicked, | | |||
139 | this, &ViewPropertiesDialog::configureAdditionalInfo); | | |||
140 | connect(m_sortFoldersFirst, &QCheckBox::clicked, | 187 | connect(m_sortFoldersFirst, &QCheckBox::clicked, | ||
141 | this, &ViewPropertiesDialog::slotSortFoldersFirstChanged); | 188 | this, &ViewPropertiesDialog::slotSortFoldersFirstChanged); | ||
142 | connect(m_previewsShown, &QCheckBox::clicked, | 189 | connect(m_previewsShown, &QCheckBox::clicked, | ||
143 | this, &ViewPropertiesDialog::slotShowPreviewChanged); | 190 | this, &ViewPropertiesDialog::slotShowPreviewChanged); | ||
144 | connect(m_showInGroups, &QCheckBox::clicked, | 191 | connect(m_showInGroups, &QCheckBox::clicked, | ||
145 | this, &ViewPropertiesDialog::slotGroupedSortingChanged); | 192 | this, &ViewPropertiesDialog::slotGroupedSortingChanged); | ||
146 | connect(m_showHiddenFiles, &QCheckBox::clicked, | 193 | connect(m_showHiddenFiles, &QCheckBox::clicked, | ||
147 | this, &ViewPropertiesDialog::slotShowHiddenFilesChanged); | 194 | this, &ViewPropertiesDialog::slotShowHiddenFilesChanged); | ||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Line(s) | |||||
274 | 321 | | |||
275 | void ViewPropertiesDialog::slotShowHiddenFilesChanged() | 322 | void ViewPropertiesDialog::slotShowHiddenFilesChanged() | ||
276 | { | 323 | { | ||
277 | const bool show = m_showHiddenFiles->isChecked(); | 324 | const bool show = m_showHiddenFiles->isChecked(); | ||
278 | m_viewProps->setHiddenFilesShown(show); | 325 | m_viewProps->setHiddenFilesShown(show); | ||
279 | markAsDirty(true); | 326 | markAsDirty(true); | ||
280 | } | 327 | } | ||
281 | 328 | | |||
329 | void ViewPropertiesDialog::slotItemChanged(QListWidgetItem *item) | ||||
330 | { | ||||
331 | Q_UNUSED(item) | ||||
332 | markAsDirty(true); | ||||
333 | } | ||||
334 | | ||||
282 | void ViewPropertiesDialog::markAsDirty(bool isDirty) | 335 | void ViewPropertiesDialog::markAsDirty(bool isDirty) | ||
283 | { | 336 | { | ||
284 | if (m_isDirty != isDirty) { | 337 | if (m_isDirty != isDirty) { | ||
285 | m_isDirty = isDirty; | 338 | m_isDirty = isDirty; | ||
286 | emit isDirtyChanged(isDirty); | 339 | emit isDirtyChanged(isDirty); | ||
287 | } | 340 | } | ||
288 | } | 341 | } | ||
289 | 342 | | |||
290 | void ViewPropertiesDialog::configureAdditionalInfo() | 343 | void ViewPropertiesDialog::applyViewProperties() | ||
291 | { | 344 | { | ||
292 | QList<QByteArray> visibleRoles = m_viewProps->visibleRoles(); | 345 | // if nothing changed in the dialog, we have nothing to apply | ||
293 | const bool useDefaultRoles = (m_viewProps->viewMode() == DolphinView::DetailsView) && visibleRoles.isEmpty(); | 346 | if (!m_isDirty) { | ||
294 | if (useDefaultRoles) { | 347 | return; | ||
295 | // Using the details view without any additional information (-> additional column) | | |||
296 | // makes no sense and leads to a usability problem as no viewport area is available | | |||
297 | // anymore. Hence as fallback provide at least a size and date column. | | |||
298 | visibleRoles.clear(); | | |||
299 | visibleRoles.append("text"); | | |||
300 | visibleRoles.append("size"); | | |||
301 | visibleRoles.append("modificationtime"); | | |||
302 | m_viewProps->setVisibleRoles(visibleRoles); | | |||
303 | } | 348 | } | ||
304 | 349 | | |||
305 | QPointer<AdditionalInfoDialog> dialog = new AdditionalInfoDialog(this, visibleRoles); | 350 | // Update visible roles. | ||
306 | if (dialog->exec() == QDialog::Accepted) { | 351 | { | ||
307 | m_viewProps->setVisibleRoles(dialog->visibleRoles()); | 352 | QList<QByteArray> visibleRoles; | ||
308 | markAsDirty(true); | 353 | int index = 0; | ||
354 | const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation(); | ||||
355 | foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { | ||||
356 | const QListWidgetItem* item = m_listWidget->item(index); | ||||
357 | if (item->checkState() == Qt::Checked) { | ||||
358 | visibleRoles.append(info.role); | ||||
309 | } | 359 | } | ||
310 | delete dialog; | 360 | ++index; | ||
311 | } | 361 | } | ||
312 | 362 | | |||
313 | void ViewPropertiesDialog::applyViewProperties() | 363 | m_viewProps->setVisibleRoles(visibleRoles); | ||
314 | { | | |||
315 | // if nothing changed in the dialog, we have nothing to apply | | |||
316 | if (!m_isDirty) { | | |||
317 | return; | | |||
318 | } | 364 | } | ||
319 | 365 | | |||
320 | const bool applyToSubFolders = m_applyToSubFolders && m_applyToSubFolders->isChecked(); | 366 | const bool applyToSubFolders = m_applyToSubFolders && m_applyToSubFolders->isChecked(); | ||
321 | if (applyToSubFolders) { | 367 | if (applyToSubFolders) { | ||
322 | const QString text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?")); | 368 | const QString text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?")); | ||
323 | if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { | 369 | if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { | ||
324 | return; | 370 | return; | ||
325 | } | 371 | } | ||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |