hfdialer has been made a singleton and will only start one
[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
37             //If the modem gets powered down for any reason, attempt to power it again to maintain connection
38             if (!adapter.modemOnline)
39             {
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                             
216                             //Once model is completed, check if the modem is powered. If not, power it
217                             if (!adapter.modemOnline)
218                             {
219                                 adapter.modemOnline = true
220                             }
221                         }
222
223                         delegate: DeviceDelegateActive {
224
225                             deviceName: model.name
226                             address: model.address
227                             dbuspath: model.path
228                             uuids: model.profiles
229                             property BluetoothDevice device: btDevicesModel.device(dbuspath)
230
231                             Connections {
232                                 target: btDevicesModel
233                                 onDevicePaired: {
234                                     console.log("new paired device address:" + device.address + "==" + model.address)
235                                     if(device.address === model.address){
236                                         device.trusted = true
237                                     }
238                                 }
239
240                                 onConnectedChanged: {
241                                 }
242                             }
243
244                             onClose: {
245                                 console.log("unparing ...");
246                                 device.unpair();
247                             }
248                         }
249                     }
250                 }
251             }
252
253             Flickable{
254                 id: modelFlickable
255                 anchors {top: horizDivider2.bottom; bottom: parent.bottom; left: parent.left; right: parent.right}
256                 clip: true
257                 contentWidth: parent.width
258                 contentHeight: parent.height
259                 flickableDirection: Flickable.VerticalFlick
260
261                 Column {
262                     id: nearbyDevicesList
263                     width: parent.width
264                     height: parent.height / 2
265
266                     Repeater {
267                         id: modelRepeater
268                         model: nearbyDevicesModel
269
270                         onCountChanged: {
271                             modelFlickable.contentHeight = (count * 80)
272                         }
273
274                         delegate: DeviceDelegate {
275                             id: availableBluetoothItem
276                             width: nearbyDevicesList.width
277                             deviceName: name
278                             icon: model.icon
279                             alias: model.alias
280                             anchors {margins: 8}
281
282                             onClicked: {
283                                 console.log("BUTTON CLICKED bubbled up")
284                                 nearbyDevicesModel.discover(false)
285                                 nearbyDevicesModel.pair(model.address)
286                             }
287
288
289                             Connections {
290                                 target: nearbyDevicesModel
291                                 onRequestConfirmation: {
292                                     console.log("spawning request confirm dialog, device = " + device + " deviceName = " + deviceName)
293                                     if(device != deviceName) return;
294
295                                     dialogLoader.type = "confirmation"
296                                     dialogLoader.device = device
297                                     dialogLoader.code = code
298                                     dialogLoader.sourceComponent = requestConfirmDialogComponent
299
300                                 }
301
302                                 onRequestPasskey: {
303                                     console.log("spawning requestPasskeyDialog")
304                                     if(device != deviceName) return;
305
306                                     dialogLoader.type = "passkey"
307                                     dialogLoader.device = device
308                                     dialogLoader.sourceComponent = requestPasskeyDialogComponent
309
310                                 }
311
312                                 onRequestPidCode: {
313                                     console.log("spawning requestPidCodeDialog")
314                                     if(device != deviceName) return;
315
316
317                                     dialogLoader.type = "pidcode"
318                                     dialogLoader.device = device
319                                     dialogLoader.legacyPairing = model.legacyPairing
320                                     dialogLoader.sourceComponent = requestPidCodeDialogComponent
321
322                                     console.log(device + " model legacyPairing: " + model.legacyPairing)
323                                 }
324                             }
325                         }
326                     }
327                 }
328             }
329
330
331             Loader {
332                 id: dialogLoader
333                 anchors.fill: parent
334                 property string type: "NULL"
335                 property string device: ""
336                 property string code: ""
337                 property bool legacyPairing: false
338
339                 onLoaded: {
340                     console.log("LOADER LOADED! type = " + type)
341                     if (type === "confirmation" )
342                     {
343                         item.deviceName = device
344                         item.key = code
345                     }
346                     else if (type === "passkey" )
347                     {
348                         item.deviceName = device
349                     }
350                     else if (type === "pidcode" )
351                     {
352                         item.deviceName = device
353                         item.legacyPairing = legacyPairing
354                     }
355                 }
356             }
357
358             Component {
359                 id: requestPasskeyDialogComponent
360                 RequestpasskeyDialog {
361                     id: requestPasskeyDialog
362
363                     onReplyRequestPasskey: {
364                         dialogLoader.sourceComponent = undefined
365                         nearbyDevicesModel.replyPasskey(reply)
366                     }
367                 }
368             }
369
370             Component {
371                 id: requestPidCodeDialogComponent
372                 RequestPidCodeDialog {
373                     id: requestPidCodeDialog
374                     onReplyRequestPidCode: {
375                         dialogLoader.sourceComponent = undefined
376                         nearbyDevicesModel.replyRequestPidCode(reply)
377                     }
378                     onCancelRequest: {
379                         dialogLoader.sourceComponent = undefined
380                     }
381                 }
382             }
383
384             Component {
385                 id: requestConfirmDialogComponent
386                 RequestConfirmDialog {
387                     id: requestConfirmDialog
388                     onReplyRequestConfirmation: {
389                         dialogLoader.sourceComponent = undefined
390                         nearbyDevicesModel.replyRequestConfirmation(reply)
391                     }
392                 }
393             }
394         }
395     }
396 }
397