Warning, /plasma/discover/discover/qml/SourcesPage.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.15
0002 import QtQuick.Controls 2.1
0003 import QtQuick.Layouts 1.1
0004 import org.kde.discover 2.0
0005 import org.kde.discover.app 1.0
0006 import org.kde.kirigami 2.14 as Kirigami
0007 import "navigation.js" as Navigation
0008 import org.kde.kquickcontrolsaddons 2.0 as KQCA
0009 
0010 DiscoverPage {
0011     id: page
0012     clip: true
0013     title: i18n("Settings")
0014     property string search: ""
0015     readonly property string name: title
0016 
0017     Kirigami.Action {
0018         id: configureUpdatesAction
0019         text: i18n("Configure Updates…")
0020         displayHint: Kirigami.DisplayHint.AlwaysHide
0021         onTriggered: {
0022             KQCA.KCMShell.openSystemSettings("kcm_updates");
0023         }
0024     }
0025 
0026     contextualActions: feedbackLoader.item ? feedbackLoader.item.actions : [configureUpdatesAction]
0027 
0028     header: ColumnLayout {
0029         Repeater {
0030             id: rep
0031             model: SourcesModel.sources
0032             delegate: Kirigami.InlineMessage {
0033                 Layout.fillWidth: true
0034                 Layout.margins: Kirigami.Units.smallSpacing
0035                 text: modelData.inlineAction ? modelData.inlineAction.toolTip : ""
0036                 visible: modelData.inlineAction && modelData.inlineAction.visible
0037                 actions: Kirigami.Action {
0038                     icon.name: modelData.inlineAction ? modelData.inlineAction.iconName : ""
0039                     text: modelData.inlineAction ? modelData.inlineAction.text : ""
0040                     onTriggered: modelData.inlineAction.trigger()
0041                 }
0042 
0043             }
0044         }
0045     }
0046 
0047     ListView {
0048         id: sourcesView
0049         model: SourcesModel
0050         Component.onCompleted: Qt.callLater(SourcesModel.showingNow)
0051         currentIndex: -1
0052         pixelAligned: true
0053         section.property: "sourceName"
0054         section.delegate: Kirigami.ListSectionHeader {
0055             id: backendItem
0056             height: Math.ceil(Math.max(Kirigami.Units.gridUnit * 2.5, contentItem.implicitHeight))
0057 
0058             readonly property QtObject backend: SourcesModel.sourcesBackendByName(section)
0059             readonly property QtObject resourcesBackend: backend.resourcesBackend
0060             readonly property bool isDefault: ResourcesModel.currentApplicationBackend === resourcesBackend
0061 
0062             width: sourcesView.width
0063 
0064             readonly property var p0: Connections {
0065                 target: backendItem.backend
0066                 function onPassiveMessage(message) {
0067                     window.showPassiveNotification(message)
0068                 }
0069                 function onProceedRequest(title, description) {
0070                     var dialog = sourceProceedDialog.createObject(window, {sourcesBackend: backendItem.backend, title: title, description: description})
0071                     dialog.open()
0072                 }
0073             }
0074 
0075             contentItem: RowLayout {
0076                 Kirigami.Heading {
0077                     text: resourcesBackend.displayName
0078                     level: 3
0079                     font.weight: backendItem.isDefault ? Font.Bold : Font.Normal
0080                 }
0081 
0082                 Kirigami.ActionToolBar {
0083                     id: actionBar
0084 
0085                     alignment: Qt.AlignRight
0086 
0087                     Kirigami.Action {
0088                         id: isDefaultbackendLabelAction
0089 
0090                         visible: backendItem.isDefault
0091                         displayHint: Kirigami.DisplayHint.KeepVisible
0092                         displayComponent: Kirigami.Heading {
0093                             text: i18n("Default source")
0094                             level: 3
0095                             font.weight: Font.Bold
0096                         }
0097                     }
0098                     Kirigami.Action {
0099                         id: addSourceAction
0100                         text: i18n("Add Source…")
0101                         icon.name: "list-add"
0102                         visible: backendItem.backend && backendItem.backend.supportsAdding
0103 
0104                         readonly property Component p0: Component {
0105                             id: dialogComponent
0106                             AddSourceDialog {
0107                                 source: backendItem.backend
0108 
0109                                 onVisibleChanged: if(!visible) {
0110                                     destroy(1000)
0111                                 }
0112                             }
0113                         }
0114 
0115                         onTriggered: {
0116                             var addSourceDialog = dialogComponent.createObject(window, {displayName: backendItem.backend.resourcesBackend.displayName })
0117                             addSourceDialog.open()
0118                         }
0119                     }
0120                     Kirigami.Action {
0121                         id: makeDefaultAction
0122                         visible: resourcesBackend && resourcesBackend.hasApplications && !backendItem.isDefault
0123 
0124                         text: i18n("Make default")
0125                         icon.name: "favorite"
0126                         onTriggered: ResourcesModel.currentApplicationBackend = backendItem.backend.resourcesBackend
0127                     }
0128 
0129                     Component {
0130                         id: kirigamiAction
0131                         ConvertDiscoverAction {}
0132                     }
0133 
0134                     function mergeActions(moreActions) {
0135                         var actions = [isDefaultbackendLabelAction,
0136                                     makeDefaultAction,
0137                                     addSourceAction]
0138                         for(var i in moreActions) {
0139                             actions.push(kirigamiAction.createObject(actionBar, {action: moreActions[i]}))
0140                         }
0141                         return actions;
0142                     }
0143                     actions: mergeActions(backendItem.backend.actions)
0144                 }
0145             }
0146         }
0147 
0148         Component {
0149             id: sourceProceedDialog
0150             Kirigami.OverlaySheet {
0151                 id: sheet
0152                 parent: applicationWindow().overlay
0153 
0154                 showCloseButton: false
0155                 property QtObject  sourcesBackend
0156                 property alias description: desc.text
0157                 property bool acted: false
0158 
0159                 ColumnLayout {
0160                     Label {
0161                         id: desc
0162                         Layout.fillWidth: true
0163                         textFormat: Text.StyledText
0164                         wrapMode: Text.WordWrap
0165                     }
0166                     RowLayout {
0167                         Layout.alignment: Qt.AlignRight
0168                         Button {
0169                             text: i18n("Proceed")
0170                             icon.name: "dialog-ok"
0171                             onClicked: {
0172                                 sourcesBackend.proceed()
0173                                 sheet.acted = true
0174                                 sheet.close()
0175                             }
0176                         }
0177                         Button {
0178                             Layout.alignment: Qt.AlignRight
0179                             text: i18n("Cancel")
0180                             icon.name: "dialog-cancel"
0181                             onClicked: {
0182                                 sourcesBackend.cancel()
0183                                 sheet.acted = true
0184                                 sheet.close()
0185                             }
0186                         }
0187                     }
0188                 }
0189                 onSheetOpenChanged: if(!sheetOpen) {
0190                     sheet.destroy(1000)
0191                     if (!sheet.acted)
0192                         sourcesBackend.cancel()
0193                 }
0194             }
0195         }
0196 
0197         delegate: Kirigami.SwipeListItem {
0198             id: delegate
0199             enabled: model.display.length>0 && model.enabled
0200             highlighted: ListView.isCurrentItem
0201             supportsMouseEvents: false
0202             visible: model.display.indexOf(page.search)>=0
0203             height: visible ? implicitHeight : 0
0204 
0205             Keys.onReturnPressed: enabledBox.clicked()
0206             Keys.onSpacePressed: enabledBox.clicked()
0207             actions: [
0208                 Kirigami.Action {
0209                     iconName: "go-up"
0210                     tooltip: i18n("Increase priority")
0211                     enabled: sourcesBackend.firstSourceId !== sourceId
0212                     visible: sourcesBackend.canMoveSources
0213                     onTriggered: {
0214                         var ret = sourcesBackend.moveSource(sourceId, -1)
0215                         if (!ret)
0216                             window.showPassiveNotification(i18n("Failed to increase '%1' preference", model.display))
0217                     }
0218                 },
0219                 Kirigami.Action {
0220                     iconName: "go-down"
0221                     tooltip: i18n("Decrease priority")
0222                     enabled: sourcesBackend.lastSourceId !== sourceId
0223                     visible: sourcesBackend.canMoveSources
0224                     onTriggered: {
0225                         var ret = sourcesBackend.moveSource(sourceId, +1)
0226                         if (!ret)
0227                             window.showPassiveNotification(i18n("Failed to decrease '%1' preference", model.display))
0228                     }
0229                 },
0230                 Kirigami.Action {
0231                     iconName: "edit-delete"
0232                     tooltip: i18n("Remove repository")
0233                     visible: sourcesBackend.supportsAdding
0234                     onTriggered: {
0235                         var backend = sourcesBackend
0236                         if (!backend.removeSource(sourceId)) {
0237                             console.warn("Failed to remove the source", model.display)
0238                         }
0239                     }
0240                 },
0241                 Kirigami.Action {
0242                     iconName: delegate.LayoutMirroring.enabled ? "go-next-symbolic-rtl" : "go-next-symbolic"
0243                     tooltip: i18n("Show contents")
0244                     visible: sourcesBackend.canFilterSources
0245                     onTriggered: {
0246                         Navigation.openApplicationListSource(sourceId)
0247                     }
0248                 }
0249             ]
0250 
0251             RowLayout {
0252                 CheckBox {
0253                     id: enabledBox
0254 
0255                     readonly property variant idx: sourcesView.model.index(index, 0)
0256                     readonly property variant modelChecked: model.checkState
0257                     checked: modelChecked !== Qt.Unchecked
0258                     enabled: sourcesView.model.flags(idx) & Qt.ItemIsUserCheckable
0259                     onClicked: {
0260                         sourcesView.model.setData(idx, checkState, Qt.CheckStateRole)
0261                         checked = Qt.binding(function() { return modelChecked !== Qt.Unchecked; })
0262                     }
0263                 }
0264                 Label {
0265                     text: model.display + (model.toolTip ? " - <i>" + model.toolTip + "</i>" : "")
0266                     elide: Text.ElideRight
0267                     textFormat: Text.StyledText
0268                     Layout.fillWidth: true
0269                 }
0270             }
0271         }
0272 
0273         footer: ColumnLayout {
0274             id: foot
0275             anchors {
0276                 right: parent.right
0277                 left: parent.left
0278                 margins: Kirigami.Units.smallSpacing
0279             }
0280             Kirigami.ListSectionHeader {
0281                 contentItem: Kirigami.Heading {
0282                     Layout.fillWidth: true
0283                     text: i18n("Missing Backends")
0284                     visible: back.count > 0
0285                     level: 3
0286                 }
0287             }
0288             spacing: 0
0289             Repeater {
0290                 id: back
0291                 model: ResourcesProxyModel {
0292                     extending: "org.kde.discover.desktop"
0293                     filterMinimumState: false
0294                     stateFilter: AbstractResource.None
0295                 }
0296                 delegate: Kirigami.BasicListItem {
0297                     supportsMouseEvents: false
0298                     label: name
0299                     icon: model.icon
0300                     subtitle: model.comment
0301                     trailing: InstallApplicationButton {
0302                         application: model.application
0303                     }
0304                 }
0305             }
0306         }
0307     }
0308 }