|
1 /** |
|
2 * Copyright (c) 2005-2009 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 @released |
|
24 */ |
|
25 |
|
26 |
|
27 #ifndef __CINIFILEMANAGER_H__ |
|
28 #define __CINIFILEMANAGER_H__ |
|
29 |
|
30 #include <e32base.h> |
|
31 #include <s32file.h> |
|
32 |
|
33 #include <cntdef.h> // for tcontactitemid. |
|
34 |
|
35 _LIT(KContactsIniFileName, "CntModel.ini"); |
|
36 |
|
37 class CCntDbManagerController; |
|
38 class CCntServerCurrentItemMap; |
|
39 class CCntServerSpeedDialManager; |
|
40 |
|
41 |
|
42 /** |
|
43 The CIniFileManager class is responsible for storing and retreiving information |
|
44 to/from the initialisation file. Data items such as the Current Item, Current |
|
45 Database and Speed Dials are stored in this file. |
|
46 */ |
|
47 class CIniFileManager : public CTimer |
|
48 { |
|
49 public: |
|
50 /** |
|
51 Binary flags to select streams to save. |
|
52 */ |
|
53 enum TSaveType { |
|
54 /** Save all streams. */ |
|
55 ESaveAll = KMaxTUint, |
|
56 /** Save Current Item. */ |
|
57 ESaveCurrentItem = 0x0001, |
|
58 /** Save Current Database. */ |
|
59 ESaveCurrentDatabase = 0x0002, |
|
60 /** Save Speed Dials. */ |
|
61 ESaveSpeedDials = 0x0004, |
|
62 /** Save default database drive. */ |
|
63 ESaveDefaultDbDrive = 0x0008, |
|
64 }; |
|
65 |
|
66 public: |
|
67 static CIniFileManager* NewL(RFs& aFs, CCntDbManagerController& aDbMgrCtrlr); |
|
68 ~CIniFileManager(); |
|
69 |
|
70 TContactItemId CurrentItem(const TDesC& aDatabase) const; |
|
71 void SetCurrentItemForDatabaseL(const TDesC& aDatabase, TContactItemId aContactId); |
|
72 void RemoveCurrentItemL(const TDesC& aDatabase); |
|
73 void SetCurrentItemL(const TDesC& aDatabase, TContactItemId aNewCurrentItem); |
|
74 const TDesC& CurrentDb() const; |
|
75 void SetCurrentDb(const TDesC& aDb); |
|
76 CCntServerSpeedDialManager& SpeedDialManager(); |
|
77 |
|
78 void RetryStoreOperation(); |
|
79 void SaveIniFileSettingsIfRequestedL(); |
|
80 |
|
81 // During a backup/restore operation schedule saving till later. |
|
82 void ScheduleSaveIniFileSettings(TInt aSaveFlags, TBool aReplace=EFalse); |
|
83 |
|
84 TInt StartRestoreIniFileSettings(); |
|
85 void RequestRestoreIniFileSettingsL(); |
|
86 |
|
87 void GetIniFileNameL(TDes& aFileName, TBool aIncPrivatePath=ETrue); |
|
88 void SetDefaultDatabaseDrive(TDriveUnit aDriveUnit, TBool aDriveSet=ETrue); |
|
89 TBool& DatabaseDriveSet(); |
|
90 |
|
91 private: |
|
92 CIniFileManager(RFs& aFs, CCntDbManagerController& aDbMgrCtrlr); |
|
93 void ConstructL(); |
|
94 |
|
95 void RunL(); |
|
96 TInt RunError(TInt aError); |
|
97 |
|
98 void RestoreIniFileSettingsL(); |
|
99 void SaveIniFileSettingsL(TInt aSaveFlags, TBool aReplace); |
|
100 CDictionaryFileStore* IniFileStoreLC(TFileName& aIniFile); |
|
101 void RestoreCurrentDatabaseL(CDictionaryFileStore& aStore); |
|
102 void RestoreDefaultDbDriveL(CDictionaryFileStore& aStore); |
|
103 void StoreCurrentDatabaseL(CDictionaryFileStore& aStore); |
|
104 void StoreDefaultDbDriveL(CDictionaryFileStore& aStore); |
|
105 |
|
106 private: |
|
107 /** |
|
108 Internal flags. |
|
109 */ |
|
110 enum TBackupFlags |
|
111 { |
|
112 ENoSaveRestore, |
|
113 /** Indicates restoring data from initialisation file. */ |
|
114 EIsRestoring, |
|
115 /** There is a need to save data to the initialisation file. If RunL() |
|
116 sees this flag it will try to save to file, and retry a number of times |
|
117 if an error is encountered. */ |
|
118 ERequestSave |
|
119 }; |
|
120 |
|
121 private: |
|
122 RFs& iFs; |
|
123 CCntDbManagerController& iDbMgrCtrlr; |
|
124 TBackupFlags iBackupFlag; |
|
125 TInt iSaveType; |
|
126 TBool iReplace; |
|
127 CCntServerCurrentItemMap* iCurrentItemMap; |
|
128 CCntServerSpeedDialManager* iSpeedDialManager; |
|
129 TFileName iCurrentDb; |
|
130 TBool iDatabaseDriveSet; |
|
131 TDriveUnit iDefaultDriveUnit; |
|
132 }; |
|
133 |
|
134 |
|
135 #endif //__CINIFILEMANAGER_H__ |