diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,7 +88,6 @@ kitemviews/private/kitemlistviewanimation.cpp kitemviews/private/kitemlistviewlayouter.cpp kitemviews/private/kpixmapmodifier.cpp - settings/additionalinfodialog.cpp settings/applyviewpropsjob.cpp settings/viewmodes/viewmodesettings.cpp settings/viewpropertiesdialog.cpp diff --git a/src/settings/additionalinfodialog.h b/src/settings/additionalinfodialog.h deleted file mode 100644 --- a/src/settings/additionalinfodialog.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2012 by Peter Penz * - * * - * 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 * - ***************************************************************************/ - -#ifndef ADDITIONALINFODIALOG_H -#define ADDITIONALINFODIALOG_H - -#include -#include -#include - -/** - * @brief Dialog for changing the additional information shown in the view. - */ -class AdditionalInfoDialog : public QDialog -{ - Q_OBJECT - -public: - AdditionalInfoDialog(QWidget* parent, const QList& visibleRoles); - ~AdditionalInfoDialog() override; - QList visibleRoles() const; - -public slots: - void accept() override; - -private: - QList m_visibleRoles; - QListWidget* m_listWidget; -}; - -#endif diff --git a/src/settings/additionalinfodialog.cpp b/src/settings/additionalinfodialog.cpp deleted file mode 100644 --- a/src/settings/additionalinfodialog.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2012 by Peter Penz * - * * - * 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 * - ***************************************************************************/ - -#include "additionalinfodialog.h" - -#include "kitemviews/kfileitemmodel.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#ifdef HAVE_BALOO - #include -#endif - -AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent, - const QList& visibleRoles) : - QDialog(parent), - m_visibleRoles(visibleRoles), - m_listWidget(nullptr) -{ - setWindowTitle(i18nc("@title:window", "Additional Information")); - setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); - - auto layout = new QVBoxLayout(this); - setLayout(layout); - - // Add header - auto header = new QLabel(this); - header->setText(i18nc("@label", "Select which additional information should be shown:")); - header->setWordWrap(true); - layout->addWidget(header); - - // Add checkboxes - bool indexingEnabled = false; -#ifdef HAVE_BALOO - Baloo::IndexerConfig config; - indexingEnabled = config.fileIndexingEnabled(); -#endif - - m_listWidget = new QListWidget(this); - m_listWidget->setSelectionMode(QAbstractItemView::NoSelection); - const QList rolesInfo = KFileItemModel::rolesInformation(); - foreach (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); - } - } - layout->addWidget(m_listWidget); - - auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); - connect(buttonBox, &QDialogButtonBox::accepted, this, &AdditionalInfoDialog::accept); - connect(buttonBox, &QDialogButtonBox::rejected, this, &AdditionalInfoDialog::reject); - layout->addWidget(buttonBox); - - auto okButton = buttonBox->button(QDialogButtonBox::Ok); - okButton->setShortcut(Qt::CTRL + Qt::Key_Return); - okButton->setDefault(true); - - const KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "AdditionalInfoDialog"); - KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig); -} - -AdditionalInfoDialog::~AdditionalInfoDialog() -{ - KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "AdditionalInfoDialog"); - KWindowConfig::saveWindowSize(windowHandle(), dialogConfig); -} - -QList AdditionalInfoDialog::visibleRoles() const -{ - return m_visibleRoles; -} - -void AdditionalInfoDialog::accept() -{ - m_visibleRoles.clear(); - - int index = 0; - const QList rolesInfo = KFileItemModel::rolesInformation(); - foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { - const QListWidgetItem* item = m_listWidget->item(index); - if (item->checkState() == Qt::Checked) { - m_visibleRoles.append(info.role); - } - ++index; - } - - QDialog::accept(); -} diff --git a/src/settings/viewpropertiesdialog.h b/src/settings/viewpropertiesdialog.h --- a/src/settings/viewpropertiesdialog.h +++ b/src/settings/viewpropertiesdialog.h @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * + * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2018 by Elvis Angelaccio * * * * 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 * @@ -26,6 +26,8 @@ #include class QCheckBox; +class QListWidget; +class QListWidgetItem; class KComboBox; class QPushButton; class QRadioButton; @@ -59,8 +61,8 @@ void slotSortFoldersFirstChanged(); void slotShowPreviewChanged(); void slotShowHiddenFilesChanged(); + void slotItemChanged(QListWidgetItem *item); void markAsDirty(bool isDirty); - void configureAdditionalInfo(); signals: void isDirtyChanged(bool isDirty); @@ -81,11 +83,11 @@ QCheckBox* m_previewsShown; QCheckBox* m_showInGroups; QCheckBox* m_showHiddenFiles; - QPushButton* m_additionalInfo; QRadioButton* m_applyToCurrentFolder; QRadioButton* m_applyToSubFolders; QRadioButton* m_applyToAllFolders; QCheckBox* m_useAsDefault; + QListWidget* m_listWidget; }; #endif diff --git a/src/settings/viewpropertiesdialog.cpp b/src/settings/viewpropertiesdialog.cpp --- a/src/settings/viewpropertiesdialog.cpp +++ b/src/settings/viewpropertiesdialog.cpp @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * + * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2018 by Elvis Angelaccio * * * * 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 * @@ -20,23 +20,28 @@ #include "viewpropertiesdialog.h" -#include "additionalinfodialog.h" #include "dolphin_generalsettings.h" #include "dolphin_iconsmodesettings.h" #include "kitemviews/kfileitemmodel.h" #include "viewpropsprogressinfo.h" #include "views/dolphinview.h" +#include #include #include #include #include +#ifdef HAVE_BALOO + #include +#endif + #include #include #include #include #include +#include #include #include @@ -54,7 +59,6 @@ m_previewsShown(nullptr), m_showInGroups(nullptr), m_showHiddenFiles(nullptr), - m_additionalInfo(nullptr), m_applyToCurrentFolder(nullptr), m_applyToSubFolders(nullptr), m_applyToAllFolders(nullptr), @@ -64,13 +68,14 @@ const bool useGlobalViewProps = GeneralSettings::globalViewProps(); setWindowTitle(i18nc("@title:window", "View Properties")); - setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); const QUrl& url = dolphinView->url(); m_viewProps = new ViewProperties(url); m_viewProps->setAutoSaveEnabled(false); auto layout = new QVBoxLayout(this); + // Otherwise the dialog won't resize when we collapse the KCollapsibleGroupBox. + layout->setSizeConstraint(QLayout::SetFixedSize); setLayout(layout); auto propsGrid = new QWidget(this); @@ -107,7 +112,51 @@ 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 Shown")); + auto innerLayout = new QVBoxLayout(); + + { + QList 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 rolesInfo = KFileItemModel::rolesInformation(); + foreach (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); + } + } + innerLayout->addWidget(m_listWidget); + } + + additionalInfoBox->setLayout(innerLayout); QHBoxLayout* sortingLayout = new QHBoxLayout(); sortingLayout->setMargin(0); @@ -127,16 +176,14 @@ propsBoxLayout->addWidget(m_previewsShown); propsBoxLayout->addWidget(m_showInGroups); propsBoxLayout->addWidget(m_showHiddenFiles); - propsBoxLayout->addWidget(m_additionalInfo); + propsBoxLayout->addWidget(additionalInfoBox); connect(m_viewMode, static_cast(&KComboBox::currentIndexChanged), this, &ViewPropertiesDialog::slotViewModeChanged); connect(m_sorting, static_cast(&KComboBox::currentIndexChanged), this, &ViewPropertiesDialog::slotSortingChanged); connect(m_sortOrder, static_cast(&KComboBox::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, @@ -279,44 +326,43 @@ markAsDirty(true); } +void ViewPropertiesDialog::slotItemChanged(QListWidgetItem *item) +{ + Q_UNUSED(item) + markAsDirty(true); +} + void ViewPropertiesDialog::markAsDirty(bool isDirty) { if (m_isDirty != isDirty) { m_isDirty = isDirty; emit isDirtyChanged(isDirty); } } -void ViewPropertiesDialog::configureAdditionalInfo() -{ - QList 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 dialog = new AdditionalInfoDialog(this, visibleRoles); - if (dialog->exec() == QDialog::Accepted) { - m_viewProps->setVisibleRoles(dialog->visibleRoles()); - markAsDirty(true); - } - delete dialog; -} - void ViewPropertiesDialog::applyViewProperties() { // if nothing changed in the dialog, we have nothing to apply if (!m_isDirty) { return; } + // Update visible roles. + { + QList visibleRoles; + int index = 0; + const QList rolesInfo = KFileItemModel::rolesInformation(); + foreach (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?"));