|
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: The sim contact field. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CVPbkSimCntField.h" |
|
22 |
|
23 #include "MVPbkSimCntStore.h" |
|
24 #include "MVPbkSimContact.h" |
|
25 #include "VPbkSimStoreTemplateFunctions.h" |
|
26 #include "TVPbkSimStoreProperty.h" |
|
27 |
|
28 // ============================ LOCAL FUNCTIONS ================================ |
|
29 |
|
30 namespace { |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // a plus character the can be used as a prefix number |
|
35 _LIT( KPlusPrefix, "+" ); |
|
36 |
|
37 // If there is no extension file or it's full then the number |
|
38 // length is max 20. This comes from 3GPP USIM specification. |
|
39 // (See spec for e.g EF ADN, 10 bytes for number) |
|
40 const TInt KMaxNumLengthNotUsingExt = 20; |
|
41 // If the number uses one record in the extension the max length is 40 |
|
42 // This comes from 3GPP USIM specification. See e.g EF EXT1, one record |
|
43 // can take 10 bytes number -> if number is splitted to EF ADN + one record |
|
44 // in EF EXT1 then max length is 40 |
|
45 const TInt KMaxNumLengthOneRecordFromExt = 40; |
|
46 |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // MaxLength |
|
50 // |
|
51 // Returns the maximum length of the new field that has the given type |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 TInt16 MaxLength( TVPbkSimCntFieldType aType, const MVPbkSimCntStore& aStore ) |
|
55 { |
|
56 TInt result = 0; |
|
57 if ( aType == EVPbkSimName || |
|
58 aType == EVPbkSimGsmNumber ) |
|
59 { |
|
60 TVPbkGsmStoreProperty prop; |
|
61 TInt err = aStore.GetGsmStoreProperties( prop ); |
|
62 if( err != KErrNone ) |
|
63 { |
|
64 result = 0; |
|
65 } |
|
66 else if( aType == EVPbkSimName ) |
|
67 { |
|
68 result = prop.iMaxTextLength; |
|
69 } |
|
70 else |
|
71 { |
|
72 result = prop.iMaxNumLength; |
|
73 } |
|
74 } |
|
75 else |
|
76 { |
|
77 TVPbkUSimStoreProperty uprop; |
|
78 TInt err = aStore.GetUSimStoreProperties( uprop ); |
|
79 if( err == KErrNone ) |
|
80 { |
|
81 switch ( aType ) |
|
82 { |
|
83 case EVPbkSimAdditionalNumber: |
|
84 { |
|
85 result = uprop.iMaxAnrLength; |
|
86 break; |
|
87 } |
|
88 case EVPbkSimReading: |
|
89 case EVPbkSimNickName: |
|
90 { |
|
91 result = uprop.iMaxScndNameLength; |
|
92 break; |
|
93 } |
|
94 case EVPbkSimEMailAddress: |
|
95 { |
|
96 result = uprop.iMaxEmailLength; |
|
97 break; |
|
98 } |
|
99 case EVPbkSimGroupName: |
|
100 { |
|
101 result = uprop.iMaxGroupNameLength; |
|
102 break; |
|
103 } |
|
104 default: |
|
105 { |
|
106 break; |
|
107 } |
|
108 } |
|
109 } |
|
110 } |
|
111 return (TInt16)result; |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CalculateNumberMaxLength |
|
116 // |
|
117 // Calculates the maximum number length for existing SIM contact. |
|
118 // |
|
119 // The logic is based on the file structure in SIM card. |
|
120 // E.g a record in EF ADN can hold a phonenumber of length 20. If the saved |
|
121 // number is longer than 20 the rest of the number is saved to EF EXT1. |
|
122 // The size of EF EXT1 is limited and it doesn't have a space for each |
|
123 // record in EF ADN. |
|
124 // |
|
125 // When getting maximum length from ETel it gives the max length that could |
|
126 // be used for a new contact. But it's not the same as the max length that |
|
127 // can be used for existing contact. |
|
128 // |
|
129 // This function checks how full the EXT1 file is using the contacts current |
|
130 // number length and the max length from ETel. |
|
131 // |
|
132 // @param aInitialData the data that is saved in the SIM card |
|
133 // @param aCurETelMaxLengthWithPlusPrefix a max number length from ETel with |
|
134 // '+' prefix. |
|
135 // @param aSystemMaxLength the system maximum length defined in VPbk. |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 TInt16 CalculateNumberMaxLength( const TDesC& aInitialData, TInt |
|
139 aCurETelMaxLengthWithPlusPrefix, |
|
140 TInt aSystemMaxLength ) |
|
141 { |
|
142 TInt curLength = aInitialData.Length(); |
|
143 if ( aInitialData.Find( KPlusPrefix ) != KErrNotFound ) |
|
144 { |
|
145 // Number contains '+' -prefix. Take that away to get |
|
146 // the actual number length |
|
147 --curLength; |
|
148 } |
|
149 |
|
150 // Lets do the checkings without plus prefix |
|
151 TInt curETelMaxLength = aCurETelMaxLengthWithPlusPrefix - 1; |
|
152 |
|
153 TInt result = curETelMaxLength; |
|
154 if ( curETelMaxLength > KMaxNumLengthOneRecordFromExt ) |
|
155 { |
|
156 // There is a at least 2 free records in the extension |
|
157 result = aSystemMaxLength; |
|
158 } |
|
159 else if ( curETelMaxLength > KMaxNumLengthNotUsingExt ) |
|
160 { |
|
161 // There is 1 free record in extension |
|
162 // Number length can be at least KMaxNumLengthOneRecordFromExt |
|
163 result = KMaxNumLengthOneRecordFromExt; |
|
164 if ( curLength > KMaxNumLengthOneRecordFromExt ) |
|
165 { |
|
166 // Number already reserves 2 recors from extension |
|
167 result = aSystemMaxLength; |
|
168 } |
|
169 } |
|
170 else |
|
171 { |
|
172 // Extension is full. Number can use the records it already |
|
173 // reserves. |
|
174 if ( curLength > KMaxNumLengthOneRecordFromExt ) |
|
175 { |
|
176 // Number already uses 2 extension records |
|
177 result = aSystemMaxLength; |
|
178 } |
|
179 else if ( curLength > KMaxNumLengthNotUsingExt ) |
|
180 { |
|
181 // Number already uses 1 extension record |
|
182 result = KMaxNumLengthOneRecordFromExt; |
|
183 } |
|
184 else |
|
185 { |
|
186 // Number is not using extension records. |
|
187 result = curETelMaxLength; |
|
188 } |
|
189 } |
|
190 |
|
191 // Finally add the length of '+' prefex and return. |
|
192 return ++result; |
|
193 } |
|
194 } |
|
195 |
|
196 // ============================ MEMBER FUNCTIONS =============================== |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CVPbkSimCntField::CVPbkSimCntField |
|
200 // C++ default constructor can NOT contain any code, that |
|
201 // might leave. |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 CVPbkSimCntField::CVPbkSimCntField( TVPbkSimCntFieldType aType, |
|
205 const MVPbkSimContact& aParentContact ) |
|
206 : iType( aType ), |
|
207 iParentContact( aParentContact ), |
|
208 iMaxLength( KErrNotFound ) |
|
209 { |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CVPbkSimCntField::ConstructL |
|
214 // Symbian 2nd phase constructor can leave. |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CVPbkSimCntField::ConstructL() |
|
218 { |
|
219 iDataPtr.Set( KNullDesC ); |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CVPbkSimCntField::NewL |
|
224 // Two-phased constructor. |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 CVPbkSimCntField* CVPbkSimCntField::NewL( TVPbkSimCntFieldType aType, |
|
228 const MVPbkSimContact& aParentContact ) |
|
229 { |
|
230 CVPbkSimCntField* self = NewLC( aType, aParentContact ); |
|
231 CleanupStack::Pop(); |
|
232 return self; |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CVPbkSimCntField::NewLC |
|
237 // Two-phased constructor. |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 CVPbkSimCntField* CVPbkSimCntField::NewLC( TVPbkSimCntFieldType aType, |
|
241 const MVPbkSimContact& aParentContact ) |
|
242 { |
|
243 CVPbkSimCntField* self = |
|
244 new( ELeave ) CVPbkSimCntField( aType, aParentContact ); |
|
245 CleanupStack::PushL( self ); |
|
246 self->ConstructL(); |
|
247 return self; |
|
248 } |
|
249 |
|
250 // Destructor |
|
251 CVPbkSimCntField::~CVPbkSimCntField() |
|
252 { |
|
253 delete iData; |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CVPbkSimCntField::SetDataL |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C void CVPbkSimCntField::SetDataL( const TDesC& aData ) |
|
261 { |
|
262 TPtr dataPtr( NULL, 0 ); |
|
263 VPbkSimStoreImpl::CheckAndUpdateBufferSizeL( iData, dataPtr, |
|
264 aData.Length() ); |
|
265 dataPtr.Copy( aData ); |
|
266 iDataPtr.Set( *iData ); |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CVPbkSimCntField::SetDataPtr |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 EXPORT_C TInt CVPbkSimCntField::MaxDataLength() |
|
274 { |
|
275 if ( iMaxLength == KErrNotFound ) |
|
276 { |
|
277 iMaxLength = MaxLength( iType, iParentContact.ParentStore() ); |
|
278 } |
|
279 return iMaxLength; |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CVPbkSimCntField::SetInitialSimDataL |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 void CVPbkSimCntField::SetInitialSimDataL( const TDesC& aData ) |
|
287 { |
|
288 SetDataL( aData ); |
|
289 |
|
290 // Max length must be calculated for number types only because other |
|
291 // types are not splitted in several records in SIM card. |
|
292 if ( iType == EVPbkSimGsmNumber || iType == EVPbkSimAdditionalNumber ) |
|
293 { |
|
294 TInt currentMaxLength = MaxLength( iType, |
|
295 iParentContact.ParentStore() ); |
|
296 iMaxLength = CalculateNumberMaxLength( aData, currentMaxLength, |
|
297 iParentContact.ParentStore().SystemPhoneNumberMaxLength() ); |
|
298 } |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CVPbkSimCntField::SetDataPtr |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 void CVPbkSimCntField::SetDataPtr( TPtrC aDataPtr ) |
|
306 { |
|
307 iDataPtr.Set( aDataPtr ); |
|
308 } |
|
309 |
|
310 // ----------------------------------------------------------------------------- |
|
311 // CVPbkSimCntField::SetType |
|
312 // ----------------------------------------------------------------------------- |
|
313 // |
|
314 void CVPbkSimCntField::SetType( TVPbkSimCntFieldType aType ) |
|
315 { |
|
316 iType = aType; |
|
317 } |
|
318 // End of File |