|
1 /* |
|
2 * Copyright (c) 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: Predefined contacts engine (state machine) |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef C_PDCENGINE_H |
|
19 #define C_PDCENGINE_H |
|
20 |
|
21 // System includes |
|
22 #include <e32std.h> //for iErrorArray |
|
23 #include <e32base.h> // CActive |
|
24 #include <f32file.h> // RFs |
|
25 #include <MVPbkContactStoreObserver.h> // MVPbkContactStoreObserver |
|
26 #include <flogger.h> |
|
27 |
|
28 // Forward declarations |
|
29 class CVPbkContactManager; |
|
30 class CPdcVCardImporter; |
|
31 class CPdcXmlImporter; |
|
32 class CPdcData; |
|
33 class MVPbkContactStore; |
|
34 class CVPbkContactLinkArray; |
|
35 class CPdcContactDeletion; |
|
36 |
|
37 /** |
|
38 * Predefined Contacts engine |
|
39 * This class as a state machine for the reading of the |
|
40 * predefined contacts from file, and adding the |
|
41 * contacts to the contacts database by the delegation of |
|
42 * the tasks to the relevent classes. |
|
43 */ |
|
44 NONSHARABLE_CLASS( CPdcEngine ): public CActive, |
|
45 public MVPbkContactStoreObserver |
|
46 { |
|
47 public: |
|
48 /** |
|
49 * Current state of the engine is |
|
50 * represented by an enumeration. |
|
51 */ |
|
52 enum TPdcEngineState |
|
53 { |
|
54 EOpeningContacts, |
|
55 EDeleteOldContacts, |
|
56 EGettingFileLocation, |
|
57 EReadingVCards, |
|
58 EReadingXML, |
|
59 EUpdateData, |
|
60 EDeleteStoredContact, |
|
61 EFinish |
|
62 }; |
|
63 |
|
64 public: |
|
65 /** |
|
66 * Symbian 1st phase constructor |
|
67 * @return Self pointer to CPdcEngine pushed to |
|
68 * the cleanup stack. |
|
69 */ |
|
70 static CPdcEngine* NewLC(); |
|
71 |
|
72 /** |
|
73 * Destructor. |
|
74 */ |
|
75 virtual ~CPdcEngine(); |
|
76 |
|
77 public: |
|
78 /** |
|
79 * Checks if the predefined contacts need to be added. |
|
80 * @return ETrue if the predefined contacts need to be added |
|
81 */ |
|
82 TBool PredefinedContactsNeedAddingL(); |
|
83 |
|
84 /** |
|
85 * Starts the asyncronous process of reading and adding the |
|
86 * predefined contacts to the contact model |
|
87 */ |
|
88 void AddPredefinedContactsL(); |
|
89 |
|
90 /** |
|
91 * Starts the asyncronous process of reading and adding the |
|
92 * predefined contacts to the contact model |
|
93 * @param aStatus TRequestStatus of caller (called by ECom |
|
94 * plugin starting mechanism. |
|
95 */ |
|
96 void AddPredefinedContactsL( TRequestStatus& aStatus ); |
|
97 |
|
98 private: // C++ constructor and the Symbian second-phase constructor |
|
99 CPdcEngine(); |
|
100 void ConstructL(); |
|
101 |
|
102 private: // private member functions |
|
103 void SelfComplete(); |
|
104 |
|
105 void DeleteContactsL(); |
|
106 void GetFileLocationL(); |
|
107 void ReadVCardsL(); |
|
108 void ReadXmlL(); |
|
109 void UpdateDataL(); |
|
110 void Finish( TInt aError ); |
|
111 |
|
112 void DisplayErrorNoteL( TInt aError, TInt aErrorPosition, |
|
113 TBool errorCannotReserve ); |
|
114 |
|
115 /** |
|
116 *CPdcEngine::DeleteStoredContactsL |
|
117 * Called when error occur iwhile reading XML or vcard file. |
|
118 */ |
|
119 void DeleteStoredContactsL(); |
|
120 |
|
121 private: // From CActive |
|
122 void DoCancel(); |
|
123 void RunL(); |
|
124 TInt RunError( TInt aError ); |
|
125 |
|
126 private: // from MVPbkContactStoreObserver |
|
127 void StoreReady( MVPbkContactStore& aContactStore ); |
|
128 void StoreUnavailable( MVPbkContactStore& aContactStore, TInt aReason ); |
|
129 void HandleStoreEventL( MVPbkContactStore& aContactStore, |
|
130 TVPbkContactStoreEvent aStoreEvent ); |
|
131 |
|
132 private: // data |
|
133 /// Current state of engine |
|
134 TPdcEngineState iEngineState; |
|
135 /// File system |
|
136 RFs iFs; |
|
137 /// Own: Contact manager |
|
138 CVPbkContactManager* iContactManager; |
|
139 /// Own: Contact store |
|
140 MVPbkContactStore* iContactStore; |
|
141 /// Own: directory containing predefined contacts |
|
142 HBufC* iFileDirectory; |
|
143 /// Own: vCard importer |
|
144 CPdcVCardImporter* iVCardImporter; |
|
145 /// Own: Xml importer |
|
146 CPdcXmlImporter* iXmlImporter; |
|
147 /// Own: Data checker |
|
148 CPdcData* iPdcData; |
|
149 /// Own: Ids of the contacts that have been added |
|
150 CVPbkContactLinkArray* iLinkArray; |
|
151 /// Own: Contact bulk deleter |
|
152 CPdcContactDeletion* iContactDeleter; |
|
153 /// Ref: TRequestStatus of caller |
|
154 TRequestStatus* iCallerStatus; |
|
155 /// Judge the type of deletion operator |
|
156 TBool iDeletedStoredContact; |
|
157 }; |
|
158 |
|
159 #endif // C_PDCENGINE_H |