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 CCalEntryView& CCalWrite::CalView()
00048 {
00049 return *iCalView;
00050 }
00051
00052 void CCalWrite::AddNewL(TTime aStartUtc, const TDesC& aDescription)
00053 {
00054
00055 HBufC8* guid = MakeGuidLC();
00056 CCalEntry* entry = CCalEntry::NewL(CCalEntry::EAppt, guid,
00057 CCalEntry::EMethodNone, 0);
00058 CleanupStack::Pop(guid);
00059 CleanupStack::PushL(entry);
00060
00061
00062 TCalTime start;
00063 start.SetTimeUtcL(aStartUtc);
00064 TTime endUtc = aStartUtc;
00065 endUtc += TTimeIntervalHours(1);
00066 TCalTime end;
00067 end.SetTimeUtcL(endUtc);
00068 entry->SetStartAndEndTimeL(start, end);
00069 entry->SetDescriptionL(aDescription);
00070
00071
00072 RPointerArray<CCalEntry> array;
00073 CleanupClosePushL(array);
00074 array.AppendL(entry);
00075
00076 TInt success = 0;
00077 iCalView->StoreL(array, success);
00078 if (success < 1)
00079 {
00080 User::Leave(KErrGeneral);
00081 }
00082 CleanupStack::PopAndDestroy(&array);
00083 CleanupStack::PopAndDestroy(entry);
00084 }
00085
00086
00087
00088
00089
00090 const TInt KMaxGuidSize = 64;
00091 _LIT(KDateFormat,"%F%Y%M%D");
00092 _LIT(KTimeSeparator,"T");
00093 _LIT(KTimeFormat,"%F%H%T%S");
00094 _LIT(KTimeDivider,"-");
00095 _LIT(KAddress,"0x2000DF18_QuickRecipes@SymbianPress.com");
00096
00097 HBufC8* CCalWrite::MakeGuidLC()
00098 {
00099 TTime now;
00100 now.UniversalTime();
00101 TBuf<KMaxGuidSize> time;
00102 now.FormatL(time,KTimeFormat);
00103 TBuf<KMaxGuidSize> date;
00104 now.FormatL(date,KDateFormat);
00105
00106 HBufC8* guid = HBufC8::NewLC(KMaxGuidSize);
00107
00108 TPtr8 guidPtr = guid->Des();
00109 guidPtr.Zero();
00110 guidPtr.Append(date);
00111 guidPtr.Append(KTimeSeparator());
00112 guidPtr.Append(time);
00113 guidPtr.Append(KTimeDivider());
00114 guidPtr.Append(KAddress());
00115
00116 return guid;
00117 }
00118
00119
00120