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