|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Phonebook 2 copy from Phonebook to SIM command object. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPsu2CopyFromPbkCmd.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include "CPsu2NumberQueryDlg.h" |
|
24 #include "CPsu2CopyToSimFieldInfoArray.h" |
|
25 #include "CPsu2CharConv.h" |
|
26 #include "CPsu2UIExtensionPlugin.h" |
|
27 |
|
28 #include <MPbk2ContactUiControl.h> |
|
29 #include <MPbk2CommandObserver.h> |
|
30 #include <CPbk2FetchDlg.h> |
|
31 #include <MPbk2FetchDlgObserver.h> |
|
32 #include <CPbk2FieldPropertyArray.h> |
|
33 #include <Pbk2UIControls.rsg> |
|
34 #include <Pbk2USimUIRes.rsg> |
|
35 #include <TPbk2AddressSelectParams.h> |
|
36 #include <CPbk2AddressSelect.h> |
|
37 #include <Pbk2DataCaging.hrh> |
|
38 #include <MPbk2ContactNameFormatter.h> |
|
39 #include <MPbk2DialogEliminator.h> |
|
40 #include <Pbk2ProcessDecoratorFactory.h> |
|
41 #include <Pbk2Commands.rsg> |
|
42 #include <CPbk2StoreProperty.h> |
|
43 #include <CPbk2StorePropertyArray.h> |
|
44 #include <MPbk2ApplicationServices.h> |
|
45 #include <MPbk2AppUi.h> |
|
46 #include <Pbk2CommonUi.rsg> |
|
47 |
|
48 // Virtual Phonebook |
|
49 #include <MVPbkStoreContact.h> |
|
50 #include <MVPbkContactLink.h> |
|
51 #include <CVPbkContactManager.h> |
|
52 #include <MVPbkContactStore.h> |
|
53 #include <MVPbkContactStoreInfo.h> |
|
54 #include <MVPbkStoreContactField.h> |
|
55 #include <MVPbkContactFieldData.h> |
|
56 #include <MVPbkContactLinkArray.h> |
|
57 #include <MVPbkContactOperationBase.h> |
|
58 #include <MVPbkContactStoreProperties.h> |
|
59 #include <MVPbkFieldType.h> |
|
60 #include <TVPbkFieldVersitProperty.h> |
|
61 #include <MVPbkContactFieldTextData.h> |
|
62 |
|
63 // System includes |
|
64 #include <coemain.h> |
|
65 #include <barsread.h> |
|
66 #include <StringLoader.h> |
|
67 #include <AknQueryDialog.h> |
|
68 #include <exterror.h> |
|
69 #include <akntitle.h> |
|
70 #include <aknnotewrappers.h> |
|
71 #include <charconv.h> |
|
72 |
|
73 |
|
74 /// Unnamed namespace for local definitions |
|
75 namespace { |
|
76 |
|
77 #ifdef _DEBUG |
|
78 |
|
79 enum TPanicCode |
|
80 { |
|
81 EPanic_Pbk2FetchCompletedL = 1 |
|
82 }; |
|
83 |
|
84 void Panic( TPanicCode aPanic ) |
|
85 { |
|
86 _LIT( KPanicCat, "CPsu2CopyFromPbkCmd" ); |
|
87 User::Panic( KPanicCat, aPanic ); |
|
88 } |
|
89 |
|
90 #endif // _DEBUG |
|
91 |
|
92 /** |
|
93 * Checks is the store full. |
|
94 * |
|
95 * @param aStore The store to check. |
|
96 * @return ETrue if the store is full, EFalse otherwise. |
|
97 */ |
|
98 inline TBool StoreFullL( MVPbkContactStore& aStore ) |
|
99 { |
|
100 const MVPbkContactStoreInfo& storeInfo = aStore.StoreInfo(); |
|
101 return storeInfo.MaxNumberOfContactsL() <= storeInfo.NumberOfContactsL(); |
|
102 } |
|
103 |
|
104 /** |
|
105 * Show error info note |
|
106 * |
|
107 * @param aResourceId The numeric ID of the resource to construct info note. |
|
108 * @param aStoreName store name to be shown in the info note |
|
109 */ |
|
110 void ShowInformationNoteL( TInt aResourceId, const TDesC* aStoreName ) |
|
111 { |
|
112 HBufC* prompt = NULL; |
|
113 |
|
114 if( aStoreName ) |
|
115 { |
|
116 prompt = StringLoader::LoadL( aResourceId , *aStoreName ); |
|
117 } |
|
118 else |
|
119 { |
|
120 prompt = StringLoader::LoadL( aResourceId ); |
|
121 } |
|
122 |
|
123 if ( prompt ) |
|
124 { |
|
125 CleanupStack::PushL(prompt); |
|
126 // This is a waiting dialog because the editor might be |
|
127 // used from the application server and the information note will |
|
128 // disappear if the application server closes before the |
|
129 // note timeout has expired, thus causing blinking |
|
130 CAknInformationNote* noteDlg = new(ELeave) CAknInformationNote(ETrue); |
|
131 noteDlg->ExecuteLD(*prompt); |
|
132 CleanupStack::PopAndDestroy(); // prompt |
|
133 } |
|
134 } |
|
135 |
|
136 void ShowStoreFullNoteL |
|
137 ( const MVPbkContactStore& aTargetStore, |
|
138 const CPbk2StorePropertyArray& aStoreProperties ) |
|
139 { |
|
140 // Fetch store name |
|
141 TVPbkContactStoreUriPtr uri = aTargetStore.StoreProperties().Uri(); |
|
142 |
|
143 const CPbk2StoreProperty* storeProperty = |
|
144 aStoreProperties.FindProperty( uri ); |
|
145 |
|
146 const TDesC* storeName = NULL; |
|
147 if ( storeProperty ) |
|
148 { |
|
149 storeName = &storeProperty->StoreName(); |
|
150 } |
|
151 else |
|
152 { |
|
153 storeName = &uri.UriDes(); |
|
154 } |
|
155 ShowInformationNoteL( R_QTN_PHOB_NOTE_STORE_FULL, storeName ); |
|
156 } |
|
157 /// Tasks |
|
158 enum TNextTask |
|
159 { |
|
160 EPsu2ContactFetch, |
|
161 EPsu2QueryAddress, |
|
162 EPsu2CopyContact, |
|
163 EPsu2Commit, |
|
164 EPsu2Complete |
|
165 }; |
|
166 |
|
167 _LIT( KPSu2InternationalPrefix, "+" ); |
|
168 |
|
169 } /// namespace |
|
170 |
|
171 // -------------------------------------------------------------------------- |
|
172 // CPsu2CopyFromPbkCmd::CPsu2CopyFromPbkCmd |
|
173 // -------------------------------------------------------------------------- |
|
174 // |
|
175 CPsu2CopyFromPbkCmd::CPsu2CopyFromPbkCmd( |
|
176 MVPbkContactStore& aTargetStore, |
|
177 MPbk2ContactUiControl& aUiControl, |
|
178 CPsu2UIExtensionPlugin* aPsu2UIExensionPlugin) : |
|
179 CActive( EPriorityStandard ), |
|
180 iTargetStore( aTargetStore ), |
|
181 iUiControl( &aUiControl ), |
|
182 iPsu2UIExensionPlugin( aPsu2UIExensionPlugin ) |
|
183 { |
|
184 } |
|
185 |
|
186 // -------------------------------------------------------------------------- |
|
187 // CPsu2CopyFromPbkCmd::~CPsu2CopyFromPbkCmd() |
|
188 // -------------------------------------------------------------------------- |
|
189 // |
|
190 CPsu2CopyFromPbkCmd::~CPsu2CopyFromPbkCmd() |
|
191 { |
|
192 Cancel(); |
|
193 delete iCopyOperation; |
|
194 delete iSourceStoreContact; |
|
195 delete iTargetStoreContact; |
|
196 delete iRetrieveOperation; |
|
197 delete iStoreContactField; |
|
198 delete iSimFieldInfos; |
|
199 delete iDecorator; |
|
200 delete iTitlePaneText; |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // CPsu2CopyFromPbkCmd::NewL |
|
205 // -------------------------------------------------------------------------- |
|
206 // |
|
207 CPsu2CopyFromPbkCmd* CPsu2CopyFromPbkCmd::NewL |
|
208 ( MVPbkContactStore& aTargetStore, |
|
209 MPbk2ContactUiControl& aUiControl, |
|
210 CPsu2UIExtensionPlugin* aPsu2UIExensionPlugin ) |
|
211 { |
|
212 CPsu2CopyFromPbkCmd* self = |
|
213 new (ELeave) CPsu2CopyFromPbkCmd( aTargetStore, aUiControl, aPsu2UIExensionPlugin ); |
|
214 CleanupStack::PushL( self ); |
|
215 self->ConstructL(); |
|
216 CleanupStack::Pop( self ); |
|
217 return self; |
|
218 } |
|
219 |
|
220 // -------------------------------------------------------------------------- |
|
221 // CPsu2CopyFromPbkCmd::ConstructL |
|
222 // -------------------------------------------------------------------------- |
|
223 // |
|
224 void CPsu2CopyFromPbkCmd::ConstructL() |
|
225 { |
|
226 CActiveScheduler::Add( this ); |
|
227 |
|
228 iSimFieldInfos = CPsu2CopyToSimFieldInfoArray::NewL |
|
229 ( Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
230 ContactManager().FieldTypes(), |
|
231 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
232 ContactManager().FsSession() ); |
|
233 iTargetStoreContact = iTargetStore.CreateNewContactLC(); |
|
234 CleanupStack::Pop(); //iTargetStoreContact |
|
235 } |
|
236 |
|
237 // -------------------------------------------------------------------------- |
|
238 // CPsu2CopyFromPbkCmd::ExecuteLD |
|
239 // -------------------------------------------------------------------------- |
|
240 // |
|
241 void CPsu2CopyFromPbkCmd::ExecuteLD() |
|
242 { |
|
243 if ( StoreFullL( iTargetStore ) ) |
|
244 { |
|
245 ShowStoreFullNoteL( iTargetStore, |
|
246 Phonebook2::Pbk2AppUi()->ApplicationServices().StoreProperties() ); |
|
247 } |
|
248 else |
|
249 { |
|
250 iNextTask = EPsu2ContactFetch; |
|
251 IssueRequest(); |
|
252 } |
|
253 } |
|
254 |
|
255 // -------------------------------------------------------------------------- |
|
256 // CPsu2CopyFromPbkCmd::AddObserver |
|
257 // -------------------------------------------------------------------------- |
|
258 // |
|
259 void CPsu2CopyFromPbkCmd::AddObserver( MPbk2CommandObserver& aObserver ) |
|
260 { |
|
261 iCommandObserver = &aObserver; |
|
262 } |
|
263 |
|
264 // -------------------------------------------------------------------------- |
|
265 // CPsu2CopyFromPbkCmd::ResetUiControl |
|
266 // -------------------------------------------------------------------------- |
|
267 // |
|
268 void CPsu2CopyFromPbkCmd::ResetUiControl( MPbk2ContactUiControl& aUiControl ) |
|
269 { |
|
270 if ( iUiControl == &aUiControl ) |
|
271 { |
|
272 iUiControl = NULL; |
|
273 } |
|
274 } |
|
275 |
|
276 // -------------------------------------------------------------------------- |
|
277 // CPsu2CopyFromPbkCmd::RunL |
|
278 // -------------------------------------------------------------------------- |
|
279 // |
|
280 void CPsu2CopyFromPbkCmd::RunL() |
|
281 { |
|
282 switch (iNextTask) |
|
283 { |
|
284 case EPsu2ContactFetch: |
|
285 { |
|
286 QueryContactL(); |
|
287 break; |
|
288 } |
|
289 case EPsu2QueryAddress: |
|
290 { |
|
291 QueryAddressL(); |
|
292 break; |
|
293 } |
|
294 case EPsu2CopyContact: |
|
295 { |
|
296 CopyContactL(); |
|
297 break; |
|
298 } |
|
299 case EPsu2Complete: // FALLTHROUGH |
|
300 default: |
|
301 { |
|
302 if ( iFetchDialogEliminator ) |
|
303 { |
|
304 iFetchDialogEliminator->RequestExitL( EEikBidOk ); |
|
305 } |
|
306 if ( iCommandObserver ) |
|
307 { |
|
308 iCommandObserver->CommandFinished(*this); |
|
309 } |
|
310 break; |
|
311 } |
|
312 } |
|
313 } |
|
314 |
|
315 // -------------------------------------------------------------------------- |
|
316 // CPsu2CopyFromPbkCmd::DoCancel |
|
317 // -------------------------------------------------------------------------- |
|
318 // |
|
319 void CPsu2CopyFromPbkCmd::DoCancel() |
|
320 { |
|
321 // Nothing to do |
|
322 } |
|
323 |
|
324 // -------------------------------------------------------------------------- |
|
325 // CPsu2CopyFromPbkCmd::RunError |
|
326 // -------------------------------------------------------------------------- |
|
327 // |
|
328 TInt CPsu2CopyFromPbkCmd::RunError( TInt aError ) |
|
329 { |
|
330 CCoeEnv::Static()->HandleError( aError ); |
|
331 if ( iCommandObserver ) |
|
332 { |
|
333 iCommandObserver->CommandFinished( *this ); |
|
334 } |
|
335 return KErrNone; |
|
336 } |
|
337 |
|
338 // -------------------------------------------------------------------------- |
|
339 // CPsu2CopyFromPbkCmd::AcceptFetchSelectionL |
|
340 // -------------------------------------------------------------------------- |
|
341 // |
|
342 MPbk2FetchDlgObserver::TPbk2FetchAcceptSelection |
|
343 CPsu2CopyFromPbkCmd::AcceptFetchSelectionL |
|
344 ( TInt aNumMarkedEntries, MVPbkContactLink& /*aLastSelection*/ ) |
|
345 { |
|
346 MPbk2FetchDlgObserver::TPbk2FetchAcceptSelection ret = |
|
347 MPbk2FetchDlgObserver::EFetchNo; |
|
348 |
|
349 if (aNumMarkedEntries == 1) |
|
350 { |
|
351 ret = MPbk2FetchDlgObserver::EFetchYes; |
|
352 } |
|
353 |
|
354 return ret; |
|
355 } |
|
356 |
|
357 // -------------------------------------------------------------------------- |
|
358 // CPsu2CopyFromPbkCmd::FetchCompletedL |
|
359 // -------------------------------------------------------------------------- |
|
360 // |
|
361 void CPsu2CopyFromPbkCmd::FetchCompletedL |
|
362 ( MVPbkContactLinkArray* aMarkedEntries ) |
|
363 { |
|
364 delete iRetrieveOperation; |
|
365 iRetrieveOperation = NULL; |
|
366 |
|
367 if ( iTitlePaneText ) |
|
368 { |
|
369 SetTitlePaneTextL( *iTitlePaneText ); |
|
370 } |
|
371 |
|
372 |
|
373 __ASSERT_DEBUG( aMarkedEntries && aMarkedEntries->Count() > 0, |
|
374 Panic( EPanic_Pbk2FetchCompletedL ) ); |
|
375 |
|
376 iRetrieveOperation = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
377 ContactManager().RetrieveContactL |
|
378 ( aMarkedEntries->At(0), *this ); |
|
379 } |
|
380 |
|
381 // -------------------------------------------------------------------------- |
|
382 // CPsu2CopyFromPbkCmd::FetchCanceled |
|
383 // -------------------------------------------------------------------------- |
|
384 // |
|
385 void CPsu2CopyFromPbkCmd::FetchCanceled() |
|
386 { |
|
387 if ( iTitlePaneText ) |
|
388 { |
|
389 // cannot leave, not fatal if settings |
|
390 // title pane text fails |
|
391 TRAP_IGNORE(SetTitlePaneTextL( *iTitlePaneText )); |
|
392 } |
|
393 |
|
394 iCommandObserver->CommandFinished( *this ); |
|
395 } |
|
396 |
|
397 // -------------------------------------------------------------------------- |
|
398 // CPsu2CopyFromPbkCmd::FetchAborted |
|
399 // -------------------------------------------------------------------------- |
|
400 // |
|
401 void CPsu2CopyFromPbkCmd::FetchAborted() |
|
402 { |
|
403 if ( iTitlePaneText ) |
|
404 { |
|
405 // cannot leave, not fatal if settings |
|
406 // title pane text fails |
|
407 TRAP_IGNORE(SetTitlePaneTextL( *iTitlePaneText )); |
|
408 } |
|
409 |
|
410 if ( iCommandObserver ) |
|
411 { |
|
412 iCommandObserver->CommandFinished( *this ); |
|
413 } |
|
414 } |
|
415 |
|
416 // -------------------------------------------------------------------------- |
|
417 // CPsu2CopyFromPbkCmd::FetchOkToExit |
|
418 // -------------------------------------------------------------------------- |
|
419 // |
|
420 TBool CPsu2CopyFromPbkCmd::FetchOkToExit() |
|
421 { |
|
422 // FDN fetch cancel is always ok |
|
423 return ETrue; |
|
424 } |
|
425 |
|
426 // -------------------------------------------------------------------------- |
|
427 // CPsu2CopyFromPbkCmd::VPbkSingleContactOperationComplete |
|
428 // -------------------------------------------------------------------------- |
|
429 // |
|
430 void CPsu2CopyFromPbkCmd::VPbkSingleContactOperationComplete |
|
431 ( MVPbkContactOperationBase& /*aOperation*/, |
|
432 MVPbkStoreContact* aContact ) |
|
433 { |
|
434 delete iRetrieveOperation; |
|
435 iRetrieveOperation = NULL; |
|
436 |
|
437 delete iSourceStoreContact; |
|
438 iSourceStoreContact = aContact; |
|
439 ProcessDismissed( KErrNone ); |
|
440 } |
|
441 |
|
442 // -------------------------------------------------------------------------- |
|
443 // CPsu2CopyFromPbkCmd::VPbkSingleContactOperationFailed |
|
444 // -------------------------------------------------------------------------- |
|
445 // |
|
446 void CPsu2CopyFromPbkCmd::VPbkSingleContactOperationFailed |
|
447 ( MVPbkContactOperationBase& /*aOperation*/, TInt /*aError*/ ) |
|
448 { |
|
449 delete iRetrieveOperation; |
|
450 iRetrieveOperation = NULL; |
|
451 |
|
452 iNextTask = EPsu2Complete; |
|
453 IssueRequest(); |
|
454 } |
|
455 |
|
456 // -------------------------------------------------------------------------- |
|
457 // CPsu2CopyFromPbkCmd::ContactOperationCompleted |
|
458 // -------------------------------------------------------------------------- |
|
459 // |
|
460 void CPsu2CopyFromPbkCmd::ContactOperationCompleted |
|
461 (TContactOpResult /*aResult*/) |
|
462 { |
|
463 if ( iDecorator ) |
|
464 { |
|
465 iDecorator->ProcessStopped(); |
|
466 } |
|
467 } |
|
468 |
|
469 // -------------------------------------------------------------------------- |
|
470 // CPsu2CopyFromPbkCmd::ContactOperationFailed |
|
471 // -------------------------------------------------------------------------- |
|
472 // |
|
473 void CPsu2CopyFromPbkCmd::ContactOperationFailed |
|
474 ( TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/ ) |
|
475 { |
|
476 iLastError = aErrorCode; |
|
477 |
|
478 if ( iDecorator ) |
|
479 { |
|
480 iDecorator->ProcessStopped(); |
|
481 } |
|
482 } |
|
483 |
|
484 // -------------------------------------------------------------------------- |
|
485 // CPsu2CopyFromPbkCmd::ProcessDismissed |
|
486 // -------------------------------------------------------------------------- |
|
487 // |
|
488 void CPsu2CopyFromPbkCmd::ProcessDismissed( TInt /*aCancelCode*/ ) |
|
489 { |
|
490 // If fetch was dismissed, its time to query address |
|
491 if ( iNextTask == EPsu2ContactFetch ) |
|
492 { |
|
493 iNextTask = EPsu2QueryAddress; |
|
494 } |
|
495 |
|
496 // Error handling: if name string contains special characters, it |
|
497 // may have to be asked again if the string wouldn't fit into SIM. |
|
498 // Otherwise just skip the error and cancel. |
|
499 if ( iLastError != KErrNone ) |
|
500 { |
|
501 iLengthQuery = EFalse; |
|
502 iNextTask = EPsu2Complete; |
|
503 |
|
504 if ( iLastError == KErrGsm0707TextStringTooLong ) |
|
505 { |
|
506 iLengthQuery = ETrue; |
|
507 iNextTask = EPsu2CopyContact; |
|
508 } |
|
509 if ( iLastError == KErrGsmCCUnassignedNumber ) |
|
510 { |
|
511 ShowInformationNoteL( R_QTN_ERR_SMS_INVALID_NUMB, NULL ); |
|
512 } |
|
513 iLastError = KErrNone; |
|
514 } |
|
515 |
|
516 IssueRequest(); |
|
517 } |
|
518 |
|
519 // -------------------------------------------------------------------------- |
|
520 // CPsu2CopyFromPbkCmd::QueryContactL |
|
521 // -------------------------------------------------------------------------- |
|
522 // |
|
523 void CPsu2CopyFromPbkCmd::QueryContactL() |
|
524 { |
|
525 CPbk2FetchDlg::TParams params; |
|
526 // Launch the fetch dialog |
|
527 CPbk2FetchDlg* fetchDlg = CPbk2FetchDlg::NewL(params, *this); |
|
528 iFetchDialogEliminator = fetchDlg; |
|
529 iFetchDialogEliminator->ResetWhenDestroyed( &iFetchDialogEliminator ); |
|
530 |
|
531 // save the current title pane text: |
|
532 delete iTitlePaneText; |
|
533 iTitlePaneText = NULL; |
|
534 iTitlePaneText = GetTitlePaneTextL(); |
|
535 |
|
536 // set title pane text: |
|
537 HBufC* title = StringLoader::LoadLC( R_QTN_FDN_PB_FETCH_TITLE ); |
|
538 SetTitlePaneTextL( *title ); |
|
539 CleanupStack::PopAndDestroy(title); // stringloader string. |
|
540 |
|
541 fetchDlg->ExecuteLD(); |
|
542 } |
|
543 |
|
544 // -------------------------------------------------------------------------- |
|
545 // CPsu2CopyFromPbkCmd::QueryAddressL |
|
546 // -------------------------------------------------------------------------- |
|
547 // |
|
548 void CPsu2CopyFromPbkCmd::QueryAddressL() |
|
549 { |
|
550 TResourceReader resReader; |
|
551 CCoeEnv::Static()->CreateResourceReaderLC |
|
552 (resReader, R_PBK2_PHONE_NUMBER_SELECT); |
|
553 |
|
554 MPbk2ApplicationServices& appServices = |
|
555 Phonebook2::Pbk2AppUi()->ApplicationServices(); |
|
556 |
|
557 TPbk2AddressSelectParams params( |
|
558 *iSourceStoreContact, |
|
559 appServices.ContactManager(), |
|
560 appServices.NameFormatter(), |
|
561 appServices.FieldProperties(), |
|
562 resReader ); |
|
563 |
|
564 CPbk2AddressSelect* addressSelect = CPbk2AddressSelect::NewL(params); |
|
565 addressSelect->SetCba( R_AVKON_SOFTKEYS_SELECT_BACK__SELECT ); |
|
566 delete iStoreContactField; |
|
567 iStoreContactField = NULL; |
|
568 iStoreContactField = addressSelect->ExecuteLD(); |
|
569 CleanupStack::PopAndDestroy(); // resReader |
|
570 |
|
571 if ( iStoreContactField ) |
|
572 { |
|
573 iNextTask = EPsu2CopyContact; |
|
574 } |
|
575 else |
|
576 { |
|
577 if ( iPsu2UIExensionPlugin->IsEndKeyPressed() ) |
|
578 { |
|
579 iPsu2UIExensionPlugin->ClearEndKeyPressedFlag(); |
|
580 // User pressed the end key, ending to copy contact |
|
581 iNextTask = EPsu2Complete; |
|
582 } |
|
583 else |
|
584 { |
|
585 // User cancelled address selection, returning to fetch |
|
586 iNextTask = EPsu2ContactFetch; |
|
587 } |
|
588 } |
|
589 IssueRequest(); |
|
590 } |
|
591 |
|
592 // -------------------------------------------------------------------------- |
|
593 // CPsu2CopyFromPbkCmd::CopyContactL |
|
594 // -------------------------------------------------------------------------- |
|
595 // |
|
596 void CPsu2CopyFromPbkCmd::CopyContactL() |
|
597 { |
|
598 iNextTask = EPsu2Complete; |
|
599 if ( AddNameL(*iSourceStoreContact, *iTargetStoreContact) ) |
|
600 { |
|
601 if ( AppendSupportedFieldL(*iStoreContactField, |
|
602 *iTargetStoreContact) ) |
|
603 { |
|
604 iTargetStoreContact->CommitL(*this); |
|
605 ShowWaitNoteL(); |
|
606 iNextTask = EPsu2Commit; |
|
607 } |
|
608 } |
|
609 |
|
610 if ( iNextTask == EPsu2Complete ) |
|
611 { |
|
612 // User cancelled copy |
|
613 IssueRequest(); |
|
614 } |
|
615 } |
|
616 |
|
617 // -------------------------------------------------------------------------- |
|
618 // CPsu2CopyFromPbkCmd::IssueRequest |
|
619 // -------------------------------------------------------------------------- |
|
620 // |
|
621 void CPsu2CopyFromPbkCmd::IssueRequest() |
|
622 { |
|
623 TRequestStatus* status = &iStatus; |
|
624 User::RequestComplete( status, KErrNone ); |
|
625 SetActive(); |
|
626 } |
|
627 |
|
628 // -------------------------------------------------------------------------- |
|
629 // CPsu2CopyFromPbkCmd::AddNameL |
|
630 // -------------------------------------------------------------------------- |
|
631 // |
|
632 TBool CPsu2CopyFromPbkCmd::AddNameL |
|
633 ( MVPbkBaseContact& aSource, MVPbkStoreContact& aTarget ) |
|
634 { |
|
635 TBool ret( ETrue ); |
|
636 HBufC* title = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
637 NameFormatter().GetContactTitleOrNullL |
|
638 ( aSource.Fields(), |
|
639 MPbk2ContactNameFormatter::EPreserveLeadingSpaces ); |
|
640 |
|
641 if ( title ) |
|
642 { |
|
643 CleanupStack::PushL( title ); |
|
644 MVPbkStoreContactField* field = |
|
645 aTarget.CreateFieldLC( iSimFieldInfos->SimNameType() ); |
|
646 MVPbkContactFieldTextData& data = |
|
647 MVPbkContactFieldTextData::Cast( field->FieldData() ); |
|
648 TPtr ptrTitle( title->Des() ); |
|
649 TInt maxLength( data.MaxLength() ); |
|
650 |
|
651 if ( ptrTitle.Length() > maxLength || iLengthQuery ) |
|
652 { |
|
653 ret = QueryNameL( ptrTitle, maxLength ); |
|
654 } |
|
655 |
|
656 if ( ret ) |
|
657 { |
|
658 data.SetTextL( ptrTitle ); |
|
659 aTarget.AddFieldL(field); |
|
660 CleanupStack::Pop(); // field |
|
661 } |
|
662 else |
|
663 { |
|
664 CleanupStack::PopAndDestroy(); // field |
|
665 ret = EFalse; |
|
666 } |
|
667 CleanupStack::PopAndDestroy(title); |
|
668 } |
|
669 return ret; |
|
670 } |
|
671 |
|
672 // -------------------------------------------------------------------------- |
|
673 // CPsu2CopyFromPbkCmd::AppendSupportedFieldL |
|
674 // -------------------------------------------------------------------------- |
|
675 // |
|
676 TBool CPsu2CopyFromPbkCmd::AppendSupportedFieldL |
|
677 ( MVPbkStoreContactField& aSource, MVPbkStoreContact& aTarget) |
|
678 { |
|
679 TBool ret( ETrue ); |
|
680 const MVPbkFieldType* type = NULL; |
|
681 // Get the source field type |
|
682 const TInt maxPriority = |
|
683 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
684 ContactManager().FieldTypes().MaxMatchPriority(); |
|
685 for (TInt k = 0; k < maxPriority && !type; ++k) |
|
686 { |
|
687 type = aSource.MatchFieldType(k); |
|
688 } |
|
689 |
|
690 // The field possible can be copied to the SIM |
|
691 // Get the target(=SIM) field type for source type |
|
692 const MVPbkFieldType* simType = |
|
693 iSimFieldInfos->ConvertToSimType(*type); |
|
694 // Check if the sim store supports the converted field |
|
695 const MVPbkFieldTypeList& supportedTypes = |
|
696 iTargetStore.StoreProperties().SupportedFields(); |
|
697 if (simType && supportedTypes.ContainsSame(*simType)) |
|
698 { |
|
699 ret = CopyFieldL(aSource, aTarget, *simType); |
|
700 } |
|
701 return ret; |
|
702 } |
|
703 |
|
704 // -------------------------------------------------------------------------- |
|
705 // CPsu2CopyFromPbkCmd::CopyFieldL |
|
706 // -------------------------------------------------------------------------- |
|
707 // |
|
708 TBool CPsu2CopyFromPbkCmd::CopyFieldL |
|
709 ( const MVPbkBaseContactField& aFieldToCopy, |
|
710 MVPbkStoreContact& aTarget, const MVPbkFieldType& aSimType ) |
|
711 { |
|
712 TBool ret = ETrue; |
|
713 |
|
714 if (aFieldToCopy.FieldData().DataType() == EVPbkFieldStorageTypeText) |
|
715 { |
|
716 const MVPbkContactFieldTextData& sourceData = |
|
717 MVPbkContactFieldTextData::Cast(aFieldToCopy.FieldData()); |
|
718 MVPbkStoreContactField* field = aTarget.CreateFieldLC(aSimType); |
|
719 MVPbkContactFieldTextData& targetData = |
|
720 MVPbkContactFieldTextData::Cast(field->FieldData()); |
|
721 // Decrease 1 which is reserved for international prefix "+" |
|
722 TInt maxNumberLength( targetData.MaxLength() - 1 ); |
|
723 HBufC* buf = HBufC::NewLC( targetData.MaxLength() ); |
|
724 TPtr ptrBuf( buf->Des() ); |
|
725 ptrBuf.Copy( sourceData.Text().Right( maxNumberLength ) ); |
|
726 |
|
727 // Because there is always one space reserved for the international prefix "+", |
|
728 // so the actual maximum digits length should be targetData.MaxLength() - 1, |
|
729 // So here use targetData.MaxLength() - 1 instead of targetData.MaxLength() to do compare to |
|
730 // show the Number Query dialog if need |
|
731 if ( sourceData.Text().Length() > ( targetData.MaxLength() - 1 ) ) |
|
732 { |
|
733 do |
|
734 { |
|
735 // Keep original data in query |
|
736 ptrBuf.Zero(); |
|
737 ptrBuf.Copy( sourceData.Text().Right( maxNumberLength ) ); |
|
738 ret = QueryNumberL( |
|
739 R_QTN_PBCOP_NOTE_NUMBER_MAX_LENGTH, |
|
740 ptrBuf, maxNumberLength, targetData.MaxLength() ); |
|
741 } |
|
742 while ( ptrBuf.Length() > maxNumberLength && |
|
743 ptrBuf[0] != KPSu2InternationalPrefix()[0] ); |
|
744 } |
|
745 |
|
746 if ( ret ) |
|
747 { |
|
748 targetData.SetTextL( ptrBuf ); |
|
749 aTarget.AddFieldL(field); |
|
750 CleanupStack::PopAndDestroy( buf ); |
|
751 CleanupStack::Pop(); // field |
|
752 } |
|
753 else |
|
754 { |
|
755 CleanupStack::PopAndDestroy( buf ); |
|
756 CleanupStack::PopAndDestroy(); // field |
|
757 } |
|
758 } |
|
759 return ret; |
|
760 } |
|
761 |
|
762 // -------------------------------------------------------------------------- |
|
763 // CPsu2CopyFromPbkCmd::SetTitlePaneTextL |
|
764 // -------------------------------------------------------------------------- |
|
765 // |
|
766 void CPsu2CopyFromPbkCmd::SetTitlePaneTextL( const TDesC& aTitle ) |
|
767 { |
|
768 CEikStatusPane* statusPane = |
|
769 CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
|
770 if ( statusPane && statusPane->PaneCapabilities |
|
771 ( TUid::Uid( EEikStatusPaneUidTitle ) ).IsPresent() ) |
|
772 { |
|
773 CAknTitlePane* titlePane = static_cast<CAknTitlePane*>( |
|
774 statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
775 |
|
776 titlePane->SetTextL( aTitle ); // takes ownership of title |
|
777 } |
|
778 } |
|
779 |
|
780 // -------------------------------------------------------------------------- |
|
781 // CPsu2CopyFromPbkCmd::GetTitlePaneTextL |
|
782 // -------------------------------------------------------------------------- |
|
783 // |
|
784 HBufC* CPsu2CopyFromPbkCmd::GetTitlePaneTextL() |
|
785 { |
|
786 CEikStatusPane* statusPane = |
|
787 CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
|
788 if ( statusPane && statusPane->PaneCapabilities |
|
789 ( TUid::Uid( EEikStatusPaneUidTitle ) ).IsPresent() ) |
|
790 { |
|
791 CAknTitlePane* titlePane = static_cast<CAknTitlePane*>( |
|
792 statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
793 |
|
794 return titlePane->Text()->AllocL(); |
|
795 } |
|
796 else |
|
797 { |
|
798 return NULL; |
|
799 } |
|
800 } |
|
801 |
|
802 // -------------------------------------------------------------------------- |
|
803 // CPsu2CopyFromPbkCmd::QueryNameL |
|
804 // -------------------------------------------------------------------------- |
|
805 // |
|
806 TBool CPsu2CopyFromPbkCmd::QueryNameL( |
|
807 TDes& aName, TInt aMaxDataLength ) |
|
808 { |
|
809 TBool ret( ETrue ); |
|
810 // Not sure if the encoding for SIM contact names is UTF-8, but it is Ok |
|
811 // because it is just used here to check if there are any unicode |
|
812 // characters in the text |
|
813 CPsu2CharConv* charConv = CPsu2CharConv::NewLC( |
|
814 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
815 ContactManager().FsSession(), |
|
816 KCharacterSetIdentifierUtf8 ); |
|
817 HBufC* prompt(0); |
|
818 |
|
819 if( charConv->IsUnicodeL( aName ) ) |
|
820 { |
|
821 // If the name includes unicode we cannot determine the actual |
|
822 // maximum length reliably so use a note without the maximum |
|
823 // length value |
|
824 prompt = StringLoader::LoadLC( |
|
825 R_QTN_PBSAV_UNICODE_NAME_TOO_LONG ); |
|
826 } |
|
827 else |
|
828 { |
|
829 prompt = StringLoader::LoadLC( |
|
830 R_QTN_PBCOP_NOTE_NAME_MAX_LENGTH, aMaxDataLength ); |
|
831 } |
|
832 |
|
833 // Check if the name needs to be cut to fit in the editor |
|
834 if( aName.Length() > aMaxDataLength ) |
|
835 { |
|
836 aName.SetLength( aMaxDataLength ); |
|
837 } |
|
838 |
|
839 CAknTextQueryDialog* dlg = |
|
840 CAknTextQueryDialog::NewL( aName ); |
|
841 dlg->SetMaxLength( aMaxDataLength ); |
|
842 ret = dlg->ExecuteLD( R_PSU2_GENERAL_TEXT_QUERY, *prompt ); |
|
843 CleanupStack::PopAndDestroy( prompt ); |
|
844 CleanupStack::PopAndDestroy( charConv ); |
|
845 |
|
846 return ret; |
|
847 } |
|
848 |
|
849 // -------------------------------------------------------------------------- |
|
850 // CPsu2CopyFromPbkCmd::QueryNumberL |
|
851 // -------------------------------------------------------------------------- |
|
852 // |
|
853 TBool CPsu2CopyFromPbkCmd::QueryNumberL |
|
854 ( TInt aPromptResourceId, TDes& aData, |
|
855 TInt aMaxDataLength, TInt aMaxEditorLength ) |
|
856 { |
|
857 TBool ret( ETrue ); |
|
858 HBufC* prompt = StringLoader::LoadLC( |
|
859 aPromptResourceId, aMaxDataLength ); |
|
860 |
|
861 if( aData.Length() > aMaxDataLength ) |
|
862 { |
|
863 aData.SetLength( aMaxDataLength ); |
|
864 } |
|
865 CAknTextQueryDialog* dlg = |
|
866 CAknTextQueryDialog::NewL( aData ); |
|
867 dlg->SetMaxLength( aMaxEditorLength ); |
|
868 ret = dlg->ExecuteLD( R_PSU2_GENERAL_NUMBER_QUERY, *prompt ); |
|
869 CleanupStack::PopAndDestroy( prompt ); |
|
870 |
|
871 return ret; |
|
872 } |
|
873 |
|
874 // -------------------------------------------------------------------------- |
|
875 // CPsu2CopyFromPbkCmd::ShowWaitNoteL |
|
876 // -------------------------------------------------------------------------- |
|
877 // |
|
878 void CPsu2CopyFromPbkCmd::ShowWaitNoteL() |
|
879 { |
|
880 delete iDecorator; |
|
881 iDecorator = NULL; |
|
882 iDecorator = Pbk2ProcessDecoratorFactory::CreateWaitNoteDecoratorL |
|
883 ( R_QTN_GEN_NOTE_FETCHING, ETrue ); |
|
884 iDecorator->SetObserver( *this ); |
|
885 iDecorator->ProcessStartedL( 0 ); // wait note doesn't care about amount |
|
886 } |
|
887 |
|
888 // End of File |