|
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: Implementation for CPbkInfoViewSindHandler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "pbkinfoviewsindhandler.h" |
|
21 #include "pbkinfoviewreshandler.h" |
|
22 #include "pbkinfoviewdefines.h" |
|
23 #include <pbkinfoview.rsg> |
|
24 |
|
25 #include <vuivoicerecogdefs.h> // KVoiceDialContext |
|
26 #include <nssvascoreconstant.h> |
|
27 #include <vascvpbkhandler.h> |
|
28 #include <CPbkContactEngine.h> |
|
29 #include <CPbkContactItem.h> |
|
30 #include <CPbkFieldInfo.h> |
|
31 #include <StringLoader.h> |
|
32 #include <nssvascoreconstant.h> |
|
33 |
|
34 #include "rubydebug.h" |
|
35 |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ======================= |
|
38 |
|
39 inline CPbkInfoViewSindHandler::CPbkInfoViewSindHandler() |
|
40 { |
|
41 } |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // CPbkInfoViewSindHandler::ConstructL |
|
45 // Creates a new instance of CPbkSindHandler. |
|
46 // @param aContactId Contact id for the contact whose voice tags are to |
|
47 // be fetched from vas db. |
|
48 // ---------------------------------------------------------------------------- |
|
49 inline void CPbkInfoViewSindHandler::ConstructL( TInt aContactId ) |
|
50 { |
|
51 InitializeL( aContactId ); |
|
52 |
|
53 CreateVoiceTagListL( aContactId ); |
|
54 |
|
55 CreatePopupArrayL(); |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // CPbkInfoViewSindHandler::TestConstructL |
|
60 // Creates an instance that doesn't require CCoeEnv for STIF testing purposes. |
|
61 // @param aContactId Contact id for the contact whose voice tags are to |
|
62 // be fetched from vas db. |
|
63 // ---------------------------------------------------------------------------- |
|
64 inline void CPbkInfoViewSindHandler::TestConstructL( TInt aContactId ) |
|
65 { |
|
66 InitializeL( aContactId ); |
|
67 |
|
68 CreateVoiceTagListL( aContactId ); |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // CPbkInfoViewSindHandler::InitializeL |
|
73 // Initialization. |
|
74 // @param aContactId Contact id for the contact whose voice tags are |
|
75 // fetched from vas db. |
|
76 // @return TInt KErrNone on success |
|
77 // ---------------------------------------------------------------------------- |
|
78 void CPbkInfoViewSindHandler::InitializeL( TInt aContactId ) |
|
79 { |
|
80 RUBY_DEBUG_BLOCK( "CPbkInfoViewSindHandler::InitializeL" ); |
|
81 |
|
82 // create Vas db manager |
|
83 iVasDbManager = CNssVASDBMgr::NewL(); |
|
84 |
|
85 iVasDbManager->InitializeL(); |
|
86 |
|
87 // Ownership not transferred |
|
88 iContextManager = iVasDbManager->GetContextMgr(); |
|
89 // Ownership not transferred |
|
90 iTagManager = iVasDbManager->GetTagMgr(); |
|
91 |
|
92 iWait = new (ELeave) CActiveSchedulerWait(); |
|
93 |
|
94 // Create and initialize phonebook handler that is used to get the |
|
95 // phone numbers etc used in voice tags. |
|
96 iPbkHandler = CVasVPbkHandler::NewL(); |
|
97 iPbkHandler->InitializeL(); |
|
98 |
|
99 iPbkEngine = CPbkContactEngine::NewL(); |
|
100 |
|
101 if( aContactId == KVoiceTaglessContactId ) |
|
102 { |
|
103 iPbkContactItem = iPbkEngine->CreateEmptyContactL(); |
|
104 } |
|
105 else |
|
106 { |
|
107 iPbkHandler->FindContactL( aContactId, ETrue ); |
|
108 iPbkContactItem = iPbkEngine->ReadContactL( aContactId ); |
|
109 } |
|
110 |
|
111 iTts = CTtsUtility::NewL( *this ); |
|
112 |
|
113 // Put to thread local storage so that CompareL can use this pointer |
|
114 Dll::SetTls( iPbkContactItem ); |
|
115 |
|
116 iPlaybackIndex = -1; |
|
117 } |
|
118 |
|
119 // ---------------------------------------------------------------------------- |
|
120 // CPbkInfoViewSindHandler::NewL |
|
121 // |
|
122 // ---------------------------------------------------------------------------- |
|
123 CPbkInfoViewSindHandler* CPbkInfoViewSindHandler::NewL( TInt aContactId ) |
|
124 { |
|
125 RUBY_DEBUG_BLOCK( "CPbkInfoViewSindHandler::NewL" ); |
|
126 |
|
127 CPbkInfoViewSindHandler* self = new (ELeave) CPbkInfoViewSindHandler; |
|
128 CleanupStack::PushL( self ); |
|
129 self->ConstructL( aContactId ); |
|
130 CleanupStack::Pop(self); |
|
131 return self; |
|
132 } |
|
133 |
|
134 // ---------------------------------------------------------------------------- |
|
135 // CPbkInfoViewSindHandler::TestNewL |
|
136 // |
|
137 // ---------------------------------------------------------------------------- |
|
138 CPbkInfoViewSindHandler* CPbkInfoViewSindHandler::TestNewL( TInt aContactId ) |
|
139 { |
|
140 CPbkInfoViewSindHandler* self = new (ELeave) CPbkInfoViewSindHandler; |
|
141 CleanupStack::PushL( self ); |
|
142 self->TestConstructL( aContactId ); |
|
143 CleanupStack::Pop(self); |
|
144 return self; |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // CPbkInfoViewSindHandler::~CPbkInfoViewSindHandler |
|
149 // |
|
150 // ---------------------------------------------------------------------------- |
|
151 CPbkInfoViewSindHandler::~CPbkInfoViewSindHandler() |
|
152 { |
|
153 delete iVasDbManager; |
|
154 iVasDbManager = NULL; |
|
155 |
|
156 delete iContext; |
|
157 iContext = NULL; |
|
158 |
|
159 delete iWait; |
|
160 iWait = NULL; |
|
161 |
|
162 iTagArray.ResetAndDestroy(); |
|
163 |
|
164 // Free iPbkContactItem from thread local storage |
|
165 Dll::FreeTls(); |
|
166 |
|
167 delete iPbkContactItem; |
|
168 iPbkContactItem = NULL; |
|
169 |
|
170 delete iPbkEngine; |
|
171 iPbkEngine = NULL; |
|
172 |
|
173 iPopupArray.ResetAndDestroy(); |
|
174 |
|
175 delete iPbkHandler; |
|
176 |
|
177 delete iTts; |
|
178 } |
|
179 |
|
180 // ---------------------------------------------------------------------------- |
|
181 // CPbkInfoViewSindHandler::VoiceTagCount |
|
182 // Returns the number of voice tags for the contact. |
|
183 // @return TInt voice tag count. |
|
184 // ---------------------------------------------------------------------------- |
|
185 TInt CPbkInfoViewSindHandler::VoiceTagCount() |
|
186 { |
|
187 RUBY_DEBUG_BLOCK( "CPbkInfoViewSindHandler::VoiceTagCount" ); |
|
188 |
|
189 return iTagArray.Count(); |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------------------------- |
|
193 // CPbkInfoViewSindHandler::VoiceTagL |
|
194 // Returns a voice tag. |
|
195 // @param aIndex index for the voice tag. 0 <= aIndex <= VoiceTagCount() - 1 |
|
196 // @return TDesC& the voice tag |
|
197 // ---------------------------------------------------------------------------- |
|
198 const TDesC& CPbkInfoViewSindHandler::VoiceTagL( TInt aIndex ) |
|
199 { |
|
200 RUBY_DEBUG_BLOCK( "CPbkInfoViewSindHandler::VoiceTagL" ); |
|
201 |
|
202 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < VoiceTagCount(), |
|
203 User::Leave( KErrArgument ) ); |
|
204 |
|
205 return iTagArray[aIndex]->SpeechItem()->Text(); |
|
206 } |
|
207 |
|
208 // ---------------------------------------------------------------------------- |
|
209 // CPbkInfoViewSindHandler::VoiceTagLabelLC |
|
210 // Returns the label associated with a voice tag (mobile, home, etc). |
|
211 // @param aIndex index for the voice tag label. |
|
212 // 0 <= aIndex <= VoiceTagCount() - 1 |
|
213 // @return TPtrC the value |
|
214 // ---------------------------------------------------------------------------- |
|
215 HBufC* CPbkInfoViewSindHandler::VoiceTagLabelLC( TInt aIndex ) |
|
216 { |
|
217 RUBY_DEBUG0( "CPbkInfoViewSindHandler::VoiceTagLabelLC START" ); |
|
218 |
|
219 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < VoiceTagCount(), |
|
220 User::Leave( KErrArgument ) ); |
|
221 |
|
222 TInt contactId = iTagArray[aIndex]->RRD() |
|
223 ->IntArray()->At( KVasContactIdRrdLocation ); |
|
224 TInt fieldId = iTagArray[aIndex]->RRD() |
|
225 ->IntArray()->At( KVasFieldIdRrdLocation ); |
|
226 |
|
227 // RawText is in the format of _1firstName_1lastName_2extension |
|
228 // or _2extension _1firstName_1lastName |
|
229 HBufC* tagLabel = iTagArray[aIndex]->SpeechItem()->RawText().AllocLC(); |
|
230 tagLabel->Des().TrimAll(); |
|
231 |
|
232 TInt separatorIndex = tagLabel->Des().Find( KTagExtensionSeparator ); |
|
233 // Checks whether this a voice tag for nick name (with or without |
|
234 // extensions) or for first-last name combination without extension. |
|
235 // In this case show the whole tag, just remove separators. |
|
236 if( iTagArray[aIndex]->RRD()->IntArray()->At( KVasTagTypeRrdLocation ) |
|
237 == ETagTypeNickName || separatorIndex == KErrNotFound ) |
|
238 { |
|
239 // Remove name separators |
|
240 while( (separatorIndex = tagLabel->Des().Find( KTagNameSeparator ) ) |
|
241 != KErrNotFound ) |
|
242 { |
|
243 tagLabel->Des().Replace( separatorIndex, KTagSeparatorLength, |
|
244 KSpace ); |
|
245 } |
|
246 // Remove extension separator |
|
247 separatorIndex = tagLabel->Des().Find( KTagExtensionSeparator ); |
|
248 if( separatorIndex != KErrNotFound ) |
|
249 { |
|
250 tagLabel->Des().Replace( separatorIndex, KTagSeparatorLength, |
|
251 KSpace ); |
|
252 } |
|
253 |
|
254 RUBY_DEBUG0( "CPbkInfoViewSindHandler::VoiceTagLabelLC EXIT" ); |
|
255 return tagLabel; |
|
256 } |
|
257 |
|
258 TInt nameSeparatorIndex = tagLabel->Des().Find( KTagNameSeparator ); |
|
259 CleanupStack::PopAndDestroy( tagLabel ); |
|
260 |
|
261 // Show the extension only |
|
262 |
|
263 // RawText is in format _2extension _1firstName_1lastName |
|
264 if( nameSeparatorIndex > separatorIndex ) |
|
265 { |
|
266 TInt length( nameSeparatorIndex - separatorIndex - KTagSeparatorLength ); |
|
267 tagLabel = iTagArray[aIndex]->SpeechItem()->RawText() |
|
268 .Mid( separatorIndex + KTagSeparatorLength, length ) |
|
269 .AllocLC(); |
|
270 } |
|
271 // _1firstName_1lastName_2extension |
|
272 else |
|
273 { |
|
274 tagLabel = iTagArray[aIndex]->SpeechItem()->RawText() |
|
275 .Mid( separatorIndex + KTagSeparatorLength ).AllocLC(); |
|
276 } |
|
277 |
|
278 RUBY_DEBUG0( "CPbkInfoViewSindHandler::VoiceTagLabelLC EXIT" ); |
|
279 |
|
280 return tagLabel; |
|
281 } |
|
282 |
|
283 // ---------------------------------------------------------------------------- |
|
284 // CPbkInfoViewSindHandler::VoiceTagValueL |
|
285 // Returns the phone number, e-mail address, etc. associated with a voice tag. |
|
286 // @param aIndex index for the voice tag. 0 <= aIndex <= VoiceTagCount() - 1 |
|
287 // @return TPtrC the value |
|
288 // ---------------------------------------------------------------------------- |
|
289 TPtrC CPbkInfoViewSindHandler::VoiceTagValueL( TInt aIndex ) |
|
290 { |
|
291 RUBY_DEBUG_BLOCK( "CPbkInfoViewSindHandler::VoiceTagValueL" ); |
|
292 |
|
293 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < VoiceTagCount(), |
|
294 User::Leave( KErrArgument ) ); |
|
295 |
|
296 // By using CVasVPbkHandler, info view will show consistent information with |
|
297 // Recognition UI. |
|
298 iPbkHandler->FindContactFieldL( iTagArray[aIndex] ); |
|
299 return iPbkHandler->TextL(); |
|
300 } |
|
301 |
|
302 // ---------------------------------------------------------------------------- |
|
303 // CPbkInfoViewSindHandler::PopupTextL |
|
304 // Returns the popup text associated with a voice tag. |
|
305 // @param aIndex index for the voice tag. 0 <= aIndex <= VoiceTagCount() - 1 |
|
306 // @return TDesC& popup text |
|
307 // ---------------------------------------------------------------------------- |
|
308 TDesC& CPbkInfoViewSindHandler::PopupTextL( TInt aIndex ) |
|
309 { |
|
310 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < VoiceTagCount(), |
|
311 User::Leave( KErrArgument ) ); |
|
312 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iPopupArray.Count(), |
|
313 User::Leave( KErrArgument ) ); |
|
314 |
|
315 return *iPopupArray[aIndex]; |
|
316 } |
|
317 |
|
318 // ---------------------------------------------------------------------------- |
|
319 // CPbkInfoViewSindHandler::PlayVoiceCommandL |
|
320 // Plays a voice tag. |
|
321 // @param aIndex index for the voice tag. 0 <= aIndex <= VoiceTagCount() - 1 |
|
322 // ---------------------------------------------------------------------------- |
|
323 void CPbkInfoViewSindHandler::PlayVoiceCommandL( TInt aIndex ) |
|
324 { |
|
325 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < VoiceTagCount(), |
|
326 User::Leave( KErrArgument ) ); |
|
327 |
|
328 if( IsPlaying() ) |
|
329 { |
|
330 CancelPlaybackL(); |
|
331 } |
|
332 iTts->Stop(); |
|
333 |
|
334 iPlaybackIndex = aIndex; |
|
335 |
|
336 // fetch contact name and contact type (mobile, e-mail etc.) |
|
337 // ignore KErrNotFound leave |
|
338 HBufC* contact = NULL; |
|
339 HBufC* type = NULL; |
|
340 TRAPD( err, contact = iTagArray[aIndex]->SpeechItem()->PartialTextL( KNameTrainingIndex ) ); |
|
341 if ( err != KErrNone && err != KErrNotFound) User::Leave( err ); |
|
342 TRAPD( err2, iTagArray[aIndex]->SpeechItem()->PartialTextL( KExtensionTrainingIndex ) ); |
|
343 if ( err2 != KErrNone && err2 != KErrNotFound) User::Leave( err2 ); |
|
344 |
|
345 // fetch whole tts string |
|
346 const TDesC& text = iTagArray[aIndex]->SpeechItem()->Text(); |
|
347 TInt contactIndex; |
|
348 TInt typeIndex; |
|
349 if ( contact && type ) |
|
350 { |
|
351 // get contact and type indexes |
|
352 // assume contactIndex is before typeIndex |
|
353 contactIndex = text.Find( *contact ); |
|
354 typeIndex = text.Right( text.Length()-contactIndex-contact->Length() ).Find( *type ); |
|
355 if ( typeIndex==KErrNotFound ) |
|
356 { |
|
357 // if not, change the order |
|
358 typeIndex = text.Find( *type ); |
|
359 contactIndex = text.Right( text.Length()-typeIndex-type->Length() ).Find( *contact ); |
|
360 contactIndex = type->Length(); |
|
361 } |
|
362 else |
|
363 { |
|
364 typeIndex = contact->Length(); |
|
365 } |
|
366 // create segments |
|
367 CTtsParsedText* parsedText = CTtsParsedText::NewL(); |
|
368 CleanupStack::PushL( parsedText ); |
|
369 |
|
370 TTtsStyle* contactStyle = new (ELeave) TTtsStyle(); |
|
371 CleanupStack::PushL( contactStyle ); |
|
372 |
|
373 TTtsStyleID* contactStyleId = new (ELeave) TTtsStyleID( 0 ); |
|
374 CleanupStack::PushL( contactStyleId ); |
|
375 |
|
376 TTtsSegment* contactSegment = new (ELeave) TTtsSegment( 0 ); |
|
377 CleanupStack::PushL( contactSegment ); |
|
378 |
|
379 contactStyle->iLanguage = User::Language(); |
|
380 *contactStyleId = iTts->AddStyleL( *contactStyle ); |
|
381 contactSegment->SetStyleID( *contactStyleId ); |
|
382 |
|
383 TTtsStyle* typeStyle = new (ELeave) TTtsStyle(); |
|
384 CleanupStack::PushL( typeStyle ); |
|
385 |
|
386 TTtsStyleID* typeStyleId = new (ELeave) TTtsStyleID( 0 ); |
|
387 CleanupStack::PushL( typeStyleId ); |
|
388 |
|
389 TTtsSegment* typeSegment = new (ELeave) TTtsSegment( 0 ); |
|
390 CleanupStack::PushL( typeSegment ); |
|
391 |
|
392 typeStyle->iLanguage = User::Language(); |
|
393 *typeStyleId = iTts->AddStyleL( *typeStyle ); |
|
394 typeSegment->SetStyleID( *typeStyleId ); |
|
395 |
|
396 if (contactIndex < typeIndex) |
|
397 { |
|
398 contactSegment->SetTextPtr( text.Mid( contactIndex, contact->Length() ) ); |
|
399 typeSegment->SetTextPtr( text.Right( text.Length()-typeIndex ) ); |
|
400 parsedText->AddSegmentL( *contactSegment ); |
|
401 parsedText->AddSegmentL( *typeSegment ); |
|
402 } |
|
403 else |
|
404 { |
|
405 typeSegment->SetTextPtr( text.Mid( typeIndex, type->Length() ) ); |
|
406 contactSegment->SetTextPtr( text.Right( text.Length()-contactIndex ) ); |
|
407 parsedText->AddSegmentL( *typeSegment ); |
|
408 parsedText->AddSegmentL( *contactSegment ); |
|
409 } |
|
410 parsedText->SetTextL( text ); |
|
411 iTts->OpenAndPlayParsedTextL( *parsedText ); |
|
412 |
|
413 CleanupStack::PopAndDestroy( typeSegment ); |
|
414 CleanupStack::PopAndDestroy( typeStyleId ); |
|
415 CleanupStack::PopAndDestroy( typeStyle ); |
|
416 CleanupStack::PopAndDestroy( contactSegment ); |
|
417 CleanupStack::PopAndDestroy( contactStyleId ); |
|
418 CleanupStack::PopAndDestroy( contactStyle ); |
|
419 CleanupStack::PopAndDestroy( parsedText ); |
|
420 } |
|
421 else |
|
422 { |
|
423 // if there is only one part (contact), play normally |
|
424 iTagArray[aIndex]->SpeechItem()->PlayL( this ); |
|
425 } |
|
426 } |
|
427 |
|
428 // ---------------------------------------------------------------------------- |
|
429 // CPbkInfoViewSindHandler::CancelPlaybackL |
|
430 // Cancels voice tag playback. |
|
431 // ---------------------------------------------------------------------------- |
|
432 void CPbkInfoViewSindHandler::CancelPlaybackL() |
|
433 { |
|
434 if( !( iPlaybackIndex > -1 && |
|
435 iPlaybackIndex < iTagArray.Count() ) ) |
|
436 { |
|
437 return; |
|
438 } |
|
439 |
|
440 iTagArray[iPlaybackIndex]->SpeechItem()->CancelL(); |
|
441 |
|
442 iPlaybackIndex = -1; |
|
443 } |
|
444 |
|
445 // ---------------------------------------------------------------------------- |
|
446 // CPbkInfoViewSindHandler::IsPlaying |
|
447 // Is voice tag playing ongoing. |
|
448 // @return TBool boolean value |
|
449 // ---------------------------------------------------------------------------- |
|
450 TBool CPbkInfoViewSindHandler::IsPlaying() |
|
451 { |
|
452 return iPlaybackIndex > -1; |
|
453 } |
|
454 |
|
455 // ---------------------------------------------------------------------------- |
|
456 // CPbkInfoViewSindHandler::IconIdL |
|
457 // Returns an icon id for the contact field the voice tag is associated with. |
|
458 // @param aIndex index for the voice tag. 0 <= aIndex <= VoiceTagCount() - 1 |
|
459 // @return TInt the icon id |
|
460 // ---------------------------------------------------------------------------- |
|
461 TInt CPbkInfoViewSindHandler::IconIdL( TInt aIndex ) |
|
462 { |
|
463 RUBY_DEBUG_BLOCK( "CPbkInfoViewSindHandler::IconIdL" ); |
|
464 |
|
465 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < VoiceTagCount(), |
|
466 User::Leave( KErrArgument ) ); |
|
467 |
|
468 TInt contactId = iTagArray[aIndex]->RRD() |
|
469 ->IntArray()->At( KVasContactIdRrdLocation ); |
|
470 TInt fieldId = iTagArray[aIndex]->RRD() |
|
471 ->IntArray()->At( KVasFieldIdRrdLocation ); |
|
472 |
|
473 iPbkContactItemField = iPbkContactItem->FindField( fieldId ); |
|
474 if ( !iPbkContactItemField ) |
|
475 { |
|
476 iPbkContactItemField = FindDefaultField( iPbkContactItem, fieldId ); |
|
477 } |
|
478 |
|
479 if ( !iPbkContactItemField ) |
|
480 { |
|
481 User::Leave( KErrNotFound ); |
|
482 } |
|
483 |
|
484 return iPbkContactItemField->IconId(); |
|
485 } |
|
486 |
|
487 // ---------------------------------------------------------------------------- |
|
488 // CPbkInfoViewSindHandler::CreateVoiceTagListL |
|
489 // Fetches voice tag list from vas db. |
|
490 // @param aContactId Contact id for the contact whose voice tags are |
|
491 // fetched from vas db. |
|
492 // ---------------------------------------------------------------------------- |
|
493 void CPbkInfoViewSindHandler::CreateVoiceTagListL( TInt aContactId ) |
|
494 { |
|
495 RUBY_DEBUG_BLOCK( "CPbkInfoViewSindHandler::CreateVoiceTagListL" ); |
|
496 |
|
497 // Get context |
|
498 TInt err = iContextManager->GetContext( this, KVoiceDialContext ); |
|
499 if ( err == KErrNone ) |
|
500 { |
|
501 if ( iWait && !iWait->IsStarted() ) |
|
502 { |
|
503 // Let's synchronize GetContext-method. |
|
504 iWait->Start(); |
|
505 if ( !iContext ) |
|
506 { |
|
507 // the context getting has failed. |
|
508 // cannot continue |
|
509 User::Leave( KErrGeneral ); |
|
510 } |
|
511 |
|
512 } |
|
513 else |
|
514 { |
|
515 User::Leave( KErrGeneral ); |
|
516 } |
|
517 } |
|
518 else |
|
519 { |
|
520 User::Leave( KErrGeneral ); |
|
521 } |
|
522 |
|
523 iErr = iTagManager->GetTagList( this, iContext, |
|
524 aContactId, KVasContactIdRrdLocation ); |
|
525 |
|
526 if( !iErr ) |
|
527 { |
|
528 // Let's synchronize the GetTagList call |
|
529 if ( iWait && !iWait->IsStarted() ) |
|
530 { |
|
531 iWait->Start(); |
|
532 RUBY_DEBUG1( "CPbkInfoViewSindHandler::CreateVoiceTagListL - iErr=[%d]", iErr ); |
|
533 } |
|
534 else |
|
535 { |
|
536 User::Leave( KErrGeneral ); |
|
537 } |
|
538 } |
|
539 } |
|
540 |
|
541 // ---------------------------------------------------------------------------- |
|
542 // CPbkInfoViewSindHandler::CreatePopupArrayL |
|
543 // Creates an array for popups in info view list. |
|
544 // @param aContactId Contact id for the contact whose voice tags are |
|
545 // fetched from vas db. |
|
546 // @return TInt KErrNone on success |
|
547 // ---------------------------------------------------------------------------- |
|
548 void CPbkInfoViewSindHandler::CreatePopupArrayL() |
|
549 { |
|
550 RUBY_DEBUG_BLOCK( "CPbkInfoViewSindHandler::CreatePopupArrayL" ); |
|
551 |
|
552 // Create popup text for each voice tag |
|
553 for( TInt i( 0 ); i < iTagArray.Count(); i++ ) |
|
554 { |
|
555 HBufC* voiceTag( iTagArray[i]->SpeechItem()->RawText().AllocLC() ); |
|
556 |
|
557 HBufC* resourceText; |
|
558 TInt index = voiceTag->Des().Find( KTagExtensionSeparator ); |
|
559 // Checks whether this a voice tag without an extension |
|
560 if( index == KErrNotFound ) |
|
561 { |
|
562 resourceText = StringLoader::LoadLC( R_INFOVIEW_POPUP_CONTACT ); |
|
563 } |
|
564 else |
|
565 { |
|
566 resourceText = StringLoader::LoadLC( R_INFOVIEW_POPUP_GENERAL ); |
|
567 } |
|
568 |
|
569 // Remove name separators |
|
570 while( (index = voiceTag->Des().Find( KTagNameSeparator ) ) |
|
571 != KErrNotFound ) |
|
572 { |
|
573 voiceTag->Des().Replace( index, KTagSeparatorLength, |
|
574 KSpace ); |
|
575 } |
|
576 // Remove extension separator |
|
577 index = voiceTag->Des().Find( KTagExtensionSeparator ); |
|
578 if( index != KErrNotFound ) |
|
579 { |
|
580 voiceTag->Des().Replace( index, KTagSeparatorLength, |
|
581 KSpace ); |
|
582 } |
|
583 voiceTag->Des().TrimAll(); |
|
584 |
|
585 TName popupText; |
|
586 // Insert voiceTag to resourceText to create popupText |
|
587 StringLoader::Format( popupText, *resourceText, -1, *voiceTag ); |
|
588 |
|
589 iPopupArray.AppendL( popupText.AllocL() ); |
|
590 |
|
591 //CleanupStack::Pop( popupText ); |
|
592 CleanupStack::PopAndDestroy( resourceText ); |
|
593 CleanupStack::PopAndDestroy( voiceTag ); |
|
594 } |
|
595 } |
|
596 |
|
597 // ---------------------------------------------------------------------------- |
|
598 // CPbkInfoViewSindHandler::GetContextCompleted |
|
599 // |
|
600 // ---------------------------------------------------------------------------- |
|
601 void CPbkInfoViewSindHandler::GetContextCompleted( MNssContext* aContext, |
|
602 TInt aErrorCode ) |
|
603 { |
|
604 if( aErrorCode == KErrNone ) |
|
605 { |
|
606 // ownership is transferred |
|
607 iContext = aContext; |
|
608 |
|
609 // if the iWait has been started, the completion of GetContext method |
|
610 // has been synchronized in VoiceTagField - method. Otherwise |
|
611 // the completion has happened in background. |
|
612 if ( iWait && iWait->IsStarted() ) |
|
613 { |
|
614 iWait->AsyncStop(); |
|
615 } |
|
616 } |
|
617 else |
|
618 { |
|
619 iErr = aErrorCode; |
|
620 // if the get context has been synchronized: |
|
621 if ( iWait && iWait->IsStarted() ) |
|
622 { |
|
623 iWait->AsyncStop(); |
|
624 } |
|
625 } |
|
626 } |
|
627 |
|
628 // ---------------------------------------------------------------------------- |
|
629 // CPbkInfoViewSindHandler::GetContextListCompleted |
|
630 // Callback, getting of contexts has completed successfully. |
|
631 // ---------------------------------------------------------------------------- |
|
632 void CPbkInfoViewSindHandler::GetContextListCompleted( |
|
633 MNssContextListArray* /*aContextList*/, TInt /*aErrorCode*/ ) |
|
634 { |
|
635 // never comes here, defined as pure virtual in MNssGetContextClient. |
|
636 } |
|
637 |
|
638 // ---------------------------------------------------------------------------- |
|
639 // CPbkInfoViewSindHandler::GetTagListCompleted |
|
640 // Callback, getting of tags has completed successfully. |
|
641 // ---------------------------------------------------------------------------- |
|
642 void CPbkInfoViewSindHandler::GetTagListCompleted( MNssTagListArray* aTagList, |
|
643 TInt aErrorCode ) |
|
644 { |
|
645 RUBY_DEBUG0( "CPbkInfoViewSindHandler::GetTagListCompleted" ); |
|
646 |
|
647 if( aErrorCode == KErrNone ) |
|
648 { |
|
649 // Fill the tag array |
|
650 for( TInt i( 0 ); i < aTagList->Count(); i++ ) |
|
651 { |
|
652 MNssTag* tag = aTagList->At( i ); |
|
653 |
|
654 TInt fieldId = tag->RRD()->IntArray()->At( KVasFieldIdRrdLocation ); |
|
655 |
|
656 // Get pointer to CPbkContactItem-object from thread local storage |
|
657 CPbkContactItem* pbkContactItem = |
|
658 static_cast<CPbkContactItem*>( Dll::Tls() ); |
|
659 |
|
660 TPbkContactItemField* field = pbkContactItem->FindField( fieldId ); |
|
661 if ( !field ) |
|
662 { |
|
663 field = FindDefaultField( pbkContactItem, fieldId ); |
|
664 } |
|
665 |
|
666 // Add only tags that have field in phonebook |
|
667 if ( field ) |
|
668 { |
|
669 iTagArray.Append( tag ); |
|
670 } |
|
671 else |
|
672 { |
|
673 // If some tag is missing then we don't want to show anything |
|
674 iTagArray.ResetAndDestroy(); |
|
675 break; |
|
676 } |
|
677 } |
|
678 |
|
679 aTagList->Reset(); |
|
680 delete aTagList; |
|
681 |
|
682 iTagArray.Sort( TLinearOrder<MNssTag>( CPbkInfoViewSindHandler::Compare ) ); |
|
683 |
|
684 // Continue with CreateVoiceTagListL-method. |
|
685 if ( iWait && iWait->IsStarted() ) |
|
686 { |
|
687 iWait->AsyncStop(); |
|
688 } |
|
689 } |
|
690 |
|
691 else // aErrorCode != KErrNone |
|
692 { |
|
693 iErr = aErrorCode; |
|
694 if ( iWait && iWait->IsStarted() ) |
|
695 { |
|
696 iWait->AsyncStop(); |
|
697 } |
|
698 } |
|
699 } |
|
700 |
|
701 // ----------------------------------------------------------------------------- |
|
702 // CPbkInfoViewSindHandler::HandlePlayComplete |
|
703 // Callback, playback has been completed. |
|
704 // ----------------------------------------------------------------------------- |
|
705 // |
|
706 void CPbkInfoViewSindHandler::HandlePlayComplete( TNssPlayResult /*aResult*/ ) |
|
707 { |
|
708 iPlaybackIndex = -1; |
|
709 } |
|
710 |
|
711 |
|
712 // ----------------------------------------------------------------------------- |
|
713 // Calls CompareL and catches possible leaves |
|
714 // ----------------------------------------------------------------------------- |
|
715 // |
|
716 TInt CPbkInfoViewSindHandler::Compare( const MNssTag& aTag1, const MNssTag& aTag2 ) |
|
717 { |
|
718 TInt result = 0; |
|
719 |
|
720 TRAP_IGNORE( result = CompareL( aTag1, aTag2 ) ); |
|
721 |
|
722 return result; |
|
723 } |
|
724 |
|
725 // ----------------------------------------------------------------------------- |
|
726 // Compares two voice tags and decides which one should be displayed first in |
|
727 // info view list. Used in the sorting of voice tags. |
|
728 // @param aTag1 A voice tag |
|
729 // @param aTag2 A voice tag |
|
730 // @return TInt -1 if aTag1 should be displayed first, 1 if aTag2 should be |
|
731 // displayed first, 0 otherwise. |
|
732 // ----------------------------------------------------------------------------- |
|
733 // |
|
734 TInt CPbkInfoViewSindHandler::CompareL( const MNssTag& aTag1, const MNssTag& aTag2 ) |
|
735 { |
|
736 RUBY_DEBUG_BLOCK( "CPbkInfoViewSindHandler::GetTagListCompleted" ); |
|
737 |
|
738 MNssTag& tag1 = const_cast<MNssTag&>( aTag1 ); |
|
739 MNssTag& tag2 = const_cast<MNssTag&>( aTag2 ); |
|
740 |
|
741 TInt tagType1 = tag1.RRD()->IntArray()->At( KVasTagTypeRrdLocation ); |
|
742 TInt tagType2 = tag2.RRD()->IntArray()->At( KVasTagTypeRrdLocation ); |
|
743 |
|
744 // Check if one of the tags is for nickname |
|
745 if( ( tagType1 == ETagTypeName || tagType1 == ETagTypeCompanyName ) && |
|
746 tagType2 == ETagTypeNickName ) |
|
747 { |
|
748 return -1; |
|
749 } |
|
750 if( ( tagType2 == ETagTypeName || tagType2 == ETagTypeCompanyName ) && |
|
751 tagType1 == ETagTypeNickName ) |
|
752 { |
|
753 return 1; |
|
754 } |
|
755 |
|
756 TInt fieldId1 = tag1.RRD()->IntArray()->At( KVasFieldIdRrdLocation ); |
|
757 TInt fieldId2 = tag2.RRD()->IntArray()->At( KVasFieldIdRrdLocation ); |
|
758 |
|
759 // Get pointer to CPbkContactItem-object from thread local storage |
|
760 CPbkContactItem* pbkContactItem = |
|
761 static_cast<CPbkContactItem*>( Dll::Tls() ); |
|
762 |
|
763 TPbkContactItemField* field1 = pbkContactItem->FindField( fieldId1 ); |
|
764 if ( !field1 ) |
|
765 { |
|
766 field1 = FindDefaultField( pbkContactItem, fieldId1 ); |
|
767 } |
|
768 TPbkContactItemField* field2 = pbkContactItem->FindField( fieldId2 ); |
|
769 if ( !field2 ) |
|
770 { |
|
771 field2 = FindDefaultField( pbkContactItem, fieldId2 ); |
|
772 } |
|
773 |
|
774 if ( !field1 || !field2 ) |
|
775 { |
|
776 User::Leave( KErrNotFound ); |
|
777 } |
|
778 |
|
779 TBool noExtension1 = EFalse; |
|
780 TBool noExtension2 = EFalse; |
|
781 |
|
782 HBufC* label = tag1.SpeechItem()->RawText().AllocLC(); |
|
783 label->Des().TrimAll(); |
|
784 |
|
785 TInt index = label->Des().Find( KTagExtensionSeparator ); |
|
786 // Checks whether this a voice tag without extension |
|
787 if( index == KErrNotFound ) |
|
788 { |
|
789 noExtension1 = ETrue; |
|
790 } |
|
791 |
|
792 CleanupStack::PopAndDestroy( label ); |
|
793 |
|
794 label = tag2.SpeechItem()->RawText().AllocLC(); |
|
795 label->Des().TrimAll(); |
|
796 |
|
797 index = label->Des().Find( KTagExtensionSeparator ); |
|
798 // Checks whether this a voice tag without extension |
|
799 if( index == KErrNotFound ) |
|
800 { |
|
801 noExtension2 = ETrue; |
|
802 } |
|
803 |
|
804 CleanupStack::PopAndDestroy( label ); |
|
805 |
|
806 if( noExtension1 && !noExtension2 ) |
|
807 { |
|
808 return -1; |
|
809 } |
|
810 else if ( !noExtension1 && noExtension2 ) |
|
811 { |
|
812 return 1; |
|
813 } |
|
814 |
|
815 // compare the two neighbors |
|
816 TInt ret = field1->Compare( *field2 ); |
|
817 |
|
818 // Sorting for normal call, sms, and multimedia msg fields |
|
819 if ( ret == 0) |
|
820 { |
|
821 TInt actionId1 = tag1.RRD()->IntArray()->At( KVasExtensionRrdLocation ); |
|
822 TInt actionId2 = tag2.RRD()->IntArray()->At( KVasExtensionRrdLocation ); |
|
823 |
|
824 if ( actionId1 != actionId2 ) |
|
825 { |
|
826 if ( actionId1 < actionId2 ) |
|
827 { |
|
828 return -1; |
|
829 } |
|
830 return 1; |
|
831 } |
|
832 } |
|
833 |
|
834 return ret; |
|
835 } |
|
836 |
|
837 // ----------------------------------------------------------------------------- |
|
838 // Tries to find a default contact item field |
|
839 // @param aContactItem A contact item |
|
840 // @param aFieldId A field to search |
|
841 // @return TPbkContactItemField* Default field if found, otherwise NULL |
|
842 // ----------------------------------------------------------------------------- |
|
843 // |
|
844 TPbkContactItemField* CPbkInfoViewSindHandler::FindDefaultField |
|
845 ( CPbkContactItem* aContactItem, TInt aFieldId ) |
|
846 { |
|
847 TPbkContactItemField* field = NULL; |
|
848 |
|
849 if ( aFieldId == EPbkFieldIdPhoneNumberVideo ) |
|
850 { |
|
851 field = aContactItem->DefaultVideoNumberField(); |
|
852 } |
|
853 else if ( aFieldId == EPbkFieldIdEmailAddress ) |
|
854 { |
|
855 field = aContactItem->DefaultEmailField(); |
|
856 } |
|
857 else if ( aFieldId == EPbkFieldIdVOIP ) |
|
858 { |
|
859 field = aContactItem->DefaultVoipField(); |
|
860 } |
|
861 |
|
862 return field; |
|
863 } |
|
864 |
|
865 // End of file |