Warning, /plasma/plasma-desktop/kcms/baloo/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2018 Tomaz Canabrava <tcanabrava@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 import QtCore 6.5 0008 import QtQuick 2.15 0009 import QtQuick.Layouts 1.1 0010 import QtQuick.Controls 2.15 as QQC2 0011 import QtQuick.Dialogs 6.3 as QtDialogs 0012 import org.kde.baloo.experimental 0.1 as Baloo 0013 import org.kde.kirigami 2.20 as Kirigami 0014 import org.kde.kcmutils as KCM 0015 0016 KCM.ScrollViewKCM { 0017 id: root 0018 0019 implicitWidth: Kirigami.Units.gridUnit * 42 0020 implicitHeight: Kirigami.Units.gridUnit * 25 0021 0022 Baloo.Monitor { 0023 id: monitor 0024 0025 readonly property bool currentlyIndexing: switch(state) { 0026 case Baloo.Global.FirstRun: 0027 case Baloo.Global.NewFiles: 0028 case Baloo.Global.ModifiedFiles: 0029 case Baloo.Global.XAttrFiles: 0030 case Baloo.Global.ContentIndexing: 0031 case Baloo.Global.UnindexedFileCheck: 0032 case Baloo.Global.StaleIndexEntriesClean: 0033 return true; 0034 default: 0035 return false; 0036 } 0037 0038 readonly property int completionPercentage: Math.floor(filesIndexed / totalFiles * 100) 0039 } 0040 0041 actions: [ 0042 Kirigami.Action { 0043 icon.name: monitor.state !== Baloo.Global.Suspended ? "media-playback-pause" : "media-playback-start" 0044 text: monitor.state !== Baloo.Global.Suspended ? i18n("Pause Indexer") : i18n("Resume Indexer") 0045 visible: kcm.balooSettings.indexingEnabled 0046 onTriggered: monitor.toggleSuspendState() 0047 } 0048 ] 0049 0050 header: Item { 0051 implicitHeight: headerColumn.implicitHeight + headerColumn.anchors.topMargin + Kirigami.Units.smallSpacing 0052 0053 ColumnLayout { 0054 id: headerColumn 0055 0056 anchors { 0057 top: parent.top 0058 topMargin: Kirigami.Units.largeSpacing 0059 left: parent.left 0060 leftMargin: Kirigami.Units.largeSpacing 0061 right: parent.right 0062 rightMargin: Kirigami.Units.largeSpacing 0063 } 0064 0065 spacing: Kirigami.Units.smallSpacing 0066 0067 Kirigami.InlineMessage { 0068 Layout.fillWidth: true 0069 visible: !fileSearchEnabled.checked && kcm.needsSave 0070 type: Kirigami.MessageType.Warning 0071 showCloseButton: true 0072 text: i18n("This will disable file searching in KRunner and launcher menus, and remove extended metadata display from all KDE applications."); 0073 } 0074 0075 Kirigami.InlineMessage { 0076 id: indexingDisabledWarning 0077 Layout.fillWidth: true 0078 visible: !kcm.balooSettings.indexingEnabled && !kcm.needsSave && kcm.rawIndexFileSize() > 0 0079 type: Kirigami.MessageType.Warning 0080 showCloseButton: true 0081 text: i18n("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 how many files you have.", kcm.prettyIndexFileSize()); 0082 actions: Kirigami.Action { 0083 text: i18n("Delete Index Data") 0084 icon.name: "edit-delete" 0085 onTriggered: { 0086 kcm.deleteIndex(); 0087 indexingDisabledWarning.visible = false; 0088 } 0089 } 0090 } 0091 0092 QQC2.Label { 0093 text: i18n("File Search helps you quickly locate your files. You can choose which folders and what types of file data are indexed.") 0094 textFormat: Text.PlainText 0095 Layout.fillWidth: true 0096 Layout.maximumWidth: Kirigami.Units.gridUnit * 24 0097 Layout.alignment: Qt.AlignHCenter 0098 Layout.bottomMargin: Kirigami.Units.largeSpacing 0099 horizontalAlignment: Text.AlignHCenter 0100 wrapMode: Text.WordWrap 0101 } 0102 0103 0104 Kirigami.FormLayout { 0105 id: indexingForm 0106 0107 QQC2.CheckBox { 0108 id: fileSearchEnabled 0109 Kirigami.FormData.label: i18nc("@title:group", "File indexing:") 0110 text: i18nc("@action:check", "Enabled") 0111 checked: kcm.balooSettings.indexingEnabled 0112 onCheckStateChanged: { 0113 kcm.balooSettings.indexingEnabled = checked 0114 } 0115 0116 KCM.SettingStateBinding { 0117 configObject: kcm.balooSettings 0118 settingName: "indexingEnabled" 0119 } 0120 } 0121 0122 // Current status 0123 QQC2.Label { 0124 Kirigami.FormData.label: i18nc("@label indexing status", "Status:") 0125 Layout.fillWidth: true 0126 leftPadding: fileSearchEnabled.indicator.width 0127 visible: fileSearchEnabled.checked 0128 text: i18nc("State and a percentage of progress", "%1, %2% complete", monitor.stateString, monitor.completionPercentage) 0129 textFormat: Text.PlainText 0130 elide: Text.ElideLeft 0131 } 0132 } 0133 0134 Item { 0135 visible: fileBeingIndexed.visible 0136 implicitHeight: Kirigami.Units.smallSpacing 0137 } 0138 0139 // Current file being indexed 0140 QQC2.Label { 0141 Layout.fillWidth: true 0142 text: i18nc("@label file currently being indexed", "Currently indexing:") 0143 textFormat: Text.PlainText 0144 horizontalAlignment: Text.AlignHCenter 0145 visible: fileBeingIndexed.visible 0146 } 0147 0148 // File being indexed, if indexing 0149 Kirigami.SelectableLabel { 0150 id: fileBeingIndexed 0151 Layout.fillWidth: true 0152 visible: fileSearchEnabled.checked && monitor.currentlyIndexing && monitor.completionPercentage !== 100 && monitor.filePath.length > 0 0153 text: xi18nc("@info Currently Indexing", "<filename>%1</filename>", monitor.filePath) 0154 } 0155 0156 Item { 0157 implicitHeight: Kirigami.Units.smallSpacing 0158 } 0159 0160 Kirigami.FormLayout { 0161 twinFormLayouts: indexingForm 0162 0163 Layout.bottomMargin: Kirigami.Units.largeSpacing * 2 0164 0165 QQC2.ButtonGroup { 0166 id: indexingStyleGroup 0167 } 0168 QQC2.RadioButton { 0169 Kirigami.FormData.label: i18nc("@title:group", "Data to index:") 0170 0171 text: i18n("File names and contents") 0172 checked: !kcm.balooSettings.onlyBasicIndexing 0173 onToggled: kcm.balooSettings.onlyBasicIndexing = !checked 0174 0175 QQC2.ButtonGroup.group: indexingStyleGroup 0176 0177 KCM.SettingStateBinding { 0178 configObject: kcm.balooSettings 0179 settingName: "onlyBasicIndexing" 0180 extraEnabledConditions: fileSearchEnabled.checked 0181 } 0182 } 0183 QQC2.RadioButton { 0184 text: i18n("File names only") 0185 checked: kcm.balooSettings.onlyBasicIndexing 0186 onToggled: kcm.balooSettings.onlyBasicIndexing = checked 0187 0188 QQC2.ButtonGroup.group: indexingStyleGroup 0189 0190 KCM.SettingStateBinding { 0191 configObject: kcm.balooSettings 0192 settingName: "onlyBasicIndexing" 0193 extraEnabledConditions: fileSearchEnabled.checked 0194 } 0195 } 0196 0197 Item { 0198 implicitHeight: Kirigami.Units.smallSpacing 0199 } 0200 0201 QQC2.CheckBox { 0202 id: indexHiddenFolders 0203 text: i18n("Hidden files and folders") 0204 checked: kcm.balooSettings.indexHiddenFolders 0205 onCheckStateChanged: kcm.balooSettings.indexHiddenFolders = checked 0206 0207 KCM.SettingStateBinding { 0208 configObject: kcm.balooSettings 0209 settingName: "indexHiddenFolders" 0210 extraEnabledConditions: fileSearchEnabled.checked 0211 } 0212 } 0213 } 0214 } 0215 } 0216 0217 view: ListView { 0218 id: directoryConfigList 0219 enabled: fileSearchEnabled.checked 0220 clip: true 0221 currentIndex: -1 0222 0223 model: kcm.filteredModel 0224 delegate: directoryConfigDelegate 0225 0226 headerPositioning: ListView.OverlayHeader 0227 header: Kirigami.InlineViewHeader { 0228 width: directoryConfigList.width 0229 text: i18nc("@title:table Locations to include or exclude from indexing", "Locations") 0230 actions: [ 0231 Kirigami.Action { 0232 text: i18nc("@action:button", "Start Indexing a Folder…") 0233 icon.name: "list-add-symbolic" 0234 onTriggered: { 0235 fileDialogLoader.included = true 0236 fileDialogLoader.active = true 0237 } 0238 }, 0239 Kirigami.Action { 0240 text: i18nc("@action:button", "Stop Indexing a Folder…") 0241 icon.name: "list-remove-symbolic" 0242 onTriggered: { 0243 fileDialogLoader.included = false 0244 fileDialogLoader.active = true 0245 } 0246 } 0247 ] 0248 } 0249 } 0250 0251 Component { 0252 id: directoryConfigDelegate 0253 QQC2.ItemDelegate { 0254 id: listItem 0255 0256 // Store this as a property so we can access it within the combobox, 0257 // which also has a `model` property 0258 property var indexingModel: model 0259 0260 width: directoryConfigList.width 0261 0262 // There's no need for a list item to ever be selected 0263 down: false 0264 highlighted: false 0265 hoverEnabled: false 0266 // ... and because of that, use alternating backgrounds to visually 0267 // connect list items' left and right side content elements 0268 Kirigami.Theme.useAlternateBackgroundColor: true 0269 0270 contentItem: RowLayout { 0271 spacing: Kirigami.Units.smallSpacing 0272 0273 // The folder's icon 0274 Kirigami.Icon { 0275 source: indexingModel.decoration 0276 0277 Layout.preferredHeight: Kirigami.Units.iconSizes.smallMedium 0278 Layout.preferredWidth: Layout.preferredHeight 0279 } 0280 0281 // The folder's path 0282 QQC2.Label { 0283 text: indexingModel.folder 0284 textFormat: Text.PlainText 0285 elide: Text.ElideRight 0286 0287 Layout.fillWidth: true 0288 } 0289 0290 // What kind of indexing to do for the folder 0291 QQC2.ComboBox { 0292 id: indexingOptionsCombobox 0293 0294 property bool indexingDisabled: !indexingModel.enableIndex 0295 property bool fullContentIndexing: indexingModel.enableIndex 0296 0297 flat: true 0298 0299 model: [ 0300 i18n("Not indexed"), 0301 i18n("Indexed"), 0302 ] 0303 0304 // Intentionally not a simple ternary to facilitate adding 0305 // more conditions in the future 0306 currentIndex: { 0307 if (indexingDisabled) return 0 0308 if (fullContentIndexing) return 1 0309 } 0310 0311 onActivated: { 0312 // New value is "Not indexed" 0313 if (indexingOptionsCombobox.currentIndex === 0 && fullContentIndexing) { 0314 indexingModel.enableIndex = false 0315 // New value is "Full content indexing" 0316 } else if (indexingOptionsCombobox.currentIndex === 1 && indexingDisabled) { 0317 indexingModel.enableIndex = true 0318 } 0319 } 0320 } 0321 0322 // Delete button to remove this folder entry 0323 QQC2.ToolButton { 0324 enabled: model.deletable 0325 0326 icon.name: "edit-delete" 0327 0328 onClicked: kcm.filteredModel.removeFolder(index) 0329 0330 QQC2.ToolTip { 0331 text: i18n("Delete entry") 0332 } 0333 } 0334 } 0335 } 0336 } 0337 0338 Loader { 0339 id: fileDialogLoader 0340 0341 property bool included: false 0342 0343 active: false 0344 0345 sourceComponent: QtDialogs.FolderDialog { 0346 title: fileDialogLoader.included ? i18n("Select a folder to include") : i18n("Select a folder to exclude") 0347 currentFolder: StandardPaths.standardLocations(StandardPaths.HomeLocation)[0] 0348 0349 onAccepted: { 0350 kcm.filteredModel.addFolder(selectedFolder, fileDialogLoader.included) 0351 fileDialogLoader.active = false 0352 } 0353 0354 onRejected: { 0355 fileDialogLoader.active = false 0356 } 0357 0358 Component.onCompleted: open() 0359 } 0360 } 0361 }