]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/settings/viewpropertiesdialog.cpp
GIT_SILENT Update Appstream for new release
[dolphin.git] / src / settings / viewpropertiesdialog.cpp
index c3078d5df492511a2233de17dcc535774e068bd9..37c3d539b3bd305d6d980f76730a5f68ba6a4f22 100644 (file)
@@ -1,27 +1,13 @@
-/***************************************************************************
- *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
- *   Copyright (C) 2018 by Elvis Angelaccio <elvis.angelaccio@kde.org>     *
- *                                                                         *
- *   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 "dolphin_generalsettings.h"
-#include "dolphin_iconsmodesettings.h"
 #include "global.h"
 #include "kitemviews/kfileitemmodel.h"
 #include "viewpropsprogressinfo.h"
 #include <KMessageBox>
 #include <KWindowConfig>
 
-#ifdef HAVE_BALOO
-    #include <Baloo/IndexerConfig>
+#include <kwidgetsaddons_version.h>
+
+#if HAVE_BALOO
+#include <Baloo/IndexerConfig>
 #endif
 
 #include <QButtonGroup>
 
 #include <views/viewproperties.h>
 
-ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
-    QDialog(dolphinView),
-    m_isDirty(false),
-    m_dolphinView(dolphinView),
-    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)
+ViewPropertiesDialog::ViewPropertiesDialog(DolphinView *dolphinView)
+    : QDialog(dolphinView)
+    , m_isDirty(false)
+    , m_dolphinView(dolphinView)
+    , m_viewProps(nullptr)
+    , m_viewMode(nullptr)
+    , m_sortOrder(nullptr)
+    , m_sorting(nullptr)
+    , m_sortFoldersFirst(nullptr)
+    , m_sortHiddenLast(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 Display Style"));
 
-    const QUrlurl = dolphinView->url();
+    const QUrl &url = dolphinView->url();
     m_viewProps = new ViewProperties(url);
     m_viewProps->setAutoSaveEnabled(false);
 
     auto layout = new QFormLayout(this);
     // Otherwise the dialog won't resize when we collapse the KCollapsibleGroupBox.
     layout->setSizeConstraint(QLayout::SetFixedSize);
-    setLayout(layout);
 
     // create 'Properties' group containing view mode, sorting, sort order and show hidden files
     m_viewMode = new QComboBox();
@@ -91,18 +79,19 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
 
     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"));
 
     auto additionalInfoBox = new KCollapsibleGroupBox();
     additionalInfoBox->setTitle(i18nc("@title:group", "Additional Information"));
-    auto innerLayout = new QVBoxLayout();
+    auto innerLayout = new QVBoxLayout(additionalInfoBox);
 
     {
         QList<QByteArray> visibleRoles = m_viewProps->visibleRoles();
@@ -120,7 +109,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
 
         // Add checkboxes
         bool indexingEnabled = false;
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
         Baloo::IndexerConfig config;
         indexingEnabled = config.fileIndexingEnabled();
 #endif
@@ -129,26 +118,23 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
         connect(m_listWidget, &QListWidget::itemChanged, this, &ViewPropertiesDialog::slotItemChanged);
         m_listWidget->setSelectionMode(QAbstractItemView::NoSelection);
         const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
-        foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
-            QListWidgetItemitem = new QListWidgetItem(info.translation, m_listWidget);
+        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";
+            const bool enable =
+                ((!info.requiresBaloo && !info.requiresIndexer) || (info.requiresBaloo) || (info.requiresIndexer && indexingEnabled)) && info.role != "text";
 
             if (!enable) {
                 item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
             }
         }
-        QLabeladditionalViewOptionsLabel = new QLabel(i18n("Choose what to see on each file or folder:"));
+        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();
+    QHBoxLayout *sortingLayout = new QHBoxLayout();
     sortingLayout->setContentsMargins(0, 0, 0, 0);
     sortingLayout->addWidget(m_sortOrder);
     sortingLayout->addWidget(m_sorting);
@@ -162,35 +148,27 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     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, QOverload<int>::of(&QComboBox::currentIndexChanged),
-            this, &ViewPropertiesDialog::slotSortingChanged);
-    connect(m_sortOrder, QOverload<int>::of(&QComboBox::currentIndexChanged),
-            this, &ViewPropertiesDialog::slotSortOrderChanged);
-    connect(m_sortFoldersFirst, &QCheckBox::clicked,
-            this, &ViewPropertiesDialog::slotSortFoldersFirstChanged);
-    connect(m_previewsShown, &QCheckBox::clicked,
-            this, &ViewPropertiesDialog::slotShowPreviewChanged);
-    connect(m_showInGroups, &QCheckBox::clicked,
-            this, &ViewPropertiesDialog::slotGroupedSortingChanged);
-    connect(m_showHiddenFiles, &QCheckBox::clicked,
-            this, &ViewPropertiesDialog::slotShowHiddenFilesChanged);
+    connect(m_viewMode, &QComboBox::currentIndexChanged, this, &ViewPropertiesDialog::slotViewModeChanged);
+    connect(m_sorting, &QComboBox::currentIndexChanged, this, &ViewPropertiesDialog::slotSortingChanged);
+    connect(m_sortOrder, &QComboBox::currentIndexChanged, this, &ViewPropertiesDialog::slotSortOrderChanged);
+    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, this, &ViewPropertiesDialog::slotGroupedSortingChanged);
+    connect(m_showHiddenFiles, &QCheckBox::clicked, this, &ViewPropertiesDialog::slotShowHiddenFilesChanged);
 
     // Only show the following settings if the view properties are remembered
     // for each directory:
     if (!useGlobalViewProps) {
         // create 'Apply View Properties To' group
-        m_applyToCurrentFolder = new QRadioButton(i18nc("@option:radio Apply View Properties To",
-                                                        "Current folder"));
+        m_applyToCurrentFolder = new QRadioButton(i18nc("@option:radio Apply View Properties To", "Current folder"));
         m_applyToCurrentFolder->setChecked(true);
-        m_applyToSubFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To",
-                                                     "Current folder and sub-folders"));
-        m_applyToAllFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To",
-                                                     "All folders"));
+        m_applyToSubFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To", "Current folder and sub-folders"));
+        m_applyToAllFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To", "All folders"));
 
-        QButtonGroupapplyGroup = new QButtonGroup(this);
+        QButtonGroup *applyGroup = new QButtonGroup(this);
         applyGroup->addButton(m_applyToCurrentFolder);
         applyGroup->addButton(m_applyToSubFolders);
         applyGroup->addButton(m_applyToAllFolders);
@@ -205,14 +183,10 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
         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);
-        connect(m_applyToSubFolders, &QRadioButton::clicked,
-                this, &ViewPropertiesDialog::markAsDirty);
-        connect(m_applyToAllFolders, &QRadioButton::clicked,
-                this, &ViewPropertiesDialog::markAsDirty);
-        connect(m_useAsDefault, &QCheckBox::clicked,
-                this, &ViewPropertiesDialog::markAsDirty);
+        connect(m_applyToCurrentFolder, &QRadioButton::clicked, this, &ViewPropertiesDialog::markAsDirty);
+        connect(m_applyToSubFolders, &QRadioButton::clicked, this, &ViewPropertiesDialog::markAsDirty);
+        connect(m_applyToAllFolders, &QRadioButton::clicked, this, &ViewPropertiesDialog::markAsDirty);
+        connect(m_useAsDefault, &QCheckBox::clicked, this, &ViewPropertiesDialog::markAsDirty);
     }
 
     layout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
@@ -225,7 +199,7 @@ 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);
@@ -235,7 +209,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
         applyButton->setEnabled(isDirty);
     });
 
-    const KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "ViewPropertiesDialog");
+    const KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), QStringLiteral("ViewPropertiesDialog"));
     KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig);
 
     loadSettings();
@@ -247,7 +221,7 @@ ViewPropertiesDialog::~ViewPropertiesDialog()
     delete m_viewProps;
     m_viewProps = nullptr;
 
-    KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "ViewPropertiesDialog");
+    KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), QStringLiteral("ViewPropertiesDialog"));
     KWindowConfig::saveWindowSize(windowHandle(), dialogConfig);
 }
 
@@ -298,6 +272,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();
@@ -322,7 +303,7 @@ void ViewPropertiesDialog::markAsDirty(bool isDirty)
 {
     if (m_isDirty != isDirty) {
         m_isDirty = isDirty;
-        emit isDirtyChanged(isDirty);
+        Q_EMIT isDirtyChanged(isDirty);
     }
 }
 
@@ -338,9 +319,9 @@ void ViewPropertiesDialog::applyViewProperties()
         QList<QByteArray> visibleRoles;
         int index = 0;
         const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
-        foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
-            const QListWidgetItemitem = m_listWidget->item(index);
-             if (item->checkState() == Qt::Checked) {
+        for (const KFileItemModel::RoleInfo &info : rolesInfo) {
+            const QListWidgetItem *item = m_listWidget->item(index);
+            if (item->checkState() == Qt::Checked) {
                 visibleRoles.append(info.role);
             }
             ++index;
@@ -352,13 +333,11 @@ void ViewPropertiesDialog::applyViewProperties()
     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?"));
-        if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) {
+        if (KMessageBox::questionTwoActions(this, text, {}, KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::SecondaryAction) {
             return;
         }
 
-        ViewPropsProgressInfo* info = new ViewPropsProgressInfo(m_dolphinView,
-                                                                m_dolphinView->url(),
-                                                                *m_viewProps);
+        ViewPropsProgressInfo *info = new ViewPropsProgressInfo(m_dolphinView, m_dolphinView->url(), *m_viewProps);
         info->setAttribute(Qt::WA_DeleteOnClose);
         info->setWindowModality(Qt::NonModal);
         info->show();
@@ -384,21 +363,22 @@ void ViewPropertiesDialog::applyViewProperties()
 
     if (applyToAllFolders) {
         const QString text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?"));
-        if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) {
+        if (KMessageBox::questionTwoActions(this, text, {}, KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::SecondaryAction) {
             return;
         }
 
         // Updating the global view properties time stamp in the general settings makes
         // all existing viewproperties invalid, as they have a smaller time stamp.
-        GeneralSettingssettings = GeneralSettings::self();
+        GeneralSettings *settings = GeneralSettings::self();
         settings->setViewPropsTimestamp(QDateTime::currentDateTime());
         settings->save();
     }
 
-    m_dolphinView->setMode(m_viewProps->viewMode());
+    m_dolphinView->setViewMode(m_viewProps->viewMode());
     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());
@@ -413,10 +393,17 @@ void ViewPropertiesDialog::loadSettings()
 {
     // Load view mode
     switch (m_viewProps->viewMode()) {
-    case DolphinView::IconsView:   m_viewMode->setCurrentIndex(0); break;
-    case DolphinView::CompactView: m_viewMode->setCurrentIndex(1); break;
-    case DolphinView::DetailsView: m_viewMode->setCurrentIndex(2); break;
-    default: break;
+    case DolphinView::IconsView:
+        m_viewMode->setCurrentIndex(0);
+        break;
+    case DolphinView::CompactView:
+        m_viewMode->setCurrentIndex(1);
+        break;
+    case DolphinView::DetailsView:
+        m_viewMode->setCurrentIndex(2);
+        break;
+    default:
+        break;
     }
 
     // Load sort order and sorting
@@ -434,6 +421,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());
@@ -442,3 +430,4 @@ void ViewPropertiesDialog::loadSettings()
     markAsDirty(false);
 }
 
+#include "moc_viewpropertiesdialog.cpp"