author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:21:09 +0300 | |
branch | RCL_3 |
changeset 20 | bf318c0ae8c0 |
parent 19 | e36f3802f733 |
permissions | -rw-r--r-- |
19 | 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 |
||
20
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1525 |
// TRAPD( err, // trapping is a fix to make the function non-leaving |
19 | 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) |
|
20
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1530 |
TRAPD(err, |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1531 |
for ( TInt k( 0 ); k < aTagList->Count(); k++ ) |
19 | 1532 |
{ |
1533 |
iDeleteTagListArray->AppendL( (*aTagList)[k] ); |
|
1534 |
} |
|
20
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1535 |
); |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1536 |
if ( err != KErrNone ) |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1537 |
{ |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1538 |
// Destroy tag list |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1539 |
aTagList->Reset(); |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1540 |
delete aTagList; |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1541 |
aTagList = 0; |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1542 |
return; |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1543 |
} |
19 | 1544 |
// We have processed this ID |
1545 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList Before removal. iDelList.Count [%d]", iDelList.Count() ); |
|
1546 |
if( iDelList.Count() > 0 ) |
|
1547 |
{ |
|
1548 |
iDelList.Remove( 0 ); |
|
1549 |
} |
|
1550 |
else |
|
1551 |
{ |
|
1552 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList Empty iDelList!" ); |
|
1553 |
} |
|
1554 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList After removal. iDelList.Count [%d]", iDelList.Count() ); |
|
1555 |
||
1556 |
// If there are still more IDs, convert the next ID into a tag. |
|
1557 |
if ( iDelList.Count() > 0 ) |
|
1558 |
{ |
|
1559 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList There are [%d] contacts to delete. Calling GetTagList for them", iDelList.Count() ); |
|
1560 |
iContactId = iDelList[0].iContactId; |
|
1561 |
||
1562 |
TInt retCode |
|
1563 |
= iTagManager->GetTagList( this, iContext, iContactId, 0 ); |
|
1564 |
||
1565 |
if ( retCode != KErrNone ) |
|
1566 |
{ |
|
1567 |
RUBY_DEBUG0( "DoRemoveNamesAfterGetTagList Failed to GetTagList, going to DoHandleEventFailedL" ); |
|
1568 |
TRAP_IGNORE( DoHandleEventFailedL() ); // to handle the process event failed |
|
1569 |
/** @todo reengineer into single return path */ |
|
1570 |
// Destroy tag list |
|
1571 |
aTagList->Reset(); |
|
1572 |
delete aTagList; |
|
1573 |
aTagList = 0; |
|
1574 |
return; |
|
1575 |
} |
|
1576 |
} |
|
1577 |
||
1578 |
// If we just finished converting the last ID, move to the next phase. |
|
1579 |
else{ |
|
1580 |
RUBY_DEBUG0( "DoRemoveNamesAfterGetTagList Moving to the next phase" ); |
|
1581 |
DoRemoveNamesCallDeleteTag(); |
|
1582 |
} |
|
20
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1583 |
// ); // TRAPD |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1584 |
// if( err != KErrNone ) |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1585 |
// { |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1586 |
// RUBY_ERROR1( "CNssContactHandlerImplementation::DoRemoveNamesAfterGetTagList Leaves with [%d] inside", err ); |
bf318c0ae8c0
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1587 |
// } |
19 | 1588 |
// Destroy tag list |
1589 |
aTagList->Reset(); |
|
1590 |
delete aTagList; |
|
1591 |
aTagList = 0; |
|
1592 |
} |
|
1593 |
||
1594 |
// --------------------------------------------------------- |
|
1595 |
// CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag |
|
1596 |
// Sends the DeleteTag() calls to lower layers when removing names. |
|
1597 |
// --------------------------------------------------------- |
|
1598 |
// |
|
1599 |
void CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag() |
|
1600 |
{ |
|
1601 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag. iDeleteTagListArray->Count() [%d] Setting iDeleteCallbackCounter = 0", |
|
1602 |
iDeleteTagListArray->Count() ); |
|
1603 |
||
1604 |
if( iDeleteTagListArray->Count() > 0 ) |
|
1605 |
{ |
|
1606 |
||
1607 |
iDeleteCallbackCounter = 0; |
|
1608 |
||
1609 |
for ( TInt k( 0 ); k < iDeleteTagListArray->Count(); k++ ) |
|
1610 |
{ |
|
1611 |
TInt ret = |
|
1612 |
iTagManager->DeleteTag( this, (*iDeleteTagListArray)[k] ); |
|
1613 |
||
1614 |
if ( ret != KErrNone ) |
|
1615 |
{ |
|
1616 |
TRAPD( err, DoHandleEventFailedL(); ); |
|
1617 |
if( err != KErrNone ) |
|
1618 |
{ |
|
1619 |
RUBY_ERROR1( "CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag Error handling Left with [%d]", err ); |
|
1620 |
} |
|
1621 |
return; /** @todo reengineer into single return path */ |
|
1622 |
} |
|
1623 |
} |
|
1624 |
} // if there are tags to delete |
|
1625 |
else |
|
1626 |
{ |
|
1627 |
// if there were no tags to delete (attempt to delete non-existing tags) |
|
1628 |
// simulating callback from successful deletion of.. 0 tags |
|
1629 |
//iDeleteCallbackCounter = -1; |
|
1630 |
//DeleteTagCompleted(); |
|
1631 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesCallDeleteTag Here!" ); |
|
1632 |
} |
|
1633 |
} |
|
1634 |
||
1635 |
// --------------------------------------------------------- |
|
1636 |
// CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted |
|
1637 |
// DeleteTag() callback calls this funciton. It counts |
|
1638 |
// the number of callbacks, and when all callbacks have arrived, |
|
1639 |
// goes to the next phase. |
|
1640 |
// --------------------------------------------------------- |
|
1641 |
// |
|
1642 |
void CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted() |
|
1643 |
{ |
|
1644 |
iDeleteCallbackCounter++; |
|
1645 |
||
1646 |
RUBY_DEBUG2( "CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted. iDeleteCallbackCounter [%d], Count() [%d]", iDeleteCallbackCounter, iDeleteTagListArray->Count() ); |
|
1647 |
||
1648 |
if ( iDeleteCallbackCounter == iDeleteTagListArray->Count() ) |
|
1649 |
{ |
|
1650 |
if( iNormalChangesError == KErrNone ) |
|
1651 |
{ |
|
1652 |
TRAPD( err, RemovingNamesCompletedL() ); |
|
1653 |
if ( err != KErrNone ) |
|
1654 |
{ |
|
1655 |
RUBY_ERROR1( "CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted. Error [%d] in RemovingNamesCompletedL", err ); |
|
1656 |
} |
|
1657 |
} |
|
1658 |
else |
|
1659 |
{ |
|
1660 |
// There is not much we can do about the deletion error |
|
1661 |
// Retrying deletion can cause endless cycle |
|
1662 |
// Sometimes failed deletions are ok (if we tried to delete non-existing tag) |
|
1663 |
/** @todo reengineer SpeechItemTrainer (and/or SRS plugin) to report deletion |
|
1664 |
of non-existing tag as success. After all they are not in the DB */ |
|
1665 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted Deletion failed. Still simulating a successful one" ); |
|
1666 |
TRAPD( err, RemovingNamesCompletedL() ); |
|
1667 |
if ( err != KErrNone ) |
|
1668 |
{ |
|
1669 |
RUBY_ERROR1( "CNssContactHandlerImplementation::DoRemoveNamesAfterDeleteTagCompleted. Error [%d] in RemovingNamesCompletedL", err ); |
|
1670 |
} |
|
1671 |
} // if (iNormalChangesError == KErrNone) else |
|
1672 |
} // if count |
|
1673 |
} |
|
1674 |
||
1675 |
// --------------------------------------------------------- |
|
1676 |
// CNssContactHandlerImplementation::RemovingNamesCompletedL |
|
1677 |
// Cleans up after some names have been removed |
|
1678 |
// --------------------------------------------------------- |
|
1679 |
// |
|
1680 |
void CNssContactHandlerImplementation::RemovingNamesCompletedL() |
|
1681 |
{ |
|
1682 |
RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::RemovingNamesCompletedL" ); |
|
1683 |
iDelList.Close(); |
|
1684 |
||
1685 |
if ( iDeleteTagListArray ) |
|
1686 |
{ |
|
1687 |
iDeleteTagListArray->ResetAndDestroy(); |
|
1688 |
iDeleteCallbackCounter = 0; |
|
1689 |
} |
|
1690 |
||
1691 |
DoAddNamesL(); |
|
1692 |
} |
|
1693 |
||
1694 |
// --------------------------------------------------------- |
|
1695 |
// CNssContactHandlerImplementation::DoAddNamesL |
|
1696 |
// Starts name addition sequence by fetching contacts data and ordering |
|
1697 |
// voice tags training |
|
1698 |
// --------------------------------------------------------- |
|
1699 |
// |
|
1700 |
void CNssContactHandlerImplementation::DoAddNamesL() |
|
1701 |
{ |
|
1702 |
RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::DoAddNamesL" ); |
|
1703 |
TInt k( 0 ); |
|
1704 |
||
1705 |
if ( iAddList.Count() == 0 ) |
|
1706 |
{ |
|
1707 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesL Nothing to add. Setting iState = ECHIdle. Return" ); |
|
1708 |
SetState ( ECHIdle ); |
|
1709 |
// If there are events on the list, DoAddNamesCompleted will fire them |
|
1710 |
DoAddNamesCompletedL(); |
|
1711 |
} |
|
1712 |
else |
|
1713 |
{ |
|
1714 |
// Create new tags and train them. |
|
1715 |
for ( k = 0; k < iAddList.Count(); k++ ) |
|
1716 |
{ |
|
1717 |
// 3 names may be created from one contact: |
|
1718 |
// * Main name (firstname + lastname XOR companyname) |
|
1719 |
// * Reversed order name (usually lastname + firstname, depends on the UI language) |
|
1720 |
// -> only if NSSVAS_CONTACTHANDLER_FREEORDER is defined |
|
1721 |
// * Nickname |
|
1722 |
||
1723 |
TContactData contactData; |
|
1724 |
||
1725 |
contactData.iID = iAddList[k].iContactId; |
|
1726 |
contactData.iSyncTime.UniversalTime(); |
|
1727 |
||
1728 |
// Nickname |
|
1729 |
contactData.iTitle = NULL; |
|
1730 |
TRAPD( err, contactData.iTitle = GetContactNicknameL( iAddList[k].iContactId ) ); |
|
1731 |
||
1732 |
if ( contactData.iTitle != NULL ) |
|
1733 |
{ |
|
1734 |
CleanupStack::PushL( contactData.iTitle ); |
|
1735 |
contactData.iType = ETagTypeNickName; |
|
1736 |
User::LeaveIfError( iContactQueue.Append( contactData ) ); |
|
1737 |
CleanupStack::Pop( contactData.iTitle ); |
|
1738 |
} |
|
1739 |
||
1740 |
// Main name ( Using GetContactTitleL() ) |
|
1741 |
contactData.iTitle = NULL; |
|
1742 |
TBool bothFound = EFalse; |
|
1743 |
TVasTagType tagType( ETagTypeUnknown ); |
|
1744 |
TRAP( err, contactData.iTitle = GetContactTitleL( iAddList[k].iContactId, ETrue, bothFound, tagType ) ); |
|
1745 |
||
1746 |
// If all the name fields are empty, nothing |
|
1747 |
// can be done for the tag. We're finished. |
|
1748 |
if ( contactData.iTitle != NULL ) |
|
1749 |
{ |
|
1750 |
RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesL For Contact id [%d] title is: [%S]", iAddList[k].iContactId, contactData.iTitle ); |
|
1751 |
CleanupStack::PushL( contactData.iTitle ); |
|
1752 |
contactData.iType = tagType; |
|
1753 |
User::LeaveIfError( iContactQueue.Append( contactData ) ); |
|
1754 |
CleanupStack::Pop( contactData.iTitle ); |
|
1755 |
} |
|
1756 |
||
1757 |
#ifdef NSSVAS_CONTACTHANDLER_FREEORDER |
|
1758 |
// Default order added previously, now adding |
|
1759 |
// secondary order if both first and lastnames are found |
|
1760 |
if ( bothFound ) |
|
1761 |
{ |
|
1762 |
contactData.iTitle = NULL; |
|
1763 |
TRAPD( err, contactData.iTitle = GetContactTitleL( iAddList[k].iContactId, EFalse, bothFound, tagType ) ); |
|
1764 |
if ( contactData.iTitle != NULL ) |
|
1765 |
{ |
|
1766 |
CleanupStack::PushL( contactData.iTitle ); |
|
1767 |
contactData.iType = tagType; |
|
1768 |
User::LeaveIfError( iContactQueue.Append( contactData ) ); |
|
1769 |
CleanupStack::Pop( contactData.iTitle ); |
|
1770 |
} |
|
1771 |
} |
|
1772 |
#endif // NSSVAS_CONTACTHANDLER_FREEORDER |
|
1773 |
||
1774 |
} |
|
1775 |
||
1776 |
// No tag had any text. |
|
1777 |
if ( iContactQueue.Count() == 0 ) |
|
1778 |
{ |
|
1779 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesL. No tag had any text, return" ); |
|
1780 |
DoAddNamesCompletedL(); |
|
1781 |
} |
|
1782 |
else |
|
1783 |
{ |
|
1784 |
// At least some tag has some text |
|
1785 |
RUBY_ASSERT_DEBUG( iTagArray.Count() == 0, User::Panic( KFile, __LINE__ ) ); |
|
1786 |
||
1787 |
for ( k = 0; k < iContactQueue.Count(); k++ ) |
|
1788 |
{ |
|
1789 |
// (1) Create a new tag |
|
1790 |
if ( iNewTag != NULL ) |
|
1791 |
{ |
|
1792 |
// If previous call to this function leaves, iNewTag can |
|
1793 |
// be not deleted |
|
1794 |
delete iNewTag; |
|
1795 |
iNewTag = NULL; |
|
1796 |
} |
|
1797 |
iNewTag = iTagManager->CreateTagL( iContext ); |
|
1798 |
||
1799 |
MNssRRD* rrd = iNewTag->RRD(); |
|
1800 |
MNssSpeechItem* speechItem = iNewTag->SpeechItem(); |
|
1801 |
||
1802 |
// (2) Fill RRD. RRD contains client-chosen data about the tag. |
|
1803 |
// In case of name dialing, RRD contains the contact ID, |
|
1804 |
// which is used later to get the phone number. |
|
1805 |
CArrayFixFlat<TInt> *id = new (ELeave) CArrayFixFlat<TInt>( 1 ); |
|
1806 |
||
1807 |
CleanupStack::PushL( id ); |
|
1808 |
||
1809 |
id->AppendL( iContactQueue[k].iID ); // ID |
|
1810 |
// select a number field for voice tag |
|
1811 |
// TInt fieldIndex( 0 ); |
|
1812 |
||
1813 |
WaitUntilNoSyncBackupIsRunning(); |
|
1814 |
TRAPD( err, ReadContactL( iContactQueue[k].iID ); ); |
|
1815 |
if ( err == KErrNone ) |
|
1816 |
{ |
|
1817 |
// 1. Default voice call number set by the user |
|
1818 |
TInt found = KErrNotFound; |
|
1819 |
TRAP( found, iPbkHandler->FindDefaultContactFieldL( EDefaultCommand ) ); |
|
1820 |
||
1821 |
if ( found == KErrNotFound ) |
|
1822 |
{ |
|
1823 |
for( TInt i = 0; i < KTaggableFieldsCount; i++) |
|
1824 |
{ |
|
1825 |
TRAP( found, iPbkHandler->FindFieldL( KTaggableFields[i] ) ); |
|
1826 |
if( found == KErrNone && ( !iPbkHandler->IsFieldEmptyL() ) ) |
|
1827 |
{ |
|
1828 |
break; // found field |
|
1829 |
} |
|
1830 |
else |
|
1831 |
{ |
|
1832 |
// When field->IsEmptyOrAllSpaces(), it is the same for us as no field present |
|
1833 |
found = KErrNotFound; |
|
1834 |
} |
|
1835 |
} // for i < KTaggableFieldsCount |
|
1836 |
} |
|
1837 |
||
1838 |
if ( found == KErrNone ) // found and is not empty |
|
1839 |
{ |
|
1840 |
id->AppendL( iPbkHandler->FieldIdL() ); // field ID to array |
|
1841 |
id->AppendL( EDial ); |
|
1842 |
id->AppendL( iContactQueue[k].iType ); |
|
1843 |
id->AppendL( EDefaultCommand ); |
|
1844 |
rrd->SetIntArrayL ( id ); |
|
1845 |
||
1846 |
// (3) Set the training text. |
|
1847 |
speechItem = iNewTag->SpeechItem(); |
|
1848 |
speechItem->SetTextL( *iContactQueue[k].iTitle ); |
|
1849 |
||
1850 |
User::LeaveIfError( iTagArray.Append( iNewTag ) ); |
|
1851 |
// Leave protection for iNewTag completed |
|
1852 |
// Ownership and deletion responsibility moved |
|
1853 |
// to iTagArray |
|
1854 |
iNewTag = NULL; |
|
1855 |
} |
|
1856 |
else |
|
1857 |
{ |
|
1858 |
// field not found or is empty |
|
1859 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesL Did NOT identify a suitable voice dial field for contact id [%d]", iContactQueue[k].iID); |
|
1860 |
||
1861 |
||
1862 |
delete iNewTag; |
|
1863 |
iNewTag = NULL; |
|
1864 |
} // if field else |
|
1865 |
#ifdef __SIND_EXTENSIONS |
|
1866 |
||
1867 |
// this part creates separate voice tags for extensions |
|
1868 |
for ( TInt i(0); i < iExtensionList.Count(); i++ ) |
|
1869 |
{ |
|
1870 |
found = KErrNotFound; |
|
1871 |
TVasExtensionAction action = iExtensionList[i].iAction; |
|
1872 |
TPbkFieldId fieldId = iExtensionList[i].iId; |
|
1873 |
||
1874 |
// default message number |
|
1875 |
// default video |
|
1876 |
// default e-mail |
|
1877 |
// default VOIP |
|
1878 |
if ( action == ENewMessage || |
|
1879 |
iExtensionList[i].iId == EPbkFieldIdPhoneNumberVideo || |
|
1880 |
iExtensionList[i].iId == EPbkFieldIdEmailAddress || |
|
1881 |
iExtensionList[i].iId == EPbkFieldIdVOIP ) |
|
1882 |
{ |
|
1883 |
// @todo Should use DefaultMessageField or something similar!! |
|
1884 |
TRAP( found, |
|
1885 |
iPbkHandler->FindDefaultContactFieldL( iExtensionList[i].iCommand ) ); |
|
1886 |
} |
|
1887 |
||
1888 |
/*if ( extensionField == NULL ) |
|
1889 |
{ |
|
1890 |
extensionField = item->FindField( iExtensionList[i].iId ); |
|
1891 |
} |
|
1892 |
||
1893 |
if ( extensionField == NULL && field != NULL |
|
1894 |
&& ( action == ENewMessage ) ) |
|
1895 |
{ |
|
1896 |
// if default neither default field or mobile field was not found |
|
1897 |
// message use normal SIND field |
|
1898 |
extensionField = field; |
|
1899 |
fieldId = field->FieldInfo().FieldId(); |
|
1900 |
}*/ |
|
1901 |
||
1902 |
// If field was not found, try to find it based on the priority lists |
|
1903 |
if ( found == KErrNotFound ) |
|
1904 |
{ |
|
1905 |
found = FindExtensionField( action, iExtensionList[i].iId ); |
|
1906 |
// If field was found, check the field ID |
|
1907 |
if ( found == KErrNone ) |
|
1908 |
{ |
|
1909 |
fieldId = iPbkHandler->FieldIdL(); |
|
1910 |
} |
|
1911 |
} |
|
1912 |
||
1913 |
if ( found == KErrNone ) |
|
1914 |
{ |
|
1915 |
// create new tag |
|
1916 |
iNewTag = iTagManager->CreateTagL( iContext ); |
|
1917 |
||
1918 |
rrd = iNewTag->RRD(); |
|
1919 |
speechItem = iNewTag->SpeechItem(); |
|
1920 |
||
1921 |
// set RRD data |
|
1922 |
CArrayFixFlat<TInt> *extIds = new (ELeave) CArrayFixFlat<TInt>( 1 ); |
|
1923 |
CleanupStack::PushL( extIds ); |
|
1924 |
||
1925 |
extIds->AppendL( iContactQueue[k].iID ); |
|
1926 |
if ( iExtensionList[i].iCommand == EMessageCommand || |
|
1927 |
iExtensionList[i].iCommand == EVideoCommand ) |
|
1928 |
{ |
|
1929 |
TInt id = iPbkHandler->FieldIdL(); |
|
1930 |
if ( id ) |
|
1931 |
{ |
|
1932 |
extIds->AppendL( id ); |
|
1933 |
} |
|
1934 |
else |
|
1935 |
{ |
|
1936 |
extIds->AppendL( fieldId ); |
|
1937 |
} |
|
1938 |
} |
|
1939 |
else |
|
1940 |
{ |
|
1941 |
extIds->AppendL( fieldId ); |
|
1942 |
} |
|
1943 |
extIds->AppendL( action ); |
|
1944 |
extIds->AppendL( iContactQueue[k].iType ); |
|
1945 |
extIds->AppendL( iExtensionList[i].iCommand ); |
|
1946 |
||
1947 |
rrd->SetIntArrayL ( extIds ); |
|
1948 |
||
1949 |
// set the training text. |
|
1950 |
TPtr namePtr( iContactQueue[k].iTitle->Des() ); |
|
1951 |
TPtr extensionPtr( iExtensionList[i].iText->Des() ); |
|
1952 |
HBufC* tempTitle = HBufC::NewLC( namePtr.Length() + extensionPtr.Length() + KTrainingIndexSize ); |
|
1953 |
TPtr titlePtr( tempTitle->Des() ); |
|
1954 |
||
1955 |
//not work: titlePtr.AppendFormat( extensionPtr, namePtr ); |
|
1956 |
||
1957 |
titlePtr = extensionPtr; |
|
1958 |
AppendExtensionMarker( titlePtr ); |
|
1959 |
TInt index = titlePtr.Find( KExtensionFormatString ); |
|
1960 |
if ( index >= 0 ) |
|
1961 |
{ |
|
1962 |
// replace %U with name |
|
1963 |
titlePtr.Delete( index, 2 ); // delete %U |
|
1964 |
titlePtr.Insert( index, namePtr ); |
|
1965 |
} |
|
1966 |
speechItem->SetTextL( titlePtr ); |
|
1967 |
||
1968 |
User::LeaveIfError( iTagArray.Append( iNewTag ) ); |
|
1969 |
iNewTag = NULL; //ownership changed |
|
1970 |
CleanupStack::PopAndDestroy( tempTitle ); |
|
1971 |
CleanupStack::PopAndDestroy( extIds ); |
|
1972 |
} |
|
1973 |
} |
|
1974 |
||
1975 |
#endif // __SIND_EXTENSIONS |
|
1976 |
// delete id |
|
1977 |
CleanupStack::PopAndDestroy( id ); |
|
1978 |
} |
|
1979 |
else |
|
1980 |
{ |
|
1981 |
// Opening contact failed. E.g. if it was just deleted by user |
|
1982 |
RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesL Failed to open contact id [%d]. Leave [%d]", iContactQueue[k].iID, err); |
|
1983 |
CleanupStack::PopAndDestroy( id ); |
|
1984 |
delete iNewTag; |
|
1985 |
iNewTag = NULL; |
|
1986 |
/** @todo Try reengineering duplicated cleanups into single piece |
|
1987 |
of the code */ |
|
1988 |
} |
|
1989 |
} // for k .. iContactQueue |
|
1990 |
||
1991 |
if ( iTagArray.Count() == 0 ) |
|
1992 |
{ |
|
1993 |
// If there are events on the list, DoAddNamesCompleted will fire them |
|
1994 |
DoAddNamesCompletedL(); |
|
1995 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesL. Returned from DoAddNamesCompleted. Setting iState = ECHIdle" ); |
|
1996 |
SetState ( ECHIdle ); |
|
1997 |
} |
|
1998 |
else |
|
1999 |
{ |
|
2000 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesL Before training tags. TagCount = [%d]", |
|
2001 |
iTagArray.Count() ); |
|
2002 |
||
2003 |
iTrainCallbackCounter = 0; |
|
2004 |
for ( k = 0; k < iTagArray.Count(); k++ ) |
|
2005 |
{ |
|
2006 |
MNssSpeechItem* speechItem = iTagArray[k]->SpeechItem(); |
|
2007 |
||
2008 |
MNssSpeechItem::TNssSpeechItemResult trainRet |
|
2009 |
= speechItem->TrainTextL( this, iTrainingParams ); |
|
2010 |
||
2011 |
if ( trainRet != MNssSpeechItem::EVasErrorNone ) |
|
2012 |
{ |
|
2013 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesL : TrainTextL call failed." ); |
|
2014 |
// Not much we can do except for timed retry. |
|
2015 |
// This stops the contact handler. |
|
2016 |
DoHandleEventFailedL(); |
|
2017 |
break; // no processing anymore. Quit function |
|
2018 |
} |
|
2019 |
} // for k < iTagArray.Count() |
|
2020 |
} // if iTagArrayCount != 0 |
|
2021 |
} |
|
2022 |
} // if ( iAddList.Count() != 0 ) |
|
2023 |
} |
|
2024 |
||
2025 |
// --------------------------------------------------------- |
|
2026 |
// CNssContactHandlerImplementation::DoAddNamesTrainingFinished |
|
2027 |
// Called after training of a current pack of tags has finished. |
|
2028 |
// Starts saving tags. |
|
2029 |
// --------------------------------------------------------- |
|
2030 |
// |
|
2031 |
void CNssContactHandlerImplementation::DoAddNamesTrainingFinished() |
|
2032 |
{ |
|
2033 |
iSaveCallbackCounter = 0; |
|
2034 |
iRetry = 0; // retry, if save tag fails |
|
2035 |
iNormalChangesError = 0; // to record failures in save tag |
|
2036 |
||
2037 |
DoAddNamesSaveTag(); |
|
2038 |
} |
|
2039 |
||
2040 |
// --------------------------------------------------------- |
|
2041 |
// CNssContactHandlerImplementation::DoAddNamesSaveTag |
|
2042 |
// This function has two branches: |
|
2043 |
// (1) Initiate saving tags |
|
2044 |
// (1) After all tags have been saved, go to the next phase. |
|
2045 |
// --------------------------------------------------------- |
|
2046 |
// |
|
2047 |
void CNssContactHandlerImplementation::DoAddNamesSaveTag() |
|
2048 |
{ |
|
2049 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag" ); |
|
2050 |
TInt retCode; |
|
2051 |
||
2052 |
// If all tags have been saved, go to the next phase. |
|
2053 |
if ( iSaveCallbackCounter == iTagArray.Count() ) |
|
2054 |
{ |
|
2055 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag All tags have been saved, go to the next phase" ); |
|
2056 |
// Tags saved - go to the next phase |
|
2057 |
if ( iNormalChangesError == KErrNone ) |
|
2058 |
{ |
|
2059 |
// This function is called once per 100 contacts -> It is ok to use TRAP |
|
2060 |
TRAPD( error, DoAddNamesCompletedL() ); |
|
2061 |
if( error != KErrNone ) |
|
2062 |
{ |
|
2063 |
/** @todo Test this branch */ |
|
2064 |
// Some fatal error occured |
|
2065 |
RUBY_ERROR1( "DoAddNamesSaveTag DoAddNamesCompletedL failed with [%d]. Disabling SIND", |
|
2066 |
error ); |
|
2067 |
DisableEventHandling(); |
|
2068 |
} |
|
2069 |
} |
|
2070 |
else |
|
2071 |
{ |
|
2072 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag Saving tags failed. Try again a few times" ); |
|
2073 |
// Saving tags failed. Try again a few times, and if it still |
|
2074 |
// doesn't work, go to fatal error handler. |
|
2075 |
if ( iRetry < KVASCHMaxRetry ) |
|
2076 |
{ |
|
2077 |
iRetry++; |
|
2078 |
RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesSaveTag Retried saving [%d] times. [%d] retries left", |
|
2079 |
iRetry, KVASCHMaxRetry - iRetry); |
|
2080 |
iSaveCallbackCounter = 0; |
|
2081 |
iNormalChangesError = KErrNone; |
|
2082 |
||
2083 |
DoAddNamesSaveTag(); |
|
2084 |
} |
|
2085 |
else |
|
2086 |
{ |
|
2087 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesSaveTag Retried saving [%d] times. Still saving fails. Handling error", iRetry ); |
|
2088 |
NormalChangesHandleError(); |
|
2089 |
} |
|
2090 |
} |
|
2091 |
} // if ( iSaveCallbackCounter == iTagArray.Count() ) |
|
2092 |
||
2093 |
// If this is the first call to this function, |
|
2094 |
// make "save tag" calls. After that, wait for the callbacks. |
|
2095 |
else if ( iSaveCallbackCounter == 0 ) |
|
2096 |
{ |
|
2097 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesSaveTag iSaveCallbackCounter == 0. Run SaveTag for [%d] contacts", |
|
2098 |
iTagArray.Count()); |
|
2099 |
for ( TInt k( 0 ); k < iTagArray.Count(); k++ ) |
|
2100 |
{ |
|
2101 |
retCode = iTagManager->SaveTag( this, iTagArray[k] ); |
|
2102 |
||
2103 |
if ( retCode != KErrNone ) |
|
2104 |
{ |
|
2105 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag - SaveTag failed." ); |
|
2106 |
TRAPD( err, DoHandleEventFailedL(); ); |
|
2107 |
if( err != KErrNone ) |
|
2108 |
{ |
|
2109 |
RUBY_ERROR1( "CNssContactHandlerImplementation::DoAddNamesSaveTag handling error Left with [%d]", err ); |
|
2110 |
} |
|
2111 |
return; |
|
2112 |
} // if retCode |
|
2113 |
} // for iTagArray |
|
2114 |
} // else if iSaveCallbackCounter == 0 |
|
2115 |
else |
|
2116 |
{ |
|
2117 |
// iSaveCallbackCounter != 0, but different from iTagArray.Count() |
|
2118 |
// This means, that SaveTag callbacks are still coming. We will wait for them |
|
2119 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesSaveTag. iSaveCallbackCounter != 0, but different from iTagArray.Count()" ); |
|
2120 |
} |
|
2121 |
} |
|
2122 |
||
2123 |
// --------------------------------------------------------- |
|
2124 |
// CNssContactHandlerImplementation::DoAddNamesSaveTagCompleted |
|
2125 |
// Saving single tag has completed. |
|
2126 |
// --------------------------------------------------------- |
|
2127 |
// |
|
2128 |
void CNssContactHandlerImplementation::DoAddNamesSaveTagCompleted( TInt aError ) |
|
2129 |
{ |
|
2130 |
iSaveCallbackCounter++; |
|
2131 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesSaveTagCompleted iSaveCallbackCounter became [%d]", |
|
2132 |
iSaveCallbackCounter); |
|
2133 |
// |= to let single KErrGeneral fail any number of KErrNone |
|
2134 |
iNormalChangesError |= aError; |
|
2135 |
||
2136 |
// Check if all tags have been saved. |
|
2137 |
DoAddNamesSaveTag(); |
|
2138 |
} |
|
2139 |
||
2140 |
// --------------------------------------------------------- |
|
2141 |
// CNssContactHandlerImplementation::DoAddNamesCompleted |
|
2142 |
// When adding names has successfully finished, clean up. |
|
2143 |
// --------------------------------------------------------- |
|
2144 |
// |
|
2145 |
void CNssContactHandlerImplementation::DoAddNamesCompletedL() |
|
2146 |
{ |
|
2147 |
RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesCompleted. iDeleteCallbackCounter [%d], Count() [%d]", iDeleteCallbackCounter, iDeleteTagListArray->Count() ); |
|
2148 |
TInt initialDeleteTagListCount = iDeleteTagListArray->Count(); |
|
2149 |
||
2150 |
iSaveCallbackCounter = 0; |
|
2151 |
iTrainCallbackCounter = 0; |
|
2152 |
||
2153 |
// DoAddNamesCompleted if often called after voice tags have been added => |
|
2154 |
// Nothing has to be done at all |
|
2155 |
TBool changedDatabase = EFalse; |
|
2156 |
||
2157 |
#ifndef __SIND_EXTENSIONS |
|
2158 |
// Set VAS_SETS_VOICETAG on if old behaviour is needed. |
|
2159 |
// That is, VAS sets on the voice tag field to Phonebook engine and Phonebook UI checks the contacts DB for voice tags. |
|
2160 |
// Off means that VAS does not set voice tag field but instead Phonebook asks from VAS. |
|
2161 |
#ifdef VAS_SETS_VOICETAG |
|
2162 |
// add voice tag fields |
|
2163 |
// iTagArray contains only successfully trained tags. |
|
2164 |
// Failed items are removed. |
|
2165 |
for ( TInt i( 0 ); i < iTagArray.Count(); i++ ) |
|
2166 |
{ |
|
2167 |
MNssRRD* rrd = iTagArray[i]->RRD(); |
|
2168 |
CArrayFixFlat<TInt>* intArray = rrd->IntArray(); |
|
2169 |
RUBY_ASSERT_DEBUG( intArray->Count() >= 2, User::Panic( KFile, __LINE__ ) ); |
|
2170 |
if ( intArray->Count() >= 2 ) |
|
2171 |
{ |
|
2172 |
TBool committed( EFalse ); // ETrue if contact is committed already |
|
2173 |
TInt contactId( intArray->At( 0 ) ); |
|
2174 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesCompleted. Working on contact id [%d]", |
|
2175 |
contactId); |
|
2176 |
TInt fieldId( intArray->At( 1 ) ); |
|
2177 |
||
2178 |
WaitUntilNoSyncBackupIsRunning(); |
|
2179 |
// Open contact item based on id |
|
2180 |
TRAPD( errFor, |
|
2181 |
OpenContactL( contactId ); |
|
2182 |
||
2183 |
RUBY_DEBUG1( "DoAddNamesCompleted Opened contact [%d]", contactId ); |
|
2184 |
TInt found == KErrNotFound; |
|
2185 |
TRAP( found, iPbkHandler->FindDefaultContactFieldL( EDefaultCommand ) ); |
|
2186 |
if ( found == KErrNotFound ) |
|
2187 |
{ |
|
2188 |
TRAP( found, iPbkHandler->FindFieldL( fieldId ) ); |
|
2189 |
} |
|
2190 |
// field - field, that SHOULD have voice tag attached |
|
2191 |
||
2192 |
if ( found == KErrNone ) |
|
2193 |
{ |
|
2194 |
TRAP( error, iPbkHandler->ChangeVoiceTagFieldL( ETrue ) ); |
|
2195 |
if ( error == KErrNone ) |
|
2196 |
{ |
|
2197 |
RUBY_DEBUG1("DoAddNamesCompleted Successfully added icon to the contact [%d]", |
|
2198 |
contactId); |
|
2199 |
iPbkHandler->CloseContactL( ETrue ); |
|
2200 |
RUBY_DEBUG1("DoAddNamesCompleted Successfully committed contact [%d]", |
|
2201 |
contactId); |
|
2202 |
iVoiceTagAddedList.Append( contactId ); |
|
2203 |
changedDatabase = ETrue; |
|
2204 |
committed = ETrue; |
|
2205 |
} |
|
2206 |
} |
|
2207 |
else |
|
2208 |
{ |
|
2209 |
// field not found anymore |
|
2210 |
RUBY_DEBUG2("DoAddNamesCompleted Field [%d] not found in (already deleted from?) contact [%d]", |
|
2211 |
fieldId, contactId ); |
|
2212 |
iDeleteTagListArray->AppendL( NULL ); // One DeleteTag will generate one callback |
|
2213 |
iTagManager->DeleteTag( this, iTagArray[i] ); |
|
2214 |
} |
|
2215 |
if ( !committed ) |
|
2216 |
{ |
|
2217 |
RUBY_DEBUG1("DoAddNamesCompleted Did not change contact [%d]. Closing without committing", |
|
2218 |
contactId); |
|
2219 |
iPbkHandler->CloseContactL( EFalse ); |
|
2220 |
} |
|
2221 |
); // TRAPD errFor |
|
2222 |
if ( errFor != KErrNone ) |
|
2223 |
{ |
|
2224 |
RUBY_DEBUG2("CNssContactHandlerImplementation::DoAddNamesCompleted Failed to add icon for contact [%d]. Error [%d]", |
|
2225 |
contactId, errFor); |
|
2226 |
// voice tag was not in the contacts database, delete it from VAS |
|
2227 |
// One DeleteTag will generate one callback |
|
2228 |
iDeleteTagListArray->AppendL( NULL ); |
|
2229 |
iTagManager->DeleteTag( this, iTagArray[i] ); |
|
2230 |
} |
|
2231 |
} // if intArray->Count() >= 2 |
|
2232 |
} // for iTagArray |
|
2233 |
#endif // VAS_SETS_VOICETAG |
|
2234 |
#endif //__SIND_EXTENSIONS |
|
2235 |
||
2236 |
iTagArray.ResetAndDestroy(); |
|
2237 |
||
2238 |
iAddList.Close(); |
|
2239 |
||
2240 |
#ifndef __SIND_EXTENSIONS |
|
2241 |
#ifdef VAS_SETS_VOICETAG |
|
2242 |
// Remove voice tag icons for contacts, that failed to be trained or saved |
|
2243 |
for( TInt l = 0 ; l < iRemoveIconList.Count(); l++ ) |
|
2244 |
{ |
|
2245 |
WaitUntilNoSyncBackupIsRunning(); |
|
2246 |
TRAPD( error, OpenContactL( iRemoveIconList[l] ) ); |
|
2247 |
if ( error != KErrNone ) |
|
2248 |
{ |
|
2249 |
RUBY_DEBUG2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to open contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2250 |
} |
|
2251 |
else |
|
2252 |
{ |
|
2253 |
TRAP( error, iPbkHandler->ChangeVoiceTagFieldL( EFalse ) ); |
|
2254 |
if ( error == KErrNotFound ) |
|
2255 |
{ |
|
2256 |
// Nothing to remove. Already no voice tag icon |
|
2257 |
TRAP( error, iPbkHandler->CloseContactL( EFalse ) ); |
|
2258 |
if ( error != KErrNone ) |
|
2259 |
{ |
|
2260 |
RUBY_ERROR2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to close contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2261 |
} |
|
2262 |
} |
|
2263 |
else if ( error != KErrNone ) |
|
2264 |
{ |
|
2265 |
RUBY_ERROR2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to remove voice tag icon for contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2266 |
TRAP( error, iPbkHandler->CloseContactL( EFalse ) ); |
|
2267 |
if ( error != KErrNone ) |
|
2268 |
{ |
|
2269 |
RUBY_ERROR2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to close contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2270 |
} |
|
2271 |
} |
|
2272 |
else |
|
2273 |
{ |
|
2274 |
iVoiceTagAddedList.Append( iRemoveIconList[l] ); |
|
2275 |
TRAP( error, iPbkHandler->CloseContactL( ETrue ) ); |
|
2276 |
if ( error != KErrNone ) |
|
2277 |
{ |
|
2278 |
RUBY_ERROR2( "CNssContactHandlerImplementation::DoAddNamesCompleted Failed to commit contact [%d]. Error [%d]", iRemoveIconList[l], error); |
|
2279 |
} |
|
2280 |
} |
|
2281 |
||
2282 |
} // if opened contact successfully |
|
2283 |
||
2284 |
} |
|
2285 |
#endif // VAS_SETS_VOICETAG |
|
2286 |
#endif //__SIND_EXTENSIONS |
|
2287 |
||
2288 |
iRemoveIconList.Close(); |
|
2289 |
||
2290 |
for( TInt k( 0 ); k < iContactQueue.Count(); k++ ) |
|
2291 |
{ |
|
2292 |
delete iContactQueue[k].iTitle; |
|
2293 |
iContactQueue[k].iTitle = NULL; |
|
2294 |
} |
|
2295 |
iContactQueue.Close(); |
|
2296 |
||
2297 |
if( changedDatabase ) |
|
2298 |
{ |
|
2299 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted changed DBx" ); |
|
2300 |
WaitUntilNoSyncBackupIsRunning(); |
|
2301 |
TRAPD(err, iPbkHandler->CompressL() ); |
|
2302 |
if ( err ) |
|
2303 |
{ |
|
2304 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesCompleted Contacts DB compression failed. Error [%d]", |
|
2305 |
err); |
|
2306 |
} |
|
2307 |
} |
|
2308 |
else |
|
2309 |
{ |
|
2310 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted did NOT change DB" ); |
|
2311 |
} |
|
2312 |
||
2313 |
// full resyncs are always tag additions |
|
2314 |
if( initialDeleteTagListCount == iDeleteTagListArray->Count() ) |
|
2315 |
{ |
|
2316 |
SetState( ECHIdle ); |
|
2317 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted Syncing with phonebook generated NO deletions" ); |
|
2318 |
// then full resync will not be initiated |
|
2319 |
iConsecutiveErrorFullResync = 0; |
|
2320 |
if ( iEventArray.Count() > 0 ) |
|
2321 |
{ |
|
2322 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesCompleted There are still [%d] events in the queue. Call DoHandleEvents for them", |
|
2323 |
iEventArray.Count() ); |
|
2324 |
TRAPD( err, DoHandleEventsL() ); |
|
2325 |
if ( err != KErrNone ) |
|
2326 |
{ |
|
2327 |
RUBY_ERROR1( "CNssContactHandlerImplementation::DoAddNamesCompleted. Error [%d] in DoHandleEventsL", err ); |
|
2328 |
} |
|
2329 |
} |
|
2330 |
else |
|
2331 |
{ |
|
2332 |
// No self-generated events, and no pending events to handle |
|
2333 |
// This is the only place in the code, where everything is completed |
|
2334 |
// and nothing is pending |
|
2335 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted All the updates completed. No DB event is pending" ); |
|
2336 |
||
2337 |
} |
|
2338 |
} |
|
2339 |
else |
|
2340 |
{ |
|
2341 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoAddNamesCompleted Generated [%d] deletions. Starting to wait for callbacks", |
|
2342 |
iDeleteTagListArray->Count() - initialDeleteTagListCount); |
|
2343 |
} |
|
2344 |
||
2345 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoAddNamesCompleted completed" ); |
|
2346 |
} |
|
2347 |
||
2348 |
// --------------------------------------------------------- |
|
2349 |
// CNssContactHandlerImplementation::NormalChangesHandleError |
|
2350 |
// Handle errors which happend when updating normal changes |
|
2351 |
// --------------------------------------------------------- |
|
2352 |
// |
|
2353 |
void CNssContactHandlerImplementation::NormalChangesHandleError() |
|
2354 |
{ |
|
2355 |
// We can't know, what went wrong. |
|
2356 |
// Stop contact handler, so that the next time the phone is booted |
|
2357 |
// full synchronization happens. |
|
2358 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::NormalChangesHandleError " ); |
|
2359 |
TRAPD( err, DoHandleEventFailedL(); ); |
|
2360 |
if( err != KErrNone ) |
|
2361 |
{ |
|
2362 |
RUBY_ERROR1( "CNssContactHandlerImplementation::NormalChangesHandleError DoHandleEventFailedL Left with [%d]", err ); |
|
2363 |
} |
|
2364 |
} |
|
2365 |
||
2366 |
//--------------------------------------------------------- |
|
2367 |
// CNssContactHandlerImplementation::HandleTrainComplete |
|
2368 |
// Saves the tag after successful training. |
|
2369 |
//--------------------------------------------------------- |
|
2370 |
// |
|
2371 |
void CNssContactHandlerImplementation::HandleTrainComplete( TInt aErrorCode ) |
|
2372 |
{ |
|
2373 |
if( aErrorCode == KErrNone ) |
|
2374 |
{ |
|
2375 |
RUBY_DEBUG1( "Training OK for %d:th name.", iTrainCallbackCounter ); |
|
2376 |
||
2377 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::HandleTrainComplete. iState [%d]", iState); |
|
2378 |
RUBY_ASSERT_DEBUG( iState == ECHInitializing || |
|
2379 |
iState == ECHHandlingNormalChanges, |
|
2380 |
User::Panic( KFile, __LINE__ ) ); |
|
2381 |
||
2382 |
iTrainCallbackCounter++; |
|
2383 |
||
2384 |
if ( iTrainCallbackCounter == iTagArray.Count() ) |
|
2385 |
{ |
|
2386 |
if ( iState != ECHInitializing ) |
|
2387 |
{ |
|
2388 |
// assert at the beginning of the function guarantees, |
|
2389 |
// that iState == ECHHandlingNormalChanges |
|
2390 |
DoAddNamesTrainingFinished(); |
|
2391 |
} |
|
2392 |
} |
|
2393 |
} |
|
2394 |
||
2395 |
else // aErrorCode != KErrNone |
|
2396 |
{ |
|
2397 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::HandleTrainComplete. Training failed for %d:th name.\n", |
|
2398 |
iTrainCallbackCounter ); |
|
2399 |
||
2400 |
RUBY_ASSERT_DEBUG( iState == ECHInitializing || |
|
2401 |
iState == ECHHandlingNormalChanges, |
|
2402 |
User::Panic( KFile, __LINE__ ) ); |
|
2403 |
||
2404 |
// Order removal of voice tag icon if present |
|
2405 |
MNssRRD* rrd = iTagArray[iTrainCallbackCounter]->RRD(); |
|
2406 |
CArrayFixFlat<TInt>* intArray = rrd->IntArray(); |
|
2407 |
RUBY_ASSERT_DEBUG( intArray->Count() >= 2, User::Panic( KFile, __LINE__ ) ); |
|
2408 |
if ( intArray->Count() >= 2 ) |
|
2409 |
{ |
|
2410 |
TInt error = iRemoveIconList.Append( intArray->At(0) ); |
|
2411 |
if( error != KErrNone ) |
|
2412 |
{ |
|
2413 |
RUBY_ERROR2( "CNssContactHandlerImplementation::HandleTrainError Failed to insert [%d] into iRemoveIconList. Error [%d]", |
|
2414 |
intArray->At(0), error); |
|
2415 |
} |
|
2416 |
} |
|
2417 |
else |
|
2418 |
{ |
|
2419 |
RUBY_ERROR2( "CNssContactHandlerImplementation::HandleTrainComplete rrd->IntArray()->Count [%d] for iTrainCallbackCounter [%d]", |
|
2420 |
intArray->Count(), iTrainCallbackCounter); |
|
2421 |
} |
|
2422 |
||
2423 |
||
2424 |
delete iTagArray[ iTrainCallbackCounter ]; |
|
2425 |
iTagArray.Remove( iTrainCallbackCounter ); |
|
2426 |
||
2427 |
if ( iTrainCallbackCounter == iTagArray.Count() ) |
|
2428 |
{ |
|
2429 |
if ( iState == ECHHandlingNormalChanges ) |
|
2430 |
{ |
|
2431 |
DoAddNamesTrainingFinished(); |
|
2432 |
} |
|
2433 |
else |
|
2434 |
{ |
|
2435 |
RUBY_ERROR1( "CNssContactHandlerImplementation::HandleTrainComplete Unexpected state [%d]", iState); |
|
2436 |
} |
|
2437 |
} |
|
2438 |
} |
|
2439 |
} |
|
2440 |
||
2441 |
//--------------------------------------------------------- |
|
2442 |
// CNssContactHandlerImplementation::HandleTrainError |
|
2443 |
// Handles single tag training failure |
|
2444 |
//--------------------------------------------------------- |
|
2445 |
// |
|
2446 |
/*void CNssContactHandlerImplementation::HandleTrainError( enum MNssTrainTextEventHandler::TNssTrainResult ) |
|
2447 |
{ |
|
2448 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::HandleTrainError Training failed for %d:th name.\n", |
|
2449 |
iTrainCallbackCounter ); |
|
2450 |
||
2451 |
RUBY_ASSERT_DEBUG( iState == ECHInitializing || |
|
2452 |
iState == ECHHandlingNormalChanges, |
|
2453 |
User::Panic( KFile, __LINE__ ) ); |
|
2454 |
||
2455 |
// Order removal of voice tag icon if present |
|
2456 |
MNssRRD* rrd = iTagArray[iTrainCallbackCounter]->RRD(); |
|
2457 |
CArrayFixFlat<TInt>* intArray = rrd->IntArray(); |
|
2458 |
RUBY_ASSERT_DEBUG( intArray->Count() >= 2, User::Panic( KFile, __LINE__ ) ); |
|
2459 |
if ( intArray->Count() >= 2 ) |
|
2460 |
{ |
|
2461 |
TInt error = iRemoveIconList.Append( intArray->At(0) ); |
|
2462 |
if( error != KErrNone ) |
|
2463 |
{ |
|
2464 |
RUBY_ERROR2( "CNssContactHandlerImplementation::HandleTrainError Failed to insert [%d] into iRemoveIconList. Error [%d]", |
|
2465 |
intArray->At(0), error); |
|
2466 |
} |
|
2467 |
} |
|
2468 |
else |
|
2469 |
{ |
|
2470 |
RUBY_ERROR2( "CNssContactHandlerImplementation::HandleTrainError rrd->IntArray()->Count [%d] for iTrainCallbackCounter [%d]", |
|
2471 |
intArray->Count(), iTrainCallbackCounter); |
|
2472 |
} |
|
2473 |
||
2474 |
||
2475 |
delete iTagArray[ iTrainCallbackCounter ]; |
|
2476 |
iTagArray.Remove( iTrainCallbackCounter ); |
|
2477 |
||
2478 |
if ( iTrainCallbackCounter == iTagArray.Count() ) |
|
2479 |
{ |
|
2480 |
if ( iState == ECHHandlingNormalChanges ) |
|
2481 |
{ |
|
2482 |
DoAddNamesTrainingFinished(); |
|
2483 |
} |
|
2484 |
else |
|
2485 |
{ |
|
2486 |
RUBY_ERROR1( "CNssContactHandlerImplementation::HandleTrainError Unexpected state [%d]", iState); |
|
2487 |
} |
|
2488 |
} |
|
2489 |
}*/ |
|
2490 |
||
2491 |
//--------------------------------------------------------- |
|
2492 |
// CNssContactHandlerImplementation::FullResyncStart |
|
2493 |
// Starts a full synchronization |
|
2494 |
//--------------------------------------------------------- |
|
2495 |
// |
|
2496 |
void CNssContactHandlerImplementation::FullResyncStart() |
|
2497 |
{ |
|
2498 |
// If we have synchronized earlier, we must delete the old context. |
|
2499 |
if ( iHaveWeEverSynced ) |
|
2500 |
{ |
|
2501 |
iContextManager->DeleteContext( this, iContext ); |
|
2502 |
} |
|
2503 |
else |
|
2504 |
{ |
|
2505 |
TRAPD( err, FullResyncCreateContextL() ); |
|
2506 |
if ( err != KErrNone ) |
|
2507 |
{ |
|
2508 |
RUBY_ERROR1( "CNssContactHandlerImplementation::FullResyncStart. Error [%d] in FullResyncCreateContextL", err ); |
|
2509 |
} |
|
2510 |
} |
|
2511 |
} |
|
2512 |
||
2513 |
// ------------------------------------------------------------ |
|
2514 |
// CNssContactHandlerImplementation::FullResyncCreateContextL |
|
2515 |
// Full resync: Create a new context |
|
2516 |
// (prev: Destroy old context, next:populate the context with tags) |
|
2517 |
// ------------------------------------------------------------ |
|
2518 |
// |
|
2519 |
void CNssContactHandlerImplementation::FullResyncCreateContextL() |
|
2520 |
{ |
|
2521 |
RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::FullResyncCreateContextL" ); |
|
2522 |
if ( iContext != 0 ) |
|
2523 |
{ |
|
2524 |
delete iContext; |
|
2525 |
iContext = 0; |
|
2526 |
} |
|
2527 |
||
2528 |
iContext = iContextManager->CreateContextL(); |
|
2529 |
iContext->SetNameL( KNssCHNameDialContext ); |
|
2530 |
iContext->SetGlobal( ETrue ); |
|
2531 |
||
2532 |
TBuf8<KClientDataSize> clientDataBuf; |
|
2533 |
iClientData.iLanguage = User::Language(); |
|
2534 |
iClientData.iContactSyncId = KErrNotFound; |
|
2535 |
||
2536 |
TRAPD( error, iClientData.ExternalizeL( clientDataBuf ) ); |
|
2537 |
if ( !error ) |
|
2538 |
{ |
|
2539 |
iContext->SetClientData( clientDataBuf ); |
|
2540 |
iContextManager->SaveContext( this, iContext ); |
|
2541 |
} |
|
2542 |
} |
|
2543 |
||
2544 |
// ------------------------------------------------------------ |
|
2545 |
// CNssContactHandlerImplementation::FullResyncCreateChanges |
|
2546 |
// Create tags and send training requests to VAS. |
|
2547 |
// VAS trains them and calls back when it's ready |
|
2548 |
// ------------------------------------------------------------ |
|
2549 |
// |
|
2550 |
void CNssContactHandlerImplementation::FullResyncCreateChangesL() |
|
2551 |
{ |
|
2552 |
RUBY_DEBUG_BLOCK( "CNssContactHandlerImplementation::FullResyncCreateChangesL" ); |
|
2553 |
||
2554 |
WaitUntilNoSyncBackupIsRunning(); |
|
2555 |
||
2556 |
CContactIdArray* ids = iPbkHandler->ContactIdArrayLC(); |
|
2557 |
||
2558 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::FullResyncCreateChanges. iContactQueue.Count() == 0" ); |
|
2559 |
RUBY_ASSERT_DEBUG( iContactQueue.Count() == 0, User::Panic( KFile, __LINE__ ) ); |
|
2560 |
// Create change events for training |
|
2561 |
for ( TInt k( 0 ); k < ids->Count(); k++ ) |
|
2562 |
{ |
|
2563 |
TPhonebookEvent event; |
|
2564 |
event.iContactId = (*ids)[k]; |
|
2565 |
event.iType = EContactAdded; |
|
2566 |
iEventArray.Append( event ); |
|
2567 |
} |
|
2568 |
||
2569 |
CleanupStack::PopAndDestroy( ids ); // Cleanup stack: empty |
|
2570 |
||
2571 |
// go to processing events |
|
2572 |
SetState ( ECHIdle ); |
|
2573 |
TRAPD( err, DoHandleEventsL() ); |
|
2574 |
if ( err != KErrNone ) |
|
2575 |
{ |
|
2576 |
RUBY_ERROR1( "CNssContactHandlerImplementation::FullResyncCreateChanges. Error [%d] in DoHandleEventsL", err ); |
|
2577 |
} |
|
2578 |
} |
|
2579 |
||
2580 |
// ------------------------------------------------------------ |
|
2581 |
// CNssContactHandlerImplementation::DeleteContextCompleted |
|
2582 |
// DeleteContext callback. Deleting a context is part of |
|
2583 |
// full synchronization. |
|
2584 |
// ------------------------------------------------------------ |
|
2585 |
// |
|
2586 |
void CNssContactHandlerImplementation::DeleteContextCompleted( TInt aErrorCode ) |
|
2587 |
{ |
|
2588 |
if( aErrorCode == KErrNone ) |
|
2589 |
{ |
|
2590 |
// Go to the next phase of full synchronization |
|
2591 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DeleteContextCompleted. iState == ECHFullResync, iState [%d]", iState ); |
|
2592 |
RUBY_ASSERT_DEBUG( iState == ECHFullResync, User::Panic( KFile, __LINE__ ) ); |
|
2593 |
TRAPD( err, FullResyncCreateContextL() ); |
|
2594 |
if ( err != KErrNone ) |
|
2595 |
{ |
|
2596 |
RUBY_ERROR1( "CNssContactHandlerImplementation::DeleteContextCompleted. Error [%d] in FullResyncCreateContextL", err ); |
|
2597 |
} |
|
2598 |
} |
|
2599 |
else |
|
2600 |
{ |
|
2601 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DeleteContextCompleted failed" ); |
|
2602 |
RUBY_ASSERT_DEBUG( iState == ECHFullResync, User::Panic( KFile, __LINE__ ) ); |
|
2603 |
||
2604 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DeleteContextCompleted - can't handle, stopping." ); |
|
2605 |
TRAPD( err, DoHandleEventFailedL(); ); |
|
2606 |
if( err != KErrNone ) |
|
2607 |
{ |
|
2608 |
RUBY_ERROR1( "CNssContactHandlerImplementation::DeleteContextCompleted Left with [%d]", err); |
|
2609 |
} |
|
2610 |
} |
|
2611 |
} |
|
2612 |
||
2613 |
// ------------------------------------------------------------ |
|
2614 |
// CNssContactHandlerImplementation::CausedByVoiceTagAddition |
|
2615 |
// Check if the event was caused by voice tag field adding |
|
2616 |
// ------------------------------------------------------------ |
|
2617 |
// |
|
2618 |
TBool CNssContactHandlerImplementation::CausedByVoiceTagAddition( const TPhonebookEvent& aEvent ) |
|
2619 |
{ |
|
2620 |
TBool isVoiceTagAddedEvent (EFalse); |
|
2621 |
if( EContactChanged == aEvent.iType ) |
|
2622 |
{ |
|
2623 |
for ( TInt i = 0; i < iVoiceTagAddedList.Count(); i++ ) |
|
2624 |
{ |
|
2625 |
if ( aEvent.iContactId == iVoiceTagAddedList[i] ) |
|
2626 |
{ |
|
2627 |
isVoiceTagAddedEvent = ETrue; |
|
2628 |
iVoiceTagAddedList.Remove( i-- ); // "i--" because of removal |
|
2629 |
// Continue iterations. We are not sure if voice tag for the given |
|
2630 |
// contact could be changed twice |
|
2631 |
} |
|
2632 |
} // for |
|
2633 |
} // if event type |
|
2634 |
return isVoiceTagAddedEvent; |
|
2635 |
} |
|
2636 |
||
2637 |
// ------------------------------------------------------------ |
|
2638 |
// CNssContactHandlerImplementation::PeriodicCallback |
|
2639 |
// Static callback required by Symbian Timer services. |
|
2640 |
// ------------------------------------------------------------ |
|
2641 |
// |
|
2642 |
TInt CNssContactHandlerImplementation::PeriodicCallback( TAny* pX ) |
|
2643 |
{ |
|
2644 |
((CNssContactHandlerImplementation*)pX)->DoPeriodicCallback(); |
|
2645 |
return KErrNone; // useless for CPeriodic |
|
2646 |
} |
|
2647 |
||
2648 |
// ------------------------------------------------------------ |
|
2649 |
// CNssContactHandlerImplementation::DoPeriodicCallback |
|
2650 |
// Periodically check if there are some events to process |
|
2651 |
// ------------------------------------------------------------ |
|
2652 |
// |
|
2653 |
void CNssContactHandlerImplementation::DoPeriodicCallback() |
|
2654 |
{ |
|
2655 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoPeriodicCallback" ); |
|
2656 |
// Check is needed to eliminate unnesessary TRAP and 64 bit time operations |
|
2657 |
// Note, that we are not checking for PeriodicAction(), but for iPeriodicHandleEventTimer == NULL |
|
2658 |
// PeriodicAction() is a method for detection of start of the action, |
|
2659 |
// while iPeriodicHandleEventTimer == NULL says if periodic action is being executed |
|
2660 |
// right *now* |
|
2661 |
||
2662 |
if ( ( iState == ECHIdle ) && ( iEventArray.Count() > 0 ) && ( !PeriodicAction() ) ) |
|
2663 |
{ |
|
2664 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::DoPeriodicCallback. iState is ECHIdle, there are [%d] events to handle and no periodic action in progress", iEventArray.Count()); |
|
2665 |
TRAPD( err, DoHandleEventsL()); |
|
2666 |
if ( err != KErrNone ) |
|
2667 |
{ |
|
2668 |
RUBY_ERROR1( "CNssContactHandlerImplementation::DoPeriodicCallback. Error [%d] in DoHandleEventsL", err ); |
|
2669 |
} |
|
2670 |
} // if there are some events |
|
2671 |
else |
|
2672 |
{ |
|
2673 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::DoPeriodicCallback No events to handle" ); |
|
2674 |
} |
|
2675 |
} |
|
2676 |
||
2677 |
// --------------------------------------------------------- |
|
2678 |
// CNssContactHandlerImplementation::PeriodicAction |
|
2679 |
// Detects periodic action. |
|
2680 |
// Checks if many events have been received "lately" |
|
2681 |
// --------------------------------------------------------- |
|
2682 |
// |
|
2683 |
TBool CNssContactHandlerImplementation::PeriodicAction() |
|
2684 |
{ |
|
2685 |
// index of the first recorded call |
|
2686 |
TInt checkedIndex = iEventMomentIndex + 1; |
|
2687 |
checkedIndex = checkedIndex < KEventMomentsSize ? checkedIndex : 0; |
|
2688 |
TTime& checkedTime = iEventMoments[checkedIndex]; |
|
2689 |
||
2690 |
// Check if the first recorded call happened "lately" = within last |
|
2691 |
// KPeriodicActionInterval seconds |
|
2692 |
TTime currentTime; |
|
2693 |
currentTime.UniversalTime(); |
|
2694 |
TTimeIntervalMicroSeconds diff = currentTime.MicroSecondsFrom( checkedTime ); |
|
2695 |
TBool result = diff < iEndOfPeriodicActionInterval; |
|
2696 |
if ( result == EFalse ) |
|
2697 |
{ |
|
2698 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::PeriodicAction. Periodic action completed." ); |
|
2699 |
RUBY_DEBUG2( "CNssContactHandlerImplementation::PeriodicAction. Periodic action completed. iEventMomentIndex [%d], checkedIndex [%d]", iEventMomentIndex, checkedIndex ); |
|
2700 |
RUBY_DEBUG1( "currentTime [%d]", I64INT(currentTime.Int64())); |
|
2701 |
RUBY_DEBUG2( "CNssContactHandlerImplementation::PeriodicAction. diff [%d], iEndOfPeriodicActionInterval [%d]", I64INT(diff.Int64()), I64INT(iEndOfPeriodicActionInterval.Int64() ) ); |
|
2702 |
||
2703 |
for( TInt i = 0; i < KEventMomentsSize; i++ ) |
|
2704 |
{ |
|
2705 |
RUBY_DEBUG2( "checkedIndex[%d] = [%d]", i, I64INT(iEventMoments[i].Int64() ) ); |
|
2706 |
} |
|
2707 |
||
2708 |
// Periodic action completed. Or hasn't even been started |
|
2709 |
// Restore timeout values |
|
2710 |
// iEndOfPeriodicActionInterval = KInitialPeriodicActionInterval; |
|
2711 |
if ( iPeriodicHandleEventTimer != NULL ) |
|
2712 |
{ |
|
2713 |
// stop the timer, it was started, when periodic action was started |
|
2714 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::PeriodicAction Stopping the periodic action timer" ); |
|
2715 |
iPeriodicHandleEventTimer->Cancel(); |
|
2716 |
delete iPeriodicHandleEventTimer; |
|
2717 |
iPeriodicHandleEventTimer = NULL; |
|
2718 |
} |
|
2719 |
} |
|
2720 |
else |
|
2721 |
{ |
|
2722 |
// Periodic action detected |
|
2723 |
// start the timer if it is not running yet |
|
2724 |
if( iPeriodicHandleEventTimer == NULL ) |
|
2725 |
{ |
|
2726 |
TRAPD( err, iPeriodicHandleEventTimer = CPeriodic::NewL( EPriorityNormal ) ); |
|
2727 |
if( err != KErrNone ) |
|
2728 |
{ |
|
2729 |
// This is a bad situation, but not the fatal one. |
|
2730 |
// If we cannot use timer to detect end of periodic action, |
|
2731 |
// Let's disable periodic action detection at all |
|
2732 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::PeriodicAction. PeriodicTimer creation failed. Error [%d]. Disabling periodic actions", err); |
|
2733 |
result = EFalse; |
|
2734 |
} |
|
2735 |
else |
|
2736 |
{ // Timer was created successfully |
|
2737 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::PeriodicAction Starting the periodic action timer" ); |
|
2738 |
iPeriodicHandleEventTimer->Start( KPeriodicTimerInterval, KPeriodicTimerInterval, TCallBack( PeriodicCallback, this ) ); |
|
2739 |
} |
|
2740 |
} |
|
2741 |
} |
|
2742 |
return result; |
|
2743 |
} |
|
2744 |
||
2745 |
// ------------------------------------------------------------ |
|
2746 |
// CNssContactHandlerImplementation::UpdatePeriodicActionVars |
|
2747 |
// Update variables, used to detect if periodic action is happening |
|
2748 |
// ------------------------------------------------------------ |
|
2749 |
// |
|
2750 |
void CNssContactHandlerImplementation::UpdatePeriodicActionVars() |
|
2751 |
{ |
|
2752 |
if ( ++iEventMomentIndex >= KEventMomentsSize ) |
|
2753 |
{ |
|
2754 |
iEventMomentIndex = 0; |
|
2755 |
} |
|
2756 |
iEventMoments[iEventMomentIndex].UniversalTime(); |
|
2757 |
||
2758 |
// Update values used to detect end of periodic action |
|
2759 |
TTimeIntervalMicroSeconds32 currInterval = MaximalInterval( iEventMoments, KEventMomentsSize, iEventMomentIndex ); |
|
2760 |
// 8 times. At the end of action, this would typically be no longer, than 0.5secs |
|
2761 |
// Note, that this is the interval fo KEventMomentsSize events |
|
2762 |
if ( ( currInterval.Int() << 3 ) >= ( KInitialPeriodicActionInterval ) ) |
|
2763 |
{ |
|
2764 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::UpdatePeriodicActionVars. Calculated interval is too big. Reverting periodic interval to the max [%d] mcs", KInitialPeriodicActionInterval); |
|
2765 |
iEndOfPeriodicActionInterval = KInitialPeriodicActionInterval; |
|
2766 |
} |
|
2767 |
else |
|
2768 |
{ |
|
2769 |
currInterval = currInterval.Int() << 3; |
|
2770 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::UpdatePeriodicActionVars. Adjusting periodic interval to [%d] mcs", currInterval.Int() ); |
|
2771 |
iEndOfPeriodicActionInterval = currInterval.Int(); |
|
2772 |
} |
|
2773 |
} |
|
2774 |
||
2775 |
// ------------------------------------------------------------ |
|
2776 |
// CNssContactHandlerImplementation::MaximalInterval |
|
2777 |
// Return maximal interval from the array of time moments |
|
2778 |
// ------------------------------------------------------------ |
|
2779 |
// |
|
2780 |
TTimeIntervalMicroSeconds32 CNssContactHandlerImplementation::MaximalInterval( const TTime aMoments[], const TInt aMomentsLength, const TInt aLastMomentIndex ) |
|
2781 |
{ |
|
2782 |
RUBY_ASSERT_DEBUG( aMomentsLength > 1, User::Panic( KFile, __LINE__ ) ); |
|
2783 |
TInt currIndex( aLastMomentIndex ); |
|
2784 |
TInt prevIndex = currIndex - 1 < 0 ? aMomentsLength - 1 : currIndex - 1; |
|
2785 |
TTimeIntervalMicroSeconds32 result( 0 ); |
|
2786 |
TTimeIntervalMicroSeconds currInterval; |
|
2787 |
||
2788 |
for ( TInt i = 0; i < aMomentsLength - 1; i++ ) |
|
2789 |
{ |
|
2790 |
currInterval = aMoments[currIndex].MicroSecondsFrom( aMoments[prevIndex] ); |
|
2791 |
const TInt64& currIntVal = currInterval.Int64(); |
|
2792 |
TBool tooBigValue = currIntVal > KMaxTInt; |
|
2793 |
||
2794 |
// if high != 0, aMoments were filled in the incorrect way |
|
2795 |
// but we should not bug the user about it |
|
2796 |
if ( tooBigValue ) |
|
2797 |
{ |
|
2798 |
// this cannot be a negative value.. if moments are recorded in the correct order. |
|
2799 |
// Then non-zero high means, that interval is too big to fit into |
|
2800 |
// TTimeIntervalMicroSeconds32 |
|
2801 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::MaximalInterval. Maximal interval is out of bounds" ); |
|
2802 |
result = TTimeIntervalMicroSeconds32( KMaxTInt ); |
|
2803 |
break; |
|
2804 |
} |
|
2805 |
else |
|
2806 |
{ |
|
2807 |
// normal size value |
|
2808 |
// casting is safe - we checked, that it fits into TInt |
|
2809 |
TTimeIntervalMicroSeconds32 currInterval32 ( (TInt)currIntVal ); |
|
2810 |
||
2811 |
if ( currInterval32 > result ) |
|
2812 |
{ |
|
2813 |
result = currInterval32; |
|
2814 |
} |
|
2815 |
} |
|
2816 |
currIndex = currIndex - 1 < 0 ? aMomentsLength - 1 : currIndex - 1; |
|
2817 |
prevIndex = currIndex - 1 < 0 ? aMomentsLength - 1 : currIndex - 1; |
|
2818 |
} // for |
|
2819 |
return result; |
|
2820 |
} |
|
2821 |
||
2822 |
// ------------------------------------------------------------ |
|
2823 |
// CNssContactHandlerImplementation::SetState |
|
2824 |
// Sets the contact handler state. |
|
2825 |
// In debug, panics (via asserts) if state change is not legal |
|
2826 |
// ------------------------------------------------------------ |
|
2827 |
// |
|
2828 |
void CNssContactHandlerImplementation::SetState( TContactHandlerState aState ) |
|
2829 |
{ |
|
2830 |
RUBY_DEBUG2( "CNssContactHandlerImplementation::SetState from [%d] to [%d]", iState, aState); |
|
2831 |
switch( aState ) |
|
2832 |
{ |
|
2833 |
case ECHFullResync: |
|
2834 |
// no pending events |
|
2835 |
RUBY_ASSERT_DEBUG( ( iDeleteTagListArray == NULL ) || ( iDeleteCallbackCounter == iDeleteTagListArray->Count() ), User::Panic( KFile, __LINE__ ) ); |
|
2836 |
RUBY_ASSERT_DEBUG( iSaveCallbackCounter == iTagArray.Count(), User::Panic( KFile, __LINE__ ) ); |
|
2837 |
||
2838 |
// full resyncronization needed again if this full resyncronization fails |
|
2839 |
RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
2840 |
break; |
|
2841 |
case ECHHandlingNormalChanges: |
|
2842 |
RUBY_ASSERT_DEBUG( iState == ECHIdle, User::Panic( KFile, __LINE__ ) ); |
|
2843 |
RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
2844 |
break; |
|
2845 |
case ECHIdle: |
|
2846 |
if ( iDeleteTagListArray != NULL ) |
|
2847 |
{ |
|
2848 |
RUBY_ASSERT_DEBUG( (iSaveCallbackCounter == iTagArray.Count() ) || ( iDeleteCallbackCounter == iDeleteTagListArray->Count() ), User::Panic( KFile, __LINE__ ) ); |
|
2849 |
} |
|
2850 |
else |
|
2851 |
{ |
|
2852 |
RUBY_ASSERT_DEBUG( ( iSaveCallbackCounter == iTagArray.Count() ) , User::Panic( KFile, __LINE__ ) ); |
|
2853 |
} |
|
2854 |
if( iEventArray.Count() == 0 ) |
|
2855 |
{ |
|
2856 |
// Idle state and no pending events mean, that contact handler |
|
2857 |
// completed its operations for now |
|
2858 |
TInt errProp = iBusyProperty.Set( EContactsNoTraining ); |
|
2859 |
if ( errProp != KErrNone ) |
|
2860 |
{ |
|
2861 |
RUBY_ERROR1("CNssContactHandlerImplementation::ConstructL() Failed to set property. Error [%d]", |
|
2862 |
errProp ); |
|
2863 |
// @todo Not a leaving function -> leave commented out |
|
2864 |
//User::Leave( errProp ) ; |
|
2865 |
} |
|
2866 |
} |
|
2867 |
||
2868 |
// all changes done, no need for resyncronization |
|
2869 |
RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( EFalse ) ); |
|
2870 |
||
2871 |
break; |
|
2872 |
default: |
|
2873 |
RUBY_ERROR0( "CNssContactHandlerImplementation::SetState Unexpected or unknown state" ); |
|
2874 |
RUBY_ASSERT_DEBUG( EFalse, User::Panic( KFile, __LINE__ ) ); |
|
2875 |
||
2876 |
// failure, full resyncronization needed |
|
2877 |
RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
2878 |
break; |
|
2879 |
} |
|
2880 |
// actually switch state |
|
2881 |
iState = aState; |
|
2882 |
} |
|
2883 |
||
2884 |
// --------------------------------------------------------- |
|
2885 |
// CNssContactHandlerImplementation::DataSyncStateChanged |
|
2886 |
// |
|
2887 |
// --------------------------------------------------------- |
|
2888 |
// |
|
2889 |
void CNssContactHandlerImplementation::DataSyncStateChanged( TBool aRunning ) |
|
2890 |
{ |
|
2891 |
if( !aRunning && ( iSyncBackupWaiter->IsStarted() ) ) |
|
2892 |
{ |
|
2893 |
RUBY_DEBUG0( "DataSyncStateChanged Sync became inactive and CH was waiting for it" ); |
|
2894 |
iSyncBackupWaiter->AsyncStop(); |
|
2895 |
} |
|
2896 |
} |
|
2897 |
||
2898 |
// --------------------------------------------------------- |
|
2899 |
// Is called when backup/restore status is changed and when backup/restore |
|
2900 |
// state observation was just started |
|
2901 |
// @param aRunning ETrue if some backup/restore action is in progress |
|
2902 |
// EFalse otherwise |
|
2903 |
// @param aRestoreType ETrue if the event is restore related |
|
2904 |
// EFalse if the event is backup related |
|
2905 |
// @see CNssChBackupObserver |
|
2906 |
// --------------------------------------------------------- |
|
2907 |
void CNssContactHandlerImplementation::BackupRestoreStateChanged( TBool aRestoreType, |
|
2908 |
TBool aRunning ) |
|
2909 |
{ |
|
2910 |
RUBY_DEBUG2( "BackupRestoreStateChanged aRestoreType [%d], aRunning [%d]", |
|
2911 |
aRestoreType, aRunning ); |
|
2912 |
||
2913 |
if( aRestoreType && aRunning ) |
|
2914 |
{ |
|
2915 |
RUBY_DEBUG0( "Setting the Full Resync CR flag" ); |
|
2916 |
RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
2917 |
} |
|
2918 |
||
2919 |
if( !aRunning && ( iSyncBackupWaiter->IsStarted() ) ) |
|
2920 |
{ |
|
2921 |
RUBY_DEBUG0( "BackupRestoreStateChanged b/r became inactive and CH was waiting for it" ); |
|
2922 |
iSyncBackupWaiter->AsyncStop(); |
|
2923 |
} |
|
2924 |
} |
|
2925 |
||
2926 |
// --------------------------------------------------------- |
|
2927 |
// CNssContactHandlerImplementation::HandleNotifyInt |
|
2928 |
// |
|
2929 |
// --------------------------------------------------------- |
|
2930 |
// |
|
2931 |
void CNssContactHandlerImplementation::HandleNotifyInt( TUint32 aId, TInt aNewValue ) |
|
2932 |
{ |
|
2933 |
RUBY_DEBUG0( "" ); |
|
2934 |
||
2935 |
if ( aId == KSRSFFullResyncNeeded ) |
|
2936 |
{ |
|
2937 |
if ( aNewValue == KImmediateResync ) |
|
2938 |
{ |
|
2939 |
RUBY_DEBUG0( "Immediate full resync requested" ); |
|
2940 |
||
2941 |
// Write the previous value back to the cenrep |
|
2942 |
TRAP_IGNORE( SetFullResyncCrFlagL( iResyncAtBoot ) ); |
|
2943 |
||
2944 |
// Create an event that will launch full resync |
|
2945 |
TPhonebookEvent event; |
|
2946 |
event.iType = ENullEvent; |
|
2947 |
event.iContactId = 0; |
|
2948 |
||
2949 |
iEventArray.Append( event ); |
|
2950 |
||
2951 |
// Start resync if nothing is ongoing |
|
2952 |
if ( iState == ECHIdle ) |
|
2953 |
{ |
|
2954 |
TRAP_IGNORE( DoHandleEventsL() ); |
|
2955 |
} |
|
2956 |
} |
|
2957 |
} |
|
2958 |
} |
|
2959 |
||
2960 |
// --------------------------------------------------------- |
|
2961 |
// Sets the central repository full resync flag |
|
2962 |
// --------------------------------------------------------- |
|
2963 |
void CNssContactHandlerImplementation::SetFullResyncCrFlagL( TBool aResyncNeeded ) |
|
2964 |
{ |
|
2965 |
RUBY_DEBUG_BLOCKL(""); |
|
2966 |
User::LeaveIfError( iRepository->Set( KSRSFFullResyncNeeded, aResyncNeeded ) ); |
|
2967 |
iResyncAtBoot = aResyncNeeded; |
|
2968 |
} |
|
2969 |
||
2970 |
// --------------------------------------------------------- |
|
2971 |
// CNssContactHandlerImplementation::WaitUntilNoSyncBackupIsRunning |
|
2972 |
// |
|
2973 |
// --------------------------------------------------------- |
|
2974 |
// |
|
2975 |
void CNssContactHandlerImplementation::WaitUntilNoSyncBackupIsRunning() |
|
2976 |
{ |
|
2977 |
RUBY_DEBUG0( "WaitUntilNoSyncBackupIsRunning start" ); |
|
2978 |
RUBY_ASSERT_DEBUG( !iSyncBackupWaiter->IsStarted(), User::Panic( KFile, __LINE__ ) ); |
|
2979 |
||
2980 |
// Disconnection from phonebook should happen only once and only if b/r is running |
|
2981 |
TBool disconnectedFromPb = EFalse; |
|
2982 |
||
2983 |
// Check the values until both data sync and backup/restore are not active |
|
2984 |
while( iDataSyncWatcher->InProgress() || iBackupObserver->InProgress() ) |
|
2985 |
{ |
|
2986 |
RUBY_DEBUG2( "WaitUntilNoSyncBackupIsRunning Have to wait. data sync [%d], backup/restore [%d]", |
|
2987 |
iDataSyncWatcher->InProgress(), iBackupObserver->InProgress() ); |
|
2988 |
if( !iSyncBackupWaiter->IsStarted() ) |
|
2989 |
{ |
|
2990 |
if( (!disconnectedFromPb) && iBackupObserver->InProgress() ) |
|
2991 |
{ |
|
2992 |
RUBY_DEBUG0( "WaitUntilNoSyncBackupIsRunning Disconnecting from phonebook" ); |
|
2993 |
DisconnectFromPhonebook(); |
|
2994 |
disconnectedFromPb = ETrue; |
|
2995 |
} |
|
2996 |
iSyncBackupWaiter->Start(); |
|
2997 |
} |
|
2998 |
else |
|
2999 |
{ |
|
3000 |
RUBY_ERROR0( "WaitUntilNoSyncBackupIsRunning Attempt to start already active iSyncBackupWaiter. Huge error!" ); |
|
3001 |
} |
|
3002 |
} |
|
3003 |
||
3004 |
if( disconnectedFromPb ) |
|
3005 |
{ |
|
3006 |
RUBY_DEBUG0( "WaitUntilNoSyncBackupIsRunning Reconnecting to phonebook" ); |
|
3007 |
TRAP_IGNORE( ConnectToPhonebookL() ); |
|
3008 |
} |
|
3009 |
||
3010 |
RUBY_DEBUG0( "WaitUntilNoSyncBackupIsRunning end" ); |
|
3011 |
} |
|
3012 |
||
3013 |
// --------------------------------------------------------- |
|
3014 |
// CNssContactHandlerImplementation::GetContactL |
|
3015 |
// |
|
3016 |
// --------------------------------------------------------- |
|
3017 |
// |
|
3018 |
void CNssContactHandlerImplementation::GetContactL( TContactItemId aContactId, TBool aReadContact ) |
|
3019 |
{ |
|
3020 |
RUBY_DEBUG1( "CNssContactHandlerImplementation::GetContactL. contact id [%d]", aContactId ); |
|
3021 |
TInt err = KErrNone; |
|
3022 |
// Number of attempts tries |
|
3023 |
TInt attemptsTried( 0 ); |
|
3024 |
do |
|
3025 |
{ |
|
3026 |
if( err == KErrInUse ) // i.e. not the first cycle iteration |
|
3027 |
{ |
|
3028 |
RUBY_DEBUG2( "GetContactL Contact [%d] is locked. Waiting one more second. Retrial [%d]", |
|
3029 |
aContactId, attemptsTried); |
|
3030 |
// start periodic timer |
|
3031 |
if( attemptsTried == 1) // i.e exactly the second cycle iteration |
|
3032 |
{ |
|
3033 |
RUBY_DEBUG0( "GetContactL Creating periodic timer" ); |
|
3034 |
iContactWaitTimer = CPeriodic::NewL( EPriorityNormal ); |
|
3035 |
iContactWaitTimer->Start( KContactWaitInterval, KContactWaitInterval, TCallBack( ContactWaitCallback, this ) ); |
|
3036 |
} |
|
3037 |
RUBY_DEBUG0( "GetContactL Starting the inner cycle waiting" ); |
|
3038 |
iContactWaiter->Start( ); |
|
3039 |
RUBY_DEBUG0( "GetContactL Waiting completed, trying to open contact again" ); |
|
3040 |
} |
|
3041 |
||
3042 |
TRAP( err, iPbkHandler->FindContactL( aContactId, aReadContact ) ); |
|
3043 |
||
3044 |
attemptsTried++; |
|
3045 |
// -1 means forever |
|
3046 |
if( ( KMaxContactLockRetrials != -1 ) && ( attemptsTried >= KMaxContactLockRetrials ) ) |
|
3047 |
{ |
|
3048 |
RUBY_DEBUG1( "GetContactL Tried for [%d] times, still no success", attemptsTried ); |
|
3049 |
break; |
|
3050 |
} |
|
3051 |
} |
|
3052 |
while( err == KErrInUse ); |
|
3053 |
if( iContactWaitTimer != NULL ) |
|
3054 |
{ |
|
3055 |
iContactWaitTimer->Cancel(); |
|
3056 |
delete iContactWaitTimer; |
|
3057 |
iContactWaitTimer = NULL; |
|
3058 |
} |
|
3059 |
// Propagate all the leaves, BUT KErrInUse |
|
3060 |
if( ( err != KErrInUse ) && ( err != KErrNone ) ) |
|
3061 |
{ |
|
3062 |
User::LeaveIfError( err ); |
|
3063 |
} |
|
3064 |
if( err == KErrInUse ) |
|
3065 |
{ |
|
3066 |
RUBY_DEBUG1( "GetContactL Failed to lock contact [%d]. Disabling CH, will resync on reboot", aContactId ); |
|
3067 |
DisableEventHandling(); |
|
3068 |
User::Leave( KErrInUse ); |
|
3069 |
} |
|
3070 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::GetContactL completed" ); |
|
3071 |
} |
|
3072 |
||
3073 |
// --------------------------------------------------------- |
|
3074 |
// CNssContactHandlerImplementation::ReadContactL |
|
3075 |
// |
|
3076 |
// --------------------------------------------------------- |
|
3077 |
// |
|
3078 |
void CNssContactHandlerImplementation::ReadContactL( TContactItemId aContactId ) |
|
3079 |
{ |
|
3080 |
GetContactL( aContactId, ETrue ); |
|
3081 |
} |
|
3082 |
||
3083 |
// --------------------------------------------------------- |
|
3084 |
// CNssContactHandlerImplementation::OpenContactL |
|
3085 |
// |
|
3086 |
// --------------------------------------------------------- |
|
3087 |
// |
|
3088 |
void CNssContactHandlerImplementation::OpenContactL( TContactItemId aContactId ) |
|
3089 |
{ |
|
3090 |
GetContactL( aContactId, EFalse ); |
|
3091 |
} |
|
3092 |
||
3093 |
// --------------------------------------------------------- |
|
3094 |
// CNssContactHandlerImplementation::ContactWaitCallback |
|
3095 |
// |
|
3096 |
// --------------------------------------------------------- |
|
3097 |
// |
|
3098 |
TInt CNssContactHandlerImplementation::ContactWaitCallback( TAny* pX ) |
|
3099 |
{ |
|
3100 |
((CNssContactHandlerImplementation*)pX)->DoContactWaitCallback(); |
|
3101 |
return KErrNone; // useless for CPeriodic |
|
3102 |
} |
|
3103 |
||
3104 |
// --------------------------------------------------------- |
|
3105 |
// CNssContactHandlerImplementation::DoContactWaitCallback |
|
3106 |
// |
|
3107 |
// --------------------------------------------------------- |
|
3108 |
// |
|
3109 |
void CNssContactHandlerImplementation::DoContactWaitCallback() |
|
3110 |
{ |
|
3111 |
iContactWaiter->AsyncStop(); |
|
3112 |
} |
|
3113 |
||
3114 |
// --------------------------------------------------------- |
|
3115 |
// CNssContactHandlerImplementation::NoDiskSpace |
|
3116 |
// Checks if there is not enough disk space to finish the |
|
3117 |
// operation. Returns ETrue if there is no space. |
|
3118 |
// --------------------------------------------------------- |
|
3119 |
// |
|
3120 |
TBool CNssContactHandlerImplementation::NoDiskSpace() |
|
3121 |
{ |
|
3122 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::NoDiskSpace" ); |
|
3123 |
TBool diskSpace( EFalse ); |
|
3124 |
TRAP_IGNORE( diskSpace = SysUtil::FFSSpaceBelowCriticalLevelL( &iFSession, KIncreaseOfDatabaseSizes ) ); |
|
3125 |
||
3126 |
if ( diskSpace ) |
|
3127 |
{ |
|
3128 |
RUBY_TRAP_IGNORE( SetFullResyncCrFlagL( ETrue ) ); |
|
3129 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::NoDiskSpace NOT enough disk space available" ); |
|
3130 |
return ETrue; |
|
3131 |
} |
|
3132 |
else |
|
3133 |
{ |
|
3134 |
RUBY_DEBUG0( "CNssContactHandlerImplementation::NoDiskSpace There is enough disk space" ); |
|
3135 |
return EFalse; |
|
3136 |
} |
|
3137 |
} |
|
3138 |
||
3139 |
// --------------------------------------------------------- |
|
3140 |
// CNssContactHandlerImplementation::TrimName |
|
3141 |
// Substitutes separator characters in descriptor with |
|
3142 |
// white spaces. Removes extra withspaces. |
|
3143 |
// --------------------------------------------------------- |
|
3144 |
// |
|
3145 |
void CNssContactHandlerImplementation::TrimName( HBufC* aBuf ) |
|
3146 |
{ |
|
3147 |
TPtr ptr = aBuf->Des(); |
|
3148 |
||
3149 |
for ( TInt findIndex = 0; findIndex < aBuf->Des().Length(); findIndex++ ) |
|
3150 |
{ |
|
3151 |
if ( ptr[findIndex] == iSeparator ) |
|
3152 |
{ |
|
3153 |
ptr[findIndex] = ' '; |
|
3154 |
} |
|
3155 |
} |
|
3156 |
||
3157 |
ptr.TrimAll(); |
|
3158 |
} |
|
3159 |
||
3160 |
// --------------------------------------------------------- |
|
3161 |
// CNssContactHandlerImplementation::AppendName |
|
3162 |
// Appends name to given buffer |
|
3163 |
// --------------------------------------------------------- |
|
3164 |
// |
|
3165 |
void CNssContactHandlerImplementation::AppendName( HBufC* aBuf, HBufC* aName ) |
|
3166 |
{ |
|
3167 |
if ( aName->Length() != 0 ) |
|
3168 |
{ |
|
3169 |
aBuf->Des().Append( iSeparator ); |
|
3170 |
aBuf->Des().Append( KNameTrainingIndex ); |
|
3171 |
aBuf->Des().Append( aName->Des() ); |
|
3172 |
} |
|
3173 |
} |
|
3174 |
||
3175 |
// --------------------------------------------------------- |
|
3176 |
// CNssContactHandlerImplementation::AppendExtensionMarker |
|
3177 |
// Appends marker for the extensions |
|
3178 |
// Parameters should be in format "%U text message" |
|
3179 |
// In which case output is "%U_2text message" |
|
3180 |
// --------------------------------------------------------- |
|
3181 |
// |
|
3182 |
void CNssContactHandlerImplementation::AppendExtensionMarker( TDes& aDes ) |
|
3183 |
{ |
|
3184 |
if ( aDes.Length() > 0 ) |
|
3185 |
{ |
|
3186 |
TInt insertPosition( 0 ); |
|
3187 |
if ( aDes.Find( KExtensionFormatString ) == 0 ) |
|
3188 |
{ |
|
3189 |
// Find the first space and insert marker to that position |
|
3190 |
TInt firstSpace( 0 ); |
|
3191 |
firstSpace = aDes.Find( _L(" ") ); |
|
3192 |
if ( firstSpace == 2 ) // Next character after KExtensionFormatString |
|
3193 |
{ |
|
3194 |
aDes.Delete( firstSpace, 1 ); |
|
3195 |
} |
|
3196 |
insertPosition = 2; |
|
3197 |
} |
|
3198 |
// Insert marker |
|
3199 |
aDes.Insert( insertPosition, KExtensionTrainingIndex ); |
|
3200 |
aDes.Insert( insertPosition, KNameSeparator ); |
|
3201 |
} |
|
3202 |
} |
|
3203 |
||
3204 |
/** |
|
3205 |
* Establishes the connection to the contact engine and |
|
3206 |
* starts listening to it |
|
3207 |
*/ |
|
3208 |
void CNssContactHandlerImplementation::ConnectToPhonebookL() |
|
3209 |
{ |
|
3210 |
RUBY_ASSERT_DEBUG( (!iPbkHandler), User::Leave( KErrNotReady ) ); |
|
3211 |
iPbkHandler = CVasVPbkHandler::NewL(); |
|
3212 |
iPbkHandler->InitializeL(); |
|
3213 |
iPbkHandler->CreateContactObserverL( this ); |
|
3214 |
} |
|
3215 |
||
3216 |
/** |
|
3217 |
* Clears the connection to the contact engine |
|
3218 |
*/ |
|
3219 |
void CNssContactHandlerImplementation::DisconnectFromPhonebook() |
|
3220 |
{ |
|
3221 |
delete iPbkHandler; |
|
3222 |
iPbkHandler = NULL; |
|
3223 |
} |
|
3224 |
||
3225 |
#ifdef __SIND_EXTENSIONS |
|
3226 |
||
3227 |
// --------------------------------------------------------- |
|
3228 |
// CNssContactHandlerImplementation::ReadExtensionsL |
|
3229 |
// Reads the extension resource file |
|
3230 |
// --------------------------------------------------------- |
|
3231 |
// |
|
3232 |
void CNssContactHandlerImplementation::ReadExtensionsL() |
|
3233 |
{ |
|
3234 |
// using StringLoader should be used, but there is no |
|
3235 |
// access to CCoeEnv |
|
3236 |
||
3237 |
||
3238 |
// letters for drives in search order |
|
3239 |
const TBuf<1> KResourceDrivers = _L("z"); |
|
3240 |
_LIT( KResourceFileName, "nssvascontacthandler.rsc" ); |
|
3241 |
||
3242 |
// number of extension commands in the resource file |
|
3243 |
const TInt KExtensionCommandCount = 8; |
|
3244 |
||
3245 |
// load resources |
|
3246 |
RResourceFile resourceFile; |
|
3247 |
RFs fs; |
|
3248 |
CleanupClosePushL( fs ); |
|
3249 |
TBool found( EFalse ); |
|
3250 |
User::LeaveIfError( fs.Connect() ); |
|
3251 |
||
3252 |
||
3253 |
TFileName name; |
|
3254 |
TInt i( 0 ); |
|
3255 |
// use the first drive |
|
3256 |
name.Append( KResourceDrivers[i] ); |
|
3257 |
name.Append(':'); |
|
3258 |
name.Append( KDC_RESOURCE_FILES_DIR ); |
|
3259 |
name.Append( KResourceFileName ); |
|
3260 |
||
3261 |
while ( !found && i < KResourceDrivers.Length() ) |
|
3262 |
{ |
|
3263 |
name[0] = KResourceDrivers[i++]; |
|
3264 |
||
3265 |
BaflUtils::NearestLanguageFile( fs, name ); |
|
3266 |
||
3267 |
if ( BaflUtils::FileExists(fs, name) ) |
|
3268 |
{ |
|
3269 |
// open resource |
|
3270 |
resourceFile.OpenL( fs, name ); |
|
3271 |
CleanupClosePushL( resourceFile ); |
|
3272 |
resourceFile.ConfirmSignatureL(); |
|
3273 |
found = ETrue; |
|
3274 |
} |
|
3275 |
} |
|
3276 |
||
3277 |
if ( !found ) |
|
3278 |
{ |
|
3279 |
User::Leave( KErrNotFound ); |
|
3280 |
} |
|
3281 |
||
3282 |
for ( TInt extensionIndex( 0 ); extensionIndex < KExtensionCommandCount; extensionIndex++ ) |
|
3283 |
{ |
|
3284 |
TExtension extension; |
|
3285 |
TResourceReader reader; |
|
3286 |
TBool extentionSupported( ETrue ); |
|
3287 |
||
3288 |
switch ( extensionIndex ) |
|
3289 |
{ |
|
3290 |
||
3291 |
case 0: |
|
3292 |
reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_MOBILE ) ); |
|
3293 |
extension.iId = EPbkFieldIdPhoneNumberMobile; |
|
3294 |
extension.iAction = EDial; |
|
3295 |
extension.iCommand = EMobileCommand; |
|
3296 |
break; |
|
3297 |
||
3298 |
case 1: |
|
3299 |
reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_MESSAGE ) ); |
|
3300 |
extension.iId = EPbkFieldIdPhoneNumberMobile; |
|
3301 |
extension.iAction = ENewMessage; |
|
3302 |
extension.iCommand = EMessageCommand; |
|
3303 |
break; |
|
3304 |
||
3305 |
case 2: |
|
3306 |
reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_GENERAL ) ); |
|
3307 |
extension.iId = EPbkFieldIdPhoneNumberGeneral; |
|
3308 |
extension.iAction = EDial; |
|
3309 |
extension.iCommand = EGeneralCommand; |
|
3310 |
break; |
|
3311 |
||
3312 |
case 3: |
|
3313 |
reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_WORK ) ); |
|
3314 |
extension.iId = EPbkFieldIdPhoneNumberWork; |
|
3315 |
extension.iAction = EDial; |
|
3316 |
extension.iCommand = EWorkCommand; |
|
3317 |
break; |
|
3318 |
||
3319 |
case 4: |
|
3320 |
reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_HOME ) ); |
|
3321 |
extension.iId = EPbkFieldIdPhoneNumberHome; |
|
3322 |
extension.iAction = EDial; |
|
3323 |
extension.iCommand = EHomeCommand; |
|
3324 |
break; |
|
3325 |
||
3326 |
case 5: |
|
3327 |
if ( iVideoCallFeatureSupported ) |
|
3328 |
{ |
|
3329 |
reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_VIDEO ) ); |
|
3330 |
extension.iId = EPbkFieldIdPhoneNumberVideo; |
|
3331 |
extension.iAction = EDial; |
|
3332 |
extension.iCommand = EVideoCommand; |
|
3333 |
} |
|
3334 |
else |
|
3335 |
{ |
|
3336 |
extentionSupported = EFalse; |
|
3337 |
} |
|
3338 |
break; |
|
3339 |
||
3340 |
case 6: |
|
3341 |
reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_EMAIL ) ); |
|
3342 |
extension.iId =EPbkFieldIdEmailAddress ; |
|
3343 |
extension.iAction = ENewEmail; |
|
3344 |
extension.iCommand = EEmailCommand; |
|
3345 |
break; |
|
3346 |
||
3347 |
case 7: |
|
3348 |
if ( iVoIPFeatureSupported ) |
|
3349 |
{ |
|
3350 |
reader.SetBuffer( resourceFile.AllocReadLC( R_SIND_EXTENSION_VOIP ) ); |
|
3351 |
extension.iId = EPbkFieldIdVOIP; |
|
3352 |
extension.iAction = EDial; |
|
3353 |
extension.iCommand = EVoipCommand; |
|
3354 |
} |
|
3355 |
else |
|
3356 |
{ |
|
3357 |
extentionSupported = EFalse; |
|
3358 |
} |
|
3359 |
break; |
|
3360 |
||
3361 |
default: |
|
3362 |
User::Leave( KErrGeneral ); // !!! @todo: PANIC |
|
3363 |
} |
|
3364 |
||
3365 |
if ( extentionSupported ) |
|
3366 |
{ |
|
3367 |
extension.iText = reader.ReadHBufCL(); |
|
3368 |
CleanupStack::PushL( extension.iText ); |
|
3369 |
User::LeaveIfError( iExtensionList.Append( extension ) ); |
|
3370 |
CleanupStack::Pop( extension.iText ); |
|
3371 |
CleanupStack::PopAndDestroy(); // AllocReadLC |
|
3372 |
} |
|
3373 |
} |
|
3374 |
||
3375 |
CleanupStack::PopAndDestroy( &resourceFile ); |
|
3376 |
CleanupStack::PopAndDestroy( &fs ); |
|
3377 |
||
3378 |
} |
|
3379 |
||
3380 |
// --------------------------------------------------------- |
|
3381 |
// CNssContactHandlerImplementation::FindExtensionField |
|
3382 |
// Finds the extension field based on priority lists |
|
3383 |
// --------------------------------------------------------- |
|
3384 |
// |
|
3385 |
TInt CNssContactHandlerImplementation::FindExtensionField( TVasExtensionAction aAction, |
|
3386 |
TPbkFieldId aDefaultFieldId ) |
|
3387 |
{ |
|
3388 |
TInt found = KErrNotFound; |
|
3389 |
||
3390 |
switch ( aDefaultFieldId ) |
|
3391 |
{ |
|
3392 |
case EPbkFieldIdPhoneNumberVideo: |
|
3393 |
{ |
|
3394 |
// Use defaults for video extension |
|
3395 |
found = ExtensionFieldFindLoop( KVideoExtensionFields, KVideoExtensionFieldsCount ); |
|
3396 |
break; |
|
3397 |
} |
|
3398 |
||
3399 |
case EPbkFieldIdPhoneNumberMobile: |
|
3400 |
{ |
|
3401 |
if ( aAction == ENewMessage ) |
|
3402 |
{ |
|
3403 |
// Use defaults for message extension |
|
3404 |
found = ExtensionFieldFindLoop( KMessageExtensionFields, KMessageExtensionFieldsCount ); |
|
3405 |
} |
|
3406 |
else |
|
3407 |
{ |
|
3408 |
TRAP( found, iPbkHandler->FindFieldL( aDefaultFieldId ) ); |
|
3409 |
} |
|
3410 |
||
3411 |
break; |
|
3412 |
} |
|
3413 |
||
3414 |
case EPbkFieldIdVOIP: |
|
3415 |
{ |
|
3416 |
// Use defaults for VOIP extension |
|
3417 |
found = ExtensionFieldFindLoop( KVOIPExtensionFields, KVOIPExtensionFieldsCount ); |
|
3418 |
||
3419 |
break; |
|
3420 |
} |
|
3421 |
||
3422 |
default: |
|
3423 |
{ |
|
3424 |
TRAP( found, iPbkHandler->FindFieldL( aDefaultFieldId ) ); |
|
3425 |
break; |
|
3426 |
} |
|
3427 |
} |
|
3428 |
return found; |
|
3429 |
} |
|
3430 |
||
3431 |
// --------------------------------------------------------- |
|
3432 |
// CNssContactHandlerImplementation::ExtensionFieldFindLoop |
|
3433 |
// Finds the extension from the prioroty list arrays |
|
3434 |
// --------------------------------------------------------- |
|
3435 |
// |
|
3436 |
TInt CNssContactHandlerImplementation::ExtensionFieldFindLoop( const TPbkFieldId* const aArray, |
|
3437 |
TInt aCount ) |
|
3438 |
{ |
|
3439 |
TInt found = KErrNotFound; |
|
3440 |
||
3441 |
for ( TInt iCounter = 0; iCounter < aCount; iCounter++ ) |
|
3442 |
{ |
|
3443 |
TRAP( found, iPbkHandler->FindFieldL( aArray[iCounter] ) ); |
|
3444 |
if ( found == KErrNone ) |
|
3445 |
{ |
|
3446 |
break; |
|
3447 |
} |
|
3448 |
} |
|
3449 |
return found; |
|
3450 |
} |
|
3451 |
||
3452 |
#endif // __SIND_EXTENSIONS |
|
3453 |
||
3454 |
// End of File |