|
1 /* |
|
2 * Copyright (c) 2005-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: Responsible for maintaining synchronization between the contact DB |
|
15 * and the VAS DB |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** @todo Read the whole contact in one go. |
|
21 |
|
22 Currently Contact handler usually opens the same contact (ReadContactL) two to |
|
23 three times in order to read its data (mostly often three times). |
|
24 One is in GetContactNickname |
|
25 Second in GetContactTitle |
|
26 Third in DoAddNamesL when deciding what number field should the voice tag |
|
27 be trained for |
|
28 If we could unite these reads, "reading contacts" phase will be 2-3 times faster. |
|
29 It would make about 10-20% improvement for the training of some 300 contacts */ |
|
30 |
|
31 // INCLUDE FILES |
|
32 #include "nssvasccontacthandlerimpl.h" |
|
33 #include "nssvasctrainingparameters.h" |
|
34 #include <nssvascvasdbmgr.h> |
|
35 #include <centralrepository.h> |
|
36 #include <f32file.h> |
|
37 #include <bautils.h> |
|
38 #include <barsc.h> |
|
39 #include <barsread.h> |
|
40 #include <sysutil.h> |
|
41 #include "srsfprivatecrkeys.h" |
|
42 |
|
43 // Publish & Subscribe of the contact handler activity |
|
44 #include <nssvascoreconstant.h> |
|
45 |
|
46 #include <vascvpbkhandler.h> |
|
47 #include <featmgr.h> |
|
48 #include "nssvasdatasyncwatcher.h" |
|
49 #include "nsschbackupobserver.h" |
|
50 #include <StringLoader.h> |
|
51 #include <nssvascontacthandler.rsg> |
|
52 #include <data_caging_path_literals.hrh> |
|
53 #include "rubydebug.h" |
|
54 |
|
55 // CONSTANTS |
|
56 // Name of the context in the SIND DB. Voice tags for contacts are saved there |
|
57 _LIT( KNssCHNameDialContext, "NAMEDIAL" ); |
|
58 |
|
59 // Languages which use lastname-firstname order |
|
60 const TLanguage KSwappedLanguages[] = |
|
61 { |
|
62 ELangHungarian, // 17 |
|
63 ELangTaiwanChinese, // 29 |
|
64 ELangHongKongChinese, // 30 |
|
65 ELangJapanese, // 32 |
|
66 ELangPrcChinese, // 31 |
|
67 ELangKorean, // 65 |
|
68 ELangVietnamese // 96 |
|
69 }; |
|
70 |
|
71 // Number of languages that use lastname-firstname order |
|
72 const TInt KNumberOfSwappedLanguages = sizeof( KSwappedLanguages ) / sizeof ( TLanguage ); |
|
73 |
|
74 |
|
75 // Maximal number of retrials to save tags |
|
76 const TInt KVASCHMaxRetry = 2; |
|
77 |
|
78 // Size of the event 'pack'. Tags are added and deleted in groups. |
|
79 // KMaxNamesAtOnce is the maximal size of a group |
|
80 const TInt KMaxNamesAtOnce = 100; |
|
81 |
|
82 // Initial value of the time interval used to detect periodic action. In |
|
83 // microseconds. If KEventMomentsSize events happened within the |
|
84 // KInitialPeriodicActionInterval, we assume, that periodic action has started |
|
85 const TInt KInitialPeriodicActionInterval = 15000000; |
|
86 |
|
87 // Time interval used to periodically check if there are pending |
|
88 // events to process. In microseconds |
|
89 const TInt KPeriodicTimerInterval = 1000000; |
|
90 |
|
91 // If there are this many consecutive full resyncs initiated by errors during |
|
92 // handling normal changes (or during previous full resync), there is probably |
|
93 // something consistently wrong at the lower layers. |
|
94 // Full resync trials (and the whole contact handler) should be disabled until |
|
95 // reboot after KMaxConsecutiveErrorFullResync consecutive unsuccessful trials |
|
96 const TInt KMaxConsecutiveErrorFullResync = 2; |
|
97 |
|
98 // List of phonebook fields, that are supported by contact handler. |
|
99 // I.e. fields, that can be dialed and voice tagged |
|
100 /** @todo Consider using information from phonebook about which fields contain numbers |
|
101 and using the following lists for priorities only */ |
|
102 const TPbkFieldId KTaggableFields[] = |
|
103 { |
|
104 EPbkFieldIdPhoneNumberMobile, |
|
105 EPbkFieldIdPhoneNumberGeneral, |
|
106 EPbkFieldIdPhoneNumberStandard, |
|
107 EPbkFieldIdPhoneNumberHome, |
|
108 EPbkFieldIdPhoneNumberWork, |
|
109 EPbkFieldIdPhoneNumberVideo, |
|
110 EPbkFieldIdVOIP, |
|
111 EPbkFieldIdXsp |
|
112 }; |
|
113 const TInt KTaggableFieldsCount = sizeof( KTaggableFields ) / sizeof ( TPbkFieldId ); |
|
114 |
|
115 // List of phonebook fields that are supported by video extension |
|
116 const TPbkFieldId KVideoExtensionFields[] = |
|
117 { |
|
118 EPbkFieldIdPhoneNumberVideo, |
|
119 EPbkFieldIdPhoneNumberMobile, |
|
120 EPbkFieldIdPhoneNumberGeneral, |
|
121 EPbkFieldIdPhoneNumberHome, |
|
122 EPbkFieldIdPhoneNumberWork |
|
123 }; |
|
124 const TInt KVideoExtensionFieldsCount = sizeof( KVideoExtensionFields ) / sizeof ( TPbkFieldId ); |
|
125 |
|
126 // List of phonebook fields that are supported by message extension |
|
127 const TPbkFieldId KMessageExtensionFields[] = |
|
128 { |
|
129 EPbkFieldIdPhoneNumberMobile, |
|
130 EPbkFieldIdPhoneNumberGeneral, |
|
131 EPbkFieldIdPhoneNumberHome, |
|
132 EPbkFieldIdPhoneNumberWork, |
|
133 EPbkFieldIdPhoneNumberVideo |
|
134 }; |
|
135 const TInt KMessageExtensionFieldsCount = sizeof( KMessageExtensionFields ) / sizeof ( TPbkFieldId ); |
|
136 |
|
137 // List of phonebook fields that are supported by VOIP extension |
|
138 const TPbkFieldId KVOIPExtensionFields[] = |
|
139 { |
|
140 EPbkFieldIdVOIP, |
|
141 EPbkFieldIdXsp |
|
142 }; |
|
143 const TInt KVOIPExtensionFieldsCount = sizeof( KVOIPExtensionFields ) / sizeof ( TPbkFieldId ); |
|
144 |
|
145 // Size of the client data per context. Is used to store the context language |
|
146 // In bytes |
|
147 const TInt KClientDataSize = sizeof(TNssContextClientData); |
|
148 |
|
149 |
|
150 // Number of retries to try to lock the same contact |
|
151 // 600 times should stand for 10 mins |
|
152 // -1 means trying forever |
|
153 const TInt KMaxContactLockRetrials = 600; |
|
154 |
|
155 // Interval between the ticks of the contact wait timer |
|
156 // in microseconds |
|
157 const TInt32 KContactWaitInterval = 1000000; |
|
158 |
|
159 // Bytes that should be free in the disk drive in addition to critical level |
|
160 // before operation is started (100kB) |
|
161 const TInt KIncreaseOfDatabaseSizes = 100000; |
|
162 |
|
163 // Define this if name free-order is enabled |
|
164 //#define NSSVAS_CONTACTHANDLER_FREEORDER |
|
165 // LOCAL FUNCTION DECLARATIONS |
|
166 |
|
167 |
|
168 // ================= MEMBER FUNCTIONS ======================= |
|
169 |
|
170 |
|
171 #ifdef _DEBUG |
|
172 _LIT( KFile, "VasCContactHandlerImpl.cpp" ); |
|
173 #endif |
|
174 |
|
175 /** |
|
176 * Is used in DoHandleEventFailedL to *asynchronously* simulate successful tag |
|
177 * deletion |
|
178 */ |
|
179 NONSHARABLE_CLASS( CSuccessfulDeletionSimulator ) : public CAsyncOneShot |
|
180 { |
|
181 public: |
|
182 CSuccessfulDeletionSimulator( CNssContactHandlerImplementation& aHost ); |
|
183 ~CSuccessfulDeletionSimulator(); |
|
184 protected: |
|
185 /** Is called by the system after we asked it to Call() closer |
|
186 */ |
|
187 virtual void RunL(); |
|
188 private: |
|
189 CNssContactHandlerImplementation& iHost; |
|
190 }; |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CSuccessfulDeletionSimulator::~CSuccessfulDeletionSimulator |
|
194 // Destructor |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 CSuccessfulDeletionSimulator::~CSuccessfulDeletionSimulator() |
|
198 { |
|
199 RUBY_DEBUG0( "~CSuccessfulDeletionSimulator" ); |
|
200 if( IsAdded() ) |
|
201 { |
|
202 RUBY_DEBUG0( "~CSuccessfulDeletionSimulator Request is still in progress, deque it" ); |
|
203 Deque(); |
|
204 } |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CSuccessfulDeletionSimulator::CSuccessfulDeletionSimulator |
|
209 // Constructor |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 CSuccessfulDeletionSimulator::CSuccessfulDeletionSimulator( CNssContactHandlerImplementation& aHost ) : |
|
213 CAsyncOneShot( CActive::EPriorityStandard ), |
|
214 iHost( aHost ) |
|
215 { |
|
216 //nothing |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CAppCloser::RunL |
|
221 // Will be called by the system and exits the application |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 void CSuccessfulDeletionSimulator::RunL() |
|
225 { |
|
226 RUBY_DEBUG0( "CSuccessfulDeletionSimulator::RunL Start" ); |
|
227 if( iStatus == KErrNone ) |
|
228 { |
|
229 CArrayPtrFlat<MNssTag>* empty = new (ELeave) CArrayPtrFlat<MNssTag>( 1 ); |
|
230 iHost.DoRemoveNamesAfterGetTagList( empty ); |
|
231 // empty will be destroyed in the DoRemoveNamesAfterGetTagList |
|
232 } |
|
233 else |
|
234 { |
|
235 RUBY_ERROR1( "CSuccessfulDeletionSimulator::RunL Unexpected iStatus [%d]", iStatus.Int() ); |
|
236 } |
|
237 RUBY_DEBUG0( "CSuccessfulDeletionSimulator::RunL End" ); |
|
238 } |
|
239 |
|
240 |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CNssContactHandlerImplementation::CNssContactHandlerImplementation |
|
244 // C++ default constructor can NOT contain any code, that |
|
245 // might leave. |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 CNssContactHandlerImplementation::CNssContactHandlerImplementation( ) |
|
249 : iState( ECHInitializing ), |
|
250 iSeparator( KNameSeparator()[0] ), |
|
251 iEndOfPeriodicActionInterval( KInitialPeriodicActionInterval ) |
|
252 { |
|
253 iClientData.iLanguage = ELangNone; |
|
254 |
|
255 // initialize last RestartTimer calls to be long ago in |
|
256 // the past (January 1st, 0 AD nominal Gregorian) |
|
257 for( TInt i = 0; i < KEventMomentsSize; i++) |
|
258 { |
|
259 iEventMoments[i] = 0; |
|
260 } |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CNssContactHandlerImplementation::ConstructL |
|
265 // EPOC second phase constructor can leave. |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CNssContactHandlerImplementation::ConstructL() |
|
269 { |
|
270 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::ConstructL" ); |
|
271 |
|
272 User::LeaveIfError( iFSession.Connect() ); |
|
273 |
|
274 // Sets up TLS, must be done before FeatureManager is used. |
|
275 FeatureManager::InitializeLibL(); |
|
276 iVoIPFeatureSupported = FeatureManager::FeatureSupported( KFeatureIdCommonVoip ); |
|
277 iVideoCallFeatureSupported = FeatureManager::FeatureSupported( KFeatureIdCsVideoTelephony ); |
|
278 // Frees the TLS! Must be done after FeatureManager is used. |
|
279 FeatureManager::UnInitializeLib(); |
|
280 |
|
281 // Before enabling event, start monitoring the PC-suite state |
|
282 iSyncBackupWaiter = new (ELeave) CActiveSchedulerWait; |
|
283 |
|
284 iDataSyncWatcher = CNssDataSyncWatcherFactory::ConstructDataSyncWatcherL( *this ); |
|
285 |
|
286 iBackupObserver = CNssChBackupObserver::NewL( *this ); |
|
287 |
|
288 iContactWaiter = new (ELeave) CActiveSchedulerWait; |
|
289 |
|
290 iDeletionSimulator = new (ELeave) CSuccessfulDeletionSimulator( *this ); |
|
291 |
|
292 EnableEventHandling(); |
|
293 |
|
294 iEventArray.Reset(); // Ready to be used |
|
295 |
|
296 TInt errProp = iBusyProperty.Define( KSINDUID, ETrainingContactsState, RProperty::EInt ); |
|
297 if( ( errProp != KErrNone ) && ( errProp != KErrAlreadyExists ) ) |
|
298 { |
|
299 RUBY_ERROR1("CNssContactHandlerImplementation::ConstructL() Failed to define the property. Error [%d]", |
|
300 errProp); |
|
301 User::Leave( errProp ); |
|
302 } |
|
303 |
|
304 // Publish contact handler as busy before the DB operations |
|
305 errProp = iBusyProperty.Attach( KSINDUID, ETrainingContactsState ); |
|
306 if( errProp != KErrNone ) |
|
307 { |
|
308 // KErrNotFound is also an error as we just defined the property |
|
309 RUBY_ERROR1("CNssContactHandlerImplementation::ConstructL() Failed to attach to property. Error [%d]", |
|
310 errProp); |
|
311 User::Leave( errProp ); |
|
312 } |
|
313 |
|
314 errProp = iBusyProperty.Set( EContactsTraining ); |
|
315 if ( errProp != KErrNone ) |
|
316 { |
|
317 RUBY_ERROR1("CNssContactHandlerImplementation::ConstructL() Failed to set property. Error [%d]", |
|
318 errProp ); |
|
319 User::Leave( errProp ) ; |
|
320 } |
|
321 |
|
322 |
|
323 // central repository |
|
324 iRepository = CRepository::NewL( KCRUidSRSFSettings ); |
|
325 iRepositoryObserver = CCenRepNotifyHandler::NewL( *this, *iRepository, |
|
326 CCenRepNotifyHandler::EIntKey, |
|
327 KSRSFFullResyncNeeded ); |
|
328 iRepositoryObserver->StartListeningL(); |
|
329 |
|
330 //Get VAS DB manager |
|
331 iVasDbManager = CNssVASDBMgr::NewL(); |
|
332 iVasDbManager->InitializeL(); |
|
333 RUBY_DEBUG0( "CNssContactHandlerImplementation::ConstructL iVasDbManager initialized" ); |
|
334 |
|
335 //Get Tag Manager and Context Manager interfaces |
|
336 iTagManager = iVasDbManager->GetTagMgr(); |
|
337 iContextManager = iVasDbManager->GetContextMgr(); |
|
338 |
|
339 // Prepare training parameters |
|
340 iTrainingParams = CNssTrainingParameters::NewL(); |
|
341 |
|
342 RUBY_DEBUG0( "CNssContactHandlerImplementation::ConstructL iTrainingParams prepared" ); |
|
343 |
|
344 // Set languages which have lastname-firstname order |
|
345 for ( TInt iCounter = 0; iCounter < KNumberOfSwappedLanguages; iCounter++ ) |
|
346 { |
|
347 User::LeaveIfError( iSwappedLanguages.Append( KSwappedLanguages[iCounter] ) ); |
|
348 } |
|
349 |
|
350 #ifdef __SINDE_TRAINING |
|
351 // Main array for languages |
|
352 RArray<RTrainingLanguageArray> languages; |
|
353 |
|
354 // Languages for names |
|
355 RArray<TLanguage> nameLanguages; |
|
356 User::LeaveIfError( nameLanguages.Append( User::Language() ) ); |
|
357 User::LeaveIfError( nameLanguages.Append( ELangOther ) ); |
|
358 User::LeaveIfError( languages.Append( nameLanguages ) ); |
|
359 |
|
360 // Languages for extensions |
|
361 RArray<TLanguage> extLanguages; |
|
362 User::LeaveIfError( extLanguages.Append( User::Language() ) ); |
|
363 User::LeaveIfError( languages.Append( extLanguages ) ); |
|
364 |
|
365 // Store languages to training parameters |
|
366 iTrainingParams->SetSindeLanguages( languages ); |
|
367 |
|
368 // Close arrays, iTrainingParams has done a copy of these |
|
369 extLanguages.Close(); |
|
370 nameLanguages.Close(); |
|
371 languages.Close(); |
|
372 |
|
373 #else |
|
374 // Set the languages |
|
375 RArray<TLanguage> *languages = new (ELeave) RArray<TLanguage>; |
|
376 CleanupStack::PushL( languages ); |
|
377 // Always generate a pronunciation in UI language |
|
378 User::LeaveIfError( languages->Append( User::Language() ) ); |
|
379 // give some extra languages, which can be selected in engine |
|
380 User::LeaveIfError( languages->Append( ELangOther ) ); |
|
381 iTrainingParams->SetLanguages( languages ); |
|
382 CleanupStack::Pop( languages ); |
|
383 #endif |
|
384 |
|
385 // The separator between the first name and the last name |
|
386 iTrainingParams->SetSeparator( iSeparator ); |
|
387 |
|
388 #ifdef __SIND_EXTENSIONS |
|
389 |
|
390 ReadExtensionsL(); |
|
391 #endif // __SIND_EXTENSIONS |
|
392 |
|
393 ConnectToPhonebookL(); |
|
394 |
|
395 TLitC<9> name = KNssCHNameDialContext; |
|
396 |
|
397 // Get context. |
|
398 |
|
399 // (1) if we have synced earlier -> we have created a context, and saved the language |
|
400 // (2) if we haven't synced -> we need to create context |
|
401 // |
|
402 // In case (2), GetContext fails. |
|
403 // We'll assume that GetContext is successful until it fails. |
|
404 iHaveWeEverSynced = ETrue; |
|
405 |
|
406 TInt err = iContextManager->GetContext( this, name ); |
|
407 RUBY_DEBUG1( "CNssContactHandlerImplementation::ConstructL Requested GetContext. err [%d]", err); |
|
408 |
|
409 if ( err != KErrNone ) |
|
410 { |
|
411 // The same function is called, whether GetContext fails synchronously |
|
412 // or asynchronously. |
|
413 GetContextCompleted( NULL, KErrNotFound ); |
|
414 } |
|
415 iDeleteTagListArray = new (ELeave) CArrayPtrFlat<MNssTag>(50); |
|
416 |
|
417 } |
|
418 |
|
419 // --------------------------------------------------------- |
|
420 // CNssContactHandlerImplementation::NewL |
|
421 // Two-phased constructor. |
|
422 // --------------------------------------------------------- |
|
423 // |
|
424 CNssContactHandlerImplementation* CNssContactHandlerImplementation::NewL( ) |
|
425 { |
|
426 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::NewL" ); |
|
427 CNssContactHandlerImplementation* self = new (ELeave) CNssContactHandlerImplementation(); |
|
428 |
|
429 CleanupStack::PushL( self ); |
|
430 self->ConstructL(); |
|
431 CleanupStack::Pop( self ); |
|
432 |
|
433 return self; |
|
434 } |
|
435 |
|
436 // --------------------------------------------------------- |
|
437 // CNssContactHandlerImplementation::~CNssContactHandlerImplementation |
|
438 // Destructor |
|
439 // --------------------------------------------------------- |
|
440 // |
|
441 CNssContactHandlerImplementation::~CNssContactHandlerImplementation() |
|
442 { |
|
443 RUBY_DEBUG0( "CNssContactHandlerImplementation::~CNssContactHandlerImplementation FIXED" ); |
|
444 |
|
445 iFSession.Close(); |
|
446 |
|
447 iEventArray.Close(); // Close the RArray |
|
448 |
|
449 delete iDataSyncWatcher; |
|
450 delete iBackupObserver; |
|
451 |
|
452 if ( iSyncBackupWaiter != NULL ) |
|
453 { |
|
454 if( iSyncBackupWaiter->IsStarted() ) |
|
455 { |
|
456 iSyncBackupWaiter->AsyncStop(); |
|
457 } |
|
458 } |
|
459 delete iSyncBackupWaiter; |
|
460 |
|
461 if ( iContactWaiter != NULL ) |
|
462 { |
|
463 if( iContactWaiter->IsStarted() ) |
|
464 { |
|
465 iContactWaiter->AsyncStop(); |
|
466 } |
|
467 } |
|
468 |
|
469 |
|
470 delete iContactWaiter; |
|
471 delete iDeletionSimulator; |
|
472 delete iPeriodicHandleEventTimer; |
|
473 |
|
474 delete iContext; |
|
475 |
|
476 delete iVasDbManager; |
|
477 RProperty::Delete( KSINDUID, ETrainingContactsState ); |
|
478 iBusyProperty.Close(); |
|
479 |
|
480 delete iRepositoryObserver; |
|
481 delete iRepository; |
|
482 |
|
483 delete iTrainingParams; |
|
484 iTagArray.ResetAndDestroy(); |
|
485 |
|
486 for( TInt k( 0 ); k < iContactQueue.Count(); k++ ) |
|
487 { |
|
488 delete iContactQueue[k].iTitle; |
|
489 } |
|
490 iContactQueue.Close(); |
|
491 |
|
492 iDelList.Close(); |
|
493 iAddList.Close(); |
|
494 iRemoveIconList.Close(); |
|
495 iVoiceTagAddedList.Close(); |
|
496 iSwappedLanguages.Close(); |
|
497 |
|
498 DisconnectFromPhonebook(); |
|
499 |
|
500 #ifdef __SIND_EXTENSIONS |
|
501 |
|
502 for ( TInt i(0); i < iExtensionList.Count(); i++ ) |
|
503 { |
|
504 delete iExtensionList[i].iText; |
|
505 } |
|
506 |
|
507 iExtensionList.Close(); |
|
508 #endif // __SIND_EXTENSIONS |
|
509 } |
|
510 |
|
511 // --------------------------------------------------------- |
|
512 // CNssContactHandlerImplementation::HandleEventL |
|
513 // Called by phonebook handler when a contact database event |
|
514 // occurs |
|
515 // --------------------------------------------------------- |
|
516 // |
|
517 void CNssContactHandlerImplementation::HandleEventL( const TPhonebookEvent& aEvent ) |
|
518 { |
|
519 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::HandleEventL" ); |
|
520 RUBY_DEBUG2( "CNssContactHandlerImplementation::HandleEventL(). Contact id [%d], event type [%d]", aEvent.iContactId, aEvent.iType ); |
|
521 |
|
522 if ( aEvent.iType == EContactChanged || |
|
523 aEvent.iType == EContactDeleted || |
|
524 aEvent.iType == EContactAdded || |
|
525 aEvent.iType == EUnknownChanges ) |
|
526 { |
|
527 if( !CausedByVoiceTagAddition( aEvent ) ) |
|
528 { |
|
529 // Check if operations can be finished |
|
530 // There should be enough disk space |
|
531 if ( NoDiskSpace() ) |
|
532 { |
|
533 RUBY_DEBUG0( "CNssContactHandlerImplementation::HandleEventL not enough disk space, disabling event handling" ); |
|
534 DisableEventHandling(); |
|
535 } |
|
536 else |
|
537 { |
|
538 TInt errProp = iBusyProperty.Set( EContactsTraining ); |
|
539 if ( errProp != KErrNone ) |
|
540 { |
|
541 RUBY_ERROR1("CNssContactHandlerImplementation::ConstructL() Failed to set property. Error [%d]", |
|
542 errProp ); |
|
543 User::Leave( errProp ) ; |
|
544 } |
|
545 UpdatePeriodicActionVars(); |
|
546 iEventArray.Append( aEvent ); |
|
547 |
|
548 if ( iState == ECHIdle ) |
|
549 { |
|
550 RUBY_DEBUG0( "CNssContactHandlerImplementation::HandleEventL() iState == ECHIdle => DoHandleEvent" ); |
|
551 |
|
552 // Process the first new event from the queue |
|
553 TRAPD( err, DoHandleEventsL() ); |
|
554 RUBY_DEBUG1( "CNssContactHandlerImplementation::HandleEventL. Assert would fail and Panic IF err != KErrNone. err [%d]", err ); |
|
555 RUBY_ASSERT_DEBUG( err == KErrNone, User::Panic( KFile, __LINE__ ) ); |
|
556 |
|
557 if ( err != KErrNone ) |
|
558 { |
|
559 RUBY_ERROR1( "CNssContactHandlerImplementation::HandleEventL. Error [%d] in DoHandleEventsL", err ); |
|
560 } |
|
561 } |
|
562 else |
|
563 { |
|
564 RUBY_DEBUG1( "CNssContactHandlerImplementation::HandleEventL() iState == [%d] => Do not handle the event right now", iState ); |
|
565 } // if iState else |
|
566 } |
|
567 } // if caused be voice tag addition |
|
568 else |
|
569 { |
|
570 RUBY_DEBUG2( "CNssContactHandlerImplementation::HandleEventL(). Event for Contact id [%d] was caused by a voice icon addition and will be ignored, eventArray size [%d]", aEvent.iContactId, iEventArray.Count() ); |
|
571 if ( ( iVoiceTagAddedList.Count() == 0 ) && ( iState == ECHIdle ) && ( iEventArray.Count() == 0 ) ) |
|
572 { |
|
573 RUBY_DEBUG0( "HandleEventL No more voice icon events expected, nothing pending." ); |
|
574 } |
|
575 else |
|
576 { |
|
577 RUBY_DEBUG1( "HandleEventL [%d] voice icon events are still expected", iVoiceTagAddedList.Count() ); |
|
578 } |
|
579 } |
|
580 } |
|
581 else if ( aEvent.iType == EStoreRestoreBeginning ) |
|
582 { |
|
583 RUBY_DEBUG0( "CNssContactHandlerImplementation::HandleEventL restore begin" ); |
|
584 iRestoreRunning = ETrue; // set to differentiate ending of restore or backup |
|
585 } |
|
586 else if ( aEvent.iType == EStoreBackupRestoreCompleted && iRestoreRunning ) |
|
587 { |
|
588 RUBY_DEBUG0( "CNssContactHandlerImplementation::HandleEventL restore end" ); |
|
589 // Set value to make full resync |
|
590 SetFullResyncCrFlagL( ETrue ); |
|
591 iRestoreRunning = EFalse; |
|
592 } // if event type |
|
593 } |
|
594 |
|
595 |
|
596 |
|
597 // --------------------------------------------------------- |
|
598 // CNssContactHandlerImplementation::DoHandleEventL |
|
599 // Process the Event from phonebook |
|
600 // --------------------------------------------------------- |
|
601 // |
|
602 void CNssContactHandlerImplementation::DoHandleEventsL() |
|
603 { |
|
604 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::DoHandleEventsL" ); |
|
605 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoHandleEventsL, eventArray size [%d]", iEventArray.Count() ); |
|
606 |
|
607 // If there is no lengthy higher level routine executed |
|
608 if( !PeriodicAction() ) |
|
609 { |
|
610 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventsL !PeriodicAction()" ); |
|
611 if ( iHandlerEnabled ) |
|
612 { |
|
613 if ( IsFullResyncNeeded() ) |
|
614 { |
|
615 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventsL() Full resync if needed. Setting iState to ECHFullResync" ); |
|
616 SetState( ECHFullResync ); |
|
617 |
|
618 iEventArray.Close(); |
|
619 |
|
620 FullResyncStart(); |
|
621 } |
|
622 else |
|
623 { |
|
624 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventsL() Full resync if NOT needed. Setting iState to ECHHandlingNormalChanges" ); |
|
625 SetState( ECHHandlingNormalChanges ); |
|
626 |
|
627 // There are 3 phases in handling events: |
|
628 // (1) Make two lists: |
|
629 // * Names to be added |
|
630 // * Names to be deleted |
|
631 CollectAddRemoveListsL(); |
|
632 |
|
633 // (2) Delete the names to be deleted. This operation is asynchronous. |
|
634 DoRemoveNamesL(); |
|
635 |
|
636 // (3) After removing names, add the names to be added. |
|
637 // DoRemoveNamesL() starts the step (3) |
|
638 } |
|
639 } |
|
640 else |
|
641 { |
|
642 // In UREL, empty "else" branch will be eliminated by the compiler |
|
643 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventsL() Handler was disabled" ); |
|
644 } |
|
645 |
|
646 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventsL() completed" ); |
|
647 |
|
648 }// if !PeriodicAction |
|
649 |
|
650 else |
|
651 { |
|
652 // In UREL, empty "else" branch will be eliminated by the compiler |
|
653 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventsL PeriodicAction detected, DoHandleEventsL omitted" ); |
|
654 } |
|
655 |
|
656 } |
|
657 |
|
658 // --------------------------------------------------------- |
|
659 // CNssContactHandlerImplementation::DeleteTagCompleted |
|
660 // Called when the deletion of a tag is completed successfully |
|
661 // --------------------------------------------------------- |
|
662 // |
|
663 void CNssContactHandlerImplementation::DeleteTagCompleted( TInt aErrorCode ) |
|
664 { |
|
665 if( aErrorCode == KErrNone ) |
|
666 { |
|
667 RUBY_DEBUG1( "CNssContactHandlerImplementation::DeleteTagCompleted. Assert iState == ECHHandlingNormalChanges. iState [%d]", iState); |
|
668 RUBY_ASSERT_DEBUG( iState == ECHHandlingNormalChanges, User::Panic( KFile, __LINE__ ) ); |
|
669 } |
|
670 else |
|
671 { |
|
672 RUBY_DEBUG0( "CNssContactHandlerImplementation::DeleteTagCompleted: tag deletion failed" ); |
|
673 |
|
674 iNormalChangesError = aErrorCode; |
|
675 } |
|
676 |
|
677 DoRemoveNamesAfterDeleteTagCompleted(); |
|
678 } |
|
679 |
|
680 // ----------------------------------------------------------------- |
|
681 // CNssContactHandlerImplementation::GetTagCompleted |
|
682 // Called by tag manager when getting of a tag list completes |
|
683 // ----------------------------------------------------------------- |
|
684 // |
|
685 void CNssContactHandlerImplementation::GetTagListCompleted( |
|
686 MNssTagListArray* aTagList, TInt aErrorCode ) |
|
687 { |
|
688 if( aErrorCode == KErrNone ) |
|
689 { |
|
690 if ( iState == ECHHandlingNormalChanges ) |
|
691 { |
|
692 DoRemoveNamesAfterGetTagList( aTagList ); |
|
693 } |
|
694 else |
|
695 { |
|
696 RUBY_DEBUG1( "CNssContactHandlerImplementation::GetTagListCompleted : Unknown state(%d)\n", iState ); |
|
697 } |
|
698 } |
|
699 else |
|
700 { |
|
701 RUBY_DEBUG1( "CNssContactHandlerImplementation::GetTagListCompleted. Error [%d]", aErrorCode ); |
|
702 |
|
703 TRAPD( err, DoHandleEventFailedL() ); // Process the event fail |
|
704 if ( err != KErrNone ) |
|
705 { |
|
706 RUBY_ERROR1( "CNssContactHandlerImplementation::GetTagFailed. Error [%d] in DoHandleEventFailedL", err ); |
|
707 } |
|
708 } |
|
709 } |
|
710 |
|
711 |
|
712 // --------------------------------------------------------- |
|
713 // CNssContactHandlerImplementation::DisableEventHandling |
|
714 // Disables the event handling. Is used in case of unrecoverable error |
|
715 // --------------------------------------------------------- |
|
716 // |
|
717 void CNssContactHandlerImplementation::DisableEventHandling() |
|
718 { |
|
719 RUBY_DEBUG0( "CNssContactHandlerImplementation::DisableEventHandling" ); |
|
720 iHandlerEnabled = EFalse; |
|
721 } |
|
722 |
|
723 // --------------------------------------------------------- |
|
724 // CNssContactHandlerImplementation::EnableEventHandling |
|
725 // Enables event handling |
|
726 //--------------------------------------------------------- |
|
727 // |
|
728 void CNssContactHandlerImplementation::EnableEventHandling() |
|
729 { |
|
730 RUBY_DEBUG0( "CNssContactHandlerImplementation::EnableEventHandling" ); |
|
731 iHandlerEnabled = ETrue; |
|
732 } |
|
733 |
|
734 |
|
735 // --------------------------------------------------------- |
|
736 // CNssContactHandlerImplementation::GetContextListCompleted |
|
737 // Called by tag manager when GetContextList() completes successfully |
|
738 //--------------------------------------------------------- |
|
739 // |
|
740 void CNssContactHandlerImplementation::GetContextListCompleted( |
|
741 MNssContextListArray* /*aContextList*/, TInt /*aErrorCode*/ ) |
|
742 { |
|
743 RUBY_ERROR0( "CNssContactHandlerImplementation::GetContextListCompleted - this function should never be called." ); |
|
744 } |
|
745 |
|
746 // --------------------------------------------------------- |
|
747 // CNssContactHandlerImplementation::CheckErrorSigns |
|
748 // Compares client data (saved in VAS context) |
|
749 // to state of the phonebook to find out if |
|
750 // full synchronization is needed. |
|
751 // |
|
752 // If full resync is needed initiates it by saving into the event queue |
|
753 // special 'full resync event' |
|
754 //--------------------------------------------------------- |
|
755 // |
|
756 void CNssContactHandlerImplementation::CheckErrorSigns() |
|
757 { |
|
758 |
|
759 RUBY_DEBUG0( "CNssContactHandlerImplementation::CheckErrorSigns" ); |
|
760 TBool errorFound( EFalse ); |
|
761 // Full resync, if this is the first time we launch. |
|
762 // if the UI language has changed. |
|
763 // if VAS Db and Contact Db time stamps do not match |
|
764 if ( iClientData.iLanguage == ELangNone || |
|
765 iClientData.iLanguage != User::Language() ) |
|
766 { |
|
767 RUBY_DEBUG0( "CNssContactHandlerImplementation::CheckErrorSigns language changed." ); |
|
768 errorFound = ETrue; |
|
769 } |
|
770 else |
|
771 { |
|
772 // check that is full resyncronization needed |
|
773 iRepository->Get( KSRSFFullResyncNeeded, errorFound ); |
|
774 } |
|
775 |
|
776 if ( errorFound ) |
|
777 { |
|
778 TPhonebookEvent event; |
|
779 event.iType = ENullEvent; |
|
780 event.iContactId = 0; |
|
781 |
|
782 if ( iEventArray.Append( event ) != KErrNone ) |
|
783 { |
|
784 RUBY_ERROR0( "CNssContactHandlerImplementation::CheckErrorSigns Failed to append to iEventArray" ); |
|
785 } |
|
786 } |
|
787 |
|
788 } |
|
789 |
|
790 // --------------------------------------------------------- |
|
791 // CNssContactHandlerImplementation::GetContextCompleted |
|
792 // Called by tag manager, when GetContext() completes successfully |
|
793 // |
|
794 // Depending on the contact handler state, continues full resync sequence or |
|
795 // sets the idle state |
|
796 //--------------------------------------------------------- |
|
797 // |
|
798 void CNssContactHandlerImplementation::GetContextCompleted( |
|
799 MNssContext* aContext, TInt aErrorCode ) |
|
800 { |
|
801 if( aErrorCode == KErrNone ) |
|
802 { |
|
803 RUBY_ASSERT_DEBUG( iState == ECHInitializing || iState == ECHFullResync, |
|
804 User::Panic( KFile, __LINE__ ) ); |
|
805 |
|
806 RUBY_DEBUG0( "CNssContactHandlerImplementation::GetContextCompleted" ); |
|
807 iContext = aContext; |
|
808 TRAPD(err, |
|
809 |
|
810 iClientData.InternalizeL( iContext->ClientData() ); |
|
811 |
|
812 if ( iState == ECHInitializing ) |
|
813 { |
|
814 // If there are warning sings of error, |
|
815 // do full resynchronization. |
|
816 CheckErrorSigns(); |
|
817 |
|
818 SetState( ECHIdle ); |
|
819 RUBY_DEBUG0( "CNssContactHandlerImplementation::GetContextCompleted. Setting iState to ECHIdle" ); |
|
820 |
|
821 if ( iEventArray.Count() ) // Verify whether more events in the queue |
|
822 { |
|
823 |
|
824 RUBY_DEBUG1( "CNssContactHandlerImplementation::GetContextCompletedhere are still [%d] events in the queue. Call DoHandleEvents for them", iEventArray.Count() ); |
|
825 |
|
826 DoHandleEventsL(); // Process the 1st new event from the queue |
|
827 } |
|
828 } |
|
829 else if ( iState == ECHFullResync ) |
|
830 { |
|
831 TRAPD( error, FullResyncCreateChangesL() ); |
|
832 if( error != KErrNone ) |
|
833 { |
|
834 RUBY_ERROR1( "FullResyncCreateChangesL failed with [%d]. Panic, nothing can be done", error ); |
|
835 RUBY_ASSERT_DEBUG( EFalse, User::Panic( KFile, __LINE__ ) ); |
|
836 } |
|
837 } |
|
838 else |
|
839 { |
|
840 RUBY_ERROR0( "CNssContactHandlerImplementation::GetContextCompleted Unexpected state" ); |
|
841 RUBY_ASSERT_DEBUG( EFalse, User::Panic( KFile, __LINE__ ) ); |
|
842 } |
|
843 ); // TRAPD |
|
844 if( err != KErrNone ) |
|
845 { |
|
846 RUBY_ERROR1( "CNssContactHandlerImplementation::GetContextCompleted Leaves with [%d] inside", err ); |
|
847 } |
|
848 RUBY_DEBUG0( "CNssContactHandlerImplementation::GetContextCompleted completed" ); |
|
849 } |
|
850 |
|
851 else // aErrorCode != KErrNone |
|
852 { |
|
853 RUBY_ASSERT_DEBUG( iState == ECHInitializing || iState == ECHFullResync, |
|
854 User::Panic( KFile, __LINE__ ) ); |
|
855 |
|
856 if ( iState == ECHInitializing ) |
|
857 { |
|
858 iHaveWeEverSynced = EFalse; |
|
859 SetState ( ECHFullResync ); |
|
860 FullResyncStart(); |
|
861 } |
|
862 } |
|
863 |
|
864 } |
|
865 |
|
866 // --------------------------------------------------------- |
|
867 // CNssContactHandlerImplementation::SaveContextCompleted |
|
868 // Called when SaveContext() completes successfully |
|
869 //--------------------------------------------------------- |
|
870 // |
|
871 void CNssContactHandlerImplementation::SaveContextCompleted( TInt aErrorCode ) |
|
872 { |
|
873 if( aErrorCode == KErrNone ) |
|
874 { |
|
875 RUBY_ASSERT_DEBUG( iState == ECHInitializing || |
|
876 iState == ECHFullResync, |
|
877 User::Panic( KFile, __LINE__ ) ); |
|
878 |
|
879 iHaveWeEverSynced = ETrue; |
|
880 |
|
881 if ( iState == ECHInitializing ) |
|
882 { |
|
883 // Retrive the Context to get the new ContextId from VasDB |
|
884 iContextManager->GetContext( this, KNssCHNameDialContext ); |
|
885 } |
|
886 else if ( iState == ECHFullResync ) |
|
887 { |
|
888 TRAPD( error, FullResyncCreateChangesL() ); |
|
889 if ( error != KErrNone ) |
|
890 { |
|
891 RUBY_ERROR1( "SaveContextCompleted Failed to create full resync changes. Critical error [%d]", |
|
892 error ); |
|
893 DisableEventHandling(); |
|
894 } // if error != KErrNone |
|
895 } // else if ( iState == ECHFullResync ) |
|
896 else |
|
897 { |
|
898 // we should never be here, because the condition is checked |
|
899 // by ASSERT_DEBUG at the start of the function |
|
900 RUBY_ERROR0( "CNssContactHandlerImplementation::SaveContextCompleted Unexpected state!" ); |
|
901 } |
|
902 } |
|
903 |
|
904 else // aErrorCode != KErrNone |
|
905 { |
|
906 // Failed to initialize will collect the events forever and will never process them |
|
907 // Will try to initialize again after reboot |
|
908 RUBY_ERROR0( "CNssContactHandlerImplementation::SaveContextCompleted failed. Staying forever in ECHFullResync" ); |
|
909 RUBY_ERROR0( "CNssContactHandlerImplementation::SaveContextCompleted failed. Reboot to try initializing again" ); |
|
910 DisableEventHandling(); |
|
911 } |
|
912 } |
|
913 |
|
914 // --------------------------------------------------------- |
|
915 // CNssContactHandlerImplementation::SaveTagCompleted |
|
916 // Called when SaveTag() completes |
|
917 //--------------------------------------------------------- |
|
918 // |
|
919 void CNssContactHandlerImplementation::SaveTagCompleted( TInt aErrorCode ) |
|
920 { |
|
921 RUBY_ASSERT_DEBUG( iState == ECHHandlingNormalChanges, User::Panic( KFile, __LINE__ ) ); |
|
922 |
|
923 DoAddNamesSaveTagCompleted( aErrorCode ); |
|
924 } |
|
925 |
|
926 // --------------------------------------------------------- |
|
927 // CNssContactHandlerImplementation::GetContactTitleL |
|
928 // Populates aTitle with either "FirstName LastName" or "CompanyName". |
|
929 // "CompanyName" is given only if both First and Last names are missing. |
|
930 //--------------------------------------------------------- |
|
931 // |
|
932 HBufC* CNssContactHandlerImplementation::GetContactTitleL( TContactItemId aContactId, |
|
933 TBool aUseDefaultOrder, |
|
934 TBool& aBothFirstAndLastFound, |
|
935 TVasTagType& aTagType ) |
|
936 { |
|
937 RUBY_DEBUG_BLOCKL( "CNssContactHandlerImplementation::GetContactTitleL" ); |
|
938 // Find out if lastname-firstname should be used |
|
939 TBool useLastFirstOrder = EFalse; |
|
940 |
|
941 // By default, this function returns firstname and/or lastname |
|
942 aTagType = ETagTypeName; |
|
943 |
|
944 if ( aUseDefaultOrder ) |
|
945 { |
|
946 useLastFirstOrder = SwapNameOrder(); |
|
947 } |
|
948 else |
|
949 { |
|
950 useLastFirstOrder = !SwapNameOrder(); |
|
951 } |
|
952 WaitUntilNoSyncBackupIsRunning(); |
|
953 ReadContactL( aContactId ); |
|
954 |
|
955 HBufC* firstNameText = NULL; |
|
956 HBufC* lastNameText = NULL; |
|
957 HBufC* companyNameText = NULL; |
|
958 |
|
959 TInt firstLength( 0 ); |
|
960 TInt lastLength( 0 ); |
|
961 TInt companyLength( 0 ); |
|
962 |
|
963 TInt error = KErrNone; |
|
964 |
|
965 // name reading fields are used in Japanese |
|
966 TRAP( error, iPbkHandler->FindFieldL( EPbkFieldIdFirstNameReading ) ); |
|
967 if ( error == KErrNotFound ) |
|
968 { |
|
969 // not found |
|
970 TRAP( error, iPbkHandler->FindFieldL( EPbkFieldIdFirstName ) ); |
|
971 } |
|
972 |
|
973 if ( error == KErrNone ) |
|
974 { |
|
975 firstNameText = iPbkHandler->TextL().AllocLC(); |
|
976 TrimName( firstNameText ); |
|
977 firstLength = firstNameText->Length(); |
|
978 if ( firstLength == 0 ) |
|
979 { |
|
980 CleanupStack::PopAndDestroy( firstNameText ); |
|
981 firstNameText = NULL; |
|
982 } |
|
983 } |
|
984 |
|
985 TRAP( error, iPbkHandler->FindFieldL( EPbkFieldIdLastNameReading ) ); |
|
986 if ( error == KErrNotFound ) |
|
987 { |
|
988 // not found |
|
989 TRAP( error, iPbkHandler->FindFieldL( EPbkFieldIdLastName ) ); |
|
990 } |
|
991 |
|
992 if ( error == KErrNone ) |
|
993 { |
|
994 lastNameText = iPbkHandler->TextL().AllocLC(); |
|
995 TrimName( lastNameText ); |
|
996 lastLength = lastNameText->Length(); |
|
997 if ( lastLength == 0 ) |
|
998 { |
|
999 CleanupStack::PopAndDestroy( lastNameText ); |
|
1000 lastNameText = NULL; |
|
1001 } |
|
1002 } |
|
1003 |
|
1004 TRAP( error, iPbkHandler->FindFieldL( EPbkFieldIdCompanyName ) ); |
|
1005 |
|
1006 if ( error == KErrNone ) |
|
1007 { |
|
1008 companyNameText = iPbkHandler->TextL().AllocLC(); |
|
1009 TrimName( companyNameText ); |
|
1010 companyLength = companyNameText->Length(); |
|
1011 if ( companyLength == 0 ) |
|
1012 { |
|
1013 CleanupStack::PopAndDestroy( companyNameText ); |
|
1014 companyNameText = NULL; |
|
1015 } |
|
1016 } |
|
1017 |
|
1018 // Use third parameter to return a flag if both lastname and firstname are found |
|
1019 if ( ( firstLength > 0 ) && ( lastLength > 0 ) ) |
|
1020 { |
|
1021 aBothFirstAndLastFound = ETrue; |
|
1022 } |
|
1023 else |
|
1024 { |
|
1025 aBothFirstAndLastFound = EFalse; |
|
1026 } |
|
1027 |
|
1028 HBufC* title( NULL ); |
|
1029 |
|
1030 #ifdef __SIND_EXTENSIONS |
|
1031 if ( firstLength + lastLength > 0 ) |
|
1032 { |
|
1033 TInt spaceForIndexes( 0 ); |
|
1034 // Find out how much more space is needed for "training indexes" |
|
1035 if ( aBothFirstAndLastFound ) |
|
1036 { |
|
1037 spaceForIndexes = 2 * KTrainingIndexSize; |
|
1038 } |
|
1039 else |
|
1040 { |
|
1041 spaceForIndexes = KTrainingIndexSize; |
|
1042 } |
|
1043 |
|
1044 title = HBufC::NewL( firstLength + lastLength + spaceForIndexes ); |
|
1045 |
|
1046 // Check the order |
|
1047 if ( useLastFirstOrder ) |
|
1048 { |
|
1049 // Lastname-firstname |
|
1050 if ( lastNameText ) |
|
1051 { |
|
1052 AppendName( title, lastNameText ); |
|
1053 } |
|
1054 |
|
1055 if ( firstNameText ) |
|
1056 { |
|
1057 AppendName( title, firstNameText ); |
|
1058 } |
|
1059 } |
|
1060 else |
|
1061 { |
|
1062 // Firstname-lastname |
|
1063 if ( firstNameText ) |
|
1064 { |
|
1065 AppendName( title, firstNameText ); |
|
1066 } |
|
1067 |
|
1068 if ( lastNameText ) |
|
1069 { |
|
1070 AppendName( title, lastNameText ); |
|
1071 } |
|
1072 } |
|
1073 } |
|
1074 // Try company name, if the personal name fails. |
|
1075 else if ( companyLength > 0 ) |
|
1076 { |
|
1077 aTagType = ETagTypeCompanyName; |
|
1078 title = HBufC::NewL( companyLength + KTrainingIndexSize ); |
|
1079 AppendName( title, companyNameText ); |
|
1080 } |
|
1081 #else |
|
1082 // Use personal name, if there is one. |
|
1083 if ( firstLength + lastLength > 0 ) |
|
1084 { |
|
1085 title = HBufC::NewL( firstLength + 1 + lastLength ); |
|
1086 |
|
1087 // Check the order |
|
1088 if ( useLastFirstOrder ) |
|
1089 { |
|
1090 // Lastname-firstname |
|
1091 if ( lastNameText ) |
|
1092 { |
|
1093 title->Des().Append( lastNameText->Des() ); |
|
1094 |
|
1095 if ( firstNameText ) |
|
1096 { |
|
1097 // Separator marker |
|
1098 title->Des().Append( iSeparator ); |
|
1099 } |
|
1100 } |
|
1101 |
|
1102 if ( firstNameText ) |
|
1103 { |
|
1104 title->Des().Append( firstNameText->Des() ); |
|
1105 } |
|
1106 |
|
1107 |
|
1108 } |
|
1109 else |
|
1110 { |
|
1111 // Firstname-lastname |
|
1112 if ( firstNameText ) |
|
1113 { |
|
1114 title->Des().Append( firstNameText->Des() ); |
|
1115 |
|
1116 if ( lastNameText ) |
|
1117 { |
|
1118 // Separator marker |
|
1119 title->Des().Append( iSeparator ); |
|
1120 } |
|
1121 } |
|
1122 |
|
1123 if ( lastNameText ) |
|
1124 { |
|
1125 title->Des().Append( lastNameText->Des() ); |
|
1126 } |
|
1127 |
|
1128 } |
|
1129 } |
|
1130 // Try company name, if the personal name fails. |
|
1131 else if ( companyLength > 0 ) |
|
1132 { |
|
1133 aTagType = ETagTypeCompanyName; |
|
1134 title = HBufC::NewL( companyLength ); |
|
1135 title->Des().Append( companyNameText->Des() ); |
|
1136 } |
|
1137 #endif // __SIND_EXTENSIONS |
|
1138 // It is possible to make a contact without a name. |
|
1139 else |
|
1140 { |
|
1141 RUBY_DEBUG1( "CNssContactHandlerImplementation::ContactTitle: No name, ContactId=[%d]" , aContactId ); |
|
1142 } |
|
1143 |
|
1144 if ( companyNameText ) |
|
1145 { |
|
1146 CleanupStack::PopAndDestroy( companyNameText ); |
|
1147 } |
|
1148 |
|
1149 if ( lastNameText ) |
|
1150 { |
|
1151 CleanupStack::PopAndDestroy( lastNameText ); |
|
1152 } |
|
1153 |
|
1154 if ( firstNameText ) |
|
1155 { |
|
1156 CleanupStack::PopAndDestroy( firstNameText ); |
|
1157 } |
|
1158 |
|
1159 return title; |
|
1160 } |
|
1161 |
|
1162 |
|
1163 // --------------------------------------------------------- |
|
1164 // CNssContactHandlerImplementation::SwapNameOrder |
|
1165 // Returns ETrue if name order for current UI language should |
|
1166 // be lastname-firstname, EFalse otherwise |
|
1167 //--------------------------------------------------------- |
|
1168 // |
|
1169 TBool CNssContactHandlerImplementation::SwapNameOrder() |
|
1170 { |
|
1171 // Find UI language |
|
1172 TLanguage uiLanguage = User::Language(); |
|
1173 |
|
1174 if ( iSwappedLanguages.Find( uiLanguage ) == KErrNotFound ) |
|
1175 { |
|
1176 return EFalse; |
|
1177 } |
|
1178 else |
|
1179 { |
|
1180 return ETrue; |
|
1181 } |
|
1182 } |
|
1183 |
|
1184 |
|
1185 // --------------------------------------------------------- |
|
1186 // CNssContactHandlerImplementation::GetContactNicknameL |
|
1187 // Returns nickname for a given contact |
|
1188 //--------------------------------------------------------- |
|
1189 // |
|
1190 HBufC* CNssContactHandlerImplementation::GetContactNicknameL( TContactItemId aContactId ) |
|
1191 { |
|
1192 RUBY_DEBUG_BLOCKL( "CNssContactHandlerImplementation::GetContactNicknameL" ); |
|
1193 WaitUntilNoSyncBackupIsRunning(); |
|
1194 ReadContactL( aContactId ); |
|
1195 |
|
1196 // Get the nick name |
|
1197 iPbkHandler->FindFieldL( EPbkFieldIdSecondName ); |
|
1198 |
|
1199 // Get the length of the additional name. |
|
1200 TInt nickLength = iPbkHandler->TextL().Length(); |
|
1201 |
|
1202 HBufC* title = NULL; |
|
1203 |
|
1204 #ifdef __SIND_EXTENSIONS |
|
1205 // Use personal name, if there is one. |
|
1206 if ( nickLength > 0 ) |
|
1207 { |
|
1208 title = HBufC::NewL( nickLength + KTrainingIndexSize ); |
|
1209 |
|
1210 HBufC* nickName = iPbkHandler->TextL().AllocL(); |
|
1211 TrimName( nickName ); |
|
1212 AppendName( title, nickName ); |
|
1213 delete nickName; |
|
1214 } |
|
1215 #else |
|
1216 // Use personal name, if there is one. |
|
1217 if ( nickLength > 0 ) |
|
1218 { |
|
1219 title = HBufC::NewL( nickLength ); |
|
1220 title->Des().Append( iPbkHandler->TextL() ); |
|
1221 } |
|
1222 #endif // __SIND_EXTENSIONS |
|
1223 |
|
1224 return title; |
|
1225 } |
|
1226 |
|
1227 // --------------------------------------------------------- |
|
1228 // CNssContactHandlerImplementation::DoHandleEventFailed |
|
1229 // Routine to process when handling the contact event failed |
|
1230 //--------------------------------------------------------- |
|
1231 // |
|
1232 void CNssContactHandlerImplementation::DoHandleEventFailedL() |
|
1233 { |
|
1234 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventFailedL start" ); |
|
1235 |
|
1236 // Errors are normal if user deletes contact without a voice tag |
|
1237 // E.g. because this contact had no number |
|
1238 if( ( iDeleteTagListArray != NULL ) && ( iDeleteTagListArray->Count() > 0 ) ) |
|
1239 { |
|
1240 // simulate successful deletion, just return no tags for further deletions |
|
1241 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventFailedL Deletion failed. Simulating successful empty deletion" ); |
|
1242 iDeletionSimulator->Call(); |
|
1243 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventFailedL Called deletion simulator" ); |
|
1244 } |
|
1245 else |
|
1246 { |
|
1247 |
|
1248 // Try full resync couple of times. If still fails, stop contact handler. |
|
1249 // When the phone is booted for the next time, try resyncing again |
|
1250 if( iConsecutiveErrorFullResync < KMaxConsecutiveErrorFullResync ) |
|
1251 { |
|
1252 iConsecutiveErrorFullResync++; |
|
1253 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoHandleEventFailedL Trying full resync for the [%d] time", iConsecutiveErrorFullResync); |
|
1254 // clean structures that might be already full |
|
1255 iTagArray.ResetAndDestroy(); |
|
1256 |
|
1257 for( TInt k( 0 ); k < iContactQueue.Count(); k++ ) |
|
1258 { |
|
1259 delete iContactQueue[k].iTitle; |
|
1260 } |
|
1261 iContactQueue.Close(); |
|
1262 |
|
1263 iDelList.Close(); |
|
1264 iAddList.Close(); |
|
1265 iVoiceTagAddedList.Close(); |
|
1266 // generate full resync event |
|
1267 TPhonebookEvent event; |
|
1268 event.iType = ENullEvent; |
|
1269 event.iContactId = 0; |
|
1270 iEventArray.Insert( event, 0 ); |
|
1271 // will start full resync |
|
1272 iTagArray.ResetAndDestroy(); |
|
1273 iSaveCallbackCounter = 0; // simulate completed action |
|
1274 RUBY_DEBUG0( "DoHandleEventFailedL No leaving in the FullResync branch, retrying" ); |
|
1275 DoHandleEventsL(); // No leaving in the FullResync branch |
|
1276 } |
|
1277 else |
|
1278 { |
|
1279 RUBY_ERROR1( "CNssContactHandlerImplementation::DoHandleEventFailedL Tried full resync for %d times. Disabling contact handler until reboot", KMaxConsecutiveErrorFullResync ); |
|
1280 // Tried several consecutive resyncs, didn't help |
|
1281 // Disable itself until reboot |
|
1282 DisableEventHandling(); |
|
1283 } |
|
1284 } // if deletion else |
|
1285 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoHandleEventFailedL end" ); |
|
1286 } |
|
1287 |
|
1288 // --------------------------------------------------------- |
|
1289 // CNssContactHandlerImplementation::PhonebookOrder |
|
1290 // TLinearOrder comparison function for sorting phonebook events |
|
1291 // according to their Phonebook ID. |
|
1292 //--------------------------------------------------------- |
|
1293 // |
|
1294 TInt CNssContactHandlerImplementation::PhonebookOrder( const TPhonebookEvent& a1, const TPhonebookEvent& a2 ) |
|
1295 { |
|
1296 if ( a1.iContactId != a2.iContactId ) |
|
1297 { |
|
1298 return( a1.iContactId - a2.iContactId ); |
|
1299 } |
|
1300 |
|
1301 if ( a1.iTime < a2.iTime ) |
|
1302 { |
|
1303 return( -1 ); |
|
1304 } |
|
1305 else if ( a1.iTime > a2.iTime ) |
|
1306 { |
|
1307 return( 1 ); |
|
1308 } |
|
1309 else{ |
|
1310 return( 0 ); |
|
1311 } |
|
1312 } |
|
1313 |
|
1314 // --------------------------------------------------------- |
|
1315 // CNssContactHandlerImplementation::IsFullResyncNeeded |
|
1316 // Checks if the event queue contains an event, which |
|
1317 // launches full resynchronization. If it does, there is |
|
1318 // no point in processing the other events. |
|
1319 // --------------------------------------------------------- |
|
1320 // |
|
1321 TBool CNssContactHandlerImplementation::IsFullResyncNeeded() |
|
1322 { |
|
1323 for( TInt k( 0 ); k < iEventArray.Count(); k++ ) |
|
1324 { |
|
1325 // Null event is used inside contact handler to signal full resync. |
|
1326 if ( iEventArray[k].iType == ENullEvent |
|
1327 || iEventArray[k].iType == EStoreBackupRestoreCompleted |
|
1328 || iEventArray[k].iType == EUnknownChanges ) |
|
1329 { |
|
1330 return ETrue; |
|
1331 } |
|
1332 } |
|
1333 |
|
1334 return EFalse; |
|
1335 } |
|
1336 |
|
1337 // --------------------------------------------------------- |
|
1338 // CNssContactHandlerImplementation::CollectAddRemoveListsL |
|
1339 // Given a list of Contact DB Events, this function compiles |
|
1340 // a list of ids to-be-deleted and ids to-be-added. |
|
1341 // A Contact DB Event contains: |
|
1342 // * Contact ID |
|
1343 // * Event type (added, modified, removed) |
|
1344 // --------------------------------------------------------- |
|
1345 // |
|
1346 void CNssContactHandlerImplementation::CollectAddRemoveListsL() |
|
1347 { |
|
1348 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::CollectAddRemoveListsL" ); |
|
1349 RUBY_DEBUG1( "CNssContactHandlerImplementation::CollectAddRemoveListsL(). iEventArray.Count [%d]", iEventArray.Count() ); |
|
1350 TInt k( 0 ); |
|
1351 |
|
1352 RUBY_ASSERT_DEBUG( iAddList.Count() == 0, User::Panic( KFile, __LINE__ ) ); |
|
1353 RUBY_ASSERT_DEBUG( iDelList.Count() == 0, User::Panic( KFile, __LINE__ ) ); |
|
1354 |
|
1355 // We collect two lists: |
|
1356 // * Contacts to be deleted. |
|
1357 // * Contacts to be added. |
|
1358 |
|
1359 TLinearOrder<TPhonebookEvent> order( PhonebookOrder ); |
|
1360 |
|
1361 // Sort events according to the phonebook ID. This way, the events |
|
1362 // modifying the same name are sequentially. |
|
1363 iEventArray.Sort( order ); |
|
1364 |
|
1365 |
|
1366 // If several events happen for the same contact, fuse them into one event. |
|
1367 for ( k = 0; k < iEventArray.Count() - 1; k++ ) |
|
1368 { |
|
1369 if ( iEventArray[k].iContactId == iEventArray[k+1].iContactId ) |
|
1370 { |
|
1371 // Sorting should have preserved the order of the events |
|
1372 RUBY_ASSERT_DEBUG(iEventArray[k+1].iTime >= iEventArray[k].iTime, User::Panic( KFile, __LINE__ ) ); |
|
1373 RUBY_DEBUG1( "CNssContactHandlerImplementation::CollectAddRemoveListsL(). Fusing events for ContactId [%d]", iEventArray[k].iContactId ); |
|
1374 iEventArray[k+1].iType = EContactChanged; |
|
1375 iEventArray.Remove( k ); |
|
1376 |
|
1377 // We have removed an element |
|
1378 k--; |
|
1379 } |
|
1380 } |
|
1381 |
|
1382 RUBY_DEBUG1( "CNssContactHandlerImplementation::CollectAddRemoveListsL(). Events sorted and fused iEventArray.Count [%d]", iEventArray.Count() ); |
|
1383 |
|
1384 for( k = 0; k < iEventArray.Count() && k < KMaxNamesAtOnce; k++ ) |
|
1385 { |
|
1386 TPhonebookEvent* event = &iEventArray[k]; |
|
1387 |
|
1388 switch ( event->iType ) |
|
1389 { |
|
1390 case EContactChanged: |
|
1391 { |
|
1392 // events caused by saving voice tag field are skipped |
|
1393 // earlier, in HandleDatabaseEventL |
|
1394 |
|
1395 // We need to delete the old name |
|
1396 User::LeaveIfError( iDelList.Append( *event ) ); |
|
1397 // and after that, add the new name. |
|
1398 User::LeaveIfError( iAddList.Append( *event ) ); |
|
1399 break; |
|
1400 } |
|
1401 case EContactDeleted: |
|
1402 { |
|
1403 User::LeaveIfError( iDelList.Append( *event ) ); |
|
1404 break; |
|
1405 } |
|
1406 case EContactAdded: |
|
1407 { |
|
1408 User::LeaveIfError( iAddList.Append( *event ) ); |
|
1409 break; |
|
1410 } |
|
1411 default: |
|
1412 RUBY_ERROR1( "CNssContactHandlerImplementation::CollectAddRemoveListsL() Unkown event type: %d", event->iType ); |
|
1413 break; |
|
1414 } |
|
1415 } |
|
1416 |
|
1417 if ( k < KMaxNamesAtOnce ) |
|
1418 { |
|
1419 iEventArray.Close(); |
|
1420 } |
|
1421 else |
|
1422 { |
|
1423 RUBY_DEBUG1( "CNssContactHandlerImplementation::CollectAddRemoveListsL(). k >= KMaxNamesAtOnce [%d]. Deleting first KMaxNamesAtOnce events, they've been sorted into corresponding lists already", |
|
1424 KMaxNamesAtOnce); |
|
1425 for ( k = 0; k < KMaxNamesAtOnce; k++ ) |
|
1426 { |
|
1427 iEventArray.Remove(0); |
|
1428 } |
|
1429 } |
|
1430 RUBY_DEBUG1( "CNssContactHandlerImplementation::CollectAddRemoveListsL() iEventArray.Count [%d]", |
|
1431 iEventArray.Count()); |
|
1432 RUBY_DEBUG2( "CNssContactHandlerImplementation::CollectAddRemoveListsL iDelList.Count() [%d], iAddList.Count() [%d]", iDelList.Count(), iAddList.Count()); |
|
1433 } |
|
1434 |
|
1435 // --------------------------------------------------------- |
|
1436 // CNssContactHandlerImplementation::DoRemoveNamesL |
|
1437 // Starts name removal sequence |
|
1438 // --------------------------------------------------------- |
|
1439 // |
|
1440 void CNssContactHandlerImplementation::DoRemoveNamesL() |
|
1441 { |
|
1442 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::DoRemoveNamesL" ); |
|
1443 if ( iDelList.Count() == 0 ) |
|
1444 { |
|
1445 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesL Nothing to delete - skipping" ); |
|
1446 |
|
1447 RemovingNamesCompletedL(); |
|
1448 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesL completed early <= nothing to remove" ); |
|
1449 return; |
|
1450 } |
|
1451 |
|
1452 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesL - removing" ); |
|
1453 |
|
1454 // we have: a list of tag IDs, which should be removed |
|
1455 // we need: a list of tags, which should be removed. |
|
1456 |
|
1457 // First, we get the tags which correspond to the tag ids. |
|
1458 // We need k async calls to VAS, |
|
1459 // where k is the number of tag ids in iDelList. |
|
1460 // We get a list of k' tags, where k' >= k. |
|
1461 // If some tag has both proper name and a nickname, then k' > k. |
|
1462 |
|
1463 iContactId = iDelList[0].iContactId; |
|
1464 |
|
1465 if ( iDeleteTagListArray ) |
|
1466 { |
|
1467 iDeleteTagListArray->ResetAndDestroy(); |
|
1468 } |
|
1469 else |
|
1470 { |
|
1471 iDeleteTagListArray = new (ELeave) CArrayPtrFlat<MNssTag>(50); |
|
1472 } |
|
1473 |
|
1474 TInt retCode = iTagManager->GetTagList( this, iContext, iContactId, 0 ); |
|
1475 |
|
1476 if ( retCode != KErrNone ) |
|
1477 { |
|
1478 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesL failed to GetTagList" ); |
|
1479 // In the case of change event, try to add names even though they are not found |
|
1480 // Might happen in scenario like this: |
|
1481 // 1. User adds a name without any phone number -> no voice tag is created |
|
1482 // 2. Contact is modified by adding a phone number |
|
1483 iDelList.Close(); |
|
1484 DoAddNamesL(); |
|
1485 } |
|
1486 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesL completed" ); |
|
1487 } |
|
1488 |
|
1489 // --------------------------------------------------------- |
|
1490 // CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList |
|
1491 // If contact database announces that n contacts need to be |
|
1492 // deleted, we do n calls to GetTagList (the first is from DoRemoveNamesL). |
|
1493 // Each callback returns 1 or more tags (name + nickname = 2 tags). |
|
1494 // This function processes the callbacks by adding the tags to the |
|
1495 // to-be-deleted list. |
|
1496 // --------------------------------------------------------- |
|
1497 // |
|
1498 void CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList( MNssTagListArray* aTagList ) |
|
1499 { |
|
1500 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList. iState [%d]", iState ); |
|
1501 |
|
1502 if ( iDelList.Count() == 0 ) |
|
1503 { |
|
1504 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList iDelList.Count() == 0" ); |
|
1505 } |
|
1506 |
|
1507 // Sieve out "false" tags: Those which have a wrong contact ID. |
|
1508 /** Why? Maybe user was fast enough to delete these contacts from the phonebook |
|
1509 * Anyway, why should we keep "false" tags in our db? |
|
1510 */ |
|
1511 for ( TInt i=0; i < aTagList->Count(); i++ ) |
|
1512 { |
|
1513 CArrayFixFlat<TInt>* intArray = aTagList->At(i)->RRD()->IntArray(); |
|
1514 |
|
1515 RUBY_ASSERT_DEBUG( intArray->Count() > 0, User::Panic( KFile, __LINE__ ) ); |
|
1516 |
|
1517 if ( intArray->At(0) != iContactId ) |
|
1518 { |
|
1519 RUBY_ERROR2( "DoRemoveNamesAfterGetTagList expected contact id %d, but got contact id: %d", iContactId, intArray->At(0) ); |
|
1520 delete aTagList->At( i ); |
|
1521 aTagList->Delete( i ); |
|
1522 } |
|
1523 } |
|
1524 |
|
1525 TRAPD( err, // trapping is a fix to make the function non-leaving |
|
1526 |
|
1527 // Add the tags to the to-be-deleted list. |
|
1528 // (there are 1 or 2 tags in aTagList depending on |
|
1529 // whether nickname is also there or not) |
|
1530 for ( TInt k( 0 ); k < aTagList->Count(); k++ ) |
|
1531 { |
|
1532 iDeleteTagListArray->AppendL( (*aTagList)[k] ); |
|
1533 } |
|
1534 |
|
1535 // We have processed this ID |
|
1536 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList Before removal. iDelList.Count [%d]", iDelList.Count() ); |
|
1537 if( iDelList.Count() > 0 ) |
|
1538 { |
|
1539 iDelList.Remove( 0 ); |
|
1540 } |
|
1541 else |
|
1542 { |
|
1543 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList Empty iDelList!" ); |
|
1544 } |
|
1545 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList After removal. iDelList.Count [%d]", iDelList.Count() ); |
|
1546 |
|
1547 // If there are still more IDs, convert the next ID into a tag. |
|
1548 if ( iDelList.Count() > 0 ) |
|
1549 { |
|
1550 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList There are [%d] contacts to delete. Calling GetTagList for them", iDelList.Count() ); |
|
1551 iContactId = iDelList[0].iContactId; |
|
1552 |
|
1553 TInt retCode |
|
1554 = iTagManager->GetTagList( this, iContext, iContactId, 0 ); |
|
1555 |
|
1556 if ( retCode != KErrNone ) |
|
1557 { |
|
1558 RUBY_DEBUG0( "DoRemoveNamesAfterGetTagList Failed to GetTagList, going to DoHandleEventFailedL" ); |
|
1559 TRAP_IGNORE( DoHandleEventFailedL() ); // to handle the process event failed |
|
1560 /** @todo reengineer into single return path */ |
|
1561 // Destroy tag list |
|
1562 aTagList->Reset(); |
|
1563 delete aTagList; |
|
1564 aTagList = 0; |
|
1565 return; |
|
1566 } |
|
1567 } |
|
1568 |
|
1569 // If we just finished converting the last ID, move to the next phase. |
|
1570 else{ |
|
1571 RUBY_DEBUG0( "DoRemoveNamesAfterGetTagList Moving to the next phase" ); |
|
1572 DoRemoveNamesCallDeleteTag(); |
|
1573 } |
|
1574 ); // TRAPD |
|
1575 if( err != KErrNone ) |
|
1576 { |
|
1577 RUBY_ERROR1( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList Leaves with [%d] inside", err ); |
|
1578 } |
|
1579 // Destroy tag list |
|
1580 aTagList->Reset(); |
|
1581 delete aTagList; |
|
1582 aTagList = 0; |
|
1583 } |
|
1584 |
|
1585 // --------------------------------------------------------- |
|
1586 // CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag |
|
1587 // Sends the DeleteTag() calls to lower layers when removing names. |
|
1588 // --------------------------------------------------------- |
|
1589 // |
|
1590 void CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag() |
|
1591 { |
|
1592 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag. iDeleteTagListArray->Count() [%d] Setting iDeleteCallbackCounter = 0", |
|
1593 iDeleteTagListArray->Count() ); |
|
1594 |
|
1595 if( iDeleteTagListArray->Count() > 0 ) |
|
1596 { |
|
1597 |
|
1598 iDeleteCallbackCounter = 0; |
|
1599 |
|
1600 for ( TInt k( 0 ); k < iDeleteTagListArray->Count(); k++ ) |
|
1601 { |
|
1602 TInt ret = |
|
1603 iTagManager->DeleteTag( this, (*iDeleteTagListArray)[k] ); |
|
1604 |
|
1605 if ( ret != KErrNone ) |
|
1606 { |
|
1607 TRAPD( err, DoHandleEventFailedL(); ); |
|
1608 if( err != KErrNone ) |
|
1609 { |
|
1610 RUBY_ERROR1( "CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag Error handling Left with [%d]", err ); |
|
1611 } |
|
1612 return; /** @todo reengineer into single return path */ |
|
1613 } |
|
1614 } |
|
1615 } // if there are tags to delete |
|
1616 else |
|
1617 { |
|
1618 // if there were no tags to delete (attempt to delete non-existing tags) |
|
1619 // simulating callback from successful deletion of.. 0 tags |
|
1620 //iDeleteCallbackCounter = -1; |
|
1621 //DeleteTagCompleted(); |
|
1622 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag Here!" ); |
|
1623 } |
|
1624 } |
|
1625 |
|
1626 // --------------------------------------------------------- |
|
1627 // CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted |
|
1628 // DeleteTag() callback calls this funciton. It counts |
|
1629 // the number of callbacks, and when all callbacks have arrived, |
|
1630 // goes to the next phase. |
|
1631 // --------------------------------------------------------- |
|
1632 // |
|
1633 void CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted() |
|
1634 { |
|
1635 iDeleteCallbackCounter++; |
|
1636 |
|
1637 RUBY_DEBUG2( "CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted. iDeleteCallbackCounter [%d], Count() [%d]", iDeleteCallbackCounter, iDeleteTagListArray->Count() ); |
|
1638 |
|
1639 if ( iDeleteCallbackCounter == iDeleteTagListArray->Count() ) |
|
1640 { |
|
1641 if( iNormalChangesError == KErrNone ) |
|
1642 { |
|
1643 TRAPD( err, RemovingNamesCompletedL() ); |
|
1644 if ( err != KErrNone ) |
|
1645 { |
|
1646 RUBY_ERROR1( "CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted. Error [%d] in RemovingNamesCompletedL", err ); |
|
1647 } |
|
1648 } |
|
1649 else |
|
1650 { |
|
1651 // There is not much we can do about the deletion error |
|
1652 // Retrying deletion can cause endless cycle |
|
1653 // Sometimes failed deletions are ok (if we tried to delete non-existing tag) |
|
1654 /** @todo reengineer SpeechItemTrainer (and/or SRS plugin) to report deletion |
|
1655 of non-existing tag as success. After all they are not in the DB */ |
|
1656 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted Deletion failed. Still simulating a successful one" ); |
|
1657 TRAPD( err, RemovingNamesCompletedL() ); |
|
1658 if ( err != KErrNone ) |
|
1659 { |
|
1660 RUBY_ERROR1( "CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted. Error [%d] in RemovingNamesCompletedL", err ); |
|
1661 } |
|
1662 } // if (iNormalChangesError == KErrNone) else |
|
1663 } // if count |
|
1664 } |
|
1665 |
|
1666 // --------------------------------------------------------- |
|
1667 // CNssContactHandlerImplementation::RemovingNamesCompletedL |
|
1668 // Cleans up after some names have been removed |
|
1669 // --------------------------------------------------------- |
|
1670 // |
|
1671 void CNssContactHandlerImplementation::RemovingNamesCompletedL() |
|
1672 { |
|
1673 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::RemovingNamesCompletedL" ); |
|
1674 iDelList.Close(); |
|
1675 |
|
1676 if ( iDeleteTagListArray ) |
|
1677 { |
|
1678 iDeleteTagListArray->ResetAndDestroy(); |
|
1679 iDeleteCallbackCounter = 0; |
|
1680 } |
|
1681 |
|
1682 DoAddNamesL(); |
|
1683 } |
|
1684 |
|
1685 // --------------------------------------------------------- |
|
1686 // CNssContactHandlerImplementation::DoAddNamesL |
|
1687 // Starts name addition sequence by fetching contacts data and ordering |
|
1688 // voice tags training |
|
1689 // --------------------------------------------------------- |
|
1690 // |
|
1691 void CNssContactHandlerImplementation::DoAddNamesL() |
|
1692 { |
|
1693 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::DoAddNamesL" ); |
|
1694 TInt k( 0 ); |
|
1695 |
|
1696 if ( iAddList.Count() == 0 ) |
|
1697 { |
|
1698 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesL Nothing to add. Setting iState = ECHIdle. Return" ); |
|
1699 SetState ( ECHIdle ); |
|
1700 // If there are events on the list, DoAddNamesCompleted will fire them |
|
1701 DoAddNamesCompletedL(); |
|
1702 } |
|
1703 else |
|
1704 { |
|
1705 // Create new tags and train them. |
|
1706 for ( k = 0; k < iAddList.Count(); k++ ) |
|
1707 { |
|
1708 // 3 names may be created from one contact: |
|
1709 // * Main name (firstname + lastname XOR companyname) |
|
1710 // * Reversed order name (usually lastname + firstname, depends on the UI language) |
|
1711 // -> only if NSSVAS_CONTACTHANDLER_FREEORDER is defined |
|
1712 // * Nickname |
|
1713 |
|
1714 TContactData contactData; |
|
1715 |
|
1716 contactData.iID = iAddList[k].iContactId; |
|
1717 contactData.iSyncTime.UniversalTime(); |
|
1718 |
|
1719 // Nickname |
|
1720 contactData.iTitle = NULL; |
|
1721 TRAPD( err, contactData.iTitle = GetContactNicknameL( iAddList[k].iContactId ) ); |
|
1722 |
|
1723 if ( contactData.iTitle != NULL ) |
|
1724 { |
|
1725 CleanupStack::PushL( contactData.iTitle ); |
|
1726 contactData.iType = ETagTypeNickName; |
|
1727 User::LeaveIfError( iContactQueue.Append( contactData ) ); |
|
1728 CleanupStack::Pop( contactData.iTitle ); |
|
1729 } |
|
1730 |
|
1731 // Main name ( Using GetContactTitleL() ) |
|
1732 contactData.iTitle = NULL; |
|
1733 TBool bothFound = EFalse; |
|
1734 TVasTagType tagType( ETagTypeUnknown ); |
|
1735 TRAP( err, contactData.iTitle = GetContactTitleL( iAddList[k].iContactId, ETrue, bothFound, tagType ) ); |
|
1736 |
|
1737 // If all the name fields are empty, nothing |
|
1738 // can be done for the tag. We're finished. |
|
1739 if ( contactData.iTitle != NULL ) |
|
1740 { |
|
1741 RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesL For Contact id [%d] title is: [%S]", iAddList[k].iContactId, contactData.iTitle ); |
|
1742 CleanupStack::PushL( contactData.iTitle ); |
|
1743 contactData.iType = tagType; |
|
1744 User::LeaveIfError( iContactQueue.Append( contactData ) ); |
|
1745 CleanupStack::Pop( contactData.iTitle ); |
|
1746 } |
|
1747 |
|
1748 #ifdef NSSVAS_CONTACTHANDLER_FREEORDER |
|
1749 // Default order added previously, now adding |
|
1750 // secondary order if both first and lastnames are found |
|
1751 if ( bothFound ) |
|
1752 { |
|
1753 contactData.iTitle = NULL; |
|
1754 TRAPD( err, contactData.iTitle = GetContactTitleL( iAddList[k].iContactId, EFalse, bothFound, tagType ) ); |
|
1755 if ( contactData.iTitle != NULL ) |
|
1756 { |
|
1757 CleanupStack::PushL( contactData.iTitle ); |
|
1758 contactData.iType = tagType; |
|
1759 User::LeaveIfError( iContactQueue.Append( contactData ) ); |
|
1760 CleanupStack::Pop( contactData.iTitle ); |
|
1761 } |
|
1762 } |
|
1763 #endif // NSSVAS_CONTACTHANDLER_FREEORDER |
|
1764 |
|
1765 } |
|
1766 |
|
1767 // No tag had any text. |
|
1768 if ( iContactQueue.Count() == 0 ) |
|
1769 { |
|
1770 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesL. No tag had any text, return" ); |
|
1771 DoAddNamesCompletedL(); |
|
1772 } |
|
1773 else |
|
1774 { |
|
1775 // At least some tag has some text |
|
1776 RUBY_ASSERT_DEBUG( iTagArray.Count() == 0, User::Panic( KFile, __LINE__ ) ); |
|
1777 |
|
1778 for ( k = 0; k < iContactQueue.Count(); k++ ) |
|
1779 { |
|
1780 // (1) Create a new tag |
|
1781 if ( iNewTag != NULL ) |
|
1782 { |
|
1783 // If previous call to this function leaves, iNewTag can |
|
1784 // be not deleted |
|
1785 delete iNewTag; |
|
1786 iNewTag = NULL; |
|
1787 } |
|
1788 iNewTag = iTagManager->CreateTagL( iContext ); |
|
1789 |
|
1790 MNssRRD* rrd = iNewTag->RRD(); |
|
1791 MNssSpeechItem* speechItem = iNewTag->SpeechItem(); |
|
1792 |
|
1793 // (2) Fill RRD. RRD contains client-chosen data about the tag. |
|
1794 // In case of name dialing, RRD contains the contact ID, |
|
1795 // which is used later to get the phone number. |
|
1796 CArrayFixFlat<TInt> *id = new (ELeave) CArrayFixFlat<TInt>( 1 ); |
|
1797 |
|
1798 CleanupStack::PushL( id ); |
|
1799 |
|
1800 id->AppendL( iContactQueue[k].iID ); // ID |
|
1801 // select a number field for voice tag |
|
1802 // TInt fieldIndex( 0 ); |
|
1803 |
|
1804 WaitUntilNoSyncBackupIsRunning(); |
|
1805 TRAPD( err, ReadContactL( iContactQueue[k].iID ); ); |
|
1806 if ( err == KErrNone ) |
|
1807 { |
|
1808 // 1. Default voice call number set by the user |
|
1809 TInt found = KErrNotFound; |
|
1810 TRAP( found, iPbkHandler->FindDefaultContactFieldL( EDefaultCommand ) ); |
|
1811 |
|
1812 if ( found == KErrNotFound ) |
|
1813 { |
|
1814 for( TInt i = 0; i < KTaggableFieldsCount; i++) |
|
1815 { |
|
1816 TRAP( found, iPbkHandler->FindFieldL( KTaggableFields[i] ) ); |
|
1817 if( found == KErrNone && ( !iPbkHandler->IsFieldEmptyL() ) ) |
|
1818 { |
|
1819 break; // found field |
|
1820 } |
|
1821 else |
|
1822 { |
|
1823 // When field->IsEmptyOrAllSpaces(), it is the same for us as no field present |
|
1824 found = KErrNotFound; |
|
1825 } |
|
1826 } // for i < KTaggableFieldsCount |
|
1827 } |
|
1828 |
|
1829 if ( found == KErrNone ) // found and is not empty |
|
1830 { |
|
1831 id->AppendL( iPbkHandler->FieldIdL() ); // field ID to array |
|
1832 id->AppendL( EDial ); |
|
1833 id->AppendL( iContactQueue[k].iType ); |
|
1834 id->AppendL( EDefaultCommand ); |
|
1835 rrd->SetIntArrayL ( id ); |
|
1836 |
|
1837 // (3) Set the training text. |
|
1838 speechItem = iNewTag->SpeechItem(); |
|
1839 speechItem->SetTextL( *iContactQueue[k].iTitle ); |
|
1840 |
|
1841 User::LeaveIfError( iTagArray.Append( iNewTag ) ); |
|
1842 // Leave protection for iNewTag completed |
|
1843 // Ownership and deletion responsibility moved |
|
1844 // to iTagArray |
|
1845 iNewTag = NULL; |
|
1846 } |
|
1847 else |
|
1848 { |
|
1849 // field not found or is empty |
|
1850 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesL Did NOT identify a suitable voice dial field for contact id [%d]", iContactQueue[k].iID); |
|
1851 |
|
1852 |
|
1853 delete iNewTag; |
|
1854 iNewTag = NULL; |
|
1855 } // if field else |
|
1856 #ifdef __SIND_EXTENSIONS |
|
1857 |
|
1858 // this part creates separate voice tags for extensions |
|
1859 for ( TInt i(0); i < iExtensionList.Count(); i++ ) |
|
1860 { |
|
1861 found = KErrNotFound; |
|
1862 TVasExtensionAction action = iExtensionList[i].iAction; |
|
1863 TPbkFieldId fieldId = iExtensionList[i].iId; |
|
1864 |
|
1865 // default message number |
|
1866 // default video |
|
1867 // default e-mail |
|
1868 // default VOIP |
|
1869 if ( action == ENewMessage || |
|
1870 iExtensionList[i].iId == EPbkFieldIdPhoneNumberVideo || |
|
1871 iExtensionList[i].iId == EPbkFieldIdEmailAddress || |
|
1872 iExtensionList[i].iId == EPbkFieldIdVOIP ) |
|
1873 { |
|
1874 // @todo Should use DefaultMessageField or something similar!! |
|
1875 TRAP( found, |
|
1876 iPbkHandler->FindDefaultContactFieldL( iExtensionList[i].iCommand ) ); |
|
1877 } |
|
1878 |
|
1879 /*if ( extensionField == NULL ) |
|
1880 { |
|
1881 extensionField = item->FindField( iExtensionList[i].iId ); |
|
1882 } |
|
1883 |
|
1884 if ( extensionField == NULL && field != NULL |
|
1885 && ( action == ENewMessage ) ) |
|
1886 { |
|
1887 // if default neither default field or mobile field was not found |
|
1888 // message use normal SIND field |
|
1889 extensionField = field; |
|
1890 fieldId = field->FieldInfo().FieldId(); |
|
1891 }*/ |
|
1892 |
|
1893 // If field was not found, try to find it based on the priority lists |
|
1894 if ( found == KErrNotFound ) |
|
1895 { |
|
1896 found = FindExtensionField( action, iExtensionList[i].iId ); |
|
1897 // If field was found, check the field ID |
|
1898 if ( found == KErrNone ) |
|
1899 { |
|
1900 fieldId = iPbkHandler->FieldIdL(); |
|
1901 } |
|
1902 } |
|
1903 |
|
1904 if ( found == KErrNone ) |
|
1905 { |
|
1906 // create new tag |
|
1907 iNewTag = iTagManager->CreateTagL( iContext ); |
|
1908 |
|
1909 rrd = iNewTag->RRD(); |
|
1910 speechItem = iNewTag->SpeechItem(); |
|
1911 |
|
1912 // set RRD data |
|
1913 CArrayFixFlat<TInt> *extIds = new (ELeave) CArrayFixFlat<TInt>( 1 ); |
|
1914 CleanupStack::PushL( extIds ); |
|
1915 |
|
1916 extIds->AppendL( iContactQueue[k].iID ); |
|
1917 extIds->AppendL( fieldId ); |
|
1918 extIds->AppendL( action ); |
|
1919 extIds->AppendL( iContactQueue[k].iType ); |
|
1920 extIds->AppendL( iExtensionList[i].iCommand ); |
|
1921 |
|
1922 rrd->SetIntArrayL ( extIds ); |
|
1923 |
|
1924 // set the training text. |
|
1925 TPtr namePtr( iContactQueue[k].iTitle->Des() ); |
|
1926 TPtr extensionPtr( iExtensionList[i].iText->Des() ); |
|
1927 HBufC* tempTitle = HBufC::NewLC( namePtr.Length() + extensionPtr.Length() + KTrainingIndexSize ); |
|
1928 TPtr titlePtr( tempTitle->Des() ); |
|
1929 |
|
1930 //not work: titlePtr.AppendFormat( extensionPtr, namePtr ); |
|
1931 |
|
1932 titlePtr = extensionPtr; |
|
1933 AppendExtensionMarker( titlePtr ); |
|
1934 TInt index = titlePtr.Find( KExtensionFormatString ); |
|
1935 if ( index >= 0 ) |
|
1936 { |
|
1937 // replace %U with name |
|
1938 titlePtr.Delete( index, 2 ); // delete %U |
|
1939 titlePtr.Insert( index, namePtr ); |
|
1940 } |
|
1941 speechItem->SetTextL( titlePtr ); |
|
1942 |
|
1943 User::LeaveIfError( iTagArray.Append( iNewTag ) ); |
|
1944 iNewTag = NULL; //ownership changed |
|
1945 CleanupStack::PopAndDestroy( tempTitle ); |
|
1946 CleanupStack::PopAndDestroy( extIds ); |
|
1947 } |
|
1948 } |
|
1949 |
|
1950 #endif // __SIND_EXTENSIONS |
|
1951 // delete id |
|
1952 CleanupStack::PopAndDestroy( id ); |
|
1953 } |
|
1954 else |
|
1955 { |
|
1956 // Opening contact failed. E.g. if it was just deleted by user |
|
1957 RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesL Failed to open contact id [%d]. Leave [%d]", iContactQueue[k].iID, err); |
|
1958 CleanupStack::PopAndDestroy( id ); |
|
1959 delete iNewTag; |
|
1960 iNewTag = NULL; |
|
1961 /** @todo Try reengineering duplicated cleanups into single piece |
|
1962 of the code */ |
|
1963 } |
|
1964 } // for k .. iContactQueue |
|
1965 |
|
1966 if ( iTagArray.Count() == 0 ) |
|
1967 { |
|
1968 // If there are events on the list, DoAddNamesCompleted will fire them |
|
1969 DoAddNamesCompletedL(); |
|
1970 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesL. Returned from DoAddNamesCompleted. Setting iState = ECHIdle" ); |
|
1971 SetState ( ECHIdle ); |
|
1972 } |
|
1973 else |
|
1974 { |
|
1975 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesL Before training tags. TagCount = [%d]", |
|
1976 iTagArray.Count() ); |
|
1977 |
|
1978 iTrainCallbackCounter = 0; |
|
1979 for ( k = 0; k < iTagArray.Count(); k++ ) |
|
1980 { |
|
1981 MNssSpeechItem* speechItem = iTagArray[k]->SpeechItem(); |
|
1982 |
|
1983 MNssSpeechItem::TNssSpeechItemResult trainRet |
|
1984 = speechItem->TrainTextL( this, iTrainingParams ); |
|
1985 |
|
1986 if ( trainRet != MNssSpeechItem::EVasErrorNone ) |
|
1987 { |
|
1988 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesL : TrainTextL call failed." ); |
|
1989 // Not much we can do except for timed retry. |
|
1990 // This stops the contact handler. |
|
1991 DoHandleEventFailedL(); |
|
1992 break; // no processing anymore. Quit function |
|
1993 } |
|
1994 } // for k < iTagArray.Count() |
|
1995 } // if iTagArrayCount != 0 |
|
1996 } |
|
1997 } // if ( iAddList.Count() != 0 ) |
|
1998 } |
|
1999 |
|
2000 // --------------------------------------------------------- |
|
2001 // CNssContactHandlerImplementation::DoAddNamesTrainingFinished |
|
2002 // Called after training of a current pack of tags has finished. |
|
2003 // Starts saving tags. |
|
2004 // --------------------------------------------------------- |
|
2005 // |
|
2006 void CNssContactHandlerImplementation::DoAddNamesTrainingFinished() |
|
2007 { |
|
2008 iSaveCallbackCounter = 0; |
|
2009 iRetry = 0; // retry, if save tag fails |
|
2010 iNormalChangesError = 0; // to record failures in save tag |
|
2011 |
|
2012 DoAddNamesSaveTag(); |
|
2013 } |
|
2014 |
|
2015 // --------------------------------------------------------- |
|
2016 // CNssContactHandlerImplementation::DoAddNamesSaveTag |
|
2017 // This function has two branches: |
|
2018 // (1) Initiate saving tags |
|
2019 // (1) After all tags have been saved, go to the next phase. |
|
2020 // --------------------------------------------------------- |
|
2021 // |
|
2022 void CNssContactHandlerImplementation::DoAddNamesSaveTag() |
|
2023 { |
|
2024 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag" ); |
|
2025 TInt retCode; |
|
2026 |
|
2027 // If all tags have been saved, go to the next phase. |
|
2028 if ( iSaveCallbackCounter == iTagArray.Count() ) |
|
2029 { |
|
2030 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag All tags have been saved, go to the next phase" ); |
|
2031 // Tags saved - go to the next phase |
|
2032 if ( iNormalChangesError == KErrNone ) |
|
2033 { |
|
2034 // This function is called once per 100 contacts -> It is ok to use TRAP |
|
2035 TRAPD( error, DoAddNamesCompletedL() ); |
|
2036 if( error != KErrNone ) |
|
2037 { |
|
2038 /** @todo Test this branch */ |
|
2039 // Some fatal error occured |
|
2040 RUBY_ERROR1( "DoAddNamesSaveTag DoAddNamesCompletedL failed with [%d]. Disabling SIND", |
|
2041 error ); |
|
2042 DisableEventHandling(); |
|
2043 } |
|
2044 } |
|
2045 else |
|
2046 { |
|
2047 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag Saving tags failed. Try again a few times" ); |
|
2048 // Saving tags failed. Try again a few times, and if it still |
|
2049 // doesn't work, go to fatal error handler. |
|
2050 if ( iRetry < KVASCHMaxRetry ) |
|
2051 { |
|
2052 iRetry++; |
|
2053 RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesSaveTag Retried saving [%d] times. [%d] retries left", |
|
2054 iRetry, KVASCHMaxRetry - iRetry); |
|
2055 iSaveCallbackCounter = 0; |
|
2056 iNormalChangesError = KErrNone; |
|
2057 |
|
2058 DoAddNamesSaveTag(); |
|
2059 } |
|
2060 else |
|
2061 { |
|
2062 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesSaveTag Retried saving [%d] times. Still saving fails. Handling error", iRetry ); |
|
2063 NormalChangesHandleError(); |
|
2064 } |
|
2065 } |
|
2066 } // if ( iSaveCallbackCounter == iTagArray.Count() ) |
|
2067 |
|
2068 // If this is the first call to this function, |
|
2069 // make "save tag" calls. After that, wait for the callbacks. |
|
2070 else if ( iSaveCallbackCounter == 0 ) |
|
2071 { |
|
2072 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesSaveTag iSaveCallbackCounter == 0. Run SaveTag for [%d] contacts", |
|
2073 iTagArray.Count()); |
|
2074 for ( TInt k( 0 ); k < iTagArray.Count(); k++ ) |
|
2075 { |
|
2076 retCode = iTagManager->SaveTag( this, iTagArray[k] ); |
|
2077 |
|
2078 if ( retCode != KErrNone ) |
|
2079 { |
|
2080 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag - SaveTag failed." ); |
|
2081 TRAPD( err, DoHandleEventFailedL(); ); |
|
2082 if( err != KErrNone ) |
|
2083 { |
|
2084 RUBY_ERROR1( "CNssContactHandlerImplementation::DoAddNamesSaveTag handling error Left with [%d]", err ); |
|
2085 } |
|
2086 return; |
|
2087 } // if retCode |
|
2088 } // for iTagArray |
|
2089 } // else if iSaveCallbackCounter == 0 |
|
2090 else |
|
2091 { |
|
2092 // iSaveCallbackCounter != 0, but different from iTagArray.Count() |
|
2093 // This means, that SaveTag callbacks are still coming. We will wait for them |
|
2094 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag. iSaveCallbackCounter != 0, but different from iTagArray.Count()" ); |
|
2095 } |
|
2096 } |
|
2097 |
|
2098 // --------------------------------------------------------- |
|
2099 // CNssContactHandlerImplementation::DoAddNamesSaveTagCompleted |
|
2100 // Saving single tag has completed. |
|
2101 // --------------------------------------------------------- |
|
2102 // |
|
2103 void CNssContactHandlerImplementation::DoAddNamesSaveTagCompleted( TInt aError ) |
|
2104 { |
|
2105 iSaveCallbackCounter++; |
|
2106 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesSaveTagCompleted iSaveCallbackCounter became [%d]", |
|
2107 iSaveCallbackCounter); |
|
2108 // |= to let single KErrGeneral fail any number of KErrNone |
|
2109 iNormalChangesError |= aError; |
|
2110 |
|
2111 // Check if all tags have been saved. |
|
2112 DoAddNamesSaveTag(); |
|
2113 } |
|
2114 |
|
2115 // --------------------------------------------------------- |
|
2116 // CNssContactHandlerImplementation::DoAddNamesCompleted |
|
2117 // When adding names has successfully finished, clean up. |
|
2118 // --------------------------------------------------------- |
|
2119 // |
|
2120 void CNssContactHandlerImplementation::DoAddNamesCompletedL() |
|
2121 { |
|
2122 RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesCompleted. iDeleteCallbackCounter [%d], Count() [%d]", iDeleteCallbackCounter, iDeleteTagListArray->Count() ); |
|
2123 TInt initialDeleteTagListCount = iDeleteTagListArray->Count(); |
|
2124 |
|
2125 iSaveCallbackCounter = 0; |
|
2126 iTrainCallbackCounter = 0; |
|
2127 |
|
2128 // DoAddNamesCompleted if often called after voice tags have been added => |
|
2129 // Nothing has to be done at all |
|
2130 TBool changedDatabase = EFalse; |
|
2131 |
|
2132 #ifndef __SIND_EXTENSIONS |
|
2133 // Set VAS_SETS_VOICETAG on if old behaviour is needed. |
|
2134 // That is, VAS sets on the voice tag field to Phonebook engine and Phonebook UI checks the contacts DB for voice tags. |
|
2135 // Off means that VAS does not set voice tag field but instead Phonebook asks from VAS. |
|
2136 #ifdef VAS_SETS_VOICETAG |
|
2137 // add voice tag fields |
|
2138 // iTagArray contains only successfully trained tags. |
|
2139 // Failed items are removed. |
|
2140 for ( TInt i( 0 ); i < iTagArray.Count(); i++ ) |
|
2141 { |
|
2142 MNssRRD* rrd = iTagArray[i]->RRD(); |
|
2143 CArrayFixFlat<TInt>* intArray = rrd->IntArray(); |
|
2144 RUBY_ASSERT_DEBUG( intArray->Count() >= 2, User::Panic( KFile, __LINE__ ) ); |
|
2145 if ( intArray->Count() >= 2 ) |
|
2146 { |
|
2147 TBool committed( EFalse ); // ETrue if contact is committed already |
|
2148 TInt contactId( intArray->At( 0 ) ); |
|
2149 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesCompleted. Working on contact id [%d]", |
|
2150 contactId); |
|
2151 TInt fieldId( intArray->At( 1 ) ); |
|
2152 |
|
2153 WaitUntilNoSyncBackupIsRunning(); |
|
2154 // Open contact item based on id |
|
2155 TRAPD( errFor, |
|
2156 OpenContactL( contactId ); |
|
2157 |
|
2158 RUBY_DEBUG1( "DoAddNamesCompleted Opened contact [%d]", contactId ); |
|
2159 TInt found == KErrNotFound; |
|
2160 TRAP( found, iPbkHandler->FindDefaultContactFieldL( EDefaultCommand ) ); |
|
2161 if ( found == KErrNotFound ) |
|
2162 { |
|
2163 TRAP( found, iPbkHandler->FindFieldL( fieldId ) ); |
|
2164 } |
|
2165 // field - field, that SHOULD have voice tag attached |
|
2166 |
|
2167 if ( found == KErrNone ) |
|
2168 { |
|
2169 TRAP( error, iPbkHandler->ChangeVoiceTagFieldL( ETrue ) ); |
|
2170 if ( error == KErrNone ) |
|
2171 { |
|
2172 RUBY_DEBUG1("DoAddNamesCompleted Successfully added icon to the contact [%d]", |
|
2173 contactId); |
|
2174 iPbkHandler->CloseContactL( ETrue ); |
|
2175 RUBY_DEBUG1("DoAddNamesCompleted Successfully committed contact [%d]", |
|
2176 contactId); |
|
2177 iVoiceTagAddedList.Append( contactId ); |
|
2178 changedDatabase = ETrue; |
|
2179 committed = ETrue; |
|
2180 } |
|
2181 } |
|
2182 else |
|
2183 { |
|
2184 // field not found anymore |
|
2185 RUBY_DEBUG2("DoAddNamesCompleted Field [%d] not found in (already deleted from?) contact [%d]", |
|
2186 fieldId, contactId ); |
|
2187 iDeleteTagListArray->AppendL( NULL ); // One DeleteTag will generate one callback |
|
2188 iTagManager->DeleteTag( this, iTagArray[i] ); |
|
2189 } |
|
2190 if ( !committed ) |
|
2191 { |
|
2192 RUBY_DEBUG1("DoAddNamesCompleted Did not change contact [%d]. Closing without committing", |
|
2193 contactId); |
|
2194 iPbkHandler->CloseContactL( EFalse ); |
|
2195 } |
|
2196 ); // TRAPD errFor |
|
2197 if ( errFor != KErrNone ) |
|
2198 { |
|
2199 RUBY_DEBUG2("CNssContactHandlerImplementation::DoAddNamesCompleted Failed to add icon for contact [%d]. Error [%d]", |
|
2200 contactId, errFor); |
|
2201 // voice tag was not in the contacts database, delete it from VAS |
|
2202 // One DeleteTag will generate one callback |
|
2203 iDeleteTagListArray->AppendL( NULL ); |
|
2204 iTagManager->DeleteTag( this, iTagArray[i] ); |
|
2205 } |
|
2206 } // if intArray->Count() >= 2 |
|
2207 } // for iTagArray |
|
2208 #endif // VAS_SETS_VOICETAG |
|
2209 #endif //__SIND_EXTENSIONS |
|
2210 |
|
2211 iTagArray.ResetAndDestroy(); |
|
2212 |
|
2213 iAddList.Close(); |
|
2214 |
|
2215 #ifndef __SIND_EXTENSIONS |
|
2216 #ifdef VAS_SETS_VOICETAG |
|
2217 // Remove voice tag icons for contacts, that failed to be trained or saved |
|
2218 for( TInt l = 0 ; l < iRemoveIconList.Count(); l++ ) |
|
2219 { |
|
2220 WaitUntilNoSyncBackupIsRunning(); |
|
2221 TRAPD( error, OpenContactL( iRemoveIconList[l] ) ); |
|
2222 if ( error != KErrNone ) |
|
2223 { |
|
2224 RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to open contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2225 } |
|
2226 else |
|
2227 { |
|
2228 TRAP( error, iPbkHandler->ChangeVoiceTagFieldL( EFalse ) ); |
|
2229 if ( error == KErrNotFound ) |
|
2230 { |
|
2231 // Nothing to remove. Already no voice tag icon |
|
2232 TRAP( error, iPbkHandler->CloseContactL( EFalse ) ); |
|
2233 if ( error != KErrNone ) |
|
2234 { |
|
2235 RUBY_ERROR2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to close contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2236 } |
|
2237 } |
|
2238 else if ( error != KErrNone ) |
|
2239 { |
|
2240 RUBY_ERROR2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to remove voice tag icon for contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2241 TRAP( error, iPbkHandler->CloseContactL( EFalse ) ); |
|
2242 if ( error != KErrNone ) |
|
2243 { |
|
2244 RUBY_ERROR2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to close contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2245 } |
|
2246 } |
|
2247 else |
|
2248 { |
|
2249 iVoiceTagAddedList.Append( iRemoveIconList[l] ); |
|
2250 TRAP( error, iPbkHandler->CloseContactL( ETrue ) ); |
|
2251 if ( error != KErrNone ) |
|
2252 { |
|
2253 RUBY_ERROR2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to commit contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2254 } |
|
2255 } |
|
2256 |
|
2257 } // if opened contact successfully |
|
2258 |
|
2259 } |
|
2260 #endif // VAS_SETS_VOICETAG |
|
2261 #endif //__SIND_EXTENSIONS |
|
2262 |
|
2263 iRemoveIconList.Close(); |
|
2264 |
|
2265 for( TInt k( 0 ); k < iContactQueue.Count(); k++ ) |
|
2266 { |
|
2267 delete iContactQueue[k].iTitle; |
|
2268 iContactQueue[k].iTitle = NULL; |
|
2269 } |
|
2270 iContactQueue.Close(); |
|
2271 |
|
2272 if( changedDatabase ) |
|
2273 { |
|
2274 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted changed DBx" ); |
|
2275 WaitUntilNoSyncBackupIsRunning(); |
|
2276 TRAPD(err, iPbkHandler->CompressL() ); |
|
2277 if ( err ) |
|
2278 { |
|
2279 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesCompleted Contacts DB compression failed. Error [%d]", |
|
2280 err); |
|
2281 } |
|
2282 } |
|
2283 else |
|
2284 { |
|
2285 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted did NOT change DB" ); |
|
2286 } |
|
2287 |
|
2288 // full resyncs are always tag additions |
|
2289 if( initialDeleteTagListCount == iDeleteTagListArray->Count() ) |
|
2290 { |
|
2291 SetState( ECHIdle ); |
|
2292 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted Syncing with phonebook generated NO deletions" ); |
|
2293 // then full resync will not be initiated |
|
2294 iConsecutiveErrorFullResync = 0; |
|
2295 if ( iEventArray.Count() > 0 ) |
|
2296 { |
|
2297 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesCompleted There are still [%d] events in the queue. Call DoHandleEvents for them", |
|
2298 iEventArray.Count() ); |
|
2299 TRAPD( err, DoHandleEventsL() ); |
|
2300 if ( err != KErrNone ) |
|
2301 { |
|
2302 RUBY_ERROR1( "CNssContactHandlerImplementation::DoAddNamesCompleted. Error [%d] in DoHandleEventsL", err ); |
|
2303 } |
|
2304 } |
|
2305 else |
|
2306 { |
|
2307 // No self-generated events, and no pending events to handle |
|
2308 // This is the only place in the code, where everything is completed |
|
2309 // and nothing is pending |
|
2310 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted All the updates completed. No DB event is pending" ); |
|
2311 |
|
2312 } |
|
2313 } |
|
2314 else |
|
2315 { |
|
2316 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesCompleted Generated [%d] deletions. Starting to wait for callbacks", |
|
2317 iDeleteTagListArray->Count() - initialDeleteTagListCount); |
|
2318 } |
|
2319 |
|
2320 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted completed" ); |
|
2321 } |
|
2322 |
|
2323 // --------------------------------------------------------- |
|
2324 // CNssContactHandlerImplementation::NormalChangesHandleError |
|
2325 // Handle errors which happend when updating normal changes |
|
2326 // --------------------------------------------------------- |
|
2327 // |
|
2328 void CNssContactHandlerImplementation::NormalChangesHandleError() |
|
2329 { |
|
2330 // We can't know, what went wrong. |
|
2331 // Stop contact handler, so that the next time the phone is booted |
|
2332 // full synchronization happens. |
|
2333 RUBY_DEBUG0( "CNssContactHandlerImplementation::NormalChangesHandleError " ); |
|
2334 TRAPD( err, DoHandleEventFailedL(); ); |
|
2335 if( err != KErrNone ) |
|
2336 { |
|
2337 RUBY_ERROR1( "CNssContactHandlerImplementation::NormalChangesHandleError DoHandleEventFailedL Left with [%d]", err ); |
|
2338 } |
|
2339 } |
|
2340 |
|
2341 //--------------------------------------------------------- |
|
2342 // CNssContactHandlerImplementation::HandleTrainComplete |
|
2343 // Saves the tag after successful training. |
|
2344 //--------------------------------------------------------- |
|
2345 // |
|
2346 void CNssContactHandlerImplementation::HandleTrainComplete( TInt aErrorCode ) |
|
2347 { |
|
2348 if( aErrorCode == KErrNone ) |
|
2349 { |
|
2350 RUBY_DEBUG1( "Training OK for %d:th name.", iTrainCallbackCounter ); |
|
2351 |
|
2352 RUBY_DEBUG1( "CNssContactHandlerImplementation::HandleTrainComplete. iState [%d]", iState); |
|
2353 RUBY_ASSERT_DEBUG( iState == ECHInitializing || |
|
2354 iState == ECHHandlingNormalChanges, |
|
2355 User::Panic( KFile, __LINE__ ) ); |
|
2356 |
|
2357 iTrainCallbackCounter++; |
|
2358 |
|
2359 if ( iTrainCallbackCounter == iTagArray.Count() ) |
|
2360 { |
|
2361 if ( iState != ECHInitializing ) |
|
2362 { |
|
2363 // assert at the beginning of the function guarantees, |
|
2364 // that iState == ECHHandlingNormalChanges |
|
2365 DoAddNamesTrainingFinished(); |
|
2366 } |
|
2367 } |
|
2368 } |
|
2369 |
|
2370 else // aErrorCode != KErrNone |
|
2371 { |
|
2372 RUBY_DEBUG1( "CNssContactHandlerImplementation::HandleTrainComplete. Training failed for %d:th name.\n", |
|
2373 iTrainCallbackCounter ); |
|
2374 |
|
2375 RUBY_ASSERT_DEBUG( iState == ECHInitializing || |
|
2376 iState == ECHHandlingNormalChanges, |
|
2377 User::Panic( KFile, __LINE__ ) ); |
|
2378 |
|
2379 // Order removal of voice tag icon if present |
|
2380 MNssRRD* rrd = iTagArray[iTrainCallbackCounter]->RRD(); |
|
2381 CArrayFixFlat<TInt>* intArray = rrd->IntArray(); |
|
2382 RUBY_ASSERT_DEBUG( intArray->Count() >= 2, User::Panic( KFile, __LINE__ ) ); |
|
2383 if ( intArray->Count() >= 2 ) |
|
2384 { |
|
2385 TInt error = iRemoveIconList.Append( intArray->At(0) ); |
|
2386 if( error != KErrNone ) |
|
2387 { |
|
2388 RUBY_ERROR2( "CNssContactHandlerImplementation::HandleTrainError Failed to insert [%d] into iRemoveIconList. Error [%d]", |
|
2389 intArray->At(0), error); |
|
2390 } |
|
2391 } |
|
2392 else |
|
2393 { |
|
2394 RUBY_ERROR2( "CNssContactHandlerImplementation::HandleTrainComplete rrd->IntArray()->Count [%d] for iTrainCallbackCounter [%d]", |
|
2395 intArray->Count(), iTrainCallbackCounter); |
|
2396 } |
|
2397 |
|
2398 |
|
2399 delete iTagArray[ iTrainCallbackCounter ]; |
|
2400 iTagArray.Remove( iTrainCallbackCounter ); |
|
2401 |
|
2402 if ( iTrainCallbackCounter == iTagArray.Count() ) |
|
2403 { |
|
2404 if ( iState == ECHHandlingNormalChanges ) |
|
2405 { |
|
2406 DoAddNamesTrainingFinished(); |
|
2407 } |
|
2408 else |
|
2409 { |
|
2410 RUBY_ERROR1( "CNssContactHandlerImplementation::HandleTrainComplete Unexpected state [%d]", iState); |
|
2411 } |
|
2412 } |
|
2413 } |
|
2414 } |
|
2415 |
|
2416 //--------------------------------------------------------- |
|
2417 // CNssContactHandlerImplementation::HandleTrainError |
|
2418 // Handles single tag training failure |
|
2419 //--------------------------------------------------------- |
|
2420 // |
|
2421 /*void CNssContactHandlerImplementation::HandleTrainError( enum MNssTrainTextEventHandler::TNssTrainResult ) |
|
2422 { |
|
2423 RUBY_DEBUG1( "CNssContactHandlerImplementation::HandleTrainError Training failed for %d:th name.\n", |
|
2424 iTrainCallbackCounter ); |
|
2425 |
|
2426 RUBY_ASSERT_DEBUG( iState == ECHInitializing || |
|
2427 iState == ECHHandlingNormalChanges, |
|
2428 User::Panic( KFile, __LINE__ ) ); |
|
2429 |
|
2430 // Order removal of voice tag icon if present |
|
2431 MNssRRD* rrd = iTagArray[iTrainCallbackCounter]->RRD(); |
|
2432 CArrayFixFlat<TInt>* intArray = rrd->IntArray(); |
|
2433 RUBY_ASSERT_DEBUG( intArray->Count() >= 2, User::Panic( KFile, __LINE__ ) ); |
|
2434 if ( intArray->Count() >= 2 ) |
|
2435 { |
|
2436 TInt error = iRemoveIconList.Append( intArray->At(0) ); |
|
2437 if( error != KErrNone ) |
|
2438 { |
|
2439 RUBY_ERROR2( "CNssContactHandlerImplementation::HandleTrainError Failed to insert [%d] into iRemoveIconList. Error [%d]", |
|
2440 intArray->At(0), error); |
|
2441 } |
|
2442 } |
|
2443 else |
|
2444 { |
|
2445 RUBY_ERROR2( "CNssContactHandlerImplementation::HandleTrainError rrd->IntArray()->Count [%d] for iTrainCallbackCounter [%d]", |
|
2446 intArray->Count(), iTrainCallbackCounter); |
|
2447 } |
|
2448 |
|
2449 |
|
2450 delete iTagArray[ iTrainCallbackCounter ]; |
|
2451 iTagArray.Remove( iTrainCallbackCounter ); |
|
2452 |
|
2453 if ( iTrainCallbackCounter == iTagArray.Count() ) |
|
2454 { |
|
2455 if ( iState == ECHHandlingNormalChanges ) |
|
2456 { |
|
2457 DoAddNamesTrainingFinished(); |
|
2458 } |
|
2459 else |
|
2460 { |
|
2461 RUBY_ERROR1( "CNssContactHandlerImplementation::HandleTrainError Unexpected state [%d]", iState); |
|
2462 } |
|
2463 } |
|
2464 }*/ |
|
2465 |
|
2466 //--------------------------------------------------------- |
|
2467 // CNssContactHandlerImplementation::FullResyncStart |
|
2468 // Starts a full synchronization |
|
2469 //--------------------------------------------------------- |
|
2470 // |
|
2471 void CNssContactHandlerImplementation::FullResyncStart() |
|
2472 { |
|
2473 // If we have synchronized earlier, we must delete the old context. |
|
2474 if ( iHaveWeEverSynced ) |
|
2475 { |
|
2476 iContextManager->DeleteContext( this, iContext ); |
|
2477 } |
|
2478 else |
|
2479 { |
|
2480 TRAPD( err, FullResyncCreateContextL() ); |
|
2481 if ( err != KErrNone ) |
|
2482 { |
|
2483 RUBY_ERROR1( "CNssContactHandlerImplementation::FullResyncStart. Error [%d] in FullResyncCreateContextL", err ); |
|
2484 } |
|
2485 } |
|
2486 } |
|
2487 |
|
2488 // ------------------------------------------------------------ |
|
2489 // CNssContactHandlerImplementation::FullResyncCreateContextL |
|
2490 // Full resync: Create a new context |
|
2491 // (prev: Destroy old context, next:populate the context with tags) |
|
2492 // ------------------------------------------------------------ |
|
2493 // |
|
2494 void CNssContactHandlerImplementation::FullResyncCreateContextL() |
|
2495 { |
|
2496 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::FullResyncCreateContextL" ); |
|
2497 if ( iContext != 0 ) |
|
2498 { |
|
2499 delete iContext; |
|
2500 iContext = 0; |
|
2501 } |
|
2502 |
|
2503 iContext = iContextManager->CreateContextL(); |
|
2504 iContext->SetNameL( KNssCHNameDialContext ); |
|
2505 iContext->SetGlobal( ETrue ); |
|
2506 |
|
2507 TBuf8<KClientDataSize> clientDataBuf; |
|
2508 iClientData.iLanguage = User::Language(); |
|
2509 iClientData.iContactSyncId = KErrNotFound; |
|
2510 |
|
2511 TRAPD( error, iClientData.ExternalizeL( clientDataBuf ) ); |
|
2512 if ( !error ) |
|
2513 { |
|
2514 iContext->SetClientData( clientDataBuf ); |
|
2515 iContextManager->SaveContext( this, iContext ); |
|
2516 } |
|
2517 } |
|
2518 |
|
2519 // ------------------------------------------------------------ |
|
2520 // CNssContactHandlerImplementation::FullResyncCreateChanges |
|
2521 // Create tags and send training requests to VAS. |
|
2522 // VAS trains them and calls back when it's ready |
|
2523 // ------------------------------------------------------------ |
|
2524 // |
|
2525 void CNssContactHandlerImplementation::FullResyncCreateChangesL() |
|
2526 { |
|
2527 RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::FullResyncCreateChangesL" ); |
|
2528 |
|
2529 WaitUntilNoSyncBackupIsRunning(); |
|
2530 |
|
2531 CContactIdArray* ids = iPbkHandler->ContactIdArrayLC(); |
|
2532 |
|
2533 RUBY_DEBUG0( "CNssContactHandlerImplementation::FullResyncCreateChanges. iContactQueue.Count() == 0" ); |
|
2534 RUBY_ASSERT_DEBUG( iContactQueue.Count() == 0, User::Panic( KFile, __LINE__ ) ); |
|
2535 // Create change events for training |
|
2536 for ( TInt k( 0 ); k < ids->Count(); k++ ) |
|
2537 { |
|
2538 TPhonebookEvent event; |
|
2539 event.iContactId = (*ids)[k]; |
|
2540 event.iType = EContactAdded; |
|
2541 iEventArray.Append( event ); |
|
2542 } |
|
2543 |
|
2544 CleanupStack::PopAndDestroy( ids ); // Cleanup stack: empty |
|
2545 |
|
2546 // go to processing events |
|
2547 SetState ( ECHIdle ); |
|
2548 TRAPD( err, DoHandleEventsL() ); |
|
2549 if ( err != KErrNone ) |
|
2550 { |
|
2551 RUBY_ERROR1( "CNssContactHandlerImplementation::FullResyncCreateChanges. Error [%d] in DoHandleEventsL", err ); |
|
2552 } |
|
2553 } |
|
2554 |
|
2555 // ------------------------------------------------------------ |
|
2556 // CNssContactHandlerImplementation::DeleteContextCompleted |
|
2557 // DeleteContext callback. Deleting a context is part of |
|
2558 // full synchronization. |
|
2559 // ------------------------------------------------------------ |
|
2560 // |
|
2561 void CNssContactHandlerImplementation::DeleteContextCompleted( TInt aErrorCode ) |
|
2562 { |
|
2563 if( aErrorCode == KErrNone ) |
|
2564 { |
|
2565 // Go to the next phase of full synchronization |
|
2566 RUBY_DEBUG1( "CNssContactHandlerImplementation::DeleteContextCompleted. iState == ECHFullResync, iState [%d]", iState ); |
|
2567 RUBY_ASSERT_DEBUG( iState == ECHFullResync, User::Panic( KFile, __LINE__ ) ); |
|
2568 TRAPD( err, FullResyncCreateContextL() ); |
|
2569 if ( err != KErrNone ) |
|
2570 { |
|
2571 RUBY_ERROR1( "CNssContactHandlerImplementation::DeleteContextCompleted. Error [%d] in FullResyncCreateContextL", err ); |
|
2572 } |
|
2573 } |
|
2574 else |
|
2575 { |
|
2576 RUBY_DEBUG0( "CNssContactHandlerImplementation::DeleteContextCompleted failed" ); |
|
2577 RUBY_ASSERT_DEBUG( iState == ECHFullResync, User::Panic( KFile, __LINE__ ) ); |
|
2578 |
|
2579 RUBY_DEBUG0( "CNssContactHandlerImplementation::DeleteContextCompleted - can't handle, stopping." ); |
|
2580 TRAPD( err, DoHandleEventFailedL(); ); |
|
2581 if( err != KErrNone ) |
|
2582 { |
|
2583 RUBY_ERROR1( "CNssContactHandlerImplementation::DeleteContextCompleted Left with [%d]", err); |
|
2584 } |
|
2585 } |
|
2586 } |
|
2587 |
|
2588 // ------------------------------------------------------------ |
|
2589 // CNssContactHandlerImplementation::CausedByVoiceTagAddition |
|
2590 // Check if the event was caused by voice tag field adding |
|
2591 // ------------------------------------------------------------ |
|
2592 // |
|
2593 TBool CNssContactHandlerImplementation::CausedByVoiceTagAddition( const TPhonebookEvent& aEvent ) |
|
2594 { |
|
2595 TBool isVoiceTagAddedEvent (EFalse); |
|
2596 if( EContactChanged == aEvent.iType ) |
|
2597 { |
|
2598 for ( TInt i = 0; i < iVoiceTagAddedList.Count(); i++ ) |
|
2599 { |
|
2600 if ( aEvent.iContactId == iVoiceTagAddedList[i] ) |
|
2601 { |
|
2602 isVoiceTagAddedEvent = ETrue; |
|
2603 iVoiceTagAddedList.Remove( i-- ); // "i--" because of removal |
|
2604 // Continue iterations. We are not sure if voice tag for the given |
|
2605 // contact could be changed twice |
|
2606 } |
|
2607 } // for |
|
2608 } // if event type |
|
2609 return isVoiceTagAddedEvent; |
|
2610 } |
|
2611 |
|
2612 // ------------------------------------------------------------ |
|
2613 // CNssContactHandlerImplementation::PeriodicCallback |
|
2614 // Static callback required by Symbian Timer services. |
|
2615 // ------------------------------------------------------------ |
|
2616 // |
|
2617 TInt CNssContactHandlerImplementation::PeriodicCallback( TAny* pX ) |
|
2618 { |
|
2619 ((CNssContactHandlerImplementation*)pX)->DoPeriodicCallback(); |
|
2620 return KErrNone; // useless for CPeriodic |
|
2621 } |
|
2622 |
|
2623 // ------------------------------------------------------------ |
|
2624 // CNssContactHandlerImplementation::DoPeriodicCallback |
|
2625 // Periodically check if there are some events to process |
|
2626 // ------------------------------------------------------------ |
|
2627 // |
|
2628 void CNssContactHandlerImplementation::DoPeriodicCallback() |
|
2629 { |
|
2630 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoPeriodicCallback" ); |
|
2631 // Check is needed to eliminate unnesessary TRAP and 64 bit time operations |
|
2632 // Note, that we are not checking for PeriodicAction(), but for iPeriodicHandleEventTimer == NULL |
|
2633 // PeriodicAction() is a method for detection of start of the action, |
|
2634 // while iPeriodicHandleEventTimer == NULL says if periodic action is being executed |
|
2635 // right *now* |
|
2636 |
|
2637 if ( ( iState == ECHIdle ) && ( iEventArray.Count() > 0 ) && ( !PeriodicAction() ) ) |
|
2638 { |
|
2639 RUBY_DEBUG1( "CNssContactHandlerImplementation::DoPeriodicCallback. iState is ECHIdle, there are [%d] events to handle and no periodic action in progress", iEventArray.Count()); |
|
2640 TRAPD( err, DoHandleEventsL()); |
|
2641 if ( err != KErrNone ) |
|
2642 { |
|
2643 RUBY_ERROR1( "CNssContactHandlerImplementation::DoPeriodicCallback. Error [%d] in DoHandleEventsL", err ); |
|
2644 } |
|
2645 } // if there are some events |
|
2646 else |
|
2647 { |
|
2648 RUBY_DEBUG0( "CNssContactHandlerImplementation::DoPeriodicCallback No events to handle" ); |
|
2649 } |
|
2650 } |
|
2651 |
|
2652 // --------------------------------------------------------- |
|
2653 // CNssContactHandlerImplementation::PeriodicAction |
|
2654 // Detects periodic action. |
|
2655 // Checks if many events have been received "lately" |
|
2656 // --------------------------------------------------------- |
|
2657 // |
|
2658 TBool CNssContactHandlerImplementation::PeriodicAction() |
|
2659 { |
|
2660 // index of the first recorded call |
|
2661 TInt checkedIndex = iEventMomentIndex + 1; |
|
2662 checkedIndex = checkedIndex < KEventMomentsSize ? checkedIndex : 0; |
|
2663 TTime& checkedTime = iEventMoments[checkedIndex]; |
|
2664 |
|
2665 // Check if the first recorded call happened "lately" = within last |
|
2666 // KPeriodicActionInterval seconds |
|
2667 TTime currentTime; |
|
2668 currentTime.UniversalTime(); |
|
2669 TTimeIntervalMicroSeconds diff = currentTime.MicroSecondsFrom( checkedTime ); |
|
2670 TBool result = diff < iEndOfPeriodicActionInterval; |
|
2671 if ( result == EFalse ) |
|
2672 { |
|
2673 RUBY_DEBUG0( "CNssContactHandlerImplementation::PeriodicAction. Periodic action completed." ); |
|
2674 RUBY_DEBUG2( "CNssContactHandlerImplementation::PeriodicAction. Periodic action completed. iEventMomentIndex [%d], checkedIndex [%d]", iEventMomentIndex, checkedIndex ); |
|
2675 RUBY_DEBUG1( "currentTime [%d]", I64INT(currentTime.Int64())); |
|
2676 RUBY_DEBUG2( "CNssContactHandlerImplementation::PeriodicAction. diff [%d], iEndOfPeriodicActionInterval [%d]", I64INT(diff.Int64()), I64INT(iEndOfPeriodicActionInterval.Int64() ) ); |
|
2677 |
|
2678 for( TInt i = 0; i < KEventMomentsSize; i++ ) |
|
2679 { |
|
2680 RUBY_DEBUG2( "checkedIndex[%d] = [%d]", i, I64INT(iEventMoments[i].Int64() ) ); |
|
2681 } |
|
2682 |
|
2683 // Periodic action completed. Or hasn't even been started |
|
2684 // Restore timeout values |
|
2685 // iEndOfPeriodicActionInterval = KInitialPeriodicActionInterval; |
|
2686 if ( iPeriodicHandleEventTimer != NULL ) |
|
2687 { |
|
2688 // stop the timer, it was started, when periodic action was started |
|
2689 RUBY_DEBUG0( "CNssContactHandlerImplementation::PeriodicAction Stopping the periodic action timer" ); |
|
2690 iPeriodicHandleEventTimer->Cancel(); |
|
2691 delete iPeriodicHandleEventTimer; |
|
2692 iPeriodicHandleEventTimer = NULL; |
|
2693 } |
|
2694 } |
|
2695 else |
|
2696 { |
|
2697 // Periodic action detected |
|
2698 // start the timer if it is not running yet |
|
2699 if( iPeriodicHandleEventTimer == NULL ) |
|
2700 { |
|
2701 TRAPD( err, iPeriodicHandleEventTimer = CPeriodic::NewL( EPriorityNormal ) ); |
|
2702 if( err != KErrNone ) |
|
2703 { |
|
2704 // This is a bad situation, but not the fatal one. |
|
2705 // If we cannot use timer to detect end of periodic action, |
|
2706 // Let's disable periodic action detection at all |
|
2707 RUBY_DEBUG1( "CNssContactHandlerImplementation::PeriodicAction. PeriodicTimer creation failed. Error [%d]. Disabling periodic actions", err); |
|
2708 result = EFalse; |
|
2709 } |
|
2710 else |
|
2711 { // Timer was created successfully |
|
2712 RUBY_DEBUG0( "CNssContactHandlerImplementation::PeriodicAction Starting the periodic action timer" ); |
|
2713 iPeriodicHandleEventTimer->Start( KPeriodicTimerInterval, KPeriodicTimerInterval, TCallBack( PeriodicCallback, this ) ); |
|
2714 } |
|
2715 } |
|
2716 } |
|
2717 return result; |
|
2718 } |
|
2719 |
|
2720 // ------------------------------------------------------------ |
|
2721 // CNssContactHandlerImplementation::UpdatePeriodicActionVars |
|
2722 // Update variables, used to detect if periodic action is happening |
|
2723 // ------------------------------------------------------------ |
|
2724 // |
|
2725 void CNssContactHandlerImplementation::UpdatePeriodicActionVars() |
|
2726 { |
|
2727 if ( ++iEventMomentIndex >= KEventMomentsSize ) |
|
2728 { |
|
2729 iEventMomentIndex = 0; |
|
2730 } |
|
2731 iEventMoments[iEventMomentIndex].UniversalTime(); |
|
2732 |
|
2733 // Update values used to detect end of periodic action |
|
2734 TTimeIntervalMicroSeconds32 currInterval = MaximalInterval( iEventMoments, KEventMomentsSize, iEventMomentIndex ); |
|
2735 // 8 times. At the end of action, this would typically be no longer, than 0.5secs |
|
2736 // Note, that this is the interval fo KEventMomentsSize events |
|
2737 if ( ( currInterval.Int() << 3 ) >= ( KInitialPeriodicActionInterval ) ) |
|
2738 { |
|
2739 RUBY_DEBUG1( "CNssContactHandlerImplementation::UpdatePeriodicActionVars. Calculated interval is too big. Reverting periodic interval to the max [%d] mcs", KInitialPeriodicActionInterval); |
|
2740 iEndOfPeriodicActionInterval = KInitialPeriodicActionInterval; |
|
2741 } |
|
2742 else |
|
2743 { |
|
2744 currInterval = currInterval.Int() << 3; |
|
2745 RUBY_DEBUG1( "CNssContactHandlerImplementation::UpdatePeriodicActionVars. Adjusting periodic interval to [%d] mcs", currInterval.Int() ); |
|
2746 iEndOfPeriodicActionInterval = currInterval.Int(); |
|
2747 } |
|
2748 } |
|
2749 |
|
2750 // ------------------------------------------------------------ |
|
2751 // CNssContactHandlerImplementation::MaximalInterval |
|
2752 // Return maximal interval from the array of time moments |
|
2753 // ------------------------------------------------------------ |
|
2754 // |
|
2755 TTimeIntervalMicroSeconds32 CNssContactHandlerImplementation::MaximalInterval( const TTime aMoments[], const TInt aMomentsLength, const TInt aLastMomentIndex ) |
|
2756 { |
|
2757 RUBY_ASSERT_DEBUG( aMomentsLength > 1, User::Panic( KFile, __LINE__ ) ); |
|
2758 TInt currIndex( aLastMomentIndex ); |
|
2759 TInt prevIndex = currIndex - 1 < 0 ? aMomentsLength - 1 : currIndex - 1; |
|
2760 TTimeIntervalMicroSeconds32 result( 0 ); |
|
2761 TTimeIntervalMicroSeconds currInterval; |
|
2762 |
|
2763 for ( TInt i = 0; i < aMomentsLength - 1; i++ ) |
|
2764 { |
|
2765 currInterval = aMoments[currIndex].MicroSecondsFrom( aMoments[prevIndex] ); |
|
2766 const TInt64& currIntVal = currInterval.Int64(); |
|
2767 TBool tooBigValue = currIntVal > KMaxTInt; |
|
2768 |
|
2769 // if high != 0, aMoments were filled in the incorrect way |
|
2770 // but we should not bug the user about it |
|
2771 if ( tooBigValue ) |
|
2772 { |
|
2773 // this cannot be a negative value.. if moments are recorded in the correct order. |
|
2774 // Then non-zero high means, that interval is too big to fit into |
|
2775 // TTimeIntervalMicroSeconds32 |
|
2776 RUBY_DEBUG0( "CNssContactHandlerImplementation::MaximalInterval. Maximal interval is out of bounds" ); |
|
2777 result = TTimeIntervalMicroSeconds32( KMaxTInt ); |
|
2778 break; |
|
2779 } |
|
2780 else |
|
2781 { |
|
2782 // normal size value |
|
2783 // casting is safe - we checked, that it fits into TInt |
|
2784 TTimeIntervalMicroSeconds32 currInterval32 ( (TInt)currIntVal ); |
|
2785 |
|
2786 if ( currInterval32 > result ) |
|
2787 { |
|
2788 result = currInterval32; |
|
2789 } |
|
2790 } |
|
2791 currIndex = currIndex - 1 < 0 ? aMomentsLength - 1 : currIndex - 1; |
|
2792 prevIndex = currIndex - 1 < 0 ? aMomentsLength - 1 : currIndex - 1; |
|
2793 } // for |
|
2794 return result; |
|
2795 } |
|
2796 |
|
2797 // ------------------------------------------------------------ |
|
2798 // CNssContactHandlerImplementation::SetState |
|
2799 // Sets the contact handler state. |
|
2800 // In debug, panics (via asserts) if state change is not legal |
|
2801 // ------------------------------------------------------------ |
|
2802 // |
|
2803 void CNssContactHandlerImplementation::SetState( TContactHandlerState aState ) |
|
2804 { |
|
2805 RUBY_DEBUG2( "CNssContactHandlerImplementation::SetState from [%d] to [%d]", iState, aState); |
|
2806 switch( aState ) |
|
2807 { |
|
2808 case ECHFullResync: |
|
2809 // no pending events |
|
2810 RUBY_ASSERT_DEBUG( ( iDeleteTagListArray == NULL ) || ( iDeleteCallbackCounter == iDeleteTagListArray->Count() ), User::Panic( KFile, __LINE__ ) ); |
|
2811 RUBY_ASSERT_DEBUG( iSaveCallbackCounter == iTagArray.Count(), User::Panic( KFile, __LINE__ ) ); |
|
2812 |
|
2813 // full resyncronization needed again if this full resyncronization fails |
|
2814 RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
2815 break; |
|
2816 case ECHHandlingNormalChanges: |
|
2817 RUBY_ASSERT_DEBUG( iState == ECHIdle, User::Panic( KFile, __LINE__ ) ); |
|
2818 RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
2819 break; |
|
2820 case ECHIdle: |
|
2821 if ( iDeleteTagListArray != NULL ) |
|
2822 { |
|
2823 RUBY_ASSERT_DEBUG( (iSaveCallbackCounter == iTagArray.Count() ) || ( iDeleteCallbackCounter == iDeleteTagListArray->Count() ), User::Panic( KFile, __LINE__ ) ); |
|
2824 } |
|
2825 else |
|
2826 { |
|
2827 RUBY_ASSERT_DEBUG( ( iSaveCallbackCounter == iTagArray.Count() ) , User::Panic( KFile, __LINE__ ) ); |
|
2828 } |
|
2829 if( iEventArray.Count() == 0 ) |
|
2830 { |
|
2831 // Idle state and no pending events mean, that contact handler |
|
2832 // completed its operations for now |
|
2833 TInt errProp = iBusyProperty.Set( EContactsNoTraining ); |
|
2834 if ( errProp != KErrNone ) |
|
2835 { |
|
2836 RUBY_ERROR1("CNssContactHandlerImplementation::ConstructL() Failed to set property. Error [%d]", |
|
2837 errProp ); |
|
2838 // @todo Not a leaving function -> leave commented out |
|
2839 //User::Leave( errProp ) ; |
|
2840 } |
|
2841 } |
|
2842 |
|
2843 // all changes done, no need for resyncronization |
|
2844 RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( EFalse ) ); |
|
2845 |
|
2846 break; |
|
2847 default: |
|
2848 RUBY_ERROR0( "CNssContactHandlerImplementation::SetState Unexpected or unknown state" ); |
|
2849 RUBY_ASSERT_DEBUG( EFalse, User::Panic( KFile, __LINE__ ) ); |
|
2850 |
|
2851 // failure, full resyncronization needed |
|
2852 RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
2853 break; |
|
2854 } |
|
2855 // actually switch state |
|
2856 iState = aState; |
|
2857 } |
|
2858 |
|
2859 // --------------------------------------------------------- |
|
2860 // CNssContactHandlerImplementation::DataSyncStateChanged |
|
2861 // |
|
2862 // --------------------------------------------------------- |
|
2863 // |
|
2864 void CNssContactHandlerImplementation::DataSyncStateChanged( TBool aRunning ) |
|
2865 { |
|
2866 if( !aRunning && ( iSyncBackupWaiter->IsStarted() ) ) |
|
2867 { |
|
2868 RUBY_DEBUG0( "DataSyncStateChanged Sync became inactive and CH was waiting for it" ); |
|
2869 iSyncBackupWaiter->AsyncStop(); |
|
2870 } |
|
2871 } |
|
2872 |
|
2873 // --------------------------------------------------------- |
|
2874 // Is called when backup/restore status is changed and when backup/restore |
|
2875 // state observation was just started |
|
2876 // @param aRunning ETrue if some backup/restore action is in progress |
|
2877 // EFalse otherwise |
|
2878 // @param aRestoreType ETrue if the event is restore related |
|
2879 // EFalse if the event is backup related |
|
2880 // @see CNssChBackupObserver |
|
2881 // --------------------------------------------------------- |
|
2882 void CNssContactHandlerImplementation::BackupRestoreStateChanged( TBool aRestoreType, |
|
2883 TBool aRunning ) |
|
2884 { |
|
2885 RUBY_DEBUG2( "BackupRestoreStateChanged aRestoreType [%d], aRunning [%d]", |
|
2886 aRestoreType, aRunning ); |
|
2887 |
|
2888 if( aRestoreType && aRunning ) |
|
2889 { |
|
2890 RUBY_DEBUG0( "Setting the Full Resync CR flag" ); |
|
2891 RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
2892 } |
|
2893 |
|
2894 if( !aRunning && ( iSyncBackupWaiter->IsStarted() ) ) |
|
2895 { |
|
2896 RUBY_DEBUG0( "BackupRestoreStateChanged b/r became inactive and CH was waiting for it" ); |
|
2897 iSyncBackupWaiter->AsyncStop(); |
|
2898 } |
|
2899 } |
|
2900 |
|
2901 // --------------------------------------------------------- |
|
2902 // CNssContactHandlerImplementation::HandleNotifyInt |
|
2903 // |
|
2904 // --------------------------------------------------------- |
|
2905 // |
|
2906 void CNssContactHandlerImplementation::HandleNotifyInt( TUint32 aId, TInt aNewValue ) |
|
2907 { |
|
2908 RUBY_DEBUG0( "" ); |
|
2909 |
|
2910 if ( aId == KSRSFFullResyncNeeded ) |
|
2911 { |
|
2912 if ( aNewValue == KImmediateResync ) |
|
2913 { |
|
2914 RUBY_DEBUG0( "Immediate full resync requested" ); |
|
2915 |
|
2916 // Write the previous value back to the cenrep |
|
2917 TRAP_IGNORE( SetFullResyncCrFlagL( iResyncAtBoot ) ); |
|
2918 |
|
2919 // Create an event that will launch full resync |
|
2920 TPhonebookEvent event; |
|
2921 event.iType = ENullEvent; |
|
2922 event.iContactId = 0; |
|
2923 |
|
2924 iEventArray.Append( event ); |
|
2925 |
|
2926 // Start resync if nothing is ongoing |
|
2927 if ( iState == ECHIdle ) |
|
2928 { |
|
2929 TRAP_IGNORE( DoHandleEventsL() ); |
|
2930 } |
|
2931 } |
|
2932 } |
|
2933 } |
|
2934 |
|
2935 // --------------------------------------------------------- |
|
2936 // Sets the central repository full resync flag |
|
2937 // --------------------------------------------------------- |
|
2938 void CNssContactHandlerImplementation::SetFullResyncCrFlagL( TBool aResyncNeeded ) |
|
2939 { |
|
2940 RUBY_DEBUG_BLOCKL(""); |
|
2941 User::LeaveIfError( iRepository->Set( KSRSFFullResyncNeeded, aResyncNeeded ) ); |
|
2942 iResyncAtBoot = aResyncNeeded; |
|
2943 } |
|
2944 |
|
2945 // --------------------------------------------------------- |
|
2946 // CNssContactHandlerImplementation::WaitUntilNoSyncBackupIsRunning |
|
2947 // |
|
2948 // --------------------------------------------------------- |
|
2949 // |
|
2950 void CNssContactHandlerImplementation::WaitUntilNoSyncBackupIsRunning() |
|
2951 { |
|
2952 RUBY_DEBUG0( "WaitUntilNoSyncBackupIsRunning start" ); |
|
2953 RUBY_ASSERT_DEBUG( !iSyncBackupWaiter->IsStarted(), User::Panic( KFile, __LINE__ ) ); |
|
2954 |
|
2955 // Disconnection from phonebook should happen only once and only if b/r is running |
|
2956 TBool disconnectedFromPb = EFalse; |
|
2957 |
|
2958 // Check the values until both data sync and backup/restore are not active |
|
2959 while( iDataSyncWatcher->InProgress() || iBackupObserver->InProgress() ) |
|
2960 { |
|
2961 RUBY_DEBUG2( "WaitUntilNoSyncBackupIsRunning Have to wait. data sync [%d], backup/restore [%d]", |
|
2962 iDataSyncWatcher->InProgress(), iBackupObserver->InProgress() ); |
|
2963 if( !iSyncBackupWaiter->IsStarted() ) |
|
2964 { |
|
2965 if( (!disconnectedFromPb) && iBackupObserver->InProgress() ) |
|
2966 { |
|
2967 RUBY_DEBUG0( "WaitUntilNoSyncBackupIsRunning Disconnecting from phonebook" ); |
|
2968 DisconnectFromPhonebook(); |
|
2969 disconnectedFromPb = ETrue; |
|
2970 } |
|
2971 iSyncBackupWaiter->Start(); |
|
2972 } |
|
2973 else |
|
2974 { |
|
2975 RUBY_ERROR0( "WaitUntilNoSyncBackupIsRunning Attempt to start already active iSyncBackupWaiter. Huge error!" ); |
|
2976 } |
|
2977 } |
|
2978 |
|
2979 if( disconnectedFromPb ) |
|
2980 { |
|
2981 RUBY_DEBUG0( "WaitUntilNoSyncBackupIsRunning Reconnecting to phonebook" ); |
|
2982 TRAP_IGNORE( ConnectToPhonebookL() ); |
|
2983 } |
|
2984 |
|
2985 RUBY_DEBUG0( "WaitUntilNoSyncBackupIsRunning end" ); |
|
2986 } |
|
2987 |
|
2988 // --------------------------------------------------------- |
|
2989 // CNssContactHandlerImplementation::GetContactL |
|
2990 // |
|
2991 // --------------------------------------------------------- |
|
2992 // |
|
2993 void CNssContactHandlerImplementation::GetContactL( TContactItemId aContactId, TBool aReadContact ) |
|
2994 { |
|
2995 RUBY_DEBUG1( "CNssContactHandlerImplementation::GetContactL. contact id [%d]", aContactId ); |
|
2996 TInt err = KErrNone; |
|
2997 // Number of attempts tries |
|
2998 TInt attemptsTried( 0 ); |
|
2999 do |
|
3000 { |
|
3001 if( err == KErrInUse ) // i.e. not the first cycle iteration |
|
3002 { |
|
3003 RUBY_DEBUG2( "GetContactL Contact [%d] is locked. Waiting one more second. Retrial [%d]", |
|
3004 aContactId, attemptsTried); |
|
3005 // start periodic timer |
|
3006 if( attemptsTried == 1) // i.e exactly the second cycle iteration |
|
3007 { |
|
3008 RUBY_DEBUG0( "GetContactL Creating periodic timer" ); |
|
3009 iContactWaitTimer = CPeriodic::NewL( EPriorityNormal ); |
|
3010 iContactWaitTimer->Start( KContactWaitInterval, KContactWaitInterval, TCallBack( ContactWaitCallback, this ) ); |
|
3011 } |
|
3012 RUBY_DEBUG0( "GetContactL Starting the inner cycle waiting" ); |
|
3013 iContactWaiter->Start( ); |
|
3014 RUBY_DEBUG0( "GetContactL Waiting completed, trying to open contact again" ); |
|
3015 } |
|
3016 |
|
3017 TRAP( err, iPbkHandler->FindContactL( aContactId, aReadContact ) ); |
|
3018 |
|
3019 attemptsTried++; |
|
3020 // -1 means forever |
|
3021 if( ( KMaxContactLockRetrials != -1 ) && ( attemptsTried >= KMaxContactLockRetrials ) ) |
|
3022 { |
|
3023 RUBY_DEBUG1( "GetContactL Tried for [%d] times, still no success", attemptsTried ); |
|
3024 break; |
|
3025 } |
|
3026 } |
|
3027 while( err == KErrInUse ); |
|
3028 if( iContactWaitTimer != NULL ) |
|
3029 { |
|
3030 iContactWaitTimer->Cancel(); |
|
3031 delete iContactWaitTimer; |
|
3032 iContactWaitTimer = NULL; |
|
3033 } |
|
3034 // Propagate all the leaves, BUT KErrInUse |
|
3035 if( ( err != KErrInUse ) && ( err != KErrNone ) ) |
|
3036 { |
|
3037 User::LeaveIfError( err ); |
|
3038 } |
|
3039 if( err == KErrInUse ) |
|
3040 { |
|
3041 RUBY_DEBUG1( "GetContactL Failed to lock contact [%d]. Disabling CH, will resync on reboot", aContactId ); |
|
3042 DisableEventHandling(); |
|
3043 User::Leave( KErrInUse ); |
|
3044 } |
|
3045 RUBY_DEBUG0( "CNssContactHandlerImplementation::GetContactL completed" ); |
|
3046 } |
|
3047 |
|
3048 // --------------------------------------------------------- |
|
3049 // CNssContactHandlerImplementation::ReadContactL |
|
3050 // |
|
3051 // --------------------------------------------------------- |
|
3052 // |
|
3053 void CNssContactHandlerImplementation::ReadContactL( TContactItemId aContactId ) |
|
3054 { |
|
3055 GetContactL( aContactId, ETrue ); |
|
3056 } |
|
3057 |
|
3058 // --------------------------------------------------------- |
|
3059 // CNssContactHandlerImplementation::OpenContactL |
|
3060 // |
|
3061 // --------------------------------------------------------- |
|
3062 // |
|
3063 void CNssContactHandlerImplementation::OpenContactL( TContactItemId aContactId ) |
|
3064 { |
|
3065 GetContactL( aContactId, EFalse ); |
|
3066 } |
|
3067 |
|
3068 // --------------------------------------------------------- |
|
3069 // CNssContactHandlerImplementation::ContactWaitCallback |
|
3070 // |
|
3071 // --------------------------------------------------------- |
|
3072 // |
|
3073 TInt CNssContactHandlerImplementation::ContactWaitCallback( TAny* pX ) |
|
3074 { |
|
3075 ((CNssContactHandlerImplementation*)pX)->DoContactWaitCallback(); |
|
3076 return KErrNone; // useless for CPeriodic |
|
3077 } |
|
3078 |
|
3079 // --------------------------------------------------------- |
|
3080 // CNssContactHandlerImplementation::DoContactWaitCallback |
|
3081 // |
|
3082 // --------------------------------------------------------- |
|
3083 // |
|
3084 void CNssContactHandlerImplementation::DoContactWaitCallback() |
|
3085 { |
|
3086 iContactWaiter->AsyncStop(); |
|
3087 } |
|
3088 |
|
3089 // --------------------------------------------------------- |
|
3090 // CNssContactHandlerImplementation::NoDiskSpace |
|
3091 // Checks if there is not enough disk space to finish the |
|
3092 // operation. Returns ETrue if there is no space. |
|
3093 // --------------------------------------------------------- |
|
3094 // |
|
3095 TBool CNssContactHandlerImplementation::NoDiskSpace() |
|
3096 { |
|
3097 RUBY_DEBUG0( "CNssContactHandlerImplementation::NoDiskSpace" ); |
|
3098 TBool diskSpace( EFalse ); |
|
3099 TRAP_IGNORE( diskSpace = SysUtil::FFSSpaceBelowCriticalLevelL( &iFSession, KIncreaseOfDatabaseSizes ) ); |
|
3100 |
|
3101 if ( diskSpace ) |
|
3102 { |
|
3103 RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
3104 RUBY_DEBUG0( "CNssContactHandlerImplementation::NoDiskSpace NOT enough disk space available" ); |
|
3105 return ETrue; |
|
3106 } |
|
3107 else |
|
3108 { |
|
3109 RUBY_DEBUG0( "CNssContactHandlerImplementation::NoDiskSpace There is enough disk space" ); |
|
3110 return EFalse; |
|
3111 } |
|
3112 } |
|
3113 |
|
3114 // --------------------------------------------------------- |
|
3115 // CNssContactHandlerImplementation::TrimName |
|
3116 // Substitutes separator characters in descriptor with |
|
3117 // white spaces. Removes extra withspaces. |
|
3118 // --------------------------------------------------------- |
|
3119 // |
|
3120 void CNssContactHandlerImplementation::TrimName( HBufC* aBuf ) |
|
3121 { |
|
3122 TPtr ptr = aBuf->Des(); |
|
3123 |
|
3124 for ( TInt findIndex = 0; findIndex < aBuf->Des().Length(); findIndex++ ) |
|
3125 { |
|
3126 if ( ptr[findIndex] == iSeparator ) |
|
3127 { |
|
3128 ptr[findIndex] = ' '; |
|
3129 } |
|
3130 } |
|
3131 |
|
3132 ptr.TrimAll(); |
|
3133 } |
|
3134 |
|
3135 // --------------------------------------------------------- |
|
3136 // CNssContactHandlerImplementation::AppendName |
|
3137 // Appends name to given buffer |
|
3138 // --------------------------------------------------------- |
|
3139 // |
|
3140 void CNssContactHandlerImplementation::AppendName( HBufC* aBuf, HBufC* aName ) |
|
3141 { |
|
3142 if ( aName->Length() != 0 ) |
|
3143 { |
|
3144 aBuf->Des().Append( iSeparator ); |
|
3145 aBuf->Des().Append( KNameTrainingIndex ); |
|
3146 aBuf->Des().Append( aName->Des() ); |
|
3147 } |
|
3148 } |
|
3149 |
|
3150 // --------------------------------------------------------- |
|
3151 // CNssContactHandlerImplementation::AppendExtensionMarker |
|
3152 // Appends marker for the extensions |
|
3153 // Parameters should be in format "%U text message" |
|
3154 // In which case output is "%U_2text message" |
|
3155 // --------------------------------------------------------- |
|
3156 // |
|
3157 void CNssContactHandlerImplementation::AppendExtensionMarker( TDes& aDes ) |
|
3158 { |
|
3159 if ( aDes.Length() > 0 ) |
|
3160 { |
|
3161 TInt insertPosition( 0 ); |
|
3162 if ( aDes.Find( KExtensionFormatString ) == 0 ) |
|
3163 { |
|
3164 // Find the first space and insert marker to that position |
|
3165 TInt firstSpace( 0 ); |
|
3166 firstSpace = aDes.Find( _L(" ") ); |
|
3167 if ( firstSpace == 2 ) // Next character after KExtensionFormatString |
|
3168 { |
|
3169 aDes.Delete( firstSpace, 1 ); |
|
3170 } |
|
3171 insertPosition = 2; |
|
3172 } |
|
3173 // Insert marker |
|
3174 aDes.Insert( insertPosition, KExtensionTrainingIndex ); |
|
3175 aDes.Insert( insertPosition, KNameSeparator ); |
|
3176 } |
|
3177 } |
|
3178 |
|
3179 /** |
|
3180 * Establishes the connection to the contact engine and |
|
3181 * starts listening to it |
|
3182 */ |
|
3183 void CNssContactHandlerImplementation::ConnectToPhonebookL() |
|
3184 { |
|
3185 RUBY_ASSERT_DEBUG( (!iPbkHandler), User::Leave( KErrNotReady ) ); |
|
3186 iPbkHandler = CVasVPbkHandler::NewL(); |
|
3187 iPbkHandler->InitializeL(); |
|
3188 iPbkHandler->CreateContactObserverL( this ); |
|
3189 } |
|
3190 |
|
3191 /** |
|
3192 * Clears the connection to the contact engine |
|
3193 */ |
|
3194 void CNssContactHandlerImplementation::DisconnectFromPhonebook() |
|
3195 { |
|
3196 delete iPbkHandler; |
|
3197 iPbkHandler = NULL; |
|
3198 } |
|
3199 |
|
3200 #ifdef __SIND_EXTENSIONS |
|
3201 |
|
3202 // --------------------------------------------------------- |
|
3203 // CNssContactHandlerImplementation::ReadExtensionsL |
|
3204 // Reads the extension resource file |
|
3205 // --------------------------------------------------------- |
|
3206 // |
|
3207 void CNssContactHandlerImplementation::ReadExtensionsL() |
|
3208 { |
|
3209 // using StringLoader should be used, but there is no |
|
3210 // access to CCoeEnv |
|
3211 |
|
3212 |
|
3213 // letters for drives in search order |
|
3214 const TBuf<1> KResourceDrivers = _L("z"); |
|
3215 _LIT( KResourceFileName, "nssvascontacthandler.rsc" ); |
|
3216 |
|
3217 // number of extension commands in the resource file |
|
3218 const TInt KExtensionCommandCount = 8; |
|
3219 |
|
3220 // load resources |
|
3221 RResourceFile resourceFile; |
|
3222 RFs fs; |
|
3223 CleanupClosePushL( fs ); |
|
3224 TBool found( EFalse ); |
|
3225 User::LeaveIfError( fs.Connect() ); |
|
3226 |
|
3227 |
|
3228 TFileName name; |
|
3229 TInt i( 0 ); |
|
3230 // use the first drive |
|
3231 name.Append( KResourceDrivers[i] ); |
|
3232 name.Append(':'); |
|
3233 name.Append( KDC_RESOURCE_FILES_DIR ); |
|
3234 name.Append( KResourceFileName ); |
|
3235 |
|
3236 while ( !found && i < KResourceDrivers.Length() ) |
|
3237 { |
|
3238 name[0] = KResourceDrivers[i++]; |
|
3239 |
|
3240 BaflUtils::NearestLanguageFile( fs, name ); |
|
3241 |
|
3242 if ( BaflUtils::FileExists(fs, name) ) |
|
3243 { |
|
3244 // open resource |
|
3245 resourceFile.OpenL( fs, name ); |
|
3246 CleanupClosePushL( resourceFile ); |
|
3247 resourceFile.ConfirmSignatureL(); |
|
3248 found = ETrue; |
|
3249 } |
|
3250 } |
|
3251 |
|
3252 if ( !found ) |
|
3253 { |
|
3254 User::Leave( KErrNotFound ); |
|
3255 } |
|
3256 |
|
3257 for ( TInt extensionIndex( 0 ); extensionIndex < KExtensionCommandCount; extensionIndex++ ) |
|
3258 { |
|
3259 TExtension extension; |
|
3260 TResourceReader reader; |
|
3261 TBool extentionSupported( ETrue ); |
|
3262 |
|
3263 switch ( extensionIndex ) |
|
3264 { |
|
3265 |
|
3266 case 0: |
|
3267 reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_MOBILE ) ); |
|
3268 extension.iId = EPbkFieldIdPhoneNumberMobile; |
|
3269 extension.iAction = EDial; |
|
3270 extension.iCommand = EMobileCommand; |
|
3271 break; |
|
3272 |
|
3273 case 1: |
|
3274 reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_MESSAGE ) ); |
|
3275 extension.iId = EPbkFieldIdPhoneNumberMobile; |
|
3276 extension.iAction = ENewMessage; |
|
3277 extension.iCommand = EMessageCommand; |
|
3278 break; |
|
3279 |
|
3280 case 2: |
|
3281 reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_GENERAL ) ); |
|
3282 extension.iId = EPbkFieldIdPhoneNumberGeneral; |
|
3283 extension.iAction = EDial; |
|
3284 extension.iCommand = EGeneralCommand; |
|
3285 break; |
|
3286 |
|
3287 case 3: |
|
3288 reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_WORK ) ); |
|
3289 extension.iId = EPbkFieldIdPhoneNumberWork; |
|
3290 extension.iAction = EDial; |
|
3291 extension.iCommand = EWorkCommand; |
|
3292 break; |
|
3293 |
|
3294 case 4: |
|
3295 reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_HOME ) ); |
|
3296 extension.iId = EPbkFieldIdPhoneNumberHome; |
|
3297 extension.iAction = EDial; |
|
3298 extension.iCommand = EHomeCommand; |
|
3299 break; |
|
3300 |
|
3301 case 5: |
|
3302 if ( iVideoCallFeatureSupported ) |
|
3303 { |
|
3304 reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_VIDEO ) ); |
|
3305 extension.iId = EPbkFieldIdPhoneNumberVideo; |
|
3306 extension.iAction = EDial; |
|
3307 extension.iCommand = EVideoCommand; |
|
3308 } |
|
3309 else |
|
3310 { |
|
3311 extentionSupported = EFalse; |
|
3312 } |
|
3313 break; |
|
3314 |
|
3315 case 6: |
|
3316 reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_EMAIL ) ); |
|
3317 extension.iId =EPbkFieldIdEmailAddress ; |
|
3318 extension.iAction = ENewEmail; |
|
3319 extension.iCommand = EEmailCommand; |
|
3320 break; |
|
3321 |
|
3322 case 7: |
|
3323 if ( iVoIPFeatureSupported ) |
|
3324 { |
|
3325 reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_VOIP ) ); |
|
3326 extension.iId = EPbkFieldIdVOIP; |
|
3327 extension.iAction = EDial; |
|
3328 extension.iCommand = EVoipCommand; |
|
3329 } |
|
3330 else |
|
3331 { |
|
3332 extentionSupported = EFalse; |
|
3333 } |
|
3334 break; |
|
3335 |
|
3336 default: |
|
3337 User::Leave( KErrGeneral ); // !!! @todo: PANIC |
|
3338 } |
|
3339 |
|
3340 if ( extentionSupported ) |
|
3341 { |
|
3342 extension.iText = reader.ReadHBufCL(); |
|
3343 CleanupStack::PushL( extension.iText ); |
|
3344 User::LeaveIfError( iExtensionList.Append( extension ) ); |
|
3345 CleanupStack::Pop( extension.iText ); |
|
3346 CleanupStack::PopAndDestroy(); // AllocReadLC |
|
3347 } |
|
3348 } |
|
3349 |
|
3350 CleanupStack::PopAndDestroy( &resourceFile ); |
|
3351 CleanupStack::PopAndDestroy( &fs ); |
|
3352 |
|
3353 } |
|
3354 |
|
3355 // --------------------------------------------------------- |
|
3356 // CNssContactHandlerImplementation::FindExtensionField |
|
3357 // Finds the extension field based on priority lists |
|
3358 // --------------------------------------------------------- |
|
3359 // |
|
3360 TInt CNssContactHandlerImplementation::FindExtensionField( TVasExtensionAction aAction, |
|
3361 TPbkFieldId aDefaultFieldId ) |
|
3362 { |
|
3363 TInt found = KErrNotFound; |
|
3364 |
|
3365 switch ( aDefaultFieldId ) |
|
3366 { |
|
3367 case EPbkFieldIdPhoneNumberVideo: |
|
3368 { |
|
3369 // Use defaults for video extension |
|
3370 found = ExtensionFieldFindLoop( KVideoExtensionFields, KVideoExtensionFieldsCount ); |
|
3371 break; |
|
3372 } |
|
3373 |
|
3374 case EPbkFieldIdPhoneNumberMobile: |
|
3375 { |
|
3376 if ( aAction == ENewMessage ) |
|
3377 { |
|
3378 // Use defaults for message extension |
|
3379 found = ExtensionFieldFindLoop( KMessageExtensionFields, KMessageExtensionFieldsCount ); |
|
3380 } |
|
3381 else |
|
3382 { |
|
3383 TRAP( found, iPbkHandler->FindFieldL( aDefaultFieldId ) ); |
|
3384 } |
|
3385 |
|
3386 break; |
|
3387 } |
|
3388 |
|
3389 case EPbkFieldIdVOIP: |
|
3390 { |
|
3391 // Use defaults for VOIP extension |
|
3392 found = ExtensionFieldFindLoop( KVOIPExtensionFields, KVOIPExtensionFieldsCount ); |
|
3393 |
|
3394 break; |
|
3395 } |
|
3396 |
|
3397 default: |
|
3398 { |
|
3399 TRAP( found, iPbkHandler->FindFieldL( aDefaultFieldId ) ); |
|
3400 break; |
|
3401 } |
|
3402 } |
|
3403 return found; |
|
3404 } |
|
3405 |
|
3406 // --------------------------------------------------------- |
|
3407 // CNssContactHandlerImplementation::ExtensionFieldFindLoop |
|
3408 // Finds the extension from the prioroty list arrays |
|
3409 // --------------------------------------------------------- |
|
3410 // |
|
3411 TInt CNssContactHandlerImplementation::ExtensionFieldFindLoop( const TPbkFieldId* const aArray, |
|
3412 TInt aCount ) |
|
3413 { |
|
3414 TInt found = KErrNotFound; |
|
3415 |
|
3416 for ( TInt iCounter = 0; iCounter < aCount; iCounter++ ) |
|
3417 { |
|
3418 TRAP( found, iPbkHandler->FindFieldL( aArray[iCounter] ) ); |
|
3419 if ( found == KErrNone ) |
|
3420 { |
|
3421 break; |
|
3422 } |
|
3423 } |
|
3424 return found; |
|
3425 } |
|
3426 |
|
3427 #endif // __SIND_EXTENSIONS |
|
3428 |
|
3429 // End of File |