summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntsrv/inc/ccntdbmanager.h
blob: 65d9b56b436f779a595494d0ca688693197b458a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/




/**
 @file
 @internalComponent
 @released
*/

#ifndef CCNTDBMANAGER_H
#define CCNTDBMANAGER_H

#include "persistencelayer.h"
#include "ccntlowdiskmanager.h"
#include <e32base.h>


enum TCntFileMode
	{
	ECntFileOpen,
	ECntFileCreate,
	ECntFileReplace
	};

class CPersistenceLayer;
class CCntStateMachine;
class CCntRequest;
class CCntBackupRestoreAgent;
class CIniFileManager;
class CViewManager;


/**
Low disk threshold is set at 128Kb.  Below this threshold only database
operations which decrease the size of the database file are allowed.
*/
const TInt64 KLowDiskThreshold = 0x20000;


/**
The CCntDbManager class represents the most abstract level of access to the
Contacts database.

There is one CCntDbManager class per Contacts database.  Multiple sessions
(CCntSession objects) can be mapped to one CCntDbManager.

Multiple instances of the CCntDbManager class are controlled by the one
CCntDbManagerController instance (owned by CCntServer2).
*/
class CCntDbManager : public CBase, public MContactDbObserverV2, public MContactLowDiskObserver, public MIniFileManager
	{
public:
	static CCntDbManager* NewLC(RFs& aFs, const TDesC& aCntFile, TCntFileMode aFileMode, CCntBackupRestoreAgent& aBackupRestoreAgent, CIniFileManager& aIniManager);
	virtual ~CCntDbManager();

	void AddSession();
	void RemoveSession();
	TInt SessionCount() const;

	// Access methods.
	CPersistenceLayer& GetPersistenceLayer();
	CCntStateMachine& StateMachineL();
	CCntBackupRestoreAgent& BackupRestoreAgent();
	CIniFileManager& IniFileManager();
	CViewManager& ViewManagerL();	

	// Database file methods.
	const TDesC& CntFile();
	TInt FileSizeL();
	
	void RegisterDatabaseEventObserverL(MContactDbObserver& aObserver);
	void UnRegisterDatabaseEventObserver(MContactDbObserver& aObserver);
	void RegisterDatabaseEventObserverL(MContactDbObserverV2& aObserver);
	void UnRegisterDatabaseEventObserver(MContactDbObserverV2& aObserver);

	// From MContactDbObserver.
	void HandleDatabaseEventV2L(TContactDbObserverEventV2 aEvent);
	void HandleBackupRestoreEventL(TContactDbObserverEventV2 aEvent);
	void HandleLowDiskL(TBool aLowDisk);

	void NotifyObserversL(const TContactDbObserverEventV2 aEvent);

	// Current item methods.
	void SetCurrentItemL(TContactItemId aContactId, TUint aConnectionId);
	TContactItemId CurrentItem() const;
	void RemoveCurrentItemL(TUint aConnectionId);
	void DeleteNotifyL(TContactItemId aContactId);
	
	// Speed dial methods.
	void GetSpeedDialContactIdAndPhoneNumberL(const TInt aSpeedDialIndex, TSpeedDialPhoneNumber& aPhoneNumber, TContactItemId& aContactId);
	TContactItemId SetSpeedDialIdForPositionL(const TInt aSpeedDialIndex, const TContactItemId aContactId,  const TSpeedDialPhoneNumber& aPhoneNumber, TUint aConnectionId, TBool aSendNotification);
	CArrayFix<TInt>* SpeedDialIndicesForContactIdLC(TContactItemId aContactId); 

	void SetCardTemplatePrefIdL(TContactItemId aCardTemplatePrefId, TInt aConnectionId);
	void RecreateSystemTemplateL();

private:
	void ConstructL(TCntFileMode aFileMode);
	CCntDbManager(RFs& aFs, const TDesC& aCntFile, CCntBackupRestoreAgent& aBackupRestoreAgent, CIniFileManager& aIniManager);

	// Access methods.
	CCntLowDiskManager&	LowDiskManagerL();

private:
	CCntStateMachine*		iStateMachine;
	CCntLowDiskManager*		iLowDiskManager;	
	CPersistenceLayer*		iPersistenceLayer;
	CViewManager* 			iViewManager;

	RFs&					iFs;
	TFileName				iCntFile;
	
	CCntBackupRestoreAgent& iBackupRestoreAgent;
	CIniFileManager&		iIniManager;

	TInt 					iSessionCount;
	
	// Array of registered database event observers.
	RPointerArray<MContactDbObserver> iObserverArray;
	RPointerArray<MContactDbObserverV2> iObserverV2Array;
 	};

	
#endif