Debian Codegraph @

examples/serviceframework/dialer/dialer.qml

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the examples of the Qt Mobility Components.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50
51 import QtQuick 2.0
52 import QtServiceFramework 5.0
53 import "content"
54
55
56 //Layout of the mainPage
57 //---------------------------------------------- ____ mainPage
58 //| ------------------- ---------------------- | /
59 //| | dialerList | | dialScreen | |/
60 //| | | | | |
61 //| | | | | |
62 //| | | | | |
63 //| ------------------- | | |
64 //| ------------------- | | |
65 //| | serviceDetails | | | |
66 //| ------------------- | | |
67 //| | | |
68 //| | | |
69 //| | | |
70 //| | | |
71 //| ------------------- | | |
72 //| | status | | | |
73 //| ------------------- ---------------------- |
74 //----------------------------------------------
75
76 Rectangle {
77 id: mainPage
78 color: "white"
79
80 property QtObject dialerObject
81
82 width: 320
83 height: 460
84 y: 20
85
86
87 DialerList {
88 id: dialerList
89 height: 240
90 width: childrenRect.width-5
91 anchors.top: dialScreen.bottom
92 anchors.left: parent.left
93 anchors.topMargin: 5
94 anchors.leftMargin: 5
95 anchors.rightMargin: 5
96 radius: 5
97 color: "steelblue"
98 border.color: "black"
99 border.width: 3
100 gradient:
101 Gradient {
102 GradientStop {
103 position: 0.0
104 color: "lightsteelblue"
105 }
106
107 GradientStop {
108 position: 1.0
109 color: "steelblue"
110 }
111 }
112 onSignalSelected: { serviceSelected(); }
113 }
114
115 function serviceSelected()
116 {
117 dialerObject = dialerList.dialService.serviceObject
118 serviceDetails.text = "Selected dial service:" + "\n " +
119 dialerList.dialService.serviceDescriptor.serviceName +
120 " (" + dialerList.dialService.serviceDescriptor.majorVersion +
121 "." + dialerList.dialService.serviceDescriptor.minorVersion + ")";
122 }
123
124 Text {
125 id: serviceDetails
126 text: "Service:"
127 width: parent.width
128 anchors.topMargin: 5
129 anchors.leftMargin: 5
130 anchors.rightMargin: 5;
131 anchors.left: parent.left
132 anchors.top: dialerList.bottom
133 wrapMode: "WrapAtWordBoundaryOrAnywhere"
134 }
135
136 Text {
137 id: status
138 width: parent.width - dialScreen.width
139 height: dialScreen.height
140 anchors.top: parent.top
141 anchors.left: dialScreen.right
142 anchors.leftMargin: 5
143 wrapMode: "Wrap"
144 }
145
146 Timer {
147 id: clearStatusTimer
148 interval: 2000
149 running: false
150 repeat: false
151 onTriggered: {
152 status.text = ""
153 }
154 }
155
156 //! [0]
157 DialScreen {
158 id: dialScreen
159 property bool activeCall : false
160 property variant currentDialer: 0;
161 anchors.topMargin: 5
162 anchors.leftMargin: 5
163 anchors.rightMargin: 5
164 anchors.left: parent.left
165 anchors.top: parent.top
166 onDial: {
167 if (activeCall === false) {
168 if (dialerObject != 0) {
169 dialerList.allowselction = false;
170 var o = dialerObject;
171 status.text = "Dialing " + numberToDial + "...";
172 dialScreen.currentDialer = o;
173 o.dialNumber(numberToDial);
174 activeCall = true;
175
176 }
177 }
178 }
179 onHangup: {
180 if (activeCall === true) {
181 if (dialScreen.currentDialer != 0) {
182 dialScreen.currentDialer.hangup();
183 }
184 dialerList.allowselction = true;
185 status.text = "Hang up";
186 }
187 }
188 }
189 //! [0]
190
191 ServiceLoader {
192 id: defaultService
193 interfaceName: "com.nokia.qt.examples.Dialer"
194
195 onStatusChanged: {
196 if (status == Service.Ready) {
197 //Note that an alias property would also work
198 dialerObject = defaultService.serviceObject;
199 serviceDetails.text = "Default dial service:" + "\n " +
200 defaultService.serviceName +
201 " (" + defaultService.majorVersion +
202 "." + defaultService.minorVersion + ")";
203 } else if (status == Service.Error) {
204 console.log("Got IPC error from SFW " + errorString);
205 dialScreen.activeCall = false;
206 status.text = "";
207 serviceDetails.text = errorString;
208 dialerList.allowselction = true;
209 }
210 }
211 }
212
213 // ! [1]
214 Connections {
215 target: dialerObject
216 ignoreUnknownSignals: true
217
218 onStateChanged: {
219 if (dialScreen.currentDialer.state == 1) {
220 status.text += "\nRinging";
221 }
222 else if (dialScreen.currentDialer.state == 2) {
223 status.text += "\nConnected";
224 }
225 else if (dialScreen.currentDialer.state == 0) {
226 status.text += "\nConnection terminated";
227 dialScreen.activeCall = false;
228 clearStatusTimer.running = true;
229 }
230 else if (dialScreen.currentDialer.state == 3) {
231 status.text += "\nPhone already engaged";
232 }
233 }
234 }
235 //! [1]
236 }
237