|
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: contact handler class implementaion to virtual phonebook observers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cvimpstdetailscontacthandler.h" |
|
20 |
|
21 #include "mvimpstdetailsviewcontactobserver.h" |
|
22 #include "cvimpstdetailsviewplugin.h" |
|
23 |
|
24 #include "tvimpstconsts.h" |
|
25 #include "vimpstdetailsviewpluginuids.hrh" |
|
26 #include <vimpstdetailsviewpluginrsc.rsg> |
|
27 |
|
28 // virtual phonebook |
|
29 #include <CVPbkContactManager.h> |
|
30 #include <MVPbkContactOperationBase.h> |
|
31 #include <MVPbkContactLinkArray.h> |
|
32 #include <MVPbkFieldType.h> |
|
33 #include <MVPbkStoreContact.h> |
|
34 #include <MVPbkContactStore.h> |
|
35 #include <MVPbkContactStoreProperties.h> |
|
36 #include <VPbkEng.rsg> |
|
37 #include <CVPbkContactStoreUriArray.h> |
|
38 #include <MVPbkContactStoreList.h> |
|
39 #include <CVPbkContactLinkArray.h> |
|
40 #include <TVPbkContactStoreUriPtr.h> |
|
41 #include <MVPbkContactFieldData.h> |
|
42 #include <MVPbkContactFieldUriData.h> |
|
43 #include <MVPbkContactLink.h> |
|
44 #include <VPbkContactStoreUris.h> |
|
45 // cca |
|
46 #include <mccapppluginparameter.h> |
|
47 #include <mccaparameter.h> |
|
48 #include <imconnectionproviderconsts.h> |
|
49 #include <MVPbkContactFieldTextData.h> |
|
50 // system include |
|
51 #include <e32property.h> |
|
52 #include <s32mem.h> |
|
53 |
|
54 |
|
55 #include "uiservicetabtracer.h" |
|
56 #include "vimpstutils.h" |
|
57 |
|
58 // ======== LOCAL FUNCTIONS ======== |
|
59 |
|
60 // ======== MEMBER FUNCTIONS ======== |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CVIMPSTDetailsContactHandler::NewL |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CVIMPSTDetailsContactHandler* CVIMPSTDetailsContactHandler::NewL( MCCAParameter& aParameter , |
|
67 MVIMPSTDetailsViewContactObserver& aObserver, |
|
68 const TDesC& aServiceStoreUri, |
|
69 const TDesC& aServiceName, |
|
70 TUint aserviceId |
|
71 ) |
|
72 { |
|
73 TRACER_AUTO; |
|
74 CVIMPSTDetailsContactHandler* self = |
|
75 new(ELeave) CVIMPSTDetailsContactHandler( aObserver, aserviceId ); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL( aParameter, aServiceStoreUri, aServiceName ); |
|
78 CleanupStack::Pop(self); |
|
79 return self; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CVIMPSTDetailsContactHandler::~CVIMPSTDetailsContactHandler |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 CVIMPSTDetailsContactHandler::~CVIMPSTDetailsContactHandler() |
|
87 { |
|
88 |
|
89 TRACER_AUTO; |
|
90 Cancel(); |
|
91 if (iWait.IsStarted()) |
|
92 { |
|
93 iWait.AsyncStop(); |
|
94 } |
|
95 delete iLinks; |
|
96 delete iRetrieveOperation; |
|
97 delete iXSPUserId; |
|
98 delete iStoreContact; |
|
99 if (iStoreList) |
|
100 { |
|
101 |
|
102 TRACE("calling store close"); |
|
103 iStoreList->CloseAll(*this); |
|
104 iStoreList = NULL; |
|
105 } |
|
106 TRACE("iStoreList deleted"); |
|
107 delete iServiceStoreUri; |
|
108 TRACE("iServiceStoreUri deleted"); |
|
109 delete iContactManager; |
|
110 TRACE("iContactManager deleted"); |
|
111 delete iServiceName; |
|
112 TRACE("iServiceName deleted"); |
|
113 delete iIdConverter; |
|
114 |
|
115 |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CVIMPSTDetailsContactHandler::CVIMPSTDetailsContactHandler |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 CVIMPSTDetailsContactHandler::CVIMPSTDetailsContactHandler( |
|
123 MVIMPSTDetailsViewContactObserver& aObserver,TUint aServiceId ) |
|
124 : CActive(EPriorityStandard), |
|
125 iObserver( aObserver ), |
|
126 iStoreType( EStoreUnkwon ), |
|
127 iServiceId (aServiceId ) |
|
128 { |
|
129 CActiveScheduler::Add(this); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CVIMPSTDetailsContactHandler::ConstructL |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CVIMPSTDetailsContactHandler::ConstructL( MCCAParameter& aParameter ,const TDesC& aServiceStoreUri,const TDesC& aServiceName ) |
|
137 { |
|
138 |
|
139 TRACER_AUTO; |
|
140 CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewLC(); |
|
141 TUid launchUid = TUid::Null() ; |
|
142 iServiceStoreUri = aServiceStoreUri.AllocL(); |
|
143 iServiceName = aServiceName.AllocL(); |
|
144 //find whether its a local store or xsp store |
|
145 if ( iServiceStoreUri && VPbkContactStoreUris::DefaultCntDbUri().Compare( *iServiceStoreUri ) |
|
146 != 0 ) |
|
147 { |
|
148 iStoreType = EStoreServer; // store has xsp store |
|
149 } |
|
150 else |
|
151 { |
|
152 iStoreType = EStoreLocal; // same as phonebook2 store name |
|
153 } |
|
154 launchUid = aParameter.LaunchedViewUid(); |
|
155 //always load the default store plus the corresponding service store |
|
156 uriArray->AppendL(TVPbkContactStoreUriPtr(VPbkContactStoreUris::DefaultCntDbUri())); |
|
157 if( launchUid.iUid != (KVIMPSTDetailsViewPluginImplmentationUid + iServiceId) ) |
|
158 { |
|
159 // launched from other than service tab |
|
160 // need to open service store |
|
161 if ( iServiceStoreUri ) |
|
162 { |
|
163 TPtr serviceStoreNamePtr = iServiceStoreUri->Des(); |
|
164 uriArray->AppendL( TVPbkContactStoreUriPtr( serviceStoreNamePtr ) ); |
|
165 TRACE("ServiceStoreUriL() - storename3: %S", &serviceStoreNamePtr); |
|
166 } |
|
167 } |
|
168 |
|
169 HBufC& contactData = aParameter.ContactDataL(); |
|
170 |
|
171 HBufC8* buf = HBufC8::NewLC( contactData.Length() ); |
|
172 buf->Des().Copy(contactData); |
|
173 TPtrC8 bufDes( buf->Des() ); |
|
174 |
|
175 RDesReadStream readStream( bufDes ); |
|
176 readStream.PushL(); |
|
177 |
|
178 const TInt versionNumber = readStream.ReadUint8L(); |
|
179 |
|
180 TInt uriCount = readStream.ReadUint16L(); |
|
181 TRACE("ServiceStoreUriL() - uriCount = %d", uriCount); |
|
182 // Read URIs |
|
183 for ( TInt i = 0; i < uriCount; ++i ) |
|
184 { |
|
185 const TInt uriLength = readStream.ReadUint16L(); |
|
186 HBufC* uriBuffer = HBufC::NewLC(uriLength); |
|
187 TPtr uriPtr = uriBuffer->Des(); |
|
188 readStream.ReadL( uriPtr, uriLength ); |
|
189 if( uriPtr.Length() > 0 ) |
|
190 { |
|
191 uriArray->AppendL( TVPbkContactStoreUriPtr( uriPtr ) ); |
|
192 TRACE("ServiceStoreUriL() - storename4: %S", &uriPtr); |
|
193 } |
|
194 CleanupStack::PopAndDestroy( uriBuffer ); |
|
195 } |
|
196 CleanupStack::PopAndDestroy(); // readStream |
|
197 CleanupStack::PopAndDestroy(); // buf |
|
198 |
|
199 |
|
200 iContactManager = CVPbkContactManager::NewL(*uriArray); |
|
201 CleanupStack::PopAndDestroy(); // uriArray |
|
202 |
|
203 iStoreList = &iContactManager->ContactStoresL(); |
|
204 iStoreList->OpenAllL(*this); |
|
205 |
|
206 if( !iWait.IsStarted() ) |
|
207 { |
|
208 iWait.Start(); |
|
209 } |
|
210 if(iStoreType == EStoreLocal) |
|
211 { |
|
212 const TDesC& contactdb = VPbkContactStoreUris::DefaultCntDbUri(); |
|
213 MVPbkContactStore* contactStore = iStoreList->Find(TVPbkContactStoreUriPtr(contactdb)); |
|
214 iIdConverter = CVPbkContactIdConverter::NewL(*contactStore); |
|
215 } |
|
216 |
|
217 } |
|
218 |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // CVIMPSTDetailsContactHandler::GetDisplayNameLC |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 HBufC* CVIMPSTDetailsContactHandler::GetDisplayNameLC() |
|
225 { |
|
226 TRACER_AUTO; |
|
227 HBufC* firstName = KNullDesC().AllocL(); |
|
228 HBufC* lastName = KNullDesC().AllocL(); |
|
229 HBufC* retValue = NULL; |
|
230 if( iStoreContact ) |
|
231 { |
|
232 MVPbkStoreContactFieldCollection& fieldCollection = iStoreContact->Fields(); |
|
233 TInt fieldCount = fieldCollection.FieldCount(); |
|
234 for( TInt i=0; i< fieldCount; i++ ) |
|
235 { |
|
236 MVPbkStoreContactField& field = fieldCollection.FieldAt( i ); |
|
237 const MVPbkFieldType* type = field.BestMatchingFieldType() ; |
|
238 if( R_VPBK_FIELD_TYPE_FIRSTNAME == type->FieldTypeResId() ) |
|
239 { |
|
240 const MVPbkContactFieldData& fieldData = field.FieldData(); |
|
241 if( fieldData.DataType() == EVPbkFieldStorageTypeText ) |
|
242 { |
|
243 delete firstName; |
|
244 firstName = MVPbkContactFieldTextData::Cast(fieldData).Text().AllocL(); |
|
245 break; |
|
246 } |
|
247 } |
|
248 } |
|
249 for( TInt i=0; i< fieldCount; i++ ) |
|
250 { |
|
251 MVPbkStoreContactField& field = fieldCollection.FieldAt( i ); |
|
252 const MVPbkFieldType* type = field.BestMatchingFieldType() ; |
|
253 if( R_VPBK_FIELD_TYPE_LASTNAME == type->FieldTypeResId() ) |
|
254 { |
|
255 const MVPbkContactFieldData& fieldData = field.FieldData(); |
|
256 if( fieldData.DataType() == EVPbkFieldStorageTypeText ) |
|
257 { |
|
258 delete lastName; |
|
259 lastName = MVPbkContactFieldTextData::Cast(fieldData).Text().AllocL(); |
|
260 break; |
|
261 } |
|
262 } |
|
263 } |
|
264 TPtr ptrFirstName = firstName->Des(); |
|
265 TPtr ptrLastName = lastName->Des(); |
|
266 if(ptrFirstName.Length() || ptrLastName.Length()) |
|
267 { |
|
268 retValue = HBufC::NewLC(ptrFirstName.Length()+ ptrLastName.Length() + 1); |
|
269 TPtr ptrRet = retValue->Des(); |
|
270 ptrRet.Append(ptrFirstName); |
|
271 if(ptrFirstName.Length()) |
|
272 { |
|
273 //append one space before appending lastname |
|
274 ptrRet.Append(' '); |
|
275 } |
|
276 ptrRet.Append(ptrLastName); |
|
277 } |
|
278 else |
|
279 { |
|
280 retValue = VIMPSTUtils::LoadResourceL( R_SERVDETAIL_UNNAMED ); |
|
281 CleanupStack::PushL(retValue); |
|
282 } |
|
283 } |
|
284 delete firstName; |
|
285 delete lastName; |
|
286 return retValue; |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // CVIMPSTDetailsContactHandler:: |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 void CVIMPSTDetailsContactHandler::SetLinks( |
|
294 MVPbkContactLinkArray* aLinks, TBool aReadXspId ) |
|
295 { |
|
296 |
|
297 TRACER_AUTO; |
|
298 delete iLinks; |
|
299 iLinks = NULL; |
|
300 iLinks = aLinks; |
|
301 TRACE("iLinks deleted"); |
|
302 iCurrentLink = NULL; |
|
303 |
|
304 iReadXspId = aReadXspId; |
|
305 if( iRetrieveOperation ) |
|
306 { |
|
307 delete iRetrieveOperation; |
|
308 iRetrieveOperation = NULL; |
|
309 TRACE("iRetrieveOperation deleted"); |
|
310 } |
|
311 TRACE("calling issue request"); |
|
312 IssueRequest(); |
|
313 |
|
314 } |
|
315 |
|
316 // --------------------------------------------------------------------------- |
|
317 // CVIMPSTDetailsContactHandler::Links |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 MVPbkContactLinkArray* CVIMPSTDetailsContactHandler::Links() const |
|
321 { |
|
322 return iLinks; |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CVIMPSTDetailsContactHandler::GetXSPUserId |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 const TDesC& CVIMPSTDetailsContactHandler::GetXSPUserId() |
|
330 { |
|
331 if( iXSPUserId ) |
|
332 { |
|
333 return *iXSPUserId; |
|
334 } |
|
335 return KNullDesC; |
|
336 } |
|
337 |
|
338 // -------------------------------------------------------------------------- |
|
339 // CVIMPSTDetailsContactHandler::ContactStoresL |
|
340 // -------------------------------------------------------------------------- |
|
341 // |
|
342 MVPbkContactStoreList& CVIMPSTDetailsContactHandler::ContactStoresL() |
|
343 { |
|
344 return *iStoreList; |
|
345 } |
|
346 // -------------------------------------------------------------------------- |
|
347 // CVIMPSTDetailsContactHandler::StoreType |
|
348 // -------------------------------------------------------------------------- |
|
349 // |
|
350 TStoreType CVIMPSTDetailsContactHandler::StoreType() |
|
351 { |
|
352 return iStoreType; |
|
353 } |
|
354 |
|
355 // ------------------------------------------------------------------------- |
|
356 // CVIMPSTDetailsContactHandler::CancelOngoingRequest |
|
357 // -------------------------------------------------------------------------- |
|
358 // |
|
359 void CVIMPSTDetailsContactHandler::CancelOngoingRequest() |
|
360 { |
|
361 TRACER_AUTO; |
|
362 delete iRetrieveOperation; |
|
363 iRetrieveOperation = NULL; |
|
364 TRACE("iRetrieveOperation deleted"); |
|
365 delete iXSPUserId; |
|
366 iXSPUserId = NULL; |
|
367 TRACE("iXSPUserId deleted"); |
|
368 delete iStoreContact; |
|
369 iStoreContact = NULL; |
|
370 TRACE("iStoreContact deleted"); |
|
371 delete iLinks; |
|
372 iLinks = NULL; |
|
373 |
|
374 } |
|
375 // --------------------------------------------------------------------------- |
|
376 // CVIMPSTDetailsContactHandler::RunL |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 void CVIMPSTDetailsContactHandler::RunL() |
|
380 { |
|
381 |
|
382 TRACER_AUTO; |
|
383 TInt index = 0; |
|
384 if (iLinks && iCurrentLink ) |
|
385 { |
|
386 TRACE("next link"); |
|
387 index = iLinks->Find(*iCurrentLink) + 1; |
|
388 } |
|
389 if ( iLinks && index < iLinks->Count() ) |
|
390 { |
|
391 TRACE("calling retrive"); |
|
392 // will get called until the index become equal to count |
|
393 iCurrentLink = &iLinks->At(index); |
|
394 TRAPD( err, iRetrieveOperation = iContactManager->RetrieveContactL(*iCurrentLink, *this) ); |
|
395 TRACE("retrive called err = %d", err); |
|
396 } |
|
397 else |
|
398 { |
|
399 TRACE("job finished"); |
|
400 iCurrentLink = NULL; |
|
401 } |
|
402 |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------------------------- |
|
406 // CVIMPSTDetailsContactHandler::RunError |
|
407 // --------------------------------------------------------------------------- |
|
408 // |
|
409 TInt CVIMPSTDetailsContactHandler::RunError(TInt aError) |
|
410 { |
|
411 return aError; |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // CVIMPSTDetailsContactHandler::DoCancel |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 void CVIMPSTDetailsContactHandler::DoCancel() |
|
419 { |
|
420 } |
|
421 |
|
422 |
|
423 // --------------------------------------------------------------------------- |
|
424 // CVIMPSTDetailsContactHandler::VPbkSingleContactOperationComplete |
|
425 // --------------------------------------------------------------------------- |
|
426 // |
|
427 void CVIMPSTDetailsContactHandler::VPbkSingleContactOperationComplete( |
|
428 MVPbkContactOperationBase& /*aOperation*/, |
|
429 MVPbkStoreContact* aContact) |
|
430 { |
|
431 TRACER_AUTO; |
|
432 TBool isIssueReguest = ETrue; |
|
433 |
|
434 delete iRetrieveOperation; |
|
435 iRetrieveOperation = NULL; |
|
436 |
|
437 delete iStoreContact; |
|
438 iStoreContact = NULL; |
|
439 iStoreContact = aContact; |
|
440 |
|
441 if( iStoreContact && iReadXspId ) |
|
442 { |
|
443 MVPbkStoreContactFieldCollection& fieldCollection = iStoreContact->Fields(); |
|
444 |
|
445 TInt fieldCount = fieldCollection.FieldCount(); |
|
446 |
|
447 for( TInt i=0; i< fieldCount; i++ ) |
|
448 { |
|
449 MVPbkStoreContactField& field = fieldCollection.FieldAt( i ); |
|
450 const MVPbkFieldType* type = field.BestMatchingFieldType() ; |
|
451 if( R_VPBK_FIELD_TYPE_IMPP == type->FieldTypeResId() ) |
|
452 { |
|
453 const MVPbkContactFieldData& fieldData = field.FieldData(); |
|
454 if( fieldData.DataType() == EVPbkFieldStorageTypeUri ) |
|
455 { |
|
456 TPtrC scheme = MVPbkContactFieldUriData::Cast(fieldData).Scheme(); |
|
457 if(iServiceName->Compare(scheme) == 0) |
|
458 { |
|
459 TRACE("EVPbkFieldStorageTypeUri called"); |
|
460 const MVPbkContactFieldUriData& uri = MVPbkContactFieldUriData::Cast(fieldData); |
|
461 HBufC* user = NULL; |
|
462 delete iXSPUserId; |
|
463 iXSPUserId = NULL; |
|
464 // call back api is not leaving function |
|
465 TRAP_IGNORE( user = uri.Uri().AllocL() ; |
|
466 if( user ) |
|
467 { |
|
468 CleanupStack::PushL( user ); |
|
469 TPtr userPtr( user->Des() ); |
|
470 TInt index = userPtr.Find( KColon ); |
|
471 if( index != KErrNotFound ) |
|
472 { |
|
473 TInt length = userPtr.Length(); |
|
474 iXSPUserId = userPtr.Right( length - index - 1 ).AllocL() ; |
|
475 } |
|
476 CleanupStack::PopAndDestroy();// user |
|
477 } |
|
478 TRACE("EVPbkFieldStorageTypeUri end"); |
|
479 ); |
|
480 break; |
|
481 } |
|
482 } |
|
483 } |
|
484 } |
|
485 if( iXSPUserId && iContactManager ) |
|
486 { |
|
487 |
|
488 TRACE("search is called"); |
|
489 // call back api is not leaving function |
|
490 TRAP_IGNORE( iRetrieveOperation = iContactManager->FindL(*iXSPUserId, iContactManager->FieldTypes(),*this) ); |
|
491 isIssueReguest = EFalse; |
|
492 } |
|
493 else |
|
494 { |
|
495 // call back api is not leaving function |
|
496 TRAP_IGNORE( iObserver.HandleContactUnavailableL() ); |
|
497 } |
|
498 } |
|
499 else if( iStoreContact ) |
|
500 { |
|
501 |
|
502 TRACE("iStoreContact Valid"); |
|
503 TBool validLink = ETrue; |
|
504 if( iStoreType == EStoreLocal && iCurrentLink ) |
|
505 { |
|
506 //Local Store |
|
507 // to check whether this contact has been added to the ServiceTab. with the help of db file |
|
508 validLink = CheckWhetherValidLocalLinkL( *iCurrentLink); |
|
509 } |
|
510 if( validLink ) |
|
511 { |
|
512 |
|
513 TRACE("HandleContactReadyL "); |
|
514 TRAP_IGNORE( iObserver.HandleContactReadyL( *iStoreContact ) ); |
|
515 } |
|
516 else |
|
517 { |
|
518 |
|
519 TRACE("No data "); |
|
520 TRAP_IGNORE( iObserver.HandleContactUnavailableL() ); |
|
521 } |
|
522 } |
|
523 if( isIssueReguest ) |
|
524 { |
|
525 IssueRequest(); |
|
526 } |
|
527 |
|
528 } |
|
529 |
|
530 // --------------------------------------------------------------------------- |
|
531 // CVIMPSTDetailsContactHandler::VPbkSingleContactOperationFailed |
|
532 // --------------------------------------------------------------------------- |
|
533 // |
|
534 void CVIMPSTDetailsContactHandler::VPbkSingleContactOperationFailed( |
|
535 MVPbkContactOperationBase& /*aOperation*/, |
|
536 TInt /*aError*/) |
|
537 { |
|
538 |
|
539 TRACER_AUTO; |
|
540 delete iRetrieveOperation; |
|
541 iRetrieveOperation = NULL; |
|
542 |
|
543 TInt index = 0; |
|
544 if (iLinks && iCurrentLink) |
|
545 { |
|
546 index = iLinks->Find(*iCurrentLink) + 1; |
|
547 |
|
548 if ( index >= iLinks->Count() ) |
|
549 { |
|
550 |
|
551 TRACE("calling HandleContactUnavailableL start "); |
|
552 TRAP_IGNORE( iObserver.HandleContactUnavailableL() ); |
|
553 |
|
554 TRACE("calling HandleContactUnavailableL end"); |
|
555 return; |
|
556 } |
|
557 } |
|
558 IssueRequest(); |
|
559 |
|
560 } |
|
561 |
|
562 // --------------------------------------------------------------------------- |
|
563 // CVIMPSTDetailsContactHandler::FindCompleteL |
|
564 // --------------------------------------------------------------------------- |
|
565 // |
|
566 void CVIMPSTDetailsContactHandler::FindCompleteL( MVPbkContactLinkArray* aResults ) |
|
567 { |
|
568 |
|
569 TRACER_AUTO; |
|
570 CVPbkContactLinkArray* linkArray = NULL; |
|
571 delete iRetrieveOperation; |
|
572 iRetrieveOperation = NULL; |
|
573 if( aResults && iServiceStoreUri ) |
|
574 { |
|
575 TInt linkCount = aResults->Count(); |
|
576 for( TInt a=0; a< linkCount; a++ ) |
|
577 { |
|
578 const MVPbkContactLink& link = aResults->At( a ) ; |
|
579 MVPbkContactStore& store = link.ContactStore(); |
|
580 const MVPbkContactStoreProperties& storeProperty = store.StoreProperties(); |
|
581 if( storeProperty.Uri().UriDes().Compare( *iServiceStoreUri ) == 0 ) |
|
582 { |
|
583 |
|
584 TRACE("one result found "); |
|
585 linkArray = CVPbkContactLinkArray::NewLC(); |
|
586 MVPbkContactLink* clone = link.CloneLC(); |
|
587 // take ownership clone |
|
588 linkArray->AppendL(clone); |
|
589 CleanupStack::Pop(2); // clone, linkArray |
|
590 TRACE("come out of loop "); |
|
591 break; |
|
592 } |
|
593 } |
|
594 } |
|
595 delete aResults; |
|
596 aResults = NULL; |
|
597 TRACE("aResults deleted "); |
|
598 if( linkArray ) |
|
599 { |
|
600 // take ownership linkArray |
|
601 SetLinks( linkArray, EFalse ); |
|
602 } |
|
603 else |
|
604 { |
|
605 iObserver.HandleContactUnavailableL(); |
|
606 } |
|
607 |
|
608 } |
|
609 // --------------------------------------------------------------------------- |
|
610 // CVIMPSTDetailsContactHandler:: |
|
611 // --------------------------------------------------------------------------- |
|
612 // |
|
613 void CVIMPSTDetailsContactHandler::FindFailed( TInt /*aError*/ ) |
|
614 { |
|
615 TRACER_AUTO; |
|
616 TRAP_IGNORE( iObserver.HandleContactUnavailableL() ); // takes ownership of contacts. |
|
617 } |
|
618 |
|
619 // --------------------------------------------------------------------------- |
|
620 // CVIMPSTDetailsContactHandler:: |
|
621 // --------------------------------------------------------------------------- |
|
622 // |
|
623 void CVIMPSTDetailsContactHandler::IssueRequest(TInt aError) |
|
624 { |
|
625 if( !IsActive() ) |
|
626 { |
|
627 SetActive(); |
|
628 TRequestStatus* status = &iStatus; |
|
629 User::RequestComplete(status, aError); |
|
630 } |
|
631 } |
|
632 |
|
633 // -------------------------------------------------------------------------- |
|
634 // CVIMPSTDetailsContactHandler::OpenComplete |
|
635 // -------------------------------------------------------------------------- |
|
636 // |
|
637 void CVIMPSTDetailsContactHandler::OpenComplete() |
|
638 { |
|
639 |
|
640 TRACER_AUTO; |
|
641 if (iWait.IsStarted()) |
|
642 { |
|
643 iWait.AsyncStop(); |
|
644 } |
|
645 |
|
646 } |
|
647 |
|
648 // -------------------------------------------------------------------------- |
|
649 // CVIMPSTDetailsContactHandler::StoreReady |
|
650 // -------------------------------------------------------------------------- |
|
651 // |
|
652 void CVIMPSTDetailsContactHandler::StoreReady(MVPbkContactStore& /*aContactStore*/ ) |
|
653 { |
|
654 |
|
655 TRACER_AUTO; |
|
656 } |
|
657 |
|
658 // -------------------------------------------------------------------------- |
|
659 // CVIMPSTDetailsContactHandler::StoreUnavailable |
|
660 // -------------------------------------------------------------------------- |
|
661 // |
|
662 void CVIMPSTDetailsContactHandler::StoreUnavailable( |
|
663 MVPbkContactStore& /*aContactStore*/, |
|
664 TInt /*aReason*/) |
|
665 { |
|
666 |
|
667 TRACER_AUTO; |
|
668 if (iWait.IsStarted()) |
|
669 { |
|
670 iWait.AsyncStop(); |
|
671 } |
|
672 |
|
673 } |
|
674 |
|
675 // ------------------------------------------------------------------------- |
|
676 // CVIMPSTDetailsContactHandler::HandleStoreEventL |
|
677 // -------------------------------------------------------------------------- |
|
678 // |
|
679 void CVIMPSTDetailsContactHandler::HandleStoreEventL( |
|
680 MVPbkContactStore& /*aContactStore*/, |
|
681 TVPbkContactStoreEvent /*aStoreEvent*/) |
|
682 { |
|
683 |
|
684 } |
|
685 |
|
686 // ----------------------------------------------------------- |
|
687 // CVIMPSTDetailsContactHandler::CheckWhetherValidLocalLink |
|
688 // ----------------------------------------------------------- |
|
689 // |
|
690 |
|
691 TBool CVIMPSTDetailsContactHandler::CheckWhetherValidLocalLinkL( |
|
692 const MVPbkContactLink& aCurrentLink ) |
|
693 { |
|
694 TRACER_AUTO; |
|
695 TBool validLocalLink = EFalse; |
|
696 User::LeaveIfError( iFs.Connect() ); |
|
697 // Open existing or create new database. |
|
698 if ( DbExists() ) |
|
699 { |
|
700 OpenDbL(); |
|
701 OpenTableL(); |
|
702 // Get Column number for contact data size |
|
703 iColset = iDb.ColSetL( KContactTable ); |
|
704 TInt32 linkId = iIdConverter->LinkToIdentifier(aCurrentLink); |
|
705 TDbColNo colNo = iColset->ColNo( KContactId ); |
|
706 validLocalLink = SeekRowL( colNo, linkId ); |
|
707 CloseDb(); |
|
708 } |
|
709 return validLocalLink; |
|
710 } |
|
711 |
|
712 //******************* Database Operations *********************************// |
|
713 // ----------------------------------------------------------- |
|
714 // CVIMPSTDetailsContactHandler::DbExists |
|
715 // ----------------------------------------------------------- |
|
716 // |
|
717 TBool CVIMPSTDetailsContactHandler::DbExists() |
|
718 { |
|
719 TRACER_AUTO; |
|
720 TBuf<512> dbName; |
|
721 RFile temp; |
|
722 TBuf< KMaxPath > storagePath; |
|
723 |
|
724 dbName.Append( iServiceName->Des() ); |
|
725 dbName.Append( KStorageExtn ); |
|
726 |
|
727 storagePath.Append( KDbPath ); |
|
728 storagePath.Append( dbName ); |
|
729 |
|
730 TInt err( temp.Open( iFs, *(&storagePath), EFileShareReadersOrWriters|EFileRead ) ); |
|
731 |
|
732 TInt size( 0 ); |
|
733 if ( err == KErrNone ) |
|
734 { |
|
735 temp.Size( size ); |
|
736 } |
|
737 |
|
738 temp.Close(); |
|
739 |
|
740 if ( size == 0 ) |
|
741 { |
|
742 return EFalse; |
|
743 } |
|
744 |
|
745 return ( err == KErrNone ); |
|
746 } |
|
747 |
|
748 |
|
749 |
|
750 // ----------------------------------------------------------- |
|
751 // CVIMPSTDetailsContactHandler::OpenDbL |
|
752 // ----------------------------------------------------------- |
|
753 // |
|
754 void CVIMPSTDetailsContactHandler::OpenDbL() |
|
755 { |
|
756 TRACER_AUTO; |
|
757 TBuf< KMaxPath > storagePath; |
|
758 TBuf<512> dbName; |
|
759 dbName.Append( iServiceName->Des() ); |
|
760 dbName.Append( KStorageExtn ); |
|
761 |
|
762 storagePath.Append( KDbPath ); |
|
763 storagePath.Append( dbName ); |
|
764 |
|
765 iFileStore = CPermanentFileStore::OpenL( iFs, storagePath, EFileShareReadersOrWriters|EFileWrite ); |
|
766 iFileStore->SetTypeL( iFileStore->Layout() ); |
|
767 iDb.OpenL( iFileStore, iFileStore->Root() ); |
|
768 } |
|
769 |
|
770 // ----------------------------------------------------------- |
|
771 // CVIMPSTDetailsContactHandler::CloseDb |
|
772 // ----------------------------------------------------------- |
|
773 // |
|
774 void CVIMPSTDetailsContactHandler::CloseDb() |
|
775 { |
|
776 iTable.Close(); |
|
777 delete iColset; |
|
778 delete iFileStore; |
|
779 iFileStore = NULL; |
|
780 iDb.Close(); |
|
781 iFs.Close(); |
|
782 } |
|
783 |
|
784 // ---------------------------------------------------------- |
|
785 // CVIMPSTDetailsContactHandler::SeekRowL |
|
786 // ---------------------------------------------------------- |
|
787 // |
|
788 TBool CVIMPSTDetailsContactHandler::SeekRowL( TDbColNo aColNo, TInt32& aIdentifier ) |
|
789 { |
|
790 TRACER_AUTO; |
|
791 TBool ret = EFalse; |
|
792 iTable.BeginningL(); |
|
793 while ( iTable.NextL() ) |
|
794 { |
|
795 iTable.GetL(); |
|
796 if ( iTable.ColInt32( aColNo ) == aIdentifier ) |
|
797 { |
|
798 ret = ETrue; |
|
799 break; |
|
800 } |
|
801 } |
|
802 return ret; |
|
803 } |
|
804 |
|
805 // ---------------------------------------------------------- |
|
806 // CVIMPSTDetailsContactHandler::OpenTableL |
|
807 // ---------------------------------------------------------- |
|
808 // |
|
809 void CVIMPSTDetailsContactHandler::OpenTableL() |
|
810 { |
|
811 TRACER_AUTO; |
|
812 TInt err( iTable.Open( iDb, KContactTable ) ); |
|
813 if ( err != KErrNone ) |
|
814 { |
|
815 iTable.Close(); |
|
816 User::Leave( err ); |
|
817 return; |
|
818 } |
|
819 return; |
|
820 } |
|
821 |
|
822 // End of File |