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:: AddRepeatL(const TDesC& aDescription, TInt aWeeklyInterval)
00053 {
00054
00055 HBufC8* guid = MakeGuidLC();
00056 CCalEntry* entry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0);
00057 CleanupStack::Pop(guid);
00058 CleanupStack::PushL(entry);
00059
00060
00061 TTime now;
00062 now.UniversalTime();
00063 now += TTimeIntervalHours(1);
00064 TCalTime start;
00065 start.SetTimeUtcL(now);
00066 now += TTimeIntervalHours(1);
00067 TCalTime end;
00068 end.SetTimeUtcL(now);
00069 entry->SetStartAndEndTimeL(start, end);
00070 entry->SetDescriptionL(aDescription);
00071
00072
00073 TCalRRule rule(TCalRRule::EWeekly);
00074 rule.SetDtStart(start);
00075 rule.SetCount(52/aWeeklyInterval);
00076 rule.SetInterval(aWeeklyInterval);
00077
00078 RArray<TDay> days;
00079 CleanupClosePushL(days);
00080 days.AppendL(EMonday);
00081 days.AppendL(ETuesday);
00082 days.AppendL(EWednesday);
00083 days.AppendL(EThursday);
00084 days.AppendL(EFriday);
00085
00086 rule.SetByDay(days);
00087 CleanupStack::PopAndDestroy(&days);
00088 entry->SetRRuleL(rule);
00089
00090
00091 RPointerArray<CCalEntry> array;
00092 CleanupClosePushL(array);
00093 array.AppendL(entry);
00094
00095 TInt success = 0;
00096 iCalView->StoreL(array, success);
00097 if (success < 1)
00098 {
00099 User::Leave(KErrGeneral);
00100 }
00101 CleanupStack::PopAndDestroy(&array);
00102 CleanupStack::PopAndDestroy(entry);
00103 }
00104
00105 const TInt KMaxGuidSize = 64;
00106 _LIT(KDateFormat,"%F%Y%M%D");
00107 _LIT(KTimeSeparator,"T");
00108 _LIT(KTimeFormat,"%F%H%T%S");
00109 _LIT(KTimeDivider,"-");
00110 _LIT(KAddress,"0x2000DF18_QuickRecipes@SymbianPress.com");
00111
00112 HBufC8* CCalWrite::MakeGuidLC()
00113 {
00114 TTime now;
00115 now.UniversalTime();
00116 TBuf<KMaxGuidSize> time;
00117 now.FormatL(time,KTimeFormat);
00118 TBuf<KMaxGuidSize> date;
00119 now.FormatL(date,KDateFormat);
00120
00121 HBufC8* guid = HBufC8::NewLC(KMaxGuidSize);
00122
00123 TPtr8 guidPtr = guid->Des();
00124 guidPtr.Zero();
00125 guidPtr.Append(date);
00126 guidPtr.Append(KTimeSeparator());
00127 guidPtr.Append(time);
00128 guidPtr.Append(KTimeDivider());
00129 guidPtr.Append(KAddress());
00130
00131 return guid;
00132 }
00133
00134