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