summaryrefslogtreecommitdiffstats
path: root/examples/applicationmanager/intents/system-ui.qml
blob: 72ca51f306207b453b446b333654e95adcc1bdd8 (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
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

pragma ComponentBehavior: Bound

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

Item {
    id: root
    width: 900
    height: 600

    // Show application names and icons
    Column {
        id: launcher
        width: 100
        spacing: 20
        Repeater {
            model: ApplicationManager
            Column {
                id: delegate
                required property bool isRunning
                required property var icon
                required property var application
                required property string name
                Image {
                    source: delegate.icon
                    MouseArea {
                        anchors.fill: parent
                        onClicked: delegate.isRunning ? delegate.application.stop()
                                                      : delegate.application.start()
                    }
                }
                Text {
                    width: parent.width
                    font.pixelSize: 10
                    text: delegate.name
                    horizontalAlignment: Text.AlignHCenter
                }
            }
        }
    }

    // Show windows
    Grid {
        anchors {
            right: parent.right
            left: launcher.right
            top: parent.top
            bottom: parent.bottom
        }
        columns: 2

        IntentsUIPage {
            id: sysui_page
            width: parent.width / 2
            height: parent.height / 2
            title: "System UI"

            onRequest: (intentId, applicationId, parameters) => {
                let request = IntentClient.sendIntentRequest(intentId, applicationId, parameters)
                request.onReplyReceived.connect(function() {
                    sysui_page.setResult(request.requestId, request.succeeded,
                                         request.succeeded ? request.result : request.errorMessage)
                })
            }
            onBroadcast: (intentId, parameters) => {
                IntentClient.broadcastIntentRequest(intentId, parameters)
            }

            RotationAnimation on rotation {
                id: rotationAnimation
                running: false
                duration: 500; from: 0; to: 360
            }
            //! [IntentServerHandler]
            IntentServerHandler {
                intentIds: [ "rotate-window" ]
                names: { "en": "Rotate System UI" }
                visibility: IntentObject.Public

                onRequestReceived: (request) => {
                    rotationAnimation.start()
                    request.sendReply({ "wasRequestedBy": request.requestingApplicationId })
                }
            }
            //! [IntentServerHandler]
        }

        Repeater {
            model: WindowManager
            WindowItem {
                required property var model
                width: sysui_page.width
                height: sysui_page.height
                window: model.window
            }
        }
    }

    //! [Connection]
    Connections {
        target: IntentServer
        function onDisambiguationRequest(requestId, potentialIntents) {
            disambiguationDialog.add(requestId, potentialIntents)
        }
    }
    //! [Connection]

    Dialog {
        id: disambiguationDialog
        title: "Disambiguation"
        standardButtons: Dialog.Ok | Dialog.Cancel
        closePolicy: Popup.NoAutoClose
        modal: true

        parent: Overlay.overlay
        x: (parent.width - width) / 2
        y: (parent.height - height) / 2
        width: parent.width / 3 * 2
        height: parent.height / 3 * 2

        property var allRequests: []
        property var currentRequest: ({})

        function add(requestId, potentialIntents) {
            allRequests.push({ "requestId": requestId, "intents": potentialIntents})

            if (!visible)
                showNext()
        }
        function showNext() {
            currentRequest = {}
            if (allRequests.length !== 0) {
                currentRequest = allRequests.pop()
                intentRequest.text = currentRequest.requestId
                intent.text = currentRequest.intents[0].intentId
                handlingApplications.model = currentRequest.intents
                open()
            }
        }

        //! [OkCancel]
        onAccepted: {
            IntentServer.acknowledgeDisambiguationRequest(currentRequest.requestId,
                                                          currentRequest.intents[handlingApplications.currentIndex]);
            showNext()
        }
        onRejected: {
            IntentServer.rejectDisambiguationRequest(currentRequest.requestId)
            showNext()
        }
        //! [OkCancel]

        GridLayout {
            id: grid
            anchors.fill: parent
            anchors.margins: 5
            rowSpacing: 5
            columns: 2

            Label { text: "Request Id:" }
            Label { id: intentRequest; font.bold: true; Layout.fillWidth: true }
            Label { text: "Intent Id:" }
            Label { id: intent; font.bold: true; Layout.fillWidth: true }

            Label {
                text: "Select one of the potential handler applications:"
                Layout.columnSpan: 2
                Layout.fillWidth: true
                Layout.alignment: Qt.AlignCenter
            }

            ListView {
                id: handlingApplications

                Layout.columnSpan: 2
                Layout.fillWidth: true
                Layout.fillHeight: true

                delegate: ItemDelegate {
                    required property int index
                    required property var modelData
                    property ApplicationObject application: ApplicationManager.application(modelData.applicationId)
                    width: parent.width
                    text: modelData.name + " (" + modelData.applicationId + ")"
                    icon.source: modelData.icon
                    icon.color: "transparent"
                    highlighted: ListView.isCurrentItem
                    onClicked: { handlingApplications.currentIndex = index }
                }
                model: []
                clip: true
                ScrollIndicator.vertical: ScrollIndicator { }
            }
        }
    }
}