|
1 /* |
|
2 * Copyright (c) 2005 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: Container of one attribute list item. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngAttributeListItem.h" |
|
20 #include "PEngListLibraryPanics.h" |
|
21 #include <e32std.h> |
|
22 #include <s32strm.h> |
|
23 |
|
24 |
|
25 //Default granurality for attribute list element members |
|
26 const TInt KAttributeListElementGranurality = 3; |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CPEngAttributeListItem::CPEngAttributeListItem |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CPEngAttributeListItem::CPEngAttributeListItem() |
|
37 : iCurrentlyDefault( EFalse ), |
|
38 iNewDefault( EFalse ), |
|
39 iListOfAttributes( KAttributeListElementGranurality ), |
|
40 iListOfContactLists( KAttributeListElementGranurality ), |
|
41 iListOfNewContactLists( KAttributeListElementGranurality ), |
|
42 iListOfContactIDs( KAttributeListElementGranurality ), |
|
43 iListOfNewContactIDs( KAttributeListElementGranurality ), |
|
44 // calculated initial size for store, 8*4 |
|
45 iSizeOfEntry( 32 ) |
|
46 { |
|
47 } |
|
48 |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CPEngAttributeListItem::ConstructL() |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CPEngAttributeListItem::ConstructL( const RArray<TUint32>& aAttributes ) |
|
55 { |
|
56 // copy attributes |
|
57 TInt count ( aAttributes.Count() ); |
|
58 for ( TInt x ( 0 ) ; x < count ; x++ ) |
|
59 { |
|
60 // we can use append since passed array is already in order |
|
61 iListOfAttributes.AppendL( aAttributes[x] ); |
|
62 |
|
63 } |
|
64 iSizeOfEntry += count * 4; // 4 bytes for each attribute ID |
|
65 } |
|
66 |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CPEngAttributeListItem::ConstructL() |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 void CPEngAttributeListItem::ConstructL( |
|
73 const CPEngAttributeListItem& aAttributeList ) |
|
74 { |
|
75 iCurrentlyDefault = aAttributeList.CurrentlyDefault(); |
|
76 iNewDefault = aAttributeList.NewDefault(); |
|
77 CopyTIntArrayL( iListOfAttributes, aAttributeList.PresenceAttributes() ); |
|
78 CopyDesArrayL( iListOfContactLists, aAttributeList.ArrayOfContacts( ECurrentContactLists ) ); |
|
79 CopyDesArrayL( iListOfNewContactLists, aAttributeList.ArrayOfContacts( ENewContactLists ) ); |
|
80 CopyDesArrayL( iListOfContactIDs, aAttributeList.ArrayOfContacts( ECurrentContactIDs ) ); |
|
81 CopyDesArrayL( iListOfNewContactIDs, aAttributeList.ArrayOfContacts( ENewContactIDs ) ); |
|
82 iSizeOfEntry = aAttributeList.SizeOfEntry(); |
|
83 } |
|
84 |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CPEngAttributeListItem::NewL() |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CPEngAttributeListItem* CPEngAttributeListItem::NewL( RReadStream& aStream ) |
|
91 { |
|
92 CPEngAttributeListItem* self = NewLC( aStream ); |
|
93 CleanupStack::Pop(); |
|
94 |
|
95 return self; |
|
96 } |
|
97 |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CPEngAttributeListItem::NewLC() |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 CPEngAttributeListItem* CPEngAttributeListItem::NewLC( |
|
104 RReadStream& aStream ) |
|
105 { |
|
106 CPEngAttributeListItem* self = new( ELeave ) CPEngAttributeListItem; |
|
107 |
|
108 CleanupStack::PushL( self ); |
|
109 self->InternalizeL( aStream ); |
|
110 return self; |
|
111 } |
|
112 |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CPEngAttributeListItem::NewL() |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 CPEngAttributeListItem* CPEngAttributeListItem::NewL( |
|
119 const RArray<TUint32>& aAttributes ) |
|
120 { |
|
121 CPEngAttributeListItem* self = NewLC( aAttributes ); |
|
122 CleanupStack::Pop(); |
|
123 |
|
124 return self; |
|
125 } |
|
126 |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CPEngAttributeListItem::NewLC() |
|
130 // Two-phased constructor. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 CPEngAttributeListItem* CPEngAttributeListItem::NewLC( |
|
134 const RArray<TUint32>& aAttributes ) |
|
135 { |
|
136 CPEngAttributeListItem* self = new( ELeave ) CPEngAttributeListItem; |
|
137 |
|
138 CleanupStack::PushL( self ); |
|
139 self->ConstructL( aAttributes ); |
|
140 return self; |
|
141 } |
|
142 |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CPEngAttributeListItem::NewL() |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 CPEngAttributeListItem* CPEngAttributeListItem::NewL( |
|
149 const CPEngAttributeListItem& aAttributeList ) |
|
150 { |
|
151 CPEngAttributeListItem* self = new( ELeave ) CPEngAttributeListItem; |
|
152 |
|
153 CleanupStack::PushL( self ); |
|
154 self->ConstructL( aAttributeList ); |
|
155 CleanupStack::Pop(); |
|
156 |
|
157 return self; |
|
158 } |
|
159 |
|
160 |
|
161 |
|
162 // Destructor |
|
163 CPEngAttributeListItem::~CPEngAttributeListItem() |
|
164 { |
|
165 iListOfAttributes.Reset(); |
|
166 iListOfContactLists.Reset(); |
|
167 iListOfNewContactLists.Reset(); |
|
168 iListOfContactIDs.Reset(); |
|
169 iListOfNewContactIDs.Reset(); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CPEngAttributeListItem::AddContactToListL() |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 TInt CPEngAttributeListItem::AddContactToListL( const TDesC& aContact, |
|
177 TPEngAttrListItemArrays aArray ) |
|
178 { |
|
179 CDesCArray& array = Array( aArray ); |
|
180 TInt err( array.InsertIsqL( aContact, ECmpFolded ) ); |
|
181 iSizeOfEntry += aContact.Size(); |
|
182 return err; |
|
183 } |
|
184 |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CPEngAttributeListItem::DeleteContactFromList() |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 TInt CPEngAttributeListItem::DeleteContactFromList( const TDesC& aContact, |
|
191 TPEngAttrListItemArrays aArray ) |
|
192 { |
|
193 CDesCArray& array = Array( aArray ); |
|
194 TInt err ( DeleteItemFromArray( array, aContact ) ); |
|
195 if ( err != KErrNone ) |
|
196 { |
|
197 return err; |
|
198 } |
|
199 |
|
200 return ContactsCount(); |
|
201 } |
|
202 |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CPEngAttributeListItem::ArrayOfContacts() |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 const CDesCArray& CPEngAttributeListItem::ArrayOfContacts( |
|
209 TPEngAttrListItemArrays aArray ) const |
|
210 { |
|
211 // this cast is here to reuse defined function, |
|
212 //it will return anyway const reference |
|
213 return const_cast<CPEngAttributeListItem*>( this )->Array( aArray ); |
|
214 } |
|
215 |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CPEngAttributeListItem::PresenceAttributes() |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 const RArray<TUint32>& CPEngAttributeListItem::PresenceAttributes() const |
|
222 { |
|
223 return iListOfAttributes; |
|
224 } |
|
225 |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CPEngAttributeListItem::UpdatePresenceAttributesL() |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 void CPEngAttributeListItem::UpdatePresenceAttributesL( |
|
232 const RArray<TUint32>& aNewPresenceAttributes ) |
|
233 { |
|
234 // 4 bytes each attribute |
|
235 iSizeOfEntry -= 4 * iListOfAttributes.Count(); |
|
236 iListOfAttributes.Reset(); |
|
237 |
|
238 TInt count( aNewPresenceAttributes.Count() ); |
|
239 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
240 { |
|
241 User::LeaveIfError( iListOfAttributes.InsertInSignedKeyOrder( aNewPresenceAttributes[ x ] ) ); |
|
242 } |
|
243 |
|
244 // 4 bytes each attribute |
|
245 iSizeOfEntry += 4 * iListOfAttributes.Count(); |
|
246 } |
|
247 |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CPEngAttributeListItem::CommitContactListL() |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CPEngAttributeListItem::CommitContactListL( const TDesC& aContact ) |
|
254 { |
|
255 CommitContactL( iListOfContactLists, iListOfNewContactLists, aContact ); |
|
256 } |
|
257 |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CPEngAttributeListItem::CommitContactIdL() |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 void CPEngAttributeListItem::CommitContactIdL( const TDesC& aContact ) |
|
264 { |
|
265 CommitContactL( iListOfContactIDs, iListOfNewContactIDs, aContact ); |
|
266 } |
|
267 |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CPEngAttributeListItem::CurrentlyDefault() |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 TBool CPEngAttributeListItem::CurrentlyDefault() const |
|
274 { |
|
275 return iCurrentlyDefault; |
|
276 } |
|
277 |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CPEngAttributeListItem::NewDefault() |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 TBool CPEngAttributeListItem::NewDefault() const |
|
284 { |
|
285 return iNewDefault; |
|
286 } |
|
287 |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CPEngAttributeListItem::SetNewDefault() |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 TInt CPEngAttributeListItem::SetNewDefault( TBool aNewDefault ) |
|
294 { |
|
295 iNewDefault = aNewDefault; |
|
296 return ContactsCount(); |
|
297 } |
|
298 |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // CPEngAttributeListItem::CommitDefault() |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 void CPEngAttributeListItem::CommitDefault() |
|
305 { |
|
306 // was it suppose to be new default |
|
307 iCurrentlyDefault = iNewDefault; |
|
308 iNewDefault = EFalse; |
|
309 } |
|
310 |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CPEngAttributeListItem::Synchronized() |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 TBool CPEngAttributeListItem::Synchronized() const |
|
317 { |
|
318 return iSynchronized; |
|
319 } |
|
320 |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CPEngAttributeListItem::SetSynchronization() |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 void CPEngAttributeListItem::SetSynchronization( TBool aSync ) |
|
327 { |
|
328 iSynchronized = aSync; |
|
329 } |
|
330 |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CPEngAttributeListItem::ExternalizeL() |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 void CPEngAttributeListItem::ExternalizeL( RWriteStream& aStream ) |
|
337 { |
|
338 aStream.WriteInt32L( iCurrentlyDefault ); |
|
339 aStream.WriteInt32L( iNewDefault ); |
|
340 aStream.WriteInt32L( iSynchronized ); |
|
341 |
|
342 TInt count ( iListOfAttributes.Count() ); |
|
343 aStream.WriteInt32L( count ); |
|
344 |
|
345 for ( TInt x ( 0 ) ; x < count ; x++ ) |
|
346 { |
|
347 aStream.WriteInt32L( iListOfAttributes[x] ); |
|
348 } |
|
349 |
|
350 ExternalizeDesArrayToStreamL( iListOfContactLists, aStream ); |
|
351 |
|
352 ExternalizeDesArrayToStreamL( iListOfContactIDs, aStream ); |
|
353 |
|
354 ExternalizeDesArrayToStreamL( iListOfNewContactLists, aStream ); |
|
355 |
|
356 ExternalizeDesArrayToStreamL( iListOfNewContactIDs, aStream ); |
|
357 } |
|
358 |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CPEngAttributeListItem::InternalizeL() |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 void CPEngAttributeListItem::InternalizeL( RReadStream& aStream ) |
|
365 { |
|
366 iCurrentlyDefault = aStream.ReadInt32L(); |
|
367 iNewDefault = aStream.ReadInt32L(); |
|
368 iSynchronized = aStream.ReadInt32L(); |
|
369 iSizeOfEntry = 12; // already those 3 flags readed before |
|
370 |
|
371 |
|
372 TInt count ( aStream.ReadInt32L() ); |
|
373 for ( TInt x ( 0 ) ; x < count ; x++ ) |
|
374 { |
|
375 iListOfAttributes.AppendL( aStream.ReadInt32L() ); |
|
376 } |
|
377 iSizeOfEntry += 4 * ( 1 + count ); |
|
378 |
|
379 iSizeOfEntry += InternalizeDesArrayFromStreamL( iListOfContactLists, |
|
380 aStream ); |
|
381 |
|
382 iSizeOfEntry += InternalizeDesArrayFromStreamL( iListOfContactIDs, |
|
383 aStream ); |
|
384 |
|
385 iSizeOfEntry += InternalizeDesArrayFromStreamL( iListOfNewContactLists, |
|
386 aStream ); |
|
387 |
|
388 iSizeOfEntry += InternalizeDesArrayFromStreamL( iListOfNewContactIDs, |
|
389 aStream ); |
|
390 } |
|
391 |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // CPEngAttributeListItem::SizeOfEntry() |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 TInt CPEngAttributeListItem::SizeOfEntry() const |
|
398 { |
|
399 return iSizeOfEntry; |
|
400 } |
|
401 |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // CPEngAttributeListItem::ContactsCount() |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 TInt CPEngAttributeListItem::ContactsCount() const |
|
408 { |
|
409 // Returns number of contact which are attached to the attribute list |
|
410 // If attribute list is set as default, it is considered like another |
|
411 // contact would be attached to the attribute list |
|
412 TInt count = iListOfContactLists.Count() + |
|
413 iListOfNewContactLists.Count() + |
|
414 iListOfContactIDs.Count() + |
|
415 iListOfNewContactIDs.Count() + |
|
416 iCurrentlyDefault + |
|
417 iNewDefault; |
|
418 return count; |
|
419 } |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // CPEngAttributeListItem::Array() |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 CDesCArray& CPEngAttributeListItem::Array( TPEngAttrListItemArrays aArray ) |
|
426 { |
|
427 switch ( aArray ) |
|
428 { |
|
429 case ENewContactLists: |
|
430 { |
|
431 return iListOfNewContactLists; |
|
432 } |
|
433 |
|
434 case ENewContactIDs: |
|
435 { |
|
436 return iListOfNewContactIDs; |
|
437 } |
|
438 |
|
439 case ECurrentContactLists: |
|
440 { |
|
441 return iListOfContactLists; |
|
442 } |
|
443 |
|
444 case ECurrentContactIDs: |
|
445 { |
|
446 return iListOfContactIDs; |
|
447 } |
|
448 |
|
449 default: |
|
450 { |
|
451 // by default work with list of new contact lists |
|
452 return iListOfNewContactLists; |
|
453 } |
|
454 } |
|
455 } |
|
456 |
|
457 |
|
458 |
|
459 // ----------------------------------------------------------------------------- |
|
460 // CPEngAttributeListItem::CommitContactL() |
|
461 // ----------------------------------------------------------------------------- |
|
462 // |
|
463 void CPEngAttributeListItem::CommitContactL( CDesCArray& aCurrentArray, |
|
464 CDesCArray& aNewArray, |
|
465 const TDesC& aContact ) |
|
466 { |
|
467 // Try to find item from New list, if it is find update Current |
|
468 // contact list |
|
469 TInt position( 0 ); |
|
470 if ( KErrNone == aNewArray.FindIsq( aContact, position, ECmpFolded ) ) |
|
471 { |
|
472 // it was found in new, add it to the current one |
|
473 // trap, since it can leave it is already in list |
|
474 TRAPD( err, aCurrentArray.InsertIsqL( aContact, ECmpFolded ) ); |
|
475 if ( err == KErrNoMemory ) // if it was no memory leave again |
|
476 { |
|
477 User::Leave( KErrNoMemory ); |
|
478 } |
|
479 // now remove it from the new contacts |
|
480 aNewArray.Delete( position ); |
|
481 // size does not change here since it was added and removed |
|
482 return; |
|
483 } |
|
484 |
|
485 // it was not found in the new contacts, so try to delete it from current |
|
486 // if it does not exist, just then it is just fine, ignore it |
|
487 DeleteItemFromArray( aCurrentArray, aContact ); |
|
488 } |
|
489 |
|
490 |
|
491 // ----------------------------------------------------------------------------- |
|
492 // CPEngAttributeListItem::DeleteItemFromArray() |
|
493 // ----------------------------------------------------------------------------- |
|
494 // |
|
495 TInt CPEngAttributeListItem::DeleteItemFromArray( CDesCArray& aArray, |
|
496 const TDesC& aItem ) |
|
497 { |
|
498 TInt posToDelete( 0 ); |
|
499 if ( KErrNone == aArray.FindIsq( aItem, posToDelete, ECmpFolded ) ) |
|
500 { |
|
501 aArray.Delete( posToDelete ); |
|
502 iSizeOfEntry -= aItem.Size(); |
|
503 return KErrNone; |
|
504 } |
|
505 |
|
506 return KErrNotFound; |
|
507 } |
|
508 |
|
509 |
|
510 // ----------------------------------------------------------------------------- |
|
511 // CPEngAttributeListItem::CopyDesArrayL() |
|
512 // ----------------------------------------------------------------------------- |
|
513 // |
|
514 void CPEngAttributeListItem::CopyDesArrayL( CDesCArray& aArrayTarget, |
|
515 const CDesCArray& aArraySource ) |
|
516 { |
|
517 TInt count ( aArraySource.Count() ); |
|
518 for ( TInt x ( 0 ) ; x < count ; x++ ) |
|
519 { |
|
520 aArrayTarget.AppendL( aArraySource.MdcaPoint( x ) ); |
|
521 } |
|
522 } |
|
523 |
|
524 |
|
525 // ----------------------------------------------------------------------------- |
|
526 // CPEngAttributeListItem::CopyTIntArrayL() |
|
527 // ----------------------------------------------------------------------------- |
|
528 // |
|
529 void CPEngAttributeListItem::CopyTIntArrayL( RArray<TUint32>& aArrayTarget, |
|
530 const RArray<TUint32>& aArraySource ) |
|
531 { |
|
532 TInt count ( aArraySource.Count() ); |
|
533 for ( TInt x ( 0 ) ; x < count ; x++ ) |
|
534 { |
|
535 aArrayTarget.AppendL( aArraySource[x] ); |
|
536 } |
|
537 } |
|
538 |
|
539 |
|
540 // ----------------------------------------------------------------------------- |
|
541 // CPEngAttributeListItem::ExternalizeDesArrayToStreamL() |
|
542 // ----------------------------------------------------------------------------- |
|
543 // |
|
544 void CPEngAttributeListItem::ExternalizeDesArrayToStreamL( CDesCArray& aArray, |
|
545 RWriteStream& aStream ) |
|
546 { |
|
547 TInt count( aArray.MdcaCount() ); |
|
548 aStream.WriteInt32L( count ); |
|
549 for ( TInt ii( 0 ); ii < count; ii++ ) |
|
550 { |
|
551 aStream << aArray.MdcaPoint( ii ); |
|
552 } |
|
553 } |
|
554 |
|
555 // ----------------------------------------------------------------------------- |
|
556 // CPEngAttributeListItem::InternalizeDesArrayFromStreamL() |
|
557 // ----------------------------------------------------------------------------- |
|
558 // |
|
559 TInt CPEngAttributeListItem::InternalizeDesArrayFromStreamL( CDesCArray& aArray, |
|
560 RReadStream& aStream ) |
|
561 { |
|
562 //internalize item and insert it in array |
|
563 // reset the content of the array |
|
564 aArray.Reset(); |
|
565 TInt sizeOfEntry( 0 ); |
|
566 TInt count ( aStream.ReadInt32L() ); |
|
567 // internalize array |
|
568 for ( TInt x ( 0 ); x < count; x++ ) |
|
569 { |
|
570 // 100 should enough for contact list names |
|
571 HBufC* item = HBufC::NewLC( aStream, 100 ); |
|
572 aArray.InsertIsqL( *item, ECmpFolded ); |
|
573 sizeOfEntry += item->Size(); |
|
574 CleanupStack::PopAndDestroy(); // item |
|
575 } |
|
576 |
|
577 return sizeOfEntry + 4; // 4 == the count |
|
578 } |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 // End of File |
|
584 |