summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntsrv/inc/cinifilemanager.h
blob: aaaf5125bfd77b83f3c4551bc2cd0d34640e3bd6 (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
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* 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 __CINIFILEMANAGER_H__
#define __CINIFILEMANAGER_H__

#include <e32base.h>
#include <s32file.h>

#include <cntdef.h> // for tcontactitemid.

_LIT(KContactsIniFileName, "CntModel.ini");

class CCntDbManagerController;
class CCntServerCurrentItemMap;
class CCntServerSpeedDialManager;


/**
The CIniFileManager class is responsible for storing and retreiving information
to/from the initialisation file.  Data items such as the Current Item, Current
Database and Speed Dials are stored in this file.
*/
class CIniFileManager : public CTimer
	{
public:
	/**
	Binary flags to select streams to save.
	*/
	enum TSaveType { 
		/** Save all streams. */
		ESaveAll = KMaxTUint,
		/** Save Current Item. */
		ESaveCurrentItem = 0x0001,
		/** Save Current Database. */
		ESaveCurrentDatabase = 0x0002,
		/** Save Speed Dials. */
		ESaveSpeedDials = 0x0004,
		/** Save default database drive. */
		ESaveDefaultDbDrive = 0x0008,
		};

public:
	static CIniFileManager* NewL(RFs& aFs, CCntDbManagerController& aDbMgrCtrlr);
	~CIniFileManager();

	TContactItemId CurrentItem(const TDesC& aDatabase) const;
	void SetCurrentItemForDatabaseL(const TDesC& aDatabase, TContactItemId aContactId);
	void RemoveCurrentItemL(const TDesC& aDatabase);
	void SetCurrentItemL(const TDesC& aDatabase, TContactItemId aNewCurrentItem);
	const TDesC& CurrentDb() const;
	void SetCurrentDb(const TDesC& aDb);
	CCntServerSpeedDialManager& SpeedDialManager();	

	void RetryStoreOperation();
	void SaveIniFileSettingsIfRequestedL();

	// During a backup/restore operation schedule saving till later.
	void ScheduleSaveIniFileSettings(TInt aSaveFlags, TBool aReplace=EFalse);

	TInt StartRestoreIniFileSettings();
	void RequestRestoreIniFileSettingsL();
	
	void GetIniFileNameL(TDes& aFileName, TBool aIncPrivatePath=ETrue);
	void SetDefaultDatabaseDrive(TDriveUnit aDriveUnit, TBool aDriveSet=ETrue);
	TBool& DatabaseDriveSet();	

private:
	CIniFileManager(RFs& aFs, CCntDbManagerController& aDbMgrCtrlr);
	void ConstructL();

	void RunL();
	TInt RunError(TInt aError);

	void RestoreIniFileSettingsL();
	void SaveIniFileSettingsL(TInt aSaveFlags, TBool aReplace);
	CDictionaryFileStore* IniFileStoreLC(TFileName& aIniFile);
	void RestoreCurrentDatabaseL(CDictionaryFileStore& aStore);
	void RestoreDefaultDbDriveL(CDictionaryFileStore& aStore);
	void StoreCurrentDatabaseL(CDictionaryFileStore& aStore);
	void StoreDefaultDbDriveL(CDictionaryFileStore& aStore);
	
private:
	/**
	Internal flags.
	*/
	enum TBackupFlags
		{
		ENoSaveRestore,
		/** Indicates restoring data from initialisation file. */
		EIsRestoring,
		/** There is a need to save data to the initialisation file.  If RunL()
		sees this flag it will try to save to file, and retry a number of times
		if an error is encountered. */
		ERequestSave
		};
	
private:
	RFs& iFs;
	CCntDbManagerController& iDbMgrCtrlr;
	TBackupFlags iBackupFlag;
	TInt iSaveType;
	TBool iReplace;
	CCntServerCurrentItemMap* iCurrentItemMap;
	CCntServerSpeedDialManager* iSpeedDialManager;
	TFileName	iCurrentDb;
	TBool		iDatabaseDriveSet;
	TDriveUnit	iDefaultDriveUnit;
	};

	
#endif //__CINIFILEMANAGER_H__