25
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: DS contacts adapters
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <e32base.h>
|
|
21 |
#include <s32strm.h>
|
|
22 |
#include <cntdb.h>
|
|
23 |
#include <e32cmn.h>
|
|
24 |
#include <e32des16.h>
|
|
25 |
#include <cntitem.h>
|
|
26 |
#include <cntfield.h>
|
|
27 |
#include <cntfldst.h>
|
|
28 |
|
|
29 |
#include "nsmlcontactsdefs.h"
|
|
30 |
#include "NSmlContactsModsFetcher.h"
|
|
31 |
#include "nsmldebug.h"
|
|
32 |
#include "nsmlsnapshotitem.h"
|
|
33 |
#include "nsmlchangefinder.h"
|
|
34 |
|
|
35 |
#include <CVPbkContactViewDefinition.h>
|
|
36 |
#include <CVPbkContactIdConverter.h>
|
|
37 |
#include <CVPbkContactFieldIterator.h>
|
|
38 |
#include <MVPbkContactStoreProperties.h>
|
|
39 |
#include <MVPbkStoreContactProperties.h>
|
|
40 |
#include <MVPbkViewContact.h>
|
|
41 |
#include <MVPbkFieldType.h>
|
|
42 |
#include <MVPbkContactFieldTextData.h>
|
|
43 |
#include <MVPbkStoreContact.h>
|
|
44 |
#include <MVPbkStoreContact2.h>
|
|
45 |
#include <MVPbkContactLink.h>
|
|
46 |
#include <VPbkEng.rsg>
|
|
47 |
|
|
48 |
|
|
49 |
// ------------------------------------------------------------------------------------------------
|
|
50 |
// CNSmlContactsModsFetcher::CNSmlContactsModsFetcher
|
|
51 |
// ------------------------------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
CNSmlContactsModsFetcher::CNSmlContactsModsFetcher( TBool& aSnapshotRegistered,CVPbkContactManager& aContactManager,MVPbkContactStore& aStore,TKeyArrayFix& aKey, CNSmlChangeFinder& aChangeFinder ) :
|
|
54 |
CActive( EPriorityLow ),
|
|
55 |
iSnapshotRegistered( aSnapshotRegistered ),
|
|
56 |
iKey( aKey ),
|
|
57 |
iChangeFinder( aChangeFinder ),
|
|
58 |
iContactManager(aContactManager) ,
|
|
59 |
iStore(aStore) ,
|
|
60 |
iContactViewBase(NULL)
|
|
61 |
{
|
|
62 |
_DBG_FILE("CNSmlContactsModsFetcher::CNSmlContactsModsFetcher(): begin");
|
|
63 |
CActiveScheduler::Add( this );
|
|
64 |
_DBG_FILE("CNSmlContactsModsFetcher::CNSmlContactsModsFetcher(): end");
|
|
65 |
}
|
|
66 |
|
|
67 |
// ------------------------------------------------------------------------------------------------
|
|
68 |
// CNSmlContactsModsFetcher::~CNSmlContactsModsFetcher
|
|
69 |
// ------------------------------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
CNSmlContactsModsFetcher::~CNSmlContactsModsFetcher()
|
|
72 |
{
|
|
73 |
_DBG_FILE("CNSmlContactsModsFetcher::~CNSmlContactsModsFetcher(): begin");
|
|
74 |
|
|
75 |
Cancel();
|
|
76 |
delete iSnapshot;
|
|
77 |
delete iContactViewBase;
|
|
78 |
|
|
79 |
|
|
80 |
_DBG_FILE("CNSmlContactsModsFetcher::~CNSmlContactsModsFetcher(): end");
|
|
81 |
}
|
|
82 |
|
|
83 |
// ----------------------------------------------------------------------------
|
|
84 |
// CNSmlContactsModsFetcher::CancelRequest
|
|
85 |
// ----------------------------------------------------------------------------
|
|
86 |
void CNSmlContactsModsFetcher::CancelRequest()
|
|
87 |
{
|
|
88 |
Cancel();
|
|
89 |
}
|
|
90 |
|
|
91 |
// ------------------------------------------------------------------------------------------------
|
|
92 |
// CNSmlContactsModsFetcher::FetchModificationsL
|
|
93 |
// ------------------------------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
void CNSmlContactsModsFetcher::FetchModificationsL( TRequestStatus& aStatus )
|
|
96 |
{
|
|
97 |
_DBG_FILE("CNSmlContactsModsFetcher::FetchModificationsL(): begin");
|
|
98 |
|
|
99 |
iCallerStatus = &aStatus;
|
|
100 |
*iCallerStatus = KRequestPending;
|
|
101 |
iContactCount = 0;
|
|
102 |
if( !iSnapshot )
|
|
103 |
{
|
|
104 |
iSnapshot = new (ELeave) CArrayFixSeg<TNSmlSnapshotItem>( KNSmlSnapshotSize );
|
|
105 |
}
|
|
106 |
|
|
107 |
if(iContactViewBase)
|
|
108 |
{
|
|
109 |
delete iContactViewBase;
|
|
110 |
iContactViewBase = NULL;
|
|
111 |
}
|
|
112 |
|
|
113 |
CreateViewL();
|
|
114 |
|
|
115 |
_DBG_FILE("CNSmlContactsModsFetcher::FetchModificationsL(): end");
|
|
116 |
|
|
117 |
}
|
|
118 |
|
|
119 |
// ------------------------------------------------------------------------------------------------
|
|
120 |
// CNSmlContactsModsFetcher::ConstructL
|
|
121 |
// ------------------------------------------------------------------------------------------------
|
|
122 |
//
|
|
123 |
void CNSmlContactsModsFetcher::ConstructL()
|
|
124 |
{
|
|
125 |
iSnapshot = new (ELeave) CArrayFixSeg<TNSmlSnapshotItem>(KNSmlSnapshotSmallSize);
|
|
126 |
|
|
127 |
}
|
|
128 |
|
|
129 |
// ------------------------------------------------------------------------------------------------
|
|
130 |
// CNSmlContactsModsFetcher::RunL
|
|
131 |
// ------------------------------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
void CNSmlContactsModsFetcher::RunL()
|
|
134 |
{
|
|
135 |
_DBG_FILE("CNSmlContactsModsFetcher::RunL(): begin");
|
|
136 |
|
|
137 |
if ( !iSnapshotRegistered )
|
|
138 |
{
|
|
139 |
FetchNextContactL();
|
|
140 |
}
|
|
141 |
#ifdef __NSML_MODULETEST__
|
|
142 |
else
|
|
143 |
{
|
|
144 |
CActiveScheduler::Stop();
|
|
145 |
}
|
|
146 |
#endif
|
|
147 |
|
|
148 |
_DBG_FILE("CNSmlContactsModsFetcher::RunL(): end");
|
|
149 |
}
|
|
150 |
|
|
151 |
// ------------------------------------------------------------------------------------------------
|
|
152 |
// CNSmlContactsModsFetcher::FetchNextContactL
|
|
153 |
// ------------------------------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
void CNSmlContactsModsFetcher::FetchNextContactL()
|
|
156 |
{
|
|
157 |
_DBG_FILE("CNSmlContactsModsFetcher::FetchNextContactL(): begin");
|
|
158 |
if(iContactViewBase->ContactCountL() == 0)
|
|
159 |
{
|
|
160 |
User::RequestComplete( iCallerStatus, KErrNone );
|
|
161 |
return;
|
|
162 |
}
|
|
163 |
if ( !iSnapshotRegistered )
|
|
164 |
{
|
|
165 |
const MVPbkViewContact& contact = iContactViewBase->ContactAtL(iContactCount);
|
|
166 |
|
|
167 |
MVPbkContactLink* contactLink = contact.CreateLinkLC();
|
|
168 |
iContactManager.RetrieveContactL( *contactLink, *this );
|
|
169 |
CleanupStack::PopAndDestroy();
|
|
170 |
}
|
|
171 |
|
|
172 |
_DBG_FILE("CNSmlContactsModsFetcher::FetchNextContactL(): end");
|
|
173 |
}
|
|
174 |
|
|
175 |
// ------------------------------------------------------------------------------------------------
|
|
176 |
// CNSmlContactsModsFetcher::DoCancel
|
|
177 |
// ------------------------------------------------------------------------------------------------
|
|
178 |
//
|
|
179 |
void CNSmlContactsModsFetcher::DoCancel()
|
|
180 |
{
|
|
181 |
_DBG_FILE("CNSmlContactsModsFetcher::DoCancel(): begin");
|
|
182 |
|
|
183 |
User::RequestComplete( iCallerStatus, KErrCancel );
|
|
184 |
|
|
185 |
_DBG_FILE("CNSmlContactsModsFetcher::DoCancel(): end");
|
|
186 |
}
|
|
187 |
|
|
188 |
// ----------------------------------------------------------------------------
|
|
189 |
// CNSmlContactsModsFetcher::IsConfidentialL
|
|
190 |
// ----------------------------------------------------------------------------
|
|
191 |
//
|
|
192 |
TBool CNSmlContactsModsFetcher::IsConfidentialL( MVPbkStoreContact& aItem )
|
|
193 |
{
|
|
194 |
_DBG_FILE("CNSmlContactsModsFetcher::IsConfidentialL(): begin");
|
|
195 |
TBool ret( EFalse );
|
|
196 |
|
|
197 |
//find X-CLASS field type
|
|
198 |
const MVPbkFieldType* syncclass =
|
|
199 |
iContactManager.FieldTypes().Find(R_VPBK_FIELD_TYPE_SYNCCLASS );
|
|
200 |
CVPbkBaseContactFieldTypeIterator* itr =
|
|
201 |
CVPbkBaseContactFieldTypeIterator::NewLC( *syncclass,
|
|
202 |
aItem.Fields() );
|
|
203 |
while ( itr->HasNext() )
|
|
204 |
{
|
|
205 |
const MVPbkBaseContactField* field = itr->Next();
|
|
206 |
const MVPbkContactFieldTextData& data =
|
|
207 |
MVPbkContactFieldTextData::Cast(field->FieldData());
|
|
208 |
TPtrC ptr = data.Text();
|
|
209 |
//compare the sync type
|
|
210 |
if ( ptr.Compare( KNSmlContactSyncNoSync ) == 0 )
|
|
211 |
{
|
|
212 |
_DBG_FILE("CNSmlContactsModsFetcher::IsConfidentialL(): \
|
|
213 |
find confidential");
|
|
214 |
ret = ETrue;
|
|
215 |
}
|
|
216 |
|
|
217 |
}
|
|
218 |
CleanupStack::PopAndDestroy( itr );
|
|
219 |
|
|
220 |
_DBG_FILE("CNSmlContactsModsFetcher::IsConfidentialL(): end");
|
|
221 |
return ret;
|
|
222 |
}
|
|
223 |
|
|
224 |
|
|
225 |
// ----------------------------------------------------------------------------
|
|
226 |
// CNSmlContactsModsFetcher::RunError
|
|
227 |
// ----------------------------------------------------------------------------
|
|
228 |
TInt CNSmlContactsModsFetcher::RunError( TInt aError )
|
|
229 |
{
|
|
230 |
DBG_FILE_CODE(aError, _S8("CNSmlContactsModsFetcher::RunError() : error code received "));
|
|
231 |
User::RequestComplete( iCallerStatus, aError );
|
|
232 |
return KErrNone;
|
|
233 |
}
|
|
234 |
|
|
235 |
// -----------------------------------------------------------------------------
|
|
236 |
// CNSmlContactsModsFetcher::CreateViewL()
|
|
237 |
// Create a contact view of the store which is opened
|
|
238 |
// -----------------------------------------------------------------------------
|
|
239 |
|
|
240 |
void CNSmlContactsModsFetcher::CreateViewL()
|
|
241 |
{
|
|
242 |
CVPbkContactViewDefinition* viewDef = CVPbkContactViewDefinition::NewL();
|
|
243 |
CleanupStack::PushL( viewDef );
|
|
244 |
viewDef->SetType( EVPbkContactsView );
|
|
245 |
|
|
246 |
viewDef->SetUriL(iStore.StoreProperties().Uri().UriDes());
|
|
247 |
|
|
248 |
iContactViewBase = iContactManager.CreateContactViewLC(
|
|
249 |
*this,
|
|
250 |
*viewDef,
|
|
251 |
iContactManager.FieldTypes() );
|
|
252 |
CleanupStack::Pop();
|
|
253 |
CleanupStack::PopAndDestroy(viewDef);
|
|
254 |
|
|
255 |
}
|
|
256 |
// ---------------------------------------------------------------------------
|
|
257 |
// CNSmlContactsModsFetcher::UpdateSnapshotL
|
|
258 |
// Add the fetched contacts id and timestamp
|
|
259 |
// to the snapshot.
|
|
260 |
// ---------------------------------------------------------------------------
|
|
261 |
//
|
|
262 |
|
|
263 |
void CNSmlContactsModsFetcher::UpdateSnapshotL(MVPbkStoreContact* aContact)
|
|
264 |
{
|
|
265 |
if(!IsConfidentialL(*aContact))
|
|
266 |
{
|
|
267 |
CVPbkContactIdConverter* idConverter = CVPbkContactIdConverter::NewL(iStore );
|
|
268 |
CleanupStack::PushL( idConverter );
|
|
269 |
|
|
270 |
TInt32 id = idConverter->LinkToIdentifier(
|
|
271 |
*iContactViewBase->ContactAtL(iContactCount).CreateLinkLC());
|
|
272 |
TNSmlSnapshotItem snap( id);
|
|
273 |
|
|
274 |
MVPbkStoreContact2* tempContact =
|
|
275 |
reinterpret_cast<MVPbkStoreContact2*> (aContact->StoreContactExtension (KMVPbkStoreContactExtension2Uid));
|
|
276 |
|
|
277 |
MVPbkStoreContactProperties *contactProterties
|
|
278 |
= tempContact ->PropertiesL();
|
|
279 |
CleanupDeletePushL(contactProterties);
|
|
280 |
snap.SetLastChangedDate(contactProterties->LastModifiedL());
|
|
281 |
CleanupStack::PopAndDestroy();
|
|
282 |
|
|
283 |
iSnapshot->InsertIsqL( snap, iKey );
|
|
284 |
iCurrentSnapshotCounter++;
|
|
285 |
if ( iCurrentSnapshotCounter > 20 )
|
|
286 |
{
|
|
287 |
iSnapshot->Compress();
|
|
288 |
iCurrentSnapshotCounter = 0;
|
|
289 |
}
|
|
290 |
CleanupStack::PopAndDestroy();
|
|
291 |
CleanupStack::PopAndDestroy(idConverter);
|
|
292 |
}
|
|
293 |
|
|
294 |
iContactCount++;
|
|
295 |
|
|
296 |
if ( iContactCount == iContactViewBase->ContactCountL() )
|
|
297 |
{
|
|
298 |
iChangeFinder.SetNewSnapshot( iSnapshot ); // changefinder takes ownership
|
|
299 |
iSnapshot = NULL;
|
|
300 |
iSnapshotRegistered = ETrue;
|
|
301 |
User::RequestComplete( iCallerStatus, KErrNone );
|
|
302 |
}
|
|
303 |
|
|
304 |
}
|
|
305 |
// ---------------------------------------------------------------------------
|
|
306 |
// CNSmlContactsModsFetcher::ContactViewReady
|
|
307 |
// Implements the view ready function of MVPbkContactViewObserver
|
|
308 |
// ---------------------------------------------------------------------------
|
|
309 |
void CNSmlContactsModsFetcher::ContactViewReady(
|
|
310 |
MVPbkContactViewBase& /*aView*/ )
|
|
311 |
{
|
|
312 |
_DBG_FILE("CNSmlContactsModsFetcher::ContactViewReady(): begin");
|
|
313 |
|
|
314 |
SetActive();
|
|
315 |
TRequestStatus* status = &iStatus;
|
|
316 |
User::RequestComplete( status, KErrNone );
|
|
317 |
|
|
318 |
_DBG_FILE("CNSmlContactsModsFetcher::ContactViewReady(): end");
|
|
319 |
}
|
|
320 |
|
|
321 |
// ---------------------------------------------------------------------------
|
|
322 |
// CNSmlContactsModsFetcher::ContactViewUnavailable
|
|
323 |
// Implements the view unavailable function of MVPbkContactViewObserver
|
|
324 |
// ---------------------------------------------------------------------------
|
|
325 |
void CNSmlContactsModsFetcher::ContactViewUnavailable(
|
|
326 |
MVPbkContactViewBase& /*aView*/ )
|
|
327 |
{
|
|
328 |
|
|
329 |
|
|
330 |
}
|
|
331 |
|
|
332 |
// ---------------------------------------------------------------------------
|
|
333 |
// CNSmlContactsModsFetcher::ContactAddedToView
|
|
334 |
// Implements the add contact function of MVPbkContactViewObserver
|
|
335 |
// ---------------------------------------------------------------------------
|
|
336 |
void CNSmlContactsModsFetcher::ContactAddedToView(
|
|
337 |
MVPbkContactViewBase& /*aView*/,
|
|
338 |
TInt /*aIndex*/,
|
|
339 |
const MVPbkContactLink& /*aContactLink*/ )
|
|
340 |
{
|
|
341 |
}
|
|
342 |
|
|
343 |
// ---------------------------------------------------------------------------
|
|
344 |
// Implements the remove contact function of MVPbkContactViewObserver
|
|
345 |
// ---------------------------------------------------------------------------
|
|
346 |
void CNSmlContactsModsFetcher::ContactRemovedFromView(
|
|
347 |
MVPbkContactViewBase& /*aView*/,
|
|
348 |
TInt /*aIndex*/,
|
|
349 |
const MVPbkContactLink& /*aContactLink*/ )
|
|
350 |
{
|
|
351 |
}
|
|
352 |
|
|
353 |
// ---------------------------------------------------------------------------
|
|
354 |
// CNSmlContactsModsFetcher::ContactViewError
|
|
355 |
// Implements the view error function of MVPbkContactViewObserver
|
|
356 |
// ---------------------------------------------------------------------------
|
|
357 |
void CNSmlContactsModsFetcher::ContactViewError(
|
|
358 |
MVPbkContactViewBase& /*aView*/,
|
|
359 |
TInt aError,
|
|
360 |
TBool /*aErrorNotified*/ )
|
|
361 |
{
|
|
362 |
User::RequestComplete( iCallerStatus, aError );
|
|
363 |
}
|
|
364 |
|
|
365 |
// ---------------------------------------------------------------------------
|
|
366 |
// CNSmlContactsModsFetcher::VPbkSingleContactOperationComplete
|
|
367 |
// Called when the contact operation is completed.
|
|
368 |
// ---------------------------------------------------------------------------
|
|
369 |
//
|
|
370 |
void CNSmlContactsModsFetcher::VPbkSingleContactOperationComplete(
|
|
371 |
MVPbkContactOperationBase& aOperation,
|
|
372 |
MVPbkStoreContact* aContact )
|
|
373 |
{
|
|
374 |
MVPbkContactOperationBase* operation = &aOperation;
|
|
375 |
if ( operation )
|
|
376 |
{
|
|
377 |
delete operation;
|
|
378 |
operation = NULL;
|
|
379 |
}
|
|
380 |
|
|
381 |
TRAPD(error,UpdateSnapshotL(aContact));
|
|
382 |
delete aContact;
|
|
383 |
if(error!= KErrNone)
|
|
384 |
{
|
|
385 |
User::RequestComplete( iCallerStatus, error );
|
|
386 |
}
|
|
387 |
else
|
|
388 |
{
|
|
389 |
SetActive();
|
|
390 |
TRequestStatus* status = &iStatus;
|
|
391 |
User::RequestComplete( status, KErrNone );
|
|
392 |
}
|
|
393 |
|
|
394 |
}
|
|
395 |
|
|
396 |
// ---------------------------------------------------------------------------
|
|
397 |
// CNSmlContactsModsFetcher::VPbkSingleContactOperationFailed
|
|
398 |
// Called when the contact operation fails
|
|
399 |
// ---------------------------------------------------------------------------
|
|
400 |
//
|
|
401 |
void CNSmlContactsModsFetcher::VPbkSingleContactOperationFailed(
|
|
402 |
MVPbkContactOperationBase& aOperation,
|
|
403 |
TInt /*aError*/ )
|
|
404 |
{
|
|
405 |
MVPbkContactOperationBase* operation = &aOperation;
|
|
406 |
if ( operation )
|
|
407 |
{
|
|
408 |
delete operation;
|
|
409 |
operation = NULL;
|
|
410 |
}
|
|
411 |
}
|
|
412 |
// End of File
|