|
1 /* |
|
2 * Copyright (c) 2007-2009 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: ESMR Address info handler implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 // Includes |
|
19 #include "emailtrace.h" |
|
20 #include "cesmraddressinfohandler.h" |
|
21 |
|
22 #include <eikenv.h> |
|
23 #include <AiwServiceHandler.h> |
|
24 #include <AiwContactSelectionDataTypes.h> |
|
25 #include <StringLoader.h> |
|
26 #include <aknnotewrappers.h> |
|
27 #include <calentry.h> |
|
28 #include <esmrgui.rsg> |
|
29 |
|
30 //Virtual Phonebook |
|
31 #include <CVPbkContactManager.h> |
|
32 #include <MVPbkContactOperationBase.h> |
|
33 #include <MVPbkStoreContact.h> |
|
34 #include <MVPbkFieldType.h> |
|
35 #include <VPbkEng.rsg> |
|
36 #include <CVPbkContactFieldIterator.h> |
|
37 #include <MVPbkContactFieldTextData.h> |
|
38 #include <MVPbkContactLink.h> |
|
39 |
|
40 #include "cesmrdynamicitemselectionlist.h" |
|
41 #include "cesmrlocationpluginhandler.h" |
|
42 |
|
43 namespace { //codescanner::namespace |
|
44 /** |
|
45 * Cleanup helpers for RPointerArrays |
|
46 */ |
|
47 template <class T> |
|
48 class CleanupResetAndDestroy |
|
49 { |
|
50 |
|
51 public: |
|
52 |
|
53 inline static void PushL( T& aRef ) |
|
54 { |
|
55 CleanupStack::PushL( TCleanupItem( &ResetAndDestroy, &aRef ) ); |
|
56 } |
|
57 |
|
58 private: |
|
59 inline static void ResetAndDestroy( TAny* aPtr ) |
|
60 { |
|
61 static_cast< T*>( aPtr )->ResetAndDestroy(); |
|
62 } |
|
63 }; |
|
64 |
|
65 template <class T> |
|
66 inline void CleanupResetAndDestroyPushL( T& aRef ) |
|
67 { |
|
68 CleanupResetAndDestroy<T>::PushL( aRef ); |
|
69 } |
|
70 |
|
71 // Tabulator for address selection list formatting |
|
72 _LIT( KTab, "\t" ); |
|
73 |
|
74 } //namespace |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CESMRAddressInfoHandler::NewL |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CESMRAddressInfoHandler* CESMRAddressInfoHandler::NewL() |
|
81 { |
|
82 FUNC_LOG; |
|
83 CESMRAddressInfoHandler* self = |
|
84 new (ELeave) CESMRAddressInfoHandler; |
|
85 CleanupStack::PushL( self ); |
|
86 self->ConstructL(); |
|
87 CleanupStack::Pop( self ); |
|
88 return self; |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CESMRAddressInfoHandler::CESMRAddressInfoHandler |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 CESMRAddressInfoHandler::CESMRAddressInfoHandler() |
|
96 { |
|
97 FUNC_LOG; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CESMRAddressInfoHandler::~CESMRAddressInfoHandler |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 CESMRAddressInfoHandler::~CESMRAddressInfoHandler() |
|
105 { |
|
106 FUNC_LOG; |
|
107 delete iWait; |
|
108 delete iServiceHandler; |
|
109 delete iLinksSet; |
|
110 delete iLinkOperationFetch; |
|
111 iAddressGeneralFields.Reset(); |
|
112 iAddressHomeFields.Reset(); |
|
113 iAddressWorkFields.Reset(); |
|
114 |
|
115 iCompleteAddresses.ResetAndDestroy(); |
|
116 |
|
117 iESMRStatic.Close(); |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CESMRAddressInfoHandler::ConstructL |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CESMRAddressInfoHandler::ConstructL() |
|
125 { |
|
126 FUNC_LOG; |
|
127 iWait = new( ELeave ) CActiveSchedulerWait; |
|
128 |
|
129 iESMRStatic.ConnectL(); |
|
130 CESMRContactManagerHandler& contactManagerHandler = iESMRStatic.ContactManagerHandlerL(); |
|
131 |
|
132 iContactManager = &contactManagerHandler.GetContactManager(); |
|
133 |
|
134 //start service handler and add the interests of this class |
|
135 iServiceHandler = CAiwServiceHandler::NewL(); |
|
136 iServiceHandler->AttachL( R_CONTACT_SELECTION_INTEREST ); |
|
137 |
|
138 //setup contact field arrays |
|
139 iAddressGeneralFields.AppendL( R_VPBK_FIELD_TYPE_ADDRLABELGEN ); |
|
140 iAddressGeneralFields.AppendL( R_VPBK_FIELD_TYPE_ADDRSTREETGEN ); |
|
141 iAddressGeneralFields.AppendL( R_VPBK_FIELD_TYPE_ADDRLOCALGEN ); |
|
142 iAddressGeneralFields.AppendL( R_VPBK_FIELD_TYPE_ADDRCOUNTRYGEN ); |
|
143 |
|
144 iAddressWorkFields.AppendL( R_VPBK_FIELD_TYPE_ADDRLABELWORK ); |
|
145 iAddressWorkFields.AppendL( R_VPBK_FIELD_TYPE_ADDRSTREETWORK ); |
|
146 iAddressWorkFields.AppendL( R_VPBK_FIELD_TYPE_ADDRLOCALWORK ); |
|
147 iAddressWorkFields.AppendL( R_VPBK_FIELD_TYPE_ADDRCOUNTRYWORK ); |
|
148 |
|
149 iAddressHomeFields.AppendL( R_VPBK_FIELD_TYPE_ADDRLABELHOME ); |
|
150 iAddressHomeFields.AppendL( R_VPBK_FIELD_TYPE_ADDRSTREETHOME ); |
|
151 iAddressHomeFields.AppendL( R_VPBK_FIELD_TYPE_ADDRLOCALHOME ); |
|
152 iAddressHomeFields.AppendL( R_VPBK_FIELD_TYPE_ADDRCOUNTRYHOME ); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CESMRAddressInfoHandler::HandleNotifyL |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 TInt CESMRAddressInfoHandler::HandleNotifyL( TInt aCmdId, //codescanner::intleaves |
|
160 TInt aEventId, |
|
161 CAiwGenericParamList& aEventParamList, |
|
162 const CAiwGenericParamList& /*aInParamList*/) |
|
163 { |
|
164 FUNC_LOG; |
|
165 if ( iLinksSet ) |
|
166 { |
|
167 delete iLinksSet; |
|
168 iLinksSet = NULL; |
|
169 } |
|
170 |
|
171 if ( iLinkOperationFetch ) |
|
172 { |
|
173 delete iLinkOperationFetch; |
|
174 iLinkOperationFetch = NULL; |
|
175 } |
|
176 TInt result = 0; |
|
177 |
|
178 if ((aCmdId == KAiwCmdSelect) && aEventId == KAiwEventCompleted ) |
|
179 { |
|
180 TInt index = 0; |
|
181 const TAiwGenericParam* param = |
|
182 aEventParamList.FindFirst(index, EGenericParamContactLinkArray); |
|
183 if (param) |
|
184 { |
|
185 TPtrC8 contactLinks = param->Value().AsData(); |
|
186 |
|
187 iLinksSet = iContactManager->CreateLinksLC( contactLinks ); |
|
188 CleanupStack::Pop(); //codescanner::cleanup |
|
189 if ( iLinksSet->Count() ) |
|
190 { |
|
191 iLinkOperationFetch = iContactManager-> |
|
192 RetrieveContactL( iLinksSet->At(0), *this ); |
|
193 } |
|
194 } |
|
195 |
|
196 } |
|
197 else if ( aEventId == KAiwEventError ) |
|
198 { |
|
199 if ( iWait->IsStarted()) |
|
200 { |
|
201 // Stop iWait so editor dialog continues |
|
202 iWait->AsyncStop(); |
|
203 } |
|
204 } |
|
205 else if ( (aEventId == KAiwEventQueryExit) ) |
|
206 { |
|
207 if ( iWait->IsStarted()) |
|
208 { |
|
209 // Stop iWait so editor dialog continues |
|
210 iWait->AsyncStop(); |
|
211 } |
|
212 // We don't need to check outParams, or do anything special during the exit |
|
213 result = ETrue; |
|
214 } |
|
215 else if ( aEventId == KAiwEventOutParamCheck ) |
|
216 { |
|
217 // Parameters don't need to be checked |
|
218 result = 1; |
|
219 } |
|
220 else if ( aEventId == KAiwEventCanceled ) |
|
221 { |
|
222 if ( iWait->IsStarted()) |
|
223 { |
|
224 // Stop iWait so editor dialog continues |
|
225 iWait->AsyncStop(); |
|
226 } |
|
227 } |
|
228 |
|
229 return result; |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // CESMRAddressInfoHandler::SearchAddressFromContacts |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 TBool CESMRAddressInfoHandler::SearchAddressFromContactsL( MESMRCalEntry& aEntry ) |
|
237 { |
|
238 FUNC_LOG; |
|
239 if( !(iWait->IsStarted()) ) |
|
240 { |
|
241 iEntry = &aEntry; |
|
242 iEntryUpdated = EFalse; |
|
243 |
|
244 TUint fetchFlags = 0; |
|
245 |
|
246 CAiwGenericParamList& inParamList = iServiceHandler->InParamListL(); |
|
247 inParamList.AppendL( |
|
248 TAiwGenericParam( |
|
249 EGenericParamContactSelectionData, |
|
250 TAiwVariant(TAiwSingleEntrySelectionDataV2Pckg( |
|
251 TAiwSingleEntrySelectionDataV2(). |
|
252 SetFlags( fetchFlags ))))); |
|
253 |
|
254 iServiceHandler->ExecuteServiceCmdL( |
|
255 KAiwCmdSelect, |
|
256 inParamList, |
|
257 iServiceHandler->OutParamListL(), |
|
258 0, |
|
259 this); |
|
260 iWait->Start(); // codescanner::callActiveObjectWithoutCheckingOrStopping |
|
261 } |
|
262 |
|
263 return iEntryUpdated; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CESMRAddressInfoHandler::VPbkSingleContactOperationComplete |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 void CESMRAddressInfoHandler::VPbkSingleContactOperationComplete( |
|
271 MVPbkContactOperationBase& aOperation, |
|
272 MVPbkStoreContact* aContact ) |
|
273 { |
|
274 FUNC_LOG; |
|
275 TRAP_IGNORE( VPbkSingleContactOperationCompleteL( aOperation, aContact ) ); |
|
276 if ( iWait->IsStarted() ) |
|
277 { |
|
278 // Stop iWait so editor dialog continues |
|
279 iWait->AsyncStop(); |
|
280 } |
|
281 |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // CESMRAddressInfoHandler::VPbkSingleContactOperationFailed |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 void CESMRAddressInfoHandler::VPbkSingleContactOperationFailed( |
|
289 MVPbkContactOperationBase& /*aOperation*/, |
|
290 TInt /*aError*/ ) |
|
291 { |
|
292 FUNC_LOG; |
|
293 if ( iWait->IsStarted() ) |
|
294 { |
|
295 iWait->AsyncStop(); |
|
296 } |
|
297 } |
|
298 |
|
299 // --------------------------------------------------------------------------- |
|
300 // CESMRAddressInfoHandler::VPbkSingleContactOperationCompleteL |
|
301 // --------------------------------------------------------------------------- |
|
302 // |
|
303 void CESMRAddressInfoHandler::VPbkSingleContactOperationCompleteL( |
|
304 MVPbkContactOperationBase& aOperation, |
|
305 MVPbkStoreContact* aContact ) |
|
306 { |
|
307 FUNC_LOG; |
|
308 if ( iLinkOperationFetch == &aOperation ) |
|
309 { |
|
310 CleanupDeletePushL( aContact ); |
|
311 |
|
312 if( iCompleteAddresses.Count() ) |
|
313 { |
|
314 iCompleteAddresses.ResetAndDestroy(); |
|
315 } |
|
316 |
|
317 RPointerArray<HBufC> homeAddress; |
|
318 CleanupResetAndDestroyPushL( homeAddress ); |
|
319 RPointerArray<HBufC> workAddress; |
|
320 CleanupResetAndDestroyPushL( workAddress ); |
|
321 RPointerArray<HBufC> generalAddress; |
|
322 CleanupResetAndDestroyPushL( generalAddress ); |
|
323 |
|
324 GetContactFieldsL( iAddressHomeFields, homeAddress, aContact ); |
|
325 GetContactFieldsL( iAddressWorkFields, workAddress, aContact ); |
|
326 GetContactFieldsL( iAddressGeneralFields, generalAddress, aContact ); |
|
327 |
|
328 FormatAddressL( homeAddress, EHomeAddress ); |
|
329 FormatAddressL( workAddress, EWorkAddress ); |
|
330 FormatAddressL( generalAddress, EGeneralAddress ); |
|
331 |
|
332 |
|
333 |
|
334 // Contact has more than one addresses, address selection |
|
335 // dialog need to be shown. |
|
336 if ( iCompleteAddresses.Count() > 1 ) |
|
337 { |
|
338 // Show address selection dialog |
|
339 CESMRDynamicItemSelectionList* query = |
|
340 CESMRDynamicItemSelectionList::NewL(); |
|
341 CleanupStack::PushL( query ); |
|
342 TInt index = |
|
343 query->ExecuteL( |
|
344 iCompleteAddresses, |
|
345 CESMRDynamicItemSelectionList::EESMRAddressSelectionList ); |
|
346 CleanupStack::PopAndDestroy( query ); |
|
347 if ( index >= 0 && ( index < iCompleteAddresses.Count() ) ) |
|
348 { |
|
349 UpdateEntryL( index ); |
|
350 } |
|
351 } |
|
352 |
|
353 // Contact has only one address |
|
354 else if ( iCompleteAddresses.Count() == 1 ) |
|
355 { |
|
356 UpdateEntryL( 0 ); |
|
357 } |
|
358 |
|
359 // Contact doesn't have any address, information note is shown |
|
360 else if ( iCompleteAddresses.Count() == 0 ) |
|
361 { |
|
362 HBufC* noAddressBuf = |
|
363 StringLoader::LoadL( R_MEET_REQ_NO_ADDRESS_FOUND ); |
|
364 CleanupStack::PushL( noAddressBuf ); |
|
365 CAknInformationNote* infNote = |
|
366 new (ELeave) CAknInformationNote(); |
|
367 infNote->ExecuteLD( *noAddressBuf ); |
|
368 // note will be deleted automatically |
|
369 // and pointer will be set to NULL after execution |
|
370 CleanupStack::PopAndDestroy( noAddressBuf ); |
|
371 } |
|
372 |
|
373 CleanupStack::PopAndDestroy( &generalAddress ); |
|
374 CleanupStack::PopAndDestroy( &workAddress ); |
|
375 CleanupStack::PopAndDestroy( &homeAddress ); |
|
376 |
|
377 CleanupStack::PopAndDestroy( aContact ); |
|
378 } |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // CESMRAddressInfoHandler::GetContactFieldsL |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 void CESMRAddressInfoHandler::GetContactFieldsL( RArray<TInt>& aFieldIds, |
|
386 RPointerArray<HBufC>& aNumbers, |
|
387 MVPbkStoreContact* aContact) |
|
388 { |
|
389 FUNC_LOG; |
|
390 for (TInt i = 0; i < aFieldIds.Count(); i++ ) |
|
391 { |
|
392 const MVPbkFieldType* myContactDataField = |
|
393 iContactManager->FieldTypes().Find( aFieldIds[i] ); |
|
394 |
|
395 CVPbkBaseContactFieldTypeIterator* itrNumber = |
|
396 CVPbkBaseContactFieldTypeIterator::NewLC( *myContactDataField, |
|
397 aContact->Fields() ); |
|
398 |
|
399 // Iterate through each of the data fields |
|
400 while ( itrNumber->HasNext() ) |
|
401 { |
|
402 const MVPbkBaseContactField* field = itrNumber->Next(); |
|
403 |
|
404 if ( (field->FieldData()).DataType() == EVPbkFieldStorageTypeText ) |
|
405 { |
|
406 HBufC* toAppend = MVPbkContactFieldTextData::Cast( |
|
407 field->FieldData() ).Text().AllocL(); |
|
408 |
|
409 aNumbers.Append( toAppend ); |
|
410 } |
|
411 } |
|
412 CleanupStack::PopAndDestroy( itrNumber ); |
|
413 } |
|
414 } |
|
415 |
|
416 // ---------------------------------------------------------------------------- |
|
417 // CESMRAddressInfoHandler::FormatAddressL |
|
418 // ---------------------------------------------------------------------------- |
|
419 // |
|
420 void CESMRAddressInfoHandler::FormatAddressL( RPointerArray<HBufC>& aAddresses, |
|
421 CESMRAddressInfoHandler::TAddressType aAddressType ) |
|
422 { |
|
423 FUNC_LOG; |
|
424 if ( aAddresses.Count() > 0 ) |
|
425 { |
|
426 HBufC* addressTitle = NULL; |
|
427 switch ( aAddressType ) |
|
428 { |
|
429 case EHomeAddress: |
|
430 { |
|
431 addressTitle = StringLoader::LoadL( R_MEET_REQ_HOME_ADDRESS ); |
|
432 break; |
|
433 } |
|
434 case EWorkAddress: |
|
435 { |
|
436 addressTitle = StringLoader::LoadL( R_MEET_REQ_WORK_ADDRESS ); |
|
437 break; |
|
438 } |
|
439 case EGeneralAddress: |
|
440 { |
|
441 addressTitle = |
|
442 StringLoader::LoadL( R_MEET_REQ_GENERAL_ADDRESS ); |
|
443 break; |
|
444 } |
|
445 default: |
|
446 { |
|
447 User::Leave( KErrGeneral ); |
|
448 } |
|
449 } |
|
450 CleanupStack::PushL( addressTitle); |
|
451 |
|
452 CPtrCArray* addressPtr = |
|
453 new( ELeave ) CPtrCArray( aAddresses.Count()); |
|
454 CleanupStack::PushL( addressPtr ); |
|
455 |
|
456 for (TInt i = 0; i < aAddresses.Count(); i++ ) |
|
457 { |
|
458 addressPtr->AppendL( aAddresses[i]->Des() ); |
|
459 } |
|
460 HBufC* streetAddress = NULL; |
|
461 switch ( aAddresses.Count()) |
|
462 { |
|
463 case EFormatOneItem: |
|
464 { |
|
465 streetAddress = aAddresses[0]->AllocL(); |
|
466 break; |
|
467 } |
|
468 case EFormatTwoItems: |
|
469 { |
|
470 streetAddress = StringLoader:: |
|
471 LoadL( R_MEET_REQ_ADDRESS_FROM_CONTACTS_TWO_ITEMS, |
|
472 *addressPtr ); |
|
473 break; |
|
474 } |
|
475 case EFormatThreeItems: |
|
476 { |
|
477 streetAddress = StringLoader:: |
|
478 LoadL( R_MEET_REQ_ADDRESS_FROM_CONTACTS_THREE_ITEMS, |
|
479 *addressPtr ); |
|
480 break; |
|
481 } |
|
482 case EFormatFourItems: |
|
483 { |
|
484 streetAddress = StringLoader:: |
|
485 LoadL( R_MEET_REQ_ADDRESS_FROM_CONTACTS_FORMAT, |
|
486 *addressPtr ); |
|
487 break; |
|
488 } |
|
489 default: |
|
490 { |
|
491 User::Leave( KErrGeneral ); |
|
492 } |
|
493 } |
|
494 |
|
495 CleanupStack::PopAndDestroy( addressPtr ); |
|
496 CleanupStack::PushL( streetAddress ); |
|
497 streetAddress = streetAddress->ReAllocL( |
|
498 streetAddress->Length() + addressTitle->Length() +1 ); |
|
499 // streetAddress item before reallocation need to be |
|
500 // removed from cleanupstack. |
|
501 CleanupStack::Pop(); //codescanner::cleanup |
|
502 CleanupStack::PushL( streetAddress ); |
|
503 |
|
504 |
|
505 streetAddress->Des().Insert( 0, KTab ); |
|
506 streetAddress->Des().Insert( 0, *addressTitle ); |
|
507 iCompleteAddresses.Append( streetAddress ); |
|
508 CleanupStack::Pop( streetAddress ); |
|
509 CleanupStack::PopAndDestroy( addressTitle ); |
|
510 } |
|
511 } |
|
512 |
|
513 // --------------------------------------------------------------------------- |
|
514 // CESMRAddressInfoHandler::UpdateEntryL |
|
515 // --------------------------------------------------------------------------- |
|
516 // |
|
517 void CESMRAddressInfoHandler::UpdateEntryL( TInt aIndex ) |
|
518 { |
|
519 FUNC_LOG; |
|
520 TInt offset = iCompleteAddresses[aIndex]->Find( KTab ); //codescanner::accessArrayElementWithoutCheck2 |
|
521 TPtrC address( iCompleteAddresses[aIndex]->Mid( offset + 1) ); //codescanner::accessArrayElementWithoutCheck2 |
|
522 iEntryUpdated = |
|
523 CESMRLocationPluginHandler::UpdateEntryLocationL( *iEntry, address, EFalse ); |
|
524 } |
|
525 |
|
526 //EOF |
|
527 |