/*SPDX-FileCopyrightText: 2018 Tomaz Canabrava <tcanabrava@kde.org>SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL*/import QtCoreimport QtQuickimport QtQuick.Layoutsimport QtQuick.Controls as QQC2import QtQuick.Dialogs as QtDialogsimport org.kde.baloo.experimental as Balooimport org.kde.kirigami as Kirigamiimport org.kde.kcmutils as KCMKCM.ScrollViewKCM {id: rootimplicitWidth: Kirigami.Units.gridUnit * 42implicitHeight: Kirigami.Units.gridUnit * 25Baloo.Monitor {id: monitorreadonly property bool currentlyIndexing: switch(state) {case Baloo.Global.FirstRun:case Baloo.Global.NewFiles:case Baloo.Global.ModifiedFiles:case Baloo.Global.XAttrFiles:case Baloo.Global.ContentIndexing:case Baloo.Global.UnindexedFileCheck:case Baloo.Global.StaleIndexEntriesClean:return true;default:return false;}readonly property int completionPercentage: Math.floor(filesIndexed / totalFiles * 100)}actions: [Kirigami.Action {icon.name: monitor.state !== Baloo.Global.Suspended ? "media-playback-pause" : "media-playback-start"text: monitor.state !== Baloo.Global.Suspended ? i18nc("@action:button", "Pause Indexer") : i18nc("@action:button", "Resume Indexer")visible: kcm.balooSettings.indexingEnableddisplayHint: Kirigami.DisplayHint.KeepVisibleonTriggered: monitor.toggleSuspendState()}]headerPaddingEnabled: false // Let the InlineMessages touch the edgesheader: ColumnLayout {spacing: Kirigami.Units.smallSpacingKirigami.InlineMessage {Layout.fillWidth: truevisible: fileSearchDisabled.checked && kcm.needsSavetype: Kirigami.MessageType.Warningposition: Kirigami.InlineMessage.Position.HeadershowCloseButton: truetext: i18nc("@info inlinemessage", "This will disable file searching in KRunner and launcher menus, and remove extended metadata display from all KDE applications.");}Kirigami.InlineMessage {id: indexingDisabledWarningLayout.fillWidth: truevisible: !kcm.balooSettings.indexingEnabled && !kcm.needsSave && kcm.rawIndexFileSize() > 0type: Kirigami.MessageType.Warningposition: Kirigami.InlineMessage.Position.HeadershowCloseButton: truetext: i18nc("@info:inlinemessage", "Do you want to delete the saved index data? %1 of space will be freed, but if indexing is re-enabled later, the entire index will have to be re-created from scratch. This may take some time, depending on the number of files to index.", kcm.prettyIndexFileSize());actions: Kirigami.Action {text: i18nc("@action:button", "Delete Index Data")icon.name: "edit-delete"onTriggered: {kcm.deleteIndex();indexingDisabledWarning.visible = false;}}}QQC2.Label {text: i18nc("@info:usagetip", "File Search helps you quickly locate your files. You can choose which folders and what types of file data are indexed.")textFormat: Text.PlainTextLayout.fillWidth: trueLayout.maximumWidth: Kirigami.Units.gridUnit * 24Layout.alignment: Qt.AlignHCenterLayout.topMargin: Kirigami.Units.largeSpacing * 2Layout.bottomMargin: Kirigami.Units.largeSpacinghorizontalAlignment: Text.AlignHCenterwrapMode: Text.WordWrap}// By disabling header margins to make the header banners look correct,// we have to re-add some margins for the content area so it doesn't// touch the window edges and look ugly. To make it apply to everything,// we wrap it all in another ColumnLayout with its own margins.Kirigami.Form {Layout.bottomMargin: Kirigami.Units.largeSpacing * 2Layout.fillWidth: trueKirigami.FormGroup {Kirigami.FormEntry {title: i18nc("@title:group", "Data to index:")contentItem: QQC2.RadioButton {id: fileSearchDisabledtext: i18nc("@option:radio Data to index", "Nothing (disable indexing entirely)")checked: !kcm.balooSettings.indexingEnabledonToggled: kcm.balooSettings.indexingEnabled = falseQQC2.ButtonGroup.group: indexingStyleGroupKCM.SettingStateBinding {configObject: kcm.balooSettingssettingName: "indexingEnabled"}QQC2.ButtonGroup {id: indexingStyleGroup}}}Kirigami.FormEntry {contentItem: QQC2.RadioButton {text: i18nc("@option:radio Data to index", "File names only")checked: kcm.balooSettings.indexingEnabled && kcm.balooSettings.onlyBasicIndexingonToggled: {kcm.balooSettings.indexingEnabled = true;kcm.balooSettings.onlyBasicIndexing = true;}QQC2.ButtonGroup.group: indexingStyleGroupKCM.SettingStateBinding {configObject: kcm.balooSettingssettingName: "onlyBasicIndexing"}}}Kirigami.FormEntry {contentItem: QQC2.RadioButton {text: i18nc("@option:radio Data to index", "File names and contents")checked: kcm.balooSettings.indexingEnabled && !kcm.balooSettings.onlyBasicIndexingonToggled: {kcm.balooSettings.indexingEnabled = true;kcm.balooSettings.onlyBasicIndexing = false;}QQC2.ButtonGroup.group: indexingStyleGroupKCM.SettingStateBinding {configObject: kcm.balooSettingssettingName: "onlyBasicIndexing"}}}Kirigami.FormEntry {contentItem: QQC2.CheckBox {id: indexHiddenFolderstext: i18nc("@option:check", "Also index hidden files and folders")checked: kcm.balooSettings.indexHiddenFoldersonCheckStateChanged: kcm.balooSettings.indexHiddenFolders = checkedKCM.SettingStateBinding {configObject: kcm.balooSettingssettingName: "indexHiddenFolders"extraEnabledConditions: !fileSearchDisabled.checked}}}}}}view: ListView {id: directoryConfigListenabled: !fileSearchDisabled.checkedclip: truecurrentIndex: -1model: kcm.filteredModeldelegate: directoryConfigDelegateheaderPositioning: ListView.OverlayHeaderheader: Kirigami.InlineViewHeader {width: directoryConfigList.widthtext: i18nc("@title:table Locations to include or exclude from indexing", "Locations")actions: [Kirigami.Action {text: i18nc("@action:button", "Start Indexing a Folderβ¦")icon.name: "list-add-symbolic"onTriggered: {fileDialogLoader.included = truefileDialogLoader.active = true}},Kirigami.Action {text: i18nc("@action:button", "Stop Indexing a Folderβ¦")icon.name: "list-remove-symbolic"onTriggered: {fileDialogLoader.included = falsefileDialogLoader.active = true}}]}}extraFooterTopPadding: true // re-add separator linefooter: ColumnLayout {visible: !fileSearchDisabled.checkedspacing: Kirigami.Units.smallSpacingQQC2.Label {Layout.fillWidth: truetext: i18nc("State and a percentage of progress", "%1, %2% complete", monitor.stateString, monitor.completionPercentage)textFormat: Text.PlainText}Kirigami.SelectableLabel {Layout.fillWidth: truevisible: monitor.currentlyIndexing && monitor.completionPercentage !== 100 && monitor.filePath.length > 0text: xi18nc("@info Currently Indexing", "Currently indexing: <filename>%1</filename>", monitor.filePath)}}Component {id: directoryConfigDelegateQQC2.ItemDelegate {id: listItem// Store this as a property so we can access it within the combobox,// which also has a `model` propertyproperty var indexingModel: modelwidth: directoryConfigList.width// There's no need for a list item to ever be selecteddown: falsehighlighted: falsehoverEnabled: false// ... and because of that, use alternating backgrounds to visually// connect list items' left and right side content elementsKirigami.Theme.useAlternateBackgroundColor: truecontentItem: RowLayout {spacing: Kirigami.Units.smallSpacing// The folder's iconKirigami.Icon {source: indexingModel.decorationLayout.preferredHeight: Kirigami.Units.iconSizes.smallMediumLayout.preferredWidth: Layout.preferredHeight}// The folder's pathQQC2.Label {text: indexingModel.foldertextFormat: Text.PlainTextelide: Text.ElideRightLayout.fillWidth: true}// What kind of indexing to do for the folderQQC2.ComboBox {id: indexingOptionsComboboxproperty bool indexingDisabled: !indexingModel.enableIndexproperty bool fullContentIndexing: indexingModel.enableIndexmodel: [i18nc("@info:status", "Not indexed"),i18nc("@info:status", "Indexed"),]// Intentionally not a simple ternary to facilitate adding// more conditions in the futurecurrentIndex: {if (indexingDisabled) return 0if (fullContentIndexing) return 1}onActivated: {// New value is "Not indexed"if (indexingOptionsCombobox.currentIndex === 0 && fullContentIndexing) {indexingModel.enableIndex = false// New value is "Full content indexing"} else if (indexingOptionsCombobox.currentIndex === 1 && indexingDisabled) {indexingModel.enableIndex = true}}}// Delete button to remove this folder entryQQC2.Button {enabled: model.deletableicon.name: "edit-delete-remove"text: i18nc("Remove the list item for this filesystem path", "Remove entry")display: QQC2.AbstractButton.IconOnlyonClicked: kcm.filteredModel.removeFolder(index)QQC2.ToolTip.text: textQQC2.ToolTip.visible: hovered || activeFocusQQC2.ToolTip.delay: Kirigami.Units.toolTipDelay}}}}Loader {id: fileDialogLoaderproperty bool included: falseactive: falsesourceComponent: QtDialogs.FolderDialog {title: fileDialogLoader.included ? i18nc("@title:window", "Select a folder to include") : i18nc("@title:window", "Select a folder to exclude")currentFolder: StandardPaths.standardLocations(StandardPaths.HomeLocation)[0]onAccepted: {kcm.filteredModel.addFolder(selectedFolder, fileDialogLoader.included)fileDialogLoader.active = false}onRejected: {fileDialogLoader.active = false}Component.onCompleted: open()}}}