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 #include "engine.h" |
|
20 #include "enginewrapper.h" |
|
21 #include "creator_contactsetcache.h" |
|
22 |
|
23 #include "creator_phonebookwrapper.h" |
|
24 #include "creator_traces.h" |
|
25 |
|
26 #include <bautils.h> |
|
27 |
|
28 typedef struct { |
|
29 TInt iFieldCode; |
|
30 QString iDetail; |
|
31 QString iFieldContext; |
|
32 QString iFieldString; |
|
33 } QDetailFieldInfo; |
|
34 //static const TInt RND_TYPE_UNDEF = -99; |
|
35 QDetailFieldInfo CreatorPbkTextFields[] = { |
|
36 { (TInt)CCreatorPhonebookWrapper::EFirstName,(QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldFirstName).operator QString()}, |
|
37 { (TInt)CCreatorPhonebookWrapper::ELastName,(QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldLastName).operator QString()}, |
|
38 { (TInt)CCreatorPhonebookWrapper::ECompanyName,(QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldName).operator QString()}, |
|
39 { (TInt)CCreatorPhonebookWrapper::EJobTitle,(QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldTitle).operator QString()}, |
|
40 { (TInt)CCreatorPhonebookWrapper::EPrefix,(QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldPrefix).operator QString()}, |
|
41 { (TInt)CCreatorPhonebookWrapper::ESuffix,(QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldSuffix).operator QString()}, |
|
42 { (TInt)CCreatorPhonebookWrapper::EMiddleName,(QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldMiddleName).operator QString()}, |
|
43 { (TInt)CCreatorPhonebookWrapper::EAddrStreetHome,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldStreet).operator QString()}, |
|
44 { (TInt)CCreatorPhonebookWrapper::EAddrLocalHome,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldLocality).operator QString()}, |
|
45 { (TInt)CCreatorPhonebookWrapper::EAddrRegionHome,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldRegion).operator QString()}, |
|
46 { (TInt)CCreatorPhonebookWrapper::EAddrPostCodeHome,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldPostcode).operator QString()}, |
|
47 { (TInt)CCreatorPhonebookWrapper::EAddrCountryHome,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldCountry).operator QString()}, |
|
48 { (TInt)CCreatorPhonebookWrapper::EAddrStreetGen,(QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldStreet).operator QString()}, |
|
49 { (TInt)CCreatorPhonebookWrapper::EAddrLocalGen,(QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldLocality).operator QString()}, |
|
50 { (TInt)CCreatorPhonebookWrapper::EAddrRegionGen,(QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldRegion).operator QString()}, |
|
51 { (TInt)CCreatorPhonebookWrapper::EAddrPostCodeGen,(QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldPostcode).operator QString()}, |
|
52 { (TInt)CCreatorPhonebookWrapper::EAddrCountryGen,(QContactAddress::DefinitionName).operator QString(), "", (QContactAddress::FieldCountry).operator QString()}, |
|
53 { (TInt)CCreatorPhonebookWrapper::EAddrStreetWork,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldStreet).operator QString()}, |
|
54 { (TInt)CCreatorPhonebookWrapper::EAddrLocalWork,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldLocality).operator QString()}, |
|
55 { (TInt)CCreatorPhonebookWrapper::EAddrRegionWork,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldRegion).operator QString()}, |
|
56 { (TInt)CCreatorPhonebookWrapper::EAddrPostCodeWork,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldPostcode).operator QString()}, |
|
57 { (TInt)CCreatorPhonebookWrapper::EAddrCountryWork,(QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldCountry).operator QString()}, |
|
58 { (TInt)CCreatorPhonebookWrapper::EMobilePhoneWork,(QContactPhoneNumber::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactPhoneNumber::SubTypeMobile).operator QString()}, |
|
59 { (TInt)CCreatorPhonebookWrapper::ELandPhoneWork,(QContactPhoneNumber::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactPhoneNumber::SubTypeLandline).operator QString()}, |
|
60 { (TInt)CCreatorPhonebookWrapper::ENote,(QContactNote::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactNote::FieldNote).operator QString()}, |
|
61 { (TInt)CCreatorPhonebookWrapper::EDepartment,(QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldDepartment).operator QString()}, |
|
62 { (TInt)CCreatorPhonebookWrapper::EAsstName,(QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldAssistantName).operator QString()}, |
|
63 { (TInt)CCreatorPhonebookWrapper::ESpouse,(QContactFamily::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactFamily::FieldSpouse).operator QString()}, |
|
64 { (TInt)CCreatorPhonebookWrapper::EChildren,(QContactFamily::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactFamily::FieldChildren).operator QString()}, |
|
65 { (TInt)CCreatorPhonebookWrapper::EGenLabel,(QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldCustomLabel).operator QString()} |
|
66 }; |
|
67 |
|
68 |
|
69 typedef struct{ |
|
70 TInt iFieldCode; |
|
71 QString iFieldContext; |
|
72 QString iFieldString; |
|
73 }PhoneNumInfo; |
|
74 PhoneNumInfo CreatorPhoneNumberFields[] = |
|
75 { |
|
76 { CCreatorPhonebookWrapper::ELandPhoneGen,"", "Landline"}, |
|
77 { CCreatorPhonebookWrapper::ELandPhoneHome,"Home", "Landline"}, |
|
78 { CCreatorPhonebookWrapper::ELandPhoneWork,"Work", "Landline"}, |
|
79 { CCreatorPhonebookWrapper::EMobilePhoneGen,"","Mobile"}, |
|
80 { CCreatorPhonebookWrapper::EMobilePhoneHome,"Home","Mobile"}, |
|
81 { CCreatorPhonebookWrapper::EMobilePhoneWork,"Work", "Mobile"}, |
|
82 { CCreatorPhonebookWrapper::EFaxNumberGen, "", "Facsimile"}, |
|
83 { CCreatorPhonebookWrapper::EFaxNumberHome, "Home", "Facsimile"}, |
|
84 { CCreatorPhonebookWrapper::EFaxNumberWork, "Work", "Facsimile"}, |
|
85 { CCreatorPhonebookWrapper::EPagerNumber, "Work", "Pager"}, |
|
86 { CCreatorPhonebookWrapper::EVideoNumberGen, "", "Video"}, |
|
87 { CCreatorPhonebookWrapper::EVideoNumberHome, "Home", "Video"}, |
|
88 { CCreatorPhonebookWrapper::EVideoNumberWork, "Work", "Video"}, //{ "Home", "Voice" },//{ "Work", "Voice" }, |
|
89 { CCreatorPhonebookWrapper::EAsstPhone, "Work", "Assistant" }, |
|
90 { CCreatorPhonebookWrapper::ECarPhone, "Home", "Car" } |
|
91 }; |
|
92 |
|
93 |
|
94 typedef struct{ |
|
95 TInt iFieldCode; |
|
96 QString iFieldContext; |
|
97 }EmailInfo; |
|
98 EmailInfo CreatorEmailFields[] = |
|
99 { |
|
100 {CCreatorPhonebookWrapper::EEmailGen,""}, |
|
101 {CCreatorPhonebookWrapper::EEmailHome,(QContactDetail::ContextHome).operator QString()}, |
|
102 {CCreatorPhonebookWrapper::EEmailWork,(QContactDetail::ContextWork).operator QString()} |
|
103 }; |
|
104 |
|
105 typedef struct{ |
|
106 TInt iFieldCode; |
|
107 QString iFieldContext; |
|
108 }UrlInfo; |
|
109 UrlInfo CreatorUrlFields[] = |
|
110 { |
|
111 {CCreatorPhonebookWrapper::EUrlGen,""}, |
|
112 {CCreatorPhonebookWrapper::EUrlHome,(QContactDetail::ContextHome).operator QString()}, |
|
113 {CCreatorPhonebookWrapper::EUrlWork,(QContactDetail::ContextWork).operator QString()} |
|
114 }; |
|
115 |
|
116 CCreatorPhonebookWrapper* CCreatorPhonebookWrapper::NewL() |
|
117 { |
|
118 CCreatorPhonebookWrapper* self = CCreatorPhonebookWrapper::NewLC(); |
|
119 CleanupStack::Pop(self); |
|
120 return self; |
|
121 } |
|
122 |
|
123 CCreatorPhonebookWrapper* CCreatorPhonebookWrapper::NewLC() |
|
124 { |
|
125 CCreatorPhonebookWrapper* self = new (ELeave) CCreatorPhonebookWrapper(); |
|
126 CleanupStack::PushL(self); |
|
127 self->ConstructL(); |
|
128 return self; |
|
129 } |
|
130 |
|
131 |
|
132 CCreatorPhonebookWrapper::CCreatorPhonebookWrapper() |
|
133 { |
|
134 } |
|
135 |
|
136 void CCreatorPhonebookWrapper::ConstructL() |
|
137 { |
|
138 LOGSTRING("Creator: CCreatorPhonebookWrapper::ConstructL"); |
|
139 |
|
140 QT_TRYCATCH_LEAVING( iPhonebookAPI = new CCreatorPhonebookAPI() ); |
|
141 |
|
142 } |
|
143 |
|
144 |
|
145 CCreatorPhonebookWrapper::~CCreatorPhonebookWrapper() |
|
146 { |
|
147 LOGSTRING("Creator: CCreatorPhonebookWrapper::~CCreatorPhonebookWrapper"); |
|
148 if( iPhonebookAPI ) |
|
149 { |
|
150 delete iPhonebookAPI; |
|
151 iPhonebookAPI = NULL; |
|
152 } |
|
153 } |
|
154 |
|
155 //---------------------------------------------------------------------------- |
|
156 |
|
157 QList<QContactDetail> CCreatorPhonebookWrapper::CreateContactDetailsFromParameters( const TCreatorContactFields& aFields ) |
|
158 { |
|
159 QList<QContactDetail> contDetList; |
|
160 QString content; |
|
161 HBufC* temp; |
|
162 TInt arraySize = sizeof(CreatorPbkTextFields)/sizeof(QDetailFieldInfo); |
|
163 for (TInt i = 0; i < arraySize; i++) |
|
164 { |
|
165 TCreatorContactFields::const_iterator it = aFields.find(CreatorPbkTextFields[i].iFieldCode); |
|
166 if( it != aFields.end() ) |
|
167 { |
|
168 temp = (*it).second; |
|
169 content = QString::fromUtf16( temp->Des().Ptr(), temp->Length() ); |
|
170 QContactDetail contactDetail = CreateContactDetail(contDetList, CreatorPbkTextFields[i].iDetail,CreatorPbkTextFields[i].iFieldContext,CreatorPbkTextFields[i].iFieldString, content ); |
|
171 AddFieldToList( contDetList, contactDetail ); |
|
172 } |
|
173 } |
|
174 arraySize = sizeof(CreatorPhoneNumberFields)/sizeof(PhoneNumInfo); |
|
175 for (TInt i = 0; i < arraySize; i++) |
|
176 { |
|
177 TCreatorContactFields::const_iterator it = aFields.find(CreatorPhoneNumberFields[i].iFieldCode); |
|
178 if( it != aFields.end() ) |
|
179 { |
|
180 temp = (*it).second; |
|
181 content = QString::fromUtf16( temp->Des().Ptr(), temp->Length() ); |
|
182 QContactDetail contactDetail = CreateContactDetail(contDetList, QContactPhoneNumber::DefinitionName ,CreatorPhoneNumberFields[i].iFieldContext,CreatorPhoneNumberFields[i].iFieldString, content ); |
|
183 AddFieldToList( contDetList, contactDetail ); |
|
184 } |
|
185 } |
|
186 |
|
187 arraySize = sizeof(CreatorEmailFields)/sizeof(EmailInfo); |
|
188 for (TInt i = 0; i < arraySize; i++) |
|
189 { |
|
190 TCreatorContactFields::const_iterator it = aFields.find(CreatorEmailFields[i].iFieldCode); |
|
191 if( it != aFields.end() ) |
|
192 { |
|
193 temp = (*it).second; |
|
194 content = QString::fromUtf16( temp->Des().Ptr(), temp->Length() ); |
|
195 QContactDetail contactDetail = CreateContactDetail(contDetList, QContactEmailAddress::DefinitionName ,CreatorEmailFields[i].iFieldContext,"", content ); |
|
196 AddFieldToList( contDetList, contactDetail ); |
|
197 } |
|
198 } |
|
199 |
|
200 arraySize = sizeof(CreatorUrlFields)/sizeof(UrlInfo); |
|
201 for (TInt i = 0; i < arraySize; i++) |
|
202 { |
|
203 TCreatorContactFields::const_iterator it = aFields.find(CreatorUrlFields[i].iFieldCode); |
|
204 if( it != aFields.end() ) |
|
205 { |
|
206 temp = (*it).second; |
|
207 content = QString::fromUtf16( temp->Des().Ptr(), temp->Length() ); |
|
208 QContactDetail contactDetail = CreateContactDetail(contDetList, QContactUrl::DefinitionName ,CreatorUrlFields[i].iFieldContext,"", content ); |
|
209 AddFieldToList( contDetList, contactDetail ); |
|
210 } |
|
211 } |
|
212 arraySize = sizeof(CreatorUrlFields)/sizeof(UrlInfo); |
|
213 for (TInt i = 0; i < arraySize; i++) |
|
214 { |
|
215 TCreatorContactFields::const_iterator it = aFields.find(CreatorUrlFields[i].iFieldCode); |
|
216 if( it != aFields.end() ) |
|
217 { |
|
218 temp = (*it).second; |
|
219 content = QString::fromUtf16( temp->Des().Ptr(), temp->Length() ); |
|
220 QContactDetail contactDetail = CreateContactDetail(contDetList, QContactUrl::DefinitionName ,CreatorUrlFields[i].iFieldContext,"", content ); |
|
221 AddFieldToList( contDetList, contactDetail ); |
|
222 } |
|
223 } |
|
224 |
|
225 TCreatorContactFields::const_iterator it = aFields.find(CCreatorPhonebookWrapper::EThumbnailPic); |
|
226 if( it != aFields.end() ) |
|
227 { |
|
228 temp = (*it).second; |
|
229 if(temp) |
|
230 { |
|
231 content = QString::fromUtf16( temp->Des().Ptr(), temp->Length() ); |
|
232 QContactDetail contactDetail = CreateContactDetail(contDetList, QContactAvatar::DefinitionName ,"","", content ); |
|
233 AddFieldToList( contDetList, contactDetail ); |
|
234 } |
|
235 } |
|
236 it = aFields.find(CCreatorPhonebookWrapper::EAnniversary); |
|
237 if( it != aFields.end() ) |
|
238 { |
|
239 temp = (*it).second; |
|
240 if(temp) |
|
241 { |
|
242 content = QString::fromUtf16( temp->Des().Ptr(), temp->Length() ); |
|
243 QContactDetail contactDetail = CreateContactDetail(contDetList, QContactAnniversary::DefinitionName ,"","", content ); |
|
244 AddFieldToList( contDetList, contactDetail ); |
|
245 } |
|
246 } |
|
247 |
|
248 return contDetList; |
|
249 } |
|
250 QContactDetail CCreatorPhonebookWrapper::CreateContactDetail( QList<QContactDetail>& aContactDetailList,QString aDetail, QString aFieldContext, QString aFieldString, QString aData ) |
|
251 { |
|
252 QContactDetail contactDetail; |
|
253 |
|
254 if( aDetail == QContactPhoneNumber::DefinitionName) |
|
255 { |
|
256 QContactPhoneNumber phoneNumber;// = contactDetail; |
|
257 if(!aFieldContext.isEmpty()) |
|
258 { |
|
259 phoneNumber.setContexts(aFieldContext); |
|
260 } |
|
261 phoneNumber.setSubTypes(aFieldString); |
|
262 //QString number = QString::fromUtf16(aData.Ptr(),aData.Length()); |
|
263 phoneNumber.setNumber(aData); |
|
264 return phoneNumber; |
|
265 } |
|
266 else if( aDetail == QContactName::DefinitionName ) //--Contact NAME----------------------------- |
|
267 { |
|
268 QContactName contactName; |
|
269 for(int i = 0 ; i < aContactDetailList.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details |
|
270 { |
|
271 if(aContactDetailList.at(i).definitionName() == QContactName::DefinitionName ) |
|
272 { |
|
273 contactName = aContactDetailList.at(i); |
|
274 } |
|
275 } |
|
276 //QString name = QString::fromUtf16(aData.Ptr(),aData.Length()); |
|
277 if(aFieldString == QContactName::FieldFirstName) |
|
278 { |
|
279 if(contactName.firstName().isEmpty()) |
|
280 { |
|
281 contactName.setFirstName( aData ); |
|
282 } |
|
283 } |
|
284 else if(aFieldString == QContactName::FieldLastName) |
|
285 { |
|
286 if(contactName.lastName().isEmpty()) |
|
287 { |
|
288 contactName.setLastName( aData ); |
|
289 } |
|
290 } |
|
291 else if(aFieldString == QContactName::FieldMiddleName) |
|
292 { |
|
293 if(contactName.middleName().isEmpty()) |
|
294 { |
|
295 contactName.setMiddleName( aData ); |
|
296 } |
|
297 } |
|
298 else if(aFieldString == QContactName::FieldPrefix) |
|
299 { |
|
300 if(contactName.prefix().isEmpty()) |
|
301 { |
|
302 contactName.setPrefix( aData ); |
|
303 } |
|
304 } |
|
305 else if(aFieldString == QContactName::FieldSuffix) |
|
306 { |
|
307 if(contactName.suffix().isEmpty()) |
|
308 { |
|
309 contactName.setSuffix( aData ); |
|
310 } |
|
311 } |
|
312 else //QContactName::FieldCustomLabel: |
|
313 { |
|
314 if(contactName.customLabel().isEmpty()) |
|
315 { |
|
316 contactName.setCustomLabel( aData ); |
|
317 } |
|
318 } |
|
319 return contactName; |
|
320 } |
|
321 else if( aDetail == QContactOrganization::DefinitionName ) //--Contact Company----------------------------- |
|
322 { |
|
323 QContactOrganization contactCompany; |
|
324 |
|
325 for(int i = 0 ; i < aContactDetailList.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details |
|
326 { |
|
327 if(aContactDetailList.at(i).definitionName() == QContactOrganization::DefinitionName ) |
|
328 { |
|
329 contactCompany = aContactDetailList.at(i); |
|
330 } |
|
331 } |
|
332 |
|
333 //QString company = QString::fromUtf16(aData.Ptr(),aData.Length()); |
|
334 if(aFieldString == QContactOrganization::FieldName) |
|
335 { |
|
336 if(contactCompany.name().isEmpty()) |
|
337 { |
|
338 contactCompany.setName( aData ); |
|
339 } |
|
340 } |
|
341 if(aFieldString == QContactOrganization::FieldTitle) |
|
342 { |
|
343 if(contactCompany.title().isEmpty()) |
|
344 { |
|
345 contactCompany.setTitle( aData ); |
|
346 } |
|
347 } |
|
348 if(aFieldString == QContactOrganization::FieldDepartment) |
|
349 { |
|
350 QStringList depList = contactCompany.department(); |
|
351 depList.append(aData); |
|
352 contactCompany.setDepartment(depList); |
|
353 } |
|
354 if(aFieldString == QContactOrganization::FieldAssistantName) |
|
355 { |
|
356 if(contactCompany.assistantName().isEmpty()) |
|
357 { |
|
358 contactCompany.setAssistantName( aData ); |
|
359 } |
|
360 } |
|
361 return contactCompany; |
|
362 } |
|
363 else if( aDetail == QContactAddress::DefinitionName ) //--Contact Address----------------------------- |
|
364 { |
|
365 QContactAddress contactAddress; |
|
366 |
|
367 for(int i = 0 ; i < aContactDetailList.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details |
|
368 { |
|
369 if(aContactDetailList.at(i).definitionName() == QContactAddress::DefinitionName && aContactDetailList.at(i).value(QContactDetail::FieldContext) == aFieldContext ) |
|
370 { |
|
371 contactAddress = aContactDetailList.at(i); |
|
372 } |
|
373 } |
|
374 if( !aFieldContext.isEmpty() ) |
|
375 { |
|
376 contactAddress.setContexts( aFieldContext ); |
|
377 } |
|
378 //QString address = QString::fromUtf16(aData.Ptr(),aData.Length()); |
|
379 if(aFieldString == QContactAddress::FieldStreet ) |
|
380 { |
|
381 if( contactAddress.street().isEmpty() ) |
|
382 { |
|
383 contactAddress.setStreet( aData ); |
|
384 } |
|
385 } |
|
386 else if(aFieldString == QContactAddress::FieldLocality ) |
|
387 { |
|
388 if( contactAddress.locality().isEmpty() ) |
|
389 { |
|
390 contactAddress.setLocality( aData ); |
|
391 } |
|
392 } |
|
393 else if(aFieldString == QContactAddress::FieldRegion ) |
|
394 { |
|
395 if( contactAddress.region().isEmpty() ) |
|
396 { |
|
397 contactAddress.setRegion( aData ); |
|
398 } |
|
399 } |
|
400 else if(aFieldString == QContactAddress::FieldPostcode ) |
|
401 { |
|
402 if( contactAddress.postcode().isEmpty() ) |
|
403 { |
|
404 contactAddress.setPostcode( aData ); |
|
405 } |
|
406 } |
|
407 else if(aFieldString == QContactAddress::FieldCountry ) |
|
408 { |
|
409 if( contactAddress.country().isEmpty() ) |
|
410 { |
|
411 contactAddress.setCountry( aData ); |
|
412 } |
|
413 } |
|
414 else |
|
415 { |
|
416 return contactDetail; |
|
417 } |
|
418 return contactAddress; |
|
419 } |
|
420 else if( aDetail == QContactNote::DefinitionName ) //--Contact Note----------------------------- |
|
421 { |
|
422 QContactNote contactNote; |
|
423 //QString note = QString::fromUtf16(aData.Ptr(),aData.Length()); |
|
424 contactNote.setNote(aData); |
|
425 return contactNote; |
|
426 } |
|
427 else if( aDetail == QContactFamily::DefinitionName ) //--Contact Family----------------------------- |
|
428 { |
|
429 QContactFamily contactFamily; |
|
430 |
|
431 for(int i = 0 ; i < aContactDetailList.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details |
|
432 { |
|
433 if(aContactDetailList.at(i).definitionName() == QContactFamily::DefinitionName && aContactDetailList.at(i).value(QContactDetail::FieldContext) == aFieldContext ) |
|
434 { |
|
435 contactFamily = aContactDetailList.at(i); |
|
436 } |
|
437 } |
|
438 |
|
439 //QString familyData = QString::fromUtf16(aData.Ptr(),aData.Length()); |
|
440 if(aFieldString == QContactFamily::FieldSpouse ) |
|
441 { |
|
442 if( contactFamily.spouse().isEmpty() ) |
|
443 { |
|
444 contactFamily.setSpouse( aData ); |
|
445 } |
|
446 } |
|
447 if(aFieldString == QContactFamily::FieldChildren ) |
|
448 { |
|
449 QStringList children = contactFamily.children(); |
|
450 children.append( aData ); |
|
451 contactFamily.setChildren( children ); |
|
452 } |
|
453 |
|
454 return contactFamily; |
|
455 } |
|
456 |
|
457 if( aDetail == QContactAvatar::DefinitionName) //--Contact Picture----------------------------- |
|
458 { |
|
459 QContactAvatar contactAvatar; |
|
460 QUrl imageUrl; |
|
461 imageUrl.setUrl(aData); |
|
462 contactAvatar.setImageUrl(imageUrl); |
|
463 |
|
464 return contactAvatar; |
|
465 } |
|
466 if( aDetail == QContactAnniversary::DefinitionName) //--Anniversary------------------------------ |
|
467 { |
|
468 QContactAnniversary contactAnniversary; |
|
469 aData.replace(QChar('/'), QChar('-')); |
|
470 QDate date = QDate::fromString(aData, "dd-MM-yyyy"); |
|
471 //TTime datetime = aEngine->RandomDate( CCreatorEngine::EDateFuture ); |
|
472 //date.setDate( datetime.DateTime().Year(),(int) (datetime.DateTime().Month()+1), datetime.DateTime().Day() ); |
|
473 contactAnniversary.setOriginalDate( date ); |
|
474 return contactAnniversary; |
|
475 } |
|
476 if( aDetail == QContactEmailAddress::DefinitionName) //--Email------------------------------------ |
|
477 { |
|
478 QContactEmailAddress email; |
|
479 //QString emailAddr = QString::fromUtf16(aData.Ptr(),aData.Length()); |
|
480 if( !aFieldContext.isEmpty() ) |
|
481 { |
|
482 email.setContexts( aFieldContext ); |
|
483 } |
|
484 email.setEmailAddress( aData ); |
|
485 return email; |
|
486 } |
|
487 if( aDetail == QContactUrl::DefinitionName ) //--Url------------------------------------------- |
|
488 { |
|
489 QContactUrl url; |
|
490 //QString urlStr = QString::fromUtf16(aData.Ptr(),aData.Length()); |
|
491 if( !aFieldContext.isEmpty() ) |
|
492 { |
|
493 url.setContexts( aFieldContext ); |
|
494 } |
|
495 url.setUrl(aData); |
|
496 return url; |
|
497 } |
|
498 if( aDetail == QContactBirthday::DefinitionName ) //--Birthday----------------------------------- |
|
499 { |
|
500 QContactBirthday birthday; |
|
501 QDate date = QDate::fromString(aData); |
|
502 //TTime datetime = aEngine->RandomDate( CCreatorEngine::EDatePast ); |
|
503 //date.setDate( datetime.DateTime().Year(),(int) (datetime.DateTime().Month()+1), datetime.DateTime().Day() ); |
|
504 birthday.setDate( date ); |
|
505 return birthday; |
|
506 } |
|
507 |
|
508 return contactDetail; |
|
509 } |
|
510 |
|
511 void CCreatorPhonebookWrapper::AddFieldToList( QList<QContactDetail>& aDetailList, QContactDetail aDetail) |
|
512 { |
|
513 bool replace = false; |
|
514 for(int i = 0 ; i< aDetailList.count() ; i++) //go through |
|
515 { |
|
516 if( !aDetail.isEmpty() && aDetail.definitionName() == aDetailList.at(i).definitionName() |
|
517 && aDetail.definitionName() != QContactPhoneNumber::DefinitionName |
|
518 && aDetail.definitionName() != QContactEmailAddress::DefinitionName |
|
519 && aDetail.definitionName() != QContactUrl::DefinitionName ) |
|
520 { |
|
521 QString context = aDetail.value(QContactDetail::FieldContext); |
|
522 bool isContextEmpty = context.isEmpty(); |
|
523 if( isContextEmpty || ( aDetail.value(QContactDetail::FieldContext) == aDetailList.at(i).value(QContactDetail::FieldContext)) ) |
|
524 { |
|
525 //replace |
|
526 aDetailList.replace(i,aDetail); |
|
527 replace = true; |
|
528 } |
|
529 } |
|
530 } |
|
531 if(!replace) |
|
532 { |
|
533 if(!aDetail.isEmpty()) |
|
534 { |
|
535 aDetailList.append(aDetail); |
|
536 } |
|
537 } |
|
538 |
|
539 } |
|
540 |
|
541 TUint32 CCreatorPhonebookWrapper::CreateContactEntryL(const TCreatorContactFields& aFields) |
|
542 { |
|
543 QList<QContactDetail> list = CreateContactDetailsFromParameters( aFields ); |
|
544 |
|
545 return iPhonebookAPI->saveContact( list ); |
|
546 } |
|
547 |
|
548 |
|
549 //---------------------------------------------------------------------------- |
|
550 |
|
551 |
|
552 |
|
553 //---------------------------------------------------------------------------- |
|
554 |
|
555 void CCreatorPhonebookWrapper::DeleteAllL() |
|
556 { |
|
557 iPhonebookAPI->deleteAllContacts(); |
|
558 } |
|
559 |
|
560 //---------------------------------------------------------------------------- |
|
561 void CCreatorPhonebookWrapper::DeleteAllGroupsL() |
|
562 { |
|
563 LOGSTRING("Creator: CCreatorPhonebookWrapper::DeleteAllGroupsL"); |
|
564 |
|
565 iPhonebookAPI->deleteAllContacts( QContactType::TypeGroup ); |
|
566 |
|
567 } |
|
568 |
|
569 //---------------------------------------------------------------------------- |
|
570 void CCreatorPhonebookWrapper::DeleteContactsL( RArray<TUint32>& aContactsToDelete, TUid aStoreUid ) |
|
571 { |
|
572 QList<QContactLocalId> contacts; |
|
573 for( TInt i = 0; i < aContactsToDelete.Count(); ++i ) |
|
574 { |
|
575 QContact contact = iPhonebookAPI->contact( QContactLocalId( aContactsToDelete[i] ) ); |
|
576 if( (contact.type() == QContactType::TypeGroup && aStoreUid == KUidDictionaryUidContactGroups ) || (contact.type() != QContactType::TypeGroup && aStoreUid != KUidDictionaryUidContactGroups) ) |
|
577 { |
|
578 contacts.append( QContactLocalId( aContactsToDelete[i] ) ); |
|
579 } |
|
580 } |
|
581 QMap<int, QContactManager::Error> errorMap; |
|
582 iPhonebookAPI->deleteContacts( contacts ); |
|
583 } |
|
584 |
|
585 //---------------------------------------------------------------------------- |
|
586 TBool CCreatorPhonebookWrapper::HasOtherThanGroupsL() |
|
587 { |
|
588 LOGSTRING("Creator: CCreatorPhonebookWrapper::HasOtherThanGroupsL"); |
|
589 TBool result( EFalse ); |
|
590 return result; |
|
591 } |
|
592 |
|
593 |
|
594 TUint32 CCreatorPhonebookWrapper::CreateGroupEntryL( HBufC* aGroupName ) |
|
595 { |
|
596 TUint32 id = 0; |
|
597 QString groupName = QString::fromUtf16( aGroupName->Des().Ptr(), aGroupName->Length() ); |
|
598 |
|
599 id = iPhonebookAPI->createGroup( groupName ); |
|
600 |
|
601 return id; |
|
602 } |
|
603 TInt CCreatorPhonebookWrapper::NumberOfContacts() |
|
604 { |
|
605 //return all stored contacts |
|
606 return iPhonebookAPI->numberOfContacts(); |
|
607 } |
|
608 |
|
609 TInt CCreatorPhonebookWrapper::AddContactToGroup( TUint32 aGroupId, TUint32 aContact ) |
|
610 { |
|
611 QContactLocalId group = QContactLocalId(aGroupId); |
|
612 QContactLocalId contact = QContactLocalId(aContact); |
|
613 |
|
614 TInt ret = iPhonebookAPI->addContactToGroup(group, contact); |
|
615 |
|
616 return ret; |
|
617 } |
|
618 TInt CCreatorPhonebookWrapper::AddToGroup( TUint32 aGroupId, TInt aAmount ) |
|
619 { |
|
620 QContactLocalId group = QContactLocalId(aGroupId); |
|
621 TInt ret = iPhonebookAPI->addToGroup( group, (int) aAmount ); |
|
622 return ret; |
|
623 } |
|
624 |
|
625 |
|
626 //---------------------------------------------------------------------------- |
|
627 |
|
628 TInt CCreatorPhonebookWrapper::CreateSubscribedContactEntryL() |
|
629 { |
|
630 LOGSTRING("Creator: CCreatorPhonebookWrapper::CreateSubscribedContactEntryL"); |
|
631 |
|
632 return KErrNotSupported; |
|
633 } |
|
634 |
|
635 |
|
636 HBufC* CCreatorPhonebookWrapper::GetPhoneNumberL( TUint32 aContactId ) |
|
637 { |
|
638 QContactLocalId contact = QContactLocalId(aContactId); |
|
639 QString phoneNumber = iPhonebookAPI->phoneNumber(contact); |
|
640 HBufC *buf = HBufC::NewLC( phoneNumber.length() ); |
|
641 buf->Des().Copy( phoneNumber.utf16() ); |
|
642 CleanupStack::Pop( buf ); |
|
643 return buf; |
|
644 } |
|
645 |
|
646 TBool CCreatorPhonebookWrapper::GetContactDetailsL( TUint32 aContactId, TDes& aName, TDes& aPhoneNumber, TDes& aEmail ) |
|
647 { |
|
648 QString name; |
|
649 QString phoneNumber; |
|
650 QString email; |
|
651 |
|
652 QContactLocalId contact = QContactLocalId(aContactId); |
|
653 bool success = iPhonebookAPI->contactDetails( contact, name, phoneNumber, email); |
|
654 if( success ) |
|
655 { |
|
656 aName.Copy( name.utf16() ); |
|
657 aPhoneNumber.Copy( phoneNumber.utf16() ); |
|
658 aEmail.Copy( email.utf16() ); |
|
659 } |
|
660 return success ? ETrue : EFalse ; |
|
661 } |
|