hfdialer has been made a singleton and will only start one
[profile/ivi/hfdialer.git] / qml / main.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 import com.hfdialer 1.0
11
12 import 'javascripts/framework.js' as Support
13
14 Item
15 {
16     id: main
17
18     width: 1024; height: 600
19
20     Dialer { id: adapter }
21
22     Component.onCompleted: {
23       console.log("######## Completed loading component, initializing...");
24
25       adapter.incomingCall.connect(function()
26       {
27         var call = adapter.currentCall;
28
29         console.log("*** QML *** :: INCOMING CALL:" + call);
30         console.log("*** QML *** ::   MSISDN: " + call.msisdn);
31         console.log("*** QML *** ::    START: " + call.startedAt);
32         console.log("");
33
34         dialpage.activeCall = call       
35
36       });
37
38       if(adapter.currentCall)
39       {
40         dialpage.activeCall = call
41       }
42
43     }
44
45     function showErrorMessage(mesg) {
46         mesgDialog.mesg = mesg;
47         mesgDialog.state = 'shown';
48     }
49
50     function dial(msisdn) {
51         if(msisdn.trim().length == 0)
52         {
53             console.log("*** QML *** :: You can't dial without a number!");
54             showErrorMessage(qsTr("No number specified!"));
55             return false;
56         }
57
58         if (!adapter.modemOnline)
59         {
60           console.log("*** QML *** :: modem is not available or powered down");
61           showErrorMessage(qsTr("modem is not available or powered down!"));
62           return false;
63         }
64
65         console.log("*** QML *** :: Attempting to dial MSISDN: " + msisdn);
66
67         dialpage.activeCall = {
68           state: 'dialing',
69           msisdn: msisdn
70         };
71
72         adapter.dial(msisdn);
73
74         return true;
75     }
76
77     function dialMailbox() {
78         if(adapter.mailbox) {
79             console.log("*** QML *** :: Attempting to call mailbox number: " + adapter.mailbox);
80             main.dial(adapter.mailbox);
81         } else {
82             console.log("*** QML *** :: No mailbox number defined!");
83             showErrorMessage(qsTr("No mailbox number defined."));
84         }
85     }
86
87     function dialSpeedDial(index) {
88         if(adapter.speedDial(index))
89         {
90             console.log("*** QML *** :: Calling speed dial " + index + ": " + adapter.speedDial(index));
91             main.dial(adapter.speedDial(index));
92         } else {
93             console.log("*** QML *** :: No speed dial number defined for: " + index);
94             showErrorMessage(qsTr("No speed dial for " + (index + 1)));
95         }
96     }
97
98     DialPage
99     {
100         id: dialpage
101         anchors.fill: parent
102     }
103
104     MessageDialog {
105         id: mesgDialog
106         state: 'hidden'
107     }
108 }
109