|
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 Qt::TextElideMode elide) |
|
141 { |
|
142 QString text = QString::fromUtf16 (cliText.Ptr (), cliText.Length ()); |
|
143 PHONE_DEBUG2("PhoneBubbleWrapper::setCli, cli:", text); |
|
144 m_bubbleManager.setCli (bubble, text, elide); |
|
145 } |
|
146 |
|
147 void PhoneBubbleWrapper::setSecondaryCli (int bubble, const TDesC &cliText, |
|
148 Qt::TextElideMode elide) |
|
149 { |
|
150 QString text = QString::fromUtf16 (cliText.Ptr (), cliText.Length ()); |
|
151 PHONE_DEBUG2("PhoneBubbleWrapper::setSecondaryCli, SecondaryCli:", text); |
|
152 m_bubbleManager.setSecondaryCli (bubble, text, elide); |
|
153 } |
|
154 |
|
155 void PhoneBubbleWrapper::setCallType (int bubble, int callType) |
|
156 { |
|
157 BubbleManagerIF::PhoneCallFlags callflag = BubbleManagerIF::Normal; |
|
158 |
|
159 switch (callType) { |
|
160 case EPECallTypeCSVoice: |
|
161 callflag = BubbleManagerIF::Normal; |
|
162 break; |
|
163 case EPECallTypeVideo: |
|
164 callflag = BubbleManagerIF::Video; |
|
165 break; |
|
166 case EPECallTypeVoIP: |
|
167 callflag = BubbleManagerIF::VoIPCall; |
|
168 break; |
|
169 default: |
|
170 break; |
|
171 } |
|
172 |
|
173 m_bubbleManager.setCallFlag (bubble, callflag, true); |
|
174 } |
|
175 |
|
176 int PhoneBubbleWrapper::bubbleId (int callId) |
|
177 { |
|
178 return m_bubbles.value (callId, -1); |
|
179 } |
|
180 |
|
181 void PhoneBubbleWrapper::setDivert (int bubble, bool enabled) |
|
182 { |
|
183 if (enabled) { |
|
184 BubbleManagerIF::PhoneCallFlags divertedFlag = BubbleManagerIF::Diverted; |
|
185 m_bubbleManager.setCallFlag (bubble, divertedFlag, true); |
|
186 } |
|
187 } |
|
188 |
|
189 void PhoneBubbleWrapper::setCiphering(int bubble, bool indicatorAllowed, bool enabled) |
|
190 { |
|
191 if (indicatorAllowed && !enabled) { |
|
192 m_bubbleManager.setCallFlag (bubble, BubbleManagerIF::NoCiphering, true); |
|
193 } else { |
|
194 m_bubbleManager.setCallFlag (bubble, BubbleManagerIF::NoCiphering, false); |
|
195 } |
|
196 } |
|
197 |
|
198 int PhoneBubbleWrapper::activeCallCount() |
|
199 { |
|
200 int count(0); |
|
201 QMap<int, int> callStateList = callStates(); |
|
202 |
|
203 for (int i=0; i<callStateList.size(); ++i) { |
|
204 if ( callStateList.values().at(i) == EPEStateConnected || |
|
205 callStateList.values().at(i) == EPEStateConnectedConference || |
|
206 callStateList.values().at(i) == EPEStateDisconnecting || |
|
207 callStateList.values().at(i) == EPEStateHeld || |
|
208 callStateList.values().at(i) == EPEStateHeldConference ) { |
|
209 count++; |
|
210 } |
|
211 } |
|
212 |
|
213 return count; |
|
214 } |
|
215 |
|
216 QMap<int, int> PhoneBubbleWrapper::callStates() const |
|
217 { |
|
218 QMap<int, int> ret; |
|
219 |
|
220 for (int i=0; i<m_callStates.size(); ++i) { |
|
221 if ( false == m_conferenceList.contains(m_callStates.keys().at(i)) |
|
222 && m_bubbles.keys().contains(m_callStates.keys().at(i)) ) { |
|
223 ret.insert(m_callStates.keys().at(i), |
|
224 m_callStates.value(m_callStates.keys().at(i))); |
|
225 } |
|
226 } |
|
227 |
|
228 return ret; |
|
229 } |
|
230 |
|
231 QMap<int, int> PhoneBubbleWrapper::bubbles() const |
|
232 { |
|
233 QMap<int, int> ret; |
|
234 |
|
235 for (int i=0; i<m_bubbles.size(); ++i) { |
|
236 if ( false == m_conferenceList.contains(m_bubbles.keys().at(i)) ) { |
|
237 ret.insert(m_bubbles.keys().at(i), m_bubbles.value(m_bubbles.keys().at(i))); |
|
238 } |
|
239 } |
|
240 |
|
241 return ret; |
|
242 } |
|
243 |
|
244 int PhoneBubbleWrapper::createConferenceBubble( |
|
245 int callId, |
|
246 int callState, |
|
247 const TDesC &labelText, |
|
248 const TDesC &cliText) |
|
249 { |
|
250 int callId1; |
|
251 int callId2; |
|
252 int bubble = -1; |
|
253 if (getCallIdsForConference(callId1, callId2)) { |
|
254 m_bubbleManager.startChanges(); |
|
255 bubble = m_bubbleManager.createConference( |
|
256 bubbleId(callId1), |
|
257 bubbleId(callId2) ); |
|
258 |
|
259 setConferenceCallId(callId1); |
|
260 setConferenceCallId(callId2); |
|
261 |
|
262 m_bubbles.insert(callId,bubble); |
|
263 setState(callId, bubble, callState ); |
|
264 setLabel(bubble, labelText); |
|
265 setCli (bubble, cliText, Qt::ElideRight); |
|
266 |
|
267 //Set conference bubble expanded if no other |
|
268 //bubbles (like waiting bubble). |
|
269 m_bubbleManager.setExpandedConferenceCallHeader( |
|
270 (1==bubbles().size())); |
|
271 |
|
272 m_bubbleManager.endChanges(); |
|
273 } |
|
274 |
|
275 return bubble; |
|
276 } |
|
277 |
|
278 void PhoneBubbleWrapper::setConferenceCallId(int callId) |
|
279 { |
|
280 if ( false == m_conferenceList.contains(callId) ) { |
|
281 m_conferenceList.append(callId); |
|
282 } |
|
283 } |
|
284 |
|
285 void PhoneBubbleWrapper::removeConferenceCallId(int callId) |
|
286 { |
|
287 if ( m_conferenceList.contains(callId) ) { |
|
288 m_conferenceList.removeOne(callId); |
|
289 } |
|
290 } |
|
291 |
|
292 bool PhoneBubbleWrapper::conferenceCallId(int callId) const |
|
293 { |
|
294 return m_conferenceList.contains(callId); |
|
295 } |
|
296 |
|
297 void PhoneBubbleWrapper::removeCallFromConference(int callId) |
|
298 { |
|
299 if (m_conferenceList.contains(callId)) { |
|
300 m_bubbleManager.startChanges(); |
|
301 if(1<m_conferenceList.size()) { |
|
302 m_bubbleManager.removeRowFromConference(m_bubbles.value(callId)); |
|
303 m_conferenceList.removeOne(callId); |
|
304 } |
|
305 else { |
|
306 m_bubbleManager.removeConference(); |
|
307 |
|
308 if (m_bubbles.contains(KConferenceCallId)) { |
|
309 m_bubbles.remove(KConferenceCallId); |
|
310 } |
|
311 m_conferenceList.clear(); |
|
312 } |
|
313 |
|
314 m_bubbleManager.endChanges(); |
|
315 } |
|
316 } |
|
317 |
|
318 QList<int> PhoneBubbleWrapper::conferenceCallList() const |
|
319 { |
|
320 return m_conferenceList; |
|
321 } |
|
322 |
|
323 void PhoneBubbleWrapper::removeConferenceBubble() |
|
324 { |
|
325 if (0 < m_conferenceList.size()) { |
|
326 m_bubbleManager.removeConference(); |
|
327 m_bubbleManager.setExpandedConferenceCallHeader(false); |
|
328 |
|
329 if (m_bubbles.contains(KConferenceCallId)) { |
|
330 m_bubbles.remove(KConferenceCallId); |
|
331 } |
|
332 m_conferenceList.clear(); |
|
333 } |
|
334 } |
|
335 |
|
336 int PhoneBubbleWrapper::callIdByBubbleId(int bubbleId) |
|
337 { |
|
338 return m_bubbles.key(bubbleId, -1); |
|
339 } |
|
340 |
|
341 void PhoneBubbleWrapper::addToConferenceBubble() |
|
342 { |
|
343 if (m_conferenceList.size()) { |
|
344 int callId = callIdForConference(); |
|
345 if (-1 != callId && |
|
346 false == m_conferenceList.contains(callId)) { |
|
347 m_bubbleManager.startChanges(); |
|
348 setConferenceCallId(callId); |
|
349 m_bubbleManager.addRowToConference(bubbleId(callId)); |
|
350 m_bubbleManager.endChanges(); |
|
351 } |
|
352 } |
|
353 } |
|
354 |
|
355 int PhoneBubbleWrapper::callIdForConference() |
|
356 { |
|
357 int callId = -1; |
|
358 QMap<int, int> bubblelist = bubbles(); |
|
359 for (int i=0; i<bubblelist.size() && callId == -1; ++i) { |
|
360 if (KConferenceCallId != bubblelist.keys().at(i)) { |
|
361 if ( bubblelist.size() > 2 ) { |
|
362 if (EPEStateRinging != |
|
363 m_callStates.value(bubblelist.keys().at(i))) { |
|
364 callId = bubblelist.keys().at(i); |
|
365 } |
|
366 } else { |
|
367 callId = bubblelist.keys().at(i); |
|
368 } |
|
369 } |
|
370 } |
|
371 |
|
372 return callId; |
|
373 } |
|
374 |
|
375 bool PhoneBubbleWrapper::getCallIdsForConference(int &first, int &second) |
|
376 { |
|
377 first = -1; |
|
378 second = -1; |
|
379 |
|
380 if (2==m_bubbles.values().size()) { |
|
381 first = m_bubbles.keys().first(); |
|
382 second = m_bubbles.keys().at(1); |
|
383 } else if (2<=m_bubbles.values().size()) { |
|
384 for (int i=0;i<m_callStates.values().size();++i) { |
|
385 if ( m_callStates.values().at(i) != EPEStateRinging ) { |
|
386 if (first==-1) { |
|
387 first = m_callStates.keys().at(i); |
|
388 } else { |
|
389 second = m_callStates.keys().at(i); |
|
390 break; |
|
391 } |
|
392 } |
|
393 } // For |
|
394 } |
|
395 |
|
396 return (first!=-1 && second!=-1); |
|
397 } |
|
398 |
|
399 void PhoneBubbleWrapper::setServiceId(int callId, int serviceId) |
|
400 { |
|
401 m_services[callId] = serviceId; |
|
402 } |
|
403 |
|
404 int PhoneBubbleWrapper::serviceIdByCallId(int callId) const |
|
405 { |
|
406 return m_services.value(callId, -1); |
|
407 } |
|
408 |
|
409 QMap<int, int> PhoneBubbleWrapper::serviceIds() const |
|
410 { |
|
411 return m_services; |
|
412 } |
|
413 |