|
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 USIM UI contact editor extension. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPsu2ContactEditorExtension.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPsu2CharConv.h" |
|
23 #include "CPsu2FdnContactEditorPhoneNumberField.h" |
|
24 #include <CPbk2UIExtensionPlugin.h> |
|
25 #include <Pbk2USimUIRes.rsg> |
|
26 #include <Pbk2UIControls.rsg> |
|
27 #include <Pbk2CommonUi.rsg> |
|
28 #include <Pbk2UIControls.hrh> |
|
29 #include <MPbk2ContactEditorControl.h> |
|
30 #include <CPbk2StoreProperty.h> |
|
31 #include <CPbk2StorePropertyArray.h> |
|
32 #include <MPbk2FieldProperty.h> |
|
33 #include <CPbk2FieldPropertyArray.h> |
|
34 #include <MPbk2ApplicationServices.h> |
|
35 #include <MPbk2AppUi.h> |
|
36 |
|
37 // Virtual Phonebook |
|
38 #include <MVPbkStoreContact.h> |
|
39 #include <MVPbkContactStore.h> |
|
40 #include <MVPbkContactStoreProperties.h> |
|
41 #include <TVPbkContactStoreUriPtr.h> |
|
42 #include <VPbkContactStoreUris.h> |
|
43 #include <MVPbkFieldType.h> |
|
44 #include <CVPbkFieldTypeSelector.h> |
|
45 #include <CVPbkContactManager.h> |
|
46 #include <MVPbkStoreContactField.h> |
|
47 #include <MVPbkStoreContactFieldCollection.h> |
|
48 #include <MVPbkContactFieldTextData.h> |
|
49 |
|
50 // System includes |
|
51 #include <etelmmerr.h> |
|
52 #include <gsmerror.h> |
|
53 #include <exterror.h> |
|
54 #include <eikmenub.h> |
|
55 #include <StringLoader.h> |
|
56 #include <aknnotewrappers.h> |
|
57 #include <barsread.h> |
|
58 #include <eikbtgpc.h> |
|
59 #include <charconv.h> |
|
60 |
|
61 // Debugging headers |
|
62 #include <Pbk2Debug.h> |
|
63 |
|
64 /// Unnamed namespace for local definitions |
|
65 namespace { |
|
66 |
|
67 /** |
|
68 * Matches field types. |
|
69 * |
|
70 * @param aFieldTypeList The field type list to use. |
|
71 * @param aField The field to match. |
|
72 * @return The matched field type. |
|
73 */ |
|
74 const MVPbkFieldType* MatchFieldType |
|
75 (const MVPbkFieldTypeList& aFieldTypeList, |
|
76 const MVPbkBaseContactField& aField) |
|
77 { |
|
78 const MVPbkFieldType* result = NULL; |
|
79 |
|
80 for (TInt matchPriority = 0; |
|
81 matchPriority <= aFieldTypeList.MaxMatchPriority() && !result; |
|
82 ++matchPriority) |
|
83 { |
|
84 result = aField.MatchFieldType(matchPriority); |
|
85 } |
|
86 |
|
87 return result; |
|
88 } |
|
89 |
|
90 /** |
|
91 * Checks is the given field type included in |
|
92 * the given selection. |
|
93 * |
|
94 * @param aField The field whose type to check. |
|
95 * @param aFieldTypeList List of field types. |
|
96 * @param aResourceId Selector's resource id. |
|
97 * @return ETrue if field type is included. |
|
98 */ |
|
99 TBool IsFieldTypeIncludedL( |
|
100 const MVPbkBaseContactField& aField, |
|
101 const MVPbkFieldTypeList& aFieldTypeList, |
|
102 const TInt aResourceId) |
|
103 { |
|
104 TResourceReader resReader; |
|
105 CCoeEnv::Static()->CreateResourceReaderLC |
|
106 (resReader, aResourceId); |
|
107 |
|
108 CVPbkFieldTypeSelector* selector = |
|
109 CVPbkFieldTypeSelector::NewL(resReader, aFieldTypeList); |
|
110 CleanupStack::PopAndDestroy(); // resReader |
|
111 // Get the field type |
|
112 const MVPbkFieldType* fieldType = MatchFieldType |
|
113 (aFieldTypeList, aField); |
|
114 |
|
115 TBool ret = EFalse; |
|
116 if ( fieldType ) |
|
117 { |
|
118 ret = selector->IsFieldTypeIncluded(*fieldType); |
|
119 } |
|
120 delete selector; |
|
121 return ret; |
|
122 } |
|
123 |
|
124 /** |
|
125 * Checks is the given field type included in |
|
126 * the given selection. |
|
127 * |
|
128 * @param aFieldType The field type to check. |
|
129 * @param aFieldTypeList Field type list. |
|
130 * @param aResourceId Selector's resource id. |
|
131 * @return ETrue if field type is included. |
|
132 */ |
|
133 TBool IsFieldTypeIncludedL( |
|
134 const MVPbkFieldType& aFieldType, |
|
135 const MVPbkFieldTypeList& aFieldTypeList, |
|
136 const TInt aResourceId) |
|
137 { |
|
138 // Get the field type |
|
139 TResourceReader resReader; |
|
140 CCoeEnv::Static()->CreateResourceReaderLC |
|
141 (resReader, aResourceId); |
|
142 |
|
143 CVPbkFieldTypeSelector* selector = |
|
144 CVPbkFieldTypeSelector::NewL(resReader, aFieldTypeList); |
|
145 CleanupStack::PopAndDestroy(); // resReader |
|
146 |
|
147 TBool ret = selector->IsFieldTypeIncluded(aFieldType); |
|
148 delete selector; |
|
149 return ret; |
|
150 } |
|
151 |
|
152 /// Text was too long (name or second name) |
|
153 const TInt KErrTextTooLong = KErrGsm0707TextStringTooLong; |
|
154 |
|
155 /// Number too long (this shouldn't be possible. It probably means that |
|
156 /// ETel store GetInfo returns incorrect max length. |
|
157 const TInt KErrNumberTooLong = KErrGsm0707DialStringTooLong; |
|
158 |
|
159 /// Number contained characters that couldn't be saved |
|
160 const TInt KErrInvalidNumber = KErrGsmCCUnassignedNumber; |
|
161 |
|
162 /// (U)SIM store is full |
|
163 const TInt KErrContactStoreFull = KErrMMEtelMaxReached; |
|
164 |
|
165 /// Second name file is full in USIM |
|
166 const TInt KErrSecondNameStoreFull = KErrGsmSimServSneFull; |
|
167 |
|
168 /// Additional number file is full in USIM |
|
169 const TInt KErrAdditionalNumberStoreFull = KErrGsmSimServAnrFull; |
|
170 |
|
171 /// Email file is full in USIM |
|
172 const TInt KErrEmailStoreFull = KErrGsmSimServEmailFull; |
|
173 |
|
174 } /// namespace |
|
175 |
|
176 // -------------------------------------------------------------------------- |
|
177 // CPsu2ContactEditorExtension::CPsu2ContactEditorExtension |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 CPsu2ContactEditorExtension::CPsu2ContactEditorExtension |
|
181 ( CVPbkContactManager& aContactManager, |
|
182 MVPbkStoreContact& aContact, |
|
183 MPbk2ContactEditorControl& aEditorControl ) : |
|
184 iContactManager( aContactManager ), |
|
185 iContact( aContact ), |
|
186 iEditorControl( aEditorControl ) |
|
187 { |
|
188 } |
|
189 |
|
190 // -------------------------------------------------------------------------- |
|
191 // CPsu2ContactEditorExtension::~CPsu2ContactEditorExtension |
|
192 // -------------------------------------------------------------------------- |
|
193 // |
|
194 CPsu2ContactEditorExtension::~CPsu2ContactEditorExtension() |
|
195 { |
|
196 } |
|
197 |
|
198 // -------------------------------------------------------------------------- |
|
199 // CPsu2ContactEditorExtension::ConstructL |
|
200 // -------------------------------------------------------------------------- |
|
201 // |
|
202 inline void CPsu2ContactEditorExtension::ConstructL() |
|
203 { |
|
204 iContactOrigin = ContactOrigin(); |
|
205 } |
|
206 |
|
207 // -------------------------------------------------------------------------- |
|
208 // CPsu2ContactEditorExtension::NewL |
|
209 // -------------------------------------------------------------------------- |
|
210 // |
|
211 CPsu2ContactEditorExtension* CPsu2ContactEditorExtension::NewL |
|
212 ( CVPbkContactManager& aContactManager, |
|
213 MVPbkStoreContact& aContact, |
|
214 MPbk2ContactEditorControl& aEditorControl ) |
|
215 { |
|
216 CPsu2ContactEditorExtension* self = |
|
217 new (ELeave) CPsu2ContactEditorExtension |
|
218 (aContactManager, aContact, aEditorControl); |
|
219 CleanupStack::PushL(self); |
|
220 self->ConstructL(); |
|
221 CleanupStack::Pop(self); |
|
222 return self; |
|
223 } |
|
224 |
|
225 // -------------------------------------------------------------------------- |
|
226 // CPsu2ContactEditorExtension::CreateEditorFieldL |
|
227 // -------------------------------------------------------------------------- |
|
228 // |
|
229 MPbk2ContactEditorField* CPsu2ContactEditorExtension::CreateEditorFieldL |
|
230 ( MVPbkStoreContactField& aField, |
|
231 const MPbk2FieldProperty& aFieldProperty, |
|
232 MPbk2ContactEditorUiBuilder& aUiBuilder, |
|
233 CPbk2IconInfoContainer& aIconInfoContainer ) |
|
234 { |
|
235 MPbk2ContactEditorField* field = NULL; |
|
236 |
|
237 if (iContactOrigin == EPsu2FdnContact) |
|
238 { |
|
239 if (aFieldProperty.CtrlType() == EPbk2FieldCtrlTypePhoneNumberEditor) |
|
240 { |
|
241 field = CPsu2FdnContactEditorPhoneNumberField::NewL |
|
242 ( aField, aFieldProperty, aUiBuilder, aIconInfoContainer ); |
|
243 } |
|
244 } |
|
245 return field; |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CPsu2ContactEditorExtension::DynInitMenuPaneL |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 void CPsu2ContactEditorExtension::DynInitMenuPaneL |
|
253 ( TInt aResourceId, CEikMenuPane* aMenuPane ) |
|
254 { |
|
255 // FDN contact has additional rules for menu filtering |
|
256 if (iContactOrigin == EPsu2FdnContact) |
|
257 { |
|
258 if (aResourceId == R_PBK2_CONTACTEDITOR_MENUPANE || |
|
259 aResourceId == R_PBK2_CONTACTEDITOR_CONTEXT_MENUPANE) |
|
260 { |
|
261 // No add/delete item menu in FDN |
|
262 aMenuPane->SetItemDimmed(EPbk2CmdAddItem, ETrue); |
|
263 aMenuPane->SetItemDimmed(EPbk2CmdDeleteItem, ETrue); |
|
264 } |
|
265 } |
|
266 |
|
267 } |
|
268 |
|
269 // -------------------------------------------------------------------------- |
|
270 // CPsu2ContactEditorExtension::ProcessCommandL |
|
271 // -------------------------------------------------------------------------- |
|
272 // |
|
273 TBool CPsu2ContactEditorExtension::ProcessCommandL |
|
274 ( TInt aCommandId ) |
|
275 { |
|
276 switch( aCommandId ) |
|
277 { |
|
278 // If Pbk2 goes to the backgound, child applications are closed |
|
279 case EAknCmdHideInBackground: |
|
280 { |
|
281 iEndKeyWasPressed = ETrue; |
|
282 } |
|
283 break; |
|
284 |
|
285 default: |
|
286 break; |
|
287 } |
|
288 return EFalse; |
|
289 } |
|
290 |
|
291 // -------------------------------------------------------------------------- |
|
292 // CPsu2ContactEditorExtension::OkToDeleteContactL |
|
293 // -------------------------------------------------------------------------- |
|
294 // |
|
295 TBool CPsu2ContactEditorExtension::OkToDeleteContactL |
|
296 ( MPbk2ContactEditorEventObserver::TParams& /*aParams*/ ) |
|
297 { |
|
298 return ETrue; |
|
299 } |
|
300 |
|
301 // -------------------------------------------------------------------------- |
|
302 // CPsu2ContactEditorExtension::OkToSaveContactL |
|
303 // -------------------------------------------------------------------------- |
|
304 // |
|
305 TBool CPsu2ContactEditorExtension::OkToSaveContactL |
|
306 ( MPbk2ContactEditorEventObserver::TParams& /*aParams*/ ) |
|
307 { |
|
308 TBool ret = ETrue; |
|
309 |
|
310 // FDN contact has additional rules for saving |
|
311 if (iContactOrigin == EPsu2FdnContact) |
|
312 { |
|
313 // Test is there a filled phone number field |
|
314 TBool controlIsEmpty = ETrue; |
|
315 TInt startIndex = 0; // find from start |
|
316 TInt numberControl = iEditorControl.IndexOfCtrlType |
|
317 (EPbk2FieldCtrlTypePhoneNumberEditor, startIndex); |
|
318 if (numberControl != KErrNotFound) |
|
319 { |
|
320 controlIsEmpty = iEditorControl.IsControlEmptyL(numberControl); |
|
321 } |
|
322 if (controlIsEmpty) |
|
323 { |
|
324 if( iEndKeyWasPressed ) |
|
325 { |
|
326 iEndKeyWasPressed = EFalse; |
|
327 } |
|
328 else |
|
329 { |
|
330 ShowInformationNoteL(R_QTN_FDN_NO_ALLOWED_SAVE, EFalse); |
|
331 } |
|
332 ret = EFalse; |
|
333 } |
|
334 } |
|
335 |
|
336 return ret; |
|
337 } |
|
338 |
|
339 // -------------------------------------------------------------------------- |
|
340 // CPsu2ContactEditorExtension::ModifyButtonGroupContainerL |
|
341 // -------------------------------------------------------------------------- |
|
342 // |
|
343 void CPsu2ContactEditorExtension::ModifyButtonGroupContainerL |
|
344 ( CEikButtonGroupContainer& aButtonGroupContainer ) |
|
345 { |
|
346 // Get FDN editor middle softkey pointer |
|
347 CCoeControl* msk = aButtonGroupContainer.ControlOrNull( EAknSoftkeyEmpty ); |
|
348 |
|
349 // FDN editor has different middle softkey |
|
350 if ( iContactOrigin == EPsu2FdnContact && !msk ) |
|
351 { |
|
352 aButtonGroupContainer.SetCommandSetL |
|
353 ( R_PSU_FDN_SOFTKEYS_OPTIONS_DONE_EMPTY ); |
|
354 } |
|
355 } |
|
356 |
|
357 // -------------------------------------------------------------------------- |
|
358 // CPsu2ContactEditorExtension::DoRelease |
|
359 // -------------------------------------------------------------------------- |
|
360 // |
|
361 void CPsu2ContactEditorExtension::DoRelease() |
|
362 { |
|
363 delete this; |
|
364 } |
|
365 |
|
366 // -------------------------------------------------------------------------- |
|
367 // CPsu2ContactEditorExtension::ContactEditorOperationCompleted |
|
368 // -------------------------------------------------------------------------- |
|
369 // |
|
370 void CPsu2ContactEditorExtension::ContactEditorOperationCompleted |
|
371 ( MVPbkContactObserver::TContactOpResult /*aResult*/, |
|
372 TParams /*aParams*/ ) |
|
373 { |
|
374 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
375 ("CPsu2ContactEditorExtension::ContactEditorOperationCompleted")); |
|
376 |
|
377 // Do nothing |
|
378 } |
|
379 |
|
380 // -------------------------------------------------------------------------- |
|
381 // CPsu2ContactEditorExtension::ContactEditorOperationFailed |
|
382 // -------------------------------------------------------------------------- |
|
383 // |
|
384 void CPsu2ContactEditorExtension::ContactEditorOperationFailed |
|
385 ( MVPbkContactObserver::TContactOp /*aOpCode*/, |
|
386 TInt aErrorCode, TParams /*aParams*/, TFailParams& aFailParams ) |
|
387 { |
|
388 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
389 ("CPsu2ContactEditorExtension::ContactEditorOperationFailed code: %d"), |
|
390 aErrorCode); |
|
391 |
|
392 if ( !aFailParams.iErrorNotified && |
|
393 iContactOrigin != EPsu2NotSimContact ) |
|
394 { |
|
395 TRAPD( err, HandleContactEditorOperationFailedL |
|
396 ( aErrorCode, aFailParams ) ); |
|
397 if ( err != KErrNone ) |
|
398 { |
|
399 CCoeEnv::Static()->HandleError( err ); |
|
400 } |
|
401 } |
|
402 } |
|
403 |
|
404 // -------------------------------------------------------------------------- |
|
405 // CPsu2ContactEditorExtension::ContactOrigin |
|
406 // -------------------------------------------------------------------------- |
|
407 // |
|
408 inline TInt CPsu2ContactEditorExtension::ContactOrigin() const |
|
409 { |
|
410 TInt ret = EPsu2NotSimContact; |
|
411 |
|
412 TVPbkContactStoreUriPtr uri = |
|
413 iContact.ParentStore().StoreProperties().Uri(); |
|
414 |
|
415 TVPbkContactStoreUriPtr adnUri(VPbkContactStoreUris::SimGlobalAdnUri()); |
|
416 TVPbkContactStoreUriPtr sdnUri(VPbkContactStoreUris::SimGlobalSdnUri()); |
|
417 TVPbkContactStoreUriPtr fdnUri(VPbkContactStoreUris::SimGlobalFdnUri()); |
|
418 |
|
419 if (uri.Compare(adnUri, |
|
420 TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) == 0) |
|
421 { |
|
422 ret = EPsu2AdnContact; |
|
423 } |
|
424 else if (uri.Compare(sdnUri, |
|
425 TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) == 0) |
|
426 { |
|
427 ret = EPsu2SdnContact; |
|
428 } |
|
429 else if (uri.Compare(fdnUri, |
|
430 TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) == 0) |
|
431 { |
|
432 ret = EPsu2FdnContact; |
|
433 } |
|
434 |
|
435 return ret; |
|
436 } |
|
437 |
|
438 // -------------------------------------------------------------------------- |
|
439 // CPsu2ContactEditorExtension::ShowInformationNote |
|
440 // -------------------------------------------------------------------------- |
|
441 // |
|
442 void CPsu2ContactEditorExtension::ShowInformationNote |
|
443 ( TInt aResourceId, TBool aShowStoreName ) const |
|
444 { |
|
445 // Somewhat safe to ignore errors in note displaying |
|
446 TRAP_IGNORE( ShowInformationNoteL( aResourceId, aShowStoreName ) ); |
|
447 } |
|
448 |
|
449 // -------------------------------------------------------------------------- |
|
450 // CPsu2ContactEditorExtension::ShowInformationNoteL |
|
451 // -------------------------------------------------------------------------- |
|
452 // |
|
453 void CPsu2ContactEditorExtension::ShowInformationNoteL |
|
454 ( TInt aResourceId, TBool aShowStoreName ) const |
|
455 { |
|
456 HBufC* prompt = NULL; |
|
457 const TDesC* storeName = NULL; |
|
458 |
|
459 if (aShowStoreName) |
|
460 { |
|
461 // Fetch store name |
|
462 TVPbkContactStoreUriPtr uri = |
|
463 iContact.ParentStore().StoreProperties().Uri(); |
|
464 const CPbk2StoreProperty* storeProperty = |
|
465 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
466 StoreProperties().FindProperty(uri); |
|
467 |
|
468 if (storeProperty) |
|
469 { |
|
470 storeName = &storeProperty->StoreName(); |
|
471 } |
|
472 else |
|
473 { |
|
474 storeName = &uri.UriDes(); |
|
475 } |
|
476 } |
|
477 |
|
478 if (aShowStoreName) |
|
479 { |
|
480 prompt = StringLoader::LoadL(aResourceId, *storeName); |
|
481 } |
|
482 else |
|
483 { |
|
484 prompt = StringLoader::LoadL(aResourceId); |
|
485 } |
|
486 |
|
487 if (prompt) |
|
488 { |
|
489 CleanupStack::PushL(prompt); |
|
490 // This is a waiting dialog because the editor might be |
|
491 // used from the application server and the information note will |
|
492 // disappear if the application server closes before the |
|
493 // note timeout has expired, thus causing blinking |
|
494 CAknInformationNote* noteDlg = new(ELeave) CAknInformationNote(ETrue); |
|
495 noteDlg->ExecuteLD(*prompt); |
|
496 CleanupStack::PopAndDestroy(); // prompt |
|
497 } |
|
498 } |
|
499 |
|
500 // -------------------------------------------------------------------------- |
|
501 // CPsu2ContactEditorExtension::FocusControlOfType |
|
502 // -------------------------------------------------------------------------- |
|
503 // |
|
504 void CPsu2ContactEditorExtension::FocusControlOfType |
|
505 ( TPbk2FieldCtrlType aType ) |
|
506 { |
|
507 TInt focusIndex = 0; |
|
508 TInt startIndex = 0; // find from start |
|
509 focusIndex = iEditorControl.IndexOfCtrlType(aType, startIndex); |
|
510 if (focusIndex > KErrNotFound) |
|
511 { |
|
512 iEditorControl.SetFocus(focusIndex); |
|
513 } |
|
514 } |
|
515 |
|
516 // -------------------------------------------------------------------------- |
|
517 // CPsu2ContactEditorExtension::AddLastNameFieldL |
|
518 // -------------------------------------------------------------------------- |
|
519 // |
|
520 void CPsu2ContactEditorExtension::AddLastNameFieldL() |
|
521 { |
|
522 // First check does the contact have the last name field |
|
523 TBool found = EFalse; |
|
524 MVPbkStoreContactFieldCollection& fields = iContact.Fields(); |
|
525 const MVPbkFieldTypeList& fieldTypes = iContactManager.FieldTypes(); |
|
526 |
|
527 const TInt fieldCount = fields.FieldCount(); |
|
528 for (TInt i=0; i<fieldCount; ++i) |
|
529 { |
|
530 if (IsFieldTypeIncludedL(fields.FieldAt(i), |
|
531 fieldTypes, R_PHONEBOOK2_LAST_NAME_SELECTOR)) |
|
532 { |
|
533 found = ETrue; |
|
534 break; |
|
535 } |
|
536 } |
|
537 |
|
538 if (!found) |
|
539 { |
|
540 // Get field properties |
|
541 CPbk2FieldPropertyArray& fieldProperties = |
|
542 Phonebook2::Pbk2AppUi()->ApplicationServices().FieldProperties(); |
|
543 |
|
544 // Find the correct field type and then add it to contact |
|
545 const TInt fieldPropCount = fieldProperties.Count(); |
|
546 for (TInt j=0; j<fieldPropCount; ++j) |
|
547 { |
|
548 const MPbk2FieldProperty& prop = fieldProperties.At(j); |
|
549 |
|
550 if (IsFieldTypeIncludedL(prop.FieldType(), |
|
551 fieldTypes, R_PHONEBOOK2_LAST_NAME_SELECTOR)) |
|
552 { |
|
553 MVPbkStoreContactField* field = iContact.CreateFieldLC |
|
554 (prop.FieldType()); |
|
555 iContact.AddFieldL(field); |
|
556 CleanupStack::Pop(); // field |
|
557 break; |
|
558 } |
|
559 } |
|
560 } |
|
561 } |
|
562 |
|
563 // -------------------------------------------------------------------------- |
|
564 // CPsu2ContactEditorExtension::HandleTextTooLongL |
|
565 // -------------------------------------------------------------------------- |
|
566 // |
|
567 void CPsu2ContactEditorExtension::HandleTextTooLongL |
|
568 ( TFailParams& aFailParams ) const |
|
569 { |
|
570 CPsu2CharConv* charConv = |
|
571 CPsu2CharConv::NewLC( Phonebook2::Pbk2AppUi()-> |
|
572 ApplicationServices().ContactManager().FsSession(), |
|
573 KCharacterSetIdentifierSms7Bit ); |
|
574 |
|
575 // Default to 'name too long' note |
|
576 TInt noteResource = R_QTN_PBSAV_UNICODE_NAME_TOO_LONG; |
|
577 TInt offender = KErrNotFound; |
|
578 |
|
579 const MVPbkFieldTypeList& fieldTypes = |
|
580 iContactManager.FieldTypes(); |
|
581 const MVPbkStoreContactFieldCollection& fields = iContact.Fields(); |
|
582 |
|
583 const TInt fieldCount = fields.FieldCount(); |
|
584 for ( TInt i = 0; i< fieldCount; ++i ) |
|
585 { |
|
586 const MVPbkStoreContactField& field = |
|
587 fields.FieldAt( i ); |
|
588 |
|
589 const MVPbkContactFieldData& fieldData = field.FieldData(); |
|
590 |
|
591 if ( fieldData.DataType() == EVPbkFieldStorageTypeText ) |
|
592 { |
|
593 const MVPbkContactFieldTextData* textData = |
|
594 &MVPbkContactFieldTextData::Cast( fieldData ); |
|
595 |
|
596 CPsu2CharConv::TPsu2FieldValidity validity; |
|
597 charConv->CheckFieldValidityL( |
|
598 textData->Text(), |
|
599 textData->MaxLength(), |
|
600 validity ); |
|
601 |
|
602 if ( validity == CPsu2CharConv::ETooLong ) |
|
603 { |
|
604 offender = i; |
|
605 |
|
606 if ( IsFieldTypeIncludedL( field, |
|
607 fieldTypes, R_PHONEBOOK2_EMAIL_SELECTOR ) ) |
|
608 { |
|
609 // We have to change the note |
|
610 noteResource = R_QTN_SIMP_NOTE_EMAIL_TOO_LONG2; |
|
611 } |
|
612 break; |
|
613 } |
|
614 } |
|
615 } |
|
616 |
|
617 CleanupStack::PopAndDestroy( charConv ); |
|
618 |
|
619 // Set focus to the guilty field |
|
620 if ( offender != KErrNotFound ) |
|
621 { |
|
622 iEditorControl.SetFocus( offender ); |
|
623 } |
|
624 |
|
625 ShowInformationNote( noteResource, EFalse ); |
|
626 |
|
627 // Don't offer relocation service for FDN contact |
|
628 // because it is security risk. |
|
629 if ( iContactOrigin != EPsu2FdnContact ) |
|
630 { |
|
631 // Request contact relocation |
|
632 aFailParams.iErrorCode = KErrNotSupported; |
|
633 } |
|
634 } |
|
635 |
|
636 // -------------------------------------------------------------------------- |
|
637 // CPsu2ContactEditorExtension::HandleContactEditorOperationFailedL |
|
638 // -------------------------------------------------------------------------- |
|
639 // |
|
640 void CPsu2ContactEditorExtension::HandleContactEditorOperationFailedL |
|
641 ( TInt aErrorCode, TFailParams& aFailParams ) |
|
642 { |
|
643 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING( |
|
644 "CPsu2ContactEditorExtension::HandleContactEditorOperationFailedL 0x%x" ), |
|
645 this ); |
|
646 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING( |
|
647 "CPsu...::HandleContactEditorOperationFailedL ERROR:%d" ), |
|
648 aErrorCode ); |
|
649 |
|
650 |
|
651 // Check if SIM specific error code |
|
652 switch ( aErrorCode ) |
|
653 { |
|
654 case KErrContactStoreFull: // FALLTHROUGH |
|
655 { |
|
656 // The contact does not fit to (U)SIM |
|
657 ShowInformationNote( R_QTN_PHOB_NOTE_STORE_FULL, ETrue ); |
|
658 |
|
659 aFailParams.iErrorNotified = ETrue; |
|
660 aFailParams.iCloseEditor = ETrue; |
|
661 break; |
|
662 } |
|
663 |
|
664 case KErrSecondNameStoreFull: // FALLTHROUGH |
|
665 case KErrAdditionalNumberStoreFull: // FALLTHROUGH |
|
666 case KErrEmailStoreFull: |
|
667 { |
|
668 // The contact does not fit to (U)SIM |
|
669 ShowInformationNote( R_QTN_PHOB_NOTE_SOME_INFO_NOT_ADDED, |
|
670 EFalse ); |
|
671 |
|
672 // Request contact relocation |
|
673 aFailParams.iErrorCode = KErrGeneral; |
|
674 aFailParams.iErrorNotified = ETrue; |
|
675 aFailParams.iCloseEditor = ETrue; |
|
676 break; |
|
677 } |
|
678 |
|
679 case KErrTextTooLong: |
|
680 { |
|
681 HandleTextTooLongL( aFailParams ); |
|
682 aFailParams.iErrorNotified = ETrue; |
|
683 aFailParams.iCloseEditor = EFalse; |
|
684 break; |
|
685 } |
|
686 |
|
687 case KErrNumberTooLong: |
|
688 { |
|
689 // Too long number field. |
|
690 // Set focus to a phone number field, which probably |
|
691 // (but not surely) was the problematic one. |
|
692 FocusControlOfType( EPbk2FieldCtrlTypePhoneNumberEditor ); |
|
693 ShowInformationNote( R_QTN_PBSAV_ERR_NUMBER_TOO_LONG, EFalse ); |
|
694 aFailParams.iErrorNotified = ETrue; |
|
695 aFailParams.iCloseEditor = EFalse; |
|
696 break; |
|
697 } |
|
698 |
|
699 case KErrInvalidNumber: |
|
700 { |
|
701 // There was an invalid number that could not be saved. |
|
702 // Set focus to a phone number field, which probably |
|
703 // (but not surely) was the problematic one |
|
704 FocusControlOfType( EPbk2FieldCtrlTypePhoneNumberEditor ); |
|
705 ShowInformationNote( R_QTN_ERR_SMS_INVALID_NUMB, EFalse ); |
|
706 aFailParams.iErrorNotified = ETrue; |
|
707 aFailParams.iCloseEditor = EFalse; |
|
708 break; |
|
709 } |
|
710 |
|
711 case KErrArgument: |
|
712 { |
|
713 // Input argument out of range, experienced i.e. when email |
|
714 // address too long for (U)SIM. Show general SIM card error |
|
715 // because error origin can not be quaranteed |
|
716 ShowInformationNote( R_TEXT_FDN_CARD_ERROR, EFalse ); |
|
717 |
|
718 // Request contact relocation |
|
719 aFailParams.iErrorCode = KErrGeneral; |
|
720 aFailParams.iErrorNotified = ETrue; |
|
721 aFailParams.iCloseEditor = EFalse; |
|
722 break; |
|
723 } |
|
724 |
|
725 case KErrNone: // FALLTHROUGH |
|
726 case KErrNoMemory: |
|
727 { |
|
728 // These are handled in the actual contact editor |
|
729 aFailParams.iErrorNotified = EFalse; |
|
730 aFailParams.iCloseEditor = ETrue; |
|
731 break; |
|
732 } |
|
733 |
|
734 default: |
|
735 { |
|
736 // Show general SIM card error |
|
737 ShowInformationNote( R_TEXT_FDN_CARD_ERROR, EFalse ); |
|
738 |
|
739 // Request contact relocation |
|
740 aFailParams.iErrorCode = KErrNotSupported; |
|
741 aFailParams.iErrorNotified = EFalse; |
|
742 aFailParams.iCloseEditor = ETrue; |
|
743 break; |
|
744 } |
|
745 } |
|
746 } |
|
747 |
|
748 // End of File |