ba0d0c6fad7899f6d1db38f8150cfb269cd9bae4
[profile/ivi/hfdialer.git] / qml / DialPage.qml
1 /*
2  * Copyright 2012 Intel Corporation.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  */
8
9 import Qt 4.7
10
11 import Tizen.Bluetooth 0.0 
12
13 Item
14 {
15     id: root
16     width: parent.width; height: parent.height
17
18     property alias activeCall: activeCallView.call
19     property alias callState: activeCallView.state
20
21     Keys.onEscapePressed: {
22         console.log("Escape Pressed");
23         Qt.quit()
24     }
25
26     onCallStateChanged: {
27         if (activeCallView.state != 'disconnected')
28             dialPage.state = 'activeCall'
29         else
30             dialPage.state = 'noCall'
31     }
32
33     Connections {
34         target: adapter
35         onModemOnlineChanged: {
36             console.log("BJONES POWERED HAS CHANGED!")
37             if (!adapter.modemOnline)
38             {
39                 console.log("BJONES MODEM NOW POWERED DOWN TRYING TO RECONNECT")
40                 adapter.modemOnline = true
41             }
42          }
43     }
44
45     Image
46     {
47         id: dialPage
48         anchors.fill: parent
49         source: "/usr/share/hfdialer/images/ivi-v1_ivi-background.jpg"
50         state: 'noCall'
51
52         DialNumberEntry
53         {
54             id: numberEntry
55             anchors {
56                 top: parent.top; //bottom: numPad.top
57                 left: parent.left; margins: 15 //right: parent.right
58                 //margins: 10
59             }
60             width: parent.width * 0.60
61             height: parent.height / 4.5
62         }
63
64         DialNumPad
65         {
66             id: numPad
67             width: numberEntry.width
68             anchors {top: numberEntry.bottom; left: parent.left; bottom: parent.bottom; margins: 15}
69             entry: numberEntry
70         }
71         states{
72             State {
73                 name: 'activeCall'
74                 PropertyChanges {target: numPad; visible: false}
75                 PropertyChanges {target: numberEntry; visible: false}
76                 PropertyChanges {target: modemList; visible: false}
77                 PropertyChanges {target: vertDivider; visible: false}
78             }
79             State {
80                 name: 'noCall'
81                 PropertyChanges {target: numPad; visible: true}
82                 PropertyChanges {target: numberEntry; visible: true}
83                 PropertyChanges {target: modemList; visible: true}
84                 PropertyChanges {target: vertDivider; visible: true}
85             }
86
87
88         }
89
90         CallItemView
91         {
92             id: activeCallView
93         }
94
95         Rectangle {
96
97             id: vertDivider
98             anchors {left: numberEntry.right; margins: 8}
99             width: 4
100             height: parent.height
101             color: "#262626"
102
103         }
104
105         Rectangle {
106             id: modemList
107             anchors {left: vertDivider.right; right: parent.right; top: parent.top; bottom: parent.bottom}
108             color: "#51504F"
109
110             Text {
111                 id: yourDevicesTxt
112                 text: "Your Devices"
113                 font.pixelSize: 42
114                 color: "white"
115                 anchors {top: parent.top; right: parent.right; left: parent.left; bottom: horizDivider1.top; leftMargin: 15}
116
117             }
118
119             Rectangle {
120                 id: horizDivider1
121                 anchors {left: parent.left; right: parent.right; topMargin: 8; bottomMargin: 8;}
122                 y: 62
123                 height: 3
124                 color: "#B3BF3C"
125             }
126
127             Text {
128                 id: moreDevicesTxt
129                 text: "More Devices"
130                 font.pixelSize: 42
131                 color: "white"
132                 anchors {right: parent.right; left: parent.left; bottom: horizDivider2.top; leftMargin: 15}
133                 height: yourDevicesTxt.height
134             }
135
136             Rectangle {
137                 id: horizDivider2
138                 anchors {left: parent.left; right: parent.right; topMargin: 8; bottomMargin: 8;}
139                 y: parent.height / 2
140                 height: 3
141                 color: "#B3BF3C"
142             }
143
144             Component.onCompleted: {
145                 nearbyDevicesModel.discover(true);
146                 console.log("Devices qml has been created, checking for BT: " + btDevicesModel.adapterPresent)
147
148             }
149
150             Component.onDestruction: {
151                 nearbyDevicesModel.discover(false);
152             }
153
154             BluetoothDevicesModel {
155                 id: btDevicesModel
156                 property bool successFullPair: false
157                 onDevicePaired: {
158
159                 }
160             }
161
162             NearbyDevicesModel {
163                 id: nearbyDevicesModel
164
165                 property bool discovering: false
166
167                 Component.onCompleted: {
168
169                 }
170
171                 onRequestConfirmation: {
172                     console.log("onRequestConfirm called")
173                 }
174
175                 onRequestPasskey: {
176                     console.log("onRequestPasskey called")
177
178                 }
179
180                 onRequestPidCode: {
181                     console.log("onRequestPidCode called")
182                 }
183
184                 onAdapterPropertiesChanged: {
185
186                     if(name == "Discovering") {
187                         discovering = value;
188                     }
189
190                 }
191
192                 onNearbyDeviceFound: {
193                     //console.log("new device: " + nearbyDevicesModel.alias(index))
194                 }
195
196             }
197
198             Flickable{
199                 id: activeFlickable
200
201                 anchors {top: horizDivider1.bottom; bottom: moreDevicesTxt.top; left: parent.left; right: parent.right}
202                 clip: true
203                 contentWidth: parent.width
204                 contentHeight: parent.height
205                 flickableDirection: Flickable.VerticalFlick
206
207                 Column {
208                     id: deviceList
209                     width: parent.width
210                     spacing: 2
211                     Repeater {
212                         model: btDevicesModel
213
214                         Component.onCompleted: {
215                             if (!adapter.modemOnline)
216                             {
217                                 console.log("BJONES previously created modem is not powered! Try and re-connect")
218                                 adapter.modemOnline = true
219                             }
220                         }
221
222                         delegate: DeviceDelegateActive {
223
224                             deviceName: model.name
225                             address: model.address
226                             dbuspath: model.path
227                             uuids: model.profiles
228                             property BluetoothDevice device: btDevicesModel.device(dbuspath)
229
230                             Connections {
231                                 target: btDevicesModel
232                                 onDevicePaired: {
233                                     console.log("new paired device address:" + device.address + "==" + model.address)
234                                     if(device.address === model.address){
235                                         device.trusted = true
236                                     }
237                                 }
238
239                                 onConnectedChanged: {
240                                     console.log("device CONNECTED, attempting to hook up audio")
241                                     // device.connectAudio()
242                                     // device.connectAudioSrc()
243                                     // device.connectInput()
244                                 }
245                             }
246
247                             onClose: {
248                                 console.log("unparing ...");
249                                 device.unpair();
250                             }
251                         }
252                     }
253                 }
254             }
255
256             Flickable{
257                 id: modelFlickable
258                 anchors {top: horizDivider2.bottom; bottom: parent.bottom; left: parent.left; right: parent.right}
259                 clip: true
260                 contentWidth: parent.width
261                 contentHeight: parent.height
262                 flickableDirection: Flickable.VerticalFlick
263
264                 Column {
265                     id: nearbyDevicesList
266                     width: parent.width
267                     height: parent.height / 2
268
269                     Repeater {
270                         id: modelRepeater
271                         model: nearbyDevicesModel
272
273                         onCountChanged: {
274                             modelFlickable.contentHeight = (count * 80)
275                         }
276
277                         delegate: DeviceDelegate {
278                             id: availableBluetoothItem
279                             width: nearbyDevicesList.width
280                             deviceName: name
281                             icon: model.icon
282                             alias: model.alias
283                             anchors {margins: 8}
284
285                             onClicked: {
286                                 console.log("BUTTON CLICKED bubbled up")
287                                 nearbyDevicesModel.discover(false)
288                                 nearbyDevicesModel.pair(model.address)
289                             }
290
291
292                             Connections {
293                                 target: nearbyDevicesModel
294                                 onRequestConfirmation: {
295                                     console.log("spawning request confirm dialog, device = " + device + " deviceName = " + deviceName)
296                                     if(device != deviceName) return;
297
298                                     dialogLoader.type = "confirmation"
299                                     dialogLoader.device = device
300                                     dialogLoader.code = code
301                                     dialogLoader.sourceComponent = requestConfirmDialogComponent
302
303                                 }
304
305                                 onRequestPasskey: {
306                                     console.log("spawning requestPasskeyDialog")
307                                     if(device != deviceName) return;
308
309                                     dialogLoader.type = "passkey"
310                                     dialogLoader.device = device
311                                     dialogLoader.sourceComponent = requestPasskeyDialogComponent
312
313                                 }
314
315                                 onRequestPidCode: {
316                                     console.log("spawning requestPidCodeDialog")
317                                     if(device != deviceName) return;
318
319
320                                     dialogLoader.type = "pidcode"
321                                     dialogLoader.device = device
322                                     dialogLoader.legacyPairing = model.legacyPairing
323                                     dialogLoader.sourceComponent = requestPidCodeDialogComponent
324
325                                     console.log(device + " model legacyPairing: " + model.legacyPairing)
326                                 }
327                             }
328                         }
329                     }
330                 }
331             }
332
333
334             Loader {
335                 id: dialogLoader
336                 anchors.fill: parent
337                 property string type: "NULL"
338                 property string device: ""
339                 property string code: ""
340                 property bool legacyPairing: false
341
342                 onLoaded: {
343                     console.log("LOADER LOADED! type = " + type)
344                     if (type === "confirmation" )
345                     {
346                         item.deviceName = device
347                         item.key = code
348                     }
349                     else if (type === "passkey" )
350                     {
351                         item.deviceName = device
352                     }
353                     else if (type === "pidcode" )
354                     {
355                         item.deviceName = device
356                         item.legacyPairing = legacyPairing
357                     }
358                 }
359             }
360
361             Component {
362                 id: requestPasskeyDialogComponent
363                 RequestpasskeyDialog {
364                     id: requestPasskeyDialog
365
366                     onReplyRequestPasskey: {
367                         dialogLoader.sourceComponent = undefined
368                         nearbyDevicesModel.replyPasskey(reply)
369                     }
370                 }
371             }
372
373             Component {
374                 id: requestPidCodeDialogComponent
375                 RequestPidCodeDialog {
376                     id: requestPidCodeDialog
377                     onReplyRequestPidCode: {
378                         dialogLoader.sourceComponent = undefined
379                         nearbyDevicesModel.replyRequestPidCode(reply)
380                     }
381                     onCancelRequest: {
382                         dialogLoader.sourceComponent = undefined
383                     }
384                 }
385             }
386
387             Component {
388                 id: requestConfirmDialogComponent
389                 RequestConfirmDialog {
390                     id: requestConfirmDialog
391                     onReplyRequestConfirmation: {
392                         dialogLoader.sourceComponent = undefined
393                         nearbyDevicesModel.replyRequestConfirmation(reply)
394                     }
395                 }
396             }
397         }
398     }
399 }
400