SourcesPage.qml 9.92 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.2 as Kirigami
7
import "navigation.js" as Navigation
8

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

15
16
17
18
    contextualActions: [
        KirigamiActionBridge { action: app.action("help_about_app") },
        KirigamiActionBridge { action: app.action("help_report_bug") }
    ]
19

20
    mainItem: ListView {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
21
        id: sourcesView
22
        model: QSortFilterProxyModel {
23
            filterRegExp: new RegExp(page.search, 'i')
24
            dynamicSortFilter: false //We don't want to sort, as sorting can have some semantics on some backends
25
            sourceModel: SourcesModel
26
27
        }
        currentIndex: -1
28

29
30
31
32
33
34
35
36
        section.property: "sourceName"
        section.delegate: Kirigami.AbstractListItem {
            id: backendItem
            hoverEnabled: false
            supportsMouseEvents: false
            readonly property QtObject backend: SourcesModel.sourcesBackendByName(section)
            readonly property QtObject resourcesBackend: backend.resourcesBackend
            readonly property bool isDefault: ResourcesModel.currentApplicationBackend == resourcesBackend
37

38
            RowLayout {
39
                Layout.fillHeight: true
40
41
42
                Connections {
                    target: backendItem.backend
                    onPassiveMessage: window.showPassiveNotification(message)
Abhijeet  sharma's avatar
Abhijeet sharma committed
43
44
45
46
                    onProceedRequest: {
                        var dialog = sourceProceedDialog.createObject(window, {sourcesBackend: sourcesBackend, title: title, description: description})
                        dialog.open()
                    }
47
                }
48

49
50
                Kirigami.Heading {
                    Layout.fillWidth: true
51
                    Layout.leftMargin: Kirigami.Units.smallSpacing
52
                    Layout.alignment: Qt.AlignVCenter
53
                    text: backendItem.isDefault ? i18n("%1 (Default)", resourcesBackend.displayName) : resourcesBackend.displayName
54
                    level: 3
55
56
                }
                Button {
57
                    Layout.alignment: Qt.AlignVCenter
58
59
60
61
62
63
64
65
66
                    icon.name: "preferences-other"

                    visible: resourcesBackend && resourcesBackend.hasApplications
                    Component {
                        id: dialogComponent
                        AddSourceDialog {
                            source: backendItem.backend
                            onVisibleChanged: if (!visible) {
                                destroy()
67
                            }
68
                        }
69
                    }
70

71
72
73
74
75
76
77
78
79
                    id: this
                    onClicked: settingsMenu.popup(this)
                    Menu {
                        id: settingsMenu
                        MenuItem {
                            enabled: !backendItem.isDefault
                            text: i18n("Make default")
                            onTriggered: ResourcesModel.currentApplicationBackend = backendItem.backend.resourcesBackend
                        }
80

81
82
83
                        MenuItem {
                            text: i18n("Add Source...")
                            visible: backendItem.backend && backendItem.backend.supportsAdding
84

85
86
87
                            onTriggered: {
                                var addSourceDialog = dialogComponent.createObject(null, {displayName: backendItem.backend.resourcesBackend.displayName })
                                addSourceDialog.open()
88
                            }
89
                        }
90

91
92
93
                        MenuSeparator {
                            visible: backendActionsInst.count>0
                        }
94

95
96
97
98
99
100
101
102
                        Instantiator {
                            id: backendActionsInst
                            model: ActionsModel {
                                actions: backendItem.backend ? backendItem.backend.actions : undefined
                            }
                            delegate: MenuItem {
                                action: ActionBridge {
                                    action: modelData
103
                                }
104
                            }
105
106
107
108
109
110
                            onObjectAdded: {
                                settingsMenu.insertItem(index, object)
                            }
                            onObjectRemoved: {
                                object.destroy()
                            }
111
112
113
                        }
                    }
                }
114
115
116
            }
        }

Abhijeet  sharma's avatar
Abhijeet sharma committed
117
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
156
157
158
159
160
161
162
163
164
165
166
        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
                ColumnLayout {
                    Kirigami.Heading {
                        id: heading
                    }
                    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()
                }
            }
        }

167
168
169
170
171
172
173
174
175
176
177
178
179
180
        delegate: Kirigami.SwipeListItem {
            Layout.fillWidth: true
            enabled: display.length>0
            highlighted: ListView.isCurrentItem
            onClicked: Navigation.openApplicationListSource(sourceId)

            Keys.onReturnPressed: clicked()
            actions: [
                Kirigami.Action {
                    iconName: "go-up"
                    enabled: sourcesBackend.firstSourceId !== sourceId
                    visible: sourcesBackend.canMoveSources
                    onTriggered: {
                            var ret = sourcesBackend.moveSource(sourceId, -1)
181
                            if (!ret)
182
                                window.showPassiveNotification(i18n("Failed to increase '%1' preference", display))
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
183
                    }
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
                },
                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))
                    }
                },
                Kirigami.Action {
                    iconName: "edit-delete"
                    tooltip: i18n("Delete the origin")
                    visible: sourcesBackend.supportsAdding
                    onTriggered: {
                        var backend = sourcesBackend
                        if (!backend.removeSource(sourceId)) {
                            window.showPassiveNotification(i18n("Failed to remove the source '%1'", display))
203
204
                        }
                    }
205
206
207
208
209
210
211
212
213
214
215
216
217
                }
            ]

            RowLayout {
                CheckBox {
                    id: enabledBox

                    readonly property variant idx: sourcesView.model.index(index, 0)
                    readonly property variant modelChecked: sourcesView.model.data(idx, Qt.CheckStateRole)
                    checked: modelChecked != Qt.Unchecked
                    enabled: modelChecked !== undefined
                    onClicked: {
                        sourcesView.model.setData(idx, checkedState, Qt.CheckStateRole)
218
                    }
219
                }
220
221
222
223
224
                Label {
                    text: display + (toolTip ? " - <i>" + toolTip + "</i>" : "")
                    elide: Text.ElideRight
                    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
245
            Repeater {
                id: back
                model: ResourcesProxyModel {
                    extending: "org.kde.discover.desktop"
                }
246
247
                delegate: Kirigami.BasicListItem {
                    supportsMouseEvents: false
248
                    visible: !model.isInstalled
249
250
                    label: name
                    icon: model.icon
251
                    InstallApplicationButton {
252
                        application: model.application
253
254
255
256
                    }
                }
            }
        }
257
    }
258
}