// AGMVCAL.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//


#if !defined(__AGMVCAL_H__)
#define __AGMVCAL_H__


#if !defined(__VCAL_H__)
#include <vcal.h>
#endif

#if !defined(__AGMENTRY_H__)
#include <agmentry.h>
#endif

#if !defined(__AGMMODEL_H__)
#include <agmmodel.h>
#endif

#include "apgdoor.h"


#include "concnf.h"
#include "confndr.h"
#include "conlist.h"


#pragma warning (disable: 4239)
// Disable 'nonstandard extension used', which
// occurs when using versit functions



const TUid KUidApaDoorStateStream={0x1000012a};
//const TUid KUidApaDoorDocStream={0x10000144};

#if defined (_UNICODE) // Change these Uid's when converters are ready
const TUid KPlainTextToWordConverterUid={0x10001823};
const TUid KWordToPlainTextConverterUid={0x10001824};
#else
const TUid KPlainTextToWordConverterUid={0x10001823};
const TUid KWordToPlainTextConverterUid={0x10001824};
#endif

#define KConverterBufferSize 1024

// Extended VCal fields

#define KVCalTokenENTRYTYPE _L("AGENDAENTRYTYPE")	// for externalizing
#define KVCalTokenXDASHENTRYTYPE _L("X-EPOCAGENDAENTRYTYPE") // for internalizing

#define KVCalTokenTypeAPPT _L("APPOINTMENT")
#define KVCalTokenTypeANNIV _L("ANNIVERSARY")
#define KVCalTokenTypeEVENT _L("EVENT")
#define KVCalTokenTypeTODO _L("TODO")

#define KVCalTokenPUBLIC _L("PUBLIC")
#define KVCalTokenPRIVATE _L("PRIVATE")
#define KVCalTokenCONFIDENTIAL _L("CONFIDENTIAL")

#define KVCalTokenTYPE _L("TYPE")
#define KVCalValueEPOCSOUND _L("X-EPOCSOUND")


// Attendee defines
#define KVCalAttendeeROLE _L("ROLE")
#define KVCalAttendeeSTATUS _L("STATUS")
#define KVCalAttendeeRSVP _L("RSVP")
#define KVCalAttendeeEXPECT _L("EXPECT")

#define KVCalAttendeeRoleATTENDEE _L("ATTENDEE")
#define KVCalAttendeeRoleORGANIZER _L("ORGANIZER")
#define KVCalAttendeeRoleOWNER _L("OWNER")
#define KVCalAttendeeRoleDELEGATE _L("DELEGATE")

#define KVCalAttendeeStatusACCEPTED _L("ACCEPTED")
#define KVCalAttendeeStatusNEEDSACTION _L("NEEDSACTION")
#define KVCalAttendeeStatusSENT _L("SENT")
#define KVCalAttendeeStatusTENTATIVE _L("TENTATIVE")
#define KVCalAttendeeStatusCONFIRMED _L("CONFIRMED")
#define KVCalAttendeeStatusDECLINED _L("DECLINED")
#define KVCalAttendeeStatusCOMPLETED _L("COMPLETED")
#define KVCalAttendeeStatusDELEGATED _L("DELEGATED")

#define KVCalAttendeeRsvpYES _L("YES")
#define KVCalAttendeeRsvpNO _L("NO")

#define KVCalAttendeeExpectFYI _L("FYI")
#define KVCalAttendeeExpectREQUIRE _L("REQUIRE")
#define KVCalAttendeeExpectREQUEST _L("REQUEST")
#define KVCalAttendeeExpectIMMEDIATE _L("IMMEDIATE")


// Picture type for adding document data to a CRichText

class CMemoPicture : public CApaDoorBase
	{
public:
	CMemoPicture(CBufFlat* aBuffer);
	~CMemoPicture();

	static CMemoPicture* NewL(CBufFlat* aBuffer);
// from CPicture
	void Draw(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect,
						MGraphicsDeviceMap* aMap)const; // draws according to current iPicFormat
	void GetOriginalSizeInTwips(TSize& aSize)const;
	TStreamId StoreL(CStreamStore& aStore) const;
private:
	// required so CPicture's can be swizzled
	void ExternalizeL(RWriteStream& aStream)const;
	// from CApaDoorBase
	virtual TSize GlassDoorSize()const;
	void ExternalizeStateStreamL(CStreamStore& aStore,CStreamDictionary& aStreamDict)const;
	void StoreDocumentDataL(CEmbeddedStore& aStore)const;
private:
	CBufFlat*	iBuffer;
	};


// Agenda Entry to VCal conversion

