|
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 |
|
22 #include "creator_phonebook.h" |
|
23 #include "creator_traces.h" |
|
24 |
|
25 #include <bautils.h> |
|
26 #include <qpixmap> |
|
27 |
|
28 //#include <QDebug> |
|
29 _LIT(KTempPath, "C:\\Data\\Creator\\"); |
|
30 |
|
31 |
|
32 typedef struct { |
|
33 QString iDetail; |
|
34 QString iFieldContext; |
|
35 QString iFieldString; |
|
36 TInt iRandomType; |
|
37 } DetailFieldInfo; |
|
38 static const TInt RND_TYPE_UNDEF = -99; |
|
39 DetailFieldInfo CreatorPbkMiscTextFields[] = { |
|
40 { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldFirstName).operator QString(), (TInt) CCreatorEngine::EFirstName}, |
|
41 { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldLastName).operator QString(), (TInt) CCreatorEngine::ESurname}, |
|
42 { (QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldName).operator QString(), (TInt) CCreatorEngine::ECompany}, |
|
43 { (QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldTitle).operator QString(), (TInt) CCreatorEngine::EJobTitle}, |
|
44 { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldPrefix).operator QString(), (TInt) CCreatorEngine::EPrefix}, |
|
45 { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldSuffix).operator QString(), (TInt) CCreatorEngine::ESuffix}, |
|
46 { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldMiddleName).operator QString(), (TInt) CCreatorEngine::EFirstName}, |
|
47 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldStreet).operator QString(), (TInt) CCreatorEngine::EAddress}, |
|
48 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldLocality).operator QString(), (TInt) CCreatorEngine::ECity}, |
|
49 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldRegion).operator QString(), (TInt) CCreatorEngine::EState}, |
|
50 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldPostcode).operator QString(), (TInt) CCreatorEngine::EPostcode}, |
|
51 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactAddress::FieldCountry).operator QString(), (TInt) CCreatorEngine::ECountry}, |
|
52 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldStreet).operator QString(), (TInt) CCreatorEngine::EAddress}, |
|
53 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldLocality).operator QString(), (TInt) CCreatorEngine::ECity}, |
|
54 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldRegion).operator QString(), (TInt) CCreatorEngine::EState}, |
|
55 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldPostcode).operator QString(), (TInt) CCreatorEngine::EPostcode}, |
|
56 { (QContactAddress::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactAddress::FieldCountry).operator QString(), (TInt) CCreatorEngine::ECountry}, |
|
57 { (QContactPhoneNumber::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactPhoneNumber::SubTypeMobile).operator QString(), (TInt) CCreatorEngine::EPhoneNumber}, |
|
58 { (QContactPhoneNumber::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactPhoneNumber::SubTypeLandline).operator QString(), (TInt) CCreatorEngine::EPhoneNumber}, |
|
59 { (QContactNote::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactNote::FieldNote).operator QString(), (TInt) CCreatorEngine::EMemoText}, |
|
60 { (QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldDepartment).operator QString(), (TInt) CCreatorEngine::ECompany}, |
|
61 { (QContactOrganization::DefinitionName).operator QString(), (QContactDetail::ContextWork).operator QString(), (QContactOrganization::FieldAssistantName).operator QString(), (TInt) CCreatorEngine::ECompany}, |
|
62 { (QContactFamily::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactFamily::FieldSpouse).operator QString(), (TInt) CCreatorEngine::EFirstName}, |
|
63 { (QContactFamily::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactFamily::FieldChildren).operator QString(), (TInt) CCreatorEngine::EFirstName}, |
|
64 { (QContactName::DefinitionName).operator QString(), (QContactDetail::ContextHome).operator QString(), (QContactName::FieldCustomLabel).operator QString(), (TInt) CCreatorEngine::EFirstName} |
|
65 }; |
|
66 |
|
67 /*TInt CreatorVPbkBinaryFields[] = { |
|
68 R_VPBK_FIELD_TYPE_CALLEROBJIMG//, |
|
69 //R_VPBK_FIELD_TYPE_THUMBNAILPATH |
|
70 };*/ |
|
71 |
|
72 /*QString CreatorPbkDateTimeFields[] = { |
|
73 QContactAnniversary::DefinitionName//R_VPBK_FIELD_TYPE_ANNIVERSARY |
|
74 };*/ |
|
75 |
|
76 //---------------------------------------------------------------------------- |
|
77 |
|
78 /* |
|
79 typedef struct{ |
|
80 QString iFieldContext; |
|
81 QString iFieldString; |
|
82 }PhoneNumInfo; |
|
83 PhoneNumInfo CreatorPhoneNumberFields[] = |
|
84 { |
|
85 { QContactPhoneNumber::ContextHome, QContactPhoneNumber::SubTypeLandline}, |
|
86 { QContactPhoneNumber::ContextWork, QContactPhoneNumber::SubTypeLandline}, |
|
87 { QContactPhoneNumber::ContextHome, QContactPhoneNumber::SubTypeMobile}, |
|
88 { QContactPhoneNumber::ContextWork, QContactPhoneNumber::SubTypeMobile}, |
|
89 { QContactPhoneNumber::ContextHome, QContactPhoneNumber::SubTypeFacsimile}, |
|
90 { QContactPhoneNumber::ContextWork, QContactPhoneNumber::SubTypeFacsimile}, |
|
91 { QContactPhoneNumber::ContextWork, QContactPhoneNumber::SubTypePager }, |
|
92 { QContactPhoneNumber::ContextHome, QContactPhoneNumber::SubTypeVideo }, |
|
93 { QContactPhoneNumber::ContextWork, QContactPhoneNumber::SubTypeVideo }, |
|
94 { QContactPhoneNumber::ContextHome, QContactPhoneNumber::SubTypeVoice }, |
|
95 { QContactPhoneNumber::ContextWork, QContactPhoneNumber::SubTypeVoice }, |
|
96 { QContactPhoneNumber::ContextWork, QContactPhoneNumber::SubTypeAssistant }, |
|
97 { QContactPhoneNumber::ContextHome, QContactPhoneNumber::SubTypeCar } |
|
98 }; |
|
99 |
|
100 */ |
|
101 typedef struct{ |
|
102 QString iFieldContext; |
|
103 QString iFieldString; |
|
104 }PhoneNumInfo; |
|
105 PhoneNumInfo CreatorPhoneNumberFields[] = |
|
106 { |
|
107 { "Home", "Landline"}, |
|
108 { "Work", "Landline"}, |
|
109 { "Home","Mobile"}, |
|
110 { "Work", "Mobile"}, |
|
111 { "Home", "Facsimile"}, |
|
112 { "Work", "Facsimile"}, |
|
113 { "Work", "Pager"}, |
|
114 { "Home", "Video"}, |
|
115 { "Work", "Video"}, //{ "Home", "Voice" },//{ "Work", "Voice" }, |
|
116 { "Work", "Assistant" }, |
|
117 { "Home", "Car" } |
|
118 }; |
|
119 |
|
120 |
|
121 /*QString CCreatorPhonebook::iPhoneNumberFields[] = |
|
122 { |
|
123 {QContactPhoneNumber::SubTypeLandline}, |
|
124 {QContactPhoneNumber::SubTypeMobile}, |
|
125 {QContactPhoneNumber::SubTypeFacsimile}, |
|
126 {QContactPhoneNumber::SubTypePager}, |
|
127 {QContactPhoneNumber::SubTypeVideo}, |
|
128 {QContactPhoneNumber::SubTypeVoice} , |
|
129 {QContactPhoneNumber::SubTypeAssistant}, |
|
130 {QContactPhoneNumber::SubTypeCar} |
|
131 }; |
|
132 */ |
|
133 /* |
|
134 QStringList CreatorPbkContextFields = |
|
135 { |
|
136 QContactDetail::ContextHome, |
|
137 QContactDetail::ContextWork |
|
138 }; |
|
139 */ |
|
140 QString CreatorPbkEmailFields[] = |
|
141 { |
|
142 //R_VPBK_FIELD_TYPE_EMAILGEN, |
|
143 (QContactDetail::ContextHome).operator QString(),//"Home",//R_VPBK_FIELD_TYPE_EMAILHOME, |
|
144 (QContactDetail::ContextWork).operator QString()//R_VPBK_FIELD_TYPE_EMAILWORK |
|
145 }; |
|
146 |
|
147 |
|
148 CPhonebookParameters::CPhonebookParameters() |
|
149 { |
|
150 LOGSTRING("Creator: CVirtualPhonebookParameters::CVirtualPhonebookParameters"); |
|
151 //iGroupName = HBufC::New(KPhonebookFieldLength); |
|
152 } |
|
153 |
|
154 CPhonebookParameters::~CPhonebookParameters() |
|
155 { |
|
156 LOGSTRING("Creator: CVirtualPhonebookParameters::~CVirtualPhonebookParameters"); |
|
157 |
|
158 //delete iGroupName; |
|
159 //iContactFields.ResetAndDestroy(); |
|
160 //iContactFields.Close(); |
|
161 |
|
162 //iLinkIds.clear(); |
|
163 iLinkIds.Reset(); |
|
164 iLinkIds.Close(); |
|
165 } |
|
166 |
|
167 void CPhonebookParameters::ParseL(CCommandParser* /*parser*/, TParseParams /*aCase = 0*/) |
|
168 { |
|
169 } |
|
170 |
|
171 TInt CPhonebookParameters::ScriptLinkId() const |
|
172 { |
|
173 return iLinkId; |
|
174 } |
|
175 |
|
176 void CPhonebookParameters::SetScriptLinkId(TInt aLinkId) |
|
177 { |
|
178 iLinkId = aLinkId; |
|
179 } |
|
180 |
|
181 |
|
182 //---------------------------------------------------------------------------- |
|
183 |
|
184 CCreatorPhonebook* CCreatorPhonebook::NewL(CCreatorEngine* aEngine) |
|
185 { |
|
186 CCreatorPhonebook* self = CCreatorPhonebook::NewLC(aEngine); |
|
187 CleanupStack::Pop(self); |
|
188 return self; |
|
189 } |
|
190 |
|
191 CCreatorPhonebook* CCreatorPhonebook::NewLC(CCreatorEngine* aEngine) |
|
192 { |
|
193 CCreatorPhonebook* self = new (ELeave) CCreatorPhonebook(); |
|
194 CleanupStack::PushL(self); |
|
195 self->ConstructL(aEngine); |
|
196 return self; |
|
197 } |
|
198 |
|
199 |
|
200 CCreatorPhonebook::CCreatorPhonebook() |
|
201 { |
|
202 iAddAllFields = EFalse; |
|
203 } |
|
204 |
|
205 void CCreatorPhonebook::ConstructL(CCreatorEngine* aEngine) |
|
206 { |
|
207 LOGSTRING("Creator: CCreatorPhonebook::ConstructL"); |
|
208 |
|
209 iEngine = aEngine; |
|
210 |
|
211 iContactMngr = new QContactManager("symbian"); |
|
212 |
|
213 SetDefaultParameters(); |
|
214 } |
|
215 |
|
216 |
|
217 CCreatorPhonebook::~CCreatorPhonebook() |
|
218 { |
|
219 LOGSTRING("Creator: CCreatorPhonebook::~CCreatorPhonebook"); |
|
220 |
|
221 if ( iContactsToDelete.Count() ) |
|
222 { |
|
223 TRAP_IGNORE( StoreLinksForDeleteL( iContactsToDelete, KUidDictionaryUidContacts ) ); |
|
224 } |
|
225 if ( iContactGroupsToDelete.Count() ) |
|
226 { |
|
227 TRAP_IGNORE( StoreLinksForDeleteL( iContactGroupsToDelete, KUidDictionaryUidContactGroups ) ); |
|
228 } |
|
229 |
|
230 if( iContactMngr ) |
|
231 { |
|
232 delete iContactMngr; |
|
233 } |
|
234 |
|
235 if (iParameters) |
|
236 { |
|
237 delete iParameters; |
|
238 } |
|
239 } |
|
240 |
|
241 //---------------------------------------------------------------------------- |
|
242 |
|
243 TBool CCreatorPhonebook::AskDataFromUserL(TInt aCommand, TInt& aNumberOfEntries) |
|
244 { |
|
245 LOGSTRING("Creator: CCreatorPhonebook::AskDataFromUserL"); |
|
246 |
|
247 TBool ret = CCreatorPhonebookBase::AskDataFromUserL(aCommand, aNumberOfEntries); |
|
248 |
|
249 if(ret && aCommand == ECmdCreatePhoneBookEntryContacts && !iDefaultFieldsSelected) |
|
250 { |
|
251 iAddAllFields = iEngine->GetEngineWrapper()->YesNoQueryDialog(_L("Add all the other fields to contacts?")); |
|
252 } |
|
253 return ret; |
|
254 } |
|
255 |
|
256 |
|
257 //---------------------------------------------------------------------------- |
|
258 |
|
259 TInt CCreatorPhonebook::CreateContactEntryL(CCreatorModuleBaseParameters *aParameters) |
|
260 { |
|
261 TInt err=0; |
|
262 |
|
263 InitializeContactParamsL(); |
|
264 bool success = false; |
|
265 // create a new contact item |
|
266 //iStore = new QContact(); |
|
267 |
|
268 QContact iStore; |
|
269 |
|
270 int numberOfFields = iParameters->iContactFields.count(); |
|
271 QString phone; |
|
272 for(int i=0; i< numberOfFields; i++ ) |
|
273 { |
|
274 QContactDetail* cntdet = new QContactDetail(iParameters->iContactFields.at(i)); |
|
275 success = iStore.saveDetail( cntdet ); |
|
276 delete cntdet; |
|
277 } |
|
278 |
|
279 iContactMngr->saveContact( &iStore ); |
|
280 |
|
281 iContactsToDelete.Append( (TUint32)iStore.localId() ); |
|
282 //delete iStore; |
|
283 return err; |
|
284 } |
|
285 |
|
286 |
|
287 //---------------------------------------------------------------------------- |
|
288 |
|
289 |
|
290 |
|
291 //---------------------------------------------------------------------------- |
|
292 |
|
293 void CCreatorPhonebook::DeleteAllL() |
|
294 { |
|
295 QList<QContactLocalId> contacts = iContactMngr->contactIds(); |
|
296 DeleteContactsL( contacts ); |
|
297 } |
|
298 |
|
299 //---------------------------------------------------------------------------- |
|
300 void CCreatorPhonebook::DeleteAllCreatedByCreatorL() |
|
301 { |
|
302 LOGSTRING("Creator: CCreatorPhonebook::DeleteAllCreatedByCreatorL"); |
|
303 DeleteItemsCreatedWithCreatorL( KUidDictionaryUidContacts ); |
|
304 } |
|
305 |
|
306 //---------------------------------------------------------------------------- |
|
307 void CCreatorPhonebook::DeleteAllGroupsL() |
|
308 { |
|
309 LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsL"); |
|
310 |
|
311 QList<QContactLocalId> contacts = iContactMngr->contactIds(); |
|
312 QList<QContactLocalId> groups; |
|
313 for(int i = 0; i < contacts.count(); i++) |
|
314 { |
|
315 QContact group = iContactMngr->contact( contacts.at(i) ); |
|
316 if( group.type() == QContactType::TypeGroup ) |
|
317 { |
|
318 groups.append( group.localId() ); |
|
319 } |
|
320 } |
|
321 DeleteContactsL( groups ); |
|
322 /* |
|
323 User::LeaveIfNull( iStore ); |
|
324 MVPbkContactLinkArray* groups = iStore->ContactGroupsLC(); |
|
325 DeleteContactsL( groups, ETrue ); |
|
326 CleanupStack::PopAndDestroy(); // cannot use groups as parameter |
|
327 */ |
|
328 } |
|
329 |
|
330 //---------------------------------------------------------------------------- |
|
331 void CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL() |
|
332 { |
|
333 LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL"); |
|
334 DeleteItemsCreatedWithCreatorL( KUidDictionaryUidContactGroups ); |
|
335 } |
|
336 |
|
337 //---------------------------------------------------------------------------- |
|
338 void CCreatorPhonebook::DeleteContactsL( QList<QContactLocalId>& aContacts /*MVPbkContactLinkArray* aContacts, TBool aGroup*/ ) |
|
339 { |
|
340 //QList<QContactLocalId> contacts = iContactMngr->contactIds(); |
|
341 QMap<int, QContactManager::Error> errorMap; |
|
342 iContactMngr->removeContacts( &aContacts, &errorMap ); |
|
343 } |
|
344 |
|
345 //---------------------------------------------------------------------------- |
|
346 void CCreatorPhonebook::DeleteItemsCreatedWithCreatorL( TUid aStoreUid ) |
|
347 { |
|
348 CDictionaryFileStore* store = iEngine->FileStoreLC(); |
|
349 User::LeaveIfNull( store ); |
|
350 |
|
351 QList<QContactLocalId> contacts; |
|
352 // backup previous contact links from store |
|
353 // otherwise they would be overwritten when calling out.WriteL |
|
354 TUint32 creatorLink; |
|
355 if ( store->IsPresentL( aStoreUid ) ) |
|
356 { |
|
357 RDictionaryReadStream in; |
|
358 in.OpenLC( *store, aStoreUid ); |
|
359 TRAP_IGNORE( |
|
360 do{ |
|
361 creatorLink = in.ReadUint32L(); |
|
362 QContact contact = iContactMngr->contact( creatorLink ); |
|
363 if( (contact.type() == QContactType::TypeGroup && aStoreUid == KUidDictionaryUidContactGroups ) || (contact.type() != QContactType::TypeGroup && aStoreUid != KUidDictionaryUidContactGroups) ) |
|
364 { |
|
365 contacts.append( creatorLink ); |
|
366 } |
|
367 }while( creatorLink );) |
|
368 |
|
369 CleanupStack::PopAndDestroy(); // in |
|
370 } |
|
371 |
|
372 |
|
373 DeleteContactsL( contacts ); |
|
374 |
|
375 store->Remove( aStoreUid ); |
|
376 store->CommitL(); |
|
377 |
|
378 CleanupStack::PopAndDestroy( store ); |
|
379 } |
|
380 |
|
381 //---------------------------------------------------------------------------- |
|
382 void CCreatorPhonebook::DoDeleteItemsCreatedWithCreatorL( TUid aStoreUid, CDictionaryFileStore* aStore ) |
|
383 { |
|
384 |
|
385 } |
|
386 |
|
387 //---------------------------------------------------------------------------- |
|
388 TBool CCreatorPhonebook::HasOtherThanGroupsL( /*MVPbkContactLinkArray* aContacts */) |
|
389 { |
|
390 LOGSTRING("Creator: CCreatorPhonebook::HasOtherThanGroupsL"); |
|
391 TBool result( EFalse ); |
|
392 return result; |
|
393 } |
|
394 |
|
395 QContactDetail CCreatorPhonebook::CreateContactDetail(QString aDetail, QString aFieldContext, QString aFieldString, TInt aRand ) |
|
396 { |
|
397 QContactDetail contactDetail; |
|
398 TPtrC contentData; |
|
399 if( aDetail == QContactPhoneNumber::DefinitionName) |
|
400 { |
|
401 QContactPhoneNumber phoneNumber;// = contactDetail; |
|
402 phoneNumber.setContexts(aFieldContext); |
|
403 phoneNumber.setSubTypes(aFieldString); |
|
404 contentData.Set(iEngine->RandomString((CCreatorEngine::TRandomStringType) aRand)); |
|
405 QString number = QString::fromUtf16(contentData.Ptr(),contentData.Length()); |
|
406 phoneNumber.setNumber(number); |
|
407 return phoneNumber; |
|
408 } |
|
409 else if( aDetail == QContactName::DefinitionName ) //--Contact NAME----------------------------- |
|
410 { |
|
411 QContactName contactName; |
|
412 for(int i = 0 ; i < iParameters->iContactFields.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details |
|
413 { |
|
414 if(iParameters->iContactFields.at(i).definitionName() == QContactName::DefinitionName ) |
|
415 { |
|
416 contactName = iParameters->iContactFields.at(i); |
|
417 } |
|
418 } |
|
419 contentData.Set(iEngine->RandomString((CCreatorEngine::TRandomStringType) aRand)); |
|
420 QString name = QString::fromUtf16(contentData.Ptr(),contentData.Length()); |
|
421 if(aFieldString == QContactName::FieldFirstName) |
|
422 { |
|
423 if(contactName.firstName().isEmpty()) |
|
424 { |
|
425 contactName.setFirstName( name ); |
|
426 } |
|
427 } |
|
428 else if(aFieldString == QContactName::FieldLastName) |
|
429 { |
|
430 if(contactName.lastName().isEmpty()) |
|
431 { |
|
432 contactName.setLastName( name ); |
|
433 } |
|
434 } |
|
435 else if(aFieldString == QContactName::FieldMiddleName) |
|
436 { |
|
437 if(contactName.middleName().isEmpty()) |
|
438 { |
|
439 contactName.setMiddleName( name ); |
|
440 } |
|
441 } |
|
442 else if(aFieldString == QContactName::FieldPrefix) |
|
443 { |
|
444 if(contactName.prefix().isEmpty()) |
|
445 { |
|
446 contactName.setPrefix( name ); |
|
447 } |
|
448 } |
|
449 else if(aFieldString == QContactName::FieldSuffix) |
|
450 { |
|
451 if(contactName.suffix().isEmpty()) |
|
452 { |
|
453 contactName.setSuffix( name ); |
|
454 } |
|
455 } |
|
456 else //QContactName::FieldCustomLabel: |
|
457 { |
|
458 if(contactName.customLabel().isEmpty()) |
|
459 { |
|
460 contactName.setCustomLabel( name ); |
|
461 } |
|
462 } |
|
463 return contactName; |
|
464 } |
|
465 else if( aDetail == QContactOrganization::DefinitionName ) //--Contact Company----------------------------- |
|
466 { |
|
467 QContactOrganization contactCompany; |
|
468 |
|
469 for(int i = 0 ; i < iParameters->iContactFields.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details |
|
470 { |
|
471 if(iParameters->iContactFields.at(i).definitionName() == QContactOrganization::DefinitionName ) |
|
472 { |
|
473 contactCompany = iParameters->iContactFields.at(i); |
|
474 } |
|
475 } |
|
476 contentData.Set(iEngine->RandomString((CCreatorEngine::TRandomStringType) aRand)); |
|
477 QString company = QString::fromUtf16(contentData.Ptr(),contentData.Length()); |
|
478 if(aFieldString == QContactOrganization::FieldName) |
|
479 { |
|
480 if(contactCompany.name().isEmpty()) |
|
481 { |
|
482 contactCompany.setName( company ); |
|
483 } |
|
484 } |
|
485 if(aFieldString == QContactOrganization::FieldTitle) |
|
486 { |
|
487 if(contactCompany.title().isEmpty()) |
|
488 { |
|
489 contactCompany.setTitle( company ); |
|
490 } |
|
491 } |
|
492 if(aFieldString == QContactOrganization::FieldDepartment) |
|
493 { |
|
494 //if(contactCompany.department().isEmpty()) |
|
495 //{ |
|
496 QStringList depList = contactCompany.department(); |
|
497 depList.append(company); |
|
498 contactCompany.setDepartment(depList); |
|
499 //} |
|
500 } |
|
501 if(aFieldString == QContactOrganization::FieldAssistantName) |
|
502 { |
|
503 if(contactCompany.assistantName().isEmpty()) |
|
504 { |
|
505 contactCompany.setAssistantName( company ); |
|
506 } |
|
507 } |
|
508 return contactCompany; |
|
509 } |
|
510 else if( aDetail == QContactAddress::DefinitionName ) //--Contact Address----------------------------- |
|
511 { |
|
512 QContactAddress contactAddress; |
|
513 |
|
514 for(int i = 0 ; i < iParameters->iContactFields.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details |
|
515 { |
|
516 if(iParameters->iContactFields.at(i).definitionName() == QContactAddress::DefinitionName && iParameters->iContactFields.at(i).value(QContactDetail::FieldContext) == aFieldContext ) |
|
517 { |
|
518 contactAddress = iParameters->iContactFields.at(i); |
|
519 } |
|
520 } |
|
521 |
|
522 contactAddress.setContexts( aFieldContext ); |
|
523 |
|
524 contentData.Set(iEngine->RandomString((CCreatorEngine::TRandomStringType) aRand)); |
|
525 QString address = QString::fromUtf16(contentData.Ptr(),contentData.Length()); |
|
526 if(aFieldString == QContactAddress::FieldStreet ) |
|
527 { |
|
528 if( contactAddress.street().isEmpty() ) |
|
529 { |
|
530 contactAddress.setStreet( address ); |
|
531 } |
|
532 } |
|
533 else if(aFieldString == QContactAddress::FieldLocality ) |
|
534 { |
|
535 if( contactAddress.locality().isEmpty() ) |
|
536 { |
|
537 contactAddress.setLocality( address ); |
|
538 } |
|
539 } |
|
540 else if(aFieldString == QContactAddress::FieldRegion ) |
|
541 { |
|
542 if( contactAddress.region().isEmpty() ) |
|
543 { |
|
544 contactAddress.setRegion( address ); |
|
545 } |
|
546 } |
|
547 else if(aFieldString == QContactAddress::FieldPostcode ) |
|
548 { |
|
549 if( contactAddress.postcode().isEmpty() ) |
|
550 { |
|
551 contactAddress.setPostcode( address ); |
|
552 } |
|
553 } |
|
554 else if(aFieldString == QContactAddress::FieldCountry ) |
|
555 { |
|
556 if( contactAddress.country().isEmpty() ) |
|
557 { |
|
558 contactAddress.setCountry( address ); |
|
559 } |
|
560 } |
|
561 else |
|
562 { |
|
563 return contactDetail; |
|
564 } |
|
565 return contactAddress; |
|
566 } |
|
567 else if( aDetail == QContactNote::DefinitionName ) //--Contact Note----------------------------- |
|
568 { |
|
569 QContactNote contactNote; |
|
570 contentData.Set(iEngine->RandomString((CCreatorEngine::TRandomStringType) aRand)); |
|
571 QString note = QString::fromUtf16(contentData.Ptr(),contentData.Length()); |
|
572 contactNote.setNote(note); |
|
573 return contactNote; |
|
574 } |
|
575 else if( aDetail == QContactFamily::DefinitionName ) //--Contact Family----------------------------- |
|
576 { |
|
577 QContactFamily contactFamily; |
|
578 |
|
579 for(int i = 0 ; i < iParameters->iContactFields.count() ; i++ ) //go through all contact details to check if there is already Contact Name to set other details |
|
580 { |
|
581 if(iParameters->iContactFields.at(i).definitionName() == QContactFamily::DefinitionName && iParameters->iContactFields.at(i).value(QContactDetail::FieldContext) == aFieldContext ) |
|
582 { |
|
583 contactFamily = iParameters->iContactFields.at(i); |
|
584 } |
|
585 } |
|
586 contentData.Set(iEngine->RandomString((CCreatorEngine::TRandomStringType) aRand)); |
|
587 QString familyData = QString::fromUtf16(contentData.Ptr(),contentData.Length()); |
|
588 if(aFieldString == QContactFamily::FieldSpouse ) |
|
589 { |
|
590 if( contactFamily.spouse().isEmpty() ) |
|
591 { |
|
592 contactFamily.setSpouse( familyData ); |
|
593 } |
|
594 } |
|
595 if(aFieldString == QContactFamily::FieldChildren ) |
|
596 { |
|
597 QStringList children = contactFamily.children(); |
|
598 children.append( familyData ); |
|
599 contactFamily.setChildren( children ); |
|
600 } |
|
601 |
|
602 return contactFamily; |
|
603 } |
|
604 |
|
605 if( aDetail == QContactAvatar::DefinitionName) //--Contact Picture----------------------------- |
|
606 { |
|
607 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
608 QContactAvatar contactAvatar; |
|
609 TBuf<KMaxFileName> srcPath; |
|
610 iEngine->RandomPictureFileL(srcPath); |
|
611 TBuf<KMaxFileName> destPath(KTempPath); |
|
612 |
|
613 if(!BaflUtils::FolderExists( fs, destPath )) |
|
614 { |
|
615 BaflUtils::EnsurePathExistsL( fs, destPath ); |
|
616 } |
|
617 |
|
618 TInt err=BaflUtils::CopyFile( fs, srcPath, destPath ); |
|
619 |
|
620 TParse temp; |
|
621 temp.Set( srcPath,NULL,NULL ); |
|
622 destPath.Append(temp.NameAndExt()); |
|
623 |
|
624 QString avatarFile = QString::fromUtf16( destPath.Ptr(),destPath.Length() ); |
|
625 |
|
626 QPixmap avatarPix(avatarFile); |
|
627 |
|
628 contactAvatar.setAvatar(avatarFile); |
|
629 contactAvatar.setPixmap(avatarPix); |
|
630 |
|
631 return contactAvatar; |
|
632 } |
|
633 if( aDetail == QContactAnniversary::DefinitionName) |
|
634 { |
|
635 QContactAnniversary contactAnniversary; |
|
636 QDate date; |
|
637 TTime datetime = iEngine->RandomDate( CCreatorEngine::EDateFuture ); |
|
638 date.setDate( datetime.DateTime().Year(),(int) (datetime.DateTime().Month()+1), datetime.DateTime().Day() ); |
|
639 //contactAnniversary.setEvent(QContactAnniversary::); |
|
640 contactAnniversary.setOriginalDate( date ); |
|
641 return contactAnniversary; |
|
642 } |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 return contactDetail; |
|
649 } |
|
650 //---------------------------------------------------------------------------- |
|
651 |
|
652 |
|
653 //---------------------------------------------------------------------------- |
|
654 void CCreatorPhonebook::StoreLinksForDeleteL( RArray<TUint32>& aLinks, TUid aStoreUid ) |
|
655 { |
|
656 LOGSTRING("Creator: CCreatorPhonebook::StoreLinksForDeleteL"); |
|
657 CDictionaryFileStore* store = iEngine->FileStoreLC(); |
|
658 User::LeaveIfNull( store ); |
|
659 |
|
660 // backup previous contact links from store |
|
661 // otherwise they would be overwritten when calling out.WriteL |
|
662 TUint32 previousLink; |
|
663 if ( store->IsPresentL( aStoreUid ) ) |
|
664 { |
|
665 RDictionaryReadStream in; |
|
666 in.OpenLC( *store, aStoreUid ); |
|
667 bool r = false; |
|
668 TRAP_IGNORE( |
|
669 do{ //iContactMngr->CreateLinksLC( in )) != NULL ) // will leave with KErrEof |
|
670 previousLink = in.ReadUint32L(); |
|
671 iPreviousDeleteLinks.Append( previousLink ); |
|
672 if(previousLink) |
|
673 { |
|
674 r=true; |
|
675 } |
|
676 else |
|
677 { |
|
678 r=false; |
|
679 } |
|
680 }while(r==true); ); |
|
681 |
|
682 CleanupStack::PopAndDestroy(); // in |
|
683 } |
|
684 |
|
685 RDictionaryWriteStream out; |
|
686 out.AssignLC( *store, aStoreUid ); |
|
687 |
|
688 // restore previous links |
|
689 for ( TInt i = 0; i < iPreviousDeleteLinks.Count(); i++ ) |
|
690 { |
|
691 out.WriteUint32L( iPreviousDeleteLinks[i] ); |
|
692 //CleanupStack::PopAndDestroy(); // PackLC |
|
693 } |
|
694 |
|
695 // write new links |
|
696 for(int i=0; i < aLinks.Count(); i++) |
|
697 { |
|
698 //TUint32 localId = (TUint32) aLinks[i]; |
|
699 //out.WriteUint32L( aLinks[i] ); |
|
700 out.WriteUint32L( aLinks[i] ); |
|
701 } |
|
702 out.CommitL(); |
|
703 //CleanupStack::PopAndDestroy(); // aLinks.PackLC |
|
704 CleanupStack::PopAndDestroy(); // out |
|
705 |
|
706 store->CommitL(); |
|
707 |
|
708 CleanupStack::PopAndDestroy( store ); |
|
709 } |
|
710 |
|
711 //---------------------------------------------------------------------------- |
|
712 |
|
713 //---------------------------------------------------------------------------- |
|
714 /*TInt CCreatorPhonebook::iPhoneNumberFields[] = |
|
715 { |
|
716 R_VPBK_FIELD_TYPE_LANDPHONEGEN, |
|
717 R_VPBK_FIELD_TYPE_LANDPHONEHOME, |
|
718 R_VPBK_FIELD_TYPE_LANDPHONEWORK, |
|
719 R_VPBK_FIELD_TYPE_MOBILEPHONEGEN, |
|
720 R_VPBK_FIELD_TYPE_MOBILEPHONEHOME, |
|
721 R_VPBK_FIELD_TYPE_MOBILEPHONEWORK, |
|
722 R_VPBK_FIELD_TYPE_FAXNUMBERGEN, |
|
723 R_VPBK_FIELD_TYPE_FAXNUMBERHOME, |
|
724 R_VPBK_FIELD_TYPE_FAXNUMBERWORK, |
|
725 R_VPBK_FIELD_TYPE_PAGERNUMBER, |
|
726 R_VPBK_FIELD_TYPE_VIDEONUMBERGEN, |
|
727 R_VPBK_FIELD_TYPE_VIDEONUMBERHOME, |
|
728 R_VPBK_FIELD_TYPE_VIDEONUMBERWORK, |
|
729 R_VPBK_FIELD_TYPE_VOIPGEN, |
|
730 R_VPBK_FIELD_TYPE_VOIPHOME, |
|
731 R_VPBK_FIELD_TYPE_VOIPWORK, |
|
732 R_VPBK_FIELD_TYPE_ASSTPHONE, |
|
733 R_VPBK_FIELD_TYPE_CARPHONE |
|
734 };*/ |
|
735 |
|
736 /*TInt CCreatorPhonebook::iUrlFields[] = |
|
737 { |
|
738 R_VPBK_FIELD_TYPE_URLGEN, |
|
739 R_VPBK_FIELD_TYPE_URLHOME, |
|
740 R_VPBK_FIELD_TYPE_URLWORK |
|
741 };*/ |
|
742 |
|
743 /*TInt CCreatorPhonebook::iEmailFields[] = |
|
744 { |
|
745 R_VPBK_FIELD_TYPE_EMAILGEN, |
|
746 R_VPBK_FIELD_TYPE_EMAILHOME, |
|
747 R_VPBK_FIELD_TYPE_EMAILWORK |
|
748 };*/ |
|
749 |
|
750 void CCreatorPhonebook::InitializeContactParamsL(/*CCreatorModuleBaseParameters* aParameters*/) |
|
751 { |
|
752 LOGSTRING("Creator: CCreatorPhonebook::InitializeContactParamsL"); |
|
753 |
|
754 iParameters = new (ELeave) CPhonebookParameters; |
|
755 |
|
756 iParameters->iNumberOfPhoneNumberFields = iNumberOfPhoneNumberFields; |
|
757 iParameters->iNumberOfURLFields = iNumberOfURLFields; |
|
758 iParameters->iNumberOfEmailAddressFields = iNumberOfEmailAddressFields; |
|
759 |
|
760 |
|
761 QContactName name; |
|
762 |
|
763 TPtrC fname = iEngine->RandomString(CCreatorEngine::EFirstName); |
|
764 TPtrC lname = iEngine->RandomString(CCreatorEngine::ESurname); |
|
765 QString firstname = QString::fromUtf16( fname.Ptr(), fname.Length() ); |
|
766 QString lastname = QString::fromUtf16( lname.Ptr(), lname.Length() ); |
|
767 |
|
768 name.setFirstName(firstname); |
|
769 name.setLastName(lastname); |
|
770 |
|
771 if( iAddAllFields ) |
|
772 { |
|
773 TInt textFieldCount = sizeof(CreatorPbkMiscTextFields) / sizeof(DetailFieldInfo); |
|
774 for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex ) |
|
775 { |
|
776 QContactDetail field = CreateContactDetail( CreatorPbkMiscTextFields[tfIndex].iDetail, CreatorPbkMiscTextFields[tfIndex].iFieldContext, CreatorPbkMiscTextFields[tfIndex].iFieldString, CreatorPbkMiscTextFields[tfIndex].iRandomType ); |
|
777 bool replace = false; |
|
778 for(int i = 0 ; i< iParameters->iContactFields.count() ; i++) |
|
779 { |
|
780 if( !field.isEmpty() && field.definitionName() == iParameters->iContactFields.at(i).definitionName() ) |
|
781 { |
|
782 QString context = field.value(QContactDetail::FieldContext); |
|
783 bool isContextEmpty = context.isEmpty(); |
|
784 if( isContextEmpty || ( field.value(QContactDetail::FieldContext) == iParameters->iContactFields.at(i).value(QContactDetail::FieldContext)) ) |
|
785 { |
|
786 //replace |
|
787 iParameters->iContactFields.replace(i,field); |
|
788 replace = true; |
|
789 } |
|
790 } |
|
791 } |
|
792 if(!replace) |
|
793 { |
|
794 if(!field.isEmpty()) |
|
795 { |
|
796 iParameters->iContactFields.append(field); |
|
797 } |
|
798 } |
|
799 } |
|
800 // Add binary fields: |
|
801 QContactDetail field = CreateContactDetail(QContactAvatar::DefinitionName,"","",0); |
|
802 iParameters->iContactFields.append(field); |
|
803 |
|
804 // Add date-time fields: |
|
805 QContactDetail fieldAnniv = CreateContactDetail(QContactAnniversary::DefinitionName,"","",0); |
|
806 iParameters->iContactFields.append(fieldAnniv); |
|
807 //*************************************************************************** |
|
808 // Add text fields: |
|
809 /* TInt textFieldCount = sizeof(CreatorVPbkMiscTextFields) / sizeof(FieldInfo); |
|
810 for( TInt tfIndex = 0; tfIndex < textFieldCount; ++tfIndex ) |
|
811 { |
|
812 //QContactDetail field; |
|
813 CCreatorContactField* field = CCreatorContactField::NewL(CreatorVPbkMiscTextFields[tfIndex].iFieldCode, KNullDesC); |
|
814 CleanupStack::PushL(field); |
|
815 field->SetRandomParametersL(CCreatorContactField::ERandomLengthDefault); |
|
816 iParameters->iContactFields.AppendL(field); |
|
817 CleanupStack::Pop(field); |
|
818 } |
|
819 |
|
820 // Add binary fields: |
|
821 TInt binFieldCount = sizeof(CreatorVPbkBinaryFields) / sizeof(TInt); |
|
822 for( TInt bfIndex = 0; bfIndex < binFieldCount; ++bfIndex ) |
|
823 { |
|
824 CCreatorContactField* field = CCreatorContactField::NewL(CreatorVPbkBinaryFields[bfIndex], KNullDesC8); |
|
825 CleanupStack::PushL(field); |
|
826 field->SetRandomParametersL(CCreatorContactField::ERandomLengthDefault); |
|
827 iParameters->iContactFields.AppendL(field); |
|
828 CleanupStack::Pop(field); |
|
829 } |
|
830 |
|
831 // Add date-time fields: |
|
832 TInt dtFieldCount = sizeof(CreatorVPbkDateTimeFields) / sizeof(TInt); |
|
833 for( TInt dtIndex = 0; dtIndex < dtFieldCount; ++dtIndex ) |
|
834 { |
|
835 AddFieldToParamsL(CreatorVPbkDateTimeFields[dtIndex], iEngine->RandomDate(CCreatorEngine::EDateFuture)); |
|
836 } |
|
837 |
|
838 AddFieldToParamsL(R_VPBK_FIELD_TYPE_CALLEROBJIMG, KNullDesC8); |
|
839 AddFieldToParamsL(R_VPBK_FIELD_TYPE_THUMBNAILPIC, KNullDesC8); |
|
840 AddFieldToParamsL(R_VPBK_FIELD_TYPE_CALLEROBJTEXT, firstname);*/ |
|
841 //*************************************************************************** |
|
842 |
|
843 //iParameters->iContactFields.append( name ); |
|
844 } |
|
845 else |
|
846 { |
|
847 iParameters->iContactFields.append( name ); |
|
848 } |
|
849 |
|
850 // Phone numbers: |
|
851 TInt phoneFieldCount = sizeof(CreatorPhoneNumberFields) / sizeof(PhoneNumInfo); |
|
852 |
|
853 TInt inc=0; |
|
854 for( int i=0; i<iNumberOfPhoneNumberFields; i++ ) |
|
855 { |
|
856 |
|
857 if(inc >= phoneFieldCount ) |
|
858 { |
|
859 inc = 0; |
|
860 } |
|
861 |
|
862 QContactPhoneNumber phoneNum; |
|
863 TPtrC phoneNumber = iEngine->RandomString(CCreatorEngine::EPhoneNumber); |
|
864 QString phone = QString::fromUtf16( phoneNumber.Ptr(), phoneNumber.Length() ); |
|
865 |
|
866 phoneNum.setContexts(CreatorPhoneNumberFields[inc].iFieldContext); |
|
867 phoneNum.setSubTypes(CreatorPhoneNumberFields[inc].iFieldString); |
|
868 |
|
869 |
|
870 phoneNum.setNumber( phone ); |
|
871 |
|
872 iParameters->iContactFields.append( phoneNum ); |
|
873 inc++; |
|
874 } |
|
875 |
|
876 |
|
877 |
|
878 // URLs: |
|
879 for( int i=0; i<iNumberOfURLFields; i++ ) |
|
880 { |
|
881 QContactUrl contactUrl; |
|
882 HBufC16* url = iEngine->CreateHTTPUrlLC(); |
|
883 QString urlAddress = QString::fromUtf16(url->Ptr(), url->Length() ); |
|
884 contactUrl.setUrl( urlAddress ); |
|
885 iParameters->iContactFields.append( contactUrl ); |
|
886 CleanupStack::PopAndDestroy(url); |
|
887 } |
|
888 |
|
889 // EMail addresses: |
|
890 for( int i=0; i<iNumberOfEmailAddressFields; i++ ) |
|
891 { |
|
892 QContactEmailAddress emailAddr; |
|
893 HBufC16* addr= iEngine->CreateEmailAddressLC();; |
|
894 /*TPtrC comp = iEngine->RandomString(CCreatorEngine::ECompany); |
|
895 QString company = QString::fromUtf16( comp.Ptr(), comp.Length() ); |
|
896 QString address = firstname+"@"+company+".com";*/ |
|
897 //CreatorPbkEmailFields |
|
898 QString address = QString::fromUtf16(addr->Ptr(), addr->Length() ); |
|
899 emailAddr.setEmailAddress( address ); |
|
900 emailAddr.setContexts(CreatorPbkEmailFields[i%2]); |
|
901 iParameters->iContactFields.append( emailAddr ); |
|
902 CleanupStack::PopAndDestroy(addr); |
|
903 } |
|
904 |
|
905 } |
|
906 |
|
907 |
|
908 |
|
909 // Checks if the link is a group or not |
|
910 TBool CCreatorPhonebook::IsContactGroupL() |
|
911 { |
|
912 return EFalse; |
|
913 } |
|
914 |
|
915 TInt CCreatorPhonebook::CreateGroupEntryL(CCreatorModuleBaseParameters *aParameters) |
|
916 { |
|
917 LOGSTRING("Creator: CCreatorVirtualPhonebook::CreateGroupEntryL"); |
|
918 delete iParameters; |
|
919 iParameters = 0; |
|
920 |
|
921 CPhonebookParameters* parameters = (CPhonebookParameters*) aParameters; |
|
922 |
|
923 if( !parameters ) |
|
924 { |
|
925 iParameters = new (ELeave) CPhonebookParameters; |
|
926 iParameters->iContactsInGroup = iContactsInGroup; |
|
927 TPtrC gname = iEngine->RandomString(CCreatorEngine::EGroupName); |
|
928 iParameters->iGroupName = QString::fromUtf16( gname.Ptr(),gname.Length() ); |
|
929 iParameters->iGroupName += " #"; |
|
930 int rnd = iEngine->RandomNumber(1000, 9999); |
|
931 iParameters->iGroupName += QString::number( rnd, 10 ); |
|
932 parameters = iParameters; |
|
933 } |
|
934 |
|
935 TInt err = KErrNone; |
|
936 |
|
937 // create a new contact group |
|
938 QContact newGroup; |
|
939 newGroup.setType(QContactType::TypeGroup); |
|
940 QContactName newGroupName; |
|
941 newGroupName.setCustomLabel( iParameters->iGroupName ); |
|
942 newGroup.saveDetail(&newGroupName); |
|
943 iContactMngr->saveContact(&newGroup); |
|
944 QContactLocalId newGroupId = newGroup.localId(); |
|
945 |
|
946 |
|
947 // define amounts of contacts to be added to the group |
|
948 TInt amountOfContactsToBeAdded = 0; |
|
949 if (parameters->iContactsInGroup == KCreateRandomAmountOfGroups) |
|
950 { |
|
951 amountOfContactsToBeAdded = iEngine->RandomNumber(30); |
|
952 } |
|
953 else |
|
954 { |
|
955 amountOfContactsToBeAdded = parameters->iContactsInGroup; |
|
956 } |
|
957 |
|
958 if( parameters->iLinkIds.Count() > 0 ) |
|
959 { |
|
960 for( TInt i = 0; i < parameters->iLinkIds.Count(); ++i ) |
|
961 {/* |
|
962 const CCreatorContactSet& set = ContactLinkCache::Instance()->ContactSet(parameters->iLinkIds[i].iLinkId); |
|
963 |
|
964 const RPointerArray<MVPbkContactLink>& links = set.ContactLinks(); |
|
965 TInt numberOfExplicitLinks = links.Count(); // Number of defined contacts in contact-set |
|
966 TInt numberOfExistingContacts = set.NumberOfExistingContacts(); // Number of existing contacts in contact-set |
|
967 TInt maxAmount = numberOfExplicitLinks + numberOfExistingContacts; |
|
968 |
|
969 if( parameters->iLinkIds[i].iLinkAmount > 0 ) |
|
970 maxAmount = parameters->iLinkIds[i].iLinkAmount; // Max amount is limited |
|
971 |
|
972 TInt addedMembers = 0; |
|
973 |
|
974 for( TInt j = 0; j < links.Count() && addedMembers < maxAmount; ++j ) |
|
975 { |
|
976 MVPbkContactLink* link = links[j]; |
|
977 if( link && IsContactGroupL(*link) == EFalse ) |
|
978 { |
|
979 TRAPD(err, newGroup->AddContactL(*link)); |
|
980 if( err != KErrAlreadyExists ) |
|
981 { |
|
982 // Ignore "allready exists" -error |
|
983 User::LeaveIfError(err); |
|
984 ++addedMembers; |
|
985 } |
|
986 } |
|
987 } |
|
988 if( addedMembers < maxAmount ) |
|
989 { |
|
990 // Add existing contacts, withing the limits set by maxAmount: |
|
991 amountOfContactsToBeAdded += maxAmount - addedMembers; |
|
992 }*/ |
|
993 } |
|
994 } |
|
995 if( amountOfContactsToBeAdded > 0 ) |
|
996 { |
|
997 QList<QContactLocalId> contacts = iContactMngr->contactIds(); |
|
998 QContactRelationshipFilter rFilter; |
|
999 rFilter.setRelationshipType(QContactRelationship::HasMember); |
|
1000 rFilter.setRelatedContactRole(QContactRelationshipFilter::First); |
|
1001 rFilter.setRelatedContactId( newGroup.id() ); |
|
1002 |
|
1003 int cnt = 0; |
|
1004 for(int i=0; cnt < amountOfContactsToBeAdded && i < contacts.count() ; i++ ) |
|
1005 { |
|
1006 QContact contact = iContactMngr->contact( iContactMngr->contactIds().at(i) ); |
|
1007 if( iContactMngr->error() == QContactManager::DoesNotExistError ) |
|
1008 { |
|
1009 |
|
1010 } |
|
1011 else |
|
1012 { |
|
1013 QList<QContactRelationship> relationships = contact.relationships(QContactRelationship::HasMember); |
|
1014 if(!relationships.count() && contact.type() == QContactType::TypeContact ) //just for contacts that are not in relationship - not in group yet |
|
1015 { |
|
1016 QContactRelationship* contactRel = new QContactRelationship(); |
|
1017 contactRel->setRelationshipType(QContactRelationship::HasMember); |
|
1018 contactRel->setFirst(newGroup.id()); |
|
1019 contactRel->setSecond(contact.id()); |
|
1020 iContactMngr->saveRelationship( contactRel ); |
|
1021 delete contactRel; |
|
1022 cnt++; |
|
1023 } |
|
1024 } |
|
1025 } |
|
1026 |
|
1027 // group members and their count |
|
1028 QList<QContactLocalId> groupMemberIds = iContactMngr->contactIds( rFilter ); |
|
1029 int testcnt = groupMemberIds.count(); |
|
1030 |
|
1031 |
|
1032 } |
|
1033 |
|
1034 // store the link to contact, so that Creator is able to delete |
|
1035 // it when user requests deletion of contacts that were created with Creator |
|
1036 iContactGroupsToDelete.Append( (TUint32)newGroupId ); |
|
1037 |
|
1038 return err; |
|
1039 } |
|
1040 |
|
1041 //---------------------------------------------------------------------------- |
|
1042 |
|
1043 TInt CCreatorPhonebook::CreateSubscribedContactEntryL(CCreatorModuleBaseParameters* /*aParameters*/) |
|
1044 { |
|
1045 LOGSTRING("Creator: CCreatorPhonebook::CreateSubscribedContactEntryL"); |
|
1046 |
|
1047 return KErrNotSupported; |
|
1048 } |
|
1049 |
|
1050 //---------------------------------------------------------------------------- |
|
1051 |
|
1052 //---------------------------------------------------------------------------- |
|
1053 |
|
1054 //---------------------------------------------------------------------------- |
|
1055 |