1 /* |
|
2 * Copyright (c) 2010 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 |
|
22 #ifndef __CREATORVIRTUALPHONEBOOK_H__ |
|
23 #define __CREATORVIRTUALPHONEBOOK_H__ |
|
24 |
|
25 #include "engine.h" |
|
26 #include "creator_phonebookbase.h" |
|
27 #include "creator_randomdatafield.h" |
|
28 |
|
29 #include <e32base.h> |
|
30 #include <cntdef.h> |
|
31 #include <cntdb.h> |
|
32 #include <cntitem.h> |
|
33 #include <cntfldst.h> |
|
34 #include <cntview.h> |
|
35 #include <cvpbkcontactmanager.h> |
|
36 #include <pbkfields.hrh> |
|
37 #include <cpbk2imagemanager.h> |
|
38 #include <mvpbkcontactstorelistobserver.h> |
|
39 #include <mvpbkbatchoperationobserver.h> |
|
40 #include <mvpbkcontactfindobserver.h> |
|
41 #include <mvpbkcontactobserver.h> |
|
42 #include <mpbk2imageoperationobservers.h> |
|
43 #include <vpbkeng.rsg> |
|
44 #include <cvpbkcontactlinkarray.h> |
|
45 #include <MVPbkContactViewObserver.h> |
|
46 |
|
47 class CCreatorEngine; |
|
48 class CCreatorModuleBaseParameters; |
|
49 |
|
50 class MVPbkStoreContact; |
|
51 class MVPbkContactStore; |
|
52 class CAsyncWaiter; |
|
53 class CContactDatabase; |
|
54 class MVPbkContactLinkArray; |
|
55 class CVirtualPhonebookParameters; |
|
56 |
|
57 |
|
58 class CCreatorVirtualPhonebook : public CCreatorPhonebookBase, |
|
59 public MVPbkContactStoreListObserver, public MVPbkBatchOperationObserver, |
|
60 public MVPbkContactFindObserver, public MVPbkContactObserver, public MPbk2ImageSetObserver, |
|
61 public MVPbkSingleContactOperationObserver, public MVPbkContactViewObserver |
|
62 { |
|
63 public: |
|
64 static CCreatorVirtualPhonebook* NewL(CCreatorEngine* aEngine); |
|
65 static CCreatorVirtualPhonebook* NewLC(CCreatorEngine* aEngine); |
|
66 ~CCreatorVirtualPhonebook(); |
|
67 |
|
68 private: |
|
69 CCreatorVirtualPhonebook(); |
|
70 void ConstructL(CCreatorEngine* aEngine); // from MCreatorModuleBase |
|
71 |
|
72 public: |
|
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 CVPbkContactLinkArray* iContactLinkArray; |
|
139 CVPbkContactLinkArray* iContactsToDelete; |
|
140 CVPbkContactLinkArray* iContactGroupsToDelete; |
|
141 RPointerArray<MVPbkContactLinkArray> iPreviousDeleteLinks; |
|
142 |
|
143 private: |
|
144 //new variables |
|
145 /// Ref: the target of the copy |
|
146 MVPbkContactStore* iStore; |
|
147 |
|
148 CAsyncWaiter* iWaiter; |
|
149 |
|
150 /// Own: Contact database for this store |
|
151 CContactDatabase* iContactDb; |
|
152 |
|
153 //Contacts found in contacts db. |
|
154 MVPbkContactLinkArray* iContactResults; |
|
155 // Contact groups that are found in the store. These are used in filtering |
|
156 // the groups from the find results. |
|
157 MVPbkContactLinkArray* iContactGroupsInStore; |
|
158 |
|
159 // Phonebook asynchronous operation |
|
160 MVPbkContactOperationBase* iOperation; |
|
161 |
|
162 // Flag to indicate whether it is required to notify |
|
163 // iEngine after operation is complete. This happens |
|
164 // when user has cancelled the operation during |
|
165 // iOperation exists. |
|
166 TBool iCancelCbRequested; |
|
167 |
|
168 public: |
|
169 //Observer implentation from MVPbkContactStoreListObserver |
|
170 void OpenComplete(); |
|
171 |
|
172 //observer implentation from MVPbkContactStoreObserver |
|
173 |
|
174 void StoreReady(MVPbkContactStore& aContactStore); |
|
175 |
|
176 void StoreUnavailable(MVPbkContactStore& aContactStore, |
|
177 TInt aReason); |
|
178 |
|
179 void HandleStoreEventL( |
|
180 MVPbkContactStore& aContactStore, |
|
181 TVPbkContactStoreEvent aStoreEvent); |
|
182 |
|
183 TAny* ContactStoreObserverExtension(TUid aExtensionUid); |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 public: |
|
190 //Observer implementation for MVPbkBatchOperationObserver |
|
191 |
|
192 void StepComplete( |
|
193 MVPbkContactOperationBase& aOperation, |
|
194 TInt aStepSize ); |
|
195 |
|
196 TBool StepFailed( |
|
197 MVPbkContactOperationBase& aOperation, |
|
198 TInt aStepSize, TInt aError ); |
|
199 |
|
200 void OperationComplete( |
|
201 MVPbkContactOperationBase& aOperation ); |
|
202 |
|
203 TAny* BatchOperationObserverExtension( |
|
204 TUid aExtensionUid ) ; |
|
205 |
|
206 |
|
207 //-------------------------------------------- |
|
208 //Observer implementation for MVPbkContactFindObserver |
|
209 public: // Interface |
|
210 |
|
211 void FindCompleteL( MVPbkContactLinkArray* aResults ); |
|
212 |
|
213 void FindFailed( TInt aError ); |
|
214 |
|
215 TAny* ContactFindObserverExtension( |
|
216 TUid aExtensionUid ); |
|
217 |
|
218 |
|
219 |
|
220 //-------------------------------------------- |
|
221 //Observer implementation for MVPbkContactObserver |
|
222 |
|
223 public: |
|
224 void ContactOperationCompleted(TContactOpResult aResult); |
|
225 |
|
226 void ContactOperationFailed |
|
227 (TContactOp aOpCode, TInt aErrorCode, TBool aErrorNotified); |
|
228 |
|
229 TAny* ContactObserverExtension(TUid aExtensionUid) ; |
|
230 //~MVPbkContactObserver(); |
|
231 |
|
232 //-------------------------------------------- |
|
233 // Implementation of MPbk2ImageSetObserver: |
|
234 public: |
|
235 void Pbk2ImageSetComplete(MPbk2ImageOperation& aOperation); |
|
236 void Pbk2ImageSetFailed(MPbk2ImageOperation& aOperation, TInt aError ); |
|
237 }; |
|
238 |
|
239 class CCreatorContactFieldImpl; |
|
240 class CCreatorContactField : public CBase, public MCreatorRandomDataField |
|
241 { |
|
242 public: |
|
243 static CCreatorContactField* NewL(TInt aFieldType, const TDesC& aData); |
|
244 static CCreatorContactField* NewL(TInt aFieldType, const TDesC8& aData); |
|
245 static CCreatorContactField* NewL(TInt aFieldType, const TTime& aData); |
|
246 |
|
247 static CCreatorContactField* NewL(TInt aFieldType, TRandomLengthType aRandomLenType, TInt aRandomLen); |
|
248 |
|
249 ~CCreatorContactField(); |
|
250 TInt FieldType(); |
|
251 virtual void AddToContactL(CCreatorEngine* aEngine, MVPbkStoreContact& aContact, CCreatorVirtualPhonebook* aVPbk); |
|
252 virtual void SetRandomParametersL( MCreatorRandomDataField::TRandomLengthType aRandomLenType = MCreatorRandomDataField::ERandomLengthDefault, |
|
253 TInt aRandomLen = 0 ); |
|
254 virtual void ParseL(CCommandParser* parser); |
|
255 |
|
256 private: |
|
257 CCreatorContactField(); |
|
258 void ConstructL(TInt aFieldType, const TDesC& aData); |
|
259 void ConstructL(TInt aFieldType, const TDesC8& aData); |
|
260 void ConstructL(TInt aFieldType, const TTime& aData); |
|
261 CCreatorContactFieldImpl* pImpl; |
|
262 }; |
|
263 |
|
264 |
|
265 /** |
|
266 * Virtual phonebook parameters |
|
267 */ |
|
268 |
|
269 |
|
270 class CVirtualPhonebookParameters : public CCreatorModuleBaseParameters |
|
271 { |
|
272 public: |
|
273 void ParseL(CCommandParser* parser, TParseParams /*aCase = 0*/); |
|
274 |
|
275 TInt CVirtualPhonebookParameters::ScriptLinkId() const; |
|
276 void CVirtualPhonebookParameters::SetScriptLinkId(TInt aLinkId); |
|
277 RPointerArray<CCreatorContactField> iContactFields; |
|
278 |
|
279 HBufC* iGroupName; |
|
280 TInt iContactsInGroup; |
|
281 TInt iNumberOfPhoneNumberFields; |
|
282 TInt iNumberOfURLFields; |
|
283 TInt iNumberOfEmailAddressFields; |
|
284 TInt iContactSetPtr; |
|
285 RArray<TLinkIdParam> iLinkIds; // For contactgroup. Stores the linked contact ids. |
|
286 |
|
287 public: |
|
288 CVirtualPhonebookParameters(); |
|
289 ~CVirtualPhonebookParameters(); |
|
290 |
|
291 private: |
|
292 TInt iLinkId; // For contact. Stores the contact id |
|
293 }; |
|
294 |
|
295 |
|
296 |
|
297 #endif // __CREATORVIRTUALPHONEBOOK_H__ |
|