SourcesPage.qml 10 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
                function mergeActions(moreActions) {
                    var actions = [makeDefault, addSource]
                    for(var i in moreActions) {
95
                        actions.push(kirigamiAction.createObject(actionBar, {action: moreActions[i]}))
96
97
98
99
                    }
                    return actions;
                }
                actions: mergeActions(backendItem.backend.actions)
100
            }
101
102
        }

Abhijeet  sharma's avatar
Abhijeet sharma committed
103
104
105
106
        Component {
            id: sourceProceedDialog
            Kirigami.OverlaySheet {
                id: sheet
107
108
                parent: applicationWindow().overlay

Abhijeet  sharma's avatar
Abhijeet sharma committed
109
110
111
112
113
                showCloseButton: false
                property QtObject  sourcesBackend
                property alias title: heading.text
                property alias description: desc.text
                property bool acted: false
114
115
116
117
118
119

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

Abhijeet  sharma's avatar
Abhijeet sharma committed
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
156
157
                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()
                }
            }
        }

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

            Keys.onReturnPressed: clicked()
            actions: [
                Kirigami.Action {
                    iconName: "go-up"
169
                    tooltip: i18n("Increase priority")
170
171
172
                    enabled: sourcesBackend.firstSourceId !== sourceId
                    visible: sourcesBackend.canMoveSources
                    onTriggered: {
173
174
                        var ret = sourcesBackend.moveSource(sourceId, -1)
                        if (!ret)
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
175
                            window.showPassiveNotification(i18n("Failed to increase '%1' preference", model.display))
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
176
                    }
177
178
179
                },
                Kirigami.Action {
                    iconName: "go-down"
180
                    tooltip: i18n("Decrease priority")
181
182
183
184
185
                    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
186
                            window.showPassiveNotification(i18n("Failed to decrease '%1' preference", model.display))
187
188
189
190
                    }
                },
                Kirigami.Action {
                    iconName: "edit-delete"
191
                    tooltip: i18n("Remove repository")
192
193
194
195
                    visible: sourcesBackend.supportsAdding
                    onTriggered: {
                        var backend = sourcesBackend
                        if (!backend.removeSource(sourceId)) {
196
                            console.warn("Failed to remove the source", model.display)
197
198
                        }
                    }
199
200
                },
                Kirigami.Action {
201
                    iconName: LayoutMirroring.enabled ? "go-next-symbolic-rtl" : "go-next-symbolic"
202
203
204
205
206
                    tooltip: i18n("Show contents")
                    visible: sourcesBackend.canFilterSources
                    onTriggered: {
                        Navigation.openApplicationListSource(sourceId)
                    }
207
208
209
210
211
212
213
214
215
                }
            ]

            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
216
                    checked: modelChecked !== Qt.Unchecked
217
218
                    enabled: modelChecked !== undefined
                    onClicked: {
219
                        sourcesView.model.setData(idx, checkState, Qt.CheckStateRole)
Laurent Montel's avatar
Laurent Montel committed
220
                        checked = Qt.binding(function() { return modelChecked !== Qt.Unchecked; })
221
                    }
222
                }
223
                Label {
224
                    text: model.display + (model.toolTip ? " - <i>" + model.toolTip + "</i>" : "")
225
                    elide: Text.ElideRight
226
                    textFormat: Text.StyledText
227
228
                    Layout.fillWidth: true
                }
229
            }
230
        }
231
232
233
234
235
236
237
238

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