class CAgendaEntryToVCalConverter : public CBase
	{
public:
	void ExportEntryL(CAgnEntry* aEntry, CVersitParser* aParser, CAgnTodoListNames* aTodoNameList, CAgnEntryModel* aModel);
private:
	void AddEntryPropertiesL(CAgnEntry* aEntry, CVersitParser* aParser,CAgnTodoListNames* aTodoNameList, CAgnEntryModel* aModel);
	void AddApptPropertiesL(CVersitParser* aParser, CAgnAppt* aEntry);
	void AddAnnivPropertiesL(CVersitParser* aParser, CAgnAnniv* aEntry);
	void AddEventPropertiesL(CVersitParser* aParser, CAgnEvent* aEntry);
	void AddTodoPropertiesL(CVersitParser* aParser, CAgnTodo* aEntry, CAgnTodoListNames* aTodoNameList);

	void AddRichTextPropertyL(CVersitParser* aParser, const TDesC& aToken, CRichText* aText, CAgnEntryModel* aModel = NULL, TStreamId aRichTextStreamId = KNullStreamId);
	void AddIntegerPropertyL(CVersitParser* aParser, const TDesC& aToken, TInt aInt);
	void AddDateTimePropertyL(CVersitParser* aParser, const TDesC& aToken, TTime aTime);
	void AddDesPropertyL(CVersitParser* aParser, const TDesC& aToken, TDesC& aDes);
	void AddAlarmPropertyL(CVersitParser* aParser, const TDesC& aToken, TTime aAlarmTime, TDesC& aAlarmName);
	void AddAttendeePropertyL(CVersitParser* aParser, CAgnAttendee* aAttendee);
	void AddRepeatPropertiesL(CVersitParser* aParser, CAgnRptDef* aRpt);
	void AddRepeatExceptionPropertiesL(CVersitParser* aParser, CAgnRptDef* aRpt);

	void ExportAttachmentL(CVersitParser* aParser, const TDesC& aToken, CAgnEntryModel* aModel, TPictureHeader aHeader, TStreamId aRichTextStreamId);


	// Repeat properties
	CVersitRecurrence* CreateWeeklyRepeatL(CAgnRptDef* aRpt, TInt aDuration, TVersitDateTime* aEndTime);
	CVersitRecurrence* CreateMonthlyByDaysRepeatL(CAgnRptDef* aRpt, TInt aDuration, TVersitDateTime* aEndTime);
	CVersitRecurrence* CreateMonthlyByDateRepeatL(CAgnRptDef* aRpt, TInt aDuration, TVersitDateTime* aEndTime);
	CVersitRecurrence* CreateYearlyByDaysRepeatL(CAgnRptDef* aRpt, TInt aDuration, TVersitDateTime* aEndTime);
	CVersitRecurrence* CreateYearlyByDateRepeatL(CAgnRptDef* aRpt, TInt aDuration, TVersitDateTime* aEndTime, TMonth aMonth);

private:
	CParserVCal *iVCal;
	};


// VCal to Agenda Entry conversion

class CVCalToAgendaEntryConverter : public CBase
	{
public:
	CAgnEntry* ImportVCalL(CVersitParser* aParser, CAgnEntryModel* aModel, const TDesC& aEntryName, CAgnTodoListNames* aTodoNameList=NULL);
private:
	CAgnEntry::TType GetEntryTypeL(CVersitParser* aParser, const TDesC& aEntityType);
	TBool GetStartAndEndDatesL(CVersitParser* aParser, TTime& aStartDate, TTime& aEndDate);

	TBool ImportApptPropertiesL(CVersitParser* aParser, CAgnAppt* aEntry);
	TBool ImportEventPropertiesL(CVersitParser* aParser, CAgnEvent* aEntry);
	TBool ImportAnnivPropertiesL(CVersitParser* aParser, CAgnAnniv* aEntry);
	TBool ImportTodoPropertiesL(CVersitParser* aParser, CAgnTodo* aEntry, CAgnTodoListNames* aTodoNameList);

	TBool ImportDateTimePropertyL(CVersitParser* aParser, const TDesC& aToken, TTime& aValue);
	TBool ImportIntegerPropertyL(CVersitParser* aParser, const TDesC& aToken, TInt& aValue);
	TBool ImportDesPropertyL(CVersitParser* aParser, const TDesC& aToken, TDes& aDes);
	TBool ImportAlarmPropertyL(CVersitParser* aParser, const TDesC& aToken, TTime aStartTime);
	void ImportAttendeePropertiesL(CVersitParser* aParser, const TDesC& aToken);

	void ImportRepeatPropertyL(CVersitParser* aParser, const TDesC& aToken, TTime aStartDate);
	void ImportDailyRepeatPropertiesL(CAgnRptDef* aRpt);
	void ImportWeeklyRepeatPropertiesL(CVersitRecurrenceWeekly* aRepeat, CAgnRptDef* aRpt);
	void ImportMonthlyByDayRepeatPropertiesL(CVersitRecurrenceMonthlyByDay* aRepeat, CAgnRptDef* aRpt, TInt aDefaultDayOfMonth);
	void ImportMonthlyByPosRepeatPropertiesL(CVersitRecurrenceMonthlyByPos* aRepeat, CAgnRptDef* aRpt);
	void ImportYearlyByMonthRepeatPropertiesL(CVersitRecurrenceYearlyByMonth* aRepeat, CAgnRptDef* aRpt);
	void ImportRepeatExceptionPropertiesL(CVersitParser* aParser, const TDesC& aToken, CAgnRptDef* aRpt);

	void ImportAttachmentsL(CVersitParser* aParser, const TDesC& aToken, CRichText* aText, CAgnEntryModel* aModel);
	void AddAttachmentL(TDesC& aAttachment, CRichText* aText, CAgnEntryModel* aModel);

private:
	CAgnEntry*	iEntry;
	};

#endif
