|
1 /* |
|
2 * Copyright (c) 2007 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: |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "cmscontact.h" |
|
22 #include "cmssession.h" |
|
23 #include "cmspresencedata.h" |
|
24 #include "cmscontactfield.h" |
|
25 #include "cmscontactfielditem.h" |
|
26 #include "cmscommondefines.h" |
|
27 |
|
28 // ---------------------------------------------------- |
|
29 // CCmsContactField::CCmsContactField |
|
30 // |
|
31 // ---------------------------------------------------- |
|
32 // |
|
33 CCmsContactField::CCmsContactField( RCmsContact& aContact, |
|
34 CCmsContactFieldItem::TCmsContactField aFieldType ) : |
|
35 CCmsContactBase( aContact ), |
|
36 iFieldType( aFieldType ) |
|
37 { |
|
38 SelectFieldType(); |
|
39 } |
|
40 |
|
41 // ---------------------------------------------------- |
|
42 // CCmsContactField::CCmsContactField |
|
43 // |
|
44 // ---------------------------------------------------- |
|
45 // |
|
46 CCmsContactField::CCmsContactField( RCmsContact& aContact, TRequestStatus& aClientStatus, |
|
47 CCmsContactFieldItem::TCmsContactField aFieldType ) : |
|
48 CCmsContactBase( aContact, aClientStatus ), |
|
49 iFieldType( aFieldType ) |
|
50 { |
|
51 SelectFieldType(); |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------- |
|
55 // CCmsContactField::CCmsContactField |
|
56 // |
|
57 // ---------------------------------------------------- |
|
58 // |
|
59 CCmsContactField::CCmsContactField( RCmsContact& aContact, TRequestStatus& aClientStatus, |
|
60 CCmsContactFieldItem::TCmsContactFieldGroup aFieldGroup ) : |
|
61 CCmsContactBase( aContact, aClientStatus ), |
|
62 iFieldGroup( aFieldGroup ) |
|
63 { |
|
64 SelectFieldType(); |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------- |
|
68 // CCmsContactField::NewL |
|
69 // |
|
70 // ---------------------------------------------------- |
|
71 // |
|
72 CCmsContactField* CCmsContactField::NewL( RCmsContact& aContact, |
|
73 CCmsContactFieldItem::TCmsContactField aFieldType ) |
|
74 { |
|
75 CCmsContactField* self = new ( ELeave ) CCmsContactField( aContact, aFieldType ); |
|
76 CleanupStack::PushL( self ); |
|
77 self->BaseConstructL(); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop(); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------- |
|
84 // CCmsContactField::NewL |
|
85 // |
|
86 // ---------------------------------------------------- |
|
87 // |
|
88 CCmsContactField* CCmsContactField::NewL( RCmsContact& aContact, TRequestStatus& aClientStatus, |
|
89 CCmsContactFieldItem::TCmsContactField aFieldType ) |
|
90 { |
|
91 CCmsContactField* self = new ( ELeave ) CCmsContactField( aContact, aClientStatus, aFieldType ); |
|
92 CleanupStack::PushL( self ); |
|
93 self->BaseConstructL(); |
|
94 self->ConstructL(); |
|
95 CleanupStack::Pop(); |
|
96 return self; |
|
97 } |
|
98 |
|
99 // ---------------------------------------------------- |
|
100 // CCmsContactField::NewL |
|
101 // |
|
102 // ---------------------------------------------------- |
|
103 // |
|
104 CCmsContactField* CCmsContactField::NewL( RCmsContact& aContact, TRequestStatus& aClientStatus, |
|
105 CCmsContactFieldItem::TCmsContactFieldGroup aFieldGroup ) |
|
106 { |
|
107 CCmsContactField* self = new ( ELeave ) CCmsContactField( aContact, aClientStatus, aFieldGroup ); |
|
108 CleanupStack::PushL( self ); |
|
109 self->BaseConstructL(); |
|
110 self->ConstructL(); |
|
111 CleanupStack::Pop(); |
|
112 return self; |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------- |
|
116 // CCmsContactField::ConstructL |
|
117 // |
|
118 // ---------------------------------------------------- |
|
119 // |
|
120 void CCmsContactField::ConstructL() |
|
121 { |
|
122 #ifdef _DEBUG |
|
123 RCmsSession::WriteToLog( _L8( "CCmsContactField::ConstructL()" ) ); |
|
124 #endif |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------- |
|
128 // CCmsContactField::SelectFieldType |
|
129 // |
|
130 // ---------------------------------------------------- |
|
131 // |
|
132 void CCmsContactField::SelectFieldType() |
|
133 { |
|
134 #ifdef _DEBUG |
|
135 RCmsSession::WriteToLog( _L8( "CCmsContactField::SelectFieldType()" ) ); |
|
136 #endif |
|
137 iBinary = CCmsContactFieldItem::ECmsThumbnailPic == iFieldType || |
|
138 CCmsContactFieldItem::ECmsPresenceData == iFieldType || |
|
139 CCmsContactFieldItem::ECmsBrandedAvailability == iFieldType; |
|
140 } |
|
141 |
|
142 // ---------------------------------------------------- |
|
143 // CCmsContactField::~CCmsContactField |
|
144 // |
|
145 // ---------------------------------------------------- |
|
146 // |
|
147 CCmsContactField::~CCmsContactField() |
|
148 { |
|
149 iFieldItems.ResetAndDestroy(); |
|
150 iFieldItems.Close(); |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------- |
|
154 // CCmsContactField::FieldCount |
|
155 // |
|
156 // ---------------------------------------------------- |
|
157 // |
|
158 EXPORT_C TInt CCmsContactField::ItemCount() const |
|
159 { |
|
160 return iFieldItems.Count(); |
|
161 } |
|
162 |
|
163 // ---------------------------------------------------- |
|
164 // CCmsContactField::Item |
|
165 // |
|
166 // ---------------------------------------------------- |
|
167 // |
|
168 EXPORT_C const CCmsContactFieldItem& CCmsContactField::ItemL( TInt aIndex ) const |
|
169 { |
|
170 CCmsContactFieldItem* item = NULL; |
|
171 if( aIndex >= 0 && aIndex < iFieldItems.Count() ) |
|
172 { |
|
173 item = iFieldItems[aIndex]; |
|
174 } |
|
175 else |
|
176 { |
|
177 User::Leave( KErrTooBig ); |
|
178 } |
|
179 return *item; |
|
180 } |
|
181 |
|
182 // ---------------------------------------------------- |
|
183 // CCmsContactField::Item |
|
184 // |
|
185 // ---------------------------------------------------- |
|
186 // |
|
187 EXPORT_C const CCmsContactFieldItem& CCmsContactField::ItemL( CCmsContactFieldItem::TCmsDefaultAttributeTypes aDefaultType ) const |
|
188 { |
|
189 CCmsContactFieldItem* result = NULL; |
|
190 |
|
191 TInt count = iFieldItems.Count(); |
|
192 for( TInt a = 0; a < count; a++ ) |
|
193 { |
|
194 CCmsContactFieldItem* item = iFieldItems[a]; |
|
195 if(item->HasDefaultAttribute(aDefaultType)) |
|
196 { |
|
197 result = item; |
|
198 break; |
|
199 } |
|
200 } |
|
201 |
|
202 if(NULL == result) |
|
203 User::Leave(KErrNotFound); |
|
204 |
|
205 return *result; |
|
206 } |
|
207 |
|
208 |
|
209 |
|
210 // ---------------------------------------------------- |
|
211 // CCmsContactField::Items |
|
212 // |
|
213 // ---------------------------------------------------- |
|
214 // |
|
215 EXPORT_C const RPointerArray<CCmsContactFieldItem>& CCmsContactField::Items() const |
|
216 { |
|
217 return iFieldItems; |
|
218 } |
|
219 |
|
220 // ---------------------------------------------------- |
|
221 // CCmsContactField::Type |
|
222 // |
|
223 // ---------------------------------------------------- |
|
224 // |
|
225 EXPORT_C CCmsContactFieldItem::TCmsContactField CCmsContactField::Type() const |
|
226 { |
|
227 return iFieldType; |
|
228 } |
|
229 |
|
230 // ---------------------------------------------------- |
|
231 // CCmsContactField::GroupType |
|
232 // |
|
233 // ---------------------------------------------------- |
|
234 // |
|
235 EXPORT_C CCmsContactFieldItem::TCmsContactFieldGroup CCmsContactField::GroupType() const |
|
236 { |
|
237 return iFieldGroup; |
|
238 } |
|
239 |
|
240 |
|
241 // ---------------------------------------------------- |
|
242 // CCmsContactField::HasDefaultAttribute |
|
243 // |
|
244 // ---------------------------------------------------- |
|
245 // |
|
246 EXPORT_C TBool CCmsContactField::HasDefaultAttribute( CCmsContactFieldItem::TCmsDefaultAttributeTypes aDefaultType ) const |
|
247 { |
|
248 TBool found = EFalse; |
|
249 |
|
250 TInt count = iFieldItems.Count(); |
|
251 for( TInt a = 0; !found && a < count; a++ ) |
|
252 { |
|
253 CCmsContactFieldItem* item = iFieldItems[a]; |
|
254 if(item->HasDefaultAttribute(aDefaultType)) |
|
255 { |
|
256 found = ETrue; |
|
257 break; |
|
258 } |
|
259 } |
|
260 |
|
261 return found; |
|
262 } |
|
263 |
|
264 // ---------------------------------------------------- |
|
265 // CCmsContactField::HasDefaultAttribute |
|
266 // |
|
267 // ---------------------------------------------------- |
|
268 // |
|
269 EXPORT_C TInt CCmsContactField::HasDefaultAttribute( ) const |
|
270 { |
|
271 TInt bitmask = 0; |
|
272 TInt count = CCmsContactFieldItem::ECmsDefaultTypeUrl; |
|
273 |
|
274 while (count > 0) |
|
275 { |
|
276 if(HasDefaultAttribute((CCmsContactFieldItem::TCmsDefaultAttributeTypes)count)) |
|
277 { |
|
278 bitmask |= count; |
|
279 } |
|
280 |
|
281 count >>= 1; |
|
282 } |
|
283 |
|
284 return bitmask; |
|
285 } |
|
286 |
|
287 |
|
288 |
|
289 // ---------------------------------------------------- |
|
290 // CCmsContactField::RunL |
|
291 // |
|
292 // ---------------------------------------------------- |
|
293 // |
|
294 void CCmsContactField::RunL() |
|
295 { |
|
296 #ifdef _DEBUG |
|
297 RCmsSession::WriteToLog( _L8( "CCmsContactField::RunL() - Error: %d" ), iStatus.Int() ); |
|
298 #endif |
|
299 if( KErrNone <= iStatus.Int() ) |
|
300 { |
|
301 #ifdef _DEBUG |
|
302 RCmsSession::WriteToLog( _L8( " Field data fetched OK." ) ); |
|
303 #endif |
|
304 if( iBinary ) |
|
305 { |
|
306 HandleBinaryDataL(); |
|
307 } |
|
308 else HandleSixteenBitDataL(); |
|
309 } |
|
310 else //An error |
|
311 { |
|
312 //Handle errors in the base class |
|
313 HandleError(); |
|
314 } |
|
315 } |
|
316 |
|
317 // ---------------------------------------------------- |
|
318 // CCmsContactField::HandleSixteenBitDataL |
|
319 // |
|
320 // ---------------------------------------------------- |
|
321 // |
|
322 void CCmsContactField::HandleSixteenBitDataL() |
|
323 { |
|
324 #ifdef _DEBUG |
|
325 RCmsSession::WriteToLog( _L8( "CCmsContactField::HandleSixteenBitDataL()" ) ); |
|
326 #endif |
|
327 if( KErrNone == iStatus.Int() ) |
|
328 { |
|
329 for( TInt i = 0;iStreamDesc16.Length() > 0;i++ ) |
|
330 { |
|
331 TInt length = 0; |
|
332 TInt infoLength = 0; |
|
333 TInt attribute = 0; |
|
334 TPtrC lengthDesc( _L( "" ) ); |
|
335 |
|
336 //data length |
|
337 TInt index = iStreamDesc16.Locate( KDelimiterSpace ); |
|
338 lengthDesc.Set( iStreamDesc16.Left( iStreamDesc16.Locate( KDelimiterSpace ) ) ); |
|
339 TLex luthor( lengthDesc ); |
|
340 User::LeaveIfError( luthor.Val( length ) ); |
|
341 iStreamDesc16.Delete( 0, index + 1 ); |
|
342 |
|
343 //info length |
|
344 index = iStreamDesc16.Locate( KDelimiterSpace ); |
|
345 lengthDesc.Set( iStreamDesc16.Left( iStreamDesc16.Locate( KDelimiterSpace ) ) ); |
|
346 TLex luthorInfo( lengthDesc ); |
|
347 User::LeaveIfError( luthorInfo.Val( infoLength ) ); |
|
348 iStreamDesc16.Delete( 0, index + 1 ); |
|
349 |
|
350 //default attributes |
|
351 index = iStreamDesc16.Locate( KDelimiterSpace ); |
|
352 TPtrC attributedata( iStreamDesc16.Left( iStreamDesc16.Locate( KDelimiterSpace )) ); |
|
353 TLex attl( attributedata ); |
|
354 User::LeaveIfError( attl.Val( attribute ) ); |
|
355 |
|
356 //data |
|
357 TPtrC data( iStreamDesc16.Mid( index + 1, length ) ); |
|
358 TPtrC dataInfo( iStreamDesc16.Mid( index + length + 1, infoLength ) ); |
|
359 CreateFieldItemL( data, dataInfo, attribute ); |
|
360 |
|
361 index > 0 ? iStreamDesc16.Delete( 0, index + 1 + length + infoLength ) : |
|
362 iStreamDesc16.Delete( 0, iStreamDesc16.Length() ); |
|
363 |
|
364 } |
|
365 User::RequestComplete( iClientStatus, KErrNone ); |
|
366 } |
|
367 else |
|
368 { |
|
369 ReAllocBufferL( iStatus.Int() ); |
|
370 TIpcArgs args( iFieldType, StreamDesc16() ); |
|
371 TInt operation( ( TInt )ECmsFetchContactField ); |
|
372 iContact.ResendReceive( operation, Activate(), args ); |
|
373 } |
|
374 } |
|
375 |
|
376 // ---------------------------------------------------- |
|
377 // CCmsContactField::HandleBinaryDataL |
|
378 // |
|
379 // ---------------------------------------------------- |
|
380 // |
|
381 void CCmsContactField::HandleBinaryDataL() |
|
382 { |
|
383 #ifdef _DEBUG |
|
384 RCmsSession::WriteToLog( _L8( "CCmsContactField::HandleBinaryDataL()" ) ); |
|
385 #endif |
|
386 if( KErrNone == iStatus.Int() ) |
|
387 { |
|
388 switch( iFieldType ) |
|
389 { |
|
390 case CCmsContactFieldItem::ECmsThumbnailPic: |
|
391 case CCmsContactFieldItem::ECmsBrandedAvailability: |
|
392 HandleBasicDataL(); |
|
393 break; |
|
394 case CCmsContactFieldItem::ECmsPresenceData: |
|
395 HandlePresenceDataL(); |
|
396 break; |
|
397 } |
|
398 } |
|
399 else |
|
400 { |
|
401 ReAllocBufferL( iStatus.Int() ); |
|
402 TIpcArgs args( iFieldType, StreamDesc8() ); |
|
403 TInt operation( ( TInt )ECmsFetchContactField ); |
|
404 iContact.ResendReceive( operation, Activate(), args ); |
|
405 } |
|
406 } |
|
407 |
|
408 // ---------------------------------------------------- |
|
409 // CCmsContactField::HandleBasicDataL |
|
410 // |
|
411 // ---------------------------------------------------- |
|
412 // |
|
413 void CCmsContactField::HandleBasicDataL() |
|
414 { |
|
415 #ifdef _DEBUG |
|
416 RCmsSession::WriteToLog( _L8( "CCmsContactField::HandleBasicDataL()" ) ); |
|
417 #endif |
|
418 _LIT8( KDelimiter, "\r\n\r\n" ); |
|
419 TPtr8 package( *StreamDesc8() ); |
|
420 TInt separator = package.Find( KDelimiter ); |
|
421 if( KErrNone < separator ) |
|
422 { |
|
423 while( 0 < package.Length() ) |
|
424 { |
|
425 TPtrC8 data( package.Left( separator ) ); |
|
426 CreateFieldItemL( data ); |
|
427 package.Delete( 0, separator + 4 ); |
|
428 separator = package.Find( KDelimiter ); |
|
429 } |
|
430 } |
|
431 else |
|
432 { |
|
433 CreateFieldItemL( package ); |
|
434 } |
|
435 User::RequestComplete( iClientStatus, KErrNone ); |
|
436 } |
|
437 |
|
438 // ---------------------------------------------------- |
|
439 // CCmsContactField::HandlePresenceDataL |
|
440 // |
|
441 // ---------------------------------------------------- |
|
442 // |
|
443 void CCmsContactField::HandlePresenceDataL() |
|
444 { |
|
445 #ifdef _DEBUG |
|
446 RCmsSession::WriteToLog( _L8( "CCmsContactField::HandlePresenceDataL()" ) ); |
|
447 #endif |
|
448 TPtr8 package( *StreamDesc8() ); |
|
449 while( 0 < package.Length() ) |
|
450 { |
|
451 const TInt index( package.Find( KDelimiterNewLine ) ); |
|
452 TPtrC8 presenceData( package.Left( index ) ); |
|
453 HandlePresencePackageL( presenceData ); |
|
454 package.Delete( 0, index + KDelimiterNewLine().Length() ); |
|
455 } |
|
456 User::RequestComplete( iClientStatus, KErrNone ); |
|
457 } |
|
458 |
|
459 // ---------------------------------------------------- |
|
460 // CCmsContactField::HandlePresencePackageL |
|
461 // |
|
462 // ---------------------------------------------------- |
|
463 // |
|
464 void CCmsContactField::HandlePresencePackageL( const TDesC8& aPresenceData ) |
|
465 { |
|
466 #ifdef _DEBUG |
|
467 RCmsSession::WriteToLog( _L8( "CCmsContactField::ExtractFieldType()" ) ); |
|
468 #endif |
|
469 const TInt length( aPresenceData.Length() ); |
|
470 TPtr8 presenceData( CONST_CAST( TUint8*, aPresenceData.Ptr() ), length, length ); |
|
471 CCmsPresenceData* item = CCmsPresenceData::NewL( iContact ); |
|
472 CleanupStack::PushL( item ); |
|
473 while( 0 < presenceData.Length() ) |
|
474 { |
|
475 TInt delIndex = 0; |
|
476 TInt type( ExtractFieldType( presenceData ) ); |
|
477 TPtrC8 data( ExtractData( presenceData, delIndex ) ); |
|
478 item->AssignDataL( type, data ); |
|
479 presenceData.Delete( 0, delIndex ); |
|
480 presenceData.TrimAll(); |
|
481 } |
|
482 User::LeaveIfError( iFieldItems.Append( item ) ); |
|
483 CleanupStack::Pop(); //item |
|
484 } |
|
485 |
|
486 // ---------------------------------------------------- |
|
487 // CCmsContactField::ExtractFieldType |
|
488 // |
|
489 // ---------------------------------------------------- |
|
490 // |
|
491 TInt CCmsContactField::ExtractFieldType( TPtr8& aDataDesc ) |
|
492 { |
|
493 #ifdef _DEBUG |
|
494 RCmsSession::WriteToLog( _L8( "CCmsContactField::ExtractFieldType()" ) ); |
|
495 #endif |
|
496 TInt fieldType = 0; |
|
497 TInt index = aDataDesc.Locate( KDelimiterSpace ); |
|
498 TPtrC8 data( aDataDesc.Left( index ) ); |
|
499 TLex8 lex( data ); |
|
500 lex.Val( fieldType ); |
|
501 aDataDesc.Delete( 0, index + 1 ); |
|
502 return fieldType; |
|
503 } |
|
504 |
|
505 // ---------------------------------------------------- |
|
506 // CCmsContactField::ExtractData |
|
507 // |
|
508 // ---------------------------------------------------- |
|
509 // |
|
510 TPtrC8 CCmsContactField::ExtractData( const TDesC8& aDataDesc, TInt& aDelIndex ) |
|
511 { |
|
512 #ifdef _DEBUG |
|
513 RCmsSession::WriteToLog( _L8( "CCmsContactField::ExtractData()" ) ); |
|
514 #endif |
|
515 TInt index1( aDataDesc.Locate( KDelimiterQuote ) ); |
|
516 TPtrC8 temp( aDataDesc.Mid( index1 + 1 ) ); |
|
517 RDebug::RawPrint( temp ); |
|
518 TInt index2 = temp.Locate( KDelimiterQuote ); |
|
519 TPtrC8 data( index2 >= 0 ? temp.Left( index2 ) : temp ); |
|
520 RDebug::RawPrint( data ); |
|
521 aDelIndex = index1 + data.Length() + 3; |
|
522 return data; |
|
523 } |
|
524 |
|
525 // ---------------------------------------------------- |
|
526 // CCmsContactField::CreateFieldItemL |
|
527 // |
|
528 // ---------------------------------------------------- |
|
529 // |
|
530 void CCmsContactField::CreateFieldItemL( const TDesC8& aItemData ) |
|
531 { |
|
532 CCmsContactFieldItem* item = CCmsContactFieldItem::NewL( aItemData ); |
|
533 CleanupStack::PushL( item ); |
|
534 User::LeaveIfError( iFieldItems.Append( item ) ); |
|
535 CleanupStack::Pop(); //item |
|
536 } |
|
537 |
|
538 // ---------------------------------------------------- |
|
539 // CCmsContactField::CreateFieldItemL |
|
540 // |
|
541 // ---------------------------------------------------- |
|
542 // |
|
543 void CCmsContactField::CreateFieldItemL( const TDesC& aItemData, const TDesC& aItemInfo, const TInt aDefaultAttribute ) |
|
544 { |
|
545 CCmsContactFieldItem* item = CCmsContactFieldItem::NewL( aItemData ); |
|
546 CleanupStack::PushL( item ); |
|
547 item->SetDefaultAttribute( aDefaultAttribute ); |
|
548 User::LeaveIfError( iFieldItems.Append( item ) ); |
|
549 CleanupStack::Pop(); //item |
|
550 item->SetInfo( aItemInfo ); |
|
551 } |
|
552 |
|
553 // End of File |
|
554 |
|
555 |