29 #include <MVPbkContactGroup.h> |
29 #include <MVPbkContactGroup.h> |
30 #include <MVPbkContactFieldTextData.h> |
30 #include <MVPbkContactFieldTextData.h> |
31 #include <MVPbkContactFieldData.h> |
31 #include <MVPbkContactFieldData.h> |
32 #include <MVPbkContactFieldBinaryData.h> |
32 #include <MVPbkContactFieldBinaryData.h> |
33 #include <MVPbkContactFieldDateTimeData.h> |
33 #include <MVPbkContactFieldDateTimeData.h> |
|
34 #include <MVPbkContactFieldUriData.h> |
34 |
35 |
35 /* |
36 /* |
36 ------------------------------------------------------------------------------------- |
37 ------------------------------------------------------------------------------------- |
37 CAddContactObserver::NewL( CContactService* aContactService, |
38 CAddContactObserver::NewL( CContactService* aContactService, |
38 MVPbkContactStore* aContactStore, |
39 MVPbkContactStore* aContactStore, |
160 void CAddContactObserver::CreateAndAddFieldToContactL() |
161 void CAddContactObserver::CreateAndAddFieldToContactL() |
161 { |
162 { |
162 TPtrC8 fieldKey(KNullDesC8); |
163 TPtrC8 fieldKey(KNullDesC8); |
163 TPtrC label(KNullDesC); |
164 TPtrC label(KNullDesC); |
164 TPtrC value(KNullDesC); |
165 TPtrC value(KNullDesC); |
|
166 TBool labelFound = EFalse; |
165 iErrorID = 0; |
167 iErrorID = 0; |
166 |
168 TBuf16<100> bufVal; |
|
169 int len =0; |
|
170 TBool xspidField = EFalse; |
|
171 TBool secTime = EFalse; |
167 TInt fieldCount = iStoreContact->FieldCount(); |
172 TInt fieldCount = iStoreContact->FieldCount(); |
168 const CVPbkContactManager* contactManager = &(iContactService->GetContactManager()); |
173 const CVPbkContactManager* contactManager = &(iContactService->GetContactManager()); |
169 for(TInt index = 0; index < fieldCount; index++) |
174 for(TInt index = 0; index < fieldCount; index++) |
170 { |
175 { |
|
176 xspidField = EFalse; |
171 CSingleContactField* field = iStoreContact->FieldAt(index); |
177 CSingleContactField* field = iStoreContact->FieldAt(index); |
172 |
178 |
173 field->GetFieldDataL(fieldKey, label, value); |
179 field->GetFieldDataL(fieldKey, label, value); |
174 TInt fieldTypeResId = CSearchFields::GetIdFromFieldKey(fieldKey); |
180 TInt fieldTypeResId = CSearchFields::GetIdFromFieldKey(fieldKey); |
175 iErrorID = fieldTypeResId; |
181 iErrorID = fieldTypeResId; |
187 else if( EVPbkFieldStorageTypeDateTime == storageType ) |
193 else if( EVPbkFieldStorageTypeDateTime == storageType ) |
188 { |
194 { |
189 TTime timeVal = field->GetDateTime(); |
195 TTime timeVal = field->GetDateTime(); |
190 (MVPbkContactFieldDateTimeData::Cast(cntField->FieldData())).SetDateTime( timeVal ); |
196 (MVPbkContactFieldDateTimeData::Cast(cntField->FieldData())).SetDateTime( timeVal ); |
191 } |
197 } |
|
198 else if(EVPbkFieldStorageTypeUri == storageType ) |
|
199 { |
|
200 |
|
201 |
|
202 xspidField = ETrue; |
|
203 RPointerArray<HBufC> xspidArray; |
|
204 //CleanupClosePushL(xspidArray); |
|
205 field->GetXspidDataL(xspidArray); |
|
206 TInt count = xspidArray.Count(); |
|
207 for(int i=0; i<count; i++) |
|
208 { |
|
209 if(secTime != EFalse) |
|
210 { |
|
211 fieldTypeResId = CSearchFields::GetIdFromFieldKey(fieldKey); |
|
212 iErrorID = fieldTypeResId; |
|
213 cntField = iContact->CreateFieldLC( * contactManager->FieldTypes().Find( fieldTypeResId ) ); |
|
214 |
|
215 iErrorID = 0; |
|
216 |
|
217 storageType = cntField->FieldData().DataType(); |
|
218 |
|
219 } |
|
220 secTime = ETrue; |
|
221 |
|
222 HBufC* val = xspidArray[i]; |
|
223 bufVal.Copy(val->Des()); |
|
224 TDes16 desVal = bufVal; |
|
225 TPtrC ptrVal; //desVal.Left(0); |
|
226 TInt valLen = val->Length(); |
|
227 (MVPbkContactFieldUriData::Cast(cntField->FieldData())).SetUriL( bufVal ); |
|
228 |
|
229 len = val->Find(_L(":")); |
|
230 |
|
231 if(len != -1) |
|
232 { |
|
233 TInt trimLen = valLen - len; |
|
234 ptrVal.Set(val->Left(valLen - (trimLen))); |
|
235 len =0; |
|
236 |
|
237 TRAP_IGNORE(cntField->SetFieldLabelL(ptrVal)); |
|
238 |
|
239 iContact->AddFieldL(cntField); |
|
240 CleanupStack::Pop(); //cntField |
|
241 } |
|
242 else |
|
243 { |
|
244 CleanupStack::Pop(); //cntField |
|
245 User::Leave(KErrArgument); |
|
246 } |
|
247 |
|
248 // delete val; |
|
249 } |
|
250 xspidArray.Reset(); |
|
251 //CleanupStack::Pop(); |
|
252 } |
192 else |
253 else |
193 { |
254 { |
194 (MVPbkContactFieldTextData::Cast(cntField->FieldData())).SetTextL( value ); |
255 (MVPbkContactFieldTextData::Cast(cntField->FieldData())).SetTextL( value ); |
195 } |
256 } |
196 |
257 if(xspidField == EFalse) |
|
258 { |
197 TRAP_IGNORE(cntField->SetFieldLabelL(label)); |
259 TRAP_IGNORE(cntField->SetFieldLabelL(label)); |
198 |
260 |
199 iContact->AddFieldL(cntField); |
261 iContact->AddFieldL(cntField); |
200 |
262 |
201 CleanupStack::Pop(); //cntField |
263 CleanupStack::Pop(); //cntField |
|
264 } |
202 } |
265 } |
203 } |
266 } |
204 |
267 |
205 |
268 |
206 /* |
269 /* |
275 //contact and edit the label and commit the same. |
338 //contact and edit the label and commit the same. |
276 if( iLockFlag && |
339 if( iLockFlag && |
277 aResult.iOpCode == EContactLock && |
340 aResult.iOpCode == EContactLock && |
278 ((*iGroupId != KNullDesC8) && (*iGroupLabel != KNullDesC)) ) |
341 ((*iGroupId != KNullDesC8) && (*iGroupLabel != KNullDesC)) ) |
279 { |
342 { |
280 (iContact->Group())->SetGroupLabelL(*iGroupLabel); |
343 MVPbkContactGroup* grpintf = iContact->Group(); |
|
344 if(grpintf != NULL) |
|
345 { |
|
346 grpintf->SetGroupLabelL(*iGroupLabel); |
281 (iContact->Group())->CommitL(*this); |
347 (iContact->Group())->CommitL(*this); |
282 //set lock flag to false, as it is done. |
348 //set lock flag to false, as it is done. |
283 iLockFlag = EFalse; |
349 iLockFlag = EFalse; |
284 //set return value to ErrNone...completed successfully. |
350 //set return value to ErrNone...completed successfully. |
285 retVal = KErrNone; |
351 retVal = KErrNone; |
|
352 } |
286 } |
353 } |
287 //lock is success, so update the fields in the contact and commit. |
354 //lock is success, so update the fields in the contact and commit. |
288 else if( iLockFlag && aResult.iOpCode == EContactLock ) |
355 else if( iLockFlag && aResult.iOpCode == EContactLock ) |
289 { |
356 { |
290 //remove all the fields from the original contact. |
357 //remove all the fields from the original contact. |
339 void CAddContactObserver::ContactOperationCompleted( TContactOpResult aResult ) |
406 void CAddContactObserver::ContactOperationCompleted( TContactOpResult aResult ) |
340 { |
407 { |
341 //if lock operation is successfull then it enters here... |
408 //if lock operation is successfull then it enters here... |
342 //call DoCommitL(), to commit the contact into the contact store. |
409 //call DoCommitL(), to commit the contact into the contact store. |
343 TRAPD(error, error = DoCommitL(aResult)); |
410 TRAPD(error, error = DoCommitL(aResult)); |
344 |
411 if(error == KErrNone) |
|
412 { |
345 //notify the user with the status of the operation. |
413 //notify the user with the status of the operation. |
346 if((aResult.iOpCode != EContactLock) || (error != KErrNone)) |
414 if((aResult.iOpCode != EContactLock) || (error != KErrNone)) |
347 { |
415 { |
348 iContactService->RequestComplete(iTransId); |
416 //iContactService->RequestComplete(iTransId); |
349 iCallback->HandleReturnValue(EOpComplete, error, iTransId); |
417 //iCallback->HandleReturnValue(EOpComplete, error, iTransId); |
350 delete this; |
418 if(iGroupLabel->Compare(KNullDesC) != 0) //.Compare(KNullDesC)) != 0) |
|
419 { |
|
420 if(iGroup != NULL) |
|
421 { |
|
422 iContactService->RequestComplete(iTransId); |
|
423 MVPbkContactLink* link = iGroup->CreateLinkLC(); |
|
424 HBufC8* grpId = link->PackLC(); |
|
425 CleanupStack::Pop(grpId); |
|
426 iCallback->HandleReturnId(error, grpId, iTransId); |
|
427 CleanupStack::PopAndDestroy(); |
|
428 //delete grpId; |
|
429 delete this; |
|
430 } |
|
431 else |
|
432 { |
|
433 iContactService->RequestComplete(iTransId); |
|
434 iCallback->HandleReturnValue(EOpComplete, error, iTransId); |
|
435 delete this; |
|
436 } |
|
437 } |
|
438 else |
|
439 { |
|
440 if(iContact != NULL) |
|
441 { |
|
442 iContactService->RequestComplete(iTransId); |
|
443 MVPbkContactLink* link = iContact->CreateLinkLC(); |
|
444 HBufC8* cntId = link->PackLC(); |
|
445 CleanupStack::Pop(cntId); |
|
446 iCallback->HandleReturnId(error, cntId, iTransId); |
|
447 CleanupStack::PopAndDestroy(); |
|
448 // delete cntId; |
|
449 delete this; |
|
450 } |
|
451 else |
|
452 { |
|
453 iContactService->RequestComplete(iTransId); |
|
454 iCallback->HandleReturnValue(EOpComplete, error, iTransId); |
|
455 delete this; |
|
456 } |
|
457 } |
|
458 } |
351 } |
459 } |
|
460 else |
|
461 { |
|
462 iContactService->RequestComplete(iTransId); |
|
463 iCallback->HandleReturnValue(EOpError, error, iTransId); |
|
464 delete this; |
|
465 } |
352 } |
466 } |
353 |
467 |
354 /* |
468 /* |
355 ------------------------------------------------------------------------------------- |
469 ------------------------------------------------------------------------------------- |
356 CAddContactObserver::ContactOperationFailed(TContactOp aOpCode, |
470 CAddContactObserver::ContactOperationFailed(TContactOp aOpCode, |