|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 @deprecated 9.1 |
|
20 */ |
|
21 |
|
22 #include "DIALUTIL.H" |
|
23 |
|
24 /** |
|
25 @deprecated 9.1 |
|
26 */ |
|
27 TInt TDialNumber::String (const TDes& aPhoneNumber, TInt aPos) const |
|
28 { |
|
29 while (aPhoneNumber[aPos] == KCharSpace && aPos < aPhoneNumber.Length()-1) // already on a space then move to a non-space |
|
30 { |
|
31 aPos++; |
|
32 } |
|
33 |
|
34 if (aPos > aPhoneNumber.Length()) |
|
35 { |
|
36 return (KErrNotFound); |
|
37 } |
|
38 |
|
39 while (aPhoneNumber[aPos] != KCharSpace && aPos < aPhoneNumber.Length()-1) |
|
40 { |
|
41 aPos++; |
|
42 } |
|
43 |
|
44 if (aPos >= aPhoneNumber.Length()-1) |
|
45 { |
|
46 return (KErrNotFound); |
|
47 } |
|
48 |
|
49 return (aPos); |
|
50 } |
|
51 |
|
52 /** |
|
53 @deprecated 9.1 |
|
54 */ |
|
55 void TDialNumber::SpaceParser(const TDes& aPhoneNumber) |
|
56 { |
|
57 TInt i = aPhoneNumber.Locate(KCharPlus) ; |
|
58 TInt j = aPhoneNumber.Locate(KCharSpace) ; |
|
59 if (j!=-1) // there space(s) |
|
60 j = String ( aPhoneNumber , 0) ; |
|
61 else |
|
62 j = -1 ; |
|
63 |
|
64 if ( i==-1 || j==-1 ) |
|
65 { |
|
66 iNatCode = _L("") ; |
|
67 iAreaCode = _L(""); |
|
68 iPhoneNumber = aPhoneNumber.Right(aPhoneNumber.Length()-1 ); // from KCharPlus onward |
|
69 return ; |
|
70 } |
|
71 else if (j>i) |
|
72 { |
|
73 if ( j-2*i-2 >= KMaxNatCode ) |
|
74 { |
|
75 iNatCode = _L("") ; |
|
76 iAreaCode = _L(""); |
|
77 iPhoneNumber = aPhoneNumber.Right(aPhoneNumber.Length()-1 ); // from KCharPlus onward |
|
78 return ; |
|
79 } |
|
80 else |
|
81 iNatCode = aPhoneNumber.Mid(i+1,j-i-1); |
|
82 } |
|
83 i=j; |
|
84 j = String ( aPhoneNumber , i) ; |
|
85 |
|
86 if ( i==-1 || j==-1 ) |
|
87 iAreaCode = _L(""); |
|
88 else if (j>i) |
|
89 { |
|
90 if ( j-2*i-2 >= KMaxAreaCode ) |
|
91 { |
|
92 iNatCode = _L("") ; |
|
93 iAreaCode = _L(""); |
|
94 iPhoneNumber = aPhoneNumber.Right(aPhoneNumber.Length()-1 ); // from KCharPlus onward |
|
95 return ; |
|
96 } |
|
97 else |
|
98 { |
|
99 iAreaCode = aPhoneNumber.Mid(i+1,j-i-1); |
|
100 DialUtil::RemoveSpace (iAreaCode) ; |
|
101 } |
|
102 } |
|
103 |
|
104 if (!iNatCode.Length() && |
|
105 !iAreaCode.Length() ) |
|
106 iPhoneNumber = aPhoneNumber ; |
|
107 else if ( !iAreaCode.Length() ) // no area code supplied take the remain from NatCode onward as telephone number |
|
108 iPhoneNumber = aPhoneNumber.Mid(i+1,aPhoneNumber.Length()-i-1); |
|
109 else |
|
110 { |
|
111 iPhoneNumber = aPhoneNumber.Mid(j+1,aPhoneNumber.Length()-j-1); |
|
112 } |
|
113 DialUtil::RemoveSpace (iPhoneNumber) ; |
|
114 } |
|
115 |
|
116 /** |
|
117 @deprecated 9.1 |
|
118 */ |
|
119 void TDialNumber::BracketParser(const TDes& aPhoneNumber) |
|
120 { |
|
121 TInt i = aPhoneNumber.Locate(KCharPlus) ; |
|
122 TInt j = aPhoneNumber.Locate(KCharSpace) ; |
|
123 if ( j == KErrNotFound ) // no space found in the string |
|
124 j = aPhoneNumber.Locate(KCharOpenBracket) ; // It must has a ( |
|
125 else |
|
126 j = Min (aPhoneNumber.Locate(TChar(KCharSpace)),aPhoneNumber.Locate(TChar(KCharOpenBracket)) ) ; |
|
127 |
|
128 if ( i==-1 || j==-1 || j<=i ) |
|
129 { |
|
130 iNatCode = _L("") ; |
|
131 iAreaCode = _L(""); |
|
132 iPhoneNumber = aPhoneNumber.Right(aPhoneNumber.Length()-1 ); // from KCharPlus onward |
|
133 return ; |
|
134 } |
|
135 else |
|
136 { |
|
137 if ( j-2*i-2 >= KMaxNatCode ) |
|
138 { |
|
139 iNatCode = _L("") ; |
|
140 iAreaCode = _L(""); |
|
141 iPhoneNumber = aPhoneNumber.Right(aPhoneNumber.Length()-1 ); // from KCharPlus onward |
|
142 return ; |
|
143 } |
|
144 else |
|
145 iNatCode = aPhoneNumber.Mid(i+1,j-i-1); |
|
146 } |
|
147 |
|
148 i = aPhoneNumber.Locate(KCharOpenBracket) ; |
|
149 j = aPhoneNumber.Locate(KCharCloseBracket) ; |
|
150 |
|
151 if ( i==-1 || j==-1 || j<=i ) |
|
152 { |
|
153 iNatCode = _L("") ; |
|
154 iAreaCode = _L(""); |
|
155 iPhoneNumber = aPhoneNumber.Right(aPhoneNumber.Length()-1 ); // from KCharPlus onward |
|
156 return ; |
|
157 } |
|
158 else |
|
159 { |
|
160 if ( j-2*i-2 >= KMaxAreaCode ) |
|
161 { |
|
162 iNatCode = _L("") ; |
|
163 iAreaCode = _L(""); |
|
164 iPhoneNumber = aPhoneNumber.Right(aPhoneNumber.Length()-1 ); // from KCharPlus onward |
|
165 return ; |
|
166 } |
|
167 else |
|
168 iAreaCode = aPhoneNumber.Mid(i+1,j-i-1); |
|
169 } |
|
170 if (!iNatCode.Length() && |
|
171 !iAreaCode.Length() ) |
|
172 iPhoneNumber = aPhoneNumber ; |
|
173 else |
|
174 iPhoneNumber = aPhoneNumber.Mid(j+1,aPhoneNumber.Length()-j-1); |
|
175 |
|
176 } |
|
177 |
|
178 /** |
|
179 @deprecated 9.1 |
|
180 */ |
|
181 TDialNumber::TDialNumber (const TDes& aPhoneNumber, |
|
182 const TDialLocation& aDialLocation , |
|
183 const TChargeCard & aChargeCard ) |
|
184 { |
|
185 |
|
186 if (aPhoneNumber.Locate(KCharPlus) == KErrNotFound) |
|
187 { |
|
188 } |
|
189 else |
|
190 { |
|
191 TInt iOpen =aPhoneNumber.Locate(KCharOpenBracket); |
|
192 TInt iClose=aPhoneNumber.Locate(KCharCloseBracket); |
|
193 |
|
194 |
|
195 if ( iOpen==KErrNotFound || |
|
196 iClose==KErrNotFound ) |
|
197 { |
|
198 SpaceParser (aPhoneNumber) ; |
|
199 } |
|
200 else // found both brackets |
|
201 { |
|
202 if (iOpen>iClose || iClose-iOpen==1 ) // close bracket before open bracket or nothing in the brackets |
|
203 SpaceParser (aPhoneNumber) ; |
|
204 else |
|
205 { |
|
206 iClose=aPhoneNumber.Locate(KCharSpace); |
|
207 |
|
208 if ( iClose==KErrNotFound) // no spaces found in string |
|
209 BracketParser(aPhoneNumber); |
|
210 else |
|
211 { |
|
212 if ( iClose>iOpen) // first space found after open bracket so bracket parser |
|
213 BracketParser (aPhoneNumber) ; |
|
214 else // spaces found before the ( |
|
215 { |
|
216 while ( iClose < aPhoneNumber.Length()-1 && |
|
217 aPhoneNumber[iClose]==KCharSpace) |
|
218 iClose++; // move on until a non-space char found |
|
219 |
|
220 if (aPhoneNumber[iClose]==KCharOpenBracket) // is a bracket ? |
|
221 BracketParser(aPhoneNumber); // the bracket parser |
|
222 else |
|
223 SpaceParser (aPhoneNumber) ; |
|
224 } |
|
225 } |
|
226 |
|
227 } |
|
228 } |
|
229 } |
|
230 iIntlPrefCode = aDialLocation.IntlPrefCode () ; |
|
231 iNatPrefCode = aDialLocation.NatPrefCode () ; |
|
232 |
|
233 if (!iNatCode.Length()) // if national code is not supplied |
|
234 { |
|
235 iNatCode = aDialLocation.NatCode () ; // set it to the current location |
|
236 if (!iAreaCode.Length()) |
|
237 iAreaCode = aDialLocation.AreaCode () ; |
|
238 } |
|
239 // else // supplied in the string |
|
240 // ; // leave the area code alone and assume user has to supplied this |
|
241 |
|
242 CallType(aDialLocation) ; |
|
243 if (aChargeCard.ValidateChargeCardInfo()) |
|
244 RuleToUse(aChargeCard) ; |
|
245 |
|
246 } |
|
247 |
|
248 /** |
|
249 @deprecated 9.1 |
|
250 */ |
|
251 TPtrC TDialNumber::IntlPrefCode () const |
|
252 { |
|
253 return TPtrC(iIntlPrefCode); |
|
254 } |
|
255 |
|
256 /** |
|
257 @deprecated 9.1 |
|
258 */ |
|
259 TPtrC TDialNumber::NatPrefCode ()const |
|
260 { |
|
261 return TPtrC(iNatPrefCode); |
|
262 } |
|
263 |
|
264 /** |
|
265 @deprecated 9.1 |
|
266 */ |
|
267 TPtrC TDialNumber::NatCode()const |
|
268 { |
|
269 return TPtrC(iNatCode); |
|
270 } |
|
271 |
|
272 /** |
|
273 @deprecated 9.1 |
|
274 */ |
|
275 TPtrC TDialNumber::AreaCode()const |
|
276 { |
|
277 return TPtrC(iAreaCode); |
|
278 } |
|
279 |
|
280 /** |
|
281 @deprecated 9.1 |
|
282 */ |
|
283 TPtrC TDialNumber::PhoneNumber()const |
|
284 { |
|
285 return TPtrC(iPhoneNumber); |
|
286 } |
|
287 |
|
288 /** |
|
289 @deprecated 9.1 |
|
290 */ |
|
291 TPtrC TDialNumber::RuleToUse()const |
|
292 { |
|
293 return TPtrC(iRuleToUse); |
|
294 } |
|
295 |
|
296 /** |
|
297 @deprecated 9.1 |
|
298 */ |
|
299 TCallType TDialNumber::CallType()const |
|
300 { |
|
301 return iCallType; |
|
302 } |
|
303 |
|
304 /** |
|
305 @deprecated 9.1 |
|
306 */ |
|
307 void TDialNumber::RuleToUse ( const TChargeCard & aChargeCard) |
|
308 { |
|
309 switch (iCallType) |
|
310 { |
|
311 case ELocalCall: |
|
312 iRuleToUse = aChargeCard.LocalRule() ; |
|
313 break; |
|
314 case ELongDistanceCall: |
|
315 iRuleToUse = aChargeCard.NatRule(); |
|
316 break; |
|
317 case EInternationalCall: |
|
318 iRuleToUse = aChargeCard.IntlRule() ; |
|
319 break; |
|
320 } |
|
321 } |
|
322 |
|
323 /** |
|
324 @deprecated 9.1 |
|
325 */ |
|
326 void TDialNumber::CallType ( const TDialLocation & aDialLocation ) |
|
327 { |
|
328 iCallType = ELocalCall ; |
|
329 if ( aDialLocation.AreaCode() != iAreaCode) |
|
330 { |
|
331 iCallType = ELongDistanceCall ; |
|
332 } |
|
333 if ( aDialLocation.NatCode() != iNatCode) |
|
334 { |
|
335 iCallType = EInternationalCall ; |
|
336 } |
|
337 |
|
338 } |
|
339 |
|
340 /** |
|
341 @deprecated 9.1 |
|
342 */ |
|
343 TBool TDialNumber::IsNatCode() const { return iNatCode.Length(); } |
|
344 /** |
|
345 @deprecated 9.1 |
|
346 */ |
|
347 TBool TDialNumber::IsAreaCode() const { return iAreaCode.Length();} |
|
348 /** |
|
349 @deprecated 9.1 |
|
350 */ |
|
351 TBool TDialNumber::IsRuleToUse() const{ return iRuleToUse.Length();} |
|
352 |
|
353 |
|
354 // |
|
355 // DialUtil |
|
356 // |
|
357 |
|
358 /** |
|
359 @deprecated 9.1 |
|
360 */ |
|
361 TBool DialUtil::AppendDialString(TDes& aDialStr, TPtrC aAppendStr ) |
|
362 { |
|
363 if ( (aDialStr.Length()+aAppendStr.Length()) < aDialStr.MaxLength() ) |
|
364 { |
|
365 aDialStr.Append (aAppendStr); |
|
366 return ETrue ; |
|
367 } |
|
368 else |
|
369 return EFalse ; |
|
370 } |
|
371 |
|
372 /** |
|
373 @deprecated 9.1 |
|
374 */ |
|
375 TBool DialUtil::AppendDialString(TDes& aDialStr, TChar aChar ) |
|
376 { |
|
377 if ( (aDialStr.Length()+1) < aDialStr.MaxLength() ) |
|
378 { |
|
379 aDialStr.Append (aChar); |
|
380 return ETrue ; |
|
381 } |
|
382 else |
|
383 return EFalse ; |
|
384 } |
|
385 |
|
386 |
|
387 /** |
|
388 @deprecated 9.1 |
|
389 */ |
|
390 void DialUtil::RemoveSpace (TDes& aDialString) |
|
391 { |
|
392 TInt pos = aDialString.Locate(KCharSpace); |
|
393 |
|
394 while ( pos != -1 ) |
|
395 { |
|
396 aDialString.Replace (pos,1,_L("")) ; |
|
397 pos = aDialString.Locate(KCharSpace); |
|
398 } |
|
399 } |
|
400 |
|
401 #if 0 |
|
402 TBool DialUtil::PhoneFormatOK( TDes& aPhoneNumber) |
|
403 { |
|
404 return !( |
|
405 (aPhoneNumber.Locate(KCharOpenBracket)!=KErrNotFound && aPhoneNumber.Locate(KCharCloseBracket)==KErrNotFound) |
|
406 || (aPhoneNumber.Locate(KCharOpenBracket)==KErrNotFound && aPhoneNumber.Locate(KCharCloseBracket)!=KErrNotFound) |
|
407 ) ; |
|
408 } |
|
409 #endif |
|
410 |
|
411 /** |
|
412 @deprecated 9.1 |
|
413 */ |
|
414 void DialUtil::RemoveUndiallableChars (TDes& aDialString) |
|
415 { |
|
416 TInt pos = 0; |
|
417 while ( pos < aDialString.Length() ) |
|
418 { |
|
419 if ( aDialString[pos] == KCharStar || |
|
420 aDialString[pos] == KCharHash || |
|
421 aDialString[pos] == KCharComma || |
|
422 ( aDialString[pos] >= '0' && aDialString[pos] <='9') ) |
|
423 |
|
424 ; |
|
425 else |
|
426 { |
|
427 aDialString.Replace (pos,1,_L("")) ; |
|
428 pos--; |
|
429 } |
|
430 pos++ ; |
|
431 } |
|
432 |
|
433 } |