]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/settings/viewpropertiesdialog.cpp
Compile with QT_NO_KEYWORDS
[dolphin.git] / src / settings / viewpropertiesdialog.cpp
index c317ed052edebbbf8afc73ed3943c7dae1d3c3de..c6dbc82b43f42d673e9eadc44dba4eedb1031521 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>
 
@@ -52,59 +39,46 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     QDialog(dolphinView),
     m_isDirty(false),
     m_dolphinView(dolphinView),
-    m_viewProps(0),
-    m_viewMode(0),
-    m_sortOrder(0),
-    m_sorting(0),
-    m_sortFoldersFirst(0),
-    m_previewsShown(0),
-    m_showInGroups(0),
-    m_showHiddenFiles(0),
-    m_additionalInfo(0),
-    m_applyToCurrentFolder(0),
-    m_applyToSubFolders(0),
-    m_applyToAllFolders(0),
-    m_useAsDefault(0)
+    m_viewProps(nullptr),
+    m_viewMode(nullptr),
+    m_sortOrder(nullptr),
+    m_sorting(nullptr),
+    m_sortFoldersFirst(nullptr),
+    m_previewsShown(nullptr),
+    m_showInGroups(nullptr),
+    m_showHiddenFiles(nullptr),
+    m_applyToCurrentFolder(nullptr),
+    m_applyToSubFolders(nullptr),
+    m_applyToAllFolders(nullptr),
+    m_useAsDefault(nullptr)
 {
     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);
+    auto layout = new QFormLayout(this);
+    // Otherwise the dialog won't resize when we collapse the KCollapsibleGroupBox.
+    layout->setSizeConstraint(QLayout::SetFixedSize);
     setLayout(layout);
 
-    auto propsGrid = new QWidget(this);
-    layout->addWidget(propsGrid);
-
     // 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);
     }
 
@@ -113,36 +87,75 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     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();
+
+    {
+        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);
+    }
+
+    additionalInfoBox->setLayout(innerLayout);
 
     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);
+
+    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_previewsShown, &QCheckBox::clicked,
@@ -156,29 +169,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 +202,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);
@@ -198,10 +212,11 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     layout->addWidget(buttonBox);
 
     auto okButton = buttonBox->button(QDialogButtonBox::Ok);
-    okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
+    okButton->setShortcut(Qt::CTRL + Qt::Key_Return);
     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);
@@ -217,7 +232,7 @@ ViewPropertiesDialog::~ViewPropertiesDialog()
 {
     m_isDirty = false;
     delete m_viewProps;
-    m_viewProps = 0;
+    m_viewProps = nullptr;
 
     KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "ViewPropertiesDialog");
     KWindowConfig::saveWindowSize(windowHandle(), dialogConfig);
@@ -284,35 +299,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 +320,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 +353,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) {