63
|
1 |
/*
|
|
2 |
* Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "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: Exporting the contact field from contact to
|
|
15 |
* CParserProperty field
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
#include "CVPbkVCardPropertyExporter.h"
|
|
21 |
#include "CVPbkVCardParserParamArray.h"
|
|
22 |
#include "CVPbkVCardFieldTypeProperty.h"
|
|
23 |
#include "CVPbkVCardIdNameMapping.h"
|
|
24 |
#include "VPbkVCardEngError.h"
|
|
25 |
#include "CVPbkVCardData.h"
|
|
26 |
#include <MVPbkContactStore.h>
|
|
27 |
#include <MVPbkBaseContactField.h>
|
|
28 |
#include <MVPbkStoreContact.h>
|
|
29 |
#include <MVPbkStoreContactFieldCollection.h>
|
|
30 |
#include <TVPbkFieldVersitProperty.h>
|
|
31 |
#include <MVPbkContactFieldTextData.h>
|
|
32 |
#include <MVPbkContactFieldUriData.h>
|
|
33 |
#include <MVPbkContactFieldDateTimeData.h>
|
|
34 |
#include <MVPbkContactFieldBinaryData.h>
|
|
35 |
#include <VPbkError.h>
|
|
36 |
#include <MVPbkSingleContactOperationObserver.h>
|
|
37 |
#include <CVPbkContactManager.h>
|
|
38 |
#include <MVPbkContactAttributeManager.h>
|
|
39 |
#include <CVPbkDefaultAttribute.h>
|
|
40 |
#include <CVPbkLocalVariationManager.h>
|
|
41 |
|
|
42 |
// System includes
|
|
43 |
#include <vcard.h>
|
|
44 |
#include <bldvariant.hrh>
|
|
45 |
|
|
46 |
// Debug includes
|
|
47 |
#include <VPbkDebug.h>
|
|
48 |
|
|
49 |
#include <centralrepository.h>
|
|
50 |
#include <MVPbkStoreContactProperties.h>
|
|
51 |
|
|
52 |
// CONSTANTS
|
|
53 |
const TInt KNsmlDsGeoField = 0x0000; // defined in DS cenrep
|
|
54 |
const TUid KCRUidGeoFieldInternalKeys = { 0x20022EE1 }; // 0x20022EE1 defined in DS cenrep
|
|
55 |
|
|
56 |
_LIT8(KGEO, "GEO");
|
|
57 |
_LIT8(KREV, "REV");
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
namespace
|
|
62 |
{
|
|
63 |
_LIT8(KPropEncoding, "ENCODING");
|
|
64 |
_LIT8(KPropBase64, "BASE64");
|
|
65 |
_LIT8(KPropType, "TYPE");
|
|
66 |
_LIT(KFormatJPEG, "JPEG");
|
|
67 |
_LIT8(KPropPREF, "PREF");
|
|
68 |
const TInt KOne = 1;
|
|
69 |
}
|
|
70 |
|
|
71 |
CVPbkVCardPropertyExporter* CVPbkVCardPropertyExporter::NewLC(
|
|
72 |
CVPbkVCardData& aData,
|
|
73 |
const MVPbkStoreContact* aSourceItem,
|
|
74 |
RWriteStream& aDestStream,
|
|
75 |
MVPbkSingleContactOperationObserver& aObserver,
|
|
76 |
const TBool aBeamed)
|
|
77 |
{
|
|
78 |
CVPbkVCardPropertyExporter* self =
|
|
79 |
new (ELeave) CVPbkVCardPropertyExporter(
|
|
80 |
aData,
|
|
81 |
aSourceItem,
|
|
82 |
aDestStream,
|
|
83 |
aObserver,
|
|
84 |
aBeamed);
|
|
85 |
CleanupStack::PushL( self );
|
|
86 |
self->ConstructL(aData);
|
|
87 |
return self;
|
|
88 |
}
|
|
89 |
|
|
90 |
CVPbkVCardPropertyExporter::CVPbkVCardPropertyExporter(
|
|
91 |
CVPbkVCardData& aData,
|
|
92 |
const MVPbkStoreContact* aSourceItem,
|
|
93 |
RWriteStream& aDestStream,
|
|
94 |
MVPbkSingleContactOperationObserver& aObserver,
|
|
95 |
const TBool aBeamed)
|
|
96 |
: CVPbkVCardActiveIncremental( EPriorityStandard,
|
|
97 |
*this,
|
|
98 |
aData,
|
|
99 |
aObserver),
|
|
100 |
iContact ( aSourceItem ),
|
|
101 |
iDestinationStream( aDestStream ),
|
|
102 |
iCurrentPropertyIndex( 0 ),
|
|
103 |
iMaxPropertyCount( aData.Properties().Count() ),
|
|
104 |
iState( EExporting ),
|
|
105 |
iMaskedFieldsArray(aData.GetMaskedFields()),
|
|
106 |
iBeamed(aBeamed)
|
|
107 |
{
|
|
108 |
}
|
|
109 |
|
|
110 |
CVPbkVCardPropertyExporter* CVPbkVCardPropertyExporter::NewLC(
|
|
111 |
CVPbkVCardData& aData,
|
|
112 |
RWriteStream& aDestStream,
|
|
113 |
MVPbkSingleContactOperationObserver& aObserver,
|
|
114 |
const TBool aBeamed)
|
|
115 |
{
|
|
116 |
CVPbkVCardPropertyExporter* self =
|
|
117 |
new (ELeave) CVPbkVCardPropertyExporter(
|
|
118 |
aData,
|
|
119 |
aDestStream,
|
|
120 |
aObserver,
|
|
121 |
aBeamed);
|
|
122 |
CleanupStack::PushL( self );
|
|
123 |
self->ConstructL(aData);
|
|
124 |
return self;
|
|
125 |
}
|
|
126 |
|
|
127 |
CVPbkVCardPropertyExporter::CVPbkVCardPropertyExporter(
|
|
128 |
CVPbkVCardData& aData,
|
|
129 |
RWriteStream& aDestStream,
|
|
130 |
MVPbkSingleContactOperationObserver& aObserver,
|
|
131 |
const TBool aBeamed)
|
|
132 |
: CVPbkVCardActiveIncremental( EPriorityStandard,
|
|
133 |
*this,
|
|
134 |
aData,
|
|
135 |
aObserver),
|
|
136 |
iDestinationStream( aDestStream ),
|
|
137 |
iCurrentPropertyIndex( 0 ),
|
|
138 |
iMaxPropertyCount( aData.Properties().Count() ),
|
|
139 |
iState( ECreatingRetriever ),
|
|
140 |
iMaskedFieldsArray(aData.GetMaskedFields()),
|
|
141 |
iBeamed(aBeamed)
|
|
142 |
{
|
|
143 |
}
|
|
144 |
|
|
145 |
CVPbkVCardPropertyExporter::~CVPbkVCardPropertyExporter()
|
|
146 |
{
|
|
147 |
iValues.ResetAndDestroy();
|
|
148 |
delete iOwnedContact;
|
|
149 |
delete iOperation;
|
|
150 |
delete iParser;
|
|
151 |
delete iOwncardHandler;
|
|
152 |
delete iGroupcardHandler;
|
|
153 |
}
|
|
154 |
|
|
155 |
void CVPbkVCardPropertyExporter::ExportFieldL( CVPbkVCardFieldTypeProperty& aVCardProperty )
|
|
156 |
{
|
|
157 |
iVCardProperty = &aVCardProperty;
|
|
158 |
|
|
159 |
if ( iVCardProperty->Name().Compare(KGEO) == 0 )
|
|
160 |
{
|
|
161 |
// Read from cenrep
|
|
162 |
CRepository* repository = CRepository::NewLC( KCRUidGeoFieldInternalKeys );
|
|
163 |
TBool geoFeatureValue(1);
|
|
164 |
// Get the geo feature value..
|
|
165 |
TInt err = repository->Get( KNsmlDsGeoField, geoFeatureValue );
|
|
166 |
User::LeaveIfError(err);
|
|
167 |
CleanupStack::PopAndDestroy(repository);
|
|
168 |
if (!geoFeatureValue)
|
|
169 |
{
|
|
170 |
return; //no Need to add GEO field during Sync/BT
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
|
174 |
// If the current operation is a beamed export
|
|
175 |
if (iBeamed)
|
|
176 |
{
|
|
177 |
TInt count(iMaskedFieldsArray ? iMaskedFieldsArray->Count() : 0);
|
|
178 |
TInt val(-1);
|
|
179 |
for (TInt i(0); i < count; i++)
|
|
180 |
{
|
|
181 |
val = iVCardProperty->Name().Find( (*iMaskedFieldsArray)[i] );
|
|
182 |
if (0 == val)
|
|
183 |
{
|
|
184 |
// This is a masked field
|
|
185 |
return;
|
|
186 |
}
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
|
190 |
GetValuesFromIndexedPropertiesL( iVCardProperty->Count() == KOne );
|
|
191 |
}
|
|
192 |
|
|
193 |
void CVPbkVCardPropertyExporter::GetValuesFromIndexedPropertiesL(
|
|
194 |
TBool aSingleItem )
|
|
195 |
{
|
|
196 |
CVPbkVCardParserParamArray* params = NULL;
|
|
197 |
TInt findIndex( 0 );
|
|
198 |
|
|
199 |
if ( aSingleItem )
|
|
200 |
{
|
|
201 |
TBool doContinue( ETrue );
|
|
202 |
const TVPbkVCardIndexedProperty& indexedProperty =
|
|
203 |
iVCardProperty->IndexedPropertyAt( 0 );
|
|
204 |
|
|
205 |
while( doContinue )
|
|
206 |
{
|
|
207 |
InitDataL();
|
|
208 |
params =
|
|
209 |
new (ELeave) CVPbkVCardParserParamArray( KOne );
|
|
210 |
CleanupStack::PushL( params );
|
|
211 |
|
|
212 |
doContinue = GetSingleValueAndParamsL( indexedProperty,
|
|
213 |
*params,
|
|
214 |
findIndex );
|
|
215 |
++findIndex;
|
|
216 |
CleanupStack::Pop( params );
|
|
217 |
// The params is pushed straight back to the CleanupStack in AddPropertyParserL
|
|
218 |
// unless AddPropertyToParserL returns EFalse
|
|
219 |
if( !AddPropertyToParserL( iValues, params ) )
|
|
220 |
{
|
|
221 |
delete params;
|
|
222 |
params = NULL;
|
|
223 |
}
|
|
224 |
}
|
|
225 |
}
|
|
226 |
else
|
|
227 |
{
|
|
228 |
TInt indexedPropertyCount( iVCardProperty->Count() );
|
|
229 |
InitDataL();
|
|
230 |
params =
|
|
231 |
new (ELeave) CVPbkVCardParserParamArray( indexedPropertyCount );
|
|
232 |
CleanupStack::PushL( params );
|
|
233 |
|
|
234 |
for ( TInt i = 0; i < indexedPropertyCount; ++i )
|
|
235 |
{
|
|
236 |
const TVPbkVCardIndexedProperty& indexedProperty =
|
|
237 |
iVCardProperty->IndexedPropertyAt( i );
|
|
238 |
findIndex = 0;
|
|
239 |
GetSingleValueAndParamsL( indexedProperty, *params, findIndex );
|
|
240 |
}
|
|
241 |
|
|
242 |
CleanupStack::Pop( params );
|
|
243 |
// The params are pushed straight back to the CleanupStack in
|
|
244 |
// AddPropertyParserL unless AddPropertyToParserL returns EFalse
|
|
245 |
if( !AddPropertyToParserL( iValues, params ) )
|
|
246 |
{
|
|
247 |
delete params;
|
|
248 |
params = NULL;
|
|
249 |
}
|
|
250 |
}
|
|
251 |
}
|
|
252 |
|
|
253 |
TBool CVPbkVCardPropertyExporter::GetSingleValueAndParamsL(
|
|
254 |
const TVPbkVCardIndexedProperty& aIndexedProperty,
|
|
255 |
CVPbkVCardParserParamArray& aParamArray,
|
|
256 |
TInt& aFindIndex )
|
|
257 |
{
|
|
258 |
MVPbkStoreContactField* field =
|
|
259 |
FindFieldFromContact( aIndexedProperty, aFindIndex );
|
|
260 |
if( !field )
|
|
261 |
{
|
|
262 |
return EFalse;
|
|
263 |
}
|
|
264 |
// Fetch field value and additional params
|
|
265 |
CParserPropertyValue* value = FetchDataFromFieldL( *field, aParamArray );
|
|
266 |
if( !value )
|
|
267 |
{
|
|
268 |
return ETrue;
|
|
269 |
}
|
|
270 |
CleanupStack::PushL( value );
|
|
271 |
TInt index ( aIndexedProperty.Index() );
|
|
272 |
iValues[ index ] = value;
|
|
273 |
CleanupStack::Pop( value );
|
|
274 |
|
|
275 |
return ETrue;
|
|
276 |
}
|
|
277 |
|
|
278 |
void CVPbkVCardPropertyExporter::ConstructL(CVPbkVCardData& aData)
|
|
279 |
{
|
|
280 |
iParser = CParserVCard::NewL();
|
|
281 |
|
|
282 |
iOwncardHandler = CVPbkOwnCardHandler::NewL(aData);
|
|
283 |
iGroupcardHandler = CVPbkGroupCardHandler::NewL(aData);
|
|
284 |
}
|
|
285 |
|
|
286 |
MVPbkStoreContactField*
|
|
287 |
CVPbkVCardPropertyExporter::FindFieldFromContact(
|
|
288 |
const TVPbkVCardIndexedProperty& aIndexedProperty, TInt& aIndex )
|
|
289 |
{
|
|
290 |
const MVPbkFieldType* exportPropertyType =
|
|
291 |
aIndexedProperty.FindMatch( iData.SupportedFieldTypes());
|
|
292 |
|
|
293 |
TInt fieldCount = iContact->Fields().FieldCount();
|
|
294 |
for ( TInt n = aIndex; n < fieldCount; ++n )
|
|
295 |
{
|
|
296 |
// We have to find out additional properties of the contact field so
|
|
297 |
// we need non-const reference of the field class.
|
|
298 |
MVPbkStoreContactField& sourceField =
|
|
299 |
const_cast<MVPbkStoreContact*>( iContact )->Fields().FieldAt( n );
|
|
300 |
|
|
301 |
const TInt maxMatchPriority =
|
|
302 |
iData.SupportedFieldTypes().MaxMatchPriority();
|
|
303 |
for ( TInt matchPriority = 0;
|
|
304 |
matchPriority <= maxMatchPriority;
|
|
305 |
++matchPriority )
|
|
306 |
{
|
|
307 |
const MVPbkFieldType* sourceFieldType =
|
|
308 |
sourceField.MatchFieldType( matchPriority );
|
|
309 |
if ( sourceFieldType &&
|
|
310 |
exportPropertyType->IsSame( *sourceFieldType ) )
|
|
311 |
{
|
|
312 |
aIndex = n;
|
|
313 |
return &sourceField;
|
|
314 |
}
|
|
315 |
}
|
|
316 |
}
|
|
317 |
return NULL;
|
|
318 |
}
|
|
319 |
|
|
320 |
CParserPropertyValue* CVPbkVCardPropertyExporter::FetchDataFromFieldL(
|
|
321 |
MVPbkStoreContactField& aField, CVPbkVCardParserParamArray& aParameters )
|
|
322 |
{
|
|
323 |
CParserPropertyValue* value = NULL;
|
|
324 |
TVPbkFieldStorageType storageType = aField.FieldData().DataType();
|
|
325 |
switch ( storageType )
|
|
326 |
{
|
|
327 |
case EVPbkFieldStorageTypeText:
|
|
328 |
{
|
|
329 |
value = GetExportTextValueL( aField );
|
|
330 |
break;
|
|
331 |
}
|
|
332 |
|
|
333 |
case EVPbkFieldStorageTypeUri:
|
|
334 |
{
|
|
335 |
value = GetExportUriValueL( aField );
|
|
336 |
break;
|
|
337 |
}
|
|
338 |
|
|
339 |
case EVPbkFieldStorageTypeBinary:
|
|
340 |
{
|
|
341 |
value = GetExportBinaryValueL(aField, aParameters);
|
|
342 |
break;
|
|
343 |
}
|
|
344 |
|
|
345 |
case EVPbkFieldStorageTypeDateTime:
|
|
346 |
{
|
|
347 |
value = GetExportDateValueL( aField );
|
|
348 |
break;
|
|
349 |
}
|
|
350 |
|
|
351 |
default:
|
|
352 |
{
|
|
353 |
value = NULL;
|
|
354 |
break;
|
|
355 |
}
|
|
356 |
}
|
|
357 |
|
|
358 |
if ( value )
|
|
359 |
{
|
|
360 |
CleanupStack::PushL( value );
|
|
361 |
GetAdditionalParamsL( aField, aParameters );
|
|
362 |
CleanupStack::Pop( value );
|
|
363 |
}
|
|
364 |
|
|
365 |
return value;
|
|
366 |
}
|
|
367 |
|
|
368 |
|
|
369 |
TBool CVPbkVCardPropertyExporter::AddPropertyToParserL(
|
|
370 |
RPointerArray< CParserPropertyValue >& aValues,
|
|
371 |
CVPbkVCardParserParamArray* aParams )
|
|
372 |
{
|
|
373 |
if( !HasValues() )
|
|
374 |
{
|
|
375 |
return EFalse;
|
|
376 |
}
|
|
377 |
|
|
378 |
CleanupStack::PushL( aParams );
|
|
379 |
CParserPropertyValue* value = GetValueL( aValues );
|
|
380 |
|
|
381 |
__ASSERT_DEBUG( value,
|
|
382 |
VPbkVCardEngError::Panic( VPbkVCardEngError::ENullParserProperty ) );
|
|
383 |
|
|
384 |
CleanupStack::PushL(value);
|
|
385 |
CParserProperty* property =
|
|
386 |
CParserProperty::NewL( *value, iVCardProperty->Name(), aParams );
|
|
387 |
CleanupStack::Pop( value );
|
|
388 |
CleanupStack::Pop( aParams ); // The ownership has taken by CParserProperty
|
|
389 |
// NOTE: Versit pushes the CParserProperty* pointer stright away
|
|
390 |
// to the cleanup stack, so to avoid duplicate entries in
|
|
391 |
// the stack pointer must not be pushed there.
|
|
392 |
iParser->AddPropertyL( property );
|
|
393 |
|
|
394 |
return ETrue;
|
|
395 |
}
|
|
396 |
|
|
397 |
TBool CVPbkVCardPropertyExporter::HasValues()
|
|
398 |
{
|
|
399 |
for ( TInt i = 0; i < iValues.Count(); ++i )
|
|
400 |
{
|
|
401 |
if ( iValues[ i ] )
|
|
402 |
{
|
|
403 |
return ETrue;
|
|
404 |
}
|
|
405 |
}
|
|
406 |
return EFalse;
|
|
407 |
}
|
|
408 |
|
|
409 |
CParserPropertyValue* CVPbkVCardPropertyExporter::GetValueL(
|
|
410 |
RPointerArray< CParserPropertyValue >& aValues)
|
|
411 |
{
|
|
412 |
CParserPropertyValue* value = NULL;
|
|
413 |
if ( aValues.Count() == KOne )
|
|
414 |
{
|
|
415 |
value = aValues[ 0 ];
|
|
416 |
aValues.Remove( 0 );
|
|
417 |
}
|
|
418 |
else
|
|
419 |
{
|
|
420 |
CDesCArrayFlat* desarr = new(ELeave) CDesCArrayFlat( aValues.Count() );
|
|
421 |
CleanupStack::PushL( desarr );
|
|
422 |
|
|
423 |
while ( aValues.Count() > 0 )
|
|
424 |
{
|
|
425 |
CParserPropertyValueHBufC* tmpValue =
|
|
426 |
static_cast<CParserPropertyValueHBufC*>( aValues[ 0 ] );
|
|
427 |
CleanupStack::PushL( tmpValue );
|
|
428 |
aValues.Remove( 0 );
|
|
429 |
|
|
430 |
if ( !tmpValue || tmpValue->Value().Length() == 0 )
|
|
431 |
{
|
|
432 |
desarr->AppendL( KNullDesC );
|
|
433 |
}
|
|
434 |
else
|
|
435 |
{
|
|
436 |
desarr->AppendL( tmpValue->Value() );
|
|
437 |
}
|
|
438 |
|
|
439 |
CleanupStack::PopAndDestroy( tmpValue );
|
|
440 |
}
|
|
441 |
|
|
442 |
value = new (ELeave) CParserPropertyValueCDesCArray( desarr );
|
|
443 |
CleanupStack::Pop( desarr );
|
|
444 |
}
|
|
445 |
|
|
446 |
__ASSERT_DEBUG( aValues.Count() == 0,
|
|
447 |
VPbkVCardEngError::Panic(
|
|
448 |
VPbkVCardEngError::EInvalidLengthOfPropertyArray ) );
|
|
449 |
|
|
450 |
return value;
|
|
451 |
}
|
|
452 |
|
|
453 |
CParserPropertyValue* CVPbkVCardPropertyExporter::GetExportTextValueL(
|
|
454 |
const MVPbkBaseContactField& aField )
|
|
455 |
{
|
|
456 |
TPtrC text( MVPbkContactFieldTextData::Cast( aField.FieldData() ).Text() );
|
|
457 |
if( !ContainsValidTextualDataL( text ) )
|
|
458 |
{
|
|
459 |
return NULL;
|
|
460 |
}
|
|
461 |
|
|
462 |
CParserPropertyValueHBufC* value = CParserPropertyValueHBufC::NewL( text );
|
|
463 |
|
|
464 |
return value;
|
|
465 |
}
|
|
466 |
|
|
467 |
CParserPropertyValue* CVPbkVCardPropertyExporter::GetExportUriValueL(
|
|
468 |
const MVPbkBaseContactField& aField )
|
|
469 |
{
|
|
470 |
TPtrC text( MVPbkContactFieldUriData::Cast( aField.FieldData() ).Uri() );
|
|
471 |
if( !ContainsValidTextualDataL( text ) )
|
|
472 |
{
|
|
473 |
return NULL;
|
|
474 |
}
|
|
475 |
|
|
476 |
CParserPropertyValueHBufC* value = CParserPropertyValueHBufC::NewL( text );
|
|
477 |
|
|
478 |
return value;
|
|
479 |
}
|
|
480 |
|
|
481 |
|
|
482 |
CParserPropertyValue* CVPbkVCardPropertyExporter::GetExportDateValueL(
|
|
483 |
const MVPbkBaseContactField& aField)
|
|
484 |
{
|
|
485 |
TTime time =
|
|
486 |
MVPbkContactFieldDateTimeData::Cast( aField.FieldData() ).DateTime();
|
|
487 |
TVersitDateTime* vdt =
|
|
488 |
new (ELeave) TVersitDateTime( time.DateTime(),
|
|
489 |
TVersitDateTime::EIsMachineLocal );
|
|
490 |
CleanupStack::PushL( vdt );
|
|
491 |
CParserPropertyValueDate* value =
|
|
492 |
new (ELeave) CParserPropertyValueDate( vdt );
|
|
493 |
CleanupStack::Pop( vdt );
|
|
494 |
return value;
|
|
495 |
}
|
|
496 |
|
|
497 |
CParserPropertyValue*
|
|
498 |
CVPbkVCardPropertyExporter::GetExportBinaryValueL(
|
|
499 |
const MVPbkBaseContactField& aField,
|
|
500 |
CVPbkVCardParserParamArray& aParameters )
|
|
501 |
{
|
|
502 |
const TDesC8& data =
|
|
503 |
MVPbkContactFieldBinaryData::Cast( aField.FieldData() ).BinaryData();
|
|
504 |
|
|
505 |
CParserParam* param = CParserParam::NewL( KPropEncoding, KPropBase64 );
|
|
506 |
CleanupStack::PushL( param );
|
|
507 |
aParameters.AppendL( param );
|
|
508 |
CleanupStack::Pop( param );
|
|
509 |
|
|
510 |
// format is always jpeg when retrieved from db
|
|
511 |
param = CParserParam::NewL( KPropType, KFormatJPEG );
|
|
512 |
CleanupStack::PushL( param );
|
|
513 |
aParameters.AppendL( param );
|
|
514 |
CleanupStack::Pop( param );
|
|
515 |
|
|
516 |
CParserPropertyValueBinary* value = CParserPropertyValueBinary::NewL( data );
|
|
517 |
return value;
|
|
518 |
}
|
|
519 |
|
|
520 |
TBool CVPbkVCardPropertyExporter::ContainsValidTextualDataL(
|
|
521 |
const TDesC& aDataText) const
|
|
522 |
{
|
|
523 |
if ( !aDataText.Length() )
|
|
524 |
{
|
|
525 |
return EFalse;
|
|
526 |
}
|
|
527 |
|
|
528 |
HBufC* tmpText = aDataText.AllocLC();
|
|
529 |
TPtr tmpPtr = tmpText->Des();
|
|
530 |
tmpPtr.Trim();
|
|
531 |
|
|
532 |
if ( tmpPtr.Length() == 0 )
|
|
533 |
{
|
|
534 |
CleanupStack::PopAndDestroy(); // tmpText
|
|
535 |
return EFalse;
|
|
536 |
}
|
|
537 |
|
|
538 |
CleanupStack::PopAndDestroy(); // tmpText
|
|
539 |
return ETrue;
|
|
540 |
}
|
|
541 |
|
|
542 |
void CVPbkVCardPropertyExporter::GetAdditionalParamsL(
|
|
543 |
MVPbkStoreContactField& aField, CVPbkVCardParserParamArray& aParams )
|
|
544 |
{
|
|
545 |
if ( aParams.Count() > 0 ) // Fetch params only once.
|
|
546 |
{
|
|
547 |
return;
|
|
548 |
}
|
|
549 |
|
|
550 |
const MVPbkFieldType* fieldType = NULL;
|
|
551 |
const TInt maxMatchPriority = iData.SupportedFieldTypes().MaxMatchPriority();
|
|
552 |
for (TInt matchPriority = 0;
|
|
553 |
matchPriority <= maxMatchPriority && !fieldType;
|
|
554 |
++matchPriority)
|
|
555 |
{
|
|
556 |
fieldType = aField.MatchFieldType( matchPriority );
|
|
557 |
}
|
|
558 |
if ( !fieldType )
|
|
559 |
{
|
|
560 |
return;
|
|
561 |
}
|
|
562 |
|
|
563 |
TBool match( EFalse );
|
|
564 |
TVPbkFieldTypeParameters params;
|
|
565 |
TArray<TVPbkFieldVersitProperty> array = fieldType->VersitProperties();
|
|
566 |
for ( TInt n = 0; n < array.Count() && !match; ++n )
|
|
567 |
{
|
|
568 |
TVPbkFieldVersitProperty vProperty = array[ n ];
|
|
569 |
for ( TInt priority = 0;
|
|
570 |
priority <= maxMatchPriority && !match;
|
|
571 |
++priority )
|
|
572 |
{
|
|
573 |
match = fieldType->Matches( vProperty, priority );
|
|
574 |
if ( match )
|
|
575 |
{
|
|
576 |
params.AddAll( vProperty.Parameters() );
|
|
577 |
}
|
|
578 |
}
|
|
579 |
}
|
|
580 |
|
|
581 |
TInt count = iData.ParamIdNameMappings().Count();
|
|
582 |
for ( TInt i = 0; i < count; ++i )
|
|
583 |
{
|
|
584 |
if ( params.Contains(
|
|
585 |
static_cast<TVPbkFieldTypeParameter>(
|
|
586 |
iData.ParamIdNameMappings()[ i ]->Id() ) ) )
|
|
587 |
{
|
|
588 |
CParserParam* param =
|
|
589 |
CParserParam::NewL( iData.ParamIdNameMappings()[ i ]->Name(),
|
|
590 |
KNullDesC );
|
|
591 |
CleanupStack::PushL( param );
|
|
592 |
aParams.AppendL( param );
|
|
593 |
CleanupStack::Pop( param );
|
|
594 |
}
|
|
595 |
}
|
|
596 |
|
|
597 |
// Set PREF param if field has default attribute set
|
|
598 |
if ( iData.AttributeManagerL().HasFieldAttributeL(
|
|
599 |
CVPbkDefaultAttribute::Uid(), aField) )
|
|
600 |
{
|
|
601 |
CParserParam* param = CParserParam::NewL( KPropPREF, KNullDesC );
|
|
602 |
CleanupStack::PushL( param );
|
|
603 |
aParams.AppendL( param );
|
|
604 |
CleanupStack::Pop( param );
|
|
605 |
}
|
|
606 |
}
|
|
607 |
|
|
608 |
void CVPbkVCardPropertyExporter::InitDataL()
|
|
609 |
{
|
|
610 |
TInt indexedPropertyCount( iVCardProperty->Count() );
|
|
611 |
|
|
612 |
iValues.ResetAndDestroy();
|
|
613 |
// Initialize array with NULL values
|
|
614 |
while ( iValues.Count() < indexedPropertyCount )
|
|
615 |
{
|
|
616 |
iValues.AppendL( NULL );
|
|
617 |
}
|
|
618 |
}
|
|
619 |
|
|
620 |
TInt CVPbkVCardPropertyExporter::Next(TInt& aRemainingSteps)
|
|
621 |
{
|
|
622 |
__ASSERT_DEBUG( iState == EExporting,
|
|
623 |
VPbkVCardEngError::Panic( VPbkVCardEngError::EInvalidStateOfExporter ) );
|
|
624 |
TInt err( KErrNone );
|
|
625 |
TRAP( err, DoNextL() );
|
|
626 |
|
|
627 |
++iCurrentPropertyIndex;
|
|
628 |
aRemainingSteps = (iCurrentPropertyIndex < iMaxPropertyCount ) ?
|
|
629 |
( iMaxPropertyCount - iCurrentPropertyIndex ) :
|
|
630 |
0;
|
|
631 |
|
|
632 |
if(!iBeamed && err == KErrNone && !aRemainingSteps )
|
|
633 |
{
|
|
634 |
TRAP( err, HandleOwnCardL() );
|
|
635 |
if(err == KErrNone )
|
|
636 |
TRAP( err, HandleGroupCardL() );
|
|
637 |
|
|
638 |
// Parse the REV (Revision) field if any
|
|
639 |
if(err == KErrNone )
|
|
640 |
TRAP( err, AddRevL() );
|
|
641 |
}
|
|
642 |
return err;
|
|
643 |
}
|
|
644 |
|
|
645 |
// ----------------------------------------------------------------------------
|
|
646 |
// CVPbkVCardPropertyExporter::HandleGroupCardL
|
|
647 |
// ----------------------------------------------------------------------------
|
|
648 |
void CVPbkVCardPropertyExporter::HandleGroupCardL()
|
|
649 |
{
|
|
650 |
CParserProperty* property = iGroupcardHandler->CreateXGroupPropertyL(iContact);
|
|
651 |
if (property)
|
|
652 |
{
|
|
653 |
CleanupStack::PushL( property );
|
|
654 |
iParser->AddPropertyL( property );
|
|
655 |
CleanupStack::Pop( property );
|
|
656 |
}
|
|
657 |
}
|
|
658 |
|
|
659 |
void CVPbkVCardPropertyExporter::HandleOwnCardL()
|
|
660 |
{
|
|
661 |
iOwncardHandler->DoInitL(iContact->ParentStore());
|
|
662 |
if(iOwncardHandler->IsOwnContactL(iContact))
|
|
663 |
{
|
|
664 |
CParserProperty* property =iOwncardHandler->CreateXSelfPropertyL();
|
|
665 |
CleanupStack::PushL( property );
|
|
666 |
iParser->AddPropertyL( property );
|
|
667 |
CleanupStack::Pop( property );
|
|
668 |
}
|
|
669 |
}
|
|
670 |
void CVPbkVCardPropertyExporter::DoNextL()
|
|
671 |
{
|
|
672 |
ExportFieldL( *iData.Properties()[ iCurrentPropertyIndex ] );
|
|
673 |
}
|
|
674 |
|
|
675 |
void CVPbkVCardPropertyExporter::CloseL()
|
|
676 |
{
|
|
677 |
iParser->ExternalizeL( iDestinationStream );
|
|
678 |
iObserver.VPbkSingleContactOperationComplete( *this, NULL );
|
|
679 |
}
|
|
680 |
|
|
681 |
void CVPbkVCardPropertyExporter::HandleLeave( TInt aError )
|
|
682 |
{
|
|
683 |
iObserver.VPbkSingleContactOperationFailed( *this, aError );
|
|
684 |
}
|
|
685 |
|
|
686 |
void CVPbkVCardPropertyExporter::HandleCancel()
|
|
687 |
{
|
|
688 |
iObserver.VPbkSingleContactOperationFailed( *this, KErrCancel );
|
|
689 |
}
|
|
690 |
|
|
691 |
void CVPbkVCardPropertyExporter::InitLinkL(
|
|
692 |
const MVPbkContactLink& aContactLink,
|
|
693 |
CVPbkContactManager& aContactManager )
|
|
694 |
{
|
|
695 |
iOperation =
|
|
696 |
aContactManager.RetrieveContactL( aContactLink, *this );
|
|
697 |
}
|
|
698 |
|
|
699 |
void CVPbkVCardPropertyExporter::VPbkSingleContactOperationComplete(
|
|
700 |
MVPbkContactOperationBase& VPBK_DEBUG_ONLY( aOperation ),
|
|
701 |
MVPbkStoreContact* aContact)
|
|
702 |
{
|
|
703 |
__ASSERT_DEBUG( iOperation == &aOperation,
|
|
704 |
VPbkVCardEngError::Panic( VPbkVCardEngError::EStrayOperation ) );
|
|
705 |
iOwnedContact = aContact;
|
|
706 |
iContact = iOwnedContact;
|
|
707 |
iState = EExporting;
|
|
708 |
Complete( KErrNone );
|
|
709 |
}
|
|
710 |
|
|
711 |
void CVPbkVCardPropertyExporter::VPbkSingleContactOperationFailed
|
|
712 |
( MVPbkContactOperationBase& VPBK_DEBUG_ONLY( aOperation ), TInt aError )
|
|
713 |
{
|
|
714 |
__ASSERT_DEBUG( iOperation == &aOperation,
|
|
715 |
VPbkVCardEngError::Panic( VPbkVCardEngError::EStrayOperation ) );
|
|
716 |
Complete( aError );
|
|
717 |
}
|
|
718 |
|
|
719 |
void CVPbkVCardPropertyExporter::StartL()
|
|
720 |
{
|
|
721 |
if ( iState == ECreatingRetriever )
|
|
722 |
{
|
|
723 |
StartWaiting();
|
|
724 |
}
|
|
725 |
else
|
|
726 |
{
|
|
727 |
Start();
|
|
728 |
}
|
|
729 |
}
|
|
730 |
|
|
731 |
void CVPbkVCardPropertyExporter::AddRevL()
|
|
732 |
{
|
|
733 |
MVPbkStoreContact* tempContact = const_cast<MVPbkStoreContact*>(iContact);
|
|
734 |
if( tempContact )
|
|
735 |
{
|
|
736 |
MVPbkStoreContact2* tempContact2 = reinterpret_cast<MVPbkStoreContact2*>
|
|
737 |
(tempContact->StoreContactExtension (KMVPbkStoreContactExtension2Uid) );
|
|
738 |
if(tempContact2)
|
|
739 |
{
|
|
740 |
MVPbkStoreContactProperties* propreties = tempContact2->PropertiesL();
|
|
741 |
if( propreties )
|
|
742 |
{
|
|
743 |
CleanupDeletePushL(propreties);
|
|
744 |
|
|
745 |
// Convert the last_modified field defined in Contact Model database
|
|
746 |
// to REV (Revision) field in vCard Specification 2.1
|
|
747 |
CParserPropertyValueDateTime* valueDateTime =
|
|
748 |
CreateDateTimePropertyL(
|
|
749 |
propreties->LastModifiedL(),
|
|
750 |
TVersitDateTime::EIsUTC );
|
|
751 |
CleanupStack::PopAndDestroy(propreties);
|
|
752 |
|
|
753 |
CleanupStack::PushL(valueDateTime);
|
|
754 |
CParserProperty* property =
|
|
755 |
CParserGroupedProperty::NewL(*valueDateTime, KREV, NULL, NULL);
|
|
756 |
|
|
757 |
CleanupStack::PushL( property );
|
|
758 |
iParser->AddPropertyL(property); //takes ownership
|
|
759 |
CleanupStack::Pop(2);//valueDateTime and property
|
|
760 |
}
|
|
761 |
}
|
|
762 |
}
|
|
763 |
}
|
|
764 |
|
|
765 |
CParserPropertyValueDateTime* CVPbkVCardPropertyExporter::CreateDateTimePropertyL
|
|
766 |
(const TTime& aDateTime, TVersitDateTime::TRelativeTime aRelativeTime)
|
|
767 |
{
|
|
768 |
TVersitDateTime* dateTime= new(ELeave)TVersitDateTime(aDateTime.DateTime(), aRelativeTime);
|
|
769 |
CleanupStack::PushL(dateTime);
|
|
770 |
CParserPropertyValueDateTime* dateTimeValue=new(ELeave) CParserPropertyValueDateTime(dateTime);
|
|
771 |
CleanupStack::Pop(dateTime);
|
|
772 |
return dateTimeValue;
|
|
773 |
}
|
|
774 |
|
|
775 |
// End of file
|