SourcesPage.qml 9.01 KB
Newer Older
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
1
import QtQuick 2.4
2
import QtQuick.Controls 1.1
3
import QtQuick.Controls 2.1 as QQC2
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
4
import QtQuick.Layouts 1.1
5
import org.kde.discover 2.0
6
import org.kde.discover.app 1.0
7
import org.kde.kirigami 2.2 as Kirigami
8
import "navigation.js" as Navigation
9

10
DiscoverPage {
11
    id: page
12
    clip: true
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
13
    title: i18n("Settings")
14
    property string search: ""
15

16
17
18
19
20
21
22
    Kirigami.Theme.inherit: false
    Kirigami.Theme.colorSet: Kirigami.Theme.View

    background: Rectangle {
        color: Kirigami.Theme.backgroundColor
    }

23
24
25
26
    contextualActions: [
        KirigamiActionBridge { action: app.action("help_about_app") },
        KirigamiActionBridge { action: app.action("help_report_bug") }
    ]
27

28
    mainItem: ListView {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
29
        id: sourcesView
30
        model: QSortFilterProxyModel {
31
            filterRegExp: new RegExp(page.search, 'i')
32
            dynamicSortFilter: false //We don't want to sort, as sorting can have some semantics on some backends
33
            sourceModel: SourcesModel
34
35
        }
        currentIndex: -1
36

37
38
        Component {
            id: sourceBackendDelegate
39
            Kirigami.AbstractListItem {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
40
                id: backendItem
41
42
                hoverEnabled: false
                supportsMouseEvents: false
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
43
44
                readonly property QtObject backend: sourcesBackend
                readonly property bool isDefault: ResourcesModel.currentApplicationBackend == resourcesBackend
45
                RowLayout {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
46
47
48
49
                    Connections {
                        target: backendItem.backend
                        onPassiveMessage: window.showPassiveNotification(message)
                    }
50
51
52
53
54
55

                    anchors {
                        right: parent.right
                        left: parent.left
                        rightMargin: parent.rightPadding
                        leftMargin: parent.leftPadding
56
                    }
57
58
59
                    Kirigami.Heading {
                        Layout.fillWidth: true
                        text: backendItem.isDefault ? i18n("%1 (Default)", resourcesBackend.displayName) : resourcesBackend.displayName
60
                    }
61
62
63
                    Button {
                        Layout.rightMargin: Kirigami.Units.smallSpacing
                        iconName: "preferences-other"
64

65
66
67
68
69
70
71
72
                        visible: resourcesBackend && resourcesBackend.hasApplications
                        Component {
                            id: dialogComponent
                            AddSourceDialog {
                                source: backendItem.backend
                                onVisibleChanged: if (!visible) {
                                    destroy()
                                }
73
                            }
74
75
                        }

76
77
78
79
80
81
                        menu: Menu {
                            id: settingsMenu
                            MenuItem {
                                enabled: !backendItem.isDefault
                                text: i18n("Make default")
                                onTriggered: ResourcesModel.currentApplicationBackend = backendItem.backend.resourcesBackend
82
                            }
83
84
85

                            MenuItem {
                                text: i18n("Add Source...")
86
                                visible: backendItem.backend && backendItem.backend.supportsAdding
87
88
89
90
91

                                onTriggered: {
                                    var addSourceDialog = dialogComponent.createObject(null, {displayName: backendItem.backend.resourcesBackend.displayName })
                                    addSourceDialog.open()
                                }
92
                            }
93
94
95

                            MenuSeparator {
                                visible: backendActionsInst.count>0
96
                            }
97
98
99
100
101
102
103

                            Instantiator {
                                id: backendActionsInst
                                model: ActionsModel {
                                    actions: backendItem.backend ? backendItem.backend.actions : undefined
                                }
                                delegate: MenuItem {
104
                                    action: ActionBridge { action: modelData.action }
105
106
107
108
109
110
111
                                }
                                onObjectAdded: {
                                    settingsMenu.insertItem(index, object)
                                }
                                onObjectRemoved: {
                                    object.destroy()
                                }
112
113
114
115
                            }
                        }
                    }
                }
116
117
118
            }
        }

119
120
121
122
123
124
125
126
127
128
129
        delegate: ConditionalLoader {
            anchors {
                right: parent.right
                left: parent.left
            }
            readonly property variant resourcesBackend: model.resourcesBackend
            readonly property variant sourcesBackend: model.sourcesBackend
            readonly property variant display: model.display
            readonly property variant checked: model.checked
            readonly property variant statusTip: model.statusTip
            readonly property variant toolTip: model.toolTip
130
            readonly property variant sourceId: model.sourceId
131
132
133
134
135
136
137
138
139
140
141
142
143
            readonly property variant modelIndex: sourcesView.model.index(index, 0)

            condition: resourcesBackend != null
            componentTrue: sourceBackendDelegate
            componentFalse: sourceDelegate
        }

        Component {
            id: sourceDelegate
            Kirigami.SwipeListItem {
                Layout.fillWidth: true
                enabled: display.length>0
                highlighted: ListView.isCurrentItem
144
                onClicked: Navigation.openApplicationListSource(sourceId)
145
146
147

                Keys.onReturnPressed: clicked()
                actions: [
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
                    Kirigami.Action {
                        iconName: "go-up"
                        enabled: sourcesBackend.firstSourceId !== sourceId
                        visible: sourcesBackend.canMoveSources
                        onTriggered: {
                             var ret = sourcesBackend.moveSource(sourceId, -1)
                             if (!ret)
                                 window.showPassiveNotification(i18n("Failed to increase '%1' preference", display))
                        }
                    },
                    Kirigami.Action {
                        iconName: "go-down"
                        enabled: sourcesBackend.lastSourceId !== sourceId
                        visible: sourcesBackend.canMoveSources
                        onTriggered: {
                            var ret = sourcesBackend.moveSource(sourceId, +1)
                            if (!ret)
                                 window.showPassiveNotification(i18n("Failed to decrease '%1' preference", display))
                        }
                    },
168
169
170
171
                    Kirigami.Action {
                        iconName: "edit-delete"
                        tooltip: i18n("Delete the origin")
                        onTriggered: {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
172
                            var backend = sourcesBackend
173
                            if (!backend.removeSource(sourceId)) {
174
175
                                window.showPassiveNotification(i18n("Failed to remove the source '%1'", display))
                            }
176
                        }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
177
                    }
178
                ]
179

180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
                RowLayout {
                    CheckBox {
                        id: enabledBox

                        readonly property variant modelChecked: sourcesView.model.data(modelIndex, Qt.CheckStateRole)
                        checked: modelChecked != Qt.Unchecked
                        enabled: modelChecked !== undefined
                        onClicked: {
                            sourcesView.model.setData(modelIndex, checkedState, Qt.CheckStateRole)
                        }
                    }
                    QQC2.Label {
                        text: display + " - <i>" + toolTip + "</i>"
                        elide: Text.ElideRight
                        Layout.fillWidth: true
195
                    }
196
                }
197
            }
198
        }
199
200
201
202
203
204
205
206

        footer: ColumnLayout {
            id: foot
            anchors {
                right: parent.right
                left: parent.left
                margins: Kirigami.Units.smallSpacing
            }
207
208
209
210
            Kirigami.Heading {
                Layout.fillWidth: true
                text: i18n("Missing Backends")
            }
211
212
213
214
215
216
217
218
219
220
221
222
            Repeater {
                id: back
                model: ResourcesProxyModel {
                    extending: "org.kde.discover.desktop"
                }
                delegate: RowLayout {
                    visible: !model.application.isInstalled
                    QQC2.Label {
                        Layout.fillWidth: true
                        text: name
                    }
                    InstallApplicationButton {
223
                        application: model.application
224
225
226
227
                    }
                }
            }
        }
228
    }
229
}