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