|
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 the License "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 #include "contactiter.h" |
|
21 #include "contactretrieveobserver.h" |
|
22 #include "contactservice.hrh" |
|
23 #include "getliststorelistobserver.h" |
|
24 #include <CVPbkContactStoreUriArray.h> |
|
25 #include <CVPbkContactManager.h> |
|
26 #include <mvpbkcontactstorelist.h> |
|
27 #include <MVPbkContactOperationBase.h> |
|
28 #include <TVPbkContactStoreUriPtr.h> |
|
29 #include <MVPbkContactLink.h> |
|
30 #include <mvpbkcontactstoreproperties.h> |
|
31 |
|
32 |
|
33 //Initialize the class variable with the result of ReadContactL |
|
34 void CContactIter::SetContactFetchResult(MVPbkStoreContact* aContact) |
|
35 { |
|
36 iContact = aContact; |
|
37 } |
|
38 |
|
39 |
|
40 /** |
|
41 * Set the class variables with the parameters sent from CContactViewObserver |
|
42 */ |
|
43 TInt CContactIter::SetParams(MVPbkContactLinkArray * aContactLinkArray, |
|
44 const TDesC& aStoreUri, |
|
45 TOrder aSortOrder, |
|
46 TInt aTransId, |
|
47 Ttype aIndicator, |
|
48 CContactService* aContactService) |
|
49 { |
|
50 TInt retVal = KErrNone; |
|
51 |
|
52 iContactLinkArray =aContactLinkArray; |
|
53 iCount = aContactLinkArray->Count(); |
|
54 |
|
55 iStoreUri = &aStoreUri; |
|
56 iSortOrder = aSortOrder; |
|
57 iTransId = aTransId; |
|
58 iIndicator = aIndicator; |
|
59 iContactService = aContactService; |
|
60 TRAPD(error, SetupEnvironL()); |
|
61 if(error != KErrNone) |
|
62 { |
|
63 retVal = error; |
|
64 } |
|
65 return retVal; |
|
66 } |
|
67 |
|
68 |
|
69 void CContactIter::SetupEnvironL() |
|
70 { |
|
71 if((iIndicator == EContacts) && (iContactLinkArray->Count() == 1)) |
|
72 { |
|
73 iStoreUri = &(iContactLinkArray->At(0).ContactStore().StoreProperties().Uri().UriDes()); |
|
74 } |
|
75 |
|
76 iSyncIter = CContactSyncIter::NewL(); |
|
77 SetupDBL(); |
|
78 } |
|
79 /* |
|
80 * NextL Function gets the next contact/group in the linkarray. |
|
81 * Based on the Ascending/Desending order chosen the links are read in that order |
|
82 */ |
|
83 |
|
84 EXPORT_C void CContactIter::NextL(CSingleContact*& aSingleContact, HBufC8*& aContactID ) |
|
85 { |
|
86 |
|
87 MVPbkContactLink* link = NULL; |
|
88 // Create the instance of CContactSyncIter class , |
|
89 // which has methods for making the iterator synchronous |
|
90 |
|
91 if((iCount>=1) && (iCursor < (iCount-1)) && (iSortOrder == EAsc)) |
|
92 { |
|
93 |
|
94 //Setup the Database before reading |
|
95 |
|
96 CContactRetrieveObserver* newObserver = CContactRetrieveObserver::NewL(this); |
|
97 CleanupStack::PushL(newObserver); |
|
98 // Reads the Contact/Group info |
|
99 ReadContactL(((*iContactLinkArray)[++iCursor]), *newObserver); |
|
100 |
|
101 // for the request to be complete |
|
102 iSyncIter->Wait(); |
|
103 |
|
104 link = const_cast<MVPbkContactLink*>(&((*iContactLinkArray)[iCursor])); |
|
105 |
|
106 //Set the output param |
|
107 aSingleContact = CSingleContact::NewL(iContact, iIndicator); |
|
108 |
|
109 //Intialiaze the ContactId info using PackLC() method |
|
110 aContactID = link->PackLC(); |
|
111 aSingleContact->SetContactIdL(*aContactID); |
|
112 |
|
113 CleanupStack::Pop(aContactID); |
|
114 CleanupStack::Pop(newObserver); |
|
115 } |
|
116 else if(iSortOrder == EDesc) |
|
117 { |
|
118 if(iCursor == -1) |
|
119 { |
|
120 iCursor = iCount; |
|
121 } |
|
122 if(iCursor != 0) |
|
123 { |
|
124 //Setup the Database before reading |
|
125 |
|
126 CContactRetrieveObserver* newObserver = CContactRetrieveObserver::NewL(this); |
|
127 CleanupStack::PushL(newObserver); |
|
128 |
|
129 // Reads the Contact/Group info |
|
130 ReadContactL(((*iContactLinkArray)[--iCursor]), *newObserver); |
|
131 |
|
132 // for the request to be complete |
|
133 iSyncIter->Wait(); |
|
134 |
|
135 link = const_cast<MVPbkContactLink*>(&((*iContactLinkArray)[iCursor])); |
|
136 |
|
137 //Set the output param |
|
138 aSingleContact = CSingleContact::NewL(iContact, iIndicator); |
|
139 |
|
140 //Intialiaze the ContactId info using PackLC() method |
|
141 aContactID = link->PackLC(); |
|
142 aSingleContact->SetContactIdL(*aContactID); |
|
143 |
|
144 CleanupStack::Pop(aContactID); |
|
145 CleanupStack::Pop(newObserver); |
|
146 } |
|
147 else |
|
148 { |
|
149 aSingleContact = NULL; |
|
150 aContactID = KNullDesC8().Alloc(); |
|
151 } |
|
152 } |
|
153 else |
|
154 { |
|
155 aSingleContact = NULL; |
|
156 aContactID = KNullDesC8().Alloc(); |
|
157 } |
|
158 |
|
159 } |
|
160 |
|
161 //Method for reading the next Database name in the list of names |
|
162 EXPORT_C void CContactIter::NextL(TPtrC& aDbs) |
|
163 { |
|
164 if(iDbArray.Count()) |
|
165 { |
|
166 if((iCount>=1) && (iCursor < (iCount-1))) |
|
167 { |
|
168 aDbs.Set(*(iDbArray[++iCursor])); |
|
169 } |
|
170 else |
|
171 { |
|
172 aDbs.Set(KNullDesC); |
|
173 } |
|
174 } |
|
175 else |
|
176 { |
|
177 aDbs.Set(KNullDesC); |
|
178 } |
|
179 } |
|
180 |
|
181 //Initialises the cursor |
|
182 EXPORT_C void CContactIter::Reset() |
|
183 { |
|
184 iCursor = -1; |
|
185 } |
|
186 |
|
187 //Sets the array of databases and the number of them |
|
188 void CContactIter::SetDbNamePtr(RPointerArray<HBufC>& aArray, TInt aCnt) |
|
189 { |
|
190 iIndicator = EDatabase; |
|
191 iDbArray= aArray; |
|
192 iCount = aCnt; |
|
193 } |
|
194 |
|
195 //Sets up the database before any operation could be performed over it. |
|
196 void CContactIter::SetupDBL() |
|
197 { |
|
198 CVPbkContactStoreUriArray* uriList = CVPbkContactStoreUriArray::NewLC(); |
|
199 uriList->AppendL( TVPbkContactStoreUriPtr( *iStoreUri ) ); |
|
200 |
|
201 User::LeaveIfError( iFs.Connect() ); |
|
202 |
|
203 iContactManager = CVPbkContactManager::NewL( *uriList ,&iFs ); |
|
204 |
|
205 MVPbkContactStoreList& stores = iContactManager->ContactStoresL(); |
|
206 |
|
207 iContactStore = &( stores.At( (stores.Count())-1 ) ); |
|
208 |
|
209 TDesC16* aSearchVal = NULL; |
|
210 TDesC8* cntId = NULL; |
|
211 CContactIter* self = this; |
|
212 |
|
213 |
|
214 iGetListStoreListObserver = CGetListStoreListObserver::NewL(*iStoreUri, |
|
215 *cntId, |
|
216 *aSearchVal , |
|
217 NULL, |
|
218 ENULL, |
|
219 NULL, |
|
220 iContactService, |
|
221 self, |
|
222 EOthers, |
|
223 iTransId, |
|
224 NULL) ; |
|
225 if(iContactStore) |
|
226 { |
|
227 iContactStore->OpenL( *iGetListStoreListObserver ); |
|
228 } |
|
229 |
|
230 //Making opening Database Synchronous |
|
231 iSyncIter->Wait(); |
|
232 |
|
233 CleanupStack::PopAndDestroy(uriList); |
|
234 |
|
235 } |
|
236 |
|
237 |
|
238 // Method that will go and fetch individual contacts |
|
239 void CContactIter::ReadContactL( const MVPbkContactLink& aLink, CContactRetrieveObserver& aObserver ) |
|
240 { |
|
241 MVPbkContactOperationBase* ret = iContactManager->RetrieveContactL(aLink,aObserver); |
|
242 } |
|
243 |
|
244 |
|
245 CContactIter::CContactIter() |
|
246 { |
|
247 iCursor = iCount = -1; |
|
248 iContactLinkArray=NULL; |
|
249 iContactManager = NULL; |
|
250 } |
|
251 |
|
252 EXPORT_C CContactIter* CContactIter::NewL() |
|
253 { |
|
254 return new (ELeave) CContactIter(); |
|
255 } |
|
256 |
|
257 |
|
258 CContactIter::~CContactIter() |
|
259 { |
|
260 if(iGetListStoreListObserver) |
|
261 { |
|
262 delete iGetListStoreListObserver; |
|
263 } |
|
264 if(iContactLinkArray) |
|
265 { |
|
266 delete iContactLinkArray; |
|
267 } |
|
268 iFs.Close(); |
|
269 if(iContactManager) |
|
270 { |
|
271 delete iContactManager; |
|
272 iContactManager =NULL; |
|
273 } |
|
274 if(iSyncIter) |
|
275 { |
|
276 delete iSyncIter; |
|
277 iSyncIter = NULL; |
|
278 } |
|
279 iDbArray.ResetAndDestroy(); |
|
280 } |
|
281 |