author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:28:47 +0100 | |
branch | RCL_3 |
changeset 45 | a9c0808a1095 |
parent 23 | 50974a8b132e |
permissions | -rw-r--r-- |
5 | 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> |
|
23
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
10
diff
changeset
|
26 |
#include <MVPbkContactStoreList.h> |
5 | 27 |
#include <MVPbkContactOperationBase.h> |
28 |
#include <TVPbkContactStoreUriPtr.h> |
|
29 |
#include <MVPbkContactLink.h> |
|
23
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
10
diff
changeset
|
30 |
#include <MVPbkContactStoreProperties.h> |
5 | 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, |
|
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
224 |
NULL, |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
225 |
EGetList) ; |
5 | 226 |
if(iContactStore) |
227 |
{ |
|
228 |
iContactStore->OpenL( *iGetListStoreListObserver ); |
|
229 |
} |
|
230 |
||
231 |
//Making opening Database Synchronous |
|
232 |
iSyncIter->Wait(); |
|
233 |
||
234 |
CleanupStack::PopAndDestroy(uriList); |
|
235 |
||
236 |
} |
|
237 |
||
238 |
||
239 |
// Method that will go and fetch individual contacts |
|
240 |
void CContactIter::ReadContactL( const MVPbkContactLink& aLink, CContactRetrieveObserver& aObserver ) |
|
241 |
{ |
|
242 |
MVPbkContactOperationBase* ret = iContactManager->RetrieveContactL(aLink,aObserver); |
|
243 |
} |
|
244 |
||
245 |
||
246 |
CContactIter::CContactIter() |
|
247 |
{ |
|
248 |
iCursor = iCount = -1; |
|
249 |
iContactLinkArray=NULL; |
|
250 |
iContactManager = NULL; |
|
251 |
} |
|
252 |
||
253 |
EXPORT_C CContactIter* CContactIter::NewL() |
|
254 |
{ |
|
255 |
return new (ELeave) CContactIter(); |
|
256 |
} |
|
257 |
||
258 |
||
259 |
CContactIter::~CContactIter() |
|
260 |
{ |
|
261 |
if(iGetListStoreListObserver) |
|
262 |
{ |
|
263 |
delete iGetListStoreListObserver; |
|
264 |
} |
|
265 |
if(iContactLinkArray) |
|
266 |
{ |
|
267 |
delete iContactLinkArray; |
|
268 |
} |
|
269 |
iFs.Close(); |
|
270 |
if(iContactManager) |
|
271 |
{ |
|
272 |
delete iContactManager; |
|
273 |
iContactManager =NULL; |
|
274 |
} |
|
275 |
if(iSyncIter) |
|
276 |
{ |
|
277 |
delete iSyncIter; |
|
278 |
iSyncIter = NULL; |
|
279 |
} |
|
280 |
iDbArray.ResetAndDestroy(); |
|
281 |
} |
|
282 |