|
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 contact editor phone number field. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2ContactEditorPhoneNumberField.h" |
|
20 #include "Pbk2PresentationUtils.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include <MPbk2ContactEditorUiBuilder.h> |
|
24 #include <MPbk2ContactEditorFieldVisitor.h> |
|
25 #include <MPbk2FieldProperty.h> |
|
26 #include <CPbk2PresentationContactField.h> |
|
27 #include <MPbk2ContactEditorExtension.h> |
|
28 #include <Phonebook2InternalCRKeys.h> |
|
29 |
|
30 // Virtual Phonebook |
|
31 #include <MVPbkContactFieldTextData.h> |
|
32 |
|
33 // System includes |
|
34 #include <eikcapc.h> |
|
35 #include <eikedwin.h> |
|
36 #include <AknUtils.h> |
|
37 #include <centralrepository.h> |
|
38 |
|
39 // Debugging headers |
|
40 #include <Pbk2Debug.h> |
|
41 |
|
42 // The empty character. |
|
43 const TText KSpace = ' '; |
|
44 |
|
45 /// Unnamed namespace for local definitions |
|
46 namespace { |
|
47 |
|
48 /** |
|
49 * Returns the number editor max length. |
|
50 * |
|
51 * @return Number editor max length. |
|
52 */ |
|
53 TInt NumberEditorMaxLengthL() |
|
54 { |
|
55 CRepository* centRep = CRepository::NewLC |
|
56 ( TUid::Uid( KCRUidPhonebookInternalConfig ) ); |
|
57 TInt maxLength( KErrNotFound ); |
|
58 User::LeaveIfError( |
|
59 centRep->Get( KPhonebookNumberEditorMaxLength, maxLength ) ); |
|
60 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
61 ("NumberEditorMaxLengthL maxLength(%d)"), maxLength ); |
|
62 CleanupStack::PopAndDestroy( centRep ); |
|
63 return maxLength; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Returns maximum field length. |
|
68 * |
|
69 * @param aContactField Contact field in question. |
|
70 * @return Maximum field length. |
|
71 */ |
|
72 TInt MaxFieldLengthL( CPbk2PresentationContactField& aContactField ) |
|
73 { |
|
74 // Determine the length of contact field in stores and central |
|
75 // repository. The smaller will be chosen. |
|
76 TInt maxLength = KVPbkUnlimitedFieldLength; |
|
77 // Read max length from store |
|
78 TVPbkFieldStorageType dataType = |
|
79 aContactField.StoreField().FieldData().DataType(); |
|
80 const MVPbkContactFieldTextData& textData = |
|
81 MVPbkContactFieldTextData::Cast |
|
82 ( aContactField.StoreField().FieldData() ); |
|
83 maxLength = textData.MaxLength(); |
|
84 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
85 ("MaxFieldLengthL maxLength(%d)"), maxLength ); |
|
86 |
|
87 // Read max length from central repository |
|
88 TInt staticMaxLength = NumberEditorMaxLengthL(); |
|
89 if (maxLength == KVPbkUnlimitedFieldLength) |
|
90 { |
|
91 maxLength = staticMaxLength; |
|
92 } |
|
93 else |
|
94 { |
|
95 maxLength = Min(staticMaxLength, maxLength); |
|
96 } |
|
97 return maxLength; |
|
98 } |
|
99 |
|
100 } /// namespace |
|
101 |
|
102 // -------------------------------------------------------------------------- |
|
103 // CPbk2ContactEditorPhoneNumberField::CPbk2ContactEditorPhoneNumberField |
|
104 // -------------------------------------------------------------------------- |
|
105 // |
|
106 inline CPbk2ContactEditorPhoneNumberField::CPbk2ContactEditorPhoneNumberField |
|
107 ( CPbk2PresentationContactField& aContactField, |
|
108 MPbk2ContactEditorUiBuilder& aUiBuilder, |
|
109 CPbk2IconInfoContainer& aIconInfoContainer ) : |
|
110 CPbk2ContactEditorFieldBase( aContactField, aUiBuilder, |
|
111 aIconInfoContainer ) |
|
112 { |
|
113 } |
|
114 |
|
115 // -------------------------------------------------------------------------- |
|
116 // CPbk2ContactEditorPhoneNumberField::~CPbk2ContactEditorPhoneNumberField |
|
117 // -------------------------------------------------------------------------- |
|
118 // |
|
119 CPbk2ContactEditorPhoneNumberField::~CPbk2ContactEditorPhoneNumberField() |
|
120 { |
|
121 } |
|
122 |
|
123 // -------------------------------------------------------------------------- |
|
124 // CPbk2ContactEditorPhoneNumberField::NewLC |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 CPbk2ContactEditorPhoneNumberField* CPbk2ContactEditorPhoneNumberField::NewLC |
|
128 ( CPbk2PresentationContactField& aContactField, |
|
129 MPbk2ContactEditorUiBuilder& aUiBuilder, |
|
130 CPbk2IconInfoContainer& aIconInfoContainer ) |
|
131 { |
|
132 CPbk2ContactEditorPhoneNumberField* self = |
|
133 new ( ELeave ) CPbk2ContactEditorPhoneNumberField( aContactField, |
|
134 aUiBuilder, aIconInfoContainer ); |
|
135 CleanupStack::PushL( self ); |
|
136 self->ConstructL(); |
|
137 return self; |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // CPbk2ContactEditorPhoneNumberField::ConstructL |
|
142 // -------------------------------------------------------------------------- |
|
143 // |
|
144 inline void CPbk2ContactEditorPhoneNumberField::ConstructL() |
|
145 { |
|
146 // Create and insert a line in the dialog |
|
147 iControl = static_cast<CEikEdwin*>(iUiBuilder.CreateLineL( |
|
148 FieldLabel(), ControlId(), EEikCtEdwin)); |
|
149 |
|
150 // Control is now owned by the dialog |
|
151 TInt maxFieldLength = MaxFieldLengthL( iContactField ); |
|
152 AknEditUtils::ConstructEditingL(iControl, maxFieldLength, |
|
153 maxFieldLength, EAknEditorTextCase | EAknEditorCharactersUpperCase |
|
154 | EAknEditorCharactersLowerCase, EAknEditorAlignLeft, |
|
155 ETrue, ETrue, EFalse); |
|
156 |
|
157 // Get text |
|
158 TPtrC dataPtr(MVPbkContactFieldTextData::Cast( |
|
159 iContactField.FieldData()).Text()); |
|
160 HBufC* textBuf = HBufC::NewLC(dataPtr.Length()); |
|
161 TPtr text = textBuf->Des(); |
|
162 text = dataPtr.Left(maxFieldLength); |
|
163 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(text); |
|
164 |
|
165 // Set input capabilities and character modes |
|
166 if (iContactField.FieldProperty().EditMode() == EPbk2FieldEditModeNumeric) |
|
167 { |
|
168 iControl->SetAknEditorNumericKeymap(EAknEditorStandardNumberModeKeymap); |
|
169 iControl->SetAknEditorInputMode(EAknEditorNumericInputMode); |
|
170 iControl->SetAknEditorAllowedInputModes(EAknEditorNumericInputMode); |
|
171 iControl->SetAknEditorSpecialCharacterTable(0); |
|
172 } |
|
173 |
|
174 // Set formatted text to editor control |
|
175 iControl->SetTextL(&text); |
|
176 // SetTextL method above copied the text to the control, |
|
177 // so it is safe to destroy the buffer |
|
178 CleanupStack::PopAndDestroy(textBuf); |
|
179 |
|
180 iUiBuilder.LoadBitmapToFieldL |
|
181 ( iContactField.FieldProperty(), iIconInfoContainer, ControlId() ); |
|
182 |
|
183 |
|
184 // Place cursor to the end of the line |
|
185 iControl->AddFlagToUserFlags(CEikEdwin::EJustAutoCurEnd); |
|
186 |
|
187 iControl->CreateTextViewL(); |
|
188 iCaptionedCtrl = iUiBuilder.LineControl(ControlId()); |
|
189 iCaptionedCtrl->SetTakesEnterKey(ETrue); |
|
190 } |
|
191 |
|
192 // -------------------------------------------------------------------------- |
|
193 // CPbk2ContactEditorPhoneNumberField::Control |
|
194 // -------------------------------------------------------------------------- |
|
195 // |
|
196 CEikEdwin* CPbk2ContactEditorPhoneNumberField::Control() const |
|
197 { |
|
198 return iControl; |
|
199 } |
|
200 |
|
201 // -------------------------------------------------------------------------- |
|
202 // CPbk2ContactEditorPhoneNumberField::SaveFieldL |
|
203 // -------------------------------------------------------------------------- |
|
204 // |
|
205 void CPbk2ContactEditorPhoneNumberField::SaveFieldL() |
|
206 { |
|
207 iContactDataHasChanged = EFalse; |
|
208 |
|
209 MVPbkContactFieldTextData& data = |
|
210 MVPbkContactFieldTextData::Cast(iContactField.FieldData()); |
|
211 TPtrC curText(data.Text()); |
|
212 |
|
213 HBufC* text = iControl->GetTextInHBufL(); |
|
214 if (text) |
|
215 { |
|
216 TPtr number = text->Des(); |
|
217 Pbk2PresentationUtils::ReplaceNonGraphicCharacters( number, KSpace ); |
|
218 AknTextUtils::ConvertDigitsTo(number, EDigitTypeWestern); |
|
219 |
|
220 TInt maxFieldLength = MaxFieldLengthL( iContactField ); |
|
221 TInt dataLength = curText.Length(); |
|
222 |
|
223 if ( curText.Compare(*text) || ( dataLength == maxFieldLength ) ) |
|
224 { |
|
225 CleanupStack::PushL(text); |
|
226 data.SetTextL(*text); |
|
227 CleanupStack::PopAndDestroy(text); |
|
228 iContactDataHasChanged = ETrue; |
|
229 } |
|
230 else |
|
231 { |
|
232 delete text; |
|
233 } |
|
234 } |
|
235 else if (curText.Length() > 0) |
|
236 { |
|
237 data.SetTextL(KNullDesC); |
|
238 iContactDataHasChanged = ETrue; |
|
239 } |
|
240 } |
|
241 |
|
242 // -------------------------------------------------------------------------- |
|
243 // CPbk2ContactEditorPhoneNumberField::ActivateL |
|
244 // -------------------------------------------------------------------------- |
|
245 // |
|
246 void CPbk2ContactEditorPhoneNumberField::ActivateL() |
|
247 { |
|
248 iCaptionedCtrl->ActivateL(); |
|
249 } |
|
250 |
|
251 // -------------------------------------------------------------------------- |
|
252 // CPbk2ContactEditorPhoneNumberField::AcceptL |
|
253 // -------------------------------------------------------------------------- |
|
254 // |
|
255 void CPbk2ContactEditorPhoneNumberField::AcceptL |
|
256 (MPbk2ContactEditorFieldVisitor& aVisitor) |
|
257 { |
|
258 aVisitor.VisitL(*this); |
|
259 } |
|
260 |
|
261 // End of File |