summaryrefslogtreecommitdiff
path: root/examples/applicationmanager/intents/system-ui.qml
blob: 31e5a5cb515f493866c3e5a8eb6965e816570ff5 (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
// 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

import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.4
import QtApplicationManager.SystemUI 2.0
import QtApplicationManager 2.0
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 {
                Image {
                    source: model.icon
                    MouseArea {
                        anchors.fill: parent
                        onClicked: model.isRunning ? application.stop() : application.start()
                    }
                }
                Text {
                    width: parent.width
                    font.pixelSize: 10
                    text: model.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) => {
                var request = IntentClient.sendIntentRequest(intentId, applicationId, parameters)
                request.onReplyReceived.connect(function() {
                    sysui_page.setResult(request.requestId, request.succeeded,
                                         request.succeeded ? request.result : request.errorMessage)
                })
            }
            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 {
                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 {
                    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 { }
            }
        }
    }
}