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