pimappservices/calendarvcalplugin/src/agmvcali.cpp
branchRCL_3
changeset 29 12af337248b1
parent 0 f979ecb2b13e
child 30 bd7edf625bdd
--- a/pimappservices/calendarvcalplugin/src/agmvcali.cpp	Thu Aug 19 09:53:43 2010 +0300
+++ b/pimappservices/calendarvcalplugin/src/agmvcali.cpp	Tue Aug 31 15:13:43 2010 +0300
@@ -111,7 +111,7 @@
 	CleanupStack::PushL(guid16);
 	
 	// the UID is stored as an 8-bit descriptor, so convert from 16-bit to 8-bit
-	HBufC8* guid8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(guid16->Des());				 
+	HBufC8* guid8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(guid16->Des());
 	CleanupStack::PopAndDestroy(guid16);  
 	CleanupStack::PushL(guid8);		
 		
@@ -179,7 +179,8 @@
 	// Import X-Recurrence-Id
 	TVersitDateTime::TRelativeTime relativeTime = TVersitDateTime::EIsUTC;
 	TTime recurrenceId;
-	TBool isRecurrenceIdPresent = ImportDateTimePropertyL(aParser, KVersitTokenXRECURRENCEID, recurrenceId, relativeTime);
+	TBool isRecurrenceIdPresent = ImportDateTimePropertyL(aParser,
+			KVersitTokenXRECURRENCEID, recurrenceId, relativeTime);
 	if (!isRecurrenceIdPresent)
 		{
 		iEntry = CCalEntry::NewL(entryType,guid8, methodStatus, seqNumber);
@@ -196,21 +197,61 @@
 			caltime.SetTimeUtcL(recurrenceId);
 			}
 	
-		iEntry = CCalEntry::NewL(entryType,guid8, methodStatus, seqNumber, caltime, CalCommon::EThisOnly);
+		iEntry = CCalEntry::NewL(entryType, guid8, methodStatus, seqNumber,
+				caltime, CalCommon::EThisOnly);
 		}
 		
 	CleanupStack::Pop(guid8); // ownership was passed to calGSData	
 	// Fill in the entry description from the SUMMARY property
 	// If this doesn't exist, use the DESCRIPTION property, and if this
 	// doesn't exist, return a NULL entry
+	
+	if (entryType != CCalEntry::ENote)
+		{
+		ImportVCalendarL(aParser, relativeTime, entryType);
+		}
+	else
+		{
+		ImportNoteL(aParser,relativeTime);
+		}
+	
+	// Import favourite property. The type will be converted to an usigned integer
+	// implicitly. 
+	TInt favourite = 0;
+	TBool integerFound = ImportIntegerPropertyL( 
+			aParser, KVCalTokenXFavourite, favourite );
+	
+	if(integerFound)
+		{
+		iEntry->SetFavouriteL(favourite);
+		}
+	
+	aEntryArray.AppendL(iEntry); // takes ownership of entry
+	iEntry = NULL;
+	}
 
- 	// get properties but don't take ownership of the elements of the array
- 	CArrayPtr<CParserProperty>* properties = aParser.PropertyL(KVersitTokenSUMMARY, TUid::Uid(KVersitPropertyHBufCUid), EFalse);
-
+// -----------------------------------------------------------------------------
+// CVCalToAgendaEntryConverter::ImportVCalendarL
+// Imports vcalendar for calendar types EAppt/EReminder/EAnniv/ETodo/EEvent
+// -----------------------------------------------------------------------------
+// 
+void CVCalToAgendaEntryConverter::ImportVCalendarL(CVersitParser& aParser,
+		TVersitDateTime::TRelativeTime& aRelativeTime,
+		CCalEntry::TType& aEntryType)
+	{
+	// Fill in the entry description from the SUMMARY property
+	// If this doesn't exist, use the DESCRIPTION property, and if this
+	// doesn't exist, return a NULL entry
+	
+	// get properties but don't take ownership of the elements of the array
+	CArrayPtr<CParserProperty>* properties = aParser.PropertyL(
+			KVersitTokenSUMMARY, TUid::Uid(KVersitPropertyHBufCUid), EFalse);
+	
 	if (!properties)
 		{
 		// get properties but don't take ownership of the elements of the array
-		properties = aParser.PropertyL(KVersitTokenDESCRIPTION, TUid::Uid(KVersitPropertyHBufCUid), EFalse);
+		properties = aParser.PropertyL(KVersitTokenDESCRIPTION,
+				TUid::Uid(KVersitPropertyHBufCUid), EFalse);
 		}
 	CleanupStack::PushL(properties);
 	
@@ -221,7 +262,8 @@
 	TPtrC summary;
 	if (properties)
 		{
-		summary.Set(static_cast<CParserPropertyValueHBufC*>((*properties)[0]->Value())->Value());
+		summary.Set(static_cast<CParserPropertyValueHBufC*>(
+				(*properties)[0]->Value())->Value());
 		}
 		
 	HBufC* summaryBuf = AgnConvertUtil::EncodeL(summary,KUidTextToEtextNoTrim);
@@ -231,7 +273,7 @@
 		iEntry->SetSummaryL(*summaryBuf);
 		}
 	CleanupStack::PopAndDestroy(summaryBuf);
