|
1 /* |
|
2 * Copyright (c) 2006 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: Constructs text to speech descriptor. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tphcnttxttospeech.h" |
|
20 #include "mphcntcontactfields.h" |
|
21 |
|
22 // Separator between lastname/firstname for TTS text. |
|
23 _LIT( KPhCntTtsNamesDelimeter, " " ); |
|
24 |
|
25 // Number of languages that use lastname-firstname order |
|
26 const TInt KPhCntTtsNumberOfSwappedLanguages = 7; |
|
27 |
|
28 // Languages which use lastname-firstname order |
|
29 const TLanguage KPhCntTtsSwappedLanguages[KPhCntTtsNumberOfSwappedLanguages] = |
|
30 { |
|
31 ELangHungarian, // 17 |
|
32 ELangTaiwanChinese, // 29 |
|
33 ELangHongKongChinese, // 30 |
|
34 ELangPrcChinese, // 31 |
|
35 ELangJapanese, // 32 |
|
36 ELangKorean, // 65 |
|
37 ELangVietnamese // 96 |
|
38 }; |
|
39 |
|
40 // ======== MEMBER FUNCTIONS ======== |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 TPhCntTxtToSpeech::TPhCntTxtToSpeech( |
|
47 const TDesC& aFirstName, |
|
48 const TDesC& aSecondName, |
|
49 const TDesC& aLastName, |
|
50 const TDesC& aCompanyName, |
|
51 const TDesC& aFirstNamePronunciation, |
|
52 const TDesC& aLastNamePronunciation, |
|
53 const TDesC& aCompanyNamePronunciation, |
|
54 TLanguage aCurrentLanguage ) : |
|
55 iFirstName( aFirstName ), |
|
56 iSecondName( aSecondName ), |
|
57 iLastName( aLastName ), |
|
58 iCompanyName( aCompanyName ), |
|
59 iFirstNamePronunciation( aFirstNamePronunciation ), |
|
60 iLastNamePronunciation( aLastNamePronunciation ), |
|
61 iCompanyNamePronunciation( aCompanyNamePronunciation ), |
|
62 iCurrentLanguage( aCurrentLanguage ) |
|
63 { |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Constructs text to speech descriptor. |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 void TPhCntTxtToSpeech::GetTextToSpeechL( HBufC*& aTxtToSpeech ) const |
|
71 { |
|
72 aTxtToSpeech = AllocAndTrimL( iSecondName ); |
|
73 |
|
74 // Try contact name (first & last name). |
|
75 if ( !aTxtToSpeech ) |
|
76 { |
|
77 HBufC* trimmedFirstName = GetTrimmedNameLC( |
|
78 iFirstName, iFirstNamePronunciation ); |
|
79 |
|
80 HBufC* trimmedLastName = GetTrimmedNameLC( |
|
81 iLastName, iLastNamePronunciation ); |
|
82 |
|
83 // Determine order. |
|
84 const TBool swapNameOrder = SwapNameOrder(); |
|
85 |
|
86 HBufC* firstComponent = trimmedFirstName; |
|
87 HBufC* lastComponent = trimmedLastName; |
|
88 if ( swapNameOrder ) |
|
89 { |
|
90 firstComponent = trimmedLastName; |
|
91 lastComponent = trimmedFirstName; |
|
92 } |
|
93 |
|
94 // Calculate length. |
|
95 const TInt totalLength( |
|
96 CalculateTxtToSpeechLength( firstComponent, lastComponent ) ); |
|
97 |
|
98 // Compose. |
|
99 if ( totalLength ) |
|
100 { |
|
101 aTxtToSpeech = HBufC::NewL( totalLength ); |
|
102 TPtr ptr = aTxtToSpeech->Des(); |
|
103 |
|
104 if ( firstComponent ) |
|
105 { |
|
106 ptr.Append( *firstComponent ); |
|
107 if ( lastComponent ) |
|
108 { |
|
109 ptr.Append( KPhCntTtsNamesDelimeter ); |
|
110 } |
|
111 } |
|
112 if ( lastComponent ) |
|
113 { |
|
114 ptr.Append( *lastComponent ); |
|
115 } |
|
116 } |
|
117 |
|
118 CleanupStack::PopAndDestroy( trimmedLastName ); |
|
119 CleanupStack::PopAndDestroy( trimmedFirstName ); |
|
120 } |
|
121 |
|
122 // Try company name. |
|
123 if ( !aTxtToSpeech ) |
|
124 { |
|
125 aTxtToSpeech = AllocAndTrimL( iCompanyNamePronunciation ); |
|
126 if( !aTxtToSpeech ) |
|
127 { |
|
128 aTxtToSpeech = AllocAndTrimL( iCompanyName ); |
|
129 } |
|
130 } |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // Copies the text and trims it. |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 HBufC* TPhCntTxtToSpeech::AllocAndTrimL( const TDesC& aText ) const |
|
138 { |
|
139 HBufC* result = NULL; |
|
140 |
|
141 if( aText.Length() > 0 ) |
|
142 { |
|
143 result = aText.AllocL(); |
|
144 TPtr ptr = result->Des(); |
|
145 ptr.Trim(); |
|
146 if ( !ptr.Length() ) |
|
147 { |
|
148 delete result; |
|
149 result = NULL; |
|
150 } |
|
151 } |
|
152 |
|
153 return result; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // Swaps name order depending on current language. |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 TBool TPhCntTxtToSpeech::SwapNameOrder() const |
|
161 { |
|
162 TBool result = EFalse; |
|
163 for ( TInt index = 0; index < KPhCntTtsNumberOfSwappedLanguages; index++ ) |
|
164 { |
|
165 if ( KPhCntTtsSwappedLanguages[ index ] == iCurrentLanguage ) |
|
166 { |
|
167 result = ETrue; |
|
168 index = KPhCntTtsNumberOfSwappedLanguages; |
|
169 } |
|
170 } |
|
171 |
|
172 return result; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // Takes suitable name, copies and trims it. |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 HBufC* TPhCntTxtToSpeech::GetTrimmedNameLC( |
|
180 const TDesC& aWritenName, |
|
181 const TDesC& aNamePronunciation ) const |
|
182 { |
|
183 HBufC* trimmedName = AllocAndTrimL( aNamePronunciation ); |
|
184 if ( !trimmedName ) |
|
185 { |
|
186 trimmedName = AllocAndTrimL( aWritenName ); |
|
187 } |
|
188 CleanupStack::PushL( trimmedName ); |
|
189 return trimmedName; |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // Calculates the length of text to speech string. |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 TInt TPhCntTxtToSpeech::CalculateTxtToSpeechLength( |
|
197 const HBufC* const aFirstComponent, |
|
198 const HBufC* const aLastComponent ) const |
|
199 { |
|
200 TInt totalLength = 0; |
|
201 if( aFirstComponent && aLastComponent ) |
|
202 { |
|
203 totalLength += KPhCntTtsNamesDelimeter().Length(); |
|
204 } |
|
205 |
|
206 if( aFirstComponent ) |
|
207 { |
|
208 totalLength += aFirstComponent->Length(); |
|
209 } |
|
210 |
|
211 if( aLastComponent ) |
|
212 { |
|
213 totalLength += aLastComponent->Length(); |
|
214 } |
|
215 |
|
216 return totalLength; |
|
217 } |
|
218 |
|
219 // End of File |