1 /* |
|
2 * Copyright (c) 2008 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 #ifndef __CREATORVIRTUALPHONEBOOK_H__ |
|
22 #define __CREATORVIRTUALPHONEBOOK_H__ |
|
23 |
|
24 #include "creator_model.h" |
|
25 #include "creator_phonebookbase.h" |
|
26 #include "creator_randomdatafield.h" |
|
27 |
|
28 #include <e32base.h> |
|
29 #include <cntdef.h> |
|
30 #include <cntdb.h> |
|
31 #include <cntitem.h> |
|
32 #include <cntfldst.h> |
|
33 #include <cntview.h> |
|
34 #include <CVPbkContactManager.h> |
|
35 #include <PbkFields.hrh> |
|
36 #include <CPbk2ImageManager.h> |
|
37 #include <MVPbkContactStoreListObserver.h> |
|
38 #include <MVPbkBatchOperationObserver.h> |
|
39 #include <MVPbkContactFindObserver.h> |
|
40 #include <MVPbkContactObserver.h> |
|
41 #include <MPbk2ImageOperationObservers.h> |
|
42 #include <VPbkEng.rsg> |
|
43 #include <CVPbkContactLinkArray.h> |
|
44 #include <MVPbkContactViewObserver.h> |
|
45 |
|
46 class CCreatorEngine; |
|
47 class CCreatorModuleBaseParameters; |
|
48 |
|
49 class MVPbkStoreContact; |
|
50 class MVPbkContactStore; |
|
51 class CAsyncWaiter; |
|
52 class CContactDatabase; |
|
53 class MVPbkContactLinkArray; |
|
54 class CVirtualPhonebookParameters; |
|
55 |
|
56 |
|
57 class CCreatorVirtualPhonebook : public CCreatorPhonebookBase, |
|
58 public MVPbkContactStoreListObserver, public MVPbkBatchOperationObserver, |
|
59 public MVPbkContactFindObserver, public MVPbkContactObserver, public MPbk2ImageSetObserver, |
|
60 public MVPbkSingleContactOperationObserver, public MVPbkContactViewObserver |
|
61 { |
|
62 public: |
|
63 static CCreatorVirtualPhonebook* NewL(CCreatorEngine* aEngine); |
|
64 static CCreatorVirtualPhonebook* NewLC(CCreatorEngine* aEngine); |
|
65 ~CCreatorVirtualPhonebook(); |
|
66 |
|
67 private: |
|
68 CCreatorVirtualPhonebook(); |
|
69 void ConstructL(CCreatorEngine* aEngine); // from MCreatorModuleBase |
|
70 |
|
71 public: |
|
72 virtual TBool AskDataFromUserL(TInt aCommand, TInt& aNumberOfEntries); |
|
73 TInt CreateContactEntryL(CCreatorModuleBaseParameters *aParameters); |
|
74 TInt CreateGroupEntryL(CCreatorModuleBaseParameters *aParameters); |
|
75 TInt CreateSubscribedContactEntryL(CCreatorModuleBaseParameters *aParameters); |
|
76 |
|
77 void AddFieldToContactItemL(MVPbkStoreContact& aItem, TPbkFieldId aFieldId, const TDesC& aFieldText); |
|
78 void AddFieldToContactItemL(MVPbkStoreContact& aItem, TPbkFieldId aFieldId, const TDesC8& aFieldText); |
|
79 void AddFieldToContactItemL(MVPbkStoreContact& aItem, TPbkFieldId aFieldId, const TTime& aFieldText); |
|
80 |
|
81 void AddImageToContactL(MVPbkStoreContact& aContact, TInt aFieldResId, const TDesC& aFileName); |
|
82 TBool IsActive(); |
|
83 void CancelOperation(); |
|
84 void DeleteAllL(); |
|
85 void DeleteAllCreatedByCreatorL(); |
|
86 void DeleteAllGroupsL(); |
|
87 void DeleteAllGroupsCreatedByCreatorL(); |
|
88 |
|
89 private: |
|
90 void CompactPbkDatabaseL(TBool aCompressImmediately=EFalse); |
|
91 void AddFieldToParamsL(TInt aFieldType, const TDesC& aData); |
|
92 void AddFieldToParamsL(TInt aFieldType, const TDesC8& aData); |
|
93 void AddFieldToParamsL(TInt aFieldType, const TTime& aData); |
|
94 void InitializeContactParamsL(/*CCreatorModuleBaseParameters* aParameters*/); |
|
95 TBool IsContactGroupL(const MVPbkContactLink& aLink); |
|
96 void StoreLinksForDeleteL( MVPbkContactLinkArray& aLinks, TUid aStoreUid ); |
|
97 void DeleteContactsL( MVPbkContactLinkArray* aContacts, TBool aGroup ); |
|
98 void DeleteItemsCreatedWithCreatorL( TUid aStoreUid ); |
|
99 void DoDeleteItemsCreatedWithCreatorL( TUid aStoreUid, CDictionaryFileStore* aStore ); |
|
100 TBool HasOtherThanGroupsL( MVPbkContactLinkArray* aContacts ); |
|
101 |
|
102 public: // MVPbkSingleContactOperationObserver |
|
103 |
|
104 void VPbkSingleContactOperationComplete( |
|
105 MVPbkContactOperationBase& aOperation, |
|
106 MVPbkStoreContact* aContact ); |
|
107 void VPbkSingleContactOperationFailed( |
|
108 MVPbkContactOperationBase& aOperation, |
|
109 TInt aError ); |
|
110 |
|
111 private: // MVPbkContactViewObserver |
|
112 |
|
113 void ContactViewReady( MVPbkContactViewBase& aView ); |
|
114 void ContactViewUnavailable( |
|
115 MVPbkContactViewBase& aView ); |
|
116 void ContactAddedToView( |
|
117 MVPbkContactViewBase& aView, |
|
118 TInt aIndex, |
|
119 const MVPbkContactLink& aContactLink ); |
|
120 void ContactRemovedFromView( |
|
121 MVPbkContactViewBase& aView, |
|
122 TInt aIndex, |
|
123 const MVPbkContactLink& aContactLink ); |
|
124 void ContactViewError( |
|
125 MVPbkContactViewBase& aView, |
|
126 TInt aError, |
|
127 TBool aErrorNotified ); |
|
128 |
|
129 private: |
|
130 CVPbkContactManager* iContactManager; |
|
131 TInt iOpCounter; |
|
132 |
|
133 CVirtualPhonebookParameters* iParameters; |
|
134 |
|
135 static TInt iPhoneNumberFields[]; |
|
136 static TInt iUrlFields[]; |
|
137 static TInt iEmailFields[]; |
|
138 TBool iAddAllFields; |
|
139 CVPbkContactLinkArray* iContactLinkArray; |
|
140 CVPbkContactLinkArray* iContactsToDelete; |
|
141 CVPbkContactLinkArray* iContactGroupsToDelete; |
|
142 RPointerArray<MVPbkContactLinkArray> iPreviousDeleteLinks; |
|
143 |
|
144 private: |
|
145 //new variables |
|
146 /// Ref: the target of the copy |
|
147 MVPbkContactStore* iStore; |
|
148 |
|
149 CAsyncWaiter* iWaiter; |
|
150 |
|
151 /// Own: Contact database for this store |
|
152 CContactDatabase* iContactDb; |
|
153 |
|
154 //Contacts found in contacts db. |
|
155 MVPbkContactLinkArray* iContactResults; |
|
156 // Contact groups that are found in the store. These are used in filtering |
|
157 // the groups from the find results. |
|
158 MVPbkContactLinkArray* iContactGroupsInStore; |
|
159 |
|
160 // Phonebook asynchronous operation |
|
161 MVPbkContactOperationBase* iOperation; |
|
162 |
|
163 // Flag to indicate whether it is required to notify |
|
164 // iEngine after operation is complete. This happens |
|
165 // when user has cancelled the operation during |
|
166 // iOperation exists. |
|
167 TBool iCancelCbRequested; |
|
168 |
|
169 TInt iLastError; |
|
170 |
|
171 public: |
|
172 //Observer implentation from MVPbkContactStoreListObserver |
|
173 void OpenComplete(); |
|
174 |
|
175 //observer implentation from MVPbkContactStoreObserver |
|
176 |
|
177 void StoreReady(MVPbkContactStore& aContactStore); |
|
178 |
|
179 void StoreUnavailable(MVPbkContactStore& aContactStore, |
|
180 TInt aReason); |
|
181 |
|
182 void HandleStoreEventL( |
|
183 MVPbkContactStore& aContactStore, |
|
184 TVPbkContactStoreEvent aStoreEvent); |
|
185 |
|
186 TAny* ContactStoreObserverExtension(TUid aExtensionUid); |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 public: |
|
193 //Observer implementation for MVPbkBatchOperationObserver |
|
194 |
|
195 void StepComplete( |
|
196 MVPbkContactOperationBase& aOperation, |
|
197 TInt aStepSize ); |
|
198 |
|
199 TBool StepFailed( |
|
200 MVPbkContactOperationBase& aOperation, |
|
201 TInt aStepSize, TInt aError ); |
|
202 |
|
203 void OperationComplete( |
|
204 MVPbkContactOperationBase& aOperation ); |
|
205 |
|
206 TAny* BatchOperationObserverExtension( |
|
207 TUid aExtensionUid ) ; |
|
208 |
|
209 |
|
210 //-------------------------------------------- |
|
211 //Observer implementation for MVPbkContactFindObserver |
|
212 public: // Interface |
|
213 |
|
214 void FindCompleteL( MVPbkContactLinkArray* aResults ); |
|
215 |
|
216 void FindFailed( TInt aError ); |
|
217 |
|
218 TAny* ContactFindObserverExtension( |
|
219 TUid aExtensionUid ); |
|
220 |
|
221 |
|
222 |
|
223 //-------------------------------------------- |
|
224 //Observer implementation for MVPbkContactObserver |
|
225 |
|
226 public: |
|
227 void ContactOperationCompleted(TContactOpResult aResult); |
|
228 |
|
229 void ContactOperationFailed |
|
230 (TContactOp aOpCode, TInt aErrorCode, TBool aErrorNotified); |
|
231 |
|
232 TAny* ContactObserverExtension(TUid aExtensionUid) ; |
|
233 //~MVPbkContactObserver(); |
|
234 |
|
235 //-------------------------------------------- |
|
236 // Implementation of MPbk2ImageSetObserver: |
|
237 public: |
|
238 void Pbk2ImageSetComplete(MPbk2ImageOperation& aOperation); |
|
239 void Pbk2ImageSetFailed(MPbk2ImageOperation& aOperation, TInt aError ); |
|
240 }; |
|
241 |
|
242 class CCreatorContactFieldImpl; |
|
243 class CCreatorContactField : public CBase, public MCreatorRandomDataField |
|
244 { |
|
245 public: |
|
246 static CCreatorContactField* NewL(TInt aFieldType, const TDesC& aData); |
|
247 static CCreatorContactField* NewL(TInt aFieldType, const TDesC8& aData); |
|
248 static CCreatorContactField* NewL(TInt aFieldType, const TTime& aData); |
|
249 |
|
250 static CCreatorContactField* NewL(TInt aFieldType, TRandomLengthType aRandomLenType, TInt aRandomLen); |
|
251 |
|
252 ~CCreatorContactField(); |
|
253 TInt FieldType(); |
|
254 virtual void AddToContactL(CCreatorEngine* aEngine, MVPbkStoreContact& aContact, CCreatorVirtualPhonebook* aVPbk); |
|
255 virtual void SetRandomParametersL( MCreatorRandomDataField::TRandomLengthType aRandomLenType = MCreatorRandomDataField::ERandomLengthDefault, |
|
256 TInt aRandomLen = 0 ); |
|
257 virtual void ParseL(CCommandParser* parser); |
|
258 |
|
259 private: |
|
260 CCreatorContactField(); |
|
261 void ConstructL(TInt aFieldType, const TDesC& aData); |
|
262 void ConstructL(TInt aFieldType, const TDesC8& aData); |
|
263 void ConstructL(TInt aFieldType, const TTime& aData); |
|
264 CCreatorContactFieldImpl* pImpl; |
|
265 }; |
|
266 |
|
267 |
|
268 /** |
|
269 * Virtual phonebook parameters |
|
270 */ |
|
271 |
|
272 |
|
273 class CVirtualPhonebookParameters : public CCreatorModuleBaseParameters |
|
274 { |
|
275 public: |
|
276 void ParseL(CCommandParser* parser, TParseParams /*aCase = 0*/); |
|
277 |
|
278 TInt CVirtualPhonebookParameters::ScriptLinkId() const; |
|
279 void CVirtualPhonebookParameters::SetScriptLinkId(TInt aLinkId); |
|
280 RPointerArray<CCreatorContactField> iContactFields; |
|
281 |
|
282 HBufC* iGroupName; |
|
283 TInt iContactsInGroup; |
|
284 TInt iNumberOfPhoneNumberFields; |
|
285 TInt iNumberOfURLFields; |
|
286 TInt iNumberOfEmailAddressFields; |
|
287 TInt iContactSetPtr; |
|
288 RArray<TLinkIdParam> iLinkIds; // For contactgroup. Stores the linked contact ids. |
|
289 |
|
290 public: |
|
291 CVirtualPhonebookParameters(); |
|
292 ~CVirtualPhonebookParameters(); |
|
293 |
|
294 private: |
|
295 TInt iLinkId; // For contact. Stores the contact id |
|
296 }; |
|
297 |
|
298 |
|
299 |
|
300 #endif // __CREATORVIRTUALPHONEBOOK_H__ |
|