|
1 /* |
|
2 * Copyright (c) 2006 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: Array wrapper for chat lists |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CCAServerContactsArrayPC.h" |
|
22 #include "CCAStorageManagerFactory.h" |
|
23 #include "ChatDebugPrint.h" |
|
24 #include "ChatDefinitions.h" |
|
25 #include "MCAStoredContacts.h" |
|
26 #include "MCAStoredContact.h" |
|
27 #include "CAUtils.h" |
|
28 #include "CCAPCUtils.h" |
|
29 |
|
30 #include <barsread.h> |
|
31 #include <eikenv.h> |
|
32 #include <collate.h> |
|
33 |
|
34 // Icon when contact already exist in phone |
|
35 _LIT( KContactExistInPhoneIcon, "\t1" ); |
|
36 |
|
37 // local functions |
|
38 TInt CCAServerContactsArrayCompare( const TCAServerContact& aFirst, |
|
39 const TCAServerContact& aSecond ) |
|
40 { |
|
41 return aFirst.iIdentification.CompareC( aSecond.iIdentification, |
|
42 KCollationLevel, NULL ); |
|
43 } |
|
44 |
|
45 // ================= MEMBER FUNCTIONS ======================= |
|
46 |
|
47 // C++ default constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // |
|
50 CCAServerContactsArrayPC::CCAServerContactsArrayPC( |
|
51 TBool aShowContactExistInPhoneIcon ) |
|
52 : iShowContactExistInPhoneIcon( aShowContactExistInPhoneIcon ) |
|
53 { |
|
54 } |
|
55 |
|
56 |
|
57 // common contruction part |
|
58 void CCAServerContactsArrayPC::CommonConstructL( const TDesC& aIconTabulator ) |
|
59 { |
|
60 iIconTabulator = aIconTabulator.AllocL(); |
|
61 iLine = HBufC::NewL( |
|
62 KFriendsListMaxIdentificationLength + iIconTabulator->Length() ); |
|
63 } |
|
64 |
|
65 |
|
66 // Symbian OS default constructor can leave. |
|
67 void CCAServerContactsArrayPC::ConstructL( CDesCArray* aNickNames, |
|
68 CDesCArray* aWVIds, |
|
69 const TDesC& aIconTabulator, |
|
70 CDesCArray* aIdentifications ) |
|
71 { |
|
72 if ( ! aNickNames || ! aWVIds ) |
|
73 { |
|
74 User::Leave( KErrArgument ); |
|
75 } |
|
76 |
|
77 if ( aNickNames->MdcaCount() != aWVIds->MdcaCount() ) |
|
78 { |
|
79 User::Leave( KErrArgument ); |
|
80 } |
|
81 |
|
82 CommonConstructL( aIconTabulator ); |
|
83 |
|
84 // create the identifications |
|
85 TInt count( aWVIds->Count() ); |
|
86 |
|
87 TCAServerContact temp; |
|
88 |
|
89 MCAStoredContacts* storageContacts = |
|
90 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
91 |
|
92 for ( TInt i( 0 ); i < count; ++i ) |
|
93 { |
|
94 if ( aIdentifications ) |
|
95 { |
|
96 if ( aIdentifications->MdcaPoint( i ).Length() > 0 ) |
|
97 { |
|
98 // if the nickname is specified, display it |
|
99 temp.iIdentification.Set( aIdentifications->MdcaPoint( i ) ); |
|
100 } |
|
101 |
|
102 } |
|
103 |
|
104 else |
|
105 { |
|
106 // otherwise display the wvid |
|
107 temp.iIdentification.Set( CCAPCUtils::DisplayId( |
|
108 aWVIds->MdcaPoint( i ) ) ); |
|
109 } |
|
110 |
|
111 temp.iNickName.Set( aNickNames->MdcaPoint( i ) ); |
|
112 temp.iWVID.Set( aWVIds->MdcaPoint( i ) ); |
|
113 |
|
114 if ( iShowContactExistInPhoneIcon ) |
|
115 { |
|
116 MCAStoredContact* contact = |
|
117 storageContacts->FindAnyContact( temp.iWVID ); |
|
118 if ( contact ) |
|
119 { |
|
120 temp.iExistInPhone = ETrue; |
|
121 } |
|
122 else |
|
123 { |
|
124 temp.iExistInPhone = EFalse; |
|
125 } |
|
126 } |
|
127 else |
|
128 { |
|
129 // not used in this case, |
|
130 // but just in case set some "default" value here |
|
131 temp.iExistInPhone = EFalse; |
|
132 } |
|
133 User::LeaveIfError( iServerContacts.Append( temp ) ); |
|
134 } |
|
135 |
|
136 Sort(); |
|
137 |
|
138 // Take the ownership here because we cannot leave anymore. |
|
139 iNickNames = aNickNames; |
|
140 if ( aIdentifications ) |
|
141 { |
|
142 iIdentifications = aIdentifications; |
|
143 } |
|
144 iWVIds = aWVIds; |
|
145 } |
|
146 |
|
147 |
|
148 // Symbian OS default constructor can leave. |
|
149 void CCAServerContactsArrayPC::ConstructL( |
|
150 RPointerArray<MCAStoredContact>& aContacts, |
|
151 const TDesC& aIconTabulator ) |
|
152 { |
|
153 CommonConstructL( aIconTabulator ); |
|
154 |
|
155 iNickNames = new ( ELeave ) CDesCArrayFlat( KArrayGranularity ); |
|
156 iWVIds = new ( ELeave ) CDesCArrayFlat( KArrayGranularity ); |
|
157 |
|
158 // create the identifications |
|
159 TInt count( aContacts.Count() ); |
|
160 |
|
161 TCAServerContact temp; |
|
162 for ( TInt i( 0 ); i < count; ++i ) |
|
163 { |
|
164 MCAStoredContact* contact = aContacts[ i ]; |
|
165 |
|
166 TPtrC wvid( contact->UserId() ); |
|
167 if ( wvid.Length() > 0 ) |
|
168 { |
|
169 // contact has WVID |
|
170 TPtrC nick( contact->Identification() ); |
|
171 |
|
172 iWVIds->AppendL( wvid ); |
|
173 iNickNames->AppendL( nick ); |
|
174 |
|
175 TInt pos( iWVIds->Count() - 1 ); |
|
176 |
|
177 if ( nick.Length() > 0 ) |
|
178 { |
|
179 // if the nickname is specified, display it |
|
180 temp.iIdentification.Set( iNickNames->MdcaPoint( pos ) ); |
|
181 } |
|
182 else |
|
183 { |
|
184 // otherwise display the wvid |
|
185 temp.iIdentification.Set( |
|
186 CCAPCUtils::DisplayId( iWVIds->MdcaPoint( pos ) ) ); |
|
187 } |
|
188 |
|
189 temp.iNickName.Set( iNickNames->MdcaPoint( pos ) ); |
|
190 temp.iWVID.Set( iWVIds->MdcaPoint( pos ) ); |
|
191 temp.iExistInPhone = EFalse; |
|
192 } |
|
193 |
|
194 User::LeaveIfError( iServerContacts.Append( temp ) ); |
|
195 } |
|
196 |
|
197 Sort(); |
|
198 } |
|
199 |
|
200 |
|
201 // Two-phased constructor. |
|
202 CCAServerContactsArrayPC* CCAServerContactsArrayPC::NewL( |
|
203 CDesCArray* aNickNames, |
|
204 CDesCArray* aWVIds, |
|
205 const TDesC& aIconTabulator /* = KTab */, |
|
206 CDesCArray* aIdentifications /* = NULL */, |
|
207 TBool aShowContactExistInPhoneIcon /* = EFalse */ |
|
208 ) |
|
209 { |
|
210 CCAServerContactsArrayPC* self = |
|
211 new( ELeave ) CCAServerContactsArrayPC( aShowContactExistInPhoneIcon ); |
|
212 |
|
213 CleanupStack::PushL( self ); |
|
214 self->ConstructL( aNickNames, aWVIds, aIconTabulator, aIdentifications ); |
|
215 CleanupStack::Pop( self ); |
|
216 |
|
217 return self; |
|
218 } |
|
219 |
|
220 // Two-phased constructor. |
|
221 CCAServerContactsArrayPC* CCAServerContactsArrayPC::NewL( |
|
222 RPointerArray<MCAStoredContact>& aContacts, |
|
223 const TDesC& aIconTabulator /*= KTab */, |
|
224 TBool aShowContactExistInPhoneIcon /*= EFalse*/ ) |
|
225 { |
|
226 CCAServerContactsArrayPC* self = |
|
227 new( ELeave ) CCAServerContactsArrayPC( aShowContactExistInPhoneIcon ); |
|
228 |
|
229 CleanupStack::PushL( self ); |
|
230 self->ConstructL( aContacts, aIconTabulator ); |
|
231 CleanupStack::Pop( self ); |
|
232 |
|
233 return self; |
|
234 } |
|
235 |
|
236 // Destructor |
|
237 CCAServerContactsArrayPC::~CCAServerContactsArrayPC() |
|
238 { |
|
239 iServerContacts.Close(); |
|
240 delete iNickNames; |
|
241 delete iIdentifications; |
|
242 delete iWVIds; |
|
243 delete iLine; |
|
244 delete iIconTabulator; |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------- |
|
248 // CCAServerContactsArray::MdcaCount() const |
|
249 // Returns number of items in array |
|
250 // (other items were commented in a header). |
|
251 // --------------------------------------------------------- |
|
252 // |
|
253 TInt CCAServerContactsArrayPC::MdcaCount() const |
|
254 { |
|
255 return iServerContacts.Count(); |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------- |
|
259 // CCAServerContactsArray::MdcaPoint() |
|
260 // (other items were commented in a header). |
|
261 // --------------------------------------------------------- |
|
262 // |
|
263 TPtrC CCAServerContactsArrayPC::MdcaPoint( TInt aIndex ) const |
|
264 { |
|
265 CHAT_DP( D_CHAT_LIT( "CCAServerContactsArray::MdcaPoint [%d]" ), aIndex ); |
|
266 __ASSERT_DEBUG( aIndex >= 0 && aIndex < iServerContacts.Count(), |
|
267 User::Panic( KPanicText, KErrArgument ) ); |
|
268 |
|
269 |
|
270 TPtr data( iLine->Des() ); |
|
271 |
|
272 data.Copy( ( *iIconTabulator ).Left( data.MaxLength() ) ); |
|
273 data.Append( iServerContacts[ aIndex ].iIdentification ); |
|
274 |
|
275 if ( iServerContacts[ aIndex ].iExistInPhone ) |
|
276 { |
|
277 data.Append( KContactExistInPhoneIcon ); |
|
278 } |
|
279 |
|
280 return iLine->Des(); |
|
281 } |
|
282 |
|
283 |
|
284 // --------------------------------------------------------- |
|
285 // CCAServerContactsArray::Sort() |
|
286 // (other items were commented in a header). |
|
287 // --------------------------------------------------------- |
|
288 // |
|
289 void CCAServerContactsArrayPC::Sort() |
|
290 { |
|
291 TLinearOrder<TCAServerContact> linOrder( *CCAServerContactsArrayCompare ); |
|
292 iServerContacts.Sort( linOrder ); |
|
293 } |
|
294 |
|
295 |
|
296 // --------------------------------------------------------- |
|
297 // CCAServerContactsArray::AddL() |
|
298 // (other items were commented in a header). |
|
299 // --------------------------------------------------------- |
|
300 // |
|
301 void CCAServerContactsArrayPC::AddL( const TDesC& aNickName, const TDesC& aWVId ) |
|
302 { |
|
303 if ( Find( aWVId ) != KErrNotFound ) |
|
304 { |
|
305 // contact with same wv id already exists |
|
306 return; |
|
307 } |
|
308 |
|
309 // get the copy of the descriptors |
|
310 iNickNames->AppendL( aNickName ); |
|
311 iWVIds->AppendL( aWVId ); |
|
312 TInt nickPos( iNickNames->MdcaCount() - 1 ); |
|
313 TInt wvidPos( iWVIds->MdcaCount() - 1 ); |
|
314 |
|
315 TCAServerContact temp; |
|
316 if ( aNickName.Length() > 0 ) |
|
317 { |
|
318 // if the nickname is specified, display it |
|
319 temp.iIdentification.Set( iNickNames->MdcaPoint( nickPos ) ); |
|
320 } |
|
321 else |
|
322 { |
|
323 // otherwise display the wvid |
|
324 temp.iIdentification.Set( CCAPCUtils::DisplayId( |
|
325 iWVIds->MdcaPoint( wvidPos ) ) ); |
|
326 } |
|
327 |
|
328 temp.iNickName.Set( iNickNames->MdcaPoint( nickPos ) ); |
|
329 temp.iWVID.Set( iWVIds->MdcaPoint( wvidPos ) ); |
|
330 |
|
331 MCAStoredContacts* storageContacts = |
|
332 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
333 |
|
334 if ( iShowContactExistInPhoneIcon ) |
|
335 { |
|
336 MCAStoredContact* contact = |
|
337 storageContacts->FindAnyContact( temp.iWVID ); |
|
338 if ( contact ) |
|
339 { |
|
340 temp.iExistInPhone = ETrue; |
|
341 } |
|
342 else |
|
343 { |
|
344 temp.iExistInPhone = EFalse; |
|
345 } |
|
346 } |
|
347 else |
|
348 { |
|
349 // not used in this case, |
|
350 // but just in case set some "default" value here |
|
351 temp.iExistInPhone = EFalse; |
|
352 } |
|
353 |
|
354 User::LeaveIfError( iServerContacts.Append( temp ) ); |
|
355 Sort(); |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------- |
|
359 // CCAServerContactsArray::Remove() |
|
360 // (other items were commented in a header). |
|
361 // --------------------------------------------------------- |
|
362 // |
|
363 void CCAServerContactsArrayPC::Remove( TInt aIndex ) |
|
364 { |
|
365 CHAT_DP( D_CHAT_LIT( "CCAServerContactsArray::Remove %d" ), aIndex ); |
|
366 if ( ( aIndex >= 0 ) && ( aIndex < iServerContacts.Count() ) ) |
|
367 { |
|
368 TInt pos; |
|
369 iWVIds->Find( iServerContacts[ aIndex ].iWVID, pos, ECmpCollated ); |
|
370 iWVIds->Delete( pos ); |
|
371 iWVIds->Compress(); |
|
372 iNickNames->Delete( pos ); |
|
373 iNickNames->Compress(); |
|
374 iIdentifications->Delete( pos ); |
|
375 iIdentifications->Compress( ); |
|
376 iServerContacts.Remove( aIndex ); |
|
377 iServerContacts.Compress(); |
|
378 } |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------- |
|
382 // CCAServerContactsArray::Find() |
|
383 // (other items were commented in a header). |
|
384 // --------------------------------------------------------- |
|
385 // |
|
386 TInt CCAServerContactsArrayPC::Find( const TDesC& aWVId ) const |
|
387 { |
|
388 TInt count( iServerContacts.Count() ); |
|
389 CHAT_DP( D_CHAT_LIT( "CCAServerContactsArray::Find::%S" ), &aWVId ); |
|
390 |
|
391 for ( TInt i( 0 ); i < count; ++i ) |
|
392 { |
|
393 if ( CAUtils::NeutralCompare( iServerContacts[i].iWVID, aWVId ) == 0 ) |
|
394 { |
|
395 CHAT_DP( D_CHAT_LIT( "CCAServerContactsArray::Find::found!" ), |
|
396 i, count ); |
|
397 return i; |
|
398 } |
|
399 } |
|
400 CHAT_DP( D_CHAT_LIT( "CCAServerContactsArray::Find::not found!" ) ); |
|
401 return KErrNotFound; |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------- |
|
405 // CCAServerContactsArray::WVIDArray() |
|
406 // (other items were commented in a header). |
|
407 // --------------------------------------------------------- |
|
408 // |
|
409 const MDesCArray& CCAServerContactsArrayPC::WVIDArray() const |
|
410 { |
|
411 return *iWVIds; |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------- |
|
415 // CCAServerContactsArray::WVIdL() |
|
416 // (other items were commented in a header). |
|
417 // --------------------------------------------------------- |
|
418 // |
|
419 const TCAServerContact* CCAServerContactsArrayPC::WVIdL( TInt aIndex, |
|
420 const TDesC& aFindBoxTxt /*= KNullDesC*/ ) const |
|
421 // Simulate the findPane functionality when getting the iSelectedItem |
|
422 // from the blockingArray structure |
|
423 { |
|
424 // check boundaries |
|
425 __ASSERT_ALWAYS( aIndex >= 0 || aIndex <= iServerContacts.Count(), |
|
426 User::Leave( KErrArgument ) ); |
|
427 |
|
428 if ( aFindBoxTxt == KNullDesC ) |
|
429 { |
|
430 return &iServerContacts[ aIndex ]; |
|
431 } |
|
432 else |
|
433 { |
|
434 //simulate the functionality of FindPane |
|
435 TInt count = iServerContacts.Count(); |
|
436 TInt findBoxTxtLen = aFindBoxTxt.Length(); |
|
437 TInt noOfFinds = -1; |
|
438 |
|
439 // Create custom collation method to ignore punctuations |
|
440 // index 0 gets the default method |
|
441 TCollationMethod collation = |
|
442 *Mem::CollationMethodByIndex( 0 ); |
|
443 collation.iFlags |= TCollationMethod::EIgnoreNone; |
|
444 |
|
445 for ( TInt index = 0; index < count; index++ ) |
|
446 { |
|
447 |
|
448 HBufC* toVerifyBuf; |
|
449 |
|
450 // Search the findPane text against the blocked items Nickname or Id |
|
451 if ( iServerContacts[ index ].iNickName.Length() > 0 ) |
|
452 { |
|
453 // If the user has nick name |
|
454 toVerifyBuf = iServerContacts[ index ].iNickName.Left( findBoxTxtLen ).AllocLC(); |
|
455 } |
|
456 else |
|
457 { |
|
458 // If not directly go to the user id |
|
459 toVerifyBuf = iServerContacts[ index ].iIdentification.Left( findBoxTxtLen ).AllocLC(); |
|
460 } |
|
461 |
|
462 TInt idResult = toVerifyBuf->CompareC( aFindBoxTxt, KCollationLevel, &collation ); |
|
463 |
|
464 // Popup and destory the the buffer |
|
465 CleanupStack::PopAndDestroy( toVerifyBuf ); |
|
466 |
|
467 |
|
468 if ( idResult == 0 ) |
|
469 { |
|
470 //there can be more than 1 item with the same findPanetext |
|
471 //so find the exact item which was selected in the UI |
|
472 noOfFinds++; |
|
473 |
|
474 if ( noOfFinds == aIndex ) |
|
475 { |
|
476 //found the exact item |
|
477 return &iServerContacts[ index ]; |
|
478 } |
|
479 } |
|
480 |
|
481 } |
|
482 } |
|
483 |
|
484 //cannot get here |
|
485 User::Leave( KErrArgument ); |
|
486 return NULL; |
|
487 |
|
488 } |
|
489 |
|
490 // --------------------------------------------------------- |
|
491 // CCAServerContactsArray::NickNameArray() |
|
492 // (other items were commented in a header). |
|
493 // --------------------------------------------------------- |
|
494 // |
|
495 const MDesCArray& CCAServerContactsArrayPC::NickNameArray() const |
|
496 { |
|
497 return *iNickNames; |
|
498 } |
|
499 |
|
500 |
|
501 // --------------------------------------------------------- |
|
502 // CCAServerContactsArray::ReplaceL() |
|
503 // (other items were commented in a header). |
|
504 // --------------------------------------------------------- |
|
505 // |
|
506 void CCAServerContactsArrayPC::ReplaceL( CDesCArray* aNickNames, |
|
507 CDesCArray* aWVIds, |
|
508 const TDesC& aIconTabulator, |
|
509 CDesCArray* aIdentifications /* NULL */ ) |
|
510 { |
|
511 iServerContacts.Close(); |
|
512 delete iNickNames; |
|
513 iNickNames = NULL; |
|
514 delete iIdentifications; |
|
515 iIdentifications = NULL; |
|
516 delete iWVIds; |
|
517 iWVIds = NULL; |
|
518 delete iLine; |
|
519 iLine = NULL; |
|
520 delete iIconTabulator; |
|
521 iIconTabulator = NULL; |
|
522 |
|
523 ConstructL( aNickNames, aWVIds, aIconTabulator, aIdentifications ); |
|
524 } |
|
525 |
|
526 // End of File |