sample/app: Allow to start applications
[apps/onscreenapp.git] / sample / app / main.qml
1 import QtQuick 2.7
2 import QtQuick.Window 2.2
3 import QtQuick.Controls 2.0
4 import QtQuick.Layouts 1.0
5 import AGL.Demo.Controls 1.0
6
7 ApplicationWindow {
8     id: root
9     visible: true
10     width: Screen.width
11     height: Screen.height
12
13     property string onsId: qsTr("onscreenapp")
14     property string onsTitle: qsTr("One Button title")
15     property string onsType: "critical"
16     property string onsContents: qsTr("An operating system is a program that manages a computer’s hardware.")
17     property string onsButton1: qsTr("Yes")
18     property string onsButton2: qsTr("")
19     property string onsButton3: qsTr("")
20     property string postmsg: qsTr("")
21     property string btndata: qsTr("")
22     property int pid: -1
23     property bool onscreen_role_set: false
24
25     Label {
26         id: title
27         width: parent.width
28         height: 40
29         text: "OnScreen Test App"
30         font.pixelSize: 40
31         font.bold: true
32         color: "white"
33     }
34
35     ColumnLayout {
36         spacing: 20
37         anchors.top: title.bottom
38         anchors.topMargin: 40
39         anchors.horizontalCenter: title.horizontalCenter
40
41         // show received reply information area
42         Flickable {
43              id: flickable
44              width: 800
45              height: 320
46              Layout.alignment: Qt.AlignCenter
47              flickableDirection: Flickable.VerticalFlick
48              boundsBehavior: Flickable.StopAtBounds
49
50              TextArea.flickable: TextArea {
51                  id: output
52                  text: "show received reply information area\n...\n...\n...\n...\n"
53                  font.pixelSize: 24
54                  wrapMode: TextArea.Wrap
55                  color: '#00ADDC'
56              }
57
58              ScrollBar.vertical: ScrollBar { }
59          }
60
61         // select onscreen type area
62         GroupBox {
63             label: Label {
64                 text: qsTr("Please select send OnScreen Message")
65                 font.pixelSize: 32
66                 font.bold: true
67                 color: "white"
68             }
69
70             width: 800
71             height: 100
72             Layout.alignment: Qt.AlignLeft
73
74             RowLayout {
75                 anchors.fill: parent
76                 RadioButton {
77                     text: qsTr("One Button")
78                     font.pixelSize: 20
79                     checked: true
80                     onClicked: {
81                         selectOneButton();
82                     }
83                 }
84                 RadioButton {
85                     text: qsTr("Two Buttons")
86                     font.pixelSize: 20
87                     onClicked: {
88                         selectTwoButtons();
89                     }
90                 }
91                 RadioButton {
92                     text: qsTr("Three Buttons")
93                     font.pixelSize: 20
94                     onClicked: {
95                         selectThreeButtons();
96                     }
97                 }
98                 RadioButton {
99                     text: qsTr("No Button")
100                     font.pixelSize: 20
101                     onClicked: {
102                         selectNoButton();
103                     }
104                 }
105             }
106         }
107
108         // edit post message area
109         GroupBox {
110             label: Label {
111                 text: qsTr("Post Infomations")
112                 font.pixelSize: 32
113                 font.bold: true
114                 color: "white"
115             }
116             width: 800
117             height: 400
118             Layout.alignment: Qt.AlignLeft
119             Layout.maximumWidth: 800
120             Layout.maximumHeight: 400
121
122             ColumnLayout {
123                 spacing:  20
124                 RowLayout {
125                     spacing: 20
126                     Label {
127                         id: ons_title
128                         anchors.left: parent.left
129                         anchors.leftMargin: 30
130                         text: qsTr("ons_title:")
131                         font.pixelSize: 20
132                         font.italic: true
133                         color: '#00ADDC'
134                     }
135
136                     Label {
137                         id: ons_title_data
138                         text: onsTitle
139                         font.pixelSize: 20
140                         font.italic: true
141                         anchors.left: ons_title.right
142                         anchors.leftMargin: 20
143                         color: '#00ADDC'
144                         Layout.maximumWidth: 600
145                         Layout.maximumHeight: 40
146                         maximumLineCount: 1
147                         wrapMode: Text.Wrap
148                         elide: Text.ElideRight
149                         horizontalAlignment: Label.AlignHCenter
150                         verticalAlignment: Label.AlignVCenter
151                     }
152                 }
153                 RowLayout {
154                     spacing: 20
155                     Label {
156                         id: ons_type
157                         anchors.left: parent.left
158                         anchors.leftMargin: 30
159                         text: qsTr("type:")
160                         font.pixelSize: 20
161                         font.italic: true
162                         color: '#00ADDC'
163                     }
164
165                     Label {
166                         id: ons_type_data
167                         text: onsType
168                         font.pixelSize: 20
169                         font.italic: true
170                         anchors.left: ons_type.right
171                         anchors.leftMargin: 20
172                         color: '#00ADDC'
173                     }
174                 }
175                 RowLayout {
176                     spacing: 20
177                     Label {
178                         id: ons_contents
179                         anchors.left: parent.left
180                         anchors.leftMargin: 30
181                         text: qsTr("contents:")
182                         font.pixelSize: 20
183                         font.italic: true
184                         color: '#00ADDC'
185                     }
186                     Label {
187                         id: ons_contents_data
188                         text: onsContents
189                         font.pixelSize: 20
190                         font.italic: true
191                         anchors.left: ons_contents.right
192                         anchors.leftMargin: 20
193                         color: '#00ADDC'
194                         Layout.maximumWidth: 600
195                         Layout.maximumHeight: 200
196                         maximumLineCount: 4
197                         wrapMode: Text.Wrap
198                         elide: Text.ElideRight
199                         horizontalAlignment: Label.AlignLeft
200                         verticalAlignment: Label.AlignVCenter
201                     }
202                 }
203                 RowLayout {
204                     spacing: 20
205                     Label {
206                         id: btn1
207                         anchors.left: parent.left
208                         anchors.leftMargin: 30
209                         text: qsTr("Button1")
210                         font.pixelSize: 20
211                         font.italic: true
212                         color: '#00ADDC'
213                     }
214
215                     Label {
216                         id: btn1_data
217                         text: onsButton1
218                         font.pixelSize: 20
219                         font.italic: true
220                         anchors.left: btn1.right
221                         anchors.leftMargin: 20
222                         color: '#00ADDC'
223                     }
224                 }
225                 RowLayout {
226                     spacing: 20
227                     Label {
228                         id: btn2
229                         anchors.left: parent.left
230                         anchors.leftMargin: 30
231                         text: qsTr("Button2")
232                         font.pixelSize: 20
233                         font.italic: true
234                         color: '#00ADDC'
235                     }
236                     Label {
237                         id: btn2_data
238                         text: onsButton2
239                         font.pixelSize: 20
240                         font.italic: true
241                         anchors.left: btn2.right
242                         anchors.leftMargin: 20
243                         color: '#00ADDC'
244                     }
245                 }
246                 RowLayout {
247                     spacing: 20
248                     Label {
249                         id: btn3
250                         anchors.left: parent.left
251                         anchors.leftMargin: 30
252                         text: qsTr("Button3")
253                         font.pixelSize: 20
254                         font.italic: true
255                         color: '#00ADDC'
256                     }
257                     Label {
258                         id: btn3_data
259                         text: onsButton3
260                         font.pixelSize: 20
261                         font.italic: true
262                         anchors.left: btn3.right
263                         anchors.leftMargin: 20
264                         color: '#00ADDC'
265                     }
266                 }
267             }
268         }
269
270         // post button
271         Button {
272             id: poster
273             text: "Post"
274             Layout.alignment: Qt.AlignCenter
275             onClicked: {
276                 postMessage();
277             }
278         }
279     }
280
281     function selectOneButton() {
282         console.log("select one button!")
283         onsTitle = qsTr("One Button title")
284         onsType = qsTr("critical")
285         onsContents = qsTr("An operating system is a program that manages a computer’s hardware.")
286         onsButton1 = qsTr("Yes")
287         onsButton2 = qsTr("")
288         onsButton3 = qsTr("")
289     }
290
291     function selectTwoButtons() {
292         console.log("select two buttons!")
293         onsTitle = qsTr("Two Buttons title")
294         onsType = qsTr("exclamation")
295         onsContents = qsTr("Beforewe can explore the details of computer system operation, we need to know something about system structure. We thus discuss the basic functions of system startup, I/O, and storage early in this chapter. We also describe the basic computer architecture that makes it possible to write a functional operating system.")
296         onsButton1 = qsTr("Yes")
297         onsButton2 = qsTr("No")
298         onsButton3 = qsTr("")
299     }
300
301     function selectThreeButtons() {
302         console.log("select three buttons!")
303         onsTitle = qsTr("Three Buttons title")
304         onsType = qsTr("information")
305         onsContents = qsTr("We can also view a computer system as consisting of hardware, software,and data. The operating system provides the means for proper use of these resources in the operation of the computer system.")
306         onsButton1 = qsTr("Yes")
307         onsButton2 = qsTr("Abort")
308         onsButton3 = qsTr("No")
309     }
310
311     function selectNoButton() {
312         console.log("select no button!")
313         onsTitle = qsTr("No Button title,very long title beyond screen wide which will show ellipsis at the end")
314         onsType = qsTr("question")
315         onsContents = qsTr("Recently, many varieties of mobile computers, such as smartphones and tablets, have come into fashion. Most mobile computers are standalone units for individual users. Quite often, they are connected to networks through cellular or other wireless technologies. Increasingly, these mobile devices are replacing desktop and laptop computers for people who are primarily interested in using computers for e-mail and web browsing. The user interface for mobile computers generally features a touch screen, where the user interacts with the system by pressing and swiping fingers across the screen rather than using a physical keyboard and mouse.")
316         onsButton1 = qsTr("")
317         onsButton2 = qsTr("")
318         onsButton3 = qsTr("")
319     }
320
321     function postMessage() {
322         console.log("poster pressed")
323         btndata = ""
324         postmsg = "{\"title\": \"" + onsTitle + "\"," + "\"type\": \"" + onsType + "\"," + "\"contents\": \"" + onsContents + "\"";
325         if (onsButton1 != "") {
326             btndata = "\"" + onsButton1 + "\"";
327         }
328         if (onsButton2 != "") {
329             if (btndata != "")
330                 btndata += ",";
331             btndata += "\"" + onsButton2 + "\"";
332         }
333         if (onsButton3 != "") {
334             if (btndata != "")
335                 btndata += ",";
336             btndata += "\"" + onsButton3 + "\"";
337         }
338
339         if(btndata != "")
340             postmsg += ",\"buttons\":[" + btndata + "]}"
341         else
342             postmsg += "}"
343
344         if (!onscreen_role_set) {
345                 console.log("onscreen_role_set is not set")
346                 eventHandler.set_window_popup(onsId, 0, 218)
347                 console.log("setting for popup for " + onsId)
348                 onscreen_role_set = true
349         }
350
351         // if the application is not already started, start it
352         if (pid === -1) {
353                 // if the application is not started, then the first time
354                 // we start we also display it using the default policy engine
355                 pid = eventHandler.start(onsId, postmsg)
356                 console.log("calling eventHandler.start for " + onsId + " with pid " + pid)
357         } else {
358                 // we just need to display it
359                 console.log("calling eventHandler.showWindow for " + onsId)
360                 eventHandler.showWindow(onsId, postmsg)
361         }
362     }
363
364     function qmlOnReplyShowWindow(text) {
365         console.log("onstestapp received:",text);
366         output.text = text;
367     }
368 }