pimappservices/calendarvcalplugin/src/agmvcali.cpp
branchRCL_3
changeset 30 bd7edf625bdd
parent 29 12af337248b1
child 31 97232defd20e
equal deleted inserted replaced
29:12af337248b1 30:bd7edf625bdd
   109 		}
   109 		}
   110 		
   110 		
   111 	CleanupStack::PushL(guid16);
   111 	CleanupStack::PushL(guid16);
   112 	
   112 	
   113 	// the UID is stored as an 8-bit descriptor, so convert from 16-bit to 8-bit
   113 	// the UID is stored as an 8-bit descriptor, so convert from 16-bit to 8-bit
   114 	HBufC8* guid8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(guid16->Des());
   114 	HBufC8* guid8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(guid16->Des());				 
   115 	CleanupStack::PopAndDestroy(guid16);  
   115 	CleanupStack::PopAndDestroy(guid16);  
   116 	CleanupStack::PushL(guid8);		
   116 	CleanupStack::PushL(guid8);		
   117 		
   117 		
   118 	// Import Sequence Number
   118 	// Import Sequence Number
   119 	TInt seqNumber;	
   119 	TInt seqNumber;	
   177 		}		
   177 		}		
   178 	
   178 	
   179 	// Import X-Recurrence-Id
   179 	// Import X-Recurrence-Id
   180 	TVersitDateTime::TRelativeTime relativeTime = TVersitDateTime::EIsUTC;
   180 	TVersitDateTime::TRelativeTime relativeTime = TVersitDateTime::EIsUTC;
   181 	TTime recurrenceId;
   181 	TTime recurrenceId;
   182 	TBool isRecurrenceIdPresent = ImportDateTimePropertyL(aParser,
   182 	TBool isRecurrenceIdPresent = ImportDateTimePropertyL(aParser, KVersitTokenXRECURRENCEID, recurrenceId, relativeTime);
   183 			KVersitTokenXRECURRENCEID, recurrenceId, relativeTime);
       
   184 	if (!isRecurrenceIdPresent)
   183 	if (!isRecurrenceIdPresent)
   185 		{
   184 		{
   186 		iEntry = CCalEntry::NewL(entryType,guid8, methodStatus, seqNumber);
   185 		iEntry = CCalEntry::NewL(entryType,guid8, methodStatus, seqNumber);
   187 		}
   186 		}
   188 	else
   187 	else
   195 		else
   194 		else
   196 			{
   195 			{
   197 			caltime.SetTimeUtcL(recurrenceId);
   196 			caltime.SetTimeUtcL(recurrenceId);
   198 			}
   197 			}
   199 	
   198 	
   200 		iEntry = CCalEntry::NewL(entryType, guid8, methodStatus, seqNumber,
   199 		iEntry = CCalEntry::NewL(entryType,guid8, methodStatus, seqNumber, caltime, CalCommon::EThisOnly);
   201 				caltime, CalCommon::EThisOnly);
       
   202 		}
   200 		}
   203 		
   201 		
   204 	CleanupStack::Pop(guid8); // ownership was passed to calGSData	
   202 	CleanupStack::Pop(guid8); // ownership was passed to calGSData	
   205 	// Fill in the entry description from the SUMMARY property
   203 	// Fill in the entry description from the SUMMARY property
   206 	// If this doesn't exist, use the DESCRIPTION property, and if this
   204 	// If this doesn't exist, use the DESCRIPTION property, and if this
   207 	// doesn't exist, return a NULL entry
   205 	// doesn't exist, return a NULL entry
   208 	
   206 
   209 	if (entryType != CCalEntry::ENote)
   207  	// get properties but don't take ownership of the elements of the array
   210 		{
   208  	CArrayPtr<CParserProperty>* properties = aParser.PropertyL(KVersitTokenSUMMARY, TUid::Uid(KVersitPropertyHBufCUid), EFalse);
   211 		ImportVCalendarL(aParser, relativeTime, entryType);
   209 
   212 		}
       
   213 	else
       
   214 		{
       
   215 		ImportNoteL(aParser,relativeTime);
       
   216 		}
       
   217 	
       
   218 	// Import favourite property. The type will be converted to an usigned integer
       
   219 	// implicitly. 
       
   220 	TInt favourite = 0;
       
   221 	TBool integerFound = ImportIntegerPropertyL( 
       
   222 			aParser, KVCalTokenXFavourite, favourite );
       
   223 	
       
   224 	if(integerFound)
       
   225 		{
       
   226 		iEntry->SetFavouriteL(favourite);
       
   227 		}
       
   228 	
       
   229 	aEntryArray.AppendL(iEntry); // takes ownership of entry
       
   230 	iEntry = NULL;
       
   231 	}
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CVCalToAgendaEntryConverter::ImportVCalendarL
       
   235 // Imports vcalendar for calendar types EAppt/EReminder/EAnniv/ETodo/EEvent
       
   236 // -----------------------------------------------------------------------------
       
   237 // 
       
   238 void CVCalToAgendaEntryConverter::ImportVCalendarL(CVersitParser& aParser,
       
   239 		TVersitDateTime::TRelativeTime& aRelativeTime,
       
   240 		CCalEntry::TType& aEntryType)
       
   241 	{
       
   242 	// Fill in the entry description from the SUMMARY property
       
   243 	// If this doesn't exist, use the DESCRIPTION property, and if this
       
   244 	// doesn't exist, return a NULL entry
       
   245 	
       
   246 	// get properties but don't take ownership of the elements of the array
       
   247 	CArrayPtr<CParserProperty>* properties = aParser.PropertyL(
       
   248 			KVersitTokenSUMMARY, TUid::Uid(KVersitPropertyHBufCUid), EFalse);
       
   249 	
       
   250 	if (!properties)
   210 	if (!properties)
   251 		{
   211 		{
   252 		// get properties but don't take ownership of the elements of the array
   212 		// get properties but don't take ownership of the elements of the array
   253 		properties = aParser.PropertyL(KVersitTokenDESCRIPTION,
   213 		properties = aParser.PropertyL(KVersitTokenDESCRIPTION, TUid::Uid(KVersitPropertyHBufCUid), EFalse);
   254 				TUid::Uid(KVersitPropertyHBufCUid), EFalse);
       
   255 		}
   214 		}
   256 	CleanupStack::PushL(properties);
   215 	CleanupStack::PushL(properties);
   257 	
   216 	
   258 	// Use the value found from the Summary/Description 
   217 	// Use the value found from the Summary/Description 
   259 	// Both Summary and Description are not found in imported vCal file 
   218 	// Both Summary and Description are not found in imported vCal file 
   260 	//then insert empty enties for summary and description
   219 	//then insert empty enties for summary and description
   261 	//  these empty entries will be descarded while exporting vCal file
   220 	//  these empty entries will be descarded while exporting vCal file
   262 	TPtrC summary;
   221 	TPtrC summary;
   263 	if (properties)
   222 	if (properties)
   264 		{
   223 		{
   265 		summary.Set(static_cast<CParserPropertyValueHBufC*>(
   224 		summary.Set(static_cast<CParserPropertyValueHBufC*>((*properties)[0]->Value())->Value());
   266 				(*properties)[0]->Value())->Value());
       
   267 		}
   225 		}
   268 		
   226 		
   269 	HBufC* summaryBuf = AgnConvertUtil::EncodeL(summary,KUidTextToEtextNoTrim);
   227 	HBufC* summaryBuf = AgnConvertUtil::EncodeL(summary,KUidTextToEtextNoTrim);
   270 	CleanupStack::PushL(summaryBuf);
   228 	CleanupStack::PushL(summaryBuf);
   271 	if (summaryBuf)
   229 	if (summaryBuf)
   272 		{
   230 		{
   273 		iEntry->SetSummaryL(*summaryBuf);
   231 		iEntry->SetSummaryL(*summaryBuf);
   274 		}
   232 		}
   275 	CleanupStack::PopAndDestroy(summaryBuf);
   233 	CleanupStack::PopAndDestroy(summaryBuf);
   276 	
   234 
   277 	HBufC* description =ImportDesPropertyL(aParser,KVersitTokenDESCRIPTION);
   235 	HBufC* description =ImportDesPropertyL(aParser,KVersitTokenDESCRIPTION);
   278 	CleanupStack::PushL(description);
   236 	CleanupStack::PushL(description);
   279 	if (description != NULL)
   237 	if (description != NULL)
   280 		{
   238 		{
   281 		iEntry->SetDescriptionL(*description); // Takes ownership
   239 		iEntry->SetDescriptionL(*description); // Takes ownership
   282 		}
   240 		}
   283 	CleanupStack::PopAndDestroy(description);
   241 	CleanupStack::PopAndDestroy(description);
   284 	
   242 
   285 	TBool validEntry = EFalse;
   243 	TBool validEntry = EFalse;
   286 	if (aEntryType == CCalEntry::ETodo)
   244 	if (entryType == CCalEntry::ETodo)
   287 		{
   245 		{
   288 		validEntry = ImportTodoPropertiesL(aParser);
   246 		validEntry = ImportTodoPropertiesL(aParser);
   289 		}
   247 		}
   290 	else
   248 	else
   291 		{
   249 		{
   297 		CleanupStack::PopAndDestroy(properties);
   255 		CleanupStack::PopAndDestroy(properties);
   298 		delete iEntry;
   256 		delete iEntry;
   299 		iEntry = NULL;
   257 		iEntry = NULL;
   300 		return;
   258 		return;
   301 		}
   259 		}
   302 	
   260 
   303 	// Import CLASS property
   261 	// Import CLASS property
   304 	HBufC* property=ImportDesPropertyL(aParser, KVersitTokenCLASS);
   262 	HBufC* property=ImportDesPropertyL(aParser, KVersitTokenCLASS);
   305 	if (property)
   263 	if (property)
   306 		{
   264 		{
   307 		CleanupStack::PushL(property);
   265 		CleanupStack::PushL(property);
   311 			iEntry->SetReplicationStatusL(CCalEntry::EPrivate);
   269 			iEntry->SetReplicationStatusL(CCalEntry::EPrivate);
   312 		else if (*property == KVCalTokenCONFIDENTIAL)
   270 		else if (*property == KVCalTokenCONFIDENTIAL)
   313 			iEntry->SetReplicationStatusL(CCalEntry::ERestricted);
   271 			iEntry->SetReplicationStatusL(CCalEntry::ERestricted);
   314 		CleanupStack::PopAndDestroy(property);
   272 		CleanupStack::PopAndDestroy(property);
   315 		}
   273 		}
   316 	
       
   317 	// Import LOCATION property
   274 	// Import LOCATION property
   318 	HBufC* locationProperty=ImportDesPropertyL(aParser, KVersitTokenLOCATION);
   275 	property=ImportDesPropertyL(aParser, KVersitTokenLOCATION);
   319 	if (locationProperty)
   276 	if (property)
   320 		{
   277 		{
   321 		CleanupStack::PushL(locationProperty);
   278 		CleanupStack::PushL(property);
   322 		iEntry->SetLocationL(*locationProperty);
   279 		iEntry->SetLocationL(*property);
   323 		CleanupStack::PopAndDestroy(locationProperty);
   280 		CleanupStack::PopAndDestroy(property);
   324 		}
   281 		}
   325 	// Import DTSTAMP
   282 	// Import DTSTAMP
   326 	TTime timeProperty;
   283 	TTime timeProperty;
   327 	if (ImportDateTimePropertyL(aParser, KVersitTokenXDTSTAMP, timeProperty,
   284 	if (ImportDateTimePropertyL(aParser, KVersitTokenXDTSTAMP, timeProperty, relativeTime))
   328 			aRelativeTime))
       
   329 		{
   285 		{
   330 		TCalTime caltimeProperty;
   286 		TCalTime caltimeProperty;
   331 		caltimeProperty.SetTimeUtcL(timeProperty);
   287 		caltimeProperty.SetTimeUtcL(timeProperty);
   332 		iEntry->SetDTStampL(caltimeProperty);
   288 		iEntry->SetDTStampL(caltimeProperty);
   333 		}
   289 		}
   334 	
   290 	
   335 	// Attendee property
   291 	// Attendee property
   336 	ImportAttendeePropertiesL(aParser, KVersitTokenATTENDEE);
   292  	ImportAttendeePropertiesL(aParser, KVersitTokenATTENDEE);
   337 	
   293 
   338 	// Categories property
   294 	// Categories property
   339 	ImportCategoriesPropertyL(aParser, KVersitTokenCATEGORIES);
   295 	ImportCategoriesPropertyL(aParser, KVersitTokenCATEGORIES);
   340 	
   296 
   341 	
   297 	
       
   298 		
   342 	TInt localId;
   299 	TInt localId;
   343 	if (ImportIntegerPropertyL(aParser, KVersitTokenXLOCALUID, localId))
   300 	if (ImportIntegerPropertyL(aParser, KVersitTokenXLOCALUID, localId))
   344 		{
   301 		{
   345 		iEntry->SetLocalUidL(localId);
   302 		iEntry->SetLocalUidL(localId);
   346 		}
   303 		}
   349 	// All entries have a priority not just ToDo's
   306 	// All entries have a priority not just ToDo's
   350 	// Todo Functionality merged into this code block
   307 	// Todo Functionality merged into this code block
   351 	TInt priority;
   308 	TInt priority;
   352 	if (ImportIntegerPropertyL(aParser, KVersitTokenPRIORITY, priority))
   309 	if (ImportIntegerPropertyL(aParser, KVersitTokenPRIORITY, priority))
   353 		{
   310 		{
   354 		iEntry->SetPriorityL(priority);	
   311 		iEntry->SetPriorityL(priority);  
   355 		}
   312 		}
   356 	
   313 
   357 	// All entries have a status - will default to Needs Action if cannot be read
   314 	// All entries have a status - will default to Needs Action if cannot be read
   358 	CCalEntry::TStatus entryStatus=CCalEntry::ENullStatus;
   315 	CCalEntry::TStatus entryStatus=CCalEntry::ENullStatus;
   359 	ImportStatusPropertyL(aParser, entryStatus);
   316 	ImportStatusPropertyL(aParser, entryStatus);
   360 	//Now sync completed and ECompleted status to keep entry consistenty 
   317 	//Now sync completed and ECompleted status to keep entry consistenty 
   361 	if (aEntryType == CCalEntry::ETodo
   318 	if(entryType==CCalEntry::ETodo && (iEntry->CompletedTimeL().TimeUtcL()) != Time::NullTTime())
   362 			&& (iEntry->CompletedTimeL().TimeUtcL()) != Time::NullTTime())
       
   363 		{
   319 		{
   364 		iEntry->SetCompletedL(ETrue, iEntry->CompletedTimeL());
   320 		iEntry->SetCompletedL(ETrue, iEntry->CompletedTimeL());
   365 		}
   321 		}
   366 	iEntry->SetStatusL(entryStatus);
   322 	iEntry->SetStatusL(entryStatus);
   367 	
   323 	
   368 	//Get last changed date from vcal
   324 	//Get last changed date from vcal
   369 	if (ImportDateTimePropertyL(aParser, KVersitTokenLASTMODIFIED,
   325 	if (ImportDateTimePropertyL(aParser, KVersitTokenLASTMODIFIED, timeProperty, relativeTime))
   370 			timeProperty, aRelativeTime))
   326 			{
   371 			{
   327 			if (iTzZone && (relativeTime == TVersitDateTime::EIsVCardLocal))
   372 			if (iTzZone && (aRelativeTime == TVersitDateTime::EIsVCardLocal))
       
   373 				{
   328 				{
   374 				iTzZone->ConvertToUtcL(timeProperty);
   329 				iTzZone->ConvertToUtcL(timeProperty);
   375 				}
   330 				}
   376 			TCalTime lastModifiedDate;
   331 			TCalTime lastModifiedDate;
   377 			lastModifiedDate.SetTimeUtcL(timeProperty);
   332 			lastModifiedDate.SetTimeUtcL(timeProperty);
   394 	HBufC* geoString=ImportDesPropertyL(aParser,KVersitTokenGEO);
   349 	HBufC* geoString=ImportDesPropertyL(aParser,KVersitTokenGEO);
   395 	
   350 	
   396 	if (geoString != NULL)
   351 	if (geoString != NULL)
   397 		{
   352 		{
   398 		CleanupStack::PushL(geoString);
   353 		CleanupStack::PushL(geoString);
   399 		// Determine the position of the delimiter for extraction of the 
   354 		// Determine the position of the delimiter for extraction of the geo latitude and longitude values
   400 		// geo latitude and longitude values
       
   401 		TInt delimiterPos = geoString->Locate(KVersitTokenCommaVal);
   355 		TInt delimiterPos = geoString->Locate(KVersitTokenCommaVal);
   402 		
   356 		
   403 		if(delimiterPos!=KErrNotFound)
   357 		if(delimiterPos!=KErrNotFound)
   404 			{
   358 			{
   405 			// Extract the latitude
   359 			// Extract the latitude
   408 			TLex geoLongitudeLex(geoString->Right(geoString->Length()-(delimiterPos+1)));
   362 			TLex geoLongitudeLex(geoString->Right(geoString->Length()-(delimiterPos+1)));
   409 			
   363 			
   410 			TReal geoLatitude;
   364 			TReal geoLatitude;
   411 			TReal geoLongitude;
   365 			TReal geoLongitude;
   412 			
   366 			
   413 			if ((geoLatitudeLex.Val(geoLatitude) == KErrNone)
   367 			if((geoLatitudeLex.Val(geoLatitude)==KErrNone) && (geoLongitudeLex.Val(geoLongitude)==KErrNone))
   414 					&& (geoLongitudeLex.Val(geoLongitude) == KErrNone))
       
   415 				{
   368 				{
   416 				CCalGeoValue* importedGeoValue=CCalGeoValue::NewL();
   369 				CCalGeoValue* importedGeoValue=CCalGeoValue::NewL();
   417 				CleanupStack::PushL(importedGeoValue);
   370 				CleanupStack::PushL(importedGeoValue);
   418 				TRAPD(err, importedGeoValue->SetLatLongL(geoLatitude,geoLongitude));
   371 				TRAPD(err, importedGeoValue->SetLatLongL(geoLatitude,geoLongitude));
   419 				if(err==KErrNone)
   372 				if(err==KErrNone)
   425 			}
   378 			}
   426 		CleanupStack::PopAndDestroy(geoString);
   379 		CleanupStack::PopAndDestroy(geoString);
   427 		}
   380 		}
   428 	
   381 	
   429 	CleanupStack::PopAndDestroy(properties);
   382 	CleanupStack::PopAndDestroy(properties);
   430 	}
   383 	aEntryArray.AppendL(iEntry); // takes ownership of entry
   431 
   384 	iEntry = NULL;
   432 // -----------------------------------------------------------------------------
       
   433 // CVCalToAgendaEntryConverter::ImportNoteL
       
   434 // Imports note from vcal and maps it to CCalEntry::ENote
       
   435 // -----------------------------------------------------------------------------
       
   436 // 
       
   437 void CVCalToAgendaEntryConverter::ImportNoteL(CVersitParser& aParser,
       
   438 		TVersitDateTime::TRelativeTime& aRelativeTime)
       
   439 	{
       
   440 	
       
   441 	// set description to entry from vcal
       
   442 	// if description property is not present,look for summary property and
       
   443 	// set the summary as description field for the note
       
   444 	CArrayPtr<CParserProperty>* properties = aParser.PropertyL(
       
   445 		KVersitTokenDESCRIPTION, TUid::Uid(KVersitPropertyHBufCUid),EFalse);
       
   446 	if(!properties)
       
   447 		{
       
   448 		properties = aParser.PropertyL(KVersitTokenSUMMARY, TUid::Uid(
       
   449 				KVersitPropertyHBufCUid), EFalse);
       
   450 		CleanupStack::PushL(properties);
       
   451 		TPtrC summary;
       
   452 		if (properties)
       
   453 			{
       
   454 			summary.Set(static_cast<CParserPropertyValueHBufC*>(
       
   455 					(*properties)[0]->Value())->Value());
       
   456 			}
       
   457 			
       
   458 		HBufC* summaryBuf = AgnConvertUtil::EncodeL(summary,
       
   459 				KUidTextToEtextNoTrim);
       
   460 		CleanupStack::PushL(summaryBuf);
       
   461 		if (summaryBuf)
       
   462 			{
       
   463 			iEntry->SetDescriptionL(*summaryBuf);
       
   464 			}
       
   465 		CleanupStack::PopAndDestroy(summaryBuf);
       
   466 		CleanupStack::PopAndDestroy(properties);
       
   467 		}
       
   468 	else
       
   469 		{
       
   470 		HBufC* description = ImportDesPropertyL(aParser,KVersitTokenDESCRIPTION);
       
   471 		CleanupStack::PushL(description);
       
   472 		if (description != NULL)
       
   473 			{
       
   474 			iEntry->SetDescriptionL(*description); // Takes ownership
       
   475 			}
       
   476 		CleanupStack::PopAndDestroy(description);
       
   477 		}
       
   478 	
       
   479 	// get local uid from vcal
       
   480 	TInt localId;
       
   481 	if (ImportIntegerPropertyL(aParser, KVersitTokenXLOCALUID, localId))
       
   482 		{
       
   483 		iEntry->SetLocalUidL(localId);
       
   484 		}
       
   485 	
       
   486 	// get last changed date from vcal
       
   487 	TTime timeProperty;
       
   488 	if (ImportDateTimePropertyL(aParser, KVersitTokenLASTMODIFIED,
       
   489 			timeProperty, aRelativeTime))
       
   490 		{
       
   491 		if (iTzZone && (aRelativeTime == TVersitDateTime::EIsVCardLocal))
       
   492 			{
       
   493 			iTzZone->ConvertToUtcL(timeProperty);
       
   494 			}
       
   495 		TCalTime lastModifiedDate;
       
   496 		lastModifiedDate.SetTimeUtcL(timeProperty);
       
   497 		iEntry->SetLastModifiedDateL(lastModifiedDate);
       
   498 		}
       
   499 	else
       
   500 		{
       
   501 		iEntry->SetLastModifiedDateL(); //set changed date to now
       
   502 		}
       
   503 	
       
   504 	// get attachments from the vcal
       
   505 	ImportAttachmentPropertyL(aParser);
       
   506 	}
   385 	}
   507 
   386 
   508 CVCalToAgendaEntryConverter::~CVCalToAgendaEntryConverter()
   387 CVCalToAgendaEntryConverter::~CVCalToAgendaEntryConverter()
   509 	{
   388 	{
   510 	delete iEntry;
   389 	delete iEntry;
   595 			}
   474 			}
   596 		
   475 		
   597 		if (type == KVCalTokenTypeREMINDER)
   476 		if (type == KVCalTokenTypeREMINDER)
   598 			{
   477 			{
   599 			return CCalEntry::EReminder;
   478 			return CCalEntry::EReminder;
   600 			}
       
   601 		
       
   602 		if (type == KVCalTokenTypeNOTE)
       
   603 			{
       
   604 			return CCalEntry::ENote;
       
   605 			}
   479 			}
   606 		
   480 		
   607 		}
   481 		}
   608 
   482 
   609 	// return an appointment as default type
   483 	// return an appointment as default type