-
+	
 	HBufC* description =ImportDesPropertyL(aParser,KVersitTokenDESCRIPTION);
 	CleanupStack::PushL(description);
 	if (description != NULL)
@@ -239,9 +281,9 @@
 		iEntry->SetDescriptionL(*description); // Takes ownership
 		}
 	CleanupStack::PopAndDestroy(description);
-
+	
 	TBool validEntry = EFalse;
-	if (entryType == CCalEntry::ETodo)
+	if (aEntryType == CCalEntry::ETodo)
 		{
 		validEntry = ImportTodoPropertiesL(aParser);
 		}
@@ -257,7 +299,7 @@
 		iEntry = NULL;
 		return;
 		}
-
+	
 	// Import CLASS property
 	HBufC* property=ImportDesPropertyL(aParser, KVersitTokenCLASS);
 	if (property)
@@ -271,17 +313,19 @@
 			iEntry->SetReplicationStatusL(CCalEntry::ERestricted);
 		CleanupStack::PopAndDestroy(property);
 		}
+	
 	// Import LOCATION property
-	property=ImportDesPropertyL(aParser, KVersitTokenLOCATION);
-	if (property)
+	HBufC* locationProperty=ImportDesPropertyL(aParser, KVersitTokenLOCATION);
+	if (locationProperty)
 		{
-		CleanupStack::PushL(property);
-		iEntry->SetLocationL(*property);
-		CleanupStack::PopAndDestroy(property);
+		CleanupStack::PushL(locationProperty);
+		iEntry->SetLocationL(*locationProperty);
+		CleanupStack::PopAndDestroy(locationProperty);
 		}
 	// Import DTSTAMP
 	TTime timeProperty;
-	if (ImportDateTimePropertyL(aParser, KVersitTokenXDTSTAMP, timeProperty, relativeTime))
+	if (ImportDateTimePropertyL(aParser, KVersitTokenXDTSTAMP, timeProperty,
+			aRelativeTime))
 		{
 		TCalTime caltimeProperty;
 		caltimeProperty.SetTimeUtcL(timeProperty);
@@ -289,13 +333,12 @@
 		}
 	
 	// Attendee property
- 	ImportAttendeePropertiesL(aParser, KVersitTokenATTENDEE);
-
+	ImportAttendeePropertiesL(aParser, KVersitTokenATTENDEE);
+	
 	// Categories property
 	ImportCategoriesPropertyL(aParser, KVersitTokenCATEGORIES);
-
 	
