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

9
DiscoverPage {
10
    id: page
11
    clip: true
12
    title: i18n("Settings")
13
    property string search: ""
14

15
    contextualActions: feedbackLoader.item ? feedbackLoader.item.actions : []
16

17
    mainItem: ListView {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
18
        id: sourcesView
19
        model: SourcesModel
20
        Component.onCompleted: Qt.callLater(SourcesModel.showingNow)
21
        currentIndex: -1
22

23
        section.property: "sourceName"
24
        section.delegate: Kirigami.ListSectionHeader {
25
            id: backendItem
26

27
28
            readonly property QtObject backend: SourcesModel.sourcesBackendByName(section)
            readonly property QtObject resourcesBackend: backend.resourcesBackend
Laurent Montel's avatar
Laurent Montel committed
29
            readonly property bool isDefault: ResourcesModel.currentApplicationBackend === resourcesBackend
30

31
32
            width: sourcesView.width
            label: backendItem.isDefault ? i18n("%1 (Default)", resourcesBackend.displayName) : resourcesBackend.displayName
33

34
            readonly property var p0: Connections {
35
                target: backendItem.backend
36
37
38
39
                function onPassiveMessage(message) {
                    window.showPassiveNotification(message)
                }
                function onProceedRequest(title, description) {
40
41
42
43
                    var dialog = sourceProceedDialog.createObject(window, {sourcesBackend: backendItem.backend, title: title, description: description})
                    dialog.open()
                }
            }
44

45
46
47
48
49
50
51
52
53
            Kirigami.ActionToolBar {
                id: actionBar
                Layout.fillWidth: true
                alignment: Qt.AlignRight
                Kirigami.Action {
                    id: addSource
                    text: i18n("Add Source...")
                    icon.name: "list-add"
                    visible: backendItem.backend && backendItem.backend.supportsAdding
54

55
56
57
58
                    readonly property Component p0: Component {
                        id: dialogComponent
                        AddSourceDialog {
                            source: backendItem.backend
59
60
61

                            onSheetOpenChanged: if(!sheetOpen) {
                                destroy(1000)
62
                            }
63
                        }
64
                    }
65
66

                    onTriggered: {
67
                        var addSourceDialog = dialogComponent.createObject(window, {displayName: backendItem.backend.resourcesBackend.displayName })
68
69
                        addSourceDialog.open()
                    }
70
                }
71
72
73
                Kirigami.Action {
                    id: makeDefault
                    visible: resourcesBackend && resourcesBackend.hasApplications
74

75
76
77
78
                    enabled: !backendItem.isDefault
                    text: i18n("Make default")
                    icon.name: "favorite"
                    onTriggered: ResourcesModel.currentApplicationBackend = backendItem.backend.resourcesBackend
79
                }
80

81
82
83
84
85
86
                Component {
                    id: kirigamiAction
                    Kirigami.Action {
                        property QtObject action
                        text: action.text
                        tooltip: action.toolTip
87
                        visible: action.visible
88
89
90
                        onTriggered: action.trigger()
                    }
                }
91

92
93
94
95
96
97
98
99
                function mergeActions(moreActions) {
                    var actions = [makeDefault, addSource]
                    for(var i in moreActions) {
                        actions.push(kirigamiAction.createObject(null, {action: moreActions[i]}))
                    }
                    return actions;
                }
                actions: mergeActions(backendItem.backend.actions)
100
            }
101
102
        }

Abhijeet  sharma's avatar
Abhijeet sharma committed
103
104
105
106
107
108
109
110
111
        Component {
            id: sourceProceedDialog
            Kirigami.OverlaySheet {
                id: sheet
                showCloseButton: false
                property QtObject  sourcesBackend
                property alias title: heading.text
                property alias description: desc.text
                property bool acted: false
112
113
114
115
116
117

                header: Kirigami.Heading {
                    id: heading
                    wrapMode: Text.WordWrap
                }

Abhijeet  sharma's avatar
Abhijeet sharma committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
                ColumnLayout {
                    Label {
                        id: desc
                        Layout.fillWidth: true
                        textFormat: Text.StyledText
                        wrapMode: Text.WordWrap
                    }
                    RowLayout {
                        Layout.alignment: Qt.AlignRight
                        Button {
                            text: i18n("Proceed")
                            icon.name: "dialog-ok"
                            onClicked: {
                                sourcesBackend.proceed()
                                sheet.acted = true
                                sheet.close()
                            }
                        }
                        Button {
                            Layout.alignment: Qt.AlignRight
                            text: i18n("Cancel")
                            icon.name: "dialog-cancel"
                            onClicked: {
                                sourcesBackend.cancel()
                                sheet.acted = true
                                sheet.close()
                            }
                        }
                    }
                }
                onSheetOpenChanged: if(!sheetOpen) {
                    sheet.destroy(1000)
                    if (!sheet.acted)
                        sourcesBackend.cancel()
                }
            }
        }

156
        delegate: Kirigami.SwipeListItem {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
157
            enabled: model.display.length>0 && model.enabled
158
            highlighted: ListView.isCurrentItem
159
            supportsMouseEvents: false
160
161
            visible: model.display.indexOf(page.search)>=0
            height: visible ? implicitHeight : 0
162
163
164
165
166
167
168
169

            Keys.onReturnPressed: clicked()
            actions: [
                Kirigami.Action {
                    iconName: "go-up"
                    enabled: sourcesBackend.firstSourceId !== sourceId
                    visible: sourcesBackend.canMoveSources
                    onTriggered: {
170
171
                        var ret = sourcesBackend.moveSource(sourceId, -1)
                        if (!ret)
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
172
                            window.showPassiveNotification(i18n("Failed to increase '%1' preference", model.display))
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
173
                    }
174
175
176
177
178
179
180
181
                },
                Kirigami.Action {
                    iconName: "go-down"
                    enabled: sourcesBackend.lastSourceId !== sourceId
                    visible: sourcesBackend.canMoveSources
                    onTriggered: {
                        var ret = sourcesBackend.moveSource(sourceId, +1)
                        if (!ret)
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
182
                            window.showPassiveNotification(i18n("Failed to decrease '%1' preference", model.display))
183
184
185
186
187
188
189
190
191
                    }
                },
                Kirigami.Action {
                    iconName: "edit-delete"
                    tooltip: i18n("Delete the origin")
                    visible: sourcesBackend.supportsAdding
                    onTriggered: {
                        var backend = sourcesBackend
                        if (!backend.removeSource(sourceId)) {
192
                            console.warn("Failed to remove the source", model.display)
193
194
                        }
                    }
195
196
197
198
199
200
201
202
                },
                Kirigami.Action {
                    iconName: "view-filter"
                    tooltip: i18n("Show contents")
                    visible: sourcesBackend.canFilterSources
                    onTriggered: {
                        Navigation.openApplicationListSource(sourceId)
                    }
203
204
205
206
207
208
209
210
211
                }
            ]

            RowLayout {
                CheckBox {
                    id: enabledBox

                    readonly property variant idx: sourcesView.model.index(index, 0)
                    readonly property variant modelChecked: sourcesView.model.data(idx, Qt.CheckStateRole)
Laurent Montel's avatar
Laurent Montel committed
212
                    checked: modelChecked !== Qt.Unchecked
213
214
                    enabled: modelChecked !== undefined
                    onClicked: {
215
                        sourcesView.model.setData(idx, checkState, Qt.CheckStateRole)
Laurent Montel's avatar
Laurent Montel committed
216
                        checked = Qt.binding(function() { return modelChecked !== Qt.Unchecked; })
217
                    }
218
                }
219
                Label {
220
                    text: model.display + (model.toolTip ? " - <i>" + model.toolTip + "</i>" : "")
221
                    elide: Text.ElideRight
222
                    textFormat: Text.StyledText
223
224
                    Layout.fillWidth: true
                }
225
            }
226
        }
227
228
229
230
231
232
233
234

        footer: ColumnLayout {
            id: foot
            anchors {
                right: parent.right
                left: parent.left
                margins: Kirigami.Units.smallSpacing
            }
235
236
237
            Kirigami.Heading {
                Layout.fillWidth: true
                text: i18n("Missing Backends")
238
                visible: back.count>0
239
            }
240
            spacing: 0
241
242
243
244
            Repeater {
                id: back
                model: ResourcesProxyModel {
                    extending: "org.kde.discover.desktop"
245
                    filterMinimumState: false
246
                }
247
248
249
250
                delegate: Kirigami.BasicListItem {
                    supportsMouseEvents: false
                    label: name
                    icon: model.icon
251
                    InstallApplicationButton {
252
                        application: model.application
253
254
255
256
                    }
                }
            }
        }
257
    }
258
}