63
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "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: Phonebook 2 vCard converter.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "CPbk2vCardConverter.h"
|
|
20 |
|
|
21 |
// Phonebook 2
|
|
22 |
#include "Pbk2SendCmdUtils.h"
|
|
23 |
#include <CPbk2AttachmentFile.h>
|
|
24 |
#include <Pbk2Commands.rsg>
|
|
25 |
#include <Pbk2CmdExtRes.rsg>
|
|
26 |
#include <MPbk2ContactLinkIterator.h>
|
|
27 |
|
|
28 |
// Virtual Phonebook
|
|
29 |
#include <CVPbkVCardEng.h>
|
|
30 |
#include <MVPbkStoreContact.h>
|
|
31 |
#include <MPbk2ContactNameFormatter.h>
|
|
32 |
#include <MVPbkContactOperationBase.h>
|
|
33 |
#include <MVPbkContactStore.h>
|
|
34 |
#include <MVPbkContactFieldData.h>
|
|
35 |
#include <CVPbkContactManager.h>
|
|
36 |
#include <MVPbkFieldType.h>
|
|
37 |
#include <TVPbkFieldTypeMapping.h>
|
|
38 |
#include <MVPbkContactFieldTextData.h>
|
|
39 |
#include <MVPbkContactFieldDateTimeData.h>
|
|
40 |
#include <MVPbkContactFieldBinaryData.h>
|
|
41 |
#include <MVPbkContactFieldUriData.h>
|
|
42 |
#include <MVPbkContactLink.h>
|
|
43 |
|
|
44 |
// System includes
|
|
45 |
#include <barsread.h>
|
|
46 |
#include <coemain.h>
|
|
47 |
|
|
48 |
// Debugging headers
|
|
49 |
#include <Pbk2Debug.h>
|
|
50 |
|
|
51 |
/// Unnamed namespace for local functions
|
|
52 |
namespace {
|
|
53 |
|
|
54 |
// CONSTANTS
|
|
55 |
_LIT(KPbk2vCardFileExtension, ".vcf");
|
|
56 |
|
|
57 |
// LOCAL FUNCTIONS
|
|
58 |
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Creates an empty vCard file from the given contact.
|
|
62 |
*
|
|
63 |
* @param aFs File server session handle.
|
|
64 |
* @param aContact The contact.
|
|
65 |
* @param aNameFormatter Contact name formatter.
|
|
66 |
* @return Created vCard file.
|
|
67 |
*/
|
|
68 |
|
|
69 |
CPbk2AttachmentFile* CreateEmptyvCardFileL
|
|
70 |
( RFs& aFs, const MVPbkStoreContact& aContact,
|
|
71 |
MPbk2ContactNameFormatter& aNameFormatter )
|
|
72 |
{
|
|
73 |
// Create the file name using contact's name
|
|
74 |
HBufC* name = aNameFormatter.GetContactTitleL
|
|
75 |
( aContact.Fields(),
|
|
76 |
MPbk2ContactNameFormatter::EPreserveLeadingSpaces );
|
|
77 |
CleanupStack::PushL(name);
|
|
78 |
HBufC* fileNameBuf = HBufC::NewLC(
|
|
79 |
name->Length() + KPbk2vCardFileExtension().Length());
|
|
80 |
TPtr fileName = fileNameBuf->Des();
|
|
81 |
fileName = *name;
|
|
82 |
fileName.Append(KPbk2vCardFileExtension);
|
|
83 |
|
|
84 |
// Create attachment file object
|
|
85 |
CPbk2AttachmentFile* result = CPbk2AttachmentFile::NewL
|
|
86 |
(fileName, aFs, EFileWrite|EFileStream|EFileShareExclusive);
|
|
87 |
|
|
88 |
CleanupStack::PopAndDestroy(2); // fileNameBuf, name
|
|
89 |
return result;
|
|
90 |
}
|
|
91 |
|
|
92 |
#ifdef _DEBUG
|
|
93 |
enum TPanicCode
|
|
94 |
{
|
|
95 |
EPanicLogic_AddFieldToContactL = 1,
|
|
96 |
EPanicInvalidStorageType,
|
|
97 |
EPanicPostCond_PrepareContactL
|
|
98 |
};
|
|
99 |
|
|
100 |
void Panic(TPanicCode aReason)
|
|
101 |
{
|
|
102 |
_LIT(KPanicText, "CPbk2vCardConverter");
|
|
103 |
User::Panic(KPanicText,aReason);
|
|
104 |
}
|
|
105 |
#endif // _DEBUG
|
|
106 |
|
|
107 |
|
|
108 |
} /// namespace
|
|
109 |
|
|
110 |
|
|
111 |
// --------------------------------------------------------------------------
|
|
112 |
// CPbk2vCardConverter::CPbk2vCardConverter
|
|
113 |
// --------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
inline CPbk2vCardConverter::CPbk2vCardConverter
|
|
116 |
(RFs& aFs, CVPbkContactManager& aEngine, CVPbkVCardEng& aVCardEngine,
|
|
117 |
MPbk2ContactNameFormatter& aNameFormatter) :
|
|
118 |
CActive(EPriorityIdle),
|
|
119 |
iFs(aFs), iEngine(aEngine), iVCardEngine(aVCardEngine),
|
|
120 |
iNameFormatter(aNameFormatter), iField(NULL),
|
|
121 |
iObserver(NULL), iOpIndex(0), iFieldLevelOperation(EFalse),
|
|
122 |
iNextDriveTried(EFalse)
|
|
123 |
{
|
|
124 |
}
|
|
125 |
|
|
126 |
// --------------------------------------------------------------------------
|
|
127 |
// CPbk2vCardConverter::~CPbk2vCardConverter
|
|
128 |
// --------------------------------------------------------------------------
|
|
129 |
//
|
|
130 |
CPbk2vCardConverter::~CPbk2vCardConverter()
|
|
131 |
{
|
|
132 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
133 |
("CPbk2vCardConverter, destructor (0x%x)"), this);
|
|
134 |
Cancel();
|
|
135 |
if (iVcardFiles)
|
|
136 |
{
|
|
137 |
iVcardFiles->ResetAndDestroy();
|
|
138 |
delete iVcardFiles;
|
|
139 |
}
|
|
140 |
delete iVCardFile;
|
|
141 |
delete iRetrieveOperation;
|
|
142 |
delete iVCardContact;
|
|
143 |
iFileWriteStream.Close();
|
|
144 |
delete iContactOperation;
|
|
145 |
iContacts.Reset(); // iContacts does not own its items
|
|
146 |
}
|
|
147 |
|
|
148 |
// --------------------------------------------------------------------------
|
|
149 |
// CPbk2vCardConverter::ConstructL
|
|
150 |
// --------------------------------------------------------------------------
|
|
151 |
//
|
|
152 |
inline void CPbk2vCardConverter::ConstructL()
|
|
153 |
{
|
|
154 |
CActiveScheduler::Add(this);
|
|
155 |
iVcardFiles = new(ELeave) CPbk2AttachmentFileArray(1);
|
|
156 |
}
|
|
157 |
|
|
158 |
// --------------------------------------------------------------------------
|
|
159 |
// CPbk2vCardConverter::CPbk2vCardConverter
|
|
160 |
// --------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
CPbk2vCardConverter* CPbk2vCardConverter::NewL
|
|
163 |
( RFs& aFs, CVPbkContactManager& aEngine,
|
|
164 |
CVPbkVCardEng& aVCardEngine,
|
|
165 |
MPbk2ContactNameFormatter& aNameFormatter )
|
|
166 |
{
|
|
167 |
CPbk2vCardConverter* self = new(ELeave) CPbk2vCardConverter
|
|
168 |
( aFs,aEngine,aVCardEngine, aNameFormatter );
|
|
169 |
CleanupStack::PushL(self);
|
|
170 |
self->ConstructL();
|
|
171 |
CleanupStack::Pop(self);
|
|
172 |
return self;
|
|
173 |
}
|
|
174 |
|
|
175 |
// --------------------------------------------------------------------------
|
|
176 |
// CPbk2vCardConverter::ConvertContactL
|
|
177 |
// --------------------------------------------------------------------------
|
|
178 |
//
|
|
179 |
void CPbk2vCardConverter::ConvertContactL
|
|
180 |
( const TArray<MVPbkStoreContact*> aContacts,
|
|
181 |
const MVPbkBaseContactField* aField, TInt aDataToSend,
|
|
182 |
MPbk2vCardConverterObserver& aObserver )
|
|
183 |
{
|
|
184 |
iField = aField;
|
|
185 |
iFieldLevelOperation = ETrue;
|
|
186 |
ConvertContactsL(aContacts, aDataToSend, aObserver);
|
|
187 |
}
|
|
188 |
|
|
189 |
// --------------------------------------------------------------------------
|
|
190 |
// CPbk2vCardConverter::ConvertContactsL
|
|
191 |
// --------------------------------------------------------------------------
|
|
192 |
//
|
|
193 |
void CPbk2vCardConverter::ConvertContactsL
|
|
194 |
( const TArray<MVPbkStoreContact*> aContacts,
|
|
195 |
TInt aDataToSend, MPbk2vCardConverterObserver& aObserver )
|
|
196 |
{
|
|
197 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
198 |
("CPbk2vCardConverter::ConvertContactsL(0x%x)"), this);
|
|
199 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
200 |
("CPbk2vCardConverter::ConvertContactsL, Contacts Count=%d"),
|
|
201 |
aContacts.Count());
|
|
202 |
Reset();
|
|
203 |
iObserver = &aObserver;
|
|
204 |
iDataToSend = aDataToSend;
|
|
205 |
for (TInt i = 0; i < aContacts.Count(); ++i)
|
|
206 |
{
|
|
207 |
iContacts.AppendL(aContacts[i]);
|
|
208 |
}
|
|
209 |
|
|
210 |
Start();
|
|
211 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
212 |
("CPbk2vCardConverter::ConvertContactsL, end (0x%x)"), this);
|
|
213 |
}
|
|
214 |
|
|
215 |
// --------------------------------------------------------------------------
|
|
216 |
// CPbk2vCardConverter::ConvertContactsL
|
|
217 |
// --------------------------------------------------------------------------
|
|
218 |
//
|
|
219 |
void CPbk2vCardConverter::ConvertContactsL
|
|
220 |
( MPbk2ContactLinkIterator& aIterator, TInt aDataToSend,
|
|
221 |
MPbk2vCardConverterObserver& aObserver )
|
|
222 |
{
|
|
223 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
224 |
("CPbk2vCardConverter::ConvertContactsL, dataToSend=%d"), aDataToSend);
|
|
225 |
Reset();
|
|
226 |
iObserver = &aObserver;
|
|
227 |
iDataToSend = aDataToSend;
|
|
228 |
iIterator = &aIterator;
|
|
229 |
Start();
|
|
230 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
231 |
("CPbk2vCardConverter::ConvertContactsL, end (0x%x)"), this);
|
|
232 |
}
|
|
233 |
|
|
234 |
|
|
235 |
// --------------------------------------------------------------------------
|
|
236 |
// CPbk2vCardConverter::FileNames
|
|
237 |
// --------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
MDesC16Array& CPbk2vCardConverter::FileNames() const
|
|
240 |
{
|
|
241 |
return ( *iVcardFiles );
|
|
242 |
}
|
|
243 |
|
|
244 |
// --------------------------------------------------------------------------
|
|
245 |
// CPbk2vCardConverter::Reset
|
|
246 |
// --------------------------------------------------------------------------
|
|
247 |
//
|
|
248 |
void CPbk2vCardConverter::Reset()
|
|
249 |
{
|
|
250 |
iIterator = NULL;
|
|
251 |
iVcardFiles->ResetAndDestroy();
|
|
252 |
iDataToSend = ESendAllData;
|
|
253 |
if (!iFieldLevelOperation)
|
|
254 |
{
|
|
255 |
iField = NULL;
|
|
256 |
}
|
|
257 |
}
|
|
258 |
|
|
259 |
// --------------------------------------------------------------------------
|
|
260 |
// CPbk2vCardConverter::AttachmentFileArray
|
|
261 |
// --------------------------------------------------------------------------
|
|
262 |
//
|
|
263 |
CPbk2AttachmentFileArray& CPbk2vCardConverter::AttachmentFileArray()
|
|
264 |
{
|
|
265 |
return *iVcardFiles;
|
|
266 |
}
|
|
267 |
|
|
268 |
// --------------------------------------------------------------------------
|
|
269 |
// CPbk2vCardConverter::RunL
|
|
270 |
// --------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
void CPbk2vCardConverter::RunL()
|
|
273 |
{
|
|
274 |
if ( iIterator && iIterator->HasNext() )
|
|
275 |
{
|
|
276 |
HandleNextContactL( NULL );
|
|
277 |
}
|
|
278 |
else if (iOpIndex < iContacts.Count())
|
|
279 |
{
|
|
280 |
HandleNextContactL( iContacts[iOpIndex] );
|
|
281 |
++iOpIndex;
|
|
282 |
}
|
|
283 |
else
|
|
284 |
{
|
|
285 |
iObserver->ConversionDone(iOpIndex);
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
// --------------------------------------------------------------------------
|
|
290 |
// CPbk2vCardConverter::DoCancel
|
|
291 |
// --------------------------------------------------------------------------
|
|
292 |
//
|
|
293 |
void CPbk2vCardConverter::DoCancel()
|
|
294 |
{
|
|
295 |
// Do nothing
|
|
296 |
}
|
|
297 |
|
|
298 |
// --------------------------------------------------------------------------
|
|
299 |
// CPbk2vCardConverter::RunError
|
|
300 |
// --------------------------------------------------------------------------
|
|
301 |
//
|
|
302 |
TInt CPbk2vCardConverter::RunError(TInt aError)
|
|
303 |
{
|
|
304 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
305 |
("CPbk2vCardConverter::RunError=%d"), aError);
|
|
306 |
Reset();
|
|
307 |
iObserver->ConversionError(aError);
|
|
308 |
return aError;
|
|
309 |
}
|
|
310 |
|
|
311 |
// --------------------------------------------------------------------------
|
|
312 |
// CPbk2vCardConverter::VPbkSingleContactOperationComplete
|
|
313 |
// --------------------------------------------------------------------------
|
|
314 |
//
|
|
315 |
void CPbk2vCardConverter::VPbkSingleContactOperationComplete
|
|
316 |
( MVPbkContactOperationBase& /*aOperation*/ ,
|
|
317 |
MVPbkStoreContact* aContact )
|
|
318 |
{
|
|
319 |
if ( iRetrieveOperation )
|
|
320 |
{
|
|
321 |
delete iRetrieveOperation;
|
|
322 |
iRetrieveOperation = NULL;
|
|
323 |
TRAPD( err, HandleNextContactL( aContact ) );
|
|
324 |
delete aContact;
|
|
325 |
aContact = NULL;
|
|
326 |
if ( err != KErrNone )
|
|
327 |
{
|
|
328 |
CCoeEnv::Static()->HandleError( err );
|
|
329 |
}
|
|
330 |
}
|
|
331 |
else
|
|
332 |
{
|
|
333 |
delete iContactOperation;
|
|
334 |
iContactOperation = NULL;
|
|
335 |
|
|
336 |
// Delete temp contact
|
|
337 |
delete iVCardContact;
|
|
338 |
iVCardContact = NULL;
|
|
339 |
|
|
340 |
FinalizeVCardExport();
|
|
341 |
|
|
342 |
IssueRequest();
|
|
343 |
}
|
|
344 |
}
|
|
345 |
|
|
346 |
// --------------------------------------------------------------------------
|
|
347 |
// CPbk2vCardConverter::VPbkSingleContactOperationFailed
|
|
348 |
// --------------------------------------------------------------------------
|
|
349 |
//
|
|
350 |
void CPbk2vCardConverter::VPbkSingleContactOperationFailed
|
|
351 |
( MVPbkContactOperationBase& /*aOperation*/, TInt aError )
|
|
352 |
{
|
|
353 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
354 |
("CPbk2vCardConverter::VPbkSingleContactOperationFailed (0x%x)"), this);
|
|
355 |
if ( iRetrieveOperation )
|
|
356 |
{
|
|
357 |
delete iRetrieveOperation;
|
|
358 |
iRetrieveOperation = NULL;
|
|
359 |
}
|
|
360 |
else
|
|
361 |
{
|
|
362 |
delete iContactOperation;
|
|
363 |
iContactOperation = NULL;
|
|
364 |
|
|
365 |
iFileWriteStream.Close();
|
|
366 |
|
|
367 |
if ( iNextDriveTried )
|
|
368 |
{
|
|
369 |
delete iVCardFile;
|
|
370 |
iVCardFile = NULL;
|
|
371 |
RunError( aError );
|
|
372 |
}
|
|
373 |
else
|
|
374 |
{
|
|
375 |
TRAPD( err,
|
|
376 |
{
|
|
377 |
// Try to switch next drive if previous failed
|
|
378 |
iVCardFile->SwitchDriveL();
|
|
379 |
iFileWriteStream.Attach( iVCardFile->File() );
|
|
380 |
iContactOperation = iVCardEngine.ExportVCardL
|
|
381 |
( iFileWriteStream, *iVCardContact, *this );
|
|
382 |
}); // TRAPD
|
|
383 |
|
|
384 |
if ( err != KErrNone )
|
|
385 |
{
|
|
386 |
RunError( aError );
|
|
387 |
}
|
|
388 |
|
|
389 |
iNextDriveTried = ETrue;
|
|
390 |
}
|
|
391 |
}
|
|
392 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
393 |
("CPbk2vCardConverter::VPbkSingleContactOperationFailed, end"), this);
|
|
394 |
}
|
|
395 |
|
|
396 |
// --------------------------------------------------------------------------
|
|
397 |
// CPbk2vCardConverter::CreatevCardFileL
|
|
398 |
// Creates a file containing vCard of aContact and attaches the file to
|
|
399 |
// internal list of files.
|
|
400 |
// --------------------------------------------------------------------------
|
|
401 |
//
|
|
402 |
void CPbk2vCardConverter::CreatevCardFileL(MVPbkStoreContact* aContact)
|
|
403 |
{
|
|
404 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
405 |
("CPbk2vCardConverter::CreatevCardFileL (0x%x)"), this);
|
|
406 |
|
|
407 |
// Check first, is the contact item empty
|
|
408 |
// If the contact is not empty, file it so it gets sent
|
|
409 |
if (!Pbk2SendCmdUtils::IsContactEmpty(aContact))
|
|
410 |
{
|
|
411 |
iVCardFile = CreateEmptyvCardFileL(iFs, *aContact, iNameFormatter);
|
|
412 |
// Create temp handle, so that iVCardFile stays valid until we close
|
|
413 |
// it. Stream will take care of closing tempHandle when closing stream
|
|
414 |
RFile tempHandle;
|
|
415 |
tempHandle.Duplicate( iVCardFile->File() );
|
|
416 |
iFileWriteStream.Attach( tempHandle );
|
|
417 |
|
|
418 |
iContactOperation =
|
|
419 |
iVCardEngine.ExportVCardL(iFileWriteStream, *aContact, *this);
|
|
420 |
}
|
|
421 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
422 |
("CPbk2vCardConverter::CreatevCardFileL, end (0x%x)"), this);
|
|
423 |
}
|
|
424 |
|
|
425 |
// --------------------------------------------------------------------------
|
|
426 |
// CPbk2vCardConverter::PrepareContactL
|
|
427 |
// --------------------------------------------------------------------------
|
|
428 |
//
|
|
429 |
MVPbkStoreContact* CPbk2vCardConverter::PrepareContactL
|
|
430 |
( MVPbkStoreContact* aContact )
|
|
431 |
{
|
|
432 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
433 |
("CPbk2vCardConverter::PrepareContactL (0x%x)"), this);
|
|
434 |
MVPbkStoreContact* vCardContact = NULL;
|
|
435 |
// Create a temporary contact
|
|
436 |
vCardContact = aContact->ParentStore().CreateNewContactLC();
|
|
437 |
// Copy currently focused field's data to a dummy contact
|
|
438 |
FillTemporaryContactL(*vCardContact, *aContact, *iField);
|
|
439 |
|
|
440 |
__ASSERT_DEBUG(vCardContact, Panic(EPanicPostCond_PrepareContactL));
|
|
441 |
|
|
442 |
CleanupStack::Pop(); // vCardContact
|
|
443 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
444 |
("CPbk2vCardConverter::PrepareContactL, end (0x%x)"), this);
|
|
445 |
return vCardContact;
|
|
446 |
}
|
|
447 |
|
|
448 |
// --------------------------------------------------------------------------
|
|
449 |
// CPbk2vCardConverter::FillTemporaryContactL
|
|
450 |
// --------------------------------------------------------------------------
|
|
451 |
//
|
|
452 |
void CPbk2vCardConverter::FillTemporaryContactL
|
|
453 |
( MVPbkStoreContact& aDestItem,
|
|
454 |
const MVPbkStoreContact& aSourceItem,
|
|
455 |
const MVPbkBaseContactField& aDataField ) const
|
|
456 |
{
|
|
457 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
458 |
("CPbk2vCardConverter::FillTemporaryContactL (0x%x)"), this);
|
|
459 |
if (iDataToSend == ESendAllData)
|
|
460 |
{
|
|
461 |
TInt fieldCount = aSourceItem.Fields().FieldCount();
|
|
462 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
463 |
("CPbk2vCardConverter::FillTemporaryContactL, fieldCount=%d"),
|
|
464 |
fieldCount);
|
|
465 |
|
|
466 |
const MVPbkStoreContactFieldCollection& fieldSet =
|
|
467 |
aSourceItem.Fields();
|
|
468 |
for (TInt i=0; i < fieldCount; ++i)
|
|
469 |
{
|
|
470 |
const MVPbkStoreContactField& field = fieldSet.FieldAt(i);
|
|
471 |
AddFieldToContactL(aDestItem, field);
|
|
472 |
}
|
|
473 |
}
|
|
474 |
else if (iDataToSend == ESendAllDataWithoutPicture)
|
|
475 |
{
|
|
476 |
TInt fieldCount = aSourceItem.Fields().FieldCount();
|
|
477 |
const MVPbkStoreContactFieldCollection& fieldSet =
|
|
478 |
aSourceItem.Fields();
|
|
479 |
const MVPbkFieldType& thumbnailFieldType =
|
|
480 |
Pbk2SendCmdUtils::ReadFieldTypeFromResL(
|
|
481 |
R_THUMBNAIL_FIELD_TYPE, iEngine.FieldTypes());
|
|
482 |
const MVPbkFieldType& imageFieldType =
|
|
483 |
Pbk2SendCmdUtils::ReadFieldTypeFromResL(
|
|
484 |
R_IMAGE_FIELD_TYPE, iEngine.FieldTypes());
|
|
485 |
for (TInt i=0; i < fieldCount; ++i)
|
|
486 |
{
|
|
487 |
const MVPbkStoreContactField& field = fieldSet.FieldAt(i);
|
|
488 |
// Do not add thumbnail or image
|
|
489 |
if (!Pbk2SendCmdUtils::IsFieldMatching(
|
|
490 |
field, thumbnailFieldType, iEngine.FieldTypes()) &&
|
|
491 |
!Pbk2SendCmdUtils::IsFieldMatching(
|
|
492 |
field, imageFieldType, iEngine.FieldTypes()))
|
|
493 |
{
|
|
494 |
AddFieldToContactL(aDestItem, field);
|
|
495 |
}
|
|
496 |
}
|
|
497 |
}
|
|
498 |
else // ESendCurrentItem
|
|
499 |
{
|
|
500 |
// Actual single data field
|
|
501 |
AddFieldToContactL(aDestItem, aDataField);
|
|
502 |
|
|
503 |
// According to specification lastname & firstname
|
|
504 |
// (when existing) must be added when sending single item
|
|
505 |
const MVPbkBaseContactField* lastName =
|
|
506 |
Pbk2SendCmdUtils::FindFieldL(
|
|
507 |
aSourceItem, R_LNAME_FIELD_TYPE, iEngine.FieldTypes());
|
|
508 |
if (lastName)
|
|
509 |
{
|
|
510 |
if (!lastName->FieldData().IsEmpty())
|
|
511 |
{
|
|
512 |
AddFieldToContactL(aDestItem, *lastName);
|
|
513 |
}
|
|
514 |
}
|
|
515 |
|
|
516 |
const MVPbkBaseContactField* firstName =
|
|
517 |
Pbk2SendCmdUtils::FindFieldL(
|
|
518 |
aSourceItem, R_FNAME_FIELD_TYPE, iEngine.FieldTypes());
|
|
519 |
if (firstName)
|
|
520 |
{
|
|
521 |
if (!firstName->FieldData().IsEmpty())
|
|
522 |
{
|
|
523 |
AddFieldToContactL(aDestItem, *firstName);
|
|
524 |
}
|
|
525 |
}
|
|
526 |
}
|
|
527 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
528 |
("CPbk2vCardConverter::FillTemporaryContactL, end (0x%x)"), this);
|
|
529 |
}
|
|
530 |
|
|
531 |
// --------------------------------------------------------------------------
|
|
532 |
// CPbk2vCardConverter::AddFieldToContactL
|
|
533 |
// --------------------------------------------------------------------------
|
|
534 |
//
|
|
535 |
void CPbk2vCardConverter::AddFieldToContactL
|
|
536 |
( MVPbkStoreContact& aDestItem,
|
|
537 |
const MVPbkBaseContactField& aSourceField ) const
|
|
538 |
{
|
|
539 |
const MVPbkFieldType* fieldType = aSourceField.BestMatchingFieldType();
|
|
540 |
if ( fieldType )
|
|
541 |
{
|
|
542 |
MVPbkStoreContactField* dstField =
|
|
543 |
aDestItem.CreateFieldLC( *fieldType );
|
|
544 |
|
|
545 |
__ASSERT_DEBUG( dstField, Panic( EPanicLogic_AddFieldToContactL ) );
|
|
546 |
|
|
547 |
switch (dstField->FieldData().DataType())
|
|
548 |
{
|
|
549 |
case EVPbkFieldStorageTypeText:
|
|
550 |
{
|
|
551 |
TPtrC data = MVPbkContactFieldTextData::Cast(
|
|
552 |
aSourceField.FieldData()).Text();
|
|
553 |
MVPbkContactFieldTextData::Cast(dstField->FieldData())
|
|
554 |
.SetTextL(data);
|
|
555 |
break;
|
|
556 |
}
|
|
557 |
case EVPbkFieldStorageTypeUri:
|
|
558 |
{
|
|
559 |
TPtrC data = MVPbkContactFieldUriData::Cast(
|
|
560 |
aSourceField.FieldData()).Uri();
|
|
561 |
MVPbkContactFieldUriData::Cast(dstField->FieldData())
|
|
562 |
.SetUriL(data);
|
|
563 |
break;
|
|
564 |
}
|
|
565 |
case EVPbkFieldStorageTypeDateTime:
|
|
566 |
{
|
|
567 |
TTime time = MVPbkContactFieldDateTimeData::Cast(
|
|
568 |
aSourceField.FieldData()).DateTime();
|
|
569 |
MVPbkContactFieldDateTimeData::Cast(dstField->FieldData())
|
|
570 |
.SetDateTime(time);
|
|
571 |
break;
|
|
572 |
}
|
|
573 |
case EVPbkFieldStorageTypeBinary:
|
|
574 |
{
|
|
575 |
TPtrC8 data = MVPbkContactFieldBinaryData::Cast(
|
|
576 |
aSourceField.FieldData()).BinaryData();
|
|
577 |
MVPbkContactFieldBinaryData::Cast(dstField->FieldData())
|
|
578 |
.SetBinaryDataL(data);
|
|
579 |
break;
|
|
580 |
}
|
|
581 |
default:
|
|
582 |
{
|
|
583 |
__ASSERT_DEBUG(EFalse, Panic(EPanicInvalidStorageType));
|
|
584 |
break;
|
|
585 |
}
|
|
586 |
}
|
|
587 |
aDestItem.AddFieldL(dstField);
|
|
588 |
CleanupStack::Pop();
|
|
589 |
}
|
|
590 |
}
|
|
591 |
|
|
592 |
// --------------------------------------------------------------------------
|
|
593 |
// CPbk2vCardConverter::Start
|
|
594 |
// --------------------------------------------------------------------------
|
|
595 |
//
|
|
596 |
void CPbk2vCardConverter::Start()
|
|
597 |
{
|
|
598 |
iOpIndex = 0;
|
|
599 |
IssueRequest();
|
|
600 |
}
|
|
601 |
|
|
602 |
// --------------------------------------------------------------------------
|
|
603 |
// CPbk2vCardConverter::HandleNextContactL
|
|
604 |
// --------------------------------------------------------------------------
|
|
605 |
//
|
|
606 |
void CPbk2vCardConverter::HandleNextContactL( MVPbkStoreContact* aContact )
|
|
607 |
{
|
|
608 |
if ( aContact )
|
|
609 |
{
|
|
610 |
if (iVCardContact)
|
|
611 |
{
|
|
612 |
delete iVCardContact;
|
|
613 |
iVCardContact = NULL;
|
|
614 |
}
|
|
615 |
iVCardContact = PrepareContactL(aContact);
|
|
616 |
CreatevCardFileL(iVCardContact);
|
|
617 |
}
|
|
618 |
else
|
|
619 |
{
|
|
620 |
MVPbkContactLink* link = iIterator->NextL();
|
|
621 |
CleanupDeletePushL( link );
|
|
622 |
iRetrieveOperation = iEngine.RetrieveContactL( *link, *this );
|
|
623 |
CleanupStack::PopAndDestroy(); // link
|
|
624 |
}
|
|
625 |
}
|
|
626 |
|
|
627 |
// --------------------------------------------------------------------------
|
|
628 |
// CPbk2vCardConverter::IssueRequest
|
|
629 |
// --------------------------------------------------------------------------
|
|
630 |
//
|
|
631 |
void CPbk2vCardConverter::IssueRequest()
|
|
632 |
{
|
|
633 |
TRequestStatus* status = &iStatus;
|
|
634 |
User::RequestComplete(status, KErrNone);
|
|
635 |
SetActive();
|
|
636 |
}
|
|
637 |
|
|
638 |
// --------------------------------------------------------------------------
|
|
639 |
// CPbk2vCardConverter::FinalizeVCardExport
|
|
640 |
// --------------------------------------------------------------------------
|
|
641 |
//
|
|
642 |
void CPbk2vCardConverter::FinalizeVCardExport()
|
|
643 |
{
|
|
644 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
645 |
("CPbk2vCardConverter::FinalizeVCardExport (0x%x)"), this);
|
|
646 |
TRAPD( err,
|
|
647 |
{
|
|
648 |
// commit stream after exportvcard has completed
|
|
649 |
iFileWriteStream.CommitL();
|
|
650 |
iFileWriteStream.Close();
|
|
651 |
iVcardFiles->AppendL(iVCardFile); // Takes ownership
|
|
652 |
iVCardFile = NULL;
|
|
653 |
}); //TRAPD
|
|
654 |
|
|
655 |
if ( err != KErrNone )
|
|
656 |
{
|
|
657 |
RunError( err );
|
|
658 |
}
|
|
659 |
|
|
660 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
661 |
("CPbk2vCardConverter::FinalizeVCardExport, end (0x%x)"), this);
|
|
662 |
}
|
|
663 |
|
|
664 |
// End of File
|