summaryrefslogtreecommitdiffstats
path: root/examples/applicationmanager/intents/shared/IntentsUIPage.qml
blob: 22432b4cd3f50be321ebfbe5cdb86e34b0989e3b (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
// 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
import QtQuick.Controls
import QtQuick.Layouts
import QtApplicationManager

Rectangle {
    id: root
    property string flavor
    property string title: flavor

    function setResult(requestId, succeeded, result) {
        lblRequestId.text = requestId
        lblRequestStatus.text = succeeded ? "Result:" : "Error:"
        lblResult.text = JSON.stringify(result)
    }

    signal request(string intentId, string applicationId, var parameters)
    signal broadcast(string intentId, var parameters)

    color: "white"
    Rectangle {
        opacity: 0.5
        anchors.fill: parent
        radius: 5
        border.width: 1
        border.color: root.color
        gradient: Gradient {
            GradientStop { position: 0.0; color: root.flavor }
            GradientStop { position: 1.0; color: root.color }
        }
    }

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

        Label {
            text: root.title
            font.bold: true;
            horizontalAlignment: Text.AlignHCenter
            Layout.columnSpan: 2
            Layout.fillWidth: true
        }
        Label { text: "Intent:" }
        ComboBox {
            id: cbIntent
            model: [ "rotate-window", "scale-window", "blue-window-private", "broadcast/blink-window" ]
            property bool isBroadcast: currentText.startsWith("broadcast/")
            Layout.fillWidth: true
        }
        Label { text: "Application:" }
        ComboBox {
            id: cbApplication
            model: [ "<not specified>", "intents.red", "intents.green", "intents.blue", IntentClient.systemUiId ]
            enabled: !cbIntent.isBroadcast
            property bool needsDisambiguation: currentIndex === 0
            Layout.fillWidth: true
        }
        Button {
            id: btRequest
            text: cbIntent.isBroadcast ? "Broadcast" : "Request"
            Layout.columnSpan: 2
            Layout.fillWidth: true
            Layout.alignment: Qt.AlignCenter

            onClicked: {
                if (cbIntent.isBroadcast) {
                    root.broadcast(cbIntent.currentText, { "Broadcast": { "Parameters": { "Testing": 42 }}})
                } else {
                    let appId = cbApplication.needsDisambiguation ? "" : cbApplication.currentText
                    root.request(cbIntent.currentText, appId, { "Request": { "Parameters": { "Testing": 1 }}})
                }
            }
        }
        Label { text: "Request:" }
        Label { id: lblRequestId; Layout.fillWidth: true }
        Label { id: lblRequestStatus }
        Label { id: lblResult; Layout.fillWidth: true }
        Item { Layout.fillHeight: true }
    }
}