63
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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:
|
|
15 |
* Implementation helper class for class CPbkContactEngine.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include "CPbkContactEngine.h"
|
|
22 |
#include "CContactDbConnection.h"
|
|
23 |
|
|
24 |
#include <cntdb.h>
|
|
25 |
#include <cntview.h>
|
|
26 |
#include <cntitem.h>
|
|
27 |
#include <sysutil.h>
|
|
28 |
#include <featmgr.h>
|
|
29 |
#include <shareddataclient.h>
|
|
30 |
|
|
31 |
#include <PbkDebug.h>
|
|
32 |
#include "PbkProfiling.h"
|
|
33 |
|
|
34 |
#include "PbkCompressConfig.h"
|
|
35 |
#include "CPbkDefaultCompressionStrategy.h"
|
|
36 |
|
|
37 |
#include "PbkUID.h"
|
|
38 |
#include "CPbkFieldsInfo.h"
|
|
39 |
#include "TPbkMatchPriorityLevel.h"
|
|
40 |
#include "CPbkEngineExtension.h"
|
|
41 |
#include "CPbkSortOrderManager.h"
|
|
42 |
#include "PbkNameFormatterFactory.h"
|
|
43 |
#include <MPbkContactNameFormat.h>
|
|
44 |
|
|
45 |
// Unnamed namespace for local definitions
|
|
46 |
|
|
47 |
namespace {
|
|
48 |
|
|
49 |
// LOCAL CONSTANTS AND MACROS
|
|
50 |
/// Name of the shared contacts view
|
|
51 |
_LIT(KPbkAllContactsViewName, "AllContacts");
|
|
52 |
|
|
53 |
/// Default contact database name
|
|
54 |
_LIT(KDefaultDbName, "C:Contacts.cdb");
|
|
55 |
|
|
56 |
/// Default contact view preferences
|
|
57 |
const TContactViewPreferences KPbkDefaultContactViewPrefs =
|
|
58 |
static_cast<TContactViewPreferences>
|
|
59 |
( EContactCardsOnly | EUnSortedAtEnd | ESingleWhiteSpaceIsEmptyField );
|
|
60 |
|
|
61 |
#ifdef _DEBUG
|
|
62 |
enum TPanicCode
|
|
63 |
{
|
|
64 |
EPanicUninitializedData = 1
|
|
65 |
};
|
|
66 |
|
|
67 |
// LOCAL FUNCTIONS
|
|
68 |
void Panic(TPanicCode aReason)
|
|
69 |
{
|
|
70 |
_LIT(KPanicText, "CContactDbConnection");
|
|
71 |
User::Panic(KPanicText, aReason);
|
|
72 |
}
|
|
73 |
#endif
|
|
74 |
|
|
75 |
|
|
76 |
// ==================== LOCAL FUNCTIONS ====================
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Returns true if aLhs and aRhs differ.
|
|
80 |
*/
|
|
81 |
inline TBool operator!=
|
|
82 |
(const RContactViewSortOrder& aLhs, const RContactViewSortOrder& aRhs)
|
|
83 |
{
|
|
84 |
return !(aLhs == aRhs);
|
|
85 |
}
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Wrapper class for calling default file name or specified filename versions
|
|
89 |
* of CContactDatabase::ReplaceL, OpenL and CreateL.
|
|
90 |
*/
|
|
91 |
NONSHARABLE_CLASS(TDbOpen)
|
|
92 |
{
|
|
93 |
public:
|
|
94 |
/**
|
|
95 |
* Constructor.
|
|
96 |
* @param aFileName file name
|
|
97 |
* @param aReplace open or replace the database
|
|
98 |
* @param aSharedDataClient shared data client
|
|
99 |
*/
|
|
100 |
TDbOpen(const TDesC* aFileName, TBool aReplace,
|
|
101 |
const RSharedDataClient& aSharedDataClient);
|
|
102 |
|
|
103 |
/**
|
|
104 |
* Opens or replaces database.
|
|
105 |
*/
|
|
106 |
CContactDatabase* OpenOrReplaceL() const;
|
|
107 |
|
|
108 |
/**
|
|
109 |
* Creates a new database.
|
|
110 |
*/
|
|
111 |
CContactDatabase* CreateL() const;
|
|
112 |
|
|
113 |
/**
|
|
114 |
* Returns the drive the database is stored on.
|
|
115 |
* @precond OpenOrReplaceL() or CreateL() has been called.
|
|
116 |
*/
|
|
117 |
TDriveNumber DbDrive(RFs& aFs) const;
|
|
118 |
|
|
119 |
private: // Implementation
|
|
120 |
CContactDatabase* ReplaceL() const;
|
|
121 |
CContactDatabase* OpenL() const;
|
|
122 |
|
|
123 |
private:
|
|
124 |
/// Own: file name
|
|
125 |
TFileName iFileName;
|
|
126 |
/// Own: open or replace flag
|
|
127 |
const TBool iReplace;
|
|
128 |
/// Ref: contact database
|
|
129 |
mutable CContactDatabase* iDb;
|
|
130 |
/// Ref: Shared data client
|
|
131 |
const RSharedDataClient& iSharedDataClient;
|
|
132 |
};
|
|
133 |
|
|
134 |
/**
|
|
135 |
* Updates system template to reflect aFieldsInfo.
|
|
136 |
*/
|
|
137 |
TBool UpdateSystemTemplateFieldsL
|
|
138 |
(CContactItem& aSysTemplate,
|
|
139 |
const CPbkFieldsInfo& aFieldsInfo);
|
|
140 |
|
|
141 |
} // namespace
|
|
142 |
|
|
143 |
|
|
144 |
// ================= MEMBER FUNCTIONS =======================
|
|
145 |
|
|
146 |
inline CPbkContactEngine::CContactDbConnection::CContactDbConnection()
|
|
147 |
{
|
|
148 |
}
|
|
149 |
|
|
150 |
inline TBool CPbkContactEngine::CContactDbConnection::CheckSystemTemplateL
|
|
151 |
(const CPbkFieldsInfo& aFieldsInfo)
|
|
152 |
{
|
|
153 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
154 |
"CContactDbConnection::CheckSystemTemplateL(0x%x)"),this);
|
|
155 |
|
|
156 |
// Open the system template
|
|
157 |
TRAPD(err, iSysTemplate = iContactDb->OpenContactL(
|
|
158 |
iContactDb->TemplateId()));
|
|
159 |
switch (err)
|
|
160 |
{
|
|
161 |
case KErrNone:
|
|
162 |
{
|
|
163 |
// All is well
|
|
164 |
break;
|
|
165 |
}
|
|
166 |
case KErrInUse:
|
|
167 |
{
|
|
168 |
// Assume some other CPbkContactEngine instance is currently
|
|
169 |
// performing this check -> skip the test. The test could be
|
|
170 |
// reattempted after a delay but that would slow down the
|
|
171 |
// initialisation of this class even more.
|
|
172 |
return EFalse;
|
|
173 |
}
|
|
174 |
default:
|
|
175 |
{
|
|
176 |
// Propagate other errors to caller
|
|
177 |
User::Leave(err);
|
|
178 |
return EFalse;
|
|
179 |
}
|
|
180 |
}
|
|
181 |
|
|
182 |
TBool result = EFalse;
|
|
183 |
if (UpdateSystemTemplateFieldsL(*iSysTemplate,aFieldsInfo))
|
|
184 |
{
|
|
185 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
186 |
"CContactDbConnection::CheckSystemTemplateL(0x%x): updating system template...."),
|
|
187 |
this);
|
|
188 |
iContactDb->CommitContactL(*iSysTemplate);
|
|
189 |
|
|
190 |
result = ETrue;
|
|
191 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
192 |
"CContactDbConnection::CheckSystemTemplateL(0x%x): system template updated."), this);
|
|
193 |
}
|
|
194 |
|
|
195 |
CloseSystemTemplate();
|
|
196 |
|
|
197 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
198 |
"CContactDbConnection::CheckSystemTemplateL(0x%x) succesful"),this);
|
|
199 |
return result;
|
|
200 |
}
|
|
201 |
|
|
202 |
inline void CPbkContactEngine::CContactDbConnection::CreateAllContactsViewL
|
|
203 |
(const RContactViewSortOrder& aSortOrder)
|
|
204 |
{
|
|
205 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
206 |
"CContactDbConnection::CreateAllContactsViewL(0x%x)"),this);
|
|
207 |
|
|
208 |
__PBK_PROFILE_RESET(PbkProfiling::EAllContactsViewOpen);
|
|
209 |
__PBK_PROFILE_START(PbkProfiling::EAllContactsViewOpen);
|
|
210 |
iAllContactsView = CContactNamedRemoteView::NewL
|
|
211 |
(*this,
|
|
212 |
KPbkAllContactsViewName,
|
|
213 |
Database(),
|
|
214 |
aSortOrder,
|
|
215 |
KPbkDefaultContactViewPrefs);
|
|
216 |
|
|
217 |
InitViewL(*iAllContactsView);
|
|
218 |
|
|
219 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
220 |
"CContactDbConnection::CreateAllContactsViewL(0x%x) succesful"),this);
|
|
221 |
}
|
|
222 |
|
|
223 |
inline void CPbkContactEngine::CContactDbConnection::ConstructL
|
|
224 |
(const TParams& aParams, TBool aSettingsVisible)
|
|
225 |
{
|
|
226 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
227 |
"CContactDbConnection::ConstructL(0x%x)"),this);
|
|
228 |
iFs = aParams.iFs;
|
|
229 |
|
|
230 |
__PBK_PROFILE_START(PbkProfiling::EContactDbOpen);
|
|
231 |
|
|
232 |
// Shared data client is created and connected in CPbkContactEngine
|
|
233 |
__ASSERT_DEBUG(aParams.iEngine && aParams.iEngine->iSharedDataClient,
|
|
234 |
Panic(EPanicUninitializedData));
|
|
235 |
|
|
236 |
TDbOpen dbOpen(aParams.iDbFileName, aParams.iReplaceExistingDb,
|
|
237 |
*aParams.iEngine->iSharedDataClient);
|
|
238 |
TRAPD(error, iContactDb = dbOpen.OpenOrReplaceL());
|
|
239 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
240 |
"CContactDbConnection::ConstructL(0x%x): CContactDatabase open result=%d."),this, error);
|
|
241 |
if (error == KErrNotFound)
|
|
242 |
{
|
|
243 |
// Db not found, create it
|
|
244 |
TRAP(error, iContactDb = dbOpen.CreateL());
|
|
245 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
246 |
"CContactDbConnection::ConstructL(0x%x): CContactDatabase create result=%d."),this, error);
|
|
247 |
}
|
|
248 |
|
|
249 |
__PBK_PROFILE_END(PbkProfiling::EContactDbOpen);
|
|
250 |
|
|
251 |
*aParams.iDbOpenError = error;
|
|
252 |
if (error != KErrNone)
|
|
253 |
{
|
|
254 |
User::Leave(error);
|
|
255 |
}
|
|
256 |
|
|
257 |
// Store database drive
|
|
258 |
iDbDrive = dbOpen.DbDrive(iFs);
|
|
259 |
|
|
260 |
// Call engine extension plugins
|
|
261 |
aParams.iExtension->AddFieldTypesL(*aParams.iFieldsInfo);
|
|
262 |
aParams.iExtension->ModifyFieldTypesL(*aParams.iFieldsInfo);
|
|
263 |
|
|
264 |
// Check and update system template if needed
|
|
265 |
TBool updated = EFalse;
|
|
266 |
TRAP(error, updated = CheckSystemTemplateL(*aParams.iFieldsInfo));
|
|
267 |
*aParams.iDbOpenError = error;
|
|
268 |
if (error != KErrNone)
|
|
269 |
{
|
|
270 |
User::Leave(error);
|
|
271 |
}
|
|
272 |
|
|
273 |
if (updated)
|
|
274 |
{
|
|
275 |
// close and reopen contact database if system template has been updated
|
|
276 |
delete iContactDb;
|
|
277 |
iContactDb = NULL;
|
|
278 |
iContactDb = dbOpen.OpenOrReplaceL();
|
|
279 |
}
|
|
280 |
|
|
281 |
// Create contact DB change notifier and connect it to aObserver
|
|
282 |
iContactChangeNotifier = CContactChangeNotifier::NewL
|
|
283 |
(*iContactDb, aParams.iContactDbObserver);
|
|
284 |
|
|
285 |
// Create DB compressor
|
|
286 |
iCompressionStrategy = CPbkDefaultCompressionStrategy::NewL
|
|
287 |
(*iContactDb, iDbDrive, iFs);
|
|
288 |
|
|
289 |
// Create contact Sort order managing object
|
|
290 |
iSortOrderManager = CPbkSortOrderManager::NewL(iFs, aSettingsVisible);
|
|
291 |
|
|
292 |
// Create the shared all contacts view
|
|
293 |
CreateAllContactsViewL(iSortOrderManager->SortOrder());
|
|
294 |
|
|
295 |
// Set view to sort order manager
|
|
296 |
iSortOrderManager->SetContactView(*iAllContactsView);
|
|
297 |
|
|
298 |
// create name formatting object
|
|
299 |
iContactNameFormatter = PbkNameFormatterFactory::CreateL
|
|
300 |
(*aParams.iUnnamedTitle, *iSortOrderManager, aSettingsVisible);
|
|
301 |
|
|
302 |
|
|
303 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
304 |
"CContactDbConnection::ConstructL(0x%x) succesful."),this);
|
|
305 |
}
|
|
306 |
|
|
307 |
CPbkContactEngine::CContactDbConnection* CPbkContactEngine::CContactDbConnection::NewL
|
|
308 |
(const TParams& aParams, TBool aSettingsVisible)
|
|
309 |
{
|
|
310 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CContactDbConnection::NewL()"));
|
|
311 |
|
|
312 |
CContactDbConnection* self = new(ELeave) CContactDbConnection;
|
|
313 |
CleanupStack::PushL(self);
|
|
314 |
self->ConstructL(aParams, aSettingsVisible);
|
|
315 |
CleanupStack::Pop(self);
|
|
316 |
|
|
317 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
318 |
"CContactDbConnection::NewL() succesful, result=0x%x"), self);
|
|
319 |
return self;
|
|
320 |
}
|
|
321 |
|
|
322 |
CPbkContactEngine::CContactDbConnection::~CContactDbConnection()
|
|
323 |
{
|
|
324 |
for (TInt i = iFilteredViews.Count()-1; i >= 0; --i)
|
|
325 |
{
|
|
326 |
iFilteredViews[i].iFilteredView->Close(*this);
|
|
327 |
}
|
|
328 |
iFilteredViews.Close();
|
|
329 |
if (iGroupsLocalView)
|
|
330 |
{
|
|
331 |
iGroupsLocalView->Close(*this);
|
|
332 |
}
|
|
333 |
|
|
334 |
if (iAllContactsView)
|
|
335 |
{
|
|
336 |
iAllContactsView->Close(*this);
|
|
337 |
}
|
|
338 |
|
|
339 |
if (iCompressionStrategy)
|
|
340 |
{
|
|
341 |
iCompressionStrategy->Release();
|
|
342 |
}
|
|
343 |
delete iContactChangeNotifier;
|
|
344 |
delete iContactNameFormatter;
|
|
345 |
delete iSortOrderManager;
|
|
346 |
CloseSystemTemplate();
|
|
347 |
delete iContactDb;
|
|
348 |
}
|
|
349 |
|
|
350 |
CContactViewBase& CPbkContactEngine::CContactDbConnection::AllGroupsViewL()
|
|
351 |
{
|
|
352 |
// start loading the all the groups
|
|
353 |
if (!iGroupsLocalView)
|
|
354 |
{
|
|
355 |
// Create a CContactLocalView that contains only groups.
|
|
356 |
RContactViewSortOrder groupViewSortOrder;
|
|
357 |
CleanupClosePushL(groupViewSortOrder);
|
|
358 |
// KUidContactFieldTemplateLabel contains the group label
|
|
359 |
groupViewSortOrder.AppendL(KUidContactFieldTemplateLabel);
|
|
360 |
|
|
361 |
iGroupsLocalView = CContactLocalView::NewL(
|
|
362 |
*this, *iContactDb, groupViewSortOrder, EGroupsOnly);
|
|
363 |
|
|
364 |
InitViewL(*iGroupsLocalView);
|
|
365 |
|
|
366 |
CleanupStack::PopAndDestroy(); // groupViewSortOrder
|
|
367 |
}
|
|
368 |
|
|
369 |
return *iGroupsLocalView;
|
|
370 |
}
|
|
371 |
|
|
372 |
CContactViewBase& CPbkContactEngine::CContactDbConnection::FilteredContactsViewL
|
|
373 |
(TInt aFilter)
|
|
374 |
{
|
|
375 |
const TInt count = iFilteredViews.Count();
|
|
376 |
for (TInt i=0; i < count; ++i)
|
|
377 |
{
|
|
378 |
if (iFilteredViews[i].iFilter == aFilter)
|
|
379 |
{
|
|
380 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
381 |
"Returned filtered view filter=%x from the cache"), aFilter);
|
|
382 |
return *iFilteredViews[i].iFilteredView;
|
|
383 |
}
|
|
384 |
}
|
|
385 |
|
|
386 |
// Ending this profile is in HandleContactViewEvent
|
|
387 |
__PBK_PROFILE_RESET(PbkProfiling::EFilteredViewOpen);
|
|
388 |
__PBK_PROFILE_START(PbkProfiling::EFilteredViewOpen);
|
|
389 |
|
|
390 |
TFilteredView filter;
|
|
391 |
filter.iFilter = aFilter;
|
|
392 |
filter.iFilteredView = CContactFilteredView::NewL
|
|
393 |
(*this, *iContactDb, *iAllContactsView, aFilter);
|
|
394 |
InitViewL(*filter.iFilteredView);
|
|
395 |
const TInt err = iFilteredViews.Append(filter);
|
|
396 |
if (err != KErrNone)
|
|
397 |
{
|
|
398 |
filter.iFilteredView->Close(*this);
|
|
399 |
User::Leave(err);
|
|
400 |
}
|
|
401 |
|
|
402 |
return *filter.iFilteredView;
|
|
403 |
}
|
|
404 |
|
|
405 |
void CPbkContactEngine::CContactDbConnection::SetCompressUi
|
|
406 |
(MPbkCompressUi* aCompressUi)
|
|
407 |
{
|
|
408 |
iCompressionStrategy->SetCompressUi(aCompressUi);
|
|
409 |
}
|
|
410 |
|
|
411 |
TBool CPbkContactEngine::CContactDbConnection::IsCompressionEnabled() const
|
|
412 |
{
|
|
413 |
return iCompressionStrategy->IsCompressionEnabled();
|
|
414 |
}
|
|
415 |
|
|
416 |
TBool CPbkContactEngine::CContactDbConnection::CheckCompress()
|
|
417 |
{
|
|
418 |
return iCompressionStrategy->CheckCompress();
|
|
419 |
}
|
|
420 |
|
|
421 |
void CPbkContactEngine::CContactDbConnection::CompressL()
|
|
422 |
{
|
|
423 |
iCompressionStrategy->CompressL();
|
|
424 |
}
|
|
425 |
|
|
426 |
void CPbkContactEngine::CContactDbConnection::CancelCompress() const
|
|
427 |
{
|
|
428 |
iCompressionStrategy->CancelCompress();
|
|
429 |
}
|
|
430 |
|
|
431 |
void CPbkContactEngine::CContactDbConnection::CheckFileSystemSpaceAndCompressL()
|
|
432 |
{
|
|
433 |
PBK_COMPRESS_LOG
|
|
434 |
(PBK_COMPRESS_STRING(
|
|
435 |
"CContactDbConnection::CheckFileSystemSpaceAndCompressL(0x%x), DB size = %d bytes"),
|
|
436 |
this, Database().FileSize());
|
|
437 |
|
|
438 |
// Cancel any async compress in progress
|
|
439 |
CancelCompress();
|
|
440 |
|
|
441 |
// Compress synchronously always if compression is required by the DB
|
|
442 |
// or file system space is below critical level
|
|
443 |
if (Database().CompressRequired() || FileSpaceLowOnDbDrive())
|
|
444 |
{
|
|
445 |
TRAPD(result, Database().CompactL());
|
|
446 |
PBK_COMPRESS_LOG(PBK_COMPRESS_STRING(" Compacted database, result=%d"), result);
|
|
447 |
}
|
|
448 |
|
|
449 |
// If file system space is still under critical level leave with
|
|
450 |
// error code KErrDiskFull.
|
|
451 |
if (FileSpaceLowOnDbDrive())
|
|
452 |
{
|
|
453 |
PBK_COMPRESS_LOG
|
|
454 |
(PBK_COMPRESS_STRING(" FFS space is under critical level -> leaving with KErrDiskFull(%d)"),
|
|
455 |
KErrDiskFull);
|
|
456 |
User::Leave(KErrDiskFull);
|
|
457 |
}
|
|
458 |
}
|
|
459 |
|
|
460 |
TBool CPbkContactEngine::CContactDbConnection::FileSpaceLowOnDbDrive() const
|
|
461 |
{
|
|
462 |
TBool result = EFalse;
|
|
463 |
TRAP_IGNORE(result = SysUtil::DiskSpaceBelowCriticalLevelL(&iFs,0,iDbDrive));
|
|
464 |
if (result)
|
|
465 |
{
|
|
466 |
PBK_COMPRESS_LOG(PBK_COMPRESS_STRING("CContactDbConnection::FileSpaceLowOnDbDrive() returning ETrue"));
|
|
467 |
}
|
|
468 |
return result;
|
|
469 |
}
|
|
470 |
|
|
471 |
void CPbkContactEngine::CContactDbConnection::HandleContactViewEvent
|
|
472 |
#ifdef PBK_ENABLE_PROFILE
|
|
473 |
(const CContactViewBase& aView, const TContactViewEvent& aEvent)
|
|
474 |
#else
|
|
475 |
(const CContactViewBase& /*aView*/, const TContactViewEvent& /*aEvent*/)
|
|
476 |
#endif
|
|
477 |
{
|
|
478 |
#ifdef PBK_ENABLE_PROFILE
|
|
479 |
if (aEvent.iEventType != TContactViewEvent::EReady)
|
|
480 |
{
|
|
481 |
return;
|
|
482 |
}
|
|
483 |
if (&aView == iAllContactsView)
|
|
484 |
{
|
|
485 |
__PBK_PROFILE_END(PbkProfiling::EAllContactsViewOpen);
|
|
486 |
__PBK_PROFILE_DISPLAY(PbkProfiling::EAllContactsViewOpen);
|
|
487 |
__PBK_PROFILE_RESET(PbkProfiling::EAllContactsViewOpen);
|
|
488 |
}
|
|
489 |
else if (iFilteredViews.Count() > 0)
|
|
490 |
{
|
|
491 |
for (TInt i=0; i < iFilteredViews.Count(); ++i)
|
|
492 |
{
|
|
493 |
if (iFilteredViews[i].iFilteredView == &aView)
|
|
494 |
{
|
|
495 |
__PBK_PROFILE_END(PbkProfiling::EFilteredViewOpen);
|
|
496 |
__PBK_PROFILE_DISPLAY(PbkProfiling::EFilteredViewOpen);
|
|
497 |
__PBK_PROFILE_RESET(PbkProfiling::EFilteredViewOpen);
|
|
498 |
}
|
|
499 |
}
|
|
500 |
|
|
501 |
}
|
|
502 |
#endif // PBK_ENABLE_PROFILE
|
|
503 |
}
|
|
504 |
|
|
505 |
void CPbkContactEngine::CContactDbConnection::CloseSystemTemplate()
|
|
506 |
{
|
|
507 |
if (iSysTemplate)
|
|
508 |
{
|
|
509 |
// Contact Model documentation says CloseContactL cannot leave
|
|
510 |
iContactDb->CloseContactL(iSysTemplate->Id());
|
|
511 |
delete iSysTemplate;
|
|
512 |
iSysTemplate = NULL;
|
|
513 |
}
|
|
514 |
}
|
|
515 |
|
|
516 |
void CPbkContactEngine::CContactDbConnection::ChangeSortOrderL
|
|
517 |
(const RContactViewSortOrder& aSortOrder) const
|
|
518 |
{
|
|
519 |
// Compare is the new sort order same than the previous one
|
|
520 |
if (iAllContactsView->SortOrderL() != aSortOrder)
|
|
521 |
{
|
|
522 |
// It wasn't, change the sort order
|
|
523 |
iAllContactsView->ChangeSortOrderL(aSortOrder);
|
|
524 |
}
|
|
525 |
}
|
|
526 |
|
|
527 |
MPbkContactNameFormat& CPbkContactEngine::CContactDbConnection::ContactNameFormatter() const
|
|
528 |
{
|
|
529 |
return *iContactNameFormatter;
|
|
530 |
}
|
|
531 |
|
|
532 |
void CPbkContactEngine::CContactDbConnection::SetNameDisplayOrderL
|
|
533 |
(TPbkNameOrder aNameOrder)
|
|
534 |
{
|
|
535 |
iSortOrderManager->SetNameDisplayOrderL(aNameOrder);
|
|
536 |
}
|
|
537 |
|
|
538 |
CPbkContactEngine::TPbkNameOrder CPbkContactEngine::CContactDbConnection::NameDisplayOrder()
|
|
539 |
{
|
|
540 |
return iSortOrderManager->NameDisplayOrder();
|
|
541 |
}
|
|
542 |
|
|
543 |
|
|
544 |
void CPbkContactEngine::CContactDbConnection::SetNameSeparatorL(TChar aNameSeparator)
|
|
545 |
{
|
|
546 |
iSortOrderManager->SetNameSeparatorL(aNameSeparator);
|
|
547 |
}
|
|
548 |
|
|
549 |
TChar CPbkContactEngine::CContactDbConnection::NameSeparator()
|
|
550 |
{
|
|
551 |
return iSortOrderManager->NameSeparator();
|
|
552 |
}
|
|
553 |
|
|
554 |
/**
|
|
555 |
* Call this method for all views created in this class.
|
|
556 |
*/
|
|
557 |
void CPbkContactEngine::CContactDbConnection::InitViewL(CContactViewBase& aView)
|
|
558 |
{
|
|
559 |
// Set find plugin
|
|
560 |
aView.SetViewFindConfigPlugin(TUid::Uid(KFindPluginUID));
|
|
561 |
}
|
|
562 |
|
|
563 |
|
|
564 |
namespace {
|
|
565 |
|
|
566 |
const TInt KDiskSpaceForDbOpening = 140*1024; // Space for db opening
|
|
567 |
|
|
568 |
// ==================== LOCAL FUNCTIONS ====================
|
|
569 |
|
|
570 |
/**
|
|
571 |
* Returns the default database name using CContactDatabase::GetDefaultNameL().
|
|
572 |
* If GetDefaultNameL() fails returns silently KDefaultDbName.
|
|
573 |
*/
|
|
574 |
void GetDefaultDatabaseName(TDes& aName)
|
|
575 |
{
|
|
576 |
TRAPD(err, CContactDatabase::GetDefaultNameL(aName));
|
|
577 |
if (err != KErrNone)
|
|
578 |
{
|
|
579 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
580 |
"CContactDatabase::GetDefaultNameL() failed with error code %d"),
|
|
581 |
err);
|
|
582 |
aName.Copy(KDefaultDbName);
|
|
583 |
}
|
|
584 |
}
|
|
585 |
TDbOpen::TDbOpen(const TDesC* aFileName, TBool aReplace,
|
|
586 |
const RSharedDataClient& aSharedDataClient):
|
|
587 |
iReplace(aReplace), iSharedDataClient(aSharedDataClient)
|
|
588 |
{
|
|
589 |
if (aFileName)
|
|
590 |
{
|
|
591 |
iFileName.Copy(aFileName->Left(iFileName.MaxLength()));
|
|
592 |
}
|
|
593 |
else
|
|
594 |
{
|
|
595 |
GetDefaultDatabaseName(iFileName);
|
|
596 |
}
|
|
597 |
}
|
|
598 |
|
|
599 |
inline CContactDatabase* TDbOpen::ReplaceL() const
|
|
600 |
{
|
|
601 |
iDb = CContactDatabase::ReplaceL(iFileName);
|
|
602 |
return iDb;
|
|
603 |
}
|
|
604 |
|
|
605 |
|
|
606 |
inline CContactDatabase* TDbOpen::OpenL() const
|
|
607 |
{
|
|
608 |
|
|
609 |
TRAPD(err,iDb = CContactDatabase::OpenL(iFileName));
|
|
610 |
|
|
611 |
//Handle KErrDiskFull case separately
|
|
612 |
if(KErrDiskFull==err)
|
|
613 |
{
|
|
614 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
615 |
"CContactDbConnection::TDbOpen::OpenL(0x%x) KErrDiskFull"),this);
|
|
616 |
// Try to release space for contact db opening
|
|
617 |
iSharedDataClient.RequestFreeDiskSpaceLC(KDiskSpaceForDbOpening);
|
|
618 |
iDb = CContactDatabase::OpenL(iFileName);
|
|
619 |
CleanupStack::PopAndDestroy(); // RequestFreeDiskSpaceLC
|
|
620 |
PBK_DEBUG_PRINT(PBK_DEBUG_STRING(
|
|
621 |
"CContactDbConnection::TDbOpen::OpenL(0x%x) ContactDb open"),this);
|
|
622 |
}
|
|
623 |
else
|
|
624 |
{
|
|
625 |
User::LeaveIfError(err);
|
|
626 |
}
|
|
627 |
return iDb;
|
|
628 |
}
|
|
629 |
|
|
630 |
|
|
631 |
CContactDatabase* TDbOpen::OpenOrReplaceL() const
|
|
632 |
{
|
|
633 |
return (iReplace ? ReplaceL() : OpenL());
|
|
634 |
}
|
|
635 |
|
|
636 |
CContactDatabase* TDbOpen::CreateL() const
|
|
637 |
{
|
|
638 |
iDb = CContactDatabase::CreateL(iFileName);
|
|
639 |
return iDb;
|
|
640 |
}
|
|
641 |
|
|
642 |
TDriveNumber TDbOpen::DbDrive(RFs& aFs) const
|
|
643 |
{
|
|
644 |
TInt result = EDriveC;
|
|
645 |
TParsePtrC fileParser(iFileName);
|
|
646 |
if (fileParser.DrivePresent())
|
|
647 |
{
|
|
648 |
const TChar driveLetter(fileParser.Drive()[0]);
|
|
649 |
TInt drive;
|
|
650 |
if (aFs.CharToDrive(driveLetter,drive) == KErrNone)
|
|
651 |
{
|
|
652 |
result = drive;
|
|
653 |
}
|
|
654 |
}
|
|
655 |
else
|
|
656 |
{
|
|
657 |
TDriveUnit driveUnit;
|
|
658 |
//Note: this function can leave
|
|
659 |
TRAPD(err, iDb->DatabaseDrive(driveUnit));
|
|
660 |
if (err == KErrNone)
|
|
661 |
{
|
|
662 |
result = driveUnit;
|
|
663 |
}
|
|
664 |
}
|
|
665 |
return static_cast<TDriveNumber>(result);
|
|
666 |
}
|
|
667 |
|
|
668 |
/**
|
|
669 |
* Updates a single field to the contact database system template. If the field
|
|
670 |
* does not exist in the system template it is added. If the field exists but
|
|
671 |
* its label differs from the field type label the system template label is
|
|
672 |
* updated.
|
|
673 |
*
|
|
674 |
* @param aSysTemplate the system template.
|
|
675 |
* @param aFieldInfo the field type to update.
|
|
676 |
* @return true if the system template was updated.
|
|
677 |
*/
|
|
678 |
TBool UpdateSystemTemplateFieldL
|
|
679 |
(CContactItem& aSysTemplate, const CPbkFieldInfo& aFieldInfo)
|
|
680 |
{
|
|
681 |
TBool updated = EFalse;
|
|
682 |
// Scan system template field set for the field
|
|
683 |
CContactItemFieldSet& fieldSet = aSysTemplate.CardFields();
|
|
684 |
TInt i;
|
|
685 |
const TInt fieldCount = fieldSet.Count();
|
|
686 |
for (i = 0; i < fieldCount; ++i)
|
|
687 |
{
|
|
688 |
CContactItemField& sysTemplateField = fieldSet[i];
|
|
689 |
if (aFieldInfo.IsEqualType(sysTemplateField))
|
|
690 |
{
|
|
691 |
// Field was found, just check the label
|
|
692 |
if (!aFieldInfo.IsEqualLabel(sysTemplateField))
|
|
693 |
{
|
|
694 |
sysTemplateField.SetLabelL(aFieldInfo.FieldName());
|
|
695 |
updated = ETrue;
|
|
696 |
}
|
|
697 |
break;
|
|
698 |
}
|
|
699 |
}
|
|
700 |
|
|
701 |
if (i == fieldCount)
|
|
702 |
{
|
|
703 |
// Field was not found, add it
|
|
704 |
CContactItemField* field = aFieldInfo.CreateFieldL();
|
|
705 |
CleanupStack::PushL(field);
|
|
706 |
fieldSet.AddL(*field);
|
|
707 |
CleanupStack::Pop(field);
|
|
708 |
updated = ETrue;
|
|
709 |
}
|
|
710 |
return updated;
|
|
711 |
}
|
|
712 |
|
|
713 |
TBool UpdateSystemTemplateFieldsL
|
|
714 |
(CContactItem& aSysTemplate,
|
|
715 |
const CPbkFieldsInfo& aFieldsInfo)
|
|
716 |
{
|
|
717 |
TBool updated = EFalse;
|
|
718 |
const TInt fieldInfoCount = aFieldsInfo.Count();
|
|
719 |
|
|
720 |
// Update fields
|
|
721 |
for (TInt i=0; i < fieldInfoCount; ++i)
|
|
722 |
{
|
|
723 |
if (UpdateSystemTemplateFieldL(aSysTemplate, *aFieldsInfo[i]))
|
|
724 |
{
|
|
725 |
updated = ETrue;
|
|
726 |
}
|
|
727 |
}
|
|
728 |
|
|
729 |
return updated;
|
|
730 |
}
|
|
731 |
|
|
732 |
} // namespace
|
|
733 |
|
|
734 |
// End of File
|