|
1 /* |
|
2 * Copyright (c) 2002-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 FDN contact editor phone number field. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPsu2FdnContactEditorPhoneNumberField.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include <MPbk2ContactEditorUiBuilder.h> |
|
23 #include <MPbk2ContactEditorFieldVisitor.h> |
|
24 #include <MPbk2FieldProperty.h> |
|
25 #include <CPbk2PresentationContactField.h> |
|
26 #include <MPbk2ContactEditorExtension.h> |
|
27 #include <Phonebook2InternalCRKeys.h> |
|
28 |
|
29 // Virtual Phonebook |
|
30 #include <MVPbkContactFieldTextData.h> |
|
31 |
|
32 // System includes |
|
33 #include <eikcapc.h> |
|
34 #include <eikedwin.h> |
|
35 #include <AknUtils.h> |
|
36 #include <centralrepository.h> |
|
37 |
|
38 // Debugging headers |
|
39 #include <Pbk2Debug.h> |
|
40 |
|
41 |
|
42 /// Unnamed namespace for local definitions |
|
43 namespace { |
|
44 |
|
45 /** |
|
46 * Returns the number editor max length. |
|
47 * |
|
48 * @return Number editor max length. |
|
49 */ |
|
50 TInt NumberEditorMaxLengthL() |
|
51 { |
|
52 CRepository* centRep = CRepository::NewLC |
|
53 ( TUid::Uid( KCRUidPhonebookInternalConfig ) ); |
|
54 TInt maxLength( KErrNotFound ); |
|
55 User::LeaveIfError( |
|
56 centRep->Get( KPhonebookNumberEditorMaxLength, maxLength ) ); |
|
57 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
58 ("FDN NumberEditorMaxLengthL maxLength(%d)"), maxLength ); |
|
59 CleanupStack::PopAndDestroy( centRep ); |
|
60 return maxLength; |
|
61 } |
|
62 |
|
63 /** |
|
64 * Returns maximum field length. |
|
65 * |
|
66 * @param aContactField Contact field in question. |
|
67 * @return Maximum field length. |
|
68 */ |
|
69 TInt MaxFieldLengthL( MVPbkStoreContactField& aContactField ) |
|
70 { |
|
71 // Determine the length of contact field in stores and central |
|
72 // repository. The smaller will be chosen. |
|
73 TInt maxLength = KVPbkUnlimitedFieldLength; |
|
74 // Read max length from store |
|
75 TVPbkFieldStorageType dataType = |
|
76 aContactField.FieldData().DataType(); |
|
77 const MVPbkContactFieldTextData& textData = |
|
78 MVPbkContactFieldTextData::Cast |
|
79 ( aContactField.FieldData() ); |
|
80 maxLength = textData.MaxLength(); |
|
81 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
82 ("FDN MaxFieldLengthL maxLength(%d)"), maxLength ); |
|
83 |
|
84 // Read max length from central repository |
|
85 TInt staticMaxLength = NumberEditorMaxLengthL(); |
|
86 if ( maxLength == KVPbkUnlimitedFieldLength ) |
|
87 { |
|
88 maxLength = staticMaxLength; |
|
89 } |
|
90 else |
|
91 { |
|
92 maxLength = Min( staticMaxLength, maxLength ); |
|
93 } |
|
94 return maxLength; |
|
95 } |
|
96 |
|
97 } /// namespace |
|
98 |
|
99 // -------------------------------------------------------------------------- |
|
100 // CPsu2FdnContactEditorPhoneNumberField::CPsu2FdnContactEditorPhoneNumberFi |
|
101 // -------------------------------------------------------------------------- |
|
102 // |
|
103 inline CPsu2FdnContactEditorPhoneNumberField:: |
|
104 CPsu2FdnContactEditorPhoneNumberField |
|
105 ( MVPbkStoreContactField& aContactField, |
|
106 const MPbk2FieldProperty& aFieldProperty, |
|
107 MPbk2ContactEditorUiBuilder& aUiBuilder, |
|
108 const CPbk2IconInfoContainer& aIconInfoContainer ) : |
|
109 iContactField( aContactField ), |
|
110 iFieldProperty( aFieldProperty ), |
|
111 iUiBuilder( aUiBuilder ), |
|
112 iIconInfoContainer( aIconInfoContainer ), |
|
113 iContactDataHasChanged( EFalse ) |
|
114 { |
|
115 } |
|
116 |
|
117 // -------------------------------------------------------------------------- |
|
118 // CPsu2FdnContactEditorPhoneNumberField::~CPsu2FdnContactEditorPhoneNumberF |
|
119 // -------------------------------------------------------------------------- |
|
120 // |
|
121 CPsu2FdnContactEditorPhoneNumberField:: |
|
122 ~CPsu2FdnContactEditorPhoneNumberField() |
|
123 { |
|
124 } |
|
125 |
|
126 // -------------------------------------------------------------------------- |
|
127 // CPsu2FdnContactEditorPhoneNumberField::NewL |
|
128 // -------------------------------------------------------------------------- |
|
129 // |
|
130 CPsu2FdnContactEditorPhoneNumberField* |
|
131 CPsu2FdnContactEditorPhoneNumberField::NewL |
|
132 ( MVPbkStoreContactField& aContactField, |
|
133 const MPbk2FieldProperty& aFieldProperty, |
|
134 MPbk2ContactEditorUiBuilder& aUiBuilder, |
|
135 CPbk2IconInfoContainer& aIconInfoContainer ) |
|
136 { |
|
137 CPsu2FdnContactEditorPhoneNumberField* self = |
|
138 new ( ELeave ) CPsu2FdnContactEditorPhoneNumberField |
|
139 ( aContactField, aFieldProperty, aUiBuilder, |
|
140 aIconInfoContainer ); |
|
141 CleanupStack::PushL( self ); |
|
142 self->ConstructL(); |
|
143 CleanupStack::Pop( self ); |
|
144 return self; |
|
145 } |
|
146 |
|
147 // -------------------------------------------------------------------------- |
|
148 // CPsu2FdnContactEditorPhoneNumberField::ConstructL |
|
149 // -------------------------------------------------------------------------- |
|
150 // |
|
151 inline void CPsu2FdnContactEditorPhoneNumberField::ConstructL() |
|
152 { |
|
153 const TInt KPlusSignLength = 1; |
|
154 |
|
155 // Create and insert a line in the dialog |
|
156 iControl = static_cast<CEikEdwin*> |
|
157 ( iUiBuilder.CreateLineL( FieldLabel(), ControlId(), EEikCtEdwin ) ); |
|
158 |
|
159 // Get max field length from store contact and central repository |
|
160 TInt maxFieldLength = MaxFieldLengthL( iContactField ); |
|
161 |
|
162 // Get max presentation field length |
|
163 TInt maxUiFieldLength = iFieldProperty.MaxLength(); |
|
164 |
|
165 // Get the minimum of all of these |
|
166 maxFieldLength = Min( maxFieldLength, maxUiFieldLength ); |
|
167 |
|
168 // Control is now owned by the dialog |
|
169 // Increase maxFieldLength by one (space for '+' sign) |
|
170 AknEditUtils::ConstructEditingL( iControl, |
|
171 maxFieldLength + KPlusSignLength, maxUiFieldLength + KPlusSignLength, |
|
172 EAknEditorTextCase | EAknEditorCharactersUpperCase |
|
173 | EAknEditorCharactersLowerCase, EAknEditorAlignLeft, |
|
174 ETrue, ETrue, EFalse ); |
|
175 |
|
176 // Get text |
|
177 TPtrC dataPtr( MVPbkContactFieldTextData::Cast |
|
178 ( iContactField.FieldData() ).Text() ) ; |
|
179 HBufC* textBuf = HBufC::NewLC( dataPtr.Length() ); |
|
180 TPtr text = textBuf->Des(); |
|
181 // Increase maxFieldLength by one (space for '+' sign) |
|
182 text = dataPtr.Left( maxFieldLength + KPlusSignLength ); |
|
183 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( text ); |
|
184 |
|
185 // Set input capabilities and character modes |
|
186 if ( iFieldProperty.EditMode() == EPbk2FieldEditModeNumeric ) |
|
187 { |
|
188 iControl->SetAknEditorNumericKeymap |
|
189 ( EAknEditorFixedDiallingNumberModeKeymap ); |
|
190 iControl->SetAknEditorInputMode( EAknEditorNumericInputMode ); |
|
191 iControl->SetAknEditorAllowedInputModes |
|
192 ( EAknEditorNumericInputMode ); |
|
193 iControl->SetAknEditorSpecialCharacterTable( 0 ); |
|
194 } |
|
195 |
|
196 // Set formatted text to editor control |
|
197 iControl->SetTextL( &text ); |
|
198 // SetTextL method above copied the text to the control, |
|
199 // so it is safe to destroy the buffer |
|
200 CleanupStack::PopAndDestroy( textBuf ); |
|
201 |
|
202 iUiBuilder.LoadBitmapToFieldL |
|
203 ( iFieldProperty, iIconInfoContainer, ControlId() ); |
|
204 |
|
205 // Place cursor to the end of the line |
|
206 iControl->AddFlagToUserFlags( CEikEdwin::EJustAutoCurEnd ); |
|
207 |
|
208 iControl->CreateTextViewL(); |
|
209 iCaptionedCtrl = iUiBuilder.LineControl( ControlId() ); |
|
210 iCaptionedCtrl->SetTakesEnterKey( ETrue ); |
|
211 |
|
212 |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CPsu2FdnContactEditorPhoneNumberField::ControlId |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 TInt CPsu2FdnContactEditorPhoneNumberField::ControlId() const |
|
220 { |
|
221 return (TInt) this; |
|
222 } |
|
223 |
|
224 // -------------------------------------------------------------------------- |
|
225 // CPsu2FdnContactEditorPhoneNumberField::Control |
|
226 // -------------------------------------------------------------------------- |
|
227 // |
|
228 CEikEdwin* CPsu2FdnContactEditorPhoneNumberField::Control() const |
|
229 { |
|
230 return iControl; |
|
231 } |
|
232 |
|
233 // -------------------------------------------------------------------------- |
|
234 // CPsu2FdnContactEditorPhoneNumberField::SaveFieldL |
|
235 // -------------------------------------------------------------------------- |
|
236 // |
|
237 void CPsu2FdnContactEditorPhoneNumberField::SaveFieldL() |
|
238 { |
|
239 iContactDataHasChanged = EFalse; |
|
240 |
|
241 MVPbkContactFieldTextData& data = |
|
242 MVPbkContactFieldTextData::Cast(iContactField.FieldData()); |
|
243 TPtrC curText(data.Text()); |
|
244 |
|
245 HBufC* text = iControl->GetTextInHBufL(); |
|
246 if (text) |
|
247 { |
|
248 TPtr number = text->Des(); |
|
249 AknTextUtils::ConvertDigitsTo(number, EDigitTypeWestern); |
|
250 if (curText.Compare(*text)) |
|
251 { |
|
252 CleanupStack::PushL(text); |
|
253 data.SetTextL(*text); |
|
254 CleanupStack::PopAndDestroy(text); |
|
255 iContactDataHasChanged = ETrue; |
|
256 } |
|
257 else |
|
258 { |
|
259 delete text; |
|
260 } |
|
261 } |
|
262 else if (curText.Length() > 0) |
|
263 { |
|
264 data.SetTextL(KNullDesC); |
|
265 iContactDataHasChanged = ETrue; |
|
266 } |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CPsu2FdnContactEditorPhoneNumberField::HandleCustomFieldCommandL |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 TBool CPsu2FdnContactEditorPhoneNumberField::HandleCustomFieldCommandL(TInt /*aCommand*/ ) |
|
274 { |
|
275 return EFalse; |
|
276 } |
|
277 |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CPsu2FdnContactEditorPhoneNumberField::ContactUiControlExtension |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 TAny* CPsu2FdnContactEditorPhoneNumberField::ContactEditorFieldExtension(TUid aExtensionUid ) |
|
284 { |
|
285 if( aExtensionUid == KMPbk2ContactEditorFieldExtension2Uid ) |
|
286 { |
|
287 return static_cast<MPbk2ContactEditorField2*>( this ); |
|
288 } |
|
289 |
|
290 return NULL; |
|
291 } |
|
292 |
|
293 |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CPsu2FdnContactEditorPhoneNumberField::FieldDataChanged |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 TBool CPsu2FdnContactEditorPhoneNumberField::FieldDataChanged() const |
|
300 { |
|
301 return iContactDataHasChanged; |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CPsu2FdnContactEditorPhoneNumberField::FieldLabel |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 TPtrC CPsu2FdnContactEditorPhoneNumberField::FieldLabel() const |
|
309 { |
|
310 return iFieldProperty.DefaultLabel(); |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CPsu2FdnContactEditorPhoneNumberField::SetFieldLabelL |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 void CPsu2FdnContactEditorPhoneNumberField::SetFieldLabelL |
|
318 ( const TDesC& /*aLabel*/ ) |
|
319 { |
|
320 // Do nothing. |
|
321 // FDN contact's label can not be changed. |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CPsu2FdnContactEditorPhoneNumberField::ControlTextL |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 HBufC* CPsu2FdnContactEditorPhoneNumberField::ControlTextL() const |
|
329 { |
|
330 HBufC* textBuf = NULL; |
|
331 CCoeControl* ctrl = iUiBuilder.Control(ControlId()); |
|
332 if (ctrl && |
|
333 iContactField.FieldData().DataType() == EVPbkFieldStorageTypeText) |
|
334 { |
|
335 textBuf = static_cast<CEikEdwin*>(ctrl)->GetTextInHBufL(); |
|
336 } |
|
337 return textBuf; |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // CPsu2FdnContactEditorPhoneNumberField::SetFocus |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 void CPsu2FdnContactEditorPhoneNumberField::SetFocus() |
|
345 { |
|
346 // It's not fatal if focusing fails |
|
347 TRAP_IGNORE(iUiBuilder.TryChangeFocusL(ControlId())); |
|
348 } |
|
349 |
|
350 // -------------------------------------------------------------------------- |
|
351 // CPsu2FdnContactEditorPhoneNumberField::ActivateL |
|
352 // -------------------------------------------------------------------------- |
|
353 // |
|
354 void CPsu2FdnContactEditorPhoneNumberField::ActivateL() |
|
355 { |
|
356 iCaptionedCtrl->ActivateL(); |
|
357 } |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // CPsu2FdnContactEditorPhoneNumberField::ContactField |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 MVPbkStoreContactField& |
|
364 CPsu2FdnContactEditorPhoneNumberField::ContactField() const |
|
365 { |
|
366 return iContactField; |
|
367 } |
|
368 |
|
369 // ----------------------------------------------------------------------------- |
|
370 // CPsu2FdnContactEditorPhoneNumberField::FieldProperty |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 const MPbk2FieldProperty& |
|
374 CPsu2FdnContactEditorPhoneNumberField::FieldProperty() const |
|
375 { |
|
376 return iFieldProperty; |
|
377 } |
|
378 |
|
379 // -------------------------------------------------------------------------- |
|
380 // CPsu2FdnContactEditorPhoneNumberField::AcceptL |
|
381 // -------------------------------------------------------------------------- |
|
382 // |
|
383 void CPsu2FdnContactEditorPhoneNumberField::AcceptL |
|
384 ( MPbk2ContactEditorFieldVisitor& aVisitor ) |
|
385 { |
|
386 aVisitor.VisitL( *this ); |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // CPsu2FdnContactEditorPhoneNumberField::ConsumesKeyEvent |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 TBool CPsu2FdnContactEditorPhoneNumberField::ConsumesKeyEvent |
|
394 ( const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/ ) |
|
395 { |
|
396 return EFalse; |
|
397 } |
|
398 |
|
399 // End of File |