|
1 /* |
|
2 * Copyright (c) 2008 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: This class handles branded presence icons for phonebook contact |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <MVPbkContactLink.h> |
|
21 #include <bamdesca.h> |
|
22 #include <badesca.h> |
|
23 |
|
24 #include "mpresencetrafficlightsobs.h" |
|
25 |
|
26 #include "presencetrafficlights.h" |
|
27 #include "cmsonecontactstatus.h" |
|
28 #include "bpas.h" |
|
29 #include "bpasinfo.h" |
|
30 #include "bpasobserver.h" |
|
31 #include "bpaspresenceinfo.h" |
|
32 #include "bpasserviceinfo.h" |
|
33 #include "bpasiconinfo.h" |
|
34 |
|
35 #include "cmsoneservicestatus.h" |
|
36 |
|
37 _LIT(KColon, ":"); |
|
38 |
|
39 const TInt KTrafficLightLimit = 2; |
|
40 |
|
41 |
|
42 // ---------------------------------------------------------- |
|
43 // CCmsOneContactStatus::NewL |
|
44 // |
|
45 // ---------------------------------------------------------- |
|
46 // |
|
47 CCmsOneContactStatus* CCmsOneContactStatus::NewL( MPresenceIconNotifier& aCallback, |
|
48 MVPbkContactLink* aContact, |
|
49 HBufC8* aDefaultTrafficLightBrandId, |
|
50 HBufC8* aDefaultOnlineElementId, |
|
51 HBufC8* aDefaultOfflineElementId, |
|
52 TInt aId ) |
|
53 { |
|
54 CCmsOneContactStatus* self = new CCmsOneContactStatus( |
|
55 aCallback, aDefaultTrafficLightBrandId, aDefaultOnlineElementId, aDefaultOfflineElementId, aId ); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL( aContact ); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ---------------------------------------------------------- |
|
63 // CCmsOneContactStatus::New |
|
64 // |
|
65 // ---------------------------------------------------------- |
|
66 // |
|
67 void CCmsOneContactStatus::ConstructL( MVPbkContactLink* aContact ) |
|
68 { |
|
69 #ifdef _DEBUG |
|
70 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::ConstructL this=%d" ), (TInt)this ); |
|
71 #endif |
|
72 iBrandedPresence = CBPAS::NewL(); |
|
73 iBrandedPresence->SetObserver( this ); |
|
74 iContactLink = aContact->CloneLC(); |
|
75 CleanupStack::Pop(); // CloneLC |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------- |
|
79 // CCmsOneContactStatus::CCmsOneContactStatus |
|
80 // |
|
81 // ---------------------------------------------------------- |
|
82 // |
|
83 CCmsOneContactStatus::CCmsOneContactStatus( MPresenceIconNotifier& aCallback, |
|
84 HBufC8* aDefaultTrafficLightBrandId, |
|
85 HBufC8* aDefaultOnlineElementId, |
|
86 HBufC8* aDefaultOfflineElementId, |
|
87 TInt aId ) |
|
88 : iCallback( aCallback ), iId(aId) |
|
89 { |
|
90 iDefaultTrafficLightBrandId = aDefaultTrafficLightBrandId; |
|
91 iDefaultOnlineElementId = aDefaultOnlineElementId; |
|
92 iDefaultOfflineElementId = aDefaultOfflineElementId; |
|
93 iAvailableServices = 0; |
|
94 iOnlineServices = 0; |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------- |
|
98 // CCmsOneContactStatus::~CCmsOneContactStatus |
|
99 // |
|
100 // ---------------------------------------------------------- |
|
101 // |
|
102 CCmsOneContactStatus::~CCmsOneContactStatus() |
|
103 { |
|
104 #ifdef _DEBUG |
|
105 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::~CCmsOneContactStatus this=%d" ), (TInt)this ); |
|
106 #endif |
|
107 delete iContactLink; |
|
108 iContactLink = NULL; |
|
109 delete iBrandedPresence; |
|
110 iBrandedPresence = NULL; |
|
111 delete iLastElement; |
|
112 iLastElement = NULL; |
|
113 delete iLastService; |
|
114 iLastService = NULL; |
|
115 iServices.ResetAndDestroy(); |
|
116 iServices.Close(); |
|
117 } |
|
118 |
|
119 // ---------------------------------------------------------- |
|
120 // CCmsOneContactStatus::SubscribeL |
|
121 // |
|
122 // ---------------------------------------------------------- |
|
123 // |
|
124 void CCmsOneContactStatus::SubscribeL( MDesC16Array* aIdentities ) |
|
125 { |
|
126 #ifdef _DEBUG |
|
127 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::SubscribeL" ) ); |
|
128 #endif |
|
129 |
|
130 RPointerArray<CBPASInfo> myInfos; |
|
131 CleanupClosePushL( myInfos ); |
|
132 |
|
133 iBrandedPresence->SubscribePresenceInfosL( *aIdentities ); |
|
134 iBrandedPresence->GiveInfosL( *aIdentities, myInfos ); |
|
135 DoHandleInfosL( myInfos, ETrue, EFalse ); |
|
136 |
|
137 CleanupStack::PopAndDestroy(); // myInfos |
|
138 } |
|
139 |
|
140 // ---------------------------------------------------------- |
|
141 // |
|
142 void CCmsOneContactStatus::GetAllL( MDesC16Array* aIdentities ) |
|
143 { |
|
144 #ifdef _DEBUG |
|
145 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::GetAllL" ) ); |
|
146 #endif |
|
147 |
|
148 RPointerArray<CBPASInfo> myInfos; |
|
149 CleanupClosePushL( myInfos ); |
|
150 |
|
151 iBrandedPresence->GiveInfosL( *aIdentities, myInfos ); |
|
152 DoHandleInfosL( myInfos, ETrue, ETrue ); |
|
153 |
|
154 CleanupStack::PopAndDestroy(); // myInfos |
|
155 } |
|
156 |
|
157 // ---------------------------------------------------------- |
|
158 // |
|
159 TBool CCmsOneContactStatus::IsSameContact( MVPbkContactLink* aLink, MPresenceIconNotifier* aCallback ) |
|
160 { |
|
161 TBool ret(EFalse); |
|
162 if ( aCallback == &iCallback && iContactLink->IsSame( *aLink )) |
|
163 { |
|
164 ret = ETrue; |
|
165 } |
|
166 return ret; |
|
167 } |
|
168 |
|
169 // ---------------------------------------------------------- |
|
170 // |
|
171 void CCmsOneContactStatus::HandleInfosL( TInt /*aErrorCode*/, RPointerArray<CBPASInfo>& aInfos ) |
|
172 { |
|
173 #ifdef _DEBUG |
|
174 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::HandleInfosL" ) ); |
|
175 #endif |
|
176 DoHandleInfosL( aInfos, EFalse, EFalse ); |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------------- |
|
180 // |
|
181 void CCmsOneContactStatus::HandleSubscribedInfoL(CBPASInfo* aInfo) |
|
182 { |
|
183 #ifdef _DEBUG |
|
184 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::HandleSubscribedInfoL" ) ); |
|
185 #endif |
|
186 RPointerArray<CBPASInfo> tempArray; |
|
187 |
|
188 tempArray.Append( aInfo ); |
|
189 TRAP_IGNORE( DoHandleInfosL( tempArray, EFalse, EFalse ) ); |
|
190 tempArray.Close(); |
|
191 } |
|
192 |
|
193 |
|
194 // -------------------------------------------------------------------------- |
|
195 // |
|
196 |
|
197 void CCmsOneContactStatus::DoHandleInfosL( RPointerArray<CBPASInfo>& aInfos, TBool aDelete, TBool aGetAllOnce ) |
|
198 { |
|
199 #ifdef _DEBUG |
|
200 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::DoHandleInfosL this=%d" ), (TInt)this ); |
|
201 #endif |
|
202 TInt count = aInfos.Count(); |
|
203 for ( TInt i=0; i<count; i++ ) |
|
204 { |
|
205 TRAP_IGNORE( DoHandleInfoL(aInfos[i])); |
|
206 if ( aDelete ) |
|
207 { |
|
208 delete aInfos[i]; |
|
209 } |
|
210 else |
|
211 { |
|
212 } |
|
213 } |
|
214 UpdateStatusL( aGetAllOnce ); |
|
215 } |
|
216 |
|
217 // -------------------------------------------------------------------------- |
|
218 // |
|
219 void CCmsOneContactStatus::DoHandleInfoL( CBPASInfo* aInfo ) |
|
220 { |
|
221 MPresenceBuddyInfo2::TAvailabilityValues newValue = MPresenceBuddyInfo2::ENotAvailable; |
|
222 CBPASServiceInfo* service = aInfo->ServiceInfo(); |
|
223 TPtrC identity = aInfo->Identity(); |
|
224 TPtrC serviceName = ExtractServiceL( identity ); |
|
225 CCmsOneServiceStatus* serviceStatus = FindService( identity ); |
|
226 CBPASPresenceInfo* presence = aInfo->PresenceInfo(); |
|
227 if ( presence ) |
|
228 { |
|
229 newValue = presence->AvailabilityEnum( ); |
|
230 #ifdef _DEBUG |
|
231 const TInt debugBufSize = 60; |
|
232 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::DoHandleInfoL presence found this=%d" ), (TInt)this ); |
|
233 TBuf8<debugBufSize> serviceBuf; |
|
234 TBuf8<debugBufSize> identityBuf; |
|
235 serviceBuf.Copy( serviceName ); |
|
236 identityBuf.Copy( identity ); |
|
237 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::DoHandleInfoL srv=%S identity=%S avail=%d" ), &serviceBuf, &identityBuf, newValue ); |
|
238 #endif |
|
239 TBool nowAvailable = (newValue < MPresenceBuddyInfo2::EBusy) ? EFalse : ETrue; |
|
240 if ( !serviceStatus ) |
|
241 { |
|
242 serviceStatus = CCmsOneServiceStatus::NewL( identity, service->BrandId(), |
|
243 service->LanguageId(), nowAvailable ); |
|
244 iServices.Append( serviceStatus ); |
|
245 } |
|
246 else |
|
247 { |
|
248 serviceStatus->SetAvailability( nowAvailable ); |
|
249 } |
|
250 CBPASIconInfo* icon = aInfo->IconInfo(); |
|
251 if ( icon ) |
|
252 { |
|
253 serviceStatus->SetElementL( icon->ImageElementId() ); |
|
254 } |
|
255 else |
|
256 { |
|
257 } |
|
258 if ( newValue == MPresenceBuddyInfo2::EUnknownAvailability ) |
|
259 { |
|
260 #ifdef _DEBUG |
|
261 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::DoHandleInfoL presence not found this=%d" ), (TInt)this ); |
|
262 #endif |
|
263 // service is closed and we delete the corresponding service entity |
|
264 RemoveService( serviceStatus ); |
|
265 } |
|
266 } |
|
267 else |
|
268 { |
|
269 // nothing to do |
|
270 } |
|
271 } |
|
272 |
|
273 // -------------------------------------------------------------------------- |
|
274 // |
|
275 TPtrC CCmsOneContactStatus::ExtractServiceL( const TDesC& aXspId ) |
|
276 { |
|
277 TPtrC ret; |
|
278 TInt pos = aXspId.Find(KColon); |
|
279 if ( pos >= 0) |
|
280 { |
|
281 // ok input |
|
282 ret.Set( aXspId.Left(pos)); |
|
283 } |
|
284 else |
|
285 { |
|
286 User::Leave( KErrArgument ); |
|
287 } |
|
288 return ret; |
|
289 } |
|
290 |
|
291 // -------------------------------------------------------------------------- |
|
292 // |
|
293 CCmsOneServiceStatus* CCmsOneContactStatus::FindService( const TDesC& aService ) |
|
294 { |
|
295 CCmsOneServiceStatus* currentService = NULL; |
|
296 TInt counter = iServices.Count(); |
|
297 for ( TInt i=0; i<counter; i++ ) |
|
298 { |
|
299 currentService = iServices[i]; |
|
300 if ( currentService->IsSameService( aService )) |
|
301 { |
|
302 return currentService; |
|
303 } |
|
304 } |
|
305 return NULL; |
|
306 } |
|
307 |
|
308 // -------------------------------------------------------------------------- |
|
309 // |
|
310 void CCmsOneContactStatus::RemoveService( CCmsOneServiceStatus* aService ) |
|
311 { |
|
312 #ifdef _DEBUG |
|
313 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::RemoveService this=%d" ), (TInt)this ); |
|
314 #endif |
|
315 CCmsOneServiceStatus* currentService = NULL; |
|
316 TInt counter = iServices.Count(); |
|
317 for ( TInt i=0; i<counter; i++ ) |
|
318 { |
|
319 currentService = iServices[i]; |
|
320 if ( currentService == aService ) |
|
321 { |
|
322 delete iServices[i]; |
|
323 iServices.Remove(i); |
|
324 break; |
|
325 } |
|
326 } |
|
327 return; |
|
328 } |
|
329 |
|
330 // -------------------------------------------------------------------------- |
|
331 // |
|
332 void CCmsOneContactStatus::UpdateStatusL( TBool aGetAllOnce ) |
|
333 { |
|
334 #ifdef _DEBUG |
|
335 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::UpdateStatusL this=%d" ), (TInt)this ); |
|
336 #endif |
|
337 |
|
338 if ( aGetAllOnce ) |
|
339 { |
|
340 UpdateAllAtOnceStatus(); |
|
341 } |
|
342 else |
|
343 { |
|
344 UpdateCommonStatusL(); |
|
345 } |
|
346 |
|
347 return; |
|
348 } |
|
349 |
|
350 // -------------------------------------------------------------------------- |
|
351 // |
|
352 void CCmsOneContactStatus::UpdateCommonStatusL( ) |
|
353 { |
|
354 #ifdef _DEBUG |
|
355 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::UpdateCommonStatusL this=%d" ), (TInt)this ); |
|
356 #endif |
|
357 CCmsOneServiceStatus* currentService = NULL; |
|
358 CCmsOneServiceStatus* onlineService = NULL; |
|
359 TInt onlineServiceCount = 0; |
|
360 |
|
361 // Count how many are online now and compare to the previous situation. |
|
362 // If only one service is online then that icon is used in certain cases. |
|
363 TInt counter = iServices.Count(); |
|
364 for ( TInt i=0; i<counter; i++ ) |
|
365 { |
|
366 currentService = iServices[i]; |
|
367 onlineServiceCount+= currentService->Availability(); |
|
368 if ( currentService->Availability() ) |
|
369 { |
|
370 onlineService = currentService; |
|
371 } |
|
372 } |
|
373 |
|
374 iAvailableServices = counter; |
|
375 iOnlineServices = onlineServiceCount; |
|
376 |
|
377 SendNotificationWhenNeededL( onlineService ? onlineService : currentService ); |
|
378 |
|
379 return; |
|
380 } |
|
381 |
|
382 |
|
383 // -------------------------------------------------------------------------- |
|
384 // |
|
385 void CCmsOneContactStatus::UpdateAllAtOnceStatus( ) |
|
386 { |
|
387 #ifdef _DEBUG |
|
388 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::UpdateAllAtOnceStatus this=%d" ), (TInt)this ); |
|
389 #endif |
|
390 |
|
391 RPointerArray<MPresenceServiceIconInfo> callbackArray; |
|
392 CCmsOneServiceStatus* currentService = NULL; |
|
393 |
|
394 // Add all available service statuses |
|
395 TInt counter = iServices.Count(); |
|
396 for ( TInt i=0; i<counter; i++ ) |
|
397 { |
|
398 currentService = iServices[i]; |
|
399 callbackArray.Append( currentService ); |
|
400 } |
|
401 |
|
402 iCallback.NewIconsForContact( |
|
403 iContactLink, |
|
404 callbackArray, |
|
405 iId ); |
|
406 |
|
407 callbackArray.Close(); |
|
408 |
|
409 return; |
|
410 } |
|
411 |
|
412 // -------------------------------------------------------------------------- |
|
413 // |
|
414 void CCmsOneContactStatus::SendNotificationWhenNeededL( CCmsOneServiceStatus* aOnlyStatus ) |
|
415 { |
|
416 #ifdef _DEBUG |
|
417 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::SendNotificationWhenNeededL this=%d" ), (TInt)this ); |
|
418 #endif |
|
419 TPtrC8 brandPtr(KNullDesC8); |
|
420 TPtrC8 elementPtr(KNullDesC8); |
|
421 TInt brandLanguage (KErrNotFound ); |
|
422 if ( !iAvailableServices ) |
|
423 { |
|
424 #ifdef _DEBUG |
|
425 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus:: NO SERVICES this=%d" ), (TInt)this ); |
|
426 #endif |
|
427 } |
|
428 else if (( 1 == iAvailableServices ) || (1 == iOnlineServices )) |
|
429 { |
|
430 #ifdef _DEBUG |
|
431 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus:: SERVICE ICON this=%d" ), (TInt)this ); |
|
432 #endif |
|
433 brandPtr.Set( aOnlyStatus->BrandId() ); |
|
434 elementPtr.Set( aOnlyStatus->ElementId() ); |
|
435 brandLanguage = aOnlyStatus->BrandLanguage(); |
|
436 } |
|
437 else if ( iOnlineServices >= KTrafficLightLimit ) |
|
438 { |
|
439 #ifdef _DEBUG |
|
440 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus:: COMMON TRAFFIC LIGHTS ON this=%d" ), (TInt)this ); |
|
441 #endif |
|
442 brandPtr.Set( TrafficLightService() ); |
|
443 elementPtr.Set( TrafficLightOnline() ); |
|
444 } |
|
445 else |
|
446 { |
|
447 #ifdef _DEBUG |
|
448 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus:: COMMON TRAFFIC LIGHTS OFF this=%d" ), (TInt)this ); |
|
449 #endif |
|
450 brandPtr.Set( TrafficLightService() ); |
|
451 elementPtr.Set( TrafficLightOffline() ); |
|
452 } |
|
453 |
|
454 if ( brandPtr.CompareF( LastBrand() ) || elementPtr.CompareF( LastElement() )) |
|
455 { |
|
456 DoSendNotificationL( brandPtr, elementPtr, brandLanguage ); |
|
457 } |
|
458 |
|
459 return; |
|
460 } |
|
461 |
|
462 // -------------------------------------------------------------------------- |
|
463 // |
|
464 void CCmsOneContactStatus::DoSendNotificationL( const TDesC8& aService, const TDesC8& aElement, |
|
465 TInt aBrandLanguage ) |
|
466 { |
|
467 #ifdef _DEBUG |
|
468 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::DoSendNotificationL begins this=%d" ), (TInt)this ); |
|
469 #endif |
|
470 delete iLastElement; |
|
471 iLastElement = NULL; |
|
472 iLastElement = aElement.AllocL(); |
|
473 |
|
474 delete iLastService; |
|
475 iLastService = NULL; |
|
476 iLastService = aService.AllocL(); |
|
477 |
|
478 iCallback.NewIconForContact( |
|
479 iContactLink, |
|
480 aService, |
|
481 aElement, |
|
482 iId, |
|
483 aBrandLanguage ); |
|
484 |
|
485 #ifdef _DEBUG |
|
486 const TInt KMyBufferSize = 60; |
|
487 TBuf8<KMyBufferSize> serviceBuf; |
|
488 TBuf8<KMyBufferSize> elementBuf; |
|
489 serviceBuf.Copy( aService ); |
|
490 elementBuf.Copy( aElement ); |
|
491 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::DoSendNotificationL srv=%S" ), |
|
492 &serviceBuf ); |
|
493 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::DoSendNotificationL element=%S" ), |
|
494 &elementBuf ); |
|
495 CPresenceTrafficLights::WriteToLog( _L8( "CCmsOneContactStatus::DoSendNotificationL ends this=%d" ), |
|
496 (TInt)this ); |
|
497 #endif |
|
498 } |
|
499 |
|
500 // -------------------------------------------------------------------------- |
|
501 // |
|
502 TPtrC8 CCmsOneContactStatus::LastBrand( ) |
|
503 { |
|
504 return iLastService ? iLastService->Des() : TPtrC8(); |
|
505 } |
|
506 |
|
507 // -------------------------------------------------------------------------- |
|
508 // |
|
509 TPtrC8 CCmsOneContactStatus::LastElement( ) |
|
510 { |
|
511 return iLastElement ? iLastElement->Des() : TPtrC8(); |
|
512 } |
|
513 |
|
514 |
|
515 // -------------------------------------------------------------------------- |
|
516 // |
|
517 TPtrC8 CCmsOneContactStatus::TrafficLightService() |
|
518 { |
|
519 return iDefaultTrafficLightBrandId ? iDefaultTrafficLightBrandId->Des() : TPtrC8(); |
|
520 } |
|
521 |
|
522 // -------------------------------------------------------------------------- |
|
523 // |
|
524 TPtrC8 CCmsOneContactStatus::TrafficLightOnline() |
|
525 { |
|
526 return iDefaultOnlineElementId ? iDefaultOnlineElementId->Des() : TPtrC8(); |
|
527 } |
|
528 |
|
529 // -------------------------------------------------------------------------- |
|
530 // |
|
531 TPtrC8 CCmsOneContactStatus::TrafficLightOffline() |
|
532 { |
|
533 return iDefaultOfflineElementId ? iDefaultOfflineElementId->Des() : TPtrC8(); |
|
534 } |
|
535 |