63
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 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: Active object to handle all data stores from vpbk
|
|
15 |
* Handles add/ modify/ delete of contacts.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
// SYSTEM INCLUDES
|
|
21 |
#include <utf.h>
|
|
22 |
#include <e32std.h>
|
|
23 |
#include <badesca.h>
|
|
24 |
#include <CVPbkContactManager.h>
|
|
25 |
#include <CVPbkContactStoreUriArray.h>
|
|
26 |
#include <CVPbkContactFieldIterator.h>
|
|
27 |
#include <CVPbkFieldTypeRefsList.h>
|
|
28 |
#include <CVPbkContactLinkArray.h>
|
|
29 |
#include <TVPbkContactStoreUriPtr.h>
|
|
30 |
#include <MVPbkContactOperationBase.h>
|
|
31 |
#include <MVPbkContactStoreList.h>
|
|
32 |
#include <MVPbkContactStore.h>
|
|
33 |
#include <MVPbkStoreContact.h>
|
|
34 |
#include <MVPbkContactFieldData.h>
|
|
35 |
#include <MVPbkContactFieldTextData.h>
|
|
36 |
#include <MVPbkContactStoreProperties.h>
|
|
37 |
#include <MVPbkContactLink.h>
|
|
38 |
#include <VPbkEng.rsg>
|
|
39 |
#include <VPbkContactStoreUris.h>
|
|
40 |
#include <CVPbkContactViewDefinition.h>
|
|
41 |
#include <MVPbkContactViewBase.h>
|
|
42 |
#include <VPbkContactView.hrh>
|
|
43 |
#include <CVPbkContactIdConverter.h>
|
|
44 |
#include <centralrepository.h>
|
|
45 |
#include <MVPbkContactGroup.h>
|
|
46 |
#include <CVPbkFieldTypeSelector.h>
|
|
47 |
#include <CVPbkContactLinkArray.h>
|
|
48 |
|
|
49 |
// USER INCLUDES
|
|
50 |
#include "cpcscontactfetch.h"
|
|
51 |
#include "CPsData.h"
|
|
52 |
#include "CPcsDebug.h"
|
|
53 |
#include "CPcsDefs.h"
|
|
54 |
|
|
55 |
// ============================== MEMBER FUNCTIONS ================================
|
|
56 |
|
|
57 |
// ---------------------------------------------------------------------------------
|
|
58 |
// 1st phase constructor
|
|
59 |
// ---------------------------------------------------------------------------------
|
|
60 |
CPcsContactFetch* CPcsContactFetch::NewL()
|
|
61 |
{
|
|
62 |
PRINT ( _L("Enter CPcsContactFetch::NewL") );
|
|
63 |
|
|
64 |
CPcsContactFetch* self = new ( ELeave ) CPcsContactFetch( );
|
|
65 |
CleanupStack::PushL( self );
|
|
66 |
self->ConstructL();
|
|
67 |
CleanupStack::Pop( self );
|
|
68 |
|
|
69 |
PRINT ( _L("End CPcsContactFetch::NewL") );
|
|
70 |
return self;
|
|
71 |
}
|
|
72 |
|
|
73 |
// ---------------------------------------------------------------------------------
|
|
74 |
// Constructor
|
|
75 |
// ---------------------------------------------------------------------------------
|
|
76 |
CPcsContactFetch::CPcsContactFetch() :
|
|
77 |
CActive( CActive::EPriorityStandard ),
|
|
78 |
iAtLeastOneStoreReady(EFalse),
|
|
79 |
iRequestForData(EFalse),
|
|
80 |
iSubStoreCreated(EFalse)
|
|
81 |
{
|
|
82 |
PRINT ( _L("Enter CPcsContactFetch::CPcsContactFetch") );
|
|
83 |
CActiveScheduler::Add( this );
|
|
84 |
PRINT ( _L("End CPcsContactFetch::CPcsContactFetch") );
|
|
85 |
}
|
|
86 |
|
|
87 |
|
|
88 |
// ---------------------------------------------------------------------------------
|
|
89 |
// CContactsSearcher::ConstructL()
|
|
90 |
// 2nd phase constructor
|
|
91 |
// ---------------------------------------------------------------------------------
|
|
92 |
void CPcsContactFetch::ConstructL()
|
|
93 |
{
|
|
94 |
PRINT ( _L("Enter CPcsContactFetch::ConstructL") );
|
|
95 |
|
|
96 |
//Read the URIs from the central repository
|
|
97 |
ReadUrisFromCenrepL();
|
|
98 |
|
|
99 |
// Initialize virtual phonebook with uris read from central repository.
|
|
100 |
CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewLC();
|
|
101 |
for(TInt i = 0; i< iUriFromCenrep.Count();i++)
|
|
102 |
{
|
|
103 |
uriArray->AppendL( TVPbkContactStoreUriPtr(*iUriFromCenrep[i]) );
|
|
104 |
}
|
|
105 |
|
|
106 |
// Create the instance of the contact manager
|
|
107 |
iContactManager = CVPbkContactManager::NewL(*uriArray);
|
|
108 |
CleanupStack::PopAndDestroy(uriArray);
|
|
109 |
|
|
110 |
|
|
111 |
iWait = new( ELeave )CActiveSchedulerWait();
|
|
112 |
|
|
113 |
// Open the data stores associated with this contact manager
|
|
114 |
iContactManager->ContactStoresL().OpenAllL( *this );
|
|
115 |
PRINT ( _L("End CPcsContactFetch::ConstructL") );
|
|
116 |
|
|
117 |
}
|
|
118 |
|
|
119 |
// ---------------------------------------------------------------------------------
|
|
120 |
// Destructor
|
|
121 |
// ---------------------------------------------------------------------------------
|
|
122 |
CPcsContactFetch::~CPcsContactFetch()
|
|
123 |
{
|
|
124 |
PRINT ( _L("Enter CPcsContactFetch::~CPcsContactFetch") );
|
|
125 |
|
|
126 |
//Delete the data stores
|
|
127 |
iAllDataStores.ResetAndDestroy();
|
|
128 |
|
|
129 |
//Delete the contact manager
|
|
130 |
if ( iContactManager )
|
|
131 |
{
|
|
132 |
TRAP_IGNORE(iContactManager->ContactStoresL().CloseAll( *this ));
|
|
133 |
delete iContactManager;
|
|
134 |
iContactManager = NULL;
|
|
135 |
}
|
|
136 |
|
|
137 |
if ( iWait )
|
|
138 |
{
|
|
139 |
if( iWait->IsStarted() )
|
|
140 |
iWait->AsyncStop();
|
|
141 |
delete iWait;
|
|
142 |
iWait = NULL;
|
|
143 |
}
|
|
144 |
|
|
145 |
iUriFromCenrep.ResetAndDestroy();
|
|
146 |
|
|
147 |
if(IsActive())
|
|
148 |
{
|
|
149 |
Deque();
|
|
150 |
}
|
|
151 |
|
|
152 |
PRINT ( _L("End CPcsContactFetch::~CPcsContactFetch") );
|
|
153 |
}
|
|
154 |
|
|
155 |
// ----------------------------------------------------------------------------
|
|
156 |
// CPcsContactFetch::SetObserver
|
|
157 |
//
|
|
158 |
// ----------------------------------------------------------------------------
|
|
159 |
void CPcsContactFetch::SetObserver(MDataStoreObserver& aObserver)
|
|
160 |
{
|
|
161 |
iObserver = &aObserver;
|
|
162 |
}
|
|
163 |
|
|
164 |
// ----------------------------------------------------------------------------
|
|
165 |
// CPcsContactFetch::GetSupportedDataStoresL
|
|
166 |
//
|
|
167 |
// ----------------------------------------------------------------------------
|
|
168 |
void CPcsContactFetch::GetSupportedDataStoresL( RPointerArray<TDesC> &aDataStoresURIs )
|
|
169 |
{
|
|
170 |
PRINT ( _L("Enter CPcsContactFetch::GetSupportedDataStoresL") );
|
|
171 |
for(TInt i =0 ; i < iUriFromCenrep.Count();i++)
|
|
172 |
{
|
|
173 |
aDataStoresURIs.Append(iUriFromCenrep[i]);
|
|
174 |
}
|
|
175 |
PRINT ( _L("End CPcsContactFetch::GetSupportedDataStoresL") );
|
|
176 |
|
|
177 |
}
|
|
178 |
|
|
179 |
// ----------------------------------------------------------------------------
|
|
180 |
// CPcsContactFetch::RequestForDataL
|
|
181 |
//
|
|
182 |
// ----------------------------------------------------------------------------
|
|
183 |
void CPcsContactFetch::RequestForDataL(TDesC& aDataStoreURI)
|
|
184 |
{
|
|
185 |
PRINT ( _L("Enter CPcsContactFetch::RequestForDataL") );
|
|
186 |
|
|
187 |
// Create the substore for this uri
|
|
188 |
CreateSubStoresL(aDataStoreURI);
|
|
189 |
|
|
190 |
PRINT ( _L("End CPcsContactFetch::RequestForDataL") );
|
|
191 |
|
|
192 |
}
|
|
193 |
|
|
194 |
// ---------------------------------------------------------------------------
|
|
195 |
// From class MVPbkContactStoreListObserver.
|
|
196 |
// ---------------------------------------------------------------------------
|
|
197 |
void CPcsContactFetch::OpenComplete()
|
|
198 |
{
|
|
199 |
PRINT ( _L("Enter CPcsContactFetch::OpenComplete") );
|
|
200 |
|
|
201 |
TRequestStatus* status = &iStatus;
|
|
202 |
User::RequestComplete( status, KErrNone );
|
|
203 |
SetActive();
|
|
204 |
|
|
205 |
PRINT ( _L("End CPcsContactFetch::OpenComplete") );
|
|
206 |
}
|
|
207 |
|
|
208 |
// ---------------------------------------------------------------------------
|
|
209 |
// From class MVPbkContactStoreObserver.
|
|
210 |
// ---------------------------------------------------------------------------
|
|
211 |
void CPcsContactFetch::StoreReady(MVPbkContactStore& /*aStore*/)
|
|
212 |
{
|
|
213 |
PRINT ( _L("Enter CPcsContactFetch::StoreReady") );
|
|
214 |
iAtLeastOneStoreReady = ETrue;
|
|
215 |
if( iWait->IsStarted() )
|
|
216 |
iWait->AsyncStop();
|
|
217 |
|
|
218 |
PRINT ( _L("End CPcsContactFetch::StoreReady") );
|
|
219 |
}
|
|
220 |
|
|
221 |
// ---------------------------------------------------------------------------
|
|
222 |
// From class MVPbkContactStoreObserver.
|
|
223 |
// ---------------------------------------------------------------------------
|
|
224 |
void CPcsContactFetch::StoreUnavailable(
|
|
225 |
MVPbkContactStore& /*aContactStore*/, TInt /*aReason*/)
|
|
226 |
{
|
|
227 |
PRINT ( _L("Enter CPcsContactFetch::StoreUnavailable") );
|
|
228 |
//Do nothing
|
|
229 |
PRINT ( _L("End CPcsContactFetch::StoreUnavailable") );
|
|
230 |
}
|
|
231 |
|
|
232 |
// ---------------------------------------------------------------------------
|
|
233 |
// From class MVPbkContactStoreObserver.
|
|
234 |
// ---------------------------------------------------------------------------
|
|
235 |
void CPcsContactFetch::HandleStoreEventL(MVPbkContactStore& aContactStore,
|
|
236 |
TVPbkContactStoreEvent aStoreEvent)
|
|
237 |
{
|
|
238 |
|
|
239 |
for ( TInt i=0; i<iAllDataStores.Count(); i++)
|
|
240 |
{
|
|
241 |
// Check if the store event is related to groups,
|
|
242 |
// if so, then call HandleStoreEventL() for the Groups data store
|
|
243 |
if((aStoreEvent.iEventType == TVPbkContactStoreEvent::EGroupAdded)||
|
|
244 |
(aStoreEvent.iEventType == TVPbkContactStoreEvent::EGroupDeleted)||
|
|
245 |
(aStoreEvent.iEventType == TVPbkContactStoreEvent::EGroupChanged) )
|
|
246 |
{
|
|
247 |
if(iAllDataStores[i]->GetStoreUri().Compare(KVPbkDefaultGrpDbURI) == 0 )
|
|
248 |
{
|
|
249 |
iAllDataStores[i]->HandleStoreEventL(aContactStore, aStoreEvent);
|
|
250 |
break;
|
|
251 |
}
|
|
252 |
}
|
|
253 |
else if(iAllDataStores[i]->GetStoreUri().Compare(aContactStore.StoreProperties().Uri().UriDes()) == 0 )
|
|
254 |
{
|
|
255 |
iAllDataStores[i]->HandleStoreEventL(aContactStore, aStoreEvent);
|
|
256 |
break;
|
|
257 |
}
|
|
258 |
}
|
|
259 |
|
|
260 |
}
|
|
261 |
|
|
262 |
// ---------------------------------------------------------------------------------
|
|
263 |
// Implements cancellation of an outstanding request.
|
|
264 |
// ---------------------------------------------------------------------------------
|
|
265 |
void CPcsContactFetch::DoCancel()
|
|
266 |
{
|
|
267 |
// Do nothing
|
|
268 |
}
|
|
269 |
|
|
270 |
|
|
271 |
// ---------------------------------------------------------------------------------
|
|
272 |
// The function is called by the active scheduler
|
|
273 |
// ---------------------------------------------------------------------------------
|
|
274 |
void CPcsContactFetch::RunL()
|
|
275 |
{
|
|
276 |
|
|
277 |
if (!iAtLeastOneStoreReady)
|
|
278 |
{
|
|
279 |
if( iWait->IsStarted() )
|
|
280 |
iWait->AsyncStop();
|
|
281 |
}
|
|
282 |
}
|
|
283 |
|
|
284 |
// ---------------------------------------------------------------------------------
|
|
285 |
// Called in case of any errros
|
|
286 |
// ---------------------------------------------------------------------------------
|
|
287 |
TInt CPcsContactFetch::RunError(TInt aError)
|
|
288 |
{
|
|
289 |
return aError;
|
|
290 |
}
|
|
291 |
|
|
292 |
// ---------------------------------------------------------------------------
|
|
293 |
// Reads the Uris from the cenrep
|
|
294 |
// ---------------------------------------------------------------------------
|
|
295 |
|
|
296 |
void CPcsContactFetch::ReadUrisFromCenrepL()
|
|
297 |
{
|
|
298 |
|
|
299 |
CRepository* repository = CRepository::NewL( KCRUidPSContacts );
|
|
300 |
CleanupStack::PushL( repository );
|
|
301 |
|
|
302 |
// Read the cenrep for URIs
|
|
303 |
TBuf<KCRMaxLen> uriStr;
|
|
304 |
for (TInt i(KUriCenRepStartKey); i < KUriCenRepStartKey + KCenrepUriSupportedCount; i++ )
|
|
305 |
{
|
|
306 |
TInt err = repository->Get( i, uriStr );
|
|
307 |
if (KErrNone != err)
|
|
308 |
{
|
|
309 |
break;
|
|
310 |
}
|
|
311 |
|
|
312 |
if (uriStr != KNullDesC)
|
|
313 |
{
|
|
314 |
HBufC* uri = uriStr.AllocLC();
|
|
315 |
iUriFromCenrep.AppendL(uri);
|
|
316 |
CleanupStack::Pop(uri);
|
|
317 |
}
|
|
318 |
|
|
319 |
}
|
|
320 |
|
|
321 |
CleanupStack::PopAndDestroy( repository );
|
|
322 |
}
|
|
323 |
|
|
324 |
|
|
325 |
// ---------------------------------------------------------------------------
|
|
326 |
// Creates the contact view
|
|
327 |
// ---------------------------------------------------------------------------
|
|
328 |
void CPcsContactFetch::CreateSubStoresL(TDesC& aDataStoreURI)
|
|
329 |
{
|
|
330 |
PRINT ( _L("Enter CPcsContactFetch::CreateSubStoresL") );
|
|
331 |
|
|
332 |
if (!iAtLeastOneStoreReady)
|
|
333 |
{
|
|
334 |
if( ! (iWait->IsStarted()) )
|
|
335 |
{
|
|
336 |
iWait->Start();
|
|
337 |
}
|
|
338 |
}
|
|
339 |
|
|
340 |
// Check if data store is already present
|
|
341 |
for ( TInt i = 0; i < iAllDataStores.Count(); i++ )
|
|
342 |
{
|
|
343 |
CPcsContactStore* contactStore = iAllDataStores[i];
|
|
344 |
if ( contactStore->GetStoreUri().Compare(aDataStoreURI) == 0 )
|
|
345 |
{
|
|
346 |
// Remove the store
|
|
347 |
delete contactStore;
|
|
348 |
iAllDataStores.Remove(i);
|
|
349 |
break;
|
|
350 |
}
|
|
351 |
}
|
|
352 |
|
|
353 |
MVPbkContactStoreList& stores = iContactManager->ContactStoresL();
|
|
354 |
for ( TInt i(0); i < stores.Count(); ++i )
|
|
355 |
{
|
|
356 |
if(stores.At(i).StoreProperties().Uri().UriDes().Compare(aDataStoreURI) == 0)
|
|
357 |
{
|
|
358 |
CPcsContactStore* contactStore = CPcsContactStore::NewL(*iContactManager,
|
|
359 |
*iObserver,
|
|
360 |
stores.At(i).StoreProperties().Uri().UriDes());
|
|
361 |
iAllDataStores.Append(contactStore);
|
|
362 |
break;
|
|
363 |
}
|
|
364 |
}
|
|
365 |
PRINT ( _L("End CPcsContactFetch::CreateSubStoresL") );
|
|
366 |
|
|
367 |
}
|
|
368 |
|
|
369 |
// ----------------------------------------------------------------------------
|
|
370 |
// CPcsContactFetch::GetSupportedDataFieldsL
|
|
371 |
//
|
|
372 |
// ----------------------------------------------------------------------------
|
|
373 |
void CPcsContactFetch::GetSupportedDataFieldsL(RArray<TInt> &aDataFields )
|
|
374 |
{
|
|
375 |
PRINT ( _L("Enter CPcsContactFetch::GetSupportedDataFieldsL") );
|
|
376 |
CRepository *repository = CRepository::NewL( KCRUidPSContacts );
|
|
377 |
|
|
378 |
// Read the data fields from cenrep
|
|
379 |
for (TInt i(KCenrepFieldsStartKey); i < KCenrepFieldsStartKey + KCenrepNumberOfFieldsCount; i++ )
|
|
380 |
{
|
|
381 |
TInt fieldToCache(-1);
|
|
382 |
|
|
383 |
TInt err = repository->Get(i, fieldToCache );
|
|
384 |
if ( KErrNone != err )
|
|
385 |
{
|
|
386 |
break;
|
|
387 |
}
|
|
388 |
if ( fieldToCache != 0 )
|
|
389 |
{
|
|
390 |
aDataFields.Append(fieldToCache);
|
|
391 |
}
|
|
392 |
|
|
393 |
}
|
|
394 |
|
|
395 |
delete repository;
|
|
396 |
PRINT ( _L("End CPcsContactFetch::GetSupportedDataFieldsL") );
|
|
397 |
}
|
|
398 |
|
|
399 |
// ----------------------------------------------------------------------------
|
|
400 |
// CPcsContactFetch::IsDataStoresSupportedL
|
|
401 |
//
|
|
402 |
// ----------------------------------------------------------------------------
|
|
403 |
TBool CPcsContactFetch::IsDataStoresSupportedL( TDesC& aDataStoreURI )
|
|
404 |
{
|
|
405 |
|
|
406 |
for ( TInt i = 0 ; i < iUriFromCenrep.Count() ; i++ )
|
|
407 |
{
|
|
408 |
if ( iUriFromCenrep[i]->Compare(aDataStoreURI) == 0 )
|
|
409 |
return ETrue;
|
|
410 |
}
|
|
411 |
|
|
412 |
return EFalse;
|
|
413 |
}
|
|
414 |
|
|
415 |
// End of file
|