summaryrefslogtreecommitdiffstats
path: root/examples/applicationmanager/package-installation/system-ui/main.qml
blob: 03e60ff0ee3da13573077f1317fa3b4df99df442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtApplicationManager.SystemUI


ApplicationWindow {
    id: root
    width: 800
    height: 600
    font.pixelSize: 20

    PackageServerInterface {
        id: packageServerInterface

        property string defaultUrl: ApplicationManager.systemProperties.packageServer.url
        url: serverUrl.text
        projectId: ApplicationManager.systemProperties.packageServer.projectId
        architecture: PackageManager.architecture

        onPackagesChanged: {
            packageModel.clear()
            for (let i = 0; i < packages.length; i++) {
                let p = packages[i]
                packageModel.append({
                    id:           p.id,
                    architecture: p.architecture,
                    name:         p.names["en"],
                    description:  p.descriptions["en"],
                    version:      p.version,
                    categories:   p.categories,
                    iconUrl:      p.iconUrl
                })
            }

            stack.currentIndex = packageModel.count ? 1 : 0
        }

        Component.onCompleted: {
            console.info("\n\n", "You can start an appman-package-server instance like this:",
                         "\n\n", "  ", ApplicationManager.systemProperties.serverBinary, "--dd",
                         ApplicationManager.systemProperties.serverBaseDir, "\n\n")
        }
    }

    AcknowledgeDialog {
        id: acknowledgeDialog
    }

    component TaskButton: Button {
        width: 150
        height: 100
        display: AbstractButton.TextUnderIcon
        icon.width: 40
        icon.height: 40
        font.pixelSize: 20
    }

    // Show application names and icons
    Column {
        width: 200
        Repeater {
            model: ApplicationManager
            Column {
                id: delegate

                required property bool isRunning
                required property var icon
                required property var application
                required property string name

                TaskButton {
                    icon.source: delegate.icon
                    icon.color: "transparent"
                    text: delegate.name
                    checkable: true
                    checked: delegate.isRunning

                    onToggled: checked ? delegate.application.start()
                                       : delegate.application.stop()
                }
            }
        }
    }

    // Show windows
    Column {
        anchors.right: parent.right
        Repeater {
            model: WindowManager
            WindowItem {
                required property var model
                width: 600
                height: 200
                window: model.window
            }
        }
    }

    TaskButton {
        anchors.bottom: parent.bottom

        icon.source: "package"
        text: "Packages"

        onClicked: { packagesDialog.open() }
    }

    Dialog {
        id: packagesDialog
        title: "Package-Server"
        standardButtons: Dialog.Close
        modal: true
        focus: true
        parent: Overlay.overlay
        anchors.centerIn: parent
        width: parent.width * 3 / 4
        height: parent.height * 7 / 8
        padding: 20

        ColumnLayout {
            anchors.fill: parent
            RowLayout {
                Label { text: "Acknowledge" }
                ComboBox {
                    Layout.fillWidth: true
                    model: [
                        { value: AcknowledgeDialog.Always,           text: 'Always' },
                        { value: AcknowledgeDialog.Never,            text: 'Never' },
                        { value: AcknowledgeDialog.CapabilitiesOnly, text: 'Only for Capabilities' }
                    ]
                    textRole: "text"
                    valueRole: "value"
                    onActivated: acknowledgeDialog.mode = currentValue
                    Component.onCompleted: currentIndex = indexOfValue(acknowledgeDialog.mode)
                }
            }
            RowLayout {
                Label { text: "Server" }
                TextField {
                    id: serverUrl
                    Layout.fillWidth: true
                    text: packageServerInterface.defaultUrl
                }
                ToolButton {
                    icon.source: "reload"
                    onClicked: packageServerInterface.reload()
                }
            }
            StackLayout {
                id: stack

                Label {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                    font.bold: true
                    wrapMode: Text.Wrap
                    text: packageServerInterface.statusText
                }

                ScrollView {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    contentWidth: availableWidth

                    ListView {
                        clip: true
                        boundsBehavior: Flickable.StopAtBounds

                        model: ListModel {
                            id: packageModel
                            dynamicRoles: true
                        }

                        delegate: ItemDelegate {
                            required property string id
                            required property var name
                            required property string iconUrl

                            property bool isInstalled: false

                            Component.onCompleted: {
                                isInstalled = (PackageManager.indexOfPackage(id) >= 0)
                            }

                            Connections {
                                target: PackageManager
                                function onPackageAdded(pkgId) {
                                    if (pkgId === id)
                                        isInstalled = true
                                }
                                function onPackageAboutToBeRemoved(pkgId) {
                                    if (pkgId === id)
                                        isInstalled = false
                                }
                            }

                            Image {
                                source: isInstalled ? "uninstall" : "install"
                                width: height
                                height: parent.height / 2
                                anchors.verticalCenter: parent.verticalCenter
                                anchors.right: parent.right
                                anchors.rightMargin: parent.height / 8
                            }

                            width: ListView.view.width
                            text: "<b>" + name + "</b> (" + id + ")"
                                  + "<br>&&nbsp;&&nbsp;&&nbsp;<i>[" + (isInstalled ? "currently installed"
                                                                                   : "not installed") + "]</i>"
                            icon.source: packageServerInterface.url + "/" + iconUrl
                            icon.color: "transparent"

                            onClicked: {
                                if (isInstalled)
                                    packageServerInterface.remove(id)
                                else
                                    packageServerInterface.install(id)
                            }
                        }
                    }
                }
            }
        }
    }
}