-		
+	
 	TInt localId;
 	if (ImportIntegerPropertyL(aParser, KVersitTokenXLOCALUID, localId))
 		{
@@ -308,23 +351,25 @@
 	TInt priority;
 	if (ImportIntegerPropertyL(aParser, KVersitTokenPRIORITY, priority))
 		{
-		iEntry->SetPriorityL(priority);  
+		iEntry->SetPriorityL(priority);	
 		}
-
+	
 	// All entries have a status - will default to Needs Action if cannot be read
 	CCalEntry::TStatus entryStatus=CCalEntry::ENullStatus;
 	ImportStatusPropertyL(aParser, entryStatus);
 	//Now sync completed and ECompleted status to keep entry consistenty 
-	if(entryType==CCalEntry::ETodo && (iEntry->CompletedTimeL().TimeUtcL()) != Time::NullTTime())
+	if (aEntryType == CCalEntry::ETodo
+			&& (iEntry->CompletedTimeL().TimeUtcL()) != Time::NullTTime())
 		{
 		iEntry->SetCompletedL(ETrue, iEntry->CompletedTimeL());
 		}
 	iEntry->SetStatusL(entryStatus);
 	
 	//Get last changed date from vcal
-	if (ImportDateTimePropertyL(aParser, KVersitTokenLASTMODIFIED, timeProperty, relativeTime))
+	if (ImportDateTimePropertyL(aParser, KVersitTokenLASTMODIFIED,
+			timeProperty, aRelativeTime))
 			{
-			if (iTzZone && (relativeTime == TVersitDateTime::EIsVCardLocal))
+			if (iTzZone && (aRelativeTime == TVersitDateTime::EIsVCardLocal))
 				{
 				iTzZone->ConvertToUtcL(timeProperty);
 				}
@@ -351,7 +396,8 @@
 	if (geoString != NULL)
 		{
 		CleanupStack::PushL(geoString);
-		// Determine the position of the delimiter for extraction of the geo latitude and longitude values
+		// Determine the position of the delimiter for extraction of the 
+		// geo latitude and longitude values
 		TInt delimiterPos = geoString->Locate(KVersitTokenCommaVal);
 		
 		if(delimiterPos!=KErrNotFound)
@@ -364,7 +410,8 @@
 			TReal geoLatitude;
 			TReal geoLongitude;
 			
-			if((geoLatitudeLex.Val(geoLatitude)==KErrNone) && (geoLongitudeLex.Val(geoLongitude)==KErrNone))
+			if ((geoLatitudeLex.Val(geoLatitude) == KErrNone)
+					&& (geoLongitudeLex.Val(geoLongitude) == KErrNone))
 				{
 				CCalGeoValue* importedGeoValue=CCalGeoValue::NewL();
 				CleanupStack::PushL(importedGeoValue);
@@ -380,8 +427,82 @@
 		}
 	
 	CleanupStack::PopAndDestroy(properties);
-	aEntryArray.AppendL(iEntry); // takes ownership of entry
-	iEntry = NULL;
+	}
+
+// -----------------------------------------------------------------------------
+// CVCalToAgendaEntryConverter::ImportNoteL
+// Imports note from vcal and maps it to CCalEntry::ENote
+// -----------------------------------------------------------------------------
+// 
+void CVCalToAgendaEntryConverter::ImportNoteL(CVersitParser& aParser,
+		TVersitDateTime::TRelativeTime& aRelativeTime)
+	{
+	
+	// set description to entry from vcal
+	// if description property is not present,look for summary property and
+	// set the summary as description field for the note
+	CArrayPtr<CParserProperty>* properties = aParser.PropertyL(
+		KVersitTokenDESCRIPTION, TUid::Uid(KVersitPropertyHBufCUid),EFalse);
+	if(!properties)
+		{
+		properties = aParser.PropertyL(KVersitTokenSUMMARY, TUid::Uid(
+				KVersitPropertyHBufCUid), EFalse);
+		CleanupStack::PushL(properties);
+		TPtrC summary;
+		if (properties)
+			{
+			summary.Set(static_cast<CParserPropertyValueHBufC*>(
+					(*properties)[0]->Value())->Value());
+			}
+			
+		HBufC* summaryBuf = AgnConvertUtil::EncodeL(summary,
+				KUidTextToEtextNoTrim);
+		CleanupStack::PushL(summaryBuf);
+		if (summaryBuf)
+			{
+			iEntry->SetDescriptionL(*summaryBuf);
+			}
+		CleanupStack::PopAndDestroy(summaryBuf);
+		CleanupStack::PopAndDestroy(properties);
+		}
+	else
+		{
+		HBufC* description = ImportDesPropertyL(aParser,KVersitTokenDESCRIPTION);
+		CleanupStack::PushL(description);
+		if (description != NULL)
+			{
+			iEntry->SetDescriptionL(*description); // Takes ownership
+			}
+		CleanupStack::PopAndDestroy(description);
+		}
+	
+	// get local uid from vcal
+	TInt localId;
+	if (ImportIntegerPropertyL(aParser, KVersitTokenXLOCALUID, localId))
+		{
+		iEntry->SetLocalUidL(localId);
+		}
+	
+	// get last changed date from vcal
+	TTime timeProperty;
+	if (ImportDateTimePropertyL(aParser, KVersitTokenLASTMODIFIED,
+			timeProperty, aRelativeTime))
+		{
+		if (iTzZone && (aRelativeTime == TVersitDateTime::EIsVCardLocal))
+			{
+			iTzZone->ConvertToUtcL(timeProperty);
+			}
+		TCalTime lastModifiedDate;
+		lastModifiedDate.SetTimeUtcL(timeProperty);
+		iEntry->SetLastModifiedDateL(lastModifiedDate);
+		}
+	else
+		{
+		iEntry->SetLastModifiedDateL(); //set changed date to now
+		}
+	
+	// get attachments from the vcal
+	ImportAttachmentPropertyL(aParser);
 	}
 
 CVCalToAgendaEntryConverter::~CVCalToAgendaEntryConverter()
@@ -478,6 +599,11 @@
 			return CCalEntry::EReminder;
 			}
 		
+		if (type == KVCalTokenTypeNOTE)
+			{
+			return CCalEntry::ENote;
+			}
+		
 		}
 
 	// return an appointment as default type