diff --git a/src/settings/general/confirmationssettingspage.cpp b/src/settings/general/confirmationssettingspage.cpp index 58d49062f..dd4d60f3b 100644 --- a/src/settings/general/confirmationssettingspage.cpp +++ b/src/settings/general/confirmationssettingspage.cpp @@ -1,199 +1,195 @@ /*************************************************************************** * Copyright (C) 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 "confirmationssettingspage.h" #include "dolphin_generalsettings.h" #include "global.h" #include #include #include #include #include #include namespace { enum ScriptExecution { AlwaysAsk = 0, Open = 1, Execute = 2 }; const bool ConfirmEmptyTrash = true; const bool ConfirmTrash = false; const bool ConfirmDelete = true; const int ConfirmScriptExecution = ScriptExecution::AlwaysAsk; } ConfirmationsSettingsPage::ConfirmationsSettingsPage(QWidget* parent) : SettingsPageBase(parent), m_confirmMoveToTrash(nullptr), m_confirmEmptyTrash(nullptr), m_confirmDelete(nullptr), #ifdef HAVE_TERMINAL m_confirmClosingTerminalRunningProgram(nullptr), #endif m_confirmClosingMultipleTabs(nullptr) { QVBoxLayout* topLayout = new QVBoxLayout(this); QLabel* confirmLabelKde = new QLabel(i18nc("@title:group", "Ask for confirmation in all KDE applications when:"), this); confirmLabelKde->setWordWrap(true); m_confirmMoveToTrash = new QCheckBox(i18nc("@option:check Ask for confirmation when", "Moving files or folders to trash"), this); m_confirmEmptyTrash = new QCheckBox(i18nc("@option:check Ask for confirmation when", "Emptying trash"), this); m_confirmDelete = new QCheckBox(i18nc("@option:check Ask for confirmation when", "Deleting files or folders"), this); QLabel* confirmLabelDolphin = new QLabel(i18nc("@title:group", "Ask for confirmation in Dolphin when:"), this); confirmLabelDolphin->setWordWrap(true); m_confirmClosingMultipleTabs = new QCheckBox(i18nc("@option:check Ask for confirmation in Dolphin when", "Closing windows with multiple tabs"), this); #ifdef HAVE_TERMINAL m_confirmClosingTerminalRunningProgram = new QCheckBox(i18nc("@option:check Ask for confirmation when", "Closing windows with a program running in the Terminal panel"), this); #endif QHBoxLayout* executableScriptLayout = new QHBoxLayout(); QLabel* executableScriptLabel = new QLabel(i18nc("@title:group", "When opening an executable file:"), this); confirmLabelKde->setWordWrap(true); executableScriptLayout->addWidget(executableScriptLabel); m_confirmScriptExecution = new QComboBox(this); m_confirmScriptExecution->addItems({i18n("Always ask"), i18n("Open in application"), i18n("Run script")}); executableScriptLayout->addWidget(m_confirmScriptExecution); topLayout->addWidget(confirmLabelKde); topLayout->addWidget(m_confirmMoveToTrash); topLayout->addWidget(m_confirmEmptyTrash); topLayout->addWidget(m_confirmDelete); topLayout->addSpacing(Dolphin::VERTICAL_SPACER_HEIGHT); topLayout->addWidget(confirmLabelDolphin); topLayout->addWidget(m_confirmClosingMultipleTabs); #ifdef HAVE_TERMINAL topLayout->addWidget(m_confirmClosingTerminalRunningProgram); #endif topLayout->addSpacing(Dolphin::VERTICAL_SPACER_HEIGHT); topLayout->addLayout(executableScriptLayout); topLayout->addStretch(); loadSettings(); connect(m_confirmMoveToTrash, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed); connect(m_confirmEmptyTrash, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed); connect(m_confirmDelete, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(m_confirmScriptExecution, QOverload::of(&QComboBox::currentIndexChanged), this, &ConfirmationsSettingsPage::changed); -#else - connect(m_confirmScriptExecution, QOverload::of(&QComboBox::currentIndexChanged), this, &ConfirmationsSettingsPage::changed); -#endif connect(m_confirmClosingMultipleTabs, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed); #ifdef HAVE_TERMINAL connect(m_confirmClosingTerminalRunningProgram, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed); #endif } ConfirmationsSettingsPage::~ConfirmationsSettingsPage() { } void ConfirmationsSettingsPage::applySettings() { KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig(QStringLiteral("kiorc"), KConfig::NoGlobals); KConfigGroup confirmationGroup(kioConfig, "Confirmations"); confirmationGroup.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked()); confirmationGroup.writeEntry("ConfirmEmptyTrash", m_confirmEmptyTrash->isChecked()); confirmationGroup.writeEntry("ConfirmDelete", m_confirmDelete->isChecked()); KConfigGroup scriptExecutionGroup(kioConfig, "Executable scripts"); const int index = m_confirmScriptExecution->currentIndex(); switch (index) { case ScriptExecution::AlwaysAsk: scriptExecutionGroup.writeEntry("behaviourOnLaunch", "alwaysAsk"); break; case ScriptExecution::Open: scriptExecutionGroup.writeEntry("behaviourOnLaunch", "dontAsk"); break; case ScriptExecution::Execute: scriptExecutionGroup.writeEntry("behaviourOnLaunch", "execute"); break; } kioConfig->sync(); GeneralSettings* settings = GeneralSettings::self(); settings->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs->isChecked()); #ifdef HAVE_TERMINAL settings->setConfirmClosingTerminalRunningProgram(m_confirmClosingTerminalRunningProgram->isChecked()); #endif settings->save(); } void ConfirmationsSettingsPage::restoreDefaults() { GeneralSettings* settings = GeneralSettings::self(); settings->useDefaults(true); loadSettings(); settings->useDefaults(false); m_confirmMoveToTrash->setChecked(ConfirmTrash); m_confirmEmptyTrash->setChecked(ConfirmEmptyTrash); m_confirmDelete->setChecked(ConfirmDelete); m_confirmScriptExecution->setCurrentIndex(ConfirmScriptExecution); } void ConfirmationsSettingsPage::loadSettings() { KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig(QStringLiteral("kiorc"), KConfig::IncludeGlobals); const KConfigGroup confirmationGroup(kioConfig, "Confirmations"); m_confirmMoveToTrash->setChecked(confirmationGroup.readEntry("ConfirmTrash", ConfirmTrash)); m_confirmEmptyTrash->setChecked(confirmationGroup.readEntry("ConfirmEmptyTrash", ConfirmEmptyTrash)); m_confirmDelete->setChecked(confirmationGroup.readEntry("ConfirmDelete", ConfirmDelete)); const KConfigGroup scriptExecutionGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), "Executable scripts"); const QString value = scriptExecutionGroup.readEntry("behaviourOnLaunch", "alwaysAsk"); if (value == QLatin1String("dontAsk")) { m_confirmScriptExecution->setCurrentIndex(ScriptExecution::Open); } else if (value == QLatin1String("execute")) { m_confirmScriptExecution->setCurrentIndex(ScriptExecution::Execute); } else /* if (value == QLatin1String("alwaysAsk"))*/ { m_confirmScriptExecution->setCurrentIndex(ScriptExecution::AlwaysAsk); } m_confirmClosingMultipleTabs->setChecked(GeneralSettings::confirmClosingMultipleTabs()); #ifdef HAVE_TERMINAL m_confirmClosingTerminalRunningProgram->setChecked(GeneralSettings::confirmClosingTerminalRunningProgram()); #endif } diff --git a/src/settings/viewmodes/viewsettingstab.cpp b/src/settings/viewmodes/viewsettingstab.cpp index 2175f75c8..06b0b8cf5 100644 --- a/src/settings/viewmodes/viewsettingstab.cpp +++ b/src/settings/viewmodes/viewsettingstab.cpp @@ -1,279 +1,267 @@ /*************************************************************************** * Copyright (C) 2008-2011 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 "viewsettingstab.h" #include "dolphin_compactmodesettings.h" #include "dolphin_detailsmodesettings.h" #include "dolphin_iconsmodesettings.h" #include "dolphinfontrequester.h" #include "global.h" #include "views/zoomlevelinfo.h" #include #include #include #include #include #include ViewSettingsTab::ViewSettingsTab(Mode mode, QWidget* parent) : QWidget(parent), m_mode(mode), m_defaultSizeSlider(nullptr), m_previewSizeSlider(nullptr), m_fontRequester(nullptr), m_widthBox(nullptr), m_maxLinesBox(nullptr), m_expandableFolders(nullptr) { QFormLayout* topLayout = new QFormLayout(this); // Create "Icon Size" section const int minRange = ZoomLevelInfo::minimumLevel(); const int maxRange = ZoomLevelInfo::maximumLevel(); m_defaultSizeSlider = new QSlider(Qt::Horizontal); m_defaultSizeSlider->setPageStep(1); m_defaultSizeSlider->setTickPosition(QSlider::TicksBelow); m_defaultSizeSlider->setRange(minRange, maxRange); connect(m_defaultSizeSlider, &QSlider::valueChanged, this, &ViewSettingsTab::slotDefaultSliderMoved); topLayout->addRow(i18nc("@label:listbox", "Default icon size:"), m_defaultSizeSlider); m_previewSizeSlider = new QSlider(Qt::Horizontal); m_previewSizeSlider->setPageStep(1); m_previewSizeSlider->setTickPosition(QSlider::TicksBelow); m_previewSizeSlider->setRange(minRange, maxRange); connect(m_previewSizeSlider, &QSlider::valueChanged, this, &ViewSettingsTab::slotPreviewSliderMoved); topLayout->addRow(i18nc("@label:listbox", "Preview icon size:"), m_previewSizeSlider); topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed)); // Create "Label" section m_fontRequester = new DolphinFontRequester(this); topLayout->addRow(i18nc("@label:listbox", "Label font:"), m_fontRequester); switch (m_mode) { case IconsMode: { m_widthBox = new QComboBox(); m_widthBox->addItem(i18nc("@item:inlistbox Label width", "Small")); m_widthBox->addItem(i18nc("@item:inlistbox Label width", "Medium")); m_widthBox->addItem(i18nc("@item:inlistbox Label width", "Large")); m_widthBox->addItem(i18nc("@item:inlistbox Label width", "Huge")); topLayout->addRow(i18nc("@label:listbox", "Label width:"), m_widthBox); m_maxLinesBox = new QComboBox(); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "Unlimited")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "1")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "2")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "3")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "4")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "5")); topLayout->addRow(i18nc("@label:listbox", "Maximum lines:"), m_maxLinesBox); break; } case CompactMode: { m_widthBox = new QComboBox(); m_widthBox->addItem(i18nc("@item:inlistbox Maximum width", "Unlimited")); m_widthBox->addItem(i18nc("@item:inlistbox Maximum width", "Small")); m_widthBox->addItem(i18nc("@item:inlistbox Maximum width", "Medium")); m_widthBox->addItem(i18nc("@item:inlistbox Maximum width", "Large")); topLayout->addRow(i18nc("@label:listbox", "Maximum width:"), m_widthBox); break; } case DetailsMode: m_expandableFolders = new QCheckBox(i18nc("@option:check", "Expandable")); topLayout->addRow(i18nc("@label:checkbox", "Folders:"), m_expandableFolders); break; default: break; } loadSettings(); connect(m_defaultSizeSlider, &QSlider::valueChanged, this, &ViewSettingsTab::changed); connect(m_previewSizeSlider, &QSlider::valueChanged, this, &ViewSettingsTab::changed); connect(m_fontRequester, &DolphinFontRequester::changed, this, &ViewSettingsTab::changed); switch (m_mode) { case IconsMode: -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(m_widthBox, QOverload::of(&QComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); -#else - connect(m_widthBox, QOverload::of(&QComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); -#endif -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(m_maxLinesBox, QOverload::of(&QComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); -#else - connect(m_maxLinesBox, QOverload::of(&QComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); -#endif break; case CompactMode: -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(m_widthBox, QOverload::of(&QComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); -#else - connect(m_widthBox, QOverload::of(&QComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); -#endif break; case DetailsMode: connect(m_expandableFolders, &QCheckBox::toggled, this, &ViewSettingsTab::changed); break; default: break; } } ViewSettingsTab::~ViewSettingsTab() { } void ViewSettingsTab::applySettings() { const QFont font = m_fontRequester->currentFont(); const bool useSystemFont = (m_fontRequester->mode() == DolphinFontRequester::SystemFont); switch (m_mode) { case IconsMode: IconsModeSettings::setTextWidthIndex(m_widthBox->currentIndex()); IconsModeSettings::setMaximumTextLines(m_maxLinesBox->currentIndex()); break; case CompactMode: CompactModeSettings::setMaximumTextWidthIndex(m_widthBox->currentIndex()); break; case DetailsMode: DetailsModeSettings::setExpandableFolders(m_expandableFolders->isChecked()); break; default: break; } ViewModeSettings settings(viewMode()); const int iconSize = ZoomLevelInfo::iconSizeForZoomLevel(m_defaultSizeSlider->value()); const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(m_previewSizeSlider->value()); settings.setIconSize(iconSize); settings.setPreviewSize(previewSize); settings.setUseSystemFont(useSystemFont); settings.setFontFamily(font.family()); settings.setFontSize(font.pointSizeF()); settings.setItalicFont(font.italic()); settings.setFontWeight(font.weight()); settings.save(); } void ViewSettingsTab::restoreDefaultSettings() { KConfigSkeleton* settings = nullptr; switch (m_mode) { case IconsMode: settings = IconsModeSettings::self(); break; case CompactMode: settings = CompactModeSettings::self(); break; case DetailsMode: settings = DetailsModeSettings::self(); break; default: Q_ASSERT(false); break; } settings->useDefaults(true); loadSettings(); settings->useDefaults(false); } void ViewSettingsTab::loadSettings() { switch (m_mode) { case IconsMode: m_widthBox->setCurrentIndex(IconsModeSettings::textWidthIndex()); m_maxLinesBox->setCurrentIndex(IconsModeSettings::maximumTextLines()); break; case CompactMode: m_widthBox->setCurrentIndex(CompactModeSettings::maximumTextWidthIndex()); break; case DetailsMode: m_expandableFolders->setChecked(DetailsModeSettings::expandableFolders()); break; default: break; } const ViewModeSettings settings(viewMode()); const QSize iconSize(settings.iconSize(), settings.iconSize()); m_defaultSizeSlider->setValue(ZoomLevelInfo::zoomLevelForIconSize(iconSize)); const QSize previewSize(settings.previewSize(), settings.previewSize()); m_previewSizeSlider->setValue(ZoomLevelInfo::zoomLevelForIconSize(previewSize)); m_fontRequester->setMode(settings.useSystemFont() ? DolphinFontRequester::SystemFont : DolphinFontRequester::CustomFont); QFont font(settings.fontFamily(), qRound(settings.fontSize())); font.setItalic(settings.italicFont()); font.setWeight(settings.fontWeight()); font.setPointSizeF(settings.fontSize()); m_fontRequester->setCustomFont(font); } ViewModeSettings::ViewMode ViewSettingsTab::viewMode() const { ViewModeSettings::ViewMode mode; switch (m_mode) { case ViewSettingsTab::IconsMode: mode = ViewModeSettings::IconsMode; break; case ViewSettingsTab::CompactMode: mode = ViewModeSettings::CompactMode; break; case ViewSettingsTab::DetailsMode: mode = ViewModeSettings::DetailsMode; break; default: mode = ViewModeSettings::IconsMode; Q_ASSERT(false); break; } return mode; } void ViewSettingsTab::slotDefaultSliderMoved(int value) { showToolTip(m_defaultSizeSlider, value); } void ViewSettingsTab::slotPreviewSliderMoved(int value) { showToolTip(m_previewSizeSlider, value); } void ViewSettingsTab::showToolTip(QSlider* slider, int value) { const int size = ZoomLevelInfo::iconSizeForZoomLevel(value); slider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); if (!slider->isVisible()) { return; } QPoint global = slider->rect().topLeft(); global.ry() += slider->height() / 2; QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), slider->mapToGlobal(global)); QApplication::sendEvent(slider, &toolTipEvent); } diff --git a/src/settings/viewpropertiesdialog.cpp b/src/settings/viewpropertiesdialog.cpp index 2f5d55523..c3078d5df 100644 --- a/src/settings/viewpropertiesdialog.cpp +++ b/src/settings/viewpropertiesdialog.cpp @@ -1,456 +1,444 @@ /*************************************************************************** * 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 * * 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 "viewpropertiesdialog.h" #include "dolphin_generalsettings.h" #include "dolphin_iconsmodesettings.h" #include "global.h" #include "kitemviews/kfileitemmodel.h" #include "viewpropsprogressinfo.h" #include "views/dolphinview.h" #include #include #include #include #ifdef HAVE_BALOO #include #endif #include #include #include #include #include #include #include #include #include #include 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) { Q_ASSERT(dolphinView); const bool useGlobalViewProps = GeneralSettings::globalViewProps(); setWindowTitle(i18nc("@title:window", "View Display Style")); 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(); 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); m_sortOrder = new QComboBox(); m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Ascending")); m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Descending")); m_sorting = new QComboBox(); const QList rolesInfo = KFileItemModel::rolesInformation(); foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { m_sorting->addItem(info.translation, info.role); } m_sortFoldersFirst = new QCheckBox(i18nc("@option:check", "Show folders first")); 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(); { 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); } } 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->setContentsMargins(0, 0, 0, 0); sortingLayout->addWidget(m_sortOrder); sortingLayout->addWidget(m_sorting); 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); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(m_viewMode, QOverload::of(&QComboBox::currentIndexChanged), -#else - connect(m_viewMode, QOverload::of(&QComboBox::currentIndexChanged), -#endif this, &ViewPropertiesDialog::slotViewModeChanged); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(m_sorting, QOverload::of(&QComboBox::currentIndexChanged), -#else - connect(m_sorting, QOverload::of(&QComboBox::currentIndexChanged), -#endif this, &ViewPropertiesDialog::slotSortingChanged); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(m_sortOrder, QOverload::of(&QComboBox::currentIndexChanged), -#else - connect(m_sortOrder, QOverload::of(&QComboBox::currentIndexChanged), -#endif 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); // 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->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")); QButtonGroup* applyGroup = new QButtonGroup(this); applyGroup->addButton(m_applyToCurrentFolder); applyGroup->addButton(m_applyToSubFolders); applyGroup->addButton(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 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); } 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); connect(buttonBox, &QDialogButtonBox::rejected, this, &ViewPropertiesDialog::reject); layout->addWidget(buttonBox); auto okButton = buttonBox->button(QDialogButtonBox::Ok); 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); }); const KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "ViewPropertiesDialog"); KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig); loadSettings(); } ViewPropertiesDialog::~ViewPropertiesDialog() { m_isDirty = false; delete m_viewProps; m_viewProps = nullptr; KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "ViewPropertiesDialog"); KWindowConfig::saveWindowSize(windowHandle(), dialogConfig); } void ViewPropertiesDialog::accept() { applyViewProperties(); QDialog::accept(); } void ViewPropertiesDialog::slotApply() { applyViewProperties(); markAsDirty(false); } void ViewPropertiesDialog::slotViewModeChanged(int index) { const QVariant itemData = m_viewMode->itemData(index); const DolphinView::Mode viewMode = static_cast(itemData.toInt()); m_viewProps->setViewMode(viewMode); markAsDirty(true); } void ViewPropertiesDialog::slotSortingChanged(int index) { const QByteArray role = m_sorting->itemData(index).toByteArray(); m_viewProps->setSortRole(role); markAsDirty(true); } void ViewPropertiesDialog::slotSortOrderChanged(int index) { const Qt::SortOrder sortOrder = (index == 0) ? Qt::AscendingOrder : Qt::DescendingOrder; m_viewProps->setSortOrder(sortOrder); markAsDirty(true); } void ViewPropertiesDialog::slotGroupedSortingChanged() { m_viewProps->setGroupedSorting(m_showInGroups->isChecked()); markAsDirty(true); } void ViewPropertiesDialog::slotSortFoldersFirstChanged() { const bool foldersFirst = m_sortFoldersFirst->isChecked(); m_viewProps->setSortFoldersFirst(foldersFirst); markAsDirty(true); } void ViewPropertiesDialog::slotShowPreviewChanged() { const bool show = m_previewsShown->isChecked(); m_viewProps->setPreviewsShown(show); markAsDirty(true); } void ViewPropertiesDialog::slotShowHiddenFilesChanged() { const bool show = m_showHiddenFiles->isChecked(); m_viewProps->setHiddenFilesShown(show); 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::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?")); if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { return; } ViewPropsProgressInfo* info = new ViewPropsProgressInfo(m_dolphinView, m_dolphinView->url(), *m_viewProps); info->setAttribute(Qt::WA_DeleteOnClose); info->setWindowModality(Qt::NonModal); info->show(); } const bool applyToAllFolders = m_applyToAllFolders && m_applyToAllFolders->isChecked(); // 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) { // For directories where no .directory file is available, the .directory // file stored for the global view properties is used as fallback. To update // this file we temporary turn on the global view properties mode. Q_ASSERT(!GeneralSettings::globalViewProps()); GeneralSettings::setGlobalViewProps(true); ViewProperties defaultProps(m_dolphinView->url()); defaultProps.setDirProperties(*m_viewProps); defaultProps.save(); GeneralSettings::setGlobalViewProps(false); } 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) { return; } // Updating the global view properties time stamp in the general settings makes // all existing viewproperties invalid, as they have a smaller time stamp. GeneralSettings* settings = GeneralSettings::self(); settings->setViewPropsTimestamp(QDateTime::currentDateTime()); settings->save(); } m_dolphinView->setMode(m_viewProps->viewMode()); m_dolphinView->setSortRole(m_viewProps->sortRole()); m_dolphinView->setSortOrder(m_viewProps->sortOrder()); m_dolphinView->setSortFoldersFirst(m_viewProps->sortFoldersFirst()); m_dolphinView->setGroupedSorting(m_viewProps->groupedSorting()); m_dolphinView->setVisibleRoles(m_viewProps->visibleRoles()); m_dolphinView->setPreviewsShown(m_viewProps->previewsShown()); m_dolphinView->setHiddenFilesShown(m_viewProps->hiddenFilesShown()); m_viewProps->save(); markAsDirty(false); } 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; } // Load sort order and sorting const int sortOrderIndex = (m_viewProps->sortOrder() == Qt::AscendingOrder) ? 0 : 1; m_sortOrder->setCurrentIndex(sortOrderIndex); const QList rolesInfo = KFileItemModel::rolesInformation(); int sortRoleIndex = 0; for (int i = 0; i < rolesInfo.count(); ++i) { if (rolesInfo[i].role == m_viewProps->sortRole()) { sortRoleIndex = i; break; } } m_sorting->setCurrentIndex(sortRoleIndex); m_sortFoldersFirst->setChecked(m_viewProps->sortFoldersFirst()); // Load show preview, show in groups and show hidden files settings m_previewsShown->setChecked(m_viewProps->previewsShown()); m_showInGroups->setChecked(m_viewProps->groupedSorting()); m_showHiddenFiles->setChecked(m_viewProps->hiddenFilesShown()); markAsDirty(false); }