46
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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 |
|
|
20 |
#include "creator_phonebook.h"
|
|
21 |
#include "creator_traces.h"
|
|
22 |
|
|
23 |
#include <CPbkContactIter.h>
|
|
24 |
|
|
25 |
//----------------------------------------------------------------------------
|
|
26 |
|
|
27 |
CPhonebookParameters::CPhonebookParameters()
|
|
28 |
{
|
|
29 |
LOGSTRING("Creator: CPhonebookParameters::CPhonebookParameters");
|
|
30 |
|
|
31 |
iContactFirstName = HBufC::New(KPhonebookFieldLength);
|
|
32 |
iContactLastName = HBufC::New(KPhonebookFieldLength);
|
|
33 |
iContactCompanyName = HBufC::New(KPhonebookFieldLength);
|
|
34 |
iContactJobTitle = HBufC::New(KPhonebookFieldLength);
|
|
35 |
iContactPostalAddress = HBufC::New(KPhonebookFieldLength);
|
|
36 |
iWvUserId = HBufC::New(KPhonebookFieldLength);
|
|
37 |
iRingingtone = HBufC::New(KPhonebookFieldLength);
|
|
38 |
iThumbnailImage = HBufC::New(KPhonebookFieldLength);
|
|
39 |
iContactPhoneNumberGeneral = HBufC::New(KPhonebookFieldLength);
|
|
40 |
iContactURL = HBufC::New(KPhonebookFieldLength);
|
|
41 |
iContactEmailAddress = HBufC::New(KPhonebookFieldLength);
|
|
42 |
iGroupName = HBufC::New(KPhonebookFieldLength);
|
|
43 |
}
|
|
44 |
|
|
45 |
CPhonebookParameters::~CPhonebookParameters()
|
|
46 |
{
|
|
47 |
LOGSTRING("Creator: CPhonebookParameters::~CPhonebookParameters");
|
|
48 |
|
|
49 |
delete iGroupName;
|
|
50 |
delete iContactEmailAddress;
|
|
51 |
delete iContactURL;
|
|
52 |
delete iContactPhoneNumberGeneral;
|
|
53 |
delete iThumbnailImage;
|
|
54 |
delete iRingingtone;
|
|
55 |
delete iWvUserId;
|
|
56 |
delete iContactPostalAddress;
|
|
57 |
delete iContactJobTitle;
|
|
58 |
delete iContactCompanyName;
|
|
59 |
delete iContactLastName;
|
|
60 |
delete iContactFirstName;
|
|
61 |
}
|
|
62 |
void CPhonebookParameters::ParseL (CCommandParser* parser, TParseParams /*aCase = 0*/)
|
|
63 |
{
|
|
64 |
parser->StrParserL (iContactFirstName, '|');
|
|
65 |
parser->StrParserL (iContactLastName, '|');
|
|
66 |
parser->StrParserL (iContactCompanyName, '|');
|
|
67 |
parser->StrParserL (iContactJobTitle, '|');
|
|
68 |
parser->StrParserL (iContactPostalAddress, '|');
|
|
69 |
parser->StrParserL (iContactPhoneNumberGeneral, '|');
|
|
70 |
parser->StrParserL (iContactURL, '|');
|
|
71 |
parser->StrParserL (iContactEmailAddress, '|');
|
|
72 |
parser->StrParserL (iWvUserId, '|');
|
|
73 |
parser->StrParserL (iRingingtone, '|');
|
|
74 |
parser->StrParserL (iThumbnailImage, ';');
|
|
75 |
}
|
|
76 |
//----------------------------------------------------------------------------
|
|
77 |
|
|
78 |
CCreatorPhonebook* CCreatorPhonebook::NewL(CCreatorEngine* aEngine)
|
|
79 |
{
|
|
80 |
CCreatorPhonebook* self = CCreatorPhonebook::NewLC(aEngine);
|
|
81 |
CleanupStack::Pop(self);
|
|
82 |
return self;
|
|
83 |
}
|
|
84 |
|
|
85 |
CCreatorPhonebook* CCreatorPhonebook::NewLC(CCreatorEngine* aEngine)
|
|
86 |
{
|
|
87 |
CCreatorPhonebook* self = new (ELeave) CCreatorPhonebook;
|
|
88 |
CleanupStack::PushL(self);
|
|
89 |
self->ConstructL(aEngine);
|
|
90 |
return self;
|
|
91 |
}
|
|
92 |
|
|
93 |
CCreatorPhonebook::CCreatorPhonebook()
|
|
94 |
{
|
|
95 |
}
|
|
96 |
|
|
97 |
void CCreatorPhonebook::ConstructL(CCreatorEngine* aEngine)
|
|
98 |
{
|
|
99 |
LOGSTRING("Creator: CCreatorPhonebook::ConstructL");
|
|
100 |
|
|
101 |
iEngine = aEngine;
|
|
102 |
iContactDBEngine = CPbkContactEngine::NewL();
|
|
103 |
iOpCounter = 0;
|
|
104 |
SetDefaultParameters();
|
|
105 |
}
|
|
106 |
|
|
107 |
CCreatorPhonebook::~CCreatorPhonebook()
|
|
108 |
{
|
|
109 |
LOGSTRING("Creator: CCreatorPhonebook::~CCreatorPhonebook");
|
|
110 |
|
|
111 |
if ( iEngine && iContactIds.Count() )
|
|
112 |
{
|
|
113 |
TRAP_IGNORE( iEngine->WriteEntryIdsToStoreL( iContactIds, KUidDictionaryUidContacts ) );
|
|
114 |
}
|
|
115 |
iContactIds.Reset();
|
|
116 |
iContactIds.Close();
|
|
117 |
|
|
118 |
if ( iEngine && iGroupIds.Count() )
|
|
119 |
{
|
|
120 |
TRAP_IGNORE( iEngine->WriteEntryIdsToStoreL( iGroupIds, KUidDictionaryUidContactGroups ) );
|
|
121 |
}
|
|
122 |
iGroupIds.Reset();
|
|
123 |
iGroupIds.Close();
|
|
124 |
|
|
125 |
iEntriesToDelete.Reset();
|
|
126 |
iEntriesToDelete.Close();
|
|
127 |
|
|
128 |
CompactPbkDatabase( ETrue );
|
|
129 |
|
|
130 |
delete iContactDBEngine;
|
|
131 |
|
|
132 |
if (iParameters)
|
|
133 |
delete iParameters;
|
|
134 |
}
|
|
135 |
|
|
136 |
//----------------------------------------------------------------------------
|
|
137 |
TInt CCreatorPhonebook::CreateContactEntryL(CCreatorModuleBaseParameters *aParameters)
|
|
138 |
{
|
|
139 |
LOGSTRING("Creator: CCreatorPhonebook::CreateContactEntryL");
|
|
140 |
|
|
141 |
delete iParameters;
|
|
142 |
iParameters = 0;
|
|
143 |
|
|
144 |
CPhonebookParameters* parameters = (CPhonebookParameters*) aParameters;
|
|
145 |
|
|
146 |
// random data needed if no predefined data available
|
|
147 |
if (!parameters)
|
|
148 |
{
|
|
149 |
iParameters = new(ELeave) CPhonebookParameters;
|
|
150 |
|
|
151 |
iParameters->iNumberOfPhoneNumberFields = iNumberOfPhoneNumberFields;
|
|
152 |
iParameters->iNumberOfURLFields = iNumberOfURLFields;
|
|
153 |
iParameters->iNumberOfEmailAddressFields = iNumberOfEmailAddressFields;
|
|
154 |
|
|
155 |
iParameters->iNumberOfPhoneNumberFields = iNumberOfPhoneNumberFields;
|
|
156 |
iParameters->iNumberOfURLFields = iNumberOfURLFields;
|
|
157 |
iParameters->iNumberOfEmailAddressFields = iNumberOfEmailAddressFields;
|
|
158 |
|
|
159 |
iParameters->iContactFirstName->Des() = iEngine->RandomString(CCreatorEngine::EFirstName);
|
|
160 |
iParameters->iContactLastName->Des() = iEngine->RandomString(CCreatorEngine::ESurname);
|
|
161 |
iParameters->iContactCompanyName->Des() = iEngine->RandomString(CCreatorEngine::ECompany);
|
|
162 |
iParameters->iContactJobTitle->Des() = iEngine->RandomString(CCreatorEngine::EJobTitle);
|
|
163 |
iParameters->iContactPostalAddress->Des() = iEngine->RandomString(CCreatorEngine::EAddress);
|
|
164 |
|
|
165 |
iParameters->iWvUserId->Des().Copy(_L("wv:"));
|
|
166 |
iParameters->iWvUserId->Des().Append(iParameters->iContactFirstName->Des());
|
|
167 |
|
|
168 |
// TO-DO.....
|
|
169 |
//iParameters->iRingingtone->Des() = KNullDesC;
|
|
170 |
//iParameters->iThumbnailImage->Des() = KNullDesC;
|
|
171 |
|
|
172 |
iParameters->iContactPhoneNumberGeneral->Des() = iEngine->RandomString(CCreatorEngine::EPhoneNumber);
|
|
173 |
|
|
174 |
iParameters->iContactURL->Des().Copy( _L("http://www.") );
|
|
175 |
iParameters->iContactURL->Des().Append( iParameters->iContactCompanyName->Des() );
|
|
176 |
iParameters->iContactURL->Des().Append( _L(".com/") );
|
|
177 |
|
|
178 |
iParameters->iContactEmailAddress->Des().Copy( iParameters->iContactFirstName->Des() );
|
|
179 |
iParameters->iContactEmailAddress->Des().Append( _L("@") );
|
|
180 |
iParameters->iContactEmailAddress->Des().Append( iParameters->iContactCompanyName->Des() );
|
|
181 |
iParameters->iContactEmailAddress->Des().Append( _L(".com") );
|
|
182 |
|
|
183 |
}
|
|
184 |
else
|
|
185 |
{
|
|
186 |
iParameters = parameters;
|
|
187 |
}
|
|
188 |
|
|
189 |
TInt err = KErrNone;
|
|
190 |
|
|
191 |
// create a new contact item based on the default template
|
|
192 |
CPbkContactItem* newContact = iContactDBEngine->CreateEmptyContactL();
|
|
193 |
CleanupStack::PushL(newContact);
|
|
194 |
|
|
195 |
AddFieldToContactItemL (*newContact, EPbkFieldIdFirstName, iParameters->iContactFirstName->Des());
|
|
196 |
AddFieldToContactItemL (*newContact, EPbkFieldIdLastName, iParameters->iContactLastName->Des());
|
|
197 |
AddFieldToContactItemL (*newContact, EPbkFieldIdCompanyName, iParameters->iContactCompanyName->Des());
|
|
198 |
AddFieldToContactItemL (*newContact, EPbkFieldIdJobTitle, iParameters->iContactJobTitle->Des());
|
|
199 |
AddFieldToContactItemL (*newContact, EPbkFieldIdPostalAddress, iParameters->iContactPostalAddress->Des());
|
|
200 |
|
|
201 |
AddFieldToContactItemL (*newContact, EPbkFieldIdWVID, iParameters->iWvUserId->Des());
|
|
202 |
AddFieldToContactItemL (*newContact, EPbkFieldIdPersonalRingingToneIndication, iParameters->iRingingtone->Des());
|
|
203 |
AddFieldToContactItemL (*newContact, EPbkFieldIdThumbnailImage, iParameters->iThumbnailImage->Des());
|
|
204 |
|
|
205 |
for (TInt i=0; i<iParameters->iNumberOfPhoneNumberFields; i++)
|
|
206 |
{
|
|
207 |
if (i%6 == 0)
|
|
208 |
AddFieldToContactItemL (*newContact, EPbkFieldIdPhoneNumberGeneral, iParameters->iContactPhoneNumberGeneral->Des());
|
|
209 |
else if (i%6 == 1)
|
|
210 |
AddFieldToContactItemL (*newContact, EPbkFieldIdPhoneNumberMobile, iParameters->iContactPhoneNumberGeneral->Des());
|
|
211 |
else if (i%6 == 2)
|
|
212 |
AddFieldToContactItemL (*newContact, EPbkFieldIdFaxNumber, iParameters->iContactPhoneNumberGeneral->Des());
|
|
213 |
else if (i%6 == 3)
|
|
214 |
AddFieldToContactItemL (*newContact, EPbkFieldIdPagerNumber, iParameters->iContactPhoneNumberGeneral->Des());
|
|
215 |
else if (i%6 == 4)
|
|
216 |
AddFieldToContactItemL (*newContact, EPbkFieldIdPhoneNumberHome, iParameters->iContactPhoneNumberGeneral->Des());
|
|
217 |
else
|
|
218 |
AddFieldToContactItemL (*newContact, EPbkFieldIdPhoneNumberWork, iParameters->iContactPhoneNumberGeneral->Des());
|
|
219 |
}
|
|
220 |
|
|
221 |
for (TInt j=0; j<iParameters->iNumberOfURLFields; j++)
|
|
222 |
AddFieldToContactItemL (*newContact, EPbkFieldIdURL, iParameters->iContactURL->Des());
|
|
223 |
|
|
224 |
for (TInt k=0; k<iParameters->iNumberOfEmailAddressFields; k++)
|
|
225 |
AddFieldToContactItemL (*newContact, EPbkFieldIdEmailAddress, iParameters->iContactEmailAddress->Des());
|
|
226 |
|
|
227 |
|
|
228 |
// add the contact item to the database
|
|
229 |
iContactDBEngine->AddNewContactL(*newContact);
|
|
230 |
|
|
231 |
// id has been generated, store it for being able to delete
|
|
232 |
// entries created only with Creator
|
|
233 |
iContactIds.Append( newContact->Id() );
|
|
234 |
|
|
235 |
CleanupStack::PopAndDestroy(); // newContact
|
|
236 |
|
|
237 |
CompactPbkDatabase();
|
|
238 |
|
|
239 |
return err;
|
|
240 |
}
|
|
241 |
|
|
242 |
//----------------------------------------------------------------------------
|
|
243 |
|
|
244 |
TInt CCreatorPhonebook::CreateGroupEntryL(CCreatorModuleBaseParameters *aParameters)
|
|
245 |
{
|
|
246 |
LOGSTRING("Creator: CCreatorPhonebook::CreateGroupEntryL");
|
|
247 |
|
|
248 |
// clear any existing parameter definations
|
|
249 |
if (iParameters)
|
|
250 |
{
|
|
251 |
delete iParameters;
|
|
252 |
iParameters = NULL;
|
|
253 |
}
|
|
254 |
|
|
255 |
// random data needed if no predefined data available
|
|
256 |
if (!aParameters)
|
|
257 |
{
|
|
258 |
iParameters = new(ELeave) CPhonebookParameters;
|
|
259 |
|
|
260 |
iParameters->iContactsInGroup = iContactsInGroup;
|
|
261 |
|
|
262 |
iParameters->iGroupName->Des().Copy( iEngine->RandomString(CCreatorEngine::EGroupName) );
|
|
263 |
iParameters->iGroupName->Des().Append( _L(" #") );
|
|
264 |
iParameters->iGroupName->Des().AppendNum( iEngine->RandomNumber(1000, 9999) );
|
|
265 |
}
|
|
266 |
else
|
|
267 |
{
|
|
268 |
// otherwise replace the parameters object
|
|
269 |
iParameters = (CPhonebookParameters*) aParameters;
|
|
270 |
}
|
|
271 |
|
|
272 |
TInt err(KErrNone);
|
|
273 |
|
|
274 |
// create contact iterator
|
|
275 |
CPbkContactIter* contactIter = iContactDBEngine->CreateContactIteratorLC();
|
|
276 |
|
|
277 |
// create contact id array
|
|
278 |
CContactIdArray* contactIdArray = CContactIdArray::NewLC();
|
|
279 |
|
|
280 |
// get all contacts
|
|
281 |
TBool getFirstContact(ETrue);
|
|
282 |
TContactItemId contactId;
|
|
283 |
|
|
284 |
for (;;)
|
|
285 |
{
|
|
286 |
if (getFirstContact)
|
|
287 |
{
|
|
288 |
// get first contact
|
|
289 |
contactId = contactIter->FirstL();
|
|
290 |
getFirstContact = EFalse;
|
|
291 |
}
|
|
292 |
else
|
|
293 |
{
|
|
294 |
// get next contact
|
|
295 |
contactId = contactIter->NextL();
|
|
296 |
}
|
|
297 |
|
|
298 |
// check if valid contact id received
|
|
299 |
if (contactId == KNullContactId)
|
|
300 |
{
|
|
301 |
// no more contacts, so break
|
|
302 |
break;
|
|
303 |
}
|
|
304 |
else
|
|
305 |
{
|
|
306 |
// append to array
|
|
307 |
contactIdArray->AddL(contactId);
|
|
308 |
}
|
|
309 |
}
|
|
310 |
|
|
311 |
// create a new contact group
|
|
312 |
CContactGroup* newGroup = iContactDBEngine->CreateContactGroupL( iParameters->iGroupName->Des() );
|
|
313 |
CleanupStack::PushL(newGroup);
|
|
314 |
|
|
315 |
// define amounts of contacts to be added to the group
|
|
316 |
TInt amountOfContactsToBeAdded;
|
|
317 |
if (iParameters->iContactsInGroup == KCreateRandomAmountOfGroups)
|
|
318 |
amountOfContactsToBeAdded = iEngine->RandomNumber(30);
|
|
319 |
else
|
|
320 |
amountOfContactsToBeAdded = iParameters->iContactsInGroup;
|
|
321 |
|
|
322 |
|
|
323 |
// a simple way to randomise order of contacts in the array
|
|
324 |
if (iEngine->RandomNumber(1, 2) == 1)
|
|
325 |
contactIdArray->ReverseOrder();
|
|
326 |
|
|
327 |
// assign contacts from the array to the group if any contacts available
|
|
328 |
if (contactIdArray->Count() > 0)
|
|
329 |
{
|
|
330 |
// get random start number which defines from which position to start adding contacts
|
|
331 |
TInt arrayPosCounter = iEngine->RandomNumber(contactIdArray->Count()-1);
|
|
332 |
TInt addedContacsCounter(0);
|
|
333 |
|
|
334 |
for (TInt y=0; y<amountOfContactsToBeAdded; y++)
|
|
335 |
{
|
|
336 |
// add contact to group
|
|
337 |
iContactDBEngine->AddContactToGroupL((*contactIdArray)[arrayPosCounter], newGroup->Id());
|
|
338 |
addedContacsCounter++;
|
|
339 |
arrayPosCounter++;
|
|
340 |
|
|
341 |
// no need to add more contacts than actually available
|
|
342 |
if (addedContacsCounter >= contactIdArray->Count())
|
|
343 |
break;
|
|
344 |
|
|
345 |
// if limit reached, start from the beginning
|
|
346 |
if (arrayPosCounter >= contactIdArray->Count())
|
|
347 |
arrayPosCounter = 0;
|
|
348 |
}
|
|
349 |
}
|
|
350 |
|
|
351 |
// id has been generated, store it for being able to delete
|
|
352 |
// entries created only with Creator
|
|
353 |
iGroupIds.Append( newGroup->Id() );
|
|
354 |
|
|
355 |
CleanupStack::PopAndDestroy(3); // newGroup, contactIdArray, contactIter
|
|
356 |
|
|
357 |
CompactPbkDatabase();
|
|
358 |
|
|
359 |
return err;
|
|
360 |
}
|
|
361 |
|
|
362 |
|
|
363 |
//----------------------------------------------------------------------------
|
|
364 |
|
|
365 |
TInt CCreatorPhonebook::CreateSubscribedContactEntryL(CCreatorModuleBaseParameters* /*aParameters*/)
|
|
366 |
{
|
|
367 |
LOGSTRING("Creator: CCreatorPhonebook::CreateSubscribedContactEntryL");
|
|
368 |
|
|
369 |
return KErrNotSupported;
|
|
370 |
}
|
|
371 |
|
|
372 |
//----------------------------------------------------------------------------
|
|
373 |
|
|
374 |
void CCreatorPhonebook::AddFieldToContactItemL(CPbkContactItem& aItem, TPbkFieldId aFieldId, const TDesC& aFieldText)
|
|
375 |
{
|
|
376 |
//LOGSTRING("Creator: CCreatorPhonebook::AddFieldToContactItemL");
|
|
377 |
|
|
378 |
CPbkFieldInfo* fieldInfo = iContactDBEngine->FieldsInfo().Find( aFieldId );
|
|
379 |
if( fieldInfo ) // field was found
|
|
380 |
{
|
|
381 |
// add the field and value to contact
|
|
382 |
TPbkContactItemField* itemField = aItem.AddOrReturnUnusedFieldL( *fieldInfo );
|
|
383 |
|
|
384 |
if( itemField && aFieldText.Length() > 0 ) // add text also
|
|
385 |
{
|
|
386 |
if( itemField->ItemField().StorageType() == KStorageTypeText )
|
|
387 |
{
|
|
388 |
CContactTextField* textField = itemField->ItemField().TextStorage();
|
|
389 |
|
|
390 |
// clip the text if it doesn't fit to the field
|
|
391 |
textField->SetTextL( aFieldText.Left( fieldInfo->MaxLength() ) );
|
|
392 |
}
|
|
393 |
}
|
|
394 |
}
|
|
395 |
}
|
|
396 |
|
|
397 |
//----------------------------------------------------------------------------
|
|
398 |
|
|
399 |
void CCreatorPhonebook::CompactPbkDatabase(TBool aCompressImmediately)
|
|
400 |
{
|
|
401 |
LOGSTRING("Creator: CCreatorPhonebook::CompactPbkDatabase");
|
|
402 |
|
|
403 |
iOpCounter++;
|
|
404 |
|
|
405 |
// compress the database immediately or after each 100th operation
|
|
406 |
if (aCompressImmediately || iOpCounter%100 == 0)
|
|
407 |
{
|
|
408 |
CContactDatabase& db = iContactDBEngine->Database();
|
|
409 |
|
|
410 |
if (db.CompressRequired())
|
|
411 |
{
|
|
412 |
LOGSTRING("Creator: CCreatorPhonebook::CompactPbkDatabase - Compacting...");
|
|
413 |
TRAP_IGNORE( db.CompactL() );
|
|
414 |
}
|
|
415 |
}
|
|
416 |
}
|
|
417 |
//----------------------------------------------------------------------------
|
|
418 |
void CCreatorPhonebook::DeleteAllL()
|
|
419 |
{
|
|
420 |
LOGSTRING("Creator: CCreatorPhonebook::DeleteAllL");
|
|
421 |
DeleteAllItemsL( KUidDictionaryUidContacts );
|
|
422 |
iContactIds.Reset();
|
|
423 |
}
|
|
424 |
|
|
425 |
//----------------------------------------------------------------------------
|
|
426 |
void CCreatorPhonebook::DeleteAllCreatedByCreatorL()
|
|
427 |
{
|
|
428 |
LOGSTRING("Creator: CCreatorPhonebook::DeleteAllCreatedByCreatorL");
|
|
429 |
DeleteItemsCreatedWithCreatorL( KUidDictionaryUidContacts );
|
|
430 |
iContactIds.Reset();
|
|
431 |
}
|
|
432 |
|
|
433 |
//----------------------------------------------------------------------------
|
|
434 |
void CCreatorPhonebook::DeleteAllGroupsL()
|
|
435 |
{
|
|
436 |
LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsL");
|
|
437 |
DeleteAllItemsL( KUidDictionaryUidContactGroups );
|
|
438 |
iGroupIds.Reset();
|
|
439 |
}
|
|
440 |
|
|
441 |
//----------------------------------------------------------------------------
|
|
442 |
void CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL()
|
|
443 |
{
|
|
444 |
LOGSTRING("Creator: CCreatorPhonebook::DeleteAllGroupsCreatedByCreatorL");
|
|
445 |
DeleteItemsCreatedWithCreatorL( KUidDictionaryUidContactGroups );
|
|
446 |
iGroupIds.Reset();
|
|
447 |
}
|
|
448 |
|
|
449 |
//----------------------------------------------------------------------------
|
|
450 |
void CCreatorPhonebook::DeleteAllItemsL( TUid aStoreUid )
|
|
451 |
{
|
|
452 |
LOGSTRING("Creator: CCreatorPhonebook::DeleteItemsL");
|
|
453 |
__ASSERT_ALWAYS( aStoreUid == KUidDictionaryUidContacts ||
|
|
454 |
aStoreUid == KUidDictionaryUidContactGroups,
|
|
455 |
User::Panic( _L("CCreatorPb"), KErrArgument ) );
|
|
456 |
|
|
457 |
CContactIdArray* allContacts = iContactDBEngine->FindLC( _L("") );
|
|
458 |
|
|
459 |
CPbkContactItem* item;
|
|
460 |
TInt i(0);
|
|
461 |
// remove that type of item ids from the array
|
|
462 |
// that we don't want to delete
|
|
463 |
while( allContacts && i < allContacts->Count() )
|
|
464 |
{
|
|
465 |
item = iContactDBEngine->ReadContactL( (*allContacts)[i] );
|
|
466 |
if ( ( aStoreUid == KUidDictionaryUidContactGroups ) ==
|
|
467 |
( item->Type() != KUidContactGroup ) )
|
|
468 |
{
|
|
469 |
allContacts->Remove( i );
|
|
470 |
}
|
|
471 |
else
|
|
472 |
{
|
|
473 |
i++;
|
|
474 |
}
|
|
475 |
delete item;
|
|
476 |
item = NULL;
|
|
477 |
}
|
|
478 |
iContactDBEngine->DeleteContactsL( *allContacts );
|
|
479 |
CleanupStack::PopAndDestroy( allContacts );
|
|
480 |
|
|
481 |
// contacts deleted, remove the store
|
|
482 |
CDictionaryFileStore* store = iEngine->FileStoreLC();
|
|
483 |
if ( store )
|
|
484 |
{
|
|
485 |
store->Remove( aStoreUid );
|
|
486 |
store->CommitL();
|
|
487 |
}
|
|
488 |
CleanupStack::PopAndDestroy( store );
|
|
489 |
}
|
|
490 |
|
|
491 |
//----------------------------------------------------------------------------
|
|
492 |
void CCreatorPhonebook::DeleteItemsCreatedWithCreatorL( TUid aStoreUid )
|
|
493 |
{
|
|
494 |
LOGSTRING("Creator: CCreatorPhonebook::DeleteItemsCreatedWithCreatorL");
|
|
495 |
__ASSERT_ALWAYS( aStoreUid == KUidDictionaryUidContacts ||
|
|
496 |
aStoreUid == KUidDictionaryUidContactGroups,
|
|
497 |
User::Panic( _L("CCreatorPb"), KErrArgument ) );
|
|
498 |
|
|
499 |
iEntriesToDelete.Reset();
|
|
500 |
|
|
501 |
// fetch ids of entries created by Creator
|
|
502 |
iEngine->ReadEntryIdsFromStoreL( iEntriesToDelete, aStoreUid );
|
|
503 |
|
|
504 |
// delete entries
|
|
505 |
for ( TInt i = 0; i < iEntriesToDelete.Count(); i++ )
|
|
506 |
{
|
|
507 |
TRAP_IGNORE( iContactDBEngine->DeleteContactL( iEntriesToDelete[i] ) );
|
|
508 |
}
|
|
509 |
|
|
510 |
iEntriesToDelete.Reset();
|
|
511 |
|
|
512 |
// all entries deleted, remove the Logs related registry
|
|
513 |
iEngine->RemoveStoreL( aStoreUid );
|
|
514 |
}
|