|
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 number grouping phone number formatter. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2NumberGroupingFormatter.h" |
|
20 |
|
21 // System includes |
|
22 #include <NumberGrouping.h> |
|
23 #include <AknUtils.h> |
|
24 |
|
25 // Define to force number grouping on for testing purposes |
|
26 #undef PBK2_FORCE_NUMBERGROUPING_ON |
|
27 |
|
28 /// Unnamed namespace for local definitions |
|
29 namespace { |
|
30 |
|
31 const TInt KGroupingFactor = 2; |
|
32 |
|
33 } /// namespace |
|
34 |
|
35 |
|
36 // -------------------------------------------------------------------------- |
|
37 // CPbk2NumberGroupingFormatter::CPbk2NumberGroupingFormatter |
|
38 // -------------------------------------------------------------------------- |
|
39 // |
|
40 CPbk2NumberGroupingFormatter::CPbk2NumberGroupingFormatter() |
|
41 { |
|
42 } |
|
43 |
|
44 // -------------------------------------------------------------------------- |
|
45 // CPbk2NumberGroupingFormatter::~CPbk2NumberGroupingFormatter |
|
46 // -------------------------------------------------------------------------- |
|
47 // |
|
48 CPbk2NumberGroupingFormatter::~CPbk2NumberGroupingFormatter() |
|
49 { |
|
50 delete iNumberGrouping; |
|
51 delete iFormatterNumberBuffer; |
|
52 } |
|
53 |
|
54 // -------------------------------------------------------------------------- |
|
55 // CPbk2NumberGroupingFormatter::ConstructL |
|
56 // -------------------------------------------------------------------------- |
|
57 // |
|
58 void CPbk2NumberGroupingFormatter::ConstructL |
|
59 ( TInt aMaxDisplayLength ) |
|
60 { |
|
61 // The grouping object takes care of calculating the size of the |
|
62 // grouped number, just pass the length of the non-grouped number |
|
63 iNumberGrouping = CPNGNumberGrouping::NewL( aMaxDisplayLength ); |
|
64 |
|
65 iFormatterNumberBuffer = HBufC::NewL |
|
66 ( KGroupingFactor * aMaxDisplayLength ); |
|
67 |
|
68 #ifdef PBK2_FORCE_NUMBERGROUPING_ON |
|
69 iNumberGrouping->iForceLanguage = ELangAmerican; |
|
70 #endif // PBK2_FORCE_NUMBERGROUPING_ON |
|
71 } |
|
72 |
|
73 // -------------------------------------------------------------------------- |
|
74 // CPbk2NumberGroupingFormatter::NewL |
|
75 // -------------------------------------------------------------------------- |
|
76 // |
|
77 CPbk2NumberGroupingFormatter* CPbk2NumberGroupingFormatter::NewL |
|
78 ( TInt aMaxDisplayLength ) |
|
79 { |
|
80 CPbk2NumberGroupingFormatter* self = |
|
81 new( ELeave ) CPbk2NumberGroupingFormatter; |
|
82 CleanupStack::PushL( self ); |
|
83 self->ConstructL( aMaxDisplayLength ); |
|
84 CleanupStack::Pop( self ); |
|
85 return self; |
|
86 } |
|
87 |
|
88 // -------------------------------------------------------------------------- |
|
89 // CPbk2NumberGroupingFormatter::SetMaxBufferLengthL |
|
90 // -------------------------------------------------------------------------- |
|
91 // |
|
92 void CPbk2NumberGroupingFormatter::SetMaxBufferLengthL( TInt aMaxLength ) |
|
93 { |
|
94 if ( aMaxLength > iNumberGrouping->MaxDisplayLength() ) |
|
95 { |
|
96 CPNGNumberGrouping* newNumberGrouping = |
|
97 CPNGNumberGrouping::NewL( aMaxLength ); |
|
98 delete iNumberGrouping; |
|
99 iNumberGrouping = newNumberGrouping; |
|
100 iFormatterNumberBuffer = |
|
101 iFormatterNumberBuffer->ReAllocL( KGroupingFactor * aMaxLength ); |
|
102 } |
|
103 |
|
104 #ifdef PBK2_FORCE_NUMBERGROUPING_ON |
|
105 iNumberGrouping->iForceLanguage = ELangAmerican; |
|
106 #endif // PBK2_FORCE_NUMBERGROUPING_ON |
|
107 } |
|
108 |
|
109 // -------------------------------------------------------------------------- |
|
110 // CPbkNumberGroupingFormatter::FormatPhoneNumberForDisplay |
|
111 // -------------------------------------------------------------------------- |
|
112 // |
|
113 TPtrC CPbk2NumberGroupingFormatter::FormatPhoneNumberForDisplay( |
|
114 const TDesC& aOriginalPhoneNumber ) |
|
115 { |
|
116 if ( aOriginalPhoneNumber.Length() <= |
|
117 iNumberGrouping->MaxDisplayLength() ) |
|
118 { |
|
119 iNumberGrouping->Set( aOriginalPhoneNumber ); |
|
120 TPtr formatterNumber = iFormatterNumberBuffer->Des(); |
|
121 formatterNumber.Copy( iNumberGrouping->FormattedNumber() ); |
|
122 |
|
123 AknTextUtils::DisplayTextLanguageSpecificNumberConversion |
|
124 ( formatterNumber ); |
|
125 return formatterNumber; |
|
126 } |
|
127 else |
|
128 { |
|
129 // Too long number to format, just return the original. This is |
|
130 // in line with MPbkPhoneNumberFormatter interface's |
|
131 // best-effort promise. |
|
132 return aOriginalPhoneNumber; |
|
133 } |
|
134 } |
|
135 |
|
136 // End of File |