1 /*! |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Bubble Wrapper. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbaction.h> |
|
19 #include <pevirtualengine.h> |
|
20 |
|
21 #include "bubblemanagerif.h" |
|
22 #include "phonebubblewrapper.h" |
|
23 #include "phoneconstants.h" |
|
24 #include "qtphonelog.h" |
|
25 |
|
26 PhoneBubbleWrapper::PhoneBubbleWrapper (BubbleManagerIF& bubble, QObject *parent) : |
|
27 QObject (parent), m_bubbleManager (bubble) |
|
28 { |
|
29 } |
|
30 |
|
31 PhoneBubbleWrapper::~PhoneBubbleWrapper () |
|
32 { |
|
33 |
|
34 } |
|
35 |
|
36 void PhoneBubbleWrapper::updateCallState (int callId, int newState) |
|
37 { |
|
38 // TODO: +1 callId because value 0 causes problems |
|
39 // when using QMap. Bug in S60 Qt? |
|
40 m_callStates [callId] = newState; |
|
41 } |
|
42 |
|
43 int PhoneBubbleWrapper::callId (int state) |
|
44 { |
|
45 // Returns call id or -1 if not found |
|
46 // TODO: callId -1 because we +1 callId when inserted |
|
47 // This is because callId 0 causes problems in QMap. |
|
48 int callId = m_callStates.key (state, -1); |
|
49 return callId; |
|
50 } |
|
51 |
|
52 int PhoneBubbleWrapper::createCallHeader (int callId) |
|
53 { |
|
54 int bubble; |
|
55 |
|
56 if (!m_bubbles.contains (callId)) { |
|
57 bubble = m_bubbleManager.createCallHeader (); |
|
58 m_bubbles.insert (callId, bubble); |
|
59 } |
|
60 else { |
|
61 bubble = m_bubbles [callId]; |
|
62 } |
|
63 |
|
64 return bubble; |
|
65 } |
|
66 |
|
67 void PhoneBubbleWrapper::removeCallHeader (int callId) |
|
68 { |
|
69 if (m_bubbles.contains (callId)) { |
|
70 m_bubbleManager.removeCallHeader (m_bubbles [callId]); |
|
71 m_bubbles.remove (callId); |
|
72 } |
|
73 } |
|
74 |
|
75 BubbleManagerIF& PhoneBubbleWrapper::bubbleManager () |
|
76 { |
|
77 return m_bubbleManager; |
|
78 } |
|
79 |
|
80 void PhoneBubbleWrapper::setState (int callId, int bubble, int callState) |
|
81 { |
|
82 BubbleManagerIF::PhoneCallState state = BubbleManagerIF::None; |
|
83 |
|
84 switch (callState) { |
|
85 case EPEStateIdle: |
|
86 state = BubbleManagerIF::Disconnected; |
|
87 break; |
|
88 case EPEStateDialing: |
|
89 state = BubbleManagerIF::Outgoing; |
|
90 break; |
|
91 case EPEStateRinging: |
|
92 if ( m_bubbles.count() > 1 ) { |
|
93 state = BubbleManagerIF::Waiting; |
|
94 } |
|
95 else { |
|
96 state = BubbleManagerIF::Incoming; |
|
97 } |
|
98 break; |
|
99 case EPEStateConnecting: |
|
100 state = BubbleManagerIF::Alerting; |
|
101 break; |
|
102 case EPEStateConnected: |
|
103 state = BubbleManagerIF::Active; |
|
104 break; |
|
105 case EPEStateHeld: |
|
106 state = BubbleManagerIF::OnHold; |
|
107 break; |
|
108 case EPEStateDisconnecting: |
|
109 state = BubbleManagerIF::Disconnected; |
|
110 break; |
|
111 case EPEStateConferenceIdle: |
|
112 state = BubbleManagerIF::Disconnected; |
|
113 break; |
|
114 case EPEStateConnectedConference: |
|
115 state = BubbleManagerIF::Active; |
|
116 break; |
|
117 case EPEStateHeldConference: |
|
118 state = BubbleManagerIF::OnHold; |
|
119 break; |
|
120 case EPEStateUnknown: |
|
121 state = BubbleManagerIF::None; |
|
122 break; |
|
123 default: |
|
124 break; |
|
125 } |
|
126 |
|
127 updateCallState (callId, callState); |
|
128 m_bubbleManager.setState (bubble, state); |
|
129 |
|
130 } |
|
131 |
|
132 void PhoneBubbleWrapper::setLabel (int bubble, const TDesC &text) |
|
133 { |
|
134 QString labelText = QString::fromUtf16 (text.Ptr (), text.Length ()); |
|
135 PHONE_DEBUG2("PhoneBubbleWrapper::setLabel, label:", labelText); |
|
136 m_bubbleManager.setLabel (bubble, labelText, Qt::ElideRight); |
|
137 } |
|
138 |
|
139 void PhoneBubbleWrapper::setCli (int bubble, const TDesC &cliText) |
|
140 { |
|
141 QString text = QString::fromUtf16 (cliText.Ptr (), cliText.Length ()); |
|
142 PHONE_DEBUG2("PhoneBubbleWrapper::setCli, cli:", text); |
|
143 m_bubbleManager.setCli (bubble, text, Qt::ElideRight); |
|
144 } |
|
145 |
|
146 void PhoneBubbleWrapper::setSecondaryCli (int bubble, const TDesC &cliText) |
|
147 { |
|
148 QString text = QString::fromUtf16 (cliText.Ptr (), cliText.Length ()); |
|
149 PHONE_DEBUG2("PhoneBubbleWrapper::setSecondaryCli, SecondaryCli:", text); |
|
150 m_bubbleManager.setSecondaryCli (bubble, text); |
|
151 } |
|
152 |
|
153 void PhoneBubbleWrapper::setCallType (int bubble, int callType) |
|
154 { |
|
155 BubbleManagerIF::PhoneCallFlags callflag = BubbleManagerIF::Normal; |
|
156 |
|
157 switch (callType) { |
|
158 case EPECallTypeCSVoice: |
|
159 callflag = BubbleManagerIF::Normal; |
|
160 break; |
|
161 case EPECallTypeVideo: |
|
162 callflag = BubbleManagerIF::Video; |
|
163 break; |
|
164 case EPECallTypeVoIP: |
|
165 callflag = BubbleManagerIF::VoIPCall; |
|
166 break; |
|
167 default: |
|
168 break; |
|
169 } |
|
170 |
|
171 m_bubbleManager.setCallFlag (bubble, callflag, true); |
|
172 } |
|
173 |
|
174 int PhoneBubbleWrapper::bubbleId (int callId) |
|
175 { |
|
176 return m_bubbles.value (callId, -1); |
|
177 } |
|
178 |
|
179 void PhoneBubbleWrapper::setDivert (int bubble, bool enabled) |
|
180 { |
|
181 if (enabled) { |
|
182 BubbleManagerIF::PhoneCallFlags divertedFlag = BubbleManagerIF::Diverted; |
|
183 m_bubbleManager.setCallFlag (bubble, divertedFlag, true); |
|
184 } |
|
185 } |
|
186 |
|
187 void PhoneBubbleWrapper::setCiphering(int bubble, bool indicatorAllowed, bool enabled) |
|
188 { |
|
189 if (indicatorAllowed && !enabled) { |
|
190 m_bubbleManager.setCallFlag (bubble, BubbleManagerIF::NoCiphering, true); |
|
191 } else { |
|
192 m_bubbleManager.setCallFlag (bubble, BubbleManagerIF::NoCiphering, false); |
|
193 } |
|
194 } |
|
195 |
|
196 int PhoneBubbleWrapper::activeCallCount() |
|
197 { |
|
198 int count(0); |
|
199 QMap<int, int> callStateList = callStates(); |
|
200 |
|
201 for (int i=0; i<callStateList.size(); ++i) { |
|
202 if ( callStateList.values().at(i) == EPEStateConnected || |
|
203 callStateList.values().at(i) == EPEStateConnectedConference || |
|
204 callStateList.values().at(i) == EPEStateDisconnecting || |
|
205 callStateList.values().at(i) == EPEStateHeld || |
|
206 callStateList.values().at(i) == EPEStateHeldConference ) { |
|
207 count++; |
|
208 } |
|
209 } |
|
210 |
|
211 return count; |
|
212 } |
|
213 |
|
214 QMap<int, int> PhoneBubbleWrapper::callStates() const |
|
215 { |
|
216 QMap<int, int> ret; |
|
217 |
|
218 for (int i=0; i<m_callStates.size(); ++i) { |
|
219 if ( false == m_conferenceList.contains(m_callStates.keys().at(i)) |
|
220 && m_bubbles.keys().contains(m_callStates.keys().at(i)) ) { |
|
221 ret.insert(m_callStates.keys().at(i), |
|
222 m_callStates.value(m_callStates.keys().at(i))); |
|
223 } |
|
224 } |
|
225 |
|
226 return ret; |
|
227 } |
|
228 |
|
229 QMap<int, int> PhoneBubbleWrapper::bubbles() const |
|
230 { |
|
231 QMap<int, int> ret; |
|
232 |
|
233 for (int i=0; i<m_bubbles.size(); ++i) { |
|
234 if ( false == m_conferenceList.contains(m_bubbles.keys().at(i)) ) { |
|
235 ret.insert(m_bubbles.keys().at(i), m_bubbles.value(m_bubbles.keys().at(i))); |
|
236 } |
|
237 } |
|
238 |
|
239 return ret; |
|
240 } |
|
241 |
|
242 int PhoneBubbleWrapper::createConferenceBubble( |
|
243 int callId, |
|
244 int callState, |
|
245 const TDesC &labelText, |
|
246 const TDesC &cliText) |
|
247 { |
|
248 int callId1; |
|
249 int callId2; |
|
250 int bubble = -1; |
|
251 if (getCallIdsForConference(callId1, callId2)) { |
|
252 m_bubbleManager.startChanges(); |
|
253 bubble = m_bubbleManager.createConference( |
|
254 bubbleId(callId1), |
|
255 bubbleId(callId2) ); |
|
256 |
|
257 setConferenceCallId(callId1); |
|
258 setConferenceCallId(callId2); |
|
259 |
|
260 m_bubbles.insert(callId,bubble); |
|
261 setState(callId, bubble, callState ); |
|
262 setLabel(bubble, labelText); |
|
263 setCli (bubble, cliText); |
|
264 |
|
265 //Set conference bubble expanded if no other |
|
266 //bubbles (like waiting bubble). |
|
267 m_bubbleManager.setExpandedConferenceCallHeader( |
|
268 (1==bubbles().size())); |
|
269 |
|
270 m_bubbleManager.endChanges(); |
|
271 } |
|
272 |
|
273 return bubble; |
|
274 } |
|
275 |
|
276 void PhoneBubbleWrapper::setConferenceCallId(int callId) |
|
277 { |
|
278 if ( false == m_conferenceList.contains(callId) ) { |
|
279 m_conferenceList.append(callId); |
|
280 } |
|
281 } |
|
282 |
|
283 void PhoneBubbleWrapper::removeConferenceCallId(int callId) |
|
284 { |
|
285 if ( m_conferenceList.contains(callId) ) { |
|
286 m_conferenceList.removeOne(callId); |
|
287 } |
|
288 } |
|
289 |
|
290 bool PhoneBubbleWrapper::conferenceCallId(int callId) const |
|
291 { |
|
292 return m_conferenceList.contains(callId); |
|
293 } |
|
294 |
|
295 void PhoneBubbleWrapper::removeCallFromConference(int callId) |
|
296 { |
|
297 if (m_conferenceList.contains(callId)) { |
|
298 m_bubbleManager.startChanges(); |
|
299 if(1<m_conferenceList.size()) { |
|
300 m_bubbleManager.removeRowFromConference(m_bubbles.value(callId)); |
|
301 m_conferenceList.removeOne(callId); |
|
302 } |
|
303 else { |
|
304 m_bubbleManager.removeConference(); |
|
305 |
|
306 if (m_bubbles.contains(KConferenceCallId)) { |
|
307 m_bubbles.remove(KConferenceCallId); |
|
308 } |
|
309 m_conferenceList.clear(); |
|
310 } |
|
311 |
|
312 m_bubbleManager.endChanges(); |
|
313 } |
|
314 } |
|
315 |
|
316 QList<int> PhoneBubbleWrapper::conferenceCallList() const |
|
317 { |
|
318 return m_conferenceList; |
|
319 } |
|
320 |
|
321 void PhoneBubbleWrapper::removeConferenceBubble() |
|
322 { |
|
323 if (0 < m_conferenceList.size()) { |
|
324 m_bubbleManager.removeConference(); |
|
325 m_bubbleManager.setExpandedConferenceCallHeader(false); |
|
326 |
|
327 if (m_bubbles.contains(KConferenceCallId)) { |
|
328 m_bubbles.remove(KConferenceCallId); |
|
329 } |
|
330 m_conferenceList.clear(); |
|
331 } |
|
332 } |
|
333 |
|
334 int PhoneBubbleWrapper::callIdByBubbleId(int bubbleId) |
|
335 { |
|
336 return m_bubbles.key(bubbleId, -1); |
|
337 } |
|
338 |
|
339 void PhoneBubbleWrapper::addToConferenceBubble() |
|
340 { |
|
341 if (m_conferenceList.size()) { |
|
342 int callId = callIdForConference(); |
|
343 if (-1 != callId && |
|
344 false == m_conferenceList.contains(callId)) { |
|
345 m_bubbleManager.startChanges(); |
|
346 setConferenceCallId(callId); |
|
347 m_bubbleManager.addRowToConference(bubbleId(callId)); |
|
348 m_bubbleManager.endChanges(); |
|
349 } |
|
350 } |
|
351 } |
|
352 |
|
353 int PhoneBubbleWrapper::callIdForConference() |
|
354 { |
|
355 int callId = -1; |
|
356 QMap<int, int> bubblelist = bubbles(); |
|
357 for (int i=0; i<bubblelist.size() && callId == -1; ++i) { |
|
358 if (KConferenceCallId != bubblelist.keys().at(i)) { |
|
359 if ( bubblelist.size() > 2 ) { |
|
360 if (EPEStateRinging != |
|
361 m_callStates.value(bubblelist.keys().at(i))) { |
|
362 callId = bubblelist.keys().at(i); |
|
363 } |
|
364 } else { |
|
365 callId = bubblelist.keys().at(i); |
|
366 } |
|
367 } |
|
368 } |
|
369 |
|
370 return callId; |
|
371 } |
|
372 |
|
373 bool PhoneBubbleWrapper::getCallIdsForConference(int &first, int &second) |
|
374 { |
|
375 first = -1; |
|
376 second = -1; |
|
377 |
|
378 if (2==m_bubbles.values().size()) { |
|
379 first = m_bubbles.keys().first(); |
|
380 second = m_bubbles.keys().at(1); |
|
381 } else if (2<=m_bubbles.values().size()) { |
|
382 for (int i=0;i<m_callStates.values().size();++i) { |
|
383 if ( m_callStates.values().at(i) != EPEStateRinging ) { |
|
384 if (first==-1) { |
|
385 first = m_callStates.keys().at(i); |
|
386 } else { |
|
387 second = m_callStates.keys().at(i); |
|
388 break; |
|
389 } |
|
390 } |
|
391 } // For |
|
392 } |
|
393 |
|
394 return (first!=-1 && second!=-1); |
|
395 } |
|
396 |
|
397 void PhoneBubbleWrapper::setServiceId(int callId, int serviceId) |
|
398 { |
|
399 m_services[callId] = serviceId; |
|
400 } |
|
401 |
|
402 int PhoneBubbleWrapper::serviceIdByCallId(int callId) const |
|
403 { |
|
404 return m_services.value(callId, -1); |
|
405 } |
|
406 |
|
407 QMap<int, int> PhoneBubbleWrapper::serviceIds() const |
|
408 { |
|
409 return m_services; |
|
410 } |
|
411 |
|