63
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-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: Contacts Model store contact store implementation.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDES
|
|
20 |
#include "CContactStore.h"
|
|
21 |
|
|
22 |
// VPbkCntModel
|
|
23 |
#include "CFieldFactory.h"
|
|
24 |
#include "CFieldTypeMap.h"
|
|
25 |
#include "CAsyncContactOperation.h"
|
|
26 |
#include "CContact.h"
|
|
27 |
#include "CContactLink.h"
|
|
28 |
#include "CContactBookmark.h"
|
|
29 |
#include "CContactView.h"
|
|
30 |
#include "CFilteredContactView.h"
|
|
31 |
#include "CFilteredGroupView.h"
|
|
32 |
#include "CGroupView.h"
|
|
33 |
#include "CContactStoreDomain.h"
|
|
34 |
#include "CFieldInfo.h"
|
|
35 |
#include "CContactRetriever.h"
|
|
36 |
#include "CDeleteContactsOperation.h"
|
|
37 |
#include "CCommitContactsOperation.h"
|
|
38 |
#include "CMatchPhoneNumberOperation.h"
|
|
39 |
#include "CFindOperation.h"
|
|
40 |
#include "CFindInTextDefOperation.h"
|
|
41 |
#include "CContactStoreInfo.h"
|
|
42 |
#include "CVPbkDiskSpaceCheck.h"
|
|
43 |
#include "CNamedRemoteViewHandle.h"
|
|
44 |
#include "CSortOrderAcquirerList.h"
|
|
45 |
#include "VoiceTagSupport.h"
|
|
46 |
#include "CContactLink.h"
|
|
47 |
#include "COwnContactLinkOperation.h"
|
|
48 |
#include <VPbkCntModelRes.rsg>
|
|
49 |
|
|
50 |
// Virtual Phonebook
|
|
51 |
#include <VPbkError.h>
|
|
52 |
#include <MVPbkContactStoreObserver.h>
|
|
53 |
#include <TVPbkContactStoreUriPtr.h>
|
|
54 |
#include <CVPbkContactStoreUri.h>
|
|
55 |
#include <CVPbkAsyncOperation.h>
|
|
56 |
#include <RLocalizedResourceFile.h>
|
|
57 |
#include <CVPbkAsyncCallback.h>
|
|
58 |
#include <CVPbkContactViewDefinition.h>
|
|
59 |
#include <VPbkContactView.hrh>
|
|
60 |
#include <CVPbkContactStoreProperties.h>
|
|
61 |
#include <CVPbkLocalVariationManager.h>
|
|
62 |
#include <CVPbkFieldTypeSelector.h>
|
|
63 |
#include <VPbkUtils.h>
|
|
64 |
#include <TVPbkContactStoreUriPtr.h>
|
|
65 |
#include <VPbkDataCaging.hrh>
|
|
66 |
#include <VPbkContactStoreUris.h>
|
|
67 |
#include <MVPbkSingleContactLinkOperationObserver.h>
|
|
68 |
|
|
69 |
// Contacts Model
|
|
70 |
#include <cntdb.h>
|
|
71 |
#include <cntitem.h>
|
|
72 |
#include <cntmodel.rsg>
|
|
73 |
|
|
74 |
// System includes
|
|
75 |
#include <barsc.h>
|
|
76 |
#include <barsread.h>
|
|
77 |
#include <featmgr.h>
|
|
78 |
#include <shareddataclient.h>
|
|
79 |
#include <coemain.h>
|
|
80 |
|
|
81 |
// Debugging headers
|
|
82 |
#include <VPbkDebug.h>
|
|
83 |
|
|
84 |
|
|
85 |
namespace VPbkCntModel {
|
|
86 |
|
|
87 |
#ifdef _DEBUG
|
|
88 |
_LIT( KContactStorePanicCat, "VPbkCntModel_CContactStore" );
|
|
89 |
void ContactStorePanic( TContactStorePanic aPanic )
|
|
90 |
{
|
|
91 |
User::Panic( KContactStorePanicCat, aPanic);
|
|
92 |
}
|
|
93 |
#endif // _DEBUG
|
|
94 |
|
|
95 |
/// Unnamed namespace for local definitions
|
|
96 |
namespace {
|
|
97 |
|
|
98 |
// LOCAL
|
|
99 |
_LIT(KCntResFile, "cntmodel.rsc");
|
|
100 |
_LIT(KCntExtResFile, "VPbkCntModelRes.rsc");
|
|
101 |
|
|
102 |
// CONSTANTS
|
|
103 |
const TInt KDefaultArrayGranularity = 4;
|
|
104 |
const TInt KDiskSpaceForDbOpening = 140 * 1024; // 140 kB space for db opening
|
|
105 |
|
|
106 |
inline void SendEventL(MVPbkContactStoreObserver* aObserver,
|
|
107 |
void (MVPbkContactStoreObserver::*aEventFunc)(MVPbkContactStore&),
|
|
108 |
MVPbkContactStore& aStore)
|
|
109 |
{
|
|
110 |
(aObserver->*aEventFunc)(aStore);
|
|
111 |
}
|
|
112 |
|
|
113 |
inline void SendEventL(
|
|
114 |
MVPbkContactStoreObserver* aObserver,
|
|
115 |
void (MVPbkContactStoreObserver::*aEventFunc)(MVPbkContactStore&,TVPbkContactStoreEvent),
|
|
116 |
MVPbkContactStore& aStore,
|
|
117 |
TVPbkContactStoreEvent aEvent)
|
|
118 |
{
|
|
119 |
(aObserver->*aEventFunc)(aStore, aEvent);
|
|
120 |
}
|
|
121 |
|
|
122 |
inline void SendErrorEvent(MVPbkContactStoreObserver* aObserver,
|
|
123 |
void (MVPbkContactStoreObserver::*aEventFunc)(MVPbkContactStore&,TInt),
|
|
124 |
MVPbkContactStore& aStore, TInt aError)
|
|
125 |
{
|
|
126 |
(aObserver->*aEventFunc)(aStore, aError);
|
|
127 |
}
|
|
128 |
|
|
129 |
void SendEventL
|
|
130 |
(RPointerArray<MVPbkContactStoreObserver>& aObservers,
|
|
131 |
void (MVPbkContactStoreObserver::*aEventFunc)(MVPbkContactStore&),
|
|
132 |
MVPbkContactStore& aStore)
|
|
133 |
{
|
|
134 |
for (TInt i = aObservers.Count() - 1; i >= 0; --i)
|
|
135 |
{
|
|
136 |
SendEventL(aObservers[i], aEventFunc, aStore);
|
|
137 |
}
|
|
138 |
}
|
|
139 |
|
|
140 |
void SendEventL
|
|
141 |
(RPointerArray<MVPbkContactStoreObserver>& aObservers,
|
|
142 |
void (MVPbkContactStoreObserver::*aEventFunc)(MVPbkContactStore&,TVPbkContactStoreEvent),
|
|
143 |
MVPbkContactStore& aStore,
|
|
144 |
TVPbkContactStoreEvent aEvent)
|
|
145 |
{
|
|
146 |
for (TInt i = aObservers.Count() - 1; i >= 0; --i)
|
|
147 |
{
|
|
148 |
SendEventL(aObservers[i], aEventFunc, aStore, aEvent);
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
void SendErrorEvent
|
|
153 |
(RPointerArray<MVPbkContactStoreObserver>& aObservers,
|
|
154 |
void (MVPbkContactStoreObserver::*aEventFunc)(MVPbkContactStore&,TInt),
|
|
155 |
MVPbkContactStore& aStore, TInt aError)
|
|
156 |
{
|
|
157 |
for (TInt i = aObservers.Count() - 1; i >= 0; --i)
|
|
158 |
{
|
|
159 |
SendErrorEvent(aObservers[i], aEventFunc, aStore, aError);
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
TBool UpdateSystemTemplateFieldL(CContactItem& aSystemTemplate,
|
|
164 |
const CFieldInfo& aFieldInfo )
|
|
165 |
{
|
|
166 |
TBool updated = EFalse;
|
|
167 |
// Scan system template field set for the field
|
|
168 |
CContactItemFieldSet& fieldSet = aSystemTemplate.CardFields();
|
|
169 |
const TInt fieldCount = fieldSet.Count();
|
|
170 |
TInt i = 0;
|
|
171 |
for (; i < fieldCount; ++i)
|
|
172 |
{
|
|
173 |
CContactItemField& sysTemplateField = fieldSet[i];
|
|
174 |
if (aFieldInfo.IsEqualType(sysTemplateField))
|
|
175 |
{
|
|
176 |
// Field was found, just check the label
|
|
177 |
if (!aFieldInfo.IsEqualLabel(sysTemplateField))
|
|
178 |
{
|
|
179 |
sysTemplateField.SetLabelL(aFieldInfo.FieldName());
|
|
180 |
updated = ETrue;
|
|
181 |
}
|
|
182 |
break;
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
if ( i == fieldCount )
|
|
187 |
{
|
|
188 |
// Field was not found, add it
|
|
189 |
CContactItemField* field = aFieldInfo.CreateFieldL();
|
|
190 |
CleanupStack::PushL( field );
|
|
191 |
fieldSet.AddL( *field );
|
|
192 |
CleanupStack::Pop( field );
|
|
193 |
updated = ETrue;
|
|
194 |
}
|
|
195 |
|
|
196 |
return updated;
|
|
197 |
}
|
|
198 |
|
|
199 |
TBool UpdateSystemTemplateFieldsL(CContactItem& aSystemTemplate, const CFieldsInfo& aFieldsInfo)
|
|
200 |
{
|
|
201 |
TBool updated = EFalse;
|
|
202 |
const TInt fieldInfoCount = aFieldsInfo.Count();
|
|
203 |
|
|
204 |
for (TInt i = 0; i < fieldInfoCount; ++i)
|
|
205 |
{
|
|
206 |
if (UpdateSystemTemplateFieldL(aSystemTemplate, *aFieldsInfo.At(i)))
|
|
207 |
{
|
|
208 |
updated = ETrue;
|
|
209 |
}
|
|
210 |
}
|
|
211 |
return updated;
|
|
212 |
}
|
|
213 |
|
|
214 |
|
|
215 |
TVPbkContactStoreEvent MapDbEventToStoreEvent(TContactDbObserverEvent aEvent)
|
|
216 |
{
|
|
217 |
TVPbkContactStoreEvent result(TVPbkContactStoreEvent::ENullEvent, NULL);
|
|
218 |
|
|
219 |
switch (aEvent.iType)
|
|
220 |
{
|
|
221 |
case EContactDbObserverEventContactAdded:
|
|
222 |
{
|
|
223 |
result.iEventType = TVPbkContactStoreEvent::EContactAdded;
|
|
224 |
break;
|
|
225 |
}
|
|
226 |
case EContactDbObserverEventContactDeleted:
|
|
227 |
case EContactDbObserverEventOwnCardDeleted:
|
|
228 |
{
|
|
229 |
result.iEventType = TVPbkContactStoreEvent::EContactDeleted;
|
|
230 |
break;
|
|
231 |
}
|
|
232 |
case EContactDbObserverEventContactChanged:
|
|
233 |
case EContactDbObserverEventSpeedDialsChanged:
|
|
234 |
case EContactDbObserverEventOwnCardChanged:
|
|
235 |
{
|
|
236 |
result.iEventType = TVPbkContactStoreEvent::EContactChanged;
|
|
237 |
break;
|
|
238 |
}
|
|
239 |
case EContactDbObserverEventGroupAdded:
|
|
240 |
{
|
|
241 |
result.iEventType = TVPbkContactStoreEvent::EGroupAdded;
|
|
242 |
break;
|
|
243 |
}
|
|
244 |
case EContactDbObserverEventGroupDeleted:
|
|
245 |
{
|
|
246 |
result.iEventType = TVPbkContactStoreEvent::EGroupDeleted;
|
|
247 |
break;
|
|
248 |
}
|
|
249 |
case EContactDbObserverEventGroupChanged:
|
|
250 |
{
|
|
251 |
result.iEventType = TVPbkContactStoreEvent::EGroupChanged;
|
|
252 |
break;
|
|
253 |
}
|
|
254 |
case EContactDbObserverEventUnknownChanges:
|
|
255 |
{
|
|
256 |
result.iEventType = TVPbkContactStoreEvent::EUnknownChanges;
|
|
257 |
break;
|
|
258 |
}
|
|
259 |
case EContactDbObserverEventBackupBeginning:
|
|
260 |
{
|
|
261 |
result.iEventType = TVPbkContactStoreEvent::EStoreBackupBeginning;
|
|
262 |
break;
|
|
263 |
}
|
|
264 |
case EContactDbObserverEventRestoreBeginning:
|
|
265 |
{
|
|
266 |
result.iEventType = TVPbkContactStoreEvent::EStoreRestoreBeginning;
|
|
267 |
break;
|
|
268 |
}
|
|
269 |
case EContactDbObserverEventBackupRestoreCompleted:
|
|
270 |
{
|
|
271 |
result.iEventType = TVPbkContactStoreEvent::EStoreBackupRestoreCompleted;
|
|
272 |
break;
|
|
273 |
}
|
|
274 |
case EContactDbObserverEventCurrentItemDeleted: // FALLTHROUGH
|
|
275 |
case EContactDbObserverEventCurrentItemChanged: // FALLTHROUGH
|
|
276 |
case EContactDbObserverEventCurrentDatabaseChanged: // FALLTHROUGH
|
|
277 |
case EContactDbObserverEventRestoreBadDatabase: // FALLTHROUGH
|
|
278 |
case EContactDbObserverEventSortOrderChanged: // FALLTHROUGH
|
|
279 |
case EContactDbObserverEventPreferredTemplateChanged: // FALLTHROUGH
|
|
280 |
case EContactDbObserverEventRecover: // FALLTHROUGH
|
|
281 |
case EContactDbObserverEventRollback: // FALLTHROUGH
|
|
282 |
case EContactDbObserverEventTablesClosed: // FALLTHROUGH
|
|
283 |
case EContactDbObserverEventTablesOpened: // FALLTHROUGH
|
|
284 |
case EContactDbObserverEventTemplateChanged: // FALLTHROUGH
|
|
285 |
case EContactDbObserverEventTemplateDeleted: // FALLTHROUGH
|
|
286 |
case EContactDbObserverEventTemplateAdded: // FALLTHROUGH
|
|
287 |
case EContactDbObserverEventNull: // FALLTHROUGH
|
|
288 |
case EContactDbObserverEventUnused: // FALLTHROUGH
|
|
289 |
default:
|
|
290 |
{
|
|
291 |
result.iEventType = TVPbkContactStoreEvent::ENullEvent;
|
|
292 |
break;
|
|
293 |
}
|
|
294 |
}
|
|
295 |
|
|
296 |
return result;
|
|
297 |
}
|
|
298 |
|
|
299 |
} // unnamed namespace
|
|
300 |
|
|
301 |
// --------------------------------------------------------------------------
|
|
302 |
// CContactStoreOpenOperation
|
|
303 |
// --------------------------------------------------------------------------
|
|
304 |
//
|
|
305 |
class CContactStoreOpenOperation : public CActive
|
|
306 |
{
|
|
307 |
public: // construction & destruction
|
|
308 |
|
|
309 |
/**
|
|
310 |
* Open native contact database operation. Started automatically.
|
|
311 |
*
|
|
312 |
* @param aStore Store that will receive events when operation is complete
|
|
313 |
* @param aReplace replace contact database (instead of open)
|
|
314 |
*/
|
|
315 |
CContactStoreOpenOperation( CContactStore& aStore, TBool aReplace );
|
|
316 |
|
|
317 |
~CContactStoreOpenOperation();
|
|
318 |
|
|
319 |
private: // From CActive
|
|
320 |
void DoCancel();
|
|
321 |
void RunL();
|
|
322 |
TInt RunError( TInt aError );
|
|
323 |
|
|
324 |
private: // data types
|
|
325 |
|
|
326 |
/// Operation states
|
|
327 |
enum TStates
|
|
328 |
{
|
|
329 |
// Operation: Replace default store
|
|
330 |
// Next states: [EStateDone]
|
|
331 |
EStateReplaceStore,
|
|
332 |
|
|
333 |
// Operation: Open default store
|
|
334 |
// Next states: [EStateStoreOpened]
|
|
335 |
EStateOpenStore,
|
|
336 |
|
|
337 |
// Result: State when store has been opened (success or failure)
|
|
338 |
// Next states: [EStateStoreOpenedAfterError, EStateDone]
|
|
339 |
EStateStoreOpened,
|
|
340 |
|
|
341 |
// Result: State after second attempt to open store (first have failed).
|
|
342 |
// Next states: [EStateDone]
|
|
343 |
EStateStoreOpenedAfterError,
|
|
344 |
|
|
345 |
// Result: DB has been opened successfully. Report it to store.
|
|
346 |
// Next states: -
|
|
347 |
EStateDone,
|
|
348 |
};
|
|
349 |
|
|
350 |
private: // implementation
|
|
351 |
|
|
352 |
/**
|
|
353 |
* Move to next state asynchronously
|
|
354 |
*/
|
|
355 |
void IssueRequest( TStates aNextState, TInt aError = KErrNone );
|
|
356 |
|
|
357 |
/**
|
|
358 |
* Handle state EStateStoreOpened
|
|
359 |
*/
|
|
360 |
void HandleStoreOpenedL( TInt aError );
|
|
361 |
|
|
362 |
private: // data
|
|
363 |
|
|
364 |
/// Active state
|
|
365 |
TStates iState;
|
|
366 |
/// Ref: Contact store
|
|
367 |
CContactStore& iStore;
|
|
368 |
/// Own: Native contact database
|
|
369 |
CContactDatabase* iDb;
|
|
370 |
/// Own: Native contact database open operation
|
|
371 |
CContactOpenOperation* iOperation;
|
|
372 |
};
|
|
373 |
|
|
374 |
// --------------------------------------------------------------------------
|
|
375 |
// CContactStoreOpenOperation::~CContactStoreOpenOperation
|
|
376 |
// --------------------------------------------------------------------------
|
|
377 |
//
|
|
378 |
CContactStoreOpenOperation::~CContactStoreOpenOperation()
|
|
379 |
{
|
|
380 |
Cancel();
|
|
381 |
delete iDb;
|
|
382 |
delete iOperation;
|
|
383 |
}
|
|
384 |
|
|
385 |
// --------------------------------------------------------------------------
|
|
386 |
// CContactStoreOpenOperation::DoCancel
|
|
387 |
// --------------------------------------------------------------------------
|
|
388 |
//
|
|
389 |
void CContactStoreOpenOperation::DoCancel()
|
|
390 |
{
|
|
391 |
delete iOperation;
|
|
392 |
iOperation = NULL;
|
|
393 |
}
|
|
394 |
|
|
395 |
// --------------------------------------------------------------------------
|
|
396 |
// CContactStoreOpenOperation::RunL
|
|
397 |
// --------------------------------------------------------------------------
|
|
398 |
//
|
|
399 |
void CContactStoreOpenOperation::RunL()
|
|
400 |
{
|
|
401 |
switch( iState )
|
|
402 |
{
|
|
403 |
case EStateReplaceStore:
|
|
404 |
{
|
|
405 |
iDb = CContactDatabase::ReplaceL(
|
|
406 |
iStore.StoreProperties().Name().UriDes() );
|
|
407 |
IssueRequest( EStateDone );
|
|
408 |
break;
|
|
409 |
}
|
|
410 |
case EStateOpenStore:
|
|
411 |
{
|
|
412 |
iOperation = CContactDatabase::Open(
|
|
413 |
iStore.StoreProperties().Name().UriDes(), iStatus );
|
|
414 |
SetActive();
|
|
415 |
iState = EStateStoreOpened;
|
|
416 |
break;
|
|
417 |
}
|
|
418 |
case EStateStoreOpened:
|
|
419 |
{
|
|
420 |
HandleStoreOpenedL( iStatus.Int() );
|
|
421 |
break;
|
|
422 |
}
|
|
423 |
case EStateStoreOpenedAfterError:
|
|
424 |
{
|
|
425 |
User::LeaveIfError( iStatus.Int() ); // report errors immediately
|
|
426 |
iDb = iOperation->TakeDatabase();
|
|
427 |
IssueRequest( EStateDone );
|
|
428 |
break;
|
|
429 |
}
|
|
430 |
case EStateDone:
|
|
431 |
{
|
|
432 |
CContactDatabase* db = iDb;
|
|
433 |
iDb = NULL; // give ownership
|
|
434 |
CContactStore& store = iStore;
|
|
435 |
|
|
436 |
TRAPD( err, store.StoreOpenedL( db ) );
|
|
437 |
// NOTE! Don't touch members after this call.
|
|
438 |
// This instance could be deleted
|
|
439 |
if( err )
|
|
440 |
{
|
|
441 |
store.StoreOpenFailed( err );
|
|
442 |
}
|
|
443 |
break;
|
|
444 |
}
|
|
445 |
default:
|
|
446 |
{
|
|
447 |
// unknown state
|
|
448 |
__ASSERT_DEBUG( EFalse,
|
|
449 |
ContactStorePanic( EPreCond_OpenOperationState ) );
|
|
450 |
iStore.StoreOpenFailed( KErrUnknown );
|
|
451 |
}
|
|
452 |
}
|
|
453 |
}
|
|
454 |
|
|
455 |
// --------------------------------------------------------------------------
|
|
456 |
// CContactStoreOpenOperation::RunError
|
|
457 |
// --------------------------------------------------------------------------
|
|
458 |
//
|
|
459 |
TInt CContactStoreOpenOperation::RunError( TInt aError )
|
|
460 |
{
|
|
461 |
iStore.StoreOpenFailed( aError );
|
|
462 |
return KErrNone;
|
|
463 |
}
|
|
464 |
|
|
465 |
// --------------------------------------------------------------------------
|
|
466 |
// CContactStoreOpenOperation::CContactStoreOpenOperation
|
|
467 |
// --------------------------------------------------------------------------
|
|
468 |
//
|
|
469 |
CContactStoreOpenOperation::CContactStoreOpenOperation(
|
|
470 |
CContactStore& aStore, TBool aReplace ) :
|
|
471 |
CActive( EPriorityLow ),
|
|
472 |
iStore( aStore )
|
|
473 |
{
|
|
474 |
CActiveScheduler::Add( this );
|
|
475 |
IssueRequest( aReplace ? EStateReplaceStore : EStateOpenStore ); // start working
|
|
476 |
}
|
|
477 |
|
|
478 |
// --------------------------------------------------------------------------
|
|
479 |
// CContactStoreOpenOperation::IssueRequest
|
|
480 |
// --------------------------------------------------------------------------
|
|
481 |
//
|
|
482 |
void CContactStoreOpenOperation::IssueRequest( TStates aNextState, TInt aError )
|
|
483 |
{
|
|
484 |
if( !IsActive() )
|
|
485 |
{
|
|
486 |
TRequestStatus* status = &iStatus;
|
|
487 |
User::RequestComplete( status, aError );
|
|
488 |
SetActive();
|
|
489 |
iState = aNextState;
|
|
490 |
}
|
|
491 |
}
|
|
492 |
|
|
493 |
// --------------------------------------------------------------------------
|
|
494 |
// CContactStoreOpenOperation::HandleStoreOpenedL
|
|
495 |
// --------------------------------------------------------------------------
|
|
496 |
//
|
|
497 |
void CContactStoreOpenOperation::HandleStoreOpenedL( TInt aError )
|
|
498 |
{
|
|
499 |
if( aError == KErrNone )
|
|
500 |
{
|
|
501 |
// Store opened succesfully
|
|
502 |
iDb = iOperation->TakeDatabase();
|
|
503 |
IssueRequest( EStateDone );
|
|
504 |
}
|
|
505 |
else // some error happened
|
|
506 |
{
|
|
507 |
delete iOperation;
|
|
508 |
iOperation = NULL;
|
|
509 |
|
|
510 |
const TDesC& dbName = iStore.StoreProperties().Name().UriDes();
|
|
511 |
TInt creating = EFalse;
|
|
512 |
|
|
513 |
if( aError == KErrNotFound )
|
|
514 |
{
|
|
515 |
// Database not found --> Creating it
|
|
516 |
creating = ETrue;
|
|
517 |
TRAP( aError, iDb = CContactDatabase::CreateL( dbName ) );
|
|
518 |
}
|
|
519 |
|
|
520 |
if ( KErrDiskFull == aError )
|
|
521 |
{
|
|
522 |
// Try to release space for contact db opening
|
|
523 |
if( iStore.RequestFreeDiskSpaceLC( KDiskSpaceForDbOpening ) )
|
|
524 |
{
|
|
525 |
aError = KErrNone;
|
|
526 |
if( creating )
|
|
527 |
{
|
|
528 |
// Databse was not found --> Creating it
|
|
529 |
iDb = CContactDatabase::CreateL( dbName );
|
|
530 |
}
|
|
531 |
else
|
|
532 |
{
|
|
533 |
// Opening database
|
|
534 |
iOperation = CContactDatabase::Open( dbName, iStatus );
|
|
535 |
SetActive();
|
|
536 |
iState = EStateStoreOpenedAfterError;
|
|
537 |
}
|
|
538 |
CleanupStack::PopAndDestroy(); // RequestFreeDiskSpaceLC
|
|
539 |
}
|
|
540 |
}
|
|
541 |
|
|
542 |
// leave on unhandled error
|
|
543 |
User::LeaveIfError( aError );
|
|
544 |
|
|
545 |
if( iDb )
|
|
546 |
{
|
|
547 |
IssueRequest( EStateDone );
|
|
548 |
}
|
|
549 |
}
|
|
550 |
}
|
|
551 |
|
|
552 |
// --------------------------------------------------------------------------
|
|
553 |
// CContactStore::CContactStore
|
|
554 |
// --------------------------------------------------------------------------
|
|
555 |
//
|
|
556 |
CContactStore::CContactStore( CContactStoreDomain& aStoreDomain ) :
|
|
557 |
iStoreDomain( aStoreDomain )
|
|
558 |
{
|
|
559 |
}
|
|
560 |
|
|
561 |
// --------------------------------------------------------------------------
|
|
562 |
// CContactStore::~CContactStore
|
|
563 |
// --------------------------------------------------------------------------
|
|
564 |
//
|
|
565 |
CContactStore::~CContactStore()
|
|
566 |
{
|
|
567 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
568 |
("CContactStore::~CContactStore(0x%x)"), this);
|
|
569 |
|
|
570 |
iNamedViewContainer.ResetAndDestroy();
|
|
571 |
CloseSystemTemplate(iContactDb);
|
|
572 |
iObservers.Close();
|
|
573 |
delete iStoreInfo;
|
|
574 |
delete iDbNotifier;
|
|
575 |
delete iContactDb;
|
|
576 |
delete iAsyncContactOperation;
|
|
577 |
delete iAsyncOpenOp;
|
|
578 |
delete iStoreURI;
|
|
579 |
delete iFieldFactory;
|
|
580 |
delete iFieldsInfo;
|
|
581 |
delete iProperties;
|
|
582 |
delete iDiskSpaceCheck;
|
|
583 |
delete iOpenOperation;
|
|
584 |
FeatureManager::UnInitializeLib();
|
|
585 |
}
|
|
586 |
|
|
587 |
// --------------------------------------------------------------------------
|
|
588 |
// CContactStore::NewL
|
|
589 |
// --------------------------------------------------------------------------
|
|
590 |
//
|
|
591 |
CContactStore* CContactStore::NewL
|
|
592 |
(const TVPbkContactStoreUriPtr& aURI,
|
|
593 |
CContactStoreDomain& aStoreDomain)
|
|
594 |
{
|
|
595 |
CContactStore* self = new(ELeave) CContactStore(aStoreDomain);
|
|
596 |
CleanupStack::PushL(self);
|
|
597 |
self->ConstructL(aURI);
|
|
598 |
CleanupStack::Pop(self);
|
|
599 |
return self;
|
|
600 |
}
|
|
601 |
|
|
602 |
// --------------------------------------------------------------------------
|
|
603 |
// CContactStore::ConstructL
|
|
604 |
// --------------------------------------------------------------------------
|
|
605 |
//
|
|
606 |
inline void CContactStore::ConstructL(
|
|
607 |
const TVPbkContactStoreUriPtr& aURI)
|
|
608 |
{
|
|
609 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
610 |
("CContactStore::ConstructL(%S)"), &aURI.UriDes());
|
|
611 |
|
|
612 |
FeatureManager::InitializeLibL();
|
|
613 |
iProperties = CVPbkContactStoreProperties::NewL();
|
|
614 |
iStoreURI = CVPbkContactStoreUri::NewL(aURI);
|
|
615 |
iProperties->SetName(iStoreURI->Uri());
|
|
616 |
|
|
617 |
// open and read the contacts model resource file cntmodel.rsc
|
|
618 |
VPbkEngUtils::RLocalizedResourceFile resFile;
|
|
619 |
resFile.OpenLC(iStoreDomain.FsSession(),
|
|
620 |
KVPbkRomFileDrive, KDC_CONTACTS_RESOURCE_DIR, KCntResFile);
|
|
621 |
|
|
622 |
TResourceReader reader;
|
|
623 |
reader.SetBuffer( resFile.AllocReadLC(R_CNTUI_NEW_FIELD_DEFNS) );
|
|
624 |
// create the fields info structure from the contacts model fields
|
|
625 |
iFieldsInfo = CFieldsInfo::NewL(reader);
|
|
626 |
CleanupStack::PopAndDestroy(2); // R_CNTUI_NEW_FIELD_DEFNS buffer, resFile
|
|
627 |
|
|
628 |
// Extend the contacts model golden template with variant fields
|
|
629 |
DoAddFieldTypesL();
|
|
630 |
|
|
631 |
iAsyncOpenOp =
|
|
632 |
CVPbkAsyncObjectOperation<MVPbkContactStoreObserver>::NewL();
|
|
633 |
iAsyncContactOperation = CAsyncContactOperation::NewL(*this);
|
|
634 |
|
|
635 |
iStoreInfo = CContactStoreInfo::NewL(*this, iStoreDomain);
|
|
636 |
|
|
637 |
// Get contact store location drive for disk space check
|
|
638 |
const TPtrC ptr( iStoreURI->Uri().Component
|
|
639 |
( TVPbkContactStoreUriPtr::EContactStoreUriStoreDrive ) );
|
|
640 |
TInt drive( EDriveA ); // c is usually the default location
|
|
641 |
User::LeaveIfError( iStoreDomain.FsSession().CharToDrive
|
|
642 |
( ptr[0], drive) );
|
|
643 |
iDiskSpaceCheck = VPbkEngUtils::CVPbkDiskSpaceCheck::NewL
|
|
644 |
( iStoreDomain.FsSession(), drive );
|
|
645 |
|
|
646 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
647 |
("CContactStore::ConstructL end"));
|
|
648 |
}
|
|
649 |
|
|
650 |
// --------------------------------------------------------------------------
|
|
651 |
// CContactStore::FieldTypeMap
|
|
652 |
// --------------------------------------------------------------------------
|
|
653 |
//
|
|
654 |
const CFieldTypeMap& CContactStore::FieldTypeMap() const
|
|
655 |
{
|
|
656 |
return iStoreDomain.FieldTypeMap();
|
|
657 |
}
|
|
658 |
|
|
659 |
// --------------------------------------------------------------------------
|
|
660 |
// CContactStore::FieldFactory
|
|
661 |
// --------------------------------------------------------------------------
|
|
662 |
//
|
|
663 |
const CFieldFactory& CContactStore::FieldFactory() const
|
|
664 |
{
|
|
665 |
return *iFieldFactory;
|
|
666 |
}
|
|
667 |
|
|
668 |
// --------------------------------------------------------------------------
|
|
669 |
// CContactStore::MasterFieldTypeList
|
|
670 |
// --------------------------------------------------------------------------
|
|
671 |
//
|
|
672 |
const MVPbkFieldTypeList& CContactStore::MasterFieldTypeList() const
|
|
673 |
{
|
|
674 |
return iStoreDomain.MasterFieldTypeList();
|
|
675 |
}
|
|
676 |
|
|
677 |
// --------------------------------------------------------------------------
|
|
678 |
// CContactStore::CreateFieldLC
|
|
679 |
// --------------------------------------------------------------------------
|
|
680 |
//
|
|
681 |
CContactItemField* CContactStore::CreateFieldLC
|
|
682 |
(const MVPbkFieldType& aFieldType) const
|
|
683 |
{
|
|
684 |
return iFieldFactory->CreateFieldLC(aFieldType);
|
|
685 |
}
|
|
686 |
|
|
687 |
// --------------------------------------------------------------------------
|
|
688 |
// CContactStore::ReadContactL
|
|
689 |
// --------------------------------------------------------------------------
|
|
690 |
//
|
|
691 |
void CContactStore::ReadContactL
|
|
692 |
(TContactItemId aContactId, MVPbkContactObserver& aObserver)
|
|
693 |
{
|
|
694 |
iAsyncContactOperation->PrepareL
|
|
695 |
(MVPbkContactObserver::EContactRead, aContactId, aObserver);
|
|
696 |
iAsyncContactOperation->Execute();
|
|
697 |
}
|
|
698 |
|
|
699 |
// --------------------------------------------------------------------------
|
|
700 |
// CContactStore::LockContactL
|
|
701 |
// --------------------------------------------------------------------------
|
|
702 |
//
|
|
703 |
void CContactStore::LockContactL
|
|
704 |
(const CContact& aContact, MVPbkContactObserver& aObserver)
|
|
705 |
{
|
|
706 |
iAsyncContactOperation->PrepareL
|
|
707 |
(MVPbkContactObserver::EContactLock, aContact, aObserver);
|
|
708 |
iAsyncContactOperation->Execute();
|
|
709 |
}
|
|
710 |
|
|
711 |
// --------------------------------------------------------------------------
|
|
712 |
// CContactStore::ReadAndLockContactL
|
|
713 |
// --------------------------------------------------------------------------
|
|
714 |
//
|
|
715 |
void CContactStore::ReadAndLockContactL
|
|
716 |
(TContactItemId aContactId, MVPbkContactObserver& aObserver)
|
|
717 |
{
|
|
718 |
iAsyncContactOperation->PrepareL
|
|
719 |
(MVPbkContactObserver::EContactReadAndLock, aContactId, aObserver);
|
|
720 |
iAsyncContactOperation->Execute();
|
|
721 |
}
|
|
722 |
|
|
723 |
// --------------------------------------------------------------------------
|
|
724 |
// CContactStore::DeleteContactL
|
|
725 |
// --------------------------------------------------------------------------
|
|
726 |
//
|
|
727 |
void CContactStore::DeleteContactL
|
|
728 |
(TContactItemId aContactId, MVPbkContactObserver& aObserver)
|
|
729 |
{
|
|
730 |
iAsyncContactOperation->PrepareL
|
|
731 |
(MVPbkContactObserver::EContactDelete, aContactId, aObserver);
|
|
732 |
iAsyncContactOperation->Execute();
|
|
733 |
}
|
|
734 |
|
|
735 |
// --------------------------------------------------------------------------
|
|
736 |
// CContactStore::CommitContactL
|
|
737 |
// --------------------------------------------------------------------------
|
|
738 |
//
|
|
739 |
void CContactStore::CommitContactL(
|
|
740 |
const CContact& aContactItem,
|
|
741 |
MVPbkContactObserver& aObserver)
|
|
742 |
{
|
|
743 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
744 |
("CContactStore::CommitContactL(0x%x,0x%x)"),
|
|
745 |
&aContactItem, &aObserver);
|
|
746 |
|
|
747 |
iDiskSpaceCheck->DiskSpaceCheckL();
|
|
748 |
|
|
749 |
// verify sync field content
|
|
750 |
VPbkUtils::VerifySyncronizationFieldL(
|
|
751 |
iStoreDomain.FsSession(),
|
|
752 |
StoreProperties().SupportedFields(),
|
|
753 |
const_cast<CContact&>(aContactItem));
|
|
754 |
|
|
755 |
iAsyncContactOperation->PrepareL
|
|
756 |
(MVPbkContactObserver::EContactCommit, aContactItem, aObserver);
|
|
757 |
iAsyncContactOperation->Execute();
|
|
758 |
}
|
|
759 |
|
|
760 |
// --------------------------------------------------------------------------
|
|
761 |
// CContactStore::CreateLinkLC
|
|
762 |
// --------------------------------------------------------------------------
|
|
763 |
//
|
|
764 |
MVPbkContactLink* CContactStore::CreateLinkLC(TContactItemId aContactId) const
|
|
765 |
{
|
|
766 |
MVPbkContactLink* ret = NULL;
|
|
767 |
// if aContactId is KGoldenTemplateId then it is probably new contact
|
|
768 |
// which is not commited to contactdb, return null then
|
|
769 |
if ( aContactId != KGoldenTemplateId &&
|
|
770 |
aContactId != KNullContactId )
|
|
771 |
{
|
|
772 |
// Contact store constness casted away, no reason to be const
|
|
773 |
ret = CContactLink::NewLC(const_cast<CContactStore&>(*this), aContactId);
|
|
774 |
}
|
|
775 |
return ret;
|
|
776 |
}
|
|
777 |
|
|
778 |
// --------------------------------------------------------------------------
|
|
779 |
// CContactStore::ContactDestroyed
|
|
780 |
// --------------------------------------------------------------------------
|
|
781 |
//
|
|
782 |
void CContactStore::ContactDestroyed(CContactItem* aContactItem, TBool aCloseContact )
|
|
783 |
{
|
|
784 |
// Release any lock on contact.
|
|
785 |
if (aContactItem)
|
|
786 |
{
|
|
787 |
// Cancel async operation if any
|
|
788 |
iAsyncContactOperation->Cancel( aContactItem );
|
|
789 |
|
|
790 |
//iContactDb may be already null if store configuration changed by
|
|
791 |
//removing the current store from store configuartion
|
|
792 |
if ( aCloseContact && iContactDb)
|
|
793 |
{
|
|
794 |
// CloseContactL doesn't leave despite its name.
|
|
795 |
iContactDb->CloseContactL(aContactItem->Id());
|
|
796 |
}
|
|
797 |
}
|
|
798 |
}
|
|
799 |
|
|
800 |
// --------------------------------------------------------------------------
|
|
801 |
// CContactStore::MatchContactStore
|
|
802 |
// --------------------------------------------------------------------------
|
|
803 |
//
|
|
804 |
TBool CContactStore::MatchContactStore(const TDesC& aContactStoreUri) const
|
|
805 |
{
|
|
806 |
if (iStoreURI->Uri().Compare(
|
|
807 |
TVPbkContactStoreUriPtr(aContactStoreUri),
|
|
808 |
TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) == 0)
|
|
809 |
{
|
|
810 |
return ETrue;
|
|
811 |
}
|
|
812 |
return EFalse;
|
|
813 |
}
|
|
814 |
|
|
815 |
// --------------------------------------------------------------------------
|
|
816 |
// CContactStore::MatchContactStoreDomain
|
|
817 |
// --------------------------------------------------------------------------
|
|
818 |
//
|
|
819 |
TBool CContactStore::MatchContactStoreDomain(const TDesC& aContactStoreDomain) const
|
|
820 |
{
|
|
821 |
if (iStoreURI->Uri().Compare(
|
|
822 |
aContactStoreDomain,
|
|
823 |
TVPbkContactStoreUriPtr::EContactStoreUriStoreType) == 0)
|
|
824 |
{
|
|
825 |
return ETrue;
|
|
826 |
}
|
|
827 |
return EFalse;
|
|
828 |
}
|
|
829 |
|
|
830 |
// --------------------------------------------------------------------------
|
|
831 |
// CContactStore::CreateBookmarkLC
|
|
832 |
// --------------------------------------------------------------------------
|
|
833 |
//
|
|
834 |
MVPbkContactBookmark* CContactStore::CreateBookmarkLC(
|
|
835 |
TContactItemId aContactId) const
|
|
836 |
{
|
|
837 |
// Contact store constness casted away, no reason to be const
|
|
838 |
return CContactBookmark::NewLC( aContactId,
|
|
839 |
const_cast<CContactStore&>(*this) );
|
|
840 |
}
|
|
841 |
|
|
842 |
// --------------------------------------------------------------------------
|
|
843 |
// CContactStore::StoreProperties
|
|
844 |
// --------------------------------------------------------------------------
|
|
845 |
//
|
|
846 |
const MVPbkContactStoreProperties& CContactStore::StoreProperties() const
|
|
847 |
{
|
|
848 |
return *iProperties;
|
|
849 |
}
|
|
850 |
|
|
851 |
// --------------------------------------------------------------------------
|
|
852 |
// CContactStore::OpenL
|
|
853 |
// --------------------------------------------------------------------------
|
|
854 |
//
|
|
855 |
void CContactStore::OpenL(
|
|
856 |
MVPbkContactStoreObserver& aObserver)
|
|
857 |
{
|
|
858 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
859 |
("CContactStore::OpenL(0x%x)"), &aObserver);
|
|
860 |
|
|
861 |
AddObserverL(aObserver);
|
|
862 |
CVPbkAsyncObjectCallback<MVPbkContactStoreObserver>* openCallback =
|
|
863 |
VPbkEngUtils::CreateAsyncObjectCallbackLC(
|
|
864 |
*this,
|
|
865 |
&CContactStore::DoOpenL,
|
|
866 |
TBool(EFalse),
|
|
867 |
&CContactStore::OpenError,
|
|
868 |
aObserver);
|
|
869 |
iAsyncOpenOp->CallbackL(openCallback);
|
|
870 |
CleanupStack::Pop( openCallback );
|
|
871 |
}
|
|
872 |
|
|
873 |
// --------------------------------------------------------------------------
|
|
874 |
// CContactStore::ReplaceL
|
|
875 |
// --------------------------------------------------------------------------
|
|
876 |
//
|
|
877 |
void CContactStore::ReplaceL(MVPbkContactStoreObserver& aObserver)
|
|
878 |
{
|
|
879 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
880 |
("CContactStore::ReplaceL(0x%x)"), &aObserver);
|
|
881 |
|
|
882 |
AddObserverL(aObserver);
|
|
883 |
CVPbkAsyncObjectCallback<MVPbkContactStoreObserver>* openCallback =
|
|
884 |
VPbkEngUtils::CreateAsyncObjectCallbackLC(
|
|
885 |
*this,
|
|
886 |
&CContactStore::DoOpenL,
|
|
887 |
TBool(ETrue),
|
|
888 |
&CContactStore::OpenError,
|
|
889 |
aObserver);
|
|
890 |
iAsyncOpenOp->CallbackL(openCallback);
|
|
891 |
CleanupStack::Pop(openCallback);
|
|
892 |
}
|
|
893 |
|
|
894 |
// --------------------------------------------------------------------------
|
|
895 |
// CContactStore::Close
|
|
896 |
// --------------------------------------------------------------------------
|
|
897 |
//
|
|
898 |
void CContactStore::Close( MVPbkContactStoreObserver& aObserver)
|
|
899 |
{
|
|
900 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
901 |
("CContactStore::Close(0x%x)"), &aObserver);
|
|
902 |
|
|
903 |
// Cancel open callback, If not active then it does nothing.
|
|
904 |
iAsyncOpenOp->CancelCallback( &aObserver );
|
|
905 |
// Remove the observer from the observer list.
|
|
906 |
RemoveObserver(aObserver);
|
|
907 |
if (iObservers.Count() == 0)
|
|
908 |
{
|
|
909 |
iNamedViewContainer.ResetAndDestroy();
|
|
910 |
// Zero observers left, clean the resources.
|
|
911 |
iAsyncOpenOp->Purge();
|
|
912 |
delete iFieldFactory;
|
|
913 |
iFieldFactory = NULL;
|
|
914 |
delete iDbNotifier;
|
|
915 |
iDbNotifier = NULL;
|
|
916 |
delete iContactDb;
|
|
917 |
iContactDb = NULL;
|
|
918 |
// Set iGroupsFetched to false.
|
|
919 |
// Make sure iGroupIds is updated again after store is opened again.
|
|
920 |
iStoreInfo->ResetGroupsFetched();
|
|
921 |
}
|
|
922 |
}
|
|
923 |
|
|
924 |
// --------------------------------------------------------------------------
|
|
925 |
// CContactStore::CreateNewContactLC
|
|
926 |
// --------------------------------------------------------------------------
|
|
927 |
//
|
|
928 |
MVPbkStoreContact* CContactStore::CreateNewContactLC()
|
|
929 |
{
|
|
930 |
TRAPD( err, iDiskSpaceCheck->DiskSpaceCheckL() );
|
|
931 |
if ( err != KErrNone )
|
|
932 |
{
|
|
933 |
CCoeEnv::Static()->HandleError( err );
|
|
934 |
User::Leave(err);
|
|
935 |
}
|
|
936 |
CContactItem* newContact = CContactCard::NewLC();
|
|
937 |
CContact* result = CContact::NewL(*this, newContact, ETrue);
|
|
938 |
CleanupStack::Pop(newContact);
|
|
939 |
CleanupStack::PushL(result);
|
|
940 |
return result;
|
|
941 |
}
|
|
942 |
|
|
943 |
// --------------------------------------------------------------------------
|
|
944 |
// CContactStore::CreateNewContactGroupLC
|
|
945 |
// --------------------------------------------------------------------------
|
|
946 |
//
|
|
947 |
MVPbkContactGroup* CContactStore::CreateNewContactGroupLC()
|
|
948 |
{
|
|
949 |
// Check that store has been opened
|
|
950 |
__ASSERT_DEBUG( iContactDb,
|
|
951 |
ContactStorePanic( EPreCond_CreateNewContactGroupLC ) );
|
|
952 |
|
|
953 |
iDiskSpaceCheck->DiskSpaceCheckL();
|
|
954 |
CContactItem* newGroup = iContactDb->CreateContactGroupLC();
|
|
955 |
TContactItemId groupId = newGroup->Id();
|
|
956 |
CleanupStack::PopAndDestroy(); // newGroup
|
|
957 |
|
|
958 |
CContactItem* group = iContactDb->OpenContactLX(groupId);
|
|
959 |
CleanupStack::PushL(group);
|
|
960 |
CContact* result = CContact::NewL(*this, group);
|
|
961 |
CleanupStack::Pop(2); // group, lock
|
|
962 |
CleanupStack::PushL(result);
|
|
963 |
|
|
964 |
return result;
|
|
965 |
}
|
|
966 |
|
|
967 |
// --------------------------------------------------------------------------
|
|
968 |
// CContactStore::CreateViewLC
|
|
969 |
// --------------------------------------------------------------------------
|
|
970 |
//
|
|
971 |
MVPbkContactView* CContactStore::CreateViewLC(
|
|
972 |
const CVPbkContactViewDefinition& aViewDefinition,
|
|
973 |
MVPbkContactViewObserver& aObserver,
|
|
974 |
const MVPbkFieldTypeList& aSortOrder )
|
|
975 |
{
|
|
976 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
977 |
("CContactStore::CreateViewLC(0x%x)"), &aSortOrder);
|
|
978 |
|
|
979 |
CViewBase* result = NULL;
|
|
980 |
if (aViewDefinition.SortPolicy() == EVPbkUnsortedContactView)
|
|
981 |
{
|
|
982 |
// Contact model doesn't have a view that is not sorted.
|
|
983 |
User::Leave( KErrArgument );
|
|
984 |
}
|
|
985 |
else if (aViewDefinition.Type() == EVPbkContactsView)
|
|
986 |
{
|
|
987 |
if ( !aViewDefinition.FieldTypeFilter() && !aViewDefinition.ContactSelector() )
|
|
988 |
{
|
|
989 |
// View without filtering
|
|
990 |
result = CContactView::NewLC( aViewDefinition, aObserver,
|
|
991 |
*this, aSortOrder );
|
|
992 |
}
|
|
993 |
else
|
|
994 |
{
|
|
995 |
// A filtered view
|
|
996 |
result = CFilteredContactView::NewLC( aViewDefinition,
|
|
997 |
aObserver, *this, aSortOrder, iStoreDomain.FsSession() );
|
|
998 |
}
|
|
999 |
}
|
|
1000 |
else // aViewDefinition.Type() == EVPbkGroupsView
|
|
1001 |
{
|
|
1002 |
if ( !aViewDefinition.FieldTypeFilter() &&
|
|
1003 |
!aViewDefinition.FlagIsOn( EVPbkExcludeEmptyGroups ) )
|
|
1004 |
{
|
|
1005 |
// View without filtering
|
|
1006 |
result = CGroupView::NewLC( aViewDefinition, aObserver, *this,
|
|
1007 |
aSortOrder );
|
|
1008 |
}
|
|
1009 |
else
|
|
1010 |
{
|
|
1011 |
// A filtered view
|
|
1012 |
result = CFilteredGroupView::NewLC( aViewDefinition,
|
|
1013 |
aObserver, *this, aSortOrder, iStoreDomain.FsSession() );
|
|
1014 |
}
|
|
1015 |
}
|
|
1016 |
|
|
1017 |
return result;
|
|
1018 |
}
|
|
1019 |
|
|
1020 |
// --------------------------------------------------------------------------
|
|
1021 |
// CContactStore::ContactGroupsLC
|
|
1022 |
// --------------------------------------------------------------------------
|
|
1023 |
//
|
|
1024 |
MVPbkContactLinkArray* CContactStore::ContactGroupsLC() const
|
|
1025 |
{
|
|
1026 |
// Check that store has been opened
|
|
1027 |
__ASSERT_DEBUG( iContactDb,
|
|
1028 |
ContactStorePanic( EPreCond_ContactGroupsLC ) );
|
|
1029 |
|
|
1030 |
CVPbkContactLinkArray* result = CVPbkContactLinkArray::NewLC();
|
|
1031 |
|
|
1032 |
CContactIdArray* groups = iContactDb->GetGroupIdListL();
|
|
1033 |
if (groups)
|
|
1034 |
{
|
|
1035 |
CleanupStack::PushL(groups);
|
|
1036 |
const TInt count = groups->Count();
|
|
1037 |
for (TInt i = 0; i < count; ++i)
|
|
1038 |
{
|
|
1039 |
MVPbkContactLink* link = CreateLinkLC((*groups)[i]);
|
|
1040 |
result->AppendL(link);
|
|
1041 |
CleanupStack::Pop(); // link
|
|
1042 |
}
|
|
1043 |
CleanupStack::PopAndDestroy(); // groups
|
|
1044 |
}
|
|
1045 |
|
|
1046 |
return result;
|
|
1047 |
}
|
|
1048 |
|
|
1049 |
// --------------------------------------------------------------------------
|
|
1050 |
// CContactStore::StoreInfo
|
|
1051 |
// --------------------------------------------------------------------------
|
|
1052 |
//
|
|
1053 |
const MVPbkContactStoreInfo& CContactStore::StoreInfo() const
|
|
1054 |
{
|
|
1055 |
return *iStoreInfo;
|
|
1056 |
}
|
|
1057 |
|
|
1058 |
// --------------------------------------------------------------------------
|
|
1059 |
// CContactStore::CreateLinkFromInternalsLC
|
|
1060 |
// --------------------------------------------------------------------------
|
|
1061 |
//
|
|
1062 |
MVPbkContactLink* CContactStore::CreateLinkFromInternalsLC(
|
|
1063 |
RReadStream& aStream) const
|
|
1064 |
{
|
|
1065 |
// Contact store constness casted away, no reason to be const
|
|
1066 |
return CContactLink::NewLC(const_cast<CContactStore&>(*this), aStream);
|
|
1067 |
}
|
|
1068 |
|
|
1069 |
|
|
1070 |
// --------------------------------------------------------------------------
|
|
1071 |
// CContactStore::ContactStoreExtension
|
|
1072 |
// --------------------------------------------------------------------------
|
|
1073 |
//
|
|
1074 |
TAny* CContactStore::ContactStoreExtension( TUid aExtensionUid )
|
|
1075 |
{
|
|
1076 |
if( aExtensionUid == KMVPbkContactStoreExtension2Uid )
|
|
1077 |
{
|
|
1078 |
return static_cast<MVPbkContactStore2*>( this );
|
|
1079 |
}
|
|
1080 |
|
|
1081 |
return NULL;
|
|
1082 |
}
|
|
1083 |
|
|
1084 |
|
|
1085 |
// --------------------------------------------------------------------------
|
|
1086 |
// CContactStore::OwnContactLinkL
|
|
1087 |
// --------------------------------------------------------------------------
|
|
1088 |
//
|
|
1089 |
MVPbkContactOperationBase* CContactStore::OwnContactLinkL(
|
|
1090 |
MVPbkSingleContactLinkOperationObserver& aObserver) const
|
|
1091 |
{
|
|
1092 |
__ASSERT_DEBUG( iContactDb,
|
|
1093 |
ContactStorePanic( EPreCond_OwnContactLinkL ) );
|
|
1094 |
|
|
1095 |
MVPbkContactLink* ownContactLink = NULL;
|
|
1096 |
TContactItemId ownCardId = iContactDb->OwnCardId();
|
|
1097 |
|
|
1098 |
if ( ownCardId != KNullContactId )
|
|
1099 |
{
|
|
1100 |
ownContactLink = CContactLink::NewLC(
|
|
1101 |
const_cast<CContactStore&>(*this),
|
|
1102 |
ownCardId );
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
// if ownCard is KNullContactId, than return ownContactLink with NULL, async
|
|
1106 |
MVPbkContactOperationBase* result = new (ELeave) COwnContactLinkOperation(
|
|
1107 |
ownContactLink,
|
|
1108 |
aObserver );
|
|
1109 |
|
|
1110 |
if ( ownCardId != KNullContactId )
|
|
1111 |
{
|
|
1112 |
CleanupStack::Pop(); //contact link
|
|
1113 |
}
|
|
1114 |
|
|
1115 |
return result;
|
|
1116 |
}
|
|
1117 |
|
|
1118 |
// --------------------------------------------------------------------------
|
|
1119 |
// CContactStore::SetOwnContactL
|
|
1120 |
// --------------------------------------------------------------------------
|
|
1121 |
//
|
|
1122 |
void CContactStore::SetAsOwnL(
|
|
1123 |
const CContact& aContactItem,
|
|
1124 |
MVPbkContactObserver& aObserver )
|
|
1125 |
{
|
|
1126 |
iAsyncContactOperation->PrepareL
|
|
1127 |
(MVPbkContactObserver::EContactSetOwn, aContactItem, aObserver);
|
|
1128 |
iAsyncContactOperation->Execute();
|
|
1129 |
}
|
|
1130 |
|
|
1131 |
// --------------------------------------------------------------------------
|
|
1132 |
// CContactStore::StoreOpenedL
|
|
1133 |
// --------------------------------------------------------------------------
|
|
1134 |
//
|
|
1135 |
void CContactStore::StoreOpenedL( CContactDatabase* aDB )
|
|
1136 |
{
|
|
1137 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
1138 |
("VPbkCntModel: CContactStore::StoreOpenedL"));
|
|
1139 |
|
|
1140 |
CleanupStack::PushL( aDB );
|
|
1141 |
|
|
1142 |
delete iOpenOperation;
|
|
1143 |
iOpenOperation = NULL;
|
|
1144 |
|
|
1145 |
if( !iGoldenTemplateUpdated )
|
|
1146 |
{
|
|
1147 |
iSysTemplate = aDB->OpenContactL(aDB->TemplateId());
|
|
1148 |
// set contact model template label texts according to localisation
|
|
1149 |
// must be done in order for contact field labels to be correct after language change
|
|
1150 |
if( UpdateSystemTemplateFieldsL( *iSysTemplate, *iFieldsInfo ) )
|
|
1151 |
{
|
|
1152 |
aDB->CommitContactL( *iSysTemplate );
|
|
1153 |
iGoldenTemplateUpdated = ETrue;
|
|
1154 |
}
|
|
1155 |
CloseSystemTemplate( aDB );
|
|
1156 |
|
|
1157 |
// reopen the contact database if the golden template has been changed
|
|
1158 |
if( iGoldenTemplateUpdated )
|
|
1159 |
{
|
|
1160 |
// template updated -> reopen store
|
|
1161 |
CleanupStack::PopAndDestroy( aDB );
|
|
1162 |
iOpenOperation = new(ELeave) CContactStoreOpenOperation( *this, EFalse );
|
|
1163 |
return;
|
|
1164 |
}
|
|
1165 |
}
|
|
1166 |
|
|
1167 |
// read the system template and create the field factory accordingly
|
|
1168 |
iSysTemplate = aDB->ReadContactL(aDB->TemplateId());
|
|
1169 |
iFieldFactory = CFieldFactory::NewL(iStoreDomain.FieldTypeMap(),
|
|
1170 |
iSysTemplate, MasterFieldTypeList(), iStoreDomain.FsSession() );
|
|
1171 |
iSysTemplate = NULL;
|
|
1172 |
|
|
1173 |
// set supported fields for this store
|
|
1174 |
iProperties->SetSupportedFields(*iFieldFactory);
|
|
1175 |
SetStaticPropertiesL();
|
|
1176 |
|
|
1177 |
iDbNotifier = CContactChangeNotifier::NewL(*aDB, this);
|
|
1178 |
CleanupStack::Pop(aDB);
|
|
1179 |
iContactDb = aDB;
|
|
1180 |
|
|
1181 |
// Activate remote views so that contacts server will build
|
|
1182 |
// the view as soon as possible when system boots.
|
|
1183 |
// This is trapped because it's not wanted to block
|
|
1184 |
// the store opening if the view building failed.
|
|
1185 |
TRAP_IGNORE( DoActivateRemoteViewsL() );
|
|
1186 |
|
|
1187 |
// Send event to all observers. This means that multiple pending open requests
|
|
1188 |
// are all signalled as complete here and we can cancel all other open operations.
|
|
1189 |
SendEventL(iObservers, &MVPbkContactStoreObserver::StoreReady, *this);
|
|
1190 |
iAsyncOpenOp->Purge();
|
|
1191 |
}
|
|
1192 |
|
|
1193 |
// --------------------------------------------------------------------------
|
|
1194 |
// CContactStore::StoreOpenFailed
|
|
1195 |
// --------------------------------------------------------------------------
|
|
1196 |
//
|
|
1197 |
void CContactStore::StoreOpenFailed( TInt aError )
|
|
1198 |
{
|
|
1199 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
1200 |
("VPbkCntModel: CContactStore::StoreOpenFailed(%d)"), aError);
|
|
1201 |
|
|
1202 |
delete iOpenOperation;
|
|
1203 |
iOpenOperation = NULL;
|
|
1204 |
|
|
1205 |
SendErrorEvent(iObservers, &MVPbkContactStoreObserver::StoreUnavailable,
|
|
1206 |
*this, aError );
|
|
1207 |
}
|
|
1208 |
|
|
1209 |
// --------------------------------------------------------------------------
|
|
1210 |
// CContactStore::RequestFreeDiskSpaceLC
|
|
1211 |
// --------------------------------------------------------------------------
|
|
1212 |
//
|
|
1213 |
TBool CContactStore::RequestFreeDiskSpaceLC( TInt aSpace )
|
|
1214 |
{
|
|
1215 |
RSharedDataClient* sharedDataClient = iStoreDomain.SharedDataClient();
|
|
1216 |
if( sharedDataClient )
|
|
1217 |
{
|
|
1218 |
// Try to release space for contact db opening
|
|
1219 |
sharedDataClient->RequestFreeDiskSpaceLC( aSpace );
|
|
1220 |
return ETrue;
|
|
1221 |
}
|
|
1222 |
return EFalse;
|
|
1223 |
}
|
|
1224 |
|
|
1225 |
// --------------------------------------------------------------------------
|
|
1226 |
// CContactStore::CreateContactRetrieverL
|
|
1227 |
// --------------------------------------------------------------------------
|
|
1228 |
//
|
|
1229 |
MVPbkContactOperation* CContactStore::CreateContactRetrieverL(
|
|
1230 |
const MVPbkContactLink& aLink,
|
|
1231 |
MVPbkSingleContactOperationObserver& aObserver)
|
|
1232 |
{
|
|
1233 |
// test if aLink is in fact a instance of this class
|
|
1234 |
CContactRetriever* operation = NULL;
|
|
1235 |
if (CContactLink::Matches(StoreProperties().Uri(), aLink))
|
|
1236 |
{
|
|
1237 |
if ( IsOpened() )
|
|
1238 |
{
|
|
1239 |
operation = CContactRetriever::NewLC(aLink, *this, aObserver);
|
|
1240 |
CleanupStack::Pop();
|
|
1241 |
}
|
|
1242 |
else
|
|
1243 |
{
|
|
1244 |
VPBK_DEBUG_PRINT( VPBK_DEBUG_STRING(
|
|
1245 |
"VPbkCntModel: ContactStore not opened" ) );
|
|
1246 |
User::Leave( KErrArgument );
|
|
1247 |
}
|
|
1248 |
}
|
|
1249 |
|
|
1250 |
return operation;
|
|
1251 |
}
|
|
1252 |
|
|
1253 |
// --------------------------------------------------------------------------
|
|
1254 |
// CContactStore::CreateDeleteContactsOperationL
|
|
1255 |
// --------------------------------------------------------------------------
|
|
1256 |
//
|
|
1257 |
MVPbkContactOperation* CContactStore::CreateDeleteContactsOperationL(
|
|
1258 |
const MVPbkContactLinkArray& aContactLinks,
|
|
1259 |
MVPbkBatchOperationObserver& aObserver)
|
|
1260 |
{
|
|
1261 |
CVPbkContactLinkArray* links = CVPbkContactLinkArray::NewLC();
|
|
1262 |
|
|
1263 |
const TInt linkCount = aContactLinks.Count();
|
|
1264 |
for (TInt i = 0; i < linkCount; ++i)
|
|
1265 |
{
|
|
1266 |
const MVPbkContactLink& link = aContactLinks.At(i);
|
|
1267 |
if (CContactLink::Matches(StoreProperties().Uri(), link))
|
|
1268 |
{
|
|
1269 |
MVPbkContactLink* newLink = link.CloneLC();
|
|
1270 |
links->AppendL(newLink);
|
|
1271 |
CleanupStack::Pop(); // newLink
|
|
1272 |
}
|
|
1273 |
}
|
|
1274 |
|
|
1275 |
MVPbkContactOperation* operation = NULL;
|
|
1276 |
if (links->Count() > 0)
|
|
1277 |
{
|
|
1278 |
__ASSERT_DEBUG( IsOpened(),
|
|
1279 |
VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
|
|
1280 |
if ( IsOpened() )
|
|
1281 |
{
|
|
1282 |
operation = CDeleteContactsOperation::NewL(*this, *links, aObserver,
|
|
1283 |
iStoreDomain.SharedDataClient(),
|
|
1284 |
*iDiskSpaceCheck );
|
|
1285 |
}
|
|
1286 |
}
|
|
1287 |
CleanupStack::PopAndDestroy(); // links
|
|
1288 |
|
|
1289 |
return operation;
|
|
1290 |
}
|
|
1291 |
|
|
1292 |
// --------------------------------------------------------------------------
|
|
1293 |
// CContactStore::CreateCommitContactsOperationL
|
|
1294 |
// --------------------------------------------------------------------------
|
|
1295 |
//
|
|
1296 |
MVPbkContactOperation* CContactStore::CreateCommitContactsOperationL(
|
|
1297 |
const TArray<MVPbkStoreContact*>& aContacts,
|
|
1298 |
MVPbkBatchOperationObserver& aObserver)
|
|
1299 |
{
|
|
1300 |
CArrayPtrFlat<CContact>* contacts =
|
|
1301 |
new(ELeave) CArrayPtrFlat<CContact>(KDefaultArrayGranularity);
|
|
1302 |
CleanupStack::PushL(contacts);
|
|
1303 |
|
|
1304 |
const TInt contactCount = aContacts.Count();
|
|
1305 |
for (TInt i = 0; i < contactCount; ++i)
|
|
1306 |
{
|
|
1307 |
MVPbkStoreContact* contact = aContacts[i];
|
|
1308 |
if (&contact->ParentStore() == this)
|
|
1309 |
{
|
|
1310 |
contacts->AppendL(static_cast<CContact*>(contact));
|
|
1311 |
|
|
1312 |
// Validate syncronization field content
|
|
1313 |
VPbkUtils::VerifySyncronizationFieldL(
|
|
1314 |
iStoreDomain.FsSession(),
|
|
1315 |
StoreProperties().SupportedFields(),
|
|
1316 |
*(aContacts[i]));
|
|
1317 |
}
|
|
1318 |
}
|
|
1319 |
|
|
1320 |
MVPbkContactOperation* operation = NULL;
|
|
1321 |
if (contacts->Count() > 0)
|
|
1322 |
{
|
|
1323 |
__ASSERT_DEBUG( IsOpened(),
|
|
1324 |
VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
|
|
1325 |
if ( IsOpened() )
|
|
1326 |
{
|
|
1327 |
operation = CCommitContactsOperation::NewL(*this, contacts->Array(), aObserver);
|
|
1328 |
}
|
|
1329 |
}
|
|
1330 |
CleanupStack::PopAndDestroy(); // contacts
|
|
1331 |
|
|
1332 |
return operation;
|
|
1333 |
}
|
|
1334 |
|
|
1335 |
// --------------------------------------------------------------------------
|
|
1336 |
// CContactStore::CreateMatchPhoneNumberOperationL
|
|
1337 |
// --------------------------------------------------------------------------
|
|
1338 |
//
|
|
1339 |
MVPbkContactOperation* CContactStore::CreateMatchPhoneNumberOperationL(
|
|
1340 |
const TDesC& aPhoneNumber,
|
|
1341 |
TInt aMaxMatchDigits,
|
|
1342 |
MVPbkContactFindObserver& aObserver)
|
|
1343 |
{
|
|
1344 |
MVPbkContactOperation* operation = NULL;
|
|
1345 |
if ( IsOpened() )
|
|
1346 |
{
|
|
1347 |
operation = CMatchPhoneNumberOperation::NewL(
|
|
1348 |
*this, aPhoneNumber, aMaxMatchDigits, aObserver);
|
|
1349 |
}
|
|
1350 |
return operation;
|
|
1351 |
}
|
|
1352 |
|
|
1353 |
// --------------------------------------------------------------------------
|
|
1354 |
// CContactStore::CreateFindOperationL
|
|
1355 |
// --------------------------------------------------------------------------
|
|
1356 |
//
|
|
1357 |
MVPbkContactOperation* CContactStore::CreateFindOperationL(
|
|
1358 |
const TDesC& aSearchString,
|
|
1359 |
const MVPbkFieldTypeList& aFieldTypes,
|
|
1360 |
MVPbkContactFindObserver& aObserver)
|
|
1361 |
{
|
|
1362 |
MVPbkContactOperation* operation = NULL;
|
|
1363 |
if ( IsOpened() )
|
|
1364 |
{
|
|
1365 |
operation = CFindOperation::NewL(
|
|
1366 |
*this, aSearchString, aFieldTypes, aObserver);
|
|
1367 |
}
|
|
1368 |
return operation;
|
|
1369 |
}
|
|
1370 |
|
|
1371 |
// --------------------------------------------------------------------------
|
|
1372 |
// CContactStore::CreateFindOperationL
|
|
1373 |
// --------------------------------------------------------------------------
|
|
1374 |
//
|
|
1375 |
MVPbkContactOperation* CContactStore::CreateFindOperationL(
|
|
1376 |
const MDesC16Array& aSearchStrings,
|
|
1377 |
const MVPbkFieldTypeList& aFieldTypes,
|
|
1378 |
MVPbkContactFindFromStoresObserver& aObserver,
|
|
1379 |
const TCallBack& aWordParserCallBack )
|
|
1380 |
{
|
|
1381 |
MVPbkContactOperation* operation = NULL;
|
|
1382 |
if ( IsOpened() )
|
|
1383 |
{
|
|
1384 |
operation = CFindInTextDefOperation::NewL( *this, aSearchStrings,
|
|
1385 |
aFieldTypes, aObserver, aWordParserCallBack );
|
|
1386 |
}
|
|
1387 |
return operation;
|
|
1388 |
}
|
|
1389 |
|
|
1390 |
// --------------------------------------------------------------------------
|
|
1391 |
// CContactStore::CreateCompressStoresOperationL
|
|
1392 |
// --------------------------------------------------------------------------
|
|
1393 |
//
|
|
1394 |
MVPbkContactOperation* CContactStore::CreateCompressStoresOperationL(
|
|
1395 |
MVPbkBatchOperationObserver& /*aObserver*/)
|
|
1396 |
{
|
|
1397 |
// Contacts model handles compress by itself nowadays
|
|
1398 |
return NULL;
|
|
1399 |
}
|
|
1400 |
|
|
1401 |
// --------------------------------------------------------------------------
|
|
1402 |
// CContactStore::AddObserverL
|
|
1403 |
// --------------------------------------------------------------------------
|
|
1404 |
//
|
|
1405 |
void CContactStore::AddObserverL(MVPbkContactStoreObserver& aObserver)
|
|
1406 |
{
|
|
1407 |
// adds aObserver to list of observers if it isnt there already, thus
|
|
1408 |
// avoids clients registering multiple times
|
|
1409 |
if (iObservers.Find(&aObserver) == KErrNotFound)
|
|
1410 |
{
|
|
1411 |
iObservers.AppendL( &aObserver );
|
|
1412 |
}
|
|
1413 |
}
|
|
1414 |
|
|
1415 |
// --------------------------------------------------------------------------
|
|
1416 |
// CContactStore::RemoveObserver
|
|
1417 |
// --------------------------------------------------------------------------
|
|
1418 |
//
|
|
1419 |
void CContactStore::RemoveObserver(MVPbkContactStoreObserver& aObserver)
|
|
1420 |
{
|
|
1421 |
const TInt pos = iObservers.Find(&aObserver);
|
|
1422 |
if (pos != KErrNotFound)
|
|
1423 |
{
|
|
1424 |
iObservers.Remove(pos);
|
|
1425 |
}
|
|
1426 |
}
|
|
1427 |
|
|
1428 |
// --------------------------------------------------------------------------
|
|
1429 |
// CContactStore::IsOpened
|
|
1430 |
// --------------------------------------------------------------------------
|
|
1431 |
//
|
|
1432 |
TBool CContactStore::IsOpened() const
|
|
1433 |
{
|
|
1434 |
if ( iContactDb )
|
|
1435 |
{
|
|
1436 |
return ETrue;
|
|
1437 |
}
|
|
1438 |
else
|
|
1439 |
{
|
|
1440 |
return EFalse;
|
|
1441 |
}
|
|
1442 |
}
|
|
1443 |
|
|
1444 |
// --------------------------------------------------------------------------
|
|
1445 |
// CContactStore::HandleDatabaseEventL
|
|
1446 |
// --------------------------------------------------------------------------
|
|
1447 |
//
|
|
1448 |
void CContactStore::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
|
|
1449 |
{
|
|
1450 |
// Note: prints Symbian event and contact id
|
|
1451 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
1452 |
("VPbkCntModel:CContactStore(0x%x)::HandleDatabaseEventL %d, cntId=%d"),
|
|
1453 |
this, aEvent.iType, aEvent.iContactId );
|
|
1454 |
|
|
1455 |
TVPbkContactStoreEvent mappedEvent = MapDbEventToStoreEvent(aEvent);
|
|
1456 |
|
|
1457 |
if (aEvent.iContactId != KNullContactId)
|
|
1458 |
{
|
|
1459 |
mappedEvent.iContactLink = CreateLinkLC(aEvent.iContactId);
|
|
1460 |
}
|
|
1461 |
|
|
1462 |
if (mappedEvent.iEventType != TVPbkContactStoreEvent::ENullEvent)
|
|
1463 |
{
|
|
1464 |
SendEventL(iObservers, &MVPbkContactStoreObserver::HandleStoreEventL,
|
|
1465 |
*this, mappedEvent);
|
|
1466 |
}
|
|
1467 |
|
|
1468 |
// Backup handling. Send unavailable event when backup/restore begins
|
|
1469 |
// and ready event when it completes.
|
|
1470 |
switch( mappedEvent.iEventType )
|
|
1471 |
{
|
|
1472 |
case TVPbkContactStoreEvent::EStoreRestoreBeginning: // FALLTHROUGH
|
|
1473 |
case TVPbkContactStoreEvent::EStoreBackupBeginning:
|
|
1474 |
{
|
|
1475 |
SendErrorEvent( iObservers,
|
|
1476 |
&MVPbkContactStoreObserver::StoreUnavailable, *this,
|
|
1477 |
KErrAccessDenied );
|
|
1478 |
break;
|
|
1479 |
}
|
|
1480 |
case TVPbkContactStoreEvent::EStoreBackupRestoreCompleted:
|
|
1481 |
{
|
|
1482 |
SendEventL( iObservers, &MVPbkContactStoreObserver::StoreReady,
|
|
1483 |
*this );
|
|
1484 |
break;
|
|
1485 |
}
|
|
1486 |
default:
|
|
1487 |
{
|
|
1488 |
// Do nothing
|
|
1489 |
break;
|
|
1490 |
}
|
|
1491 |
}
|
|
1492 |
|
|
1493 |
if ( mappedEvent.iContactLink )
|
|
1494 |
{
|
|
1495 |
CleanupStack::PopAndDestroy(); // mappedEvent.iContactLink;
|
|
1496 |
}
|
|
1497 |
}
|
|
1498 |
|
|
1499 |
// --------------------------------------------------------------------------
|
|
1500 |
// CContactStore::DoOpenL
|
|
1501 |
// --------------------------------------------------------------------------
|
|
1502 |
//
|
|
1503 |
void CContactStore::DoOpenL(MVPbkContactStoreObserver& aObserver, TBool aReplace)
|
|
1504 |
{
|
|
1505 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
1506 |
("CContactStore::DoOpenL(0x%x)"), &aObserver);
|
|
1507 |
|
|
1508 |
if (!iContactDb)
|
|
1509 |
{
|
|
1510 |
// start opening store if it's not already pending
|
|
1511 |
if( !iOpenOperation )
|
|
1512 |
{
|
|
1513 |
iOpenOperation = new(ELeave) CContactStoreOpenOperation( *this, EFalse );
|
|
1514 |
}
|
|
1515 |
}
|
|
1516 |
else
|
|
1517 |
{
|
|
1518 |
// In case the contact database is already open, we come here
|
|
1519 |
SendEventL(&aObserver, &MVPbkContactStoreObserver::StoreReady, *this);
|
|
1520 |
}
|
|
1521 |
}
|
|
1522 |
|
|
1523 |
// --------------------------------------------------------------------------
|
|
1524 |
// CContactStore::OpenError
|
|
1525 |
// --------------------------------------------------------------------------
|
|
1526 |
//
|
|
1527 |
void CContactStore::OpenError(MVPbkContactStoreObserver& aObserver,
|
|
1528 |
TInt aError)
|
|
1529 |
{
|
|
1530 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
1531 |
("VPbkCntModel: CContactStore::OpenError(%d,0x%x)"), aError, &aObserver);
|
|
1532 |
|
|
1533 |
SendErrorEvent(iObservers, &MVPbkContactStoreObserver::StoreUnavailable,
|
|
1534 |
*this, aError);
|
|
1535 |
}
|
|
1536 |
|
|
1537 |
// --------------------------------------------------------------------------
|
|
1538 |
// CContactStore::SetStaticPropertiesL
|
|
1539 |
// --------------------------------------------------------------------------
|
|
1540 |
//
|
|
1541 |
inline void CContactStore::SetStaticPropertiesL()
|
|
1542 |
{
|
|
1543 |
iProperties->SetBooleanProperty
|
|
1544 |
(CVPbkContactStoreProperties::EPropertyFieldLabelSupported, ETrue);
|
|
1545 |
iProperties->SetBooleanProperty
|
|
1546 |
(CVPbkContactStoreProperties::EPropertyDefaultsSupported, ETrue);
|
|
1547 |
iProperties->SetBooleanProperty
|
|
1548 |
(CVPbkContactStoreProperties::EPropertyVoiceTagsSupported,
|
|
1549 |
VoiceTagSupported() );
|
|
1550 |
iProperties->SetBooleanProperty
|
|
1551 |
(CVPbkContactStoreProperties::EPropertySpeedDialsSupported, ETrue);
|
|
1552 |
iProperties->SetBooleanProperty
|
|
1553 |
(CVPbkContactStoreProperties::EPropertyContactGroupsSupported, ETrue);
|
|
1554 |
iProperties->SetBooleanProperty
|
|
1555 |
(CVPbkContactStoreProperties::EPropertyOwnContactSupported, ETrue);
|
|
1556 |
// Contacts Model store is never remote store but always in device memory
|
|
1557 |
// or memory card.
|
|
1558 |
iProperties->SetBooleanProperty(
|
|
1559 |
CVPbkContactStoreProperties::EPropertyLocal, ETrue );
|
|
1560 |
// The store is always persistent because contacts are saved in data base.
|
|
1561 |
iProperties->SetBooleanProperty(
|
|
1562 |
CVPbkContactStoreProperties::EPropertyPersistent, ETrue );
|
|
1563 |
|
|
1564 |
// For setting removable property we need the drive letter from the URI
|
|
1565 |
TDriveUnit driveUnit( iStoreURI->Uri().Component(
|
|
1566 |
TVPbkContactStoreUriPtr::EContactStoreUriStoreDrive ) );
|
|
1567 |
// Then the removable information can be received from TDriveInfo
|
|
1568 |
TVolumeInfo volInfo;
|
|
1569 |
User::LeaveIfError( iStoreDomain.FsSession().Volume(
|
|
1570 |
volInfo, driveUnit ) );
|
|
1571 |
if ( volInfo.iDrive.iDriveAtt & KDriveAttRemovable )
|
|
1572 |
{
|
|
1573 |
iProperties->SetBooleanProperty(
|
|
1574 |
CVPbkContactStoreProperties::EPropertyRemovable, ETrue );
|
|
1575 |
}
|
|
1576 |
}
|
|
1577 |
|
|
1578 |
// --------------------------------------------------------------------------
|
|
1579 |
// CContactStore::DoAddFieldTypesL
|
|
1580 |
// --------------------------------------------------------------------------
|
|
1581 |
//
|
|
1582 |
void CContactStore::DoAddFieldTypesL()
|
|
1583 |
{
|
|
1584 |
CVPbkLocalVariationManager* localVariation =
|
|
1585 |
CVPbkLocalVariationManager::NewL();
|
|
1586 |
CleanupStack::PushL(localVariation);
|
|
1587 |
|
|
1588 |
// open the golden template extension resource file
|
|
1589 |
VPbkEngUtils::RLocalizedResourceFile resFile;
|
|
1590 |
resFile.OpenLC( iStoreDomain.FsSession(),
|
|
1591 |
KVPbkRomFileDrive, KDC_RESOURCE_FILES_DIR, KCntExtResFile );
|
|
1592 |
|
|
1593 |
// Nick name field
|
|
1594 |
if ( localVariation->LocallyVariatedFeatureEnabled(
|
|
1595 |
EVPbkLVAddNickNameField ) )
|
|
1596 |
{
|
|
1597 |
TResourceReader reader;
|
|
1598 |
reader.SetBuffer(
|
|
1599 |
resFile.AllocReadLC( R_CNTUI_ADD_NICK_NAME_FIELD_DEFNS) );
|
|
1600 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1601 |
// R_CNTUI_ADD_NICK_NAME_FIELD_DEFNS buffer
|
|
1602 |
CleanupStack::PopAndDestroy();
|
|
1603 |
}
|
|
1604 |
|
|
1605 |
// Video telephony fields
|
|
1606 |
if ( localVariation->LocallyVariatedFeatureEnabled(
|
|
1607 |
EVPbkLVAddVideoTelephonyFields) )
|
|
1608 |
{
|
|
1609 |
TResourceReader reader;
|
|
1610 |
reader.SetBuffer(
|
|
1611 |
resFile.AllocReadLC( R_CNTUI_ADD_VIDEO_TELEPHONY_FIELD_DEFNS) );
|
|
1612 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1613 |
// R_CNTUI_ADD_VIDEO_TELEPHONY_FIELD_DEFNS buffer
|
|
1614 |
CleanupStack::PopAndDestroy();
|
|
1615 |
}
|
|
1616 |
|
|
1617 |
// VOIP fields
|
|
1618 |
if ( localVariation->LocallyVariatedFeatureEnabled( EVPbkLVVOIP ) )
|
|
1619 |
{
|
|
1620 |
TResourceReader reader;
|
|
1621 |
reader.SetBuffer( resFile.AllocReadLC( R_CNTUI_ADD_VOIP_FIELD_DEFNS) );
|
|
1622 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1623 |
CleanupStack::PopAndDestroy(); // R_CNTUI_ADD_VOIP_FIELD_DEFNS buffer
|
|
1624 |
}
|
|
1625 |
|
|
1626 |
// PTT/POC field
|
|
1627 |
if ( localVariation->LocallyVariatedFeatureEnabled( EVPbkLVPOC ) )
|
|
1628 |
{
|
|
1629 |
TResourceReader reader;
|
|
1630 |
reader.SetBuffer( resFile.AllocReadLC( R_CNTUI_ADD_POC_FIELD_DEF ) );
|
|
1631 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1632 |
CleanupStack::PopAndDestroy(); // R_CNTUI_ADD_POC_FIELD_DEF buffer
|
|
1633 |
}
|
|
1634 |
|
|
1635 |
// Share View field
|
|
1636 |
if ( localVariation->LocallyVariatedFeatureEnabled( EVPbkLVShareView ) )
|
|
1637 |
{
|
|
1638 |
TResourceReader reader;
|
|
1639 |
reader.SetBuffer(
|
|
1640 |
resFile.AllocReadLC( R_CNTUI_ADD_SHARE_VIEW_FIELD_DEF ) );
|
|
1641 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1642 |
// R_CNTUI_ADD_SHARE_VIEW_FIELD_DEF buffer
|
|
1643 |
CleanupStack::PopAndDestroy();
|
|
1644 |
}
|
|
1645 |
|
|
1646 |
|
|
1647 |
// OLD VOIP fields for compatibility
|
|
1648 |
if ( localVariation->LocallyVariatedFeatureEnabled( EVPbkLVVOIP ) )
|
|
1649 |
{
|
|
1650 |
TResourceReader reader;
|
|
1651 |
reader.SetBuffer( resFile.AllocReadLC(
|
|
1652 |
R_CNTUI_ADD_OLD_VOIP_FIELD_DEFNS ) );
|
|
1653 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1654 |
// R_CNTUI_ADD_OLD_VOIP_FIELD_DEFNS buffer
|
|
1655 |
CleanupStack::PopAndDestroy();
|
|
1656 |
}
|
|
1657 |
|
|
1658 |
|
|
1659 |
// OLD PTT/POC field for compatibility
|
|
1660 |
if ( localVariation->LocallyVariatedFeatureEnabled( EVPbkLVPOC ) )
|
|
1661 |
{
|
|
1662 |
TResourceReader reader;
|
|
1663 |
reader.SetBuffer(
|
|
1664 |
resFile.AllocReadLC( R_CNTUI_ADD_OLD_POC_FIELD_DEF ) );
|
|
1665 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1666 |
CleanupStack::PopAndDestroy(); // R_CNTUI_ADD_OLD_POC_FIELD_DEF buffer
|
|
1667 |
}
|
|
1668 |
|
|
1669 |
|
|
1670 |
// OLD Share View field for compatibility
|
|
1671 |
if ( localVariation->LocallyVariatedFeatureEnabled( EVPbkLVShareView ) )
|
|
1672 |
{
|
|
1673 |
TResourceReader reader;
|
|
1674 |
reader.SetBuffer(
|
|
1675 |
resFile.AllocReadLC( R_CNTUI_ADD_OLD_SHARE_VIEW_FIELD_DEF ) );
|
|
1676 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1677 |
// R_CNTUI_ADD_OLD_SHARE_VIEW_FIELD_DEF buffer
|
|
1678 |
CleanupStack::PopAndDestroy();
|
|
1679 |
}
|
|
1680 |
|
|
1681 |
// Generic SIP field
|
|
1682 |
if ( localVariation->LocallyVariatedFeatureEnabled( EVPbkLVAddSIPFields ) )
|
|
1683 |
{
|
|
1684 |
TResourceReader reader;
|
|
1685 |
reader.SetBuffer( resFile.AllocReadLC( R_CNTUI_ADD_SIP_FIELD_DEF ) );
|
|
1686 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1687 |
CleanupStack::PopAndDestroy(); // R_CNTUI_ADD_SIP_FIELD_DEF buffer
|
|
1688 |
}
|
|
1689 |
|
|
1690 |
// COD fields
|
|
1691 |
if ( FeatureManager::FeatureSupported( KFeatureIdCallImagetext ) )
|
|
1692 |
{
|
|
1693 |
TResourceReader reader;
|
|
1694 |
reader.SetBuffer( resFile.AllocReadLC( R_CNTUI_ADD_COD_FIELD_DEFNS ) );
|
|
1695 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1696 |
CleanupStack::PopAndDestroy(); // R_CNTUI_ADD_COD_FIELD_DEFNS buffer
|
|
1697 |
}
|
|
1698 |
|
|
1699 |
// MDO fields
|
|
1700 |
if ( localVariation->LocallyVariatedFeatureEnabled( EVPbkLVAddMDOFields ) )
|
|
1701 |
{
|
|
1702 |
TResourceReader reader;
|
|
1703 |
reader.SetBuffer(
|
|
1704 |
resFile.AllocReadLC( R_CNTUI_ADD_PREFIX_SUFFIX_FIELD_DEFNS ) );
|
|
1705 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1706 |
// R_CNTUI_ADD_PREFIX_SUFFIX_FIELD_DEFNS buffer
|
|
1707 |
CleanupStack::PopAndDestroy();
|
|
1708 |
}
|
|
1709 |
|
|
1710 |
// MegaOperator fields
|
|
1711 |
if ( localVariation->LocallyVariatedFeatureEnabled(
|
|
1712 |
EVPbkLVMegaOperatorFields ) )
|
|
1713 |
{
|
|
1714 |
TResourceReader reader;
|
|
1715 |
reader.SetBuffer(
|
|
1716 |
resFile.AllocReadLC( R_CNTUI_ADD_MEGAOP_FIELD_DEFNS ) );
|
|
1717 |
iFieldsInfo->AppendFieldsL( reader );
|
|
1718 |
CleanupStack::PopAndDestroy(); // R_CNTUI_ADD_MEGAOP_FIELD_DEFNS buffer
|
|
1719 |
}
|
|
1720 |
|
|
1721 |
CleanupStack::PopAndDestroy(2); // resFile, localVariation
|
|
1722 |
}
|
|
1723 |
|
|
1724 |
// --------------------------------------------------------------------------
|
|
1725 |
// CContactStore::CloseSystemTemplate
|
|
1726 |
// --------------------------------------------------------------------------
|
|
1727 |
//
|
|
1728 |
void CContactStore::CloseSystemTemplate(CContactDatabase* aContactDb)
|
|
1729 |
{
|
|
1730 |
if(iSysTemplate && aContactDb)
|
|
1731 |
{
|
|
1732 |
// according to contacts model documentation closecontactL
|
|
1733 |
// cannot leave, so this is safe.
|
|
1734 |
aContactDb->CloseContactL(iSysTemplate->Id());
|
|
1735 |
delete iSysTemplate;
|
|
1736 |
iSysTemplate = NULL;
|
|
1737 |
}
|
|
1738 |
}
|
|
1739 |
|
|
1740 |
// --------------------------------------------------------------------------
|
|
1741 |
// CContactStore::OpenL
|
|
1742 |
// --------------------------------------------------------------------------
|
|
1743 |
//
|
|
1744 |
CContactDatabase* CContactStore::OpenInternalL()
|
|
1745 |
{
|
|
1746 |
TBool creating = EFalse;
|
|
1747 |
|
|
1748 |
CContactDatabase* db = NULL;
|
|
1749 |
|
|
1750 |
TPtrC dbName( StoreProperties().Name().UriDes() );
|
|
1751 |
TRAPD( err, db = CContactDatabase::OpenL(dbName) );
|
|
1752 |
|
|
1753 |
if ( KErrNotFound == err )
|
|
1754 |
{
|
|
1755 |
// Database not found --> Creating it
|
|
1756 |
creating = ETrue;
|
|
1757 |
TRAP( err, db = CContactDatabase::CreateL(dbName) );
|
|
1758 |
}
|
|
1759 |
|
|
1760 |
RSharedDataClient* sharedDataClient = iStoreDomain.SharedDataClient();
|
|
1761 |
if ( KErrDiskFull == err && sharedDataClient )
|
|
1762 |
{
|
|
1763 |
// Try to release space for contact db opening
|
|
1764 |
sharedDataClient->RequestFreeDiskSpaceLC(KDiskSpaceForDbOpening);
|
|
1765 |
if (creating)
|
|
1766 |
{
|
|
1767 |
// Databse was not found --> Creating it
|
|
1768 |
db = CContactDatabase::CreateL(dbName);
|
|
1769 |
}
|
|
1770 |
else
|
|
1771 |
{
|
|
1772 |
// Opening database
|
|
1773 |
db = CContactDatabase::OpenL(dbName);
|
|
1774 |
}
|
|
1775 |
CleanupStack::PopAndDestroy(); // RequestFreeDiskSpaceLC
|
|
1776 |
}
|
|
1777 |
else
|
|
1778 |
{
|
|
1779 |
User::LeaveIfError(err);
|
|
1780 |
}
|
|
1781 |
return db;
|
|
1782 |
}
|
|
1783 |
|
|
1784 |
// --------------------------------------------------------------------------
|
|
1785 |
// CContactStore::DoActivateRemoteViewsL
|
|
1786 |
// --------------------------------------------------------------------------
|
|
1787 |
//
|
|
1788 |
void CContactStore::DoActivateRemoteViewsL()
|
|
1789 |
{
|
|
1790 |
// create the parameter object
|
|
1791 |
CVPbkSortOrderAcquirer::TSortOrderAcquirerParam param(
|
|
1792 |
MasterFieldTypeList() );
|
|
1793 |
// load ecom plugins to acquire the sort orders from the presentation
|
|
1794 |
// layer
|
|
1795 |
CSortOrderAcquirerList* ecomList = CSortOrderAcquirerList::NewLC(param);
|
|
1796 |
|
|
1797 |
const TInt count = ecomList->Count();
|
|
1798 |
for ( TInt i = 0; i < count; ++i )
|
|
1799 |
{
|
|
1800 |
CVPbkSortOrderAcquirer& acquirer = ecomList->At( i );
|
|
1801 |
if ( acquirer.ApplySortOrderToStoreL( iStoreURI->Uri() ) )
|
|
1802 |
{
|
|
1803 |
RContactViewSortOrder cntSortOrder = CreateSortOrderL(
|
|
1804 |
acquirer.SortOrder() );
|
|
1805 |
CleanupClosePushL(cntSortOrder);
|
|
1806 |
// Info is always found because acquirer is from same
|
|
1807 |
// CSortOrderAcquirerList instance.
|
|
1808 |
const CImplementationInformation* info =
|
|
1809 |
ecomList->FindInfo(acquirer);
|
|
1810 |
TContactViewPreferences viewPrefs = ConvertViewPrefsL(
|
|
1811 |
info->OpaqueData());
|
|
1812 |
|
|
1813 |
CNamedRemoteViewHandle* handle = CNamedRemoteViewHandle::NewLC();
|
|
1814 |
// create remote view
|
|
1815 |
handle->CreateRemoteViewL( info->DisplayName(), *iContactDb,
|
|
1816 |
cntSortOrder, viewPrefs );
|
|
1817 |
// append handle to container
|
|
1818 |
iNamedViewContainer.AppendL( handle );
|
|
1819 |
CleanupStack::Pop( handle );
|
|
1820 |
CleanupStack::PopAndDestroy(); // cntSortOrder
|
|
1821 |
}
|
|
1822 |
}
|
|
1823 |
CleanupStack::PopAndDestroy( ecomList );
|
|
1824 |
}
|
|
1825 |
|
|
1826 |
// --------------------------------------------------------------------------
|
|
1827 |
// CContactStore::CreateSortOrderL
|
|
1828 |
// --------------------------------------------------------------------------
|
|
1829 |
//
|
|
1830 |
RContactViewSortOrder CContactStore::CreateSortOrderL(
|
|
1831 |
const MVPbkFieldTypeList& aSortOrder) const
|
|
1832 |
{
|
|
1833 |
RContactViewSortOrder sortOrder;
|
|
1834 |
CleanupClosePushL(sortOrder);
|
|
1835 |
|
|
1836 |
const TInt count = aSortOrder.FieldTypeCount();
|
|
1837 |
for ( TInt i = 0; i < count; ++i )
|
|
1838 |
{
|
|
1839 |
const MVPbkFieldType& fieldType = aSortOrder.FieldTypeAt(i);
|
|
1840 |
// Ignores all field types that are not supported by this store
|
|
1841 |
const CContactItemField* field = iFieldFactory->FindField(
|
|
1842 |
fieldType);
|
|
1843 |
if (field)
|
|
1844 |
{
|
|
1845 |
sortOrder.AppendL(field->ContentType().FieldType(0));
|
|
1846 |
}
|
|
1847 |
}
|
|
1848 |
CleanupStack::Pop(); // sortOrder
|
|
1849 |
return sortOrder;
|
|
1850 |
}
|
|
1851 |
|
|
1852 |
// --------------------------------------------------------------------------
|
|
1853 |
// CContactStore::ConvertViewPrefsL
|
|
1854 |
// --------------------------------------------------------------------------
|
|
1855 |
//
|
|
1856 |
TContactViewPreferences CContactStore::ConvertViewPrefsL(const TDesC8& aData)
|
|
1857 |
{
|
|
1858 |
// convert character to TContactViewPreferences
|
|
1859 |
TLex8 lexer(aData);
|
|
1860 |
TUint32 output;
|
|
1861 |
User::LeaveIfError(lexer.Val(output, EDecimal));
|
|
1862 |
|
|
1863 |
TContactViewPreferences prefs = static_cast<TContactViewPreferences>(
|
|
1864 |
output);
|
|
1865 |
return prefs;
|
|
1866 |
}
|
|
1867 |
|
|
1868 |
// --------------------------------------------------------------------------
|
|
1869 |
// CContactStore::ContactStoreDomainFsSession
|
|
1870 |
// --------------------------------------------------------------------------
|
|
1871 |
//
|
|
1872 |
RFs& CContactStore::ContactStoreDomainFsSession()
|
|
1873 |
{
|
|
1874 |
return iStoreDomain.FsSession();
|
|
1875 |
}
|
|
1876 |
|
|
1877 |
} /// namespace VPbkCntModel
|
|
1878 |
|
|
1879 |
// End of File
|