]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/settings/viewpropertiesdialog.cpp
SVN_SILENT made messages (.desktop file) - always resolve ours
[dolphin.git] / src / settings / viewpropertiesdialog.cpp
index 2f5d55523dc14b147f94cd28181fef5f22ab1e74..30995f1f72d5644a1f0ce291b621bb85d55045d7 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"
@@ -32,7 +18,9 @@
 #include <KMessageBox>
 #include <KWindowConfig>
 
-#ifdef HAVE_BALOO
+#include <kwidgetsaddons_version.h>
+
+#if HAVE_BALOO
     #include <Baloo/IndexerConfig>
 #endif
 
@@ -57,6 +45,7 @@ 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),
@@ -77,7 +66,6 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     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,7 +118,7 @@ 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) {
+        for (const KFileItemModel::RoleInfo& info : rolesInfo) {
             QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget);
             item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked);
 
@@ -146,8 +135,6 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
         innerLayout->addWidget(m_listWidget);
     }
 
-    additionalInfoBox->setLayout(innerLayout);
-
     QHBoxLayout* sortingLayout = new QHBoxLayout();
     sortingLayout->setContentsMargins(0, 0, 0, 0);
     sortingLayout->addWidget(m_sortOrder);
@@ -162,27 +149,18 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     layout->addRow(QString(), m_previewsShown);
     layout->addRow(QString(), m_showInGroups);
     layout->addRow(QString(), m_showHiddenFiles);
+    layout->addRow(QString(), m_sortHiddenLast);
 
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
-    connect(m_viewMode, QOverload<int>::of(&QComboBox::currentIndexChanged),
-#else
-    connect(m_viewMode, QOverload<int, const QString &>::of(&QComboBox::currentIndexChanged),
-#endif
+    connect(m_viewMode, &QComboBox::currentIndexChanged,
             this, &ViewPropertiesDialog::slotViewModeChanged);
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
-    connect(m_sorting, QOverload<int>::of(&QComboBox::currentIndexChanged),
-#else
-    connect(m_sorting, QOverload<int, const QString &>::of(&QComboBox::currentIndexChanged),
-#endif
+    connect(m_sorting, &QComboBox::currentIndexChanged,
             this, &ViewPropertiesDialog::slotSortingChanged);
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
-    connect(m_sortOrder, QOverload<int>::of(&QComboBox::currentIndexChanged),
-#else
-    connect(m_sortOrder, QOverload<int, const QString &>::of(&QComboBox::currentIndexChanged),
-#endif
+    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,
@@ -237,7 +215,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);
@@ -310,6 +288,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();
@@ -334,7 +319,7 @@ void ViewPropertiesDialog::markAsDirty(bool isDirty)
 {
     if (m_isDirty != isDirty) {
         m_isDirty = isDirty;
-        emit isDirtyChanged(isDirty);
+        Q_EMIT isDirtyChanged(isDirty);
     }
 }
 
@@ -350,7 +335,7 @@ void ViewPropertiesDialog::applyViewProperties()
         QList<QByteArray> visibleRoles;
         int index = 0;
         const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
-        foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+        for (const KFileItemModel::RoleInfo& info : rolesInfo) {
             const QListWidgetItem* item = m_listWidget->item(index);
              if (item->checkState() == Qt::Checked) {
                 visibleRoles.append(info.role);
@@ -364,7 +349,15 @@ 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 KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
+        if (KMessageBox::questionTwoActions(this, text, {},
+                                            KStandardGuiItem::cont(),
+                                            KStandardGuiItem::cancel()) == KMessageBox::SecondaryAction) {
+#else
+        if (KMessageBox::questionYesNo(this, text, {},
+                                       KStandardGuiItem::cont(),
+                                       KStandardGuiItem::cancel()) == KMessageBox::No) {
+#endif
             return;
         }
 
@@ -396,7 +389,15 @@ 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 KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
+        if (KMessageBox::questionTwoActions(this, text, {},
+                                            KStandardGuiItem::cont(),
+                                            KStandardGuiItem::cancel()) == KMessageBox::SecondaryAction) {
+#else
+        if (KMessageBox::questionYesNo(this, text, {},
+                                       KStandardGuiItem::cont(),
+                                       KStandardGuiItem::cancel()) == KMessageBox::No) {
+#endif
             return;
         }
 
@@ -407,10 +408,11 @@ void ViewPropertiesDialog::applyViewProperties()
         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());
@@ -446,6 +448,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());