00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "CalWrite.h"
00018
00019 CCalWrite* CCalWrite::NewL()
00020 {
00021 CCalWrite* self = new (ELeave) CCalWrite();
00022 CleanupStack::PushL(self);
00023 self->ConstructL();
00024 CleanupStack::Pop(self);
00025 return self;
00026 }
00027
00028 CCalWrite::~CCalWrite()
00029 {
00030 delete iCalView;
00031 delete iCalSes;
00032 }
00033
00034 void CCalWrite::ConstructL()
00035 {
00036 iCalSes = CCalSession::NewL();
00037 const TDesC& name = iCalSes->DefaultFileNameL();
00038 TRAPD(error, iCalSes->CreateCalFileL(name));
00039 if (error != KErrAlreadyExists)
00040 {
00041 User::LeaveIfError(error);
00042 }
00043 iCalSes->OpenL(KNullDesC());
00044 iCalView = CCalEntryView::NewL(*iCalSes, *this);
00045 }
00046
00047 void CCalWrite::AddNewL(TTime aStartUtc, const TDesC& aDescription, const CDesCArray& aAttendees)
00048 {
00049
00050 HBufC8* guid = MakeGuidLC();
00051 CCalEntry* entry = CCalEntry::NewL(CCalEntry::EAppt, guid,
00052 CCalEntry::EMethodNone, 0);
00053 CleanupStack::Pop(guid);
00054 CleanupStack::PushL(entry);
00055
00056
00057 TCalTime start;
00058 start.SetTimeUtcL(aStartUtc);
00059 TTime endUtc = aStartUtc;
00060 endUtc += TTimeIntervalHours(1);
00061 TCalTime end;
00062 end.SetTimeUtcL(endUtc);
00063 entry->SetStartAndEndTimeL(start, end);
00064 entry->SetDescriptionL(aDescription);
00065
00066 for (TInt ii = 0 ; ii < aAttendees.MdcaCount() ; ++ii)
00067 {
00068 CCalAttendee* user = CCalAttendee::NewL(aAttendees.MdcaPoint(ii));
00069 user->SetResponseRequested(EFalse);
00070 entry->AddAttendeeL(user);
00071
00072 }
00073
00074
00075 RPointerArray<CCalEntry> array;
00076 CleanupClosePushL(array);
00077 array.AppendL(entry);
00078
00079 TInt success = 0;
00080 iCalView->StoreL(array, success);
00081 if (success < 1)
00082 {
00083 User::Leave(KErrGeneral);
00084 }
00085 CleanupStack::PopAndDestroy(&array);
00086 CleanupStack::PopAndDestroy(entry);
00087 }
00088
00089
00090
00091
00092
00093 const TInt KMaxGuidSize = 64;
00094 _LIT(KDateFormat,"%F%Y%M%D");
00095 _LIT(KTimeSeparator,"T");
00096 _LIT(KTimeFormat,"%F%H%T%S");
00097 _LIT(KTimeDivider,"-");
00098 _LIT(KAddress,"0x2000DF18_QuickRecipes@SymbianPress.com");
00099
00100 HBufC8* CCalWrite::MakeGuidLC()
00101 {
00102 TTime now;
00103 now.UniversalTime();
00104 TBuf<KMaxGuidSize> time;
00105 now.FormatL(time,KTimeFormat);
00106 TBuf<KMaxGuidSize> date;
00107 now.FormatL(date,KDateFormat);
00108
00109 HBufC8* guid = HBufC8::NewLC(KMaxGuidSize);
00110
00111 TPtr8 guidPtr = guid->Des();
00112 guidPtr.Zero();
00113 guidPtr.Append(date);
00114 guidPtr.Append(KTimeSeparator());
00115 guidPtr.Append(time);
00116 guidPtr.Append(KTimeDivider());
00117 guidPtr.Append(KAddress());
00118
00119 return guid;
00120 }
00121
00122
00123