author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:45:40 +0200 | |
changeset 42 | 92cfb77afb61 |
parent 22 | fc9cf246af83 |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2006-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: Iterator in the output of GetList |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "contactiterator.h" |
|
20 |
#include "contactinterface.hrh" |
|
21 |
||
22 |
/* |
|
23 |
----------------------------------------------------------------------------- |
|
24 |
CContactIterator::~CContactIterator() |
|
25 |
Description : Destructor |
|
26 |
Return values : N/A |
|
27 |
----------------------------------------------------------------------------- |
|
28 |
*/ |
|
29 |
CContactIterator::~CContactIterator() |
|
30 |
{ |
|
31 |
delete iContactIter; |
|
32 |
} |
|
33 |
||
34 |
||
35 |
/* |
|
36 |
----------------------------------------------------------------------------- |
|
37 |
CContactIterator::NewL() |
|
38 |
Description : Allocates memory |
|
39 |
Return values : Returns class instance |
|
40 |
----------------------------------------------------------------------------- |
|
41 |
*/ |
|
42 |
||
43 |
CContactIterator* CContactIterator::NewL(CContactIter* aIter) |
|
44 |
{ |
|
45 |
return (new (ELeave) CContactIterator(aIter)); |
|
46 |
} |
|
47 |
||
48 |
||
49 |
/* |
|
50 |
----------------------------------------------------------------------------- |
|
51 |
CContactIterator::CContactIterator() |
|
52 |
Description : Constructor- Initializes data |
|
53 |
Return values : N/A |
|
54 |
----------------------------------------------------------------------------- |
|
55 |
*/ |
|
56 |
CContactIterator::CContactIterator(CContactIter* aIter) |
|
57 |
{ |
|
58 |
iContactIter = aIter; |
|
59 |
iIndex = -1; |
|
60 |
} |
|
61 |
||
62 |
/* |
|
63 |
----------------------------------------------------------------------------- |
|
64 |
CContactIterator::Reset() |
|
65 |
Description : Resets the cursor of the iterator to -1 |
|
66 |
Return values : N/A |
|
67 |
----------------------------------------------------------------------------- |
|
68 |
*/ |
|
69 |
void CContactIterator:: Reset() |
|
70 |
{ |
|
71 |
iIndex=-1; |
|
72 |
} |
|
73 |
||
74 |
/* |
|
75 |
----------------------------------------------------------------------------- |
|
76 |
CContactIterator::GetContactIDUTF() |
|
77 |
Description : Converts to UTF format |
|
78 |
Return values : N/A |
|
79 |
----------------------------------------------------------------------------- |
|
80 |
*/ |
|
81 |
void CContactIterator :: ContactIDToUTF(HBufC* aContactID) |
|
82 |
{ |
|
83 |
TInt len = aContactID->Length(); |
|
84 |
TUint16* ptr16 = const_cast<TUint16*> (aContactID->Des().Ptr()); |
|
85 |
for(TInt i=0; i<len; i++) |
|
86 |
{ |
|
87 |
ptr16[i] = ptr16[i] | 0xE000; |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
/* |
|
92 |
----------------------------------------------------------------------------- |
|
93 |
CContactIterator::NextL() |
|
94 |
Description : returns in outparam, the next item in the list that iterator |
|
95 |
is iterating on |
|
96 |
Return values : ETrue/EFalse based on success or failure |
|
97 |
----------------------------------------------------------------------------- |
|
98 |
*/ |
|
99 |
TBool CContactIterator::NextL(TLiwVariant& aEntry) |
|
100 |
{ |
|
101 |
||
102 |
CLiwMap* pContactMap = NULL; |
|
103 |
TBool retVal = EFalse; |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
104 |
RPointerArray<HBufC> xspidArray; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
105 |
CLiwList* IdList = NULL; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
106 |
TLiwVariant outputVal; |
19 | 107 |
//If iterator is iterating over contacts |
108 |
if(iContactIter->iIndicator == EContacts) |
|
109 |
{ |
|
110 |
CSingleContact* contact = NULL; |
|
111 |
HBufC8* cntId = NULL ; |
|
112 |
CSingleContactField* field = NULL; |
|
113 |
HBufC* cntIdUnicode = NULL; |
|
114 |
||
115 |
//Get the next contact on the list |
|
116 |
iContactIter->NextL(contact, cntId); |
|
117 |
||
118 |
if(contact) |
|
119 |
{ |
|
120 |
TPtrC8 fieldName; |
|
121 |
TPtrC fieldLabel; |
|
122 |
TPtrC fieldValue; |
|
123 |
TTime fieldTime; |
|
124 |
TBool date = EFalse; |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
125 |
TBool xspid = EFalse; |
19 | 126 |
|
127 |
CleanupStack :: PushL(contact); |
|
128 |
||
129 |
pContactMap = CLiwDefaultMap::NewL(); |
|
130 |
CleanupStack :: PushL(pContactMap); |
|
131 |
||
132 |
cntIdUnicode = HBufC::NewL(cntId->Length()); |
|
133 |
CleanupStack :: PushL(cntIdUnicode); |
|
134 |
cntIdUnicode->Des().Copy(*cntId); |
|
135 |
delete cntId; |
|
136 |
cntId = NULL; |
|
137 |
ContactIDToUTF(cntIdUnicode); |
|
138 |
pContactMap->InsertL(KContactId,TLiwVariant(*cntIdUnicode)); |
|
139 |
CleanupStack :: Pop(cntIdUnicode); |
|
140 |
||
141 |
TLiwVariant val; |
|
142 |
CleanupStack::PushL( TCleanupItem( TLiwVariant::VariantCleanup , &val) ); |
|
143 |
||
144 |
TInt fieldCount = contact->FieldCount(); |
|
145 |
for(TInt i=0 ; i< fieldCount ; i++) |
|
146 |
{ |
|
147 |
CLiwMap* pFieldLinkedMap = CLiwDefaultMap::NewL(); |
|
148 |
CleanupClosePushL(*pFieldLinkedMap); |
|
149 |
//Get the next field |
|
150 |
field = contact->FieldAt(i); |
|
151 |
||
152 |
//Get field data and populate the map structure |
|
153 |
field->GetFieldDataL(fieldName, fieldLabel, fieldValue); |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
154 |
if(fieldName.Compare(KXspid) == 0) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
155 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
156 |
xspid = ETrue; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
157 |
fieldLabel.Set(KXspidLabel); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
158 |
field->GetUriFieldParamL(xspidArray); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
159 |
if(xspidArray.Count() > 0) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
160 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
161 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
162 |
TInt count = xspidArray.Count(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
163 |
TInt i; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
164 |
IdList = CLiwDefaultList::NewL(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
165 |
for(i=0; i<count; i++) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
166 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
167 |
TDesC* idVal = xspidArray[i]; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
168 |
outputVal.Set(*idVal); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
169 |
IdList->AppendL(outputVal); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
170 |
} |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
171 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
172 |
} |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
173 |
xspidArray.ResetAndDestroy(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
174 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
175 |
} |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
176 |
if((fieldName.Compare(KDate) == 0) || (fieldName.Compare(KAnniversary) == 0)) // || fieldName.Compare(KBirthDay) == 0) |
19 | 177 |
{ |
178 |
date = ETrue; |
|
179 |
fieldTime = field->GetDateTime(); |
|
180 |
} |
|
181 |
||
182 |
if(EFalse != pContactMap->FindL(fieldName,val)) |
|
183 |
{ |
|
184 |
//In case there are multiple values for a given Fieldkey, add "Next" key to the map. |
|
185 |
// and create a linked list of label-value pairs for a given key |
|
186 |
pFieldLinkedMap->InsertL(KFieldLabel,TLiwVariant(fieldLabel)); |
|
187 |
if(date) |
|
188 |
{ |
|
189 |
pFieldLinkedMap->InsertL(KFieldValue,TLiwVariant(fieldTime)); |
|
190 |
} |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
191 |
else if(xspid) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
192 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
193 |
// CLiwMap* pFieldLinkedMap = CLiwDefaultMap::NewL(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
194 |
// CleanupClosePushL(*pFieldLinkedMap); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
195 |
pFieldLinkedMap->InsertL(KFieldValue,TLiwVariant(IdList)); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
196 |
} |
19 | 197 |
else |
198 |
{ |
|
199 |
pFieldLinkedMap->InsertL(KFieldValue,TLiwVariant(fieldValue)); |
|
200 |
} |
|
201 |
pFieldLinkedMap->InsertL(KFieldNext,TLiwVariant(val)); |
|
202 |
} |
|
203 |
else |
|
204 |
{ |
|
205 |
//In case its the first time the FieldKey is being read, just have label-value pair inserted |
|
206 |
pFieldLinkedMap->InsertL(KFieldLabel,TLiwVariant(fieldLabel)); |
|
207 |
if(date) |
|
208 |
{ |
|
209 |
date = EFalse; |
|
210 |
pFieldLinkedMap->InsertL(KFieldValue,TLiwVariant(fieldTime)); |
|
211 |
} |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
212 |
else if(xspid) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
213 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
214 |
xspid = EFalse; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
215 |
pFieldLinkedMap->InsertL(KFieldValue,TLiwVariant(IdList)); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
216 |
} |
19 | 217 |
else |
218 |
{ |
|
219 |
pFieldLinkedMap->InsertL(KFieldValue,TLiwVariant(fieldValue)); |
|
220 |
} |
|
221 |
} |
|
222 |
//For the given Fieldkey insert the label-value pair |
|
223 |
pContactMap->InsertL(fieldName, TLiwVariant(pFieldLinkedMap)); |
|
224 |
CleanupStack::PopAndDestroy(pFieldLinkedMap); |
|
225 |
} |
|
226 |
CleanupStack::Pop(&val); |
|
227 |
val.Reset(); |
|
228 |
CleanupStack::Pop(pContactMap); |
|
229 |
CleanupStack::PopAndDestroy(contact); |
|
230 |
retVal = ETrue; |
|
231 |
} |
|
232 |
else |
|
233 |
{ |
|
234 |
delete cntId; |
|
235 |
} |
|
236 |
} |
|
237 |
//In case the iterator is iterating over a list of groups |
|
238 |
else if(iContactIter->iIndicator == EGroups) |
|
239 |
{ |
|
240 |
CSingleContact* contact; |
|
241 |
HBufC8* grpID; |
|
242 |
CSingleContactField* field; |
|
243 |
HBufC* grpUnicode = NULL; |
|
244 |
//Get the next group |
|
245 |
iContactIter->NextL(contact, grpID); |
|
246 |
||
247 |
if(contact) |
|
248 |
{ |
|
249 |
CleanupStack::PushL(contact); |
|
250 |
||
251 |
TPtrC groupLabel; |
|
252 |
RPointerArray<TDesC8> array; |
|
253 |
CleanupClosePushL(array); |
|
254 |
pContactMap = CLiwDefaultMap::NewL(); |
|
255 |
CleanupStack::PushL(pContactMap); |
|
256 |
||
257 |
grpUnicode = HBufC::NewL(grpID->Length()); |
|
258 |
grpUnicode->Des().Copy(*grpID); |
|
259 |
delete grpID; |
|
260 |
grpID = NULL; |
|
261 |
ContactIDToUTF(grpUnicode); |
|
262 |
CleanupStack::PushL(grpUnicode); |
|
263 |
//Insert the contact id |
|
264 |
pContactMap->InsertL(KGroupId,TLiwVariant(*grpUnicode)); |
|
265 |
CleanupStack::Pop(grpUnicode); |
|
266 |
||
267 |
field = contact->FieldAt(0); |
|
268 |
||
269 |
//Get the field data of the group |
|
270 |
field->GetFieldDataL(groupLabel, array); |
|
271 |
||
272 |
//Insert group label |
|
273 |
pContactMap->InsertL(KGroupLabel,TLiwVariant(groupLabel)); |
|
274 |
||
275 |
CLiwList* pContentsList = CLiwDefaultList::NewL(); |
|
276 |
CleanupClosePushL(*pContentsList); |
|
277 |
TInt count = array.Count(); |
|
278 |
if(count) |
|
279 |
{ |
|
280 |
for(TInt i=0; i<count ; i++) |
|
281 |
{ |
|
282 |
HBufC* cntidUni = HBufC:: NewL(array[i]->Length()); |
|
283 |
cntidUni->Des().Copy(*array[i]); |
|
284 |
CleanupStack::PushL(cntidUni); |
|
285 |
ContactIDToUTF(cntidUni); |
|
286 |
pContentsList->AppendL(*cntidUni); |
|
287 |
CleanupStack::Pop(cntidUni); |
|
288 |
} |
|
289 |
//Insert the list of contacts for the given group |
|
290 |
pContactMap->InsertL(KContents,TLiwVariant(pContentsList)); |
|
291 |
} |
|
292 |
CleanupStack::PopAndDestroy(pContentsList); |
|
293 |
CleanupStack :: Pop(pContactMap); |
|
294 |
CleanupStack :: PopAndDestroy(); |
|
295 |
CleanupStack :: PopAndDestroy(contact); |
|
296 |
||
297 |
retVal = ETrue; |
|
298 |
} |
|
299 |
else |
|
300 |
{ |
|
301 |
delete grpID; |
|
302 |
} |
|
303 |
} |
|
304 |
//In case iterator is iterating over list of databases |
|
305 |
else if(iContactIter->iIndicator == EDatabase) |
|
306 |
{ |
|
307 |
TPtrC DbName; |
|
308 |
//Get the next database name |
|
309 |
iContactIter->NextL(DbName); |
|
310 |
if(DbName.Compare(KNullDesC) != 0) |
|
311 |
{ |
|
312 |
pContactMap = CLiwDefaultMap::NewL(); |
|
313 |
CleanupStack::PushL(pContactMap); |
|
314 |
//Insert DbName into the map |
|
315 |
pContactMap->InsertL(KDBUri,TLiwVariant(DbName)); |
|
316 |
CleanupStack::Pop(pContactMap); |
|
317 |
retVal = ETrue; |
|
318 |
} |
|
319 |
} |
|
320 |
if(pContactMap) |
|
321 |
{ |
|
322 |
CleanupClosePushL(*pContactMap); |
|
323 |
aEntry.SetL(pContactMap); |
|
324 |
CleanupStack::PopAndDestroy(pContactMap); |
|
325 |
} |
|
326 |
return retVal; |
|
327 |
} |