]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/settings/viewpropertiesdialog.cpp
Configurable Show hidden files and folders last toggle
[dolphin.git] / src / settings / viewpropertiesdialog.cpp
index 980ab0bba465d73e92f09fcfce5726d81334a75b..6659d79b63f0b3c9f23cefd0cb4829ed7661e4df 100644 (file)
@@ -1,50 +1,37 @@
-/***************************************************************************
- *   Copyright (C) 2006 by Peter Penz                                      *
- *   peter.penz@gmx.at                                                     *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
+ * SPDX-FileCopyrightText: 2018 Elvis Angelaccio <elvis.angelaccio@kde.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "viewpropertiesdialog.h"
 
-#include "additionalinfodialog.h"
-#include "kitemviews/kfileitemmodel.h"
-#include "views/dolphinview.h"
 #include "dolphin_generalsettings.h"
 #include "dolphin_iconsmodesettings.h"
+#include "global.h"
+#include "kitemviews/kfileitemmodel.h"
 #include "viewpropsprogressinfo.h"
+#include "views/dolphinview.h"
 
-#include <config-baloo.h>
-
+#include <KCollapsibleGroupBox>
 #include <KLocalizedString>
 #include <KMessageBox>
-#include <QUrl>
-#include <KComboBox>
-#include <KConfigGroup>
 #include <KWindowConfig>
 
+#ifdef HAVE_BALOO
+    #include <Baloo/IndexerConfig>
+#endif
+
 #include <QButtonGroup>
 #include <QCheckBox>
-#include <QGridLayout>
-#include <QGroupBox>
+#include <QComboBox>
+#include <QFormLayout>
 #include <QLabel>
+#include <QListWidget>
 #include <QPushButton>
 #include <QRadioButton>
-#include <QDialogButtonBox>
-#include <QVBoxLayout>
+#include <QSpacerItem>
 
 #include <views/viewproperties.h>
 
@@ -57,10 +44,10 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     m_sortOrder(nullptr),
     m_sorting(nullptr),
     m_sortFoldersFirst(nullptr),
+    m_sortHiddenLast(nullptr),
     m_previewsShown(nullptr),
     m_showInGroups(nullptr),
     m_showHiddenFiles(nullptr),
-    m_additionalInfo(nullptr),
     m_applyToCurrentFolder(nullptr),
     m_applyToSubFolders(nullptr),
     m_applyToAllFolders(nullptr),
@@ -69,82 +56,110 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     Q_ASSERT(dolphinView);
     const bool useGlobalViewProps = GeneralSettings::globalViewProps();
 
-    setWindowTitle(i18nc("@title:window", "View Properties"));
-    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
+    setWindowTitle(i18nc("@title:window", "View Display Style"));
 
     const QUrl& url = dolphinView->url();
     m_viewProps = new ViewProperties(url);
     m_viewProps->setAutoSaveEnabled(false);
 
-    auto layout = new QVBoxLayout(this);
-    setLayout(layout);
-
-    auto propsGrid = new QWidget(this);
-    layout->addWidget(propsGrid);
+    auto layout = new QFormLayout(this);
+    // Otherwise the dialog won't resize when we collapse the KCollapsibleGroupBox.
+    layout->setSizeConstraint(QLayout::SetFixedSize);
 
     // create 'Properties' group containing view mode, sorting, sort order and show hidden files
-    QWidget* propsBox = this;
-    if (!useGlobalViewProps) {
-        propsBox = new QGroupBox(i18nc("@title:group", "Properties"), this);
-        layout->addWidget(propsBox);
-    }
-
-    QLabel* viewModeLabel = new QLabel(i18nc("@label:listbox", "View mode:"), propsGrid);
-    m_viewMode = new KComboBox(propsGrid);
+    m_viewMode = new QComboBox();
     m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-icons")), i18nc("@item:inlistbox", "Icons"), DolphinView::IconsView);
     m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-details")), i18nc("@item:inlistbox", "Compact"), DolphinView::CompactView);
     m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-tree")), i18nc("@item:inlistbox", "Details"), DolphinView::DetailsView);
 
-    QLabel* sortingLabel = new QLabel(i18nc("@label:listbox", "Sorting:"), propsGrid);
-    QWidget* sortingBox = new QWidget(propsGrid);
-
-    m_sortOrder = new KComboBox(sortingBox);
+    m_sortOrder = new QComboBox();
     m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Ascending"));
     m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Descending"));
 
-    m_sorting = new KComboBox(sortingBox);
+    m_sorting = new QComboBox();
     const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
-    foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+    for (const KFileItemModel::RoleInfo& info : rolesInfo) {
         m_sorting->addItem(info.translation, info.role);
     }
 
     m_sortFoldersFirst = new QCheckBox(i18nc("@option:check", "Show folders first"));
+    m_sortHiddenLast = new QCheckBox(i18nc("@option:check", "Show hidden files last"));
     m_previewsShown = new QCheckBox(i18nc("@option:check", "Show preview"));
     m_showInGroups = new QCheckBox(i18nc("@option:check", "Show in groups"));
     m_showHiddenFiles = new QCheckBox(i18nc("@option:check", "Show hidden files"));
 
-    m_additionalInfo = new QPushButton(i18nc("@action:button", "Additional Information"));
+    auto additionalInfoBox = new KCollapsibleGroupBox();
+    additionalInfoBox->setTitle(i18nc("@title:group", "Additional Information"));
+    auto innerLayout = new QVBoxLayout(additionalInfoBox);
+
+    {
+        QList<QByteArray> visibleRoles = m_viewProps->visibleRoles();
+        const bool useDefaultRoles = (m_viewProps->viewMode() == DolphinView::DetailsView) && visibleRoles.isEmpty();
+        if (useDefaultRoles) {
+            // Using the details view without any additional information (-> additional column)
+            // makes no sense and leads to a usability problem as no viewport area is available
+            // anymore. Hence as fallback provide at least a size and date column.
+            visibleRoles.clear();
+            visibleRoles.append("text");
+            visibleRoles.append("size");
+            visibleRoles.append("modificationtime");
+            m_viewProps->setVisibleRoles(visibleRoles);
+        }
+
+        // Add checkboxes
+        bool indexingEnabled = false;
+#ifdef HAVE_BALOO
+        Baloo::IndexerConfig config;
+        indexingEnabled = config.fileIndexingEnabled();
+#endif
+
+        m_listWidget = new QListWidget();
+        connect(m_listWidget, &QListWidget::itemChanged, this, &ViewPropertiesDialog::slotItemChanged);
+        m_listWidget->setSelectionMode(QAbstractItemView::NoSelection);
+        const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+        for (const KFileItemModel::RoleInfo& info : rolesInfo) {
+            QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget);
+            item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked);
+
+            const bool enable = ((!info.requiresBaloo && !info.requiresIndexer) ||
+                                (info.requiresBaloo) ||
+                                (info.requiresIndexer && indexingEnabled)) && info.role != "text";
+
+            if (!enable) {
+                item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
+            }
+        }
+        QLabel* additionalViewOptionsLabel = new QLabel(i18n("Choose what to see on each file or folder:"));
+        innerLayout->addWidget(additionalViewOptionsLabel);
+        innerLayout->addWidget(m_listWidget);
+    }
 
     QHBoxLayout* sortingLayout = new QHBoxLayout();
-    sortingLayout->setMargin(0);
+    sortingLayout->setContentsMargins(0, 0, 0, 0);
     sortingLayout->addWidget(m_sortOrder);
     sortingLayout->addWidget(m_sorting);
-    sortingBox->setLayout(sortingLayout);
-
-    QGridLayout* propsGridLayout = new QGridLayout(propsGrid);
-    propsGridLayout->addWidget(viewModeLabel, 0, 0, Qt::AlignRight);
-    propsGridLayout->addWidget(m_viewMode, 0, 1);
-    propsGridLayout->addWidget(sortingLabel, 1, 0, Qt::AlignRight);
-    propsGridLayout->addWidget(sortingBox, 1, 1);
-
-    QVBoxLayout* propsBoxLayout = propsBox == this ? layout : new QVBoxLayout(propsBox);
-    propsBoxLayout->addWidget(propsGrid);
-    propsBoxLayout->addWidget(m_sortFoldersFirst);
-    propsBoxLayout->addWidget(m_previewsShown);
-    propsBoxLayout->addWidget(m_showInGroups);
-    propsBoxLayout->addWidget(m_showHiddenFiles);
-    propsBoxLayout->addWidget(m_additionalInfo);
-
-    connect(m_viewMode, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged),
+
+    layout->addRow(i18nc("@label:listbox", "View mode:"), m_viewMode);
+    layout->addRow(i18nc("@label:listbox", "Sorting:"), sortingLayout);
+
+    layout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
+
+    layout->addRow(i18n("View options:"), m_sortFoldersFirst);
+    layout->addRow(QString(), m_previewsShown);
+    layout->addRow(QString(), m_showInGroups);
+    layout->addRow(QString(), m_showHiddenFiles);
+    layout->addRow(QString(), m_sortHiddenLast);
+
+    connect(m_viewMode, QOverload<int>::of(&QComboBox::currentIndexChanged),
             this, &ViewPropertiesDialog::slotViewModeChanged);
-    connect(m_sorting, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged),
+    connect(m_sorting, QOverload<int>::of(&QComboBox::currentIndexChanged),
             this, &ViewPropertiesDialog::slotSortingChanged);
-    connect(m_sortOrder, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged),
+    connect(m_sortOrder, QOverload<int>::of(&QComboBox::currentIndexChanged),
             this, &ViewPropertiesDialog::slotSortOrderChanged);
-    connect(m_additionalInfo, &QPushButton::clicked,
-            this, &ViewPropertiesDialog::configureAdditionalInfo);
     connect(m_sortFoldersFirst, &QCheckBox::clicked,
             this, &ViewPropertiesDialog::slotSortFoldersFirstChanged);
+    connect(m_sortHiddenLast, &QCheckBox::clicked,
+            this, &ViewPropertiesDialog::slotSortHiddenLastChanged);
     connect(m_previewsShown, &QCheckBox::clicked,
             this, &ViewPropertiesDialog::slotShowPreviewChanged);
     connect(m_showInGroups, &QCheckBox::clicked,
@@ -156,29 +171,28 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     // for each directory:
     if (!useGlobalViewProps) {
         // create 'Apply View Properties To' group
-        QGroupBox* applyBox = new QGroupBox(i18nc("@title:group", "Apply View Properties To"), this);
-        layout->addWidget(applyBox);
-
         m_applyToCurrentFolder = new QRadioButton(i18nc("@option:radio Apply View Properties To",
-                                                        "Current folder"), applyBox);
+                                                        "Current folder"));
         m_applyToCurrentFolder->setChecked(true);
         m_applyToSubFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To",
-                                                     "Current folder including all sub-folders"), applyBox);
+                                                     "Current folder and sub-folders"));
         m_applyToAllFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To",
-                                                     "All folders"), applyBox);
+                                                     "All folders"));
 
         QButtonGroup* applyGroup = new QButtonGroup(this);
         applyGroup->addButton(m_applyToCurrentFolder);
         applyGroup->addButton(m_applyToSubFolders);
         applyGroup->addButton(m_applyToAllFolders);
 
-        QVBoxLayout* applyBoxLayout = new QVBoxLayout(applyBox);
-        applyBoxLayout->addWidget(m_applyToCurrentFolder);
-        applyBoxLayout->addWidget(m_applyToSubFolders);
-        applyBoxLayout->addWidget(m_applyToAllFolders);
+        layout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
+
+        layout->addRow(i18nc("@title:group", "Apply to:"), m_applyToCurrentFolder);
+        layout->addRow(QString(), m_applyToSubFolders);
+        layout->addRow(QString(), m_applyToAllFolders);
+        layout->addRow(QString(), m_applyToAllFolders);
 
-        m_useAsDefault = new QCheckBox(i18nc("@option:check", "Use these view properties as default"), this);
-        layout->addWidget(m_useAsDefault);
+        m_useAsDefault = new QCheckBox(i18nc("@option:check", "Use as default view settings"), this);
+        layout->addRow(QString(), m_useAsDefault);
 
         connect(m_applyToCurrentFolder, &QRadioButton::clicked,
                 this, &ViewPropertiesDialog::markAsDirty);
@@ -190,7 +204,9 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
                 this, &ViewPropertiesDialog::markAsDirty);
     }
 
-    layout->addStretch();
+    layout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
+
+    layout->addRow(additionalInfoBox);
 
     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply, this);
     connect(buttonBox, &QDialogButtonBox::accepted, this, &ViewPropertiesDialog::accept);
@@ -202,6 +218,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     okButton->setDefault(true);
 
     auto applyButton = buttonBox->button(QDialogButtonBox::Apply);
+    applyButton->setEnabled(false);
     connect(applyButton, &QPushButton::clicked, this, &ViewPropertiesDialog::slotApply);
     connect(this, &ViewPropertiesDialog::isDirtyChanged, applyButton, [applyButton](bool isDirty) {
         applyButton->setEnabled(isDirty);
@@ -270,6 +287,13 @@ void ViewPropertiesDialog::slotSortFoldersFirstChanged()
     markAsDirty(true);
 }
 
+void ViewPropertiesDialog::slotSortHiddenLastChanged()
+{
+    const bool hiddenLast = m_sortHiddenLast->isChecked();
+    m_viewProps->setSortHiddenLast(hiddenLast);
+    markAsDirty(true);
+}
+
 void ViewPropertiesDialog::slotShowPreviewChanged()
 {
     const bool show = m_previewsShown->isChecked();
@@ -284,35 +308,18 @@ void ViewPropertiesDialog::slotShowHiddenFilesChanged()
     markAsDirty(true);
 }
 
-void ViewPropertiesDialog::markAsDirty(bool isDirty)
+void ViewPropertiesDialog::slotItemChanged(QListWidgetItem *item)
 {
-    if (m_isDirty != isDirty) {
-        m_isDirty = isDirty;
-        emit isDirtyChanged(isDirty);
-    }
+    Q_UNUSED(item)
+    markAsDirty(true);
 }
 
-void ViewPropertiesDialog::configureAdditionalInfo()
+void ViewPropertiesDialog::markAsDirty(bool isDirty)
 {
-    QList<QByteArray> visibleRoles = m_viewProps->visibleRoles();
-    const bool useDefaultRoles = (m_viewProps->viewMode() == DolphinView::DetailsView) && visibleRoles.isEmpty();
-    if (useDefaultRoles) {
-        // Using the details view without any additional information (-> additional column)
-        // makes no sense and leads to a usability problem as no viewport area is available
-        // anymore. Hence as fallback provide at least a size and date column.
-        visibleRoles.clear();
-        visibleRoles.append("text");
-        visibleRoles.append("size");
-        visibleRoles.append("modificationtime");
-        m_viewProps->setVisibleRoles(visibleRoles);
-    }
-
-    QPointer<AdditionalInfoDialog> dialog = new AdditionalInfoDialog(this, visibleRoles);
-    if (dialog->exec() == QDialog::Accepted) {
-        m_viewProps->setVisibleRoles(dialog->visibleRoles());
-        markAsDirty(true);
+    if (m_isDirty != isDirty) {
+        m_isDirty = isDirty;
+        Q_EMIT isDirtyChanged(isDirty);
     }
-    delete dialog;
 }
 
 void ViewPropertiesDialog::applyViewProperties()
@@ -322,6 +329,22 @@ void ViewPropertiesDialog::applyViewProperties()
         return;
     }
 
+    // Update visible roles.
+    {
+        QList<QByteArray> visibleRoles;
+        int index = 0;
+        const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+        for (const KFileItemModel::RoleInfo& info : rolesInfo) {
+            const QListWidgetItem* item = m_listWidget->item(index);
+             if (item->checkState() == Qt::Checked) {
+                visibleRoles.append(info.role);
+            }
+            ++index;
+        }
+
+        m_viewProps->setVisibleRoles(visibleRoles);
+    }
+
     const bool applyToSubFolders = m_applyToSubFolders && m_applyToSubFolders->isChecked();
     if (applyToSubFolders) {
         const QString text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?"));
@@ -339,7 +362,7 @@ void ViewPropertiesDialog::applyViewProperties()
 
     const bool applyToAllFolders = m_applyToAllFolders && m_applyToAllFolders->isChecked();
 
-    // If the user selected 'Apply To All Folders' the view properties implicitely
+    // If the user selected 'Apply To All Folders' the view properties implicitly
     // are also used as default for new folders.
     const bool useAsDefault = applyToAllFolders || (m_useAsDefault && m_useAsDefault->isChecked());
     if (useAsDefault) {
@@ -372,6 +395,7 @@ void ViewPropertiesDialog::applyViewProperties()
     m_dolphinView->setSortRole(m_viewProps->sortRole());
     m_dolphinView->setSortOrder(m_viewProps->sortOrder());
     m_dolphinView->setSortFoldersFirst(m_viewProps->sortFoldersFirst());
+    m_dolphinView->setSortHiddenLast(m_viewProps->sortHiddenLast());
     m_dolphinView->setGroupedSorting(m_viewProps->groupedSorting());
     m_dolphinView->setVisibleRoles(m_viewProps->visibleRoles());
     m_dolphinView->setPreviewsShown(m_viewProps->previewsShown());
@@ -407,6 +431,7 @@ void ViewPropertiesDialog::loadSettings()
     m_sorting->setCurrentIndex(sortRoleIndex);
 
     m_sortFoldersFirst->setChecked(m_viewProps->sortFoldersFirst());
+    m_sortHiddenLast->setChecked(m_viewProps->sortHiddenLast());
 
     // Load show preview, show in groups and show hidden files settings
     m_previewsShown->setChecked(m_viewProps->previewsShown());