00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CalExample.h"
00017
00018 #include <calinstance.h>
00019
00020 CCalExample::CCalExample()
00021 {
00022 }
00023
00024 CCalExample::~CCalExample()
00025 {
00026 _LIT(KExitMsg,"\n\nPress any key to exit the application ");
00027 iConsole->Printf(KExitMsg);
00028 iConsole->Getch();
00029
00030 delete iCalEntryView;
00031 delete iCalSession;
00032 delete iConsole;
00033 }
00034
00035 CCalExample* CCalExample::NewL()
00036 {
00037 CCalExample* self= new (ELeave) CCalExample();
00038 CleanupStack::PushL(self);
00039 self->ConstructL();
00040 CleanupStack::Pop();
00041 return self;
00042 }
00043
00044 void CCalExample::ConstructL()
00045 {
00046 _LIT(KTitle, "calexample" );
00047 iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
00048
00049 _LIT(KPressAKeyMsg, "\n\nPress any key to step through the example");
00050 iConsole->Printf ( KPressAKeyMsg );
00051 iConsole->Getch ();
00052
00053 iCalSession = CCalSession::NewL();
00054
00055 _LIT(KFileName,"calendarfile");
00056 TRAPD(err, iCalSession->CreateCalFileL(KFileName));
00057
00058 if (err != KErrAlreadyExists)
00059 {
00060 User::LeaveIfError(err);
00061 }
00062
00063 iCalSession->OpenL(KFileName);
00064
00065 _LIT(KProgressMsg, "\nCalendar entry view creation is in progress...");
00066 iConsole->Printf(KProgressMsg);
00067
00068 iCalEntryView = CCalEntryView::NewL(*iCalSession,*this);
00069 CActiveScheduler::Start();
00070 }
00071
00072
00073 void CCalExample::Progress(TInt aProgress)
00074 {
00075 _LIT(KProgressVal,"\n%d%% complete");
00076 iConsole->Printf(KProgressVal,aProgress);
00077 }
00078
00079
00080 void CCalExample::Completed(TInt )
00081 {
00082 CActiveScheduler::Stop();
00083 }
00084
00085
00086 TBool CCalExample::NotifyProgress()
00087 {
00088
00089 return ETrue;
00090 }
00091
00092
00093 void CCalExample::SetEntryDetailsL(CCalEntry* aEntry,const TDesC& aDescription, TDateTime& aStartTime,TDateTime& aEndTime)
00094 {
00095 TCalTime startTime;
00096 TCalTime endTime;
00097
00098
00099 startTime.SetTimeLocalL(aStartTime);
00100 endTime.SetTimeLocalL(aEndTime);
00101 aEntry->SetStartAndEndTimeL(startTime, endTime);
00102
00103
00104 aEntry->SetDescriptionL(aDescription);
00105
00106
00107 const RPointerArray<CCalCategory> categoryList = aEntry->CategoryListL();
00108 if(categoryList.Count() == 0)
00109 {
00110 TBuf<32> buf;
00111 _LIT(KCategoryName, "Dummy Category");
00112 buf.Copy(KCategoryName);
00113
00114 CCalCategory* category = CCalCategory::NewL(buf);
00115 CleanupStack::PushL(category);
00116 aEntry->AddCategoryL(category);
00117 CleanupStack::Pop(category);
00118 }
00119
00120
00121 const RPointerArray<CCalAttendee>attendeeList = aEntry->AttendeesL();
00122 if(attendeeList.Count() == 0)
00123 {
00124 _LIT(KAttendeeOne, "nokiauk@nokia.com");
00125 _LIT(KAttendeeTwo, "nokiaindia@nokia.com");
00126
00127 CCalAttendee* attendeeOne = CCalAttendee::NewL(KAttendeeOne);
00128 CleanupStack::PushL(attendeeOne);
00129 aEntry->AddAttendeeL(attendeeOne);
00130 CleanupStack::Pop(attendeeOne);
00131
00132 CCalAttendee* attendeeTwo = CCalAttendee::NewL(KAttendeeTwo);
00133 CleanupStack::PushL(attendeeTwo);
00134 aEntry->AddAttendeeL(attendeeTwo);
00135 CleanupStack::Pop(attendeeTwo);
00136 }
00137 }
00138
00139
00140 void CCalExample::AddEntryL()
00141 {
00142 const TDesC8& guidDes = KGuid;
00143 HBufC8* guid = guidDes.AllocL();
00144
00145 CCalEntry* entry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0);
00146 CleanupStack::PushL(entry);
00147
00148
00149 TDateTime startTime(2006, EJanuary, 04, 10, 0, 0, 0);
00150 TDateTime endTime(2006, EJanuary, 05, 16, 0, 0, 0);
00151
00152 _LIT(KAddingMsg, "\n\nAdding an entry...");
00153 iConsole->Printf ( KAddingMsg );
00154
00155 _LIT(KDescription,"Meeting is scheduled in 1st week of January");
00156 SetEntryDetailsL(entry,KDescription, startTime, endTime);
00157
00158 RPointerArray<CCalEntry> array;
00159 CleanupClosePushL(array);
00160 array.AppendL(entry);
00161
00162 TInt success(0);
00163
00164
00165 iCalEntryView->StoreL(array, success);
00166
00167 CleanupStack::PopAndDestroy(&array);
00168 CleanupStack::PopAndDestroy(entry);
00169 }
00170
00171
00172 void DestroyRPointerArray(TAny* aPtr)
00173 {
00174 RPointerArray<CCalEntry>* self = static_cast<RPointerArray<CCalEntry>*> (aPtr);
00175 self->ResetAndDestroy();
00176 }
00177
00178
00179 void CCalExample::UpdateEntryL()
00180 {
00181 RPointerArray<CCalEntry> array;
00182 CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &array));
00183 iCalEntryView->FetchL(KGuid, array);
00184
00185
00186 _LIT(KUpdatingMsg,"\n\nUpdating the entry...");
00187 iConsole->Printf(KUpdatingMsg);
00188 CCalEntry* entry = array[0];
00189
00190 _LIT(KNewDescription,"Meeting rescheduled to 2nd week of January");
00191 TDateTime startTime(2006, EJanuary, 11, 10, 0, 0, 0);
00192 TDateTime endTime(2006, EJanuary, 12, 16, 0, 0, 0);
00193 SetEntryDetailsL(entry,KNewDescription, startTime, endTime);
00194
00195 TInt numberOfEntries(0);
00196
00197
00198 iCalEntryView->UpdateL(array,numberOfEntries);
00199 CleanupStack::PopAndDestroy(&array);
00200 }
00201
00202
00203 void CCalExample::AddOriginatingEntryL()
00204 {
00205 _LIT(KAddingMsg, "\n\nAdding a repeating entry...");
00206 iConsole->Printf ( KAddingMsg );
00207
00208 TTime startTime(TDateTime(2006, EJanuary, 0, 14, 0, 0, 0));
00209 TTime endTime(startTime + TTimeIntervalHours(1));
00210
00211 const TDesC8& guidDes = KGuid;
00212 HBufC8* guid = guidDes.AllocL();
00213 CCalEntry* originatingEntry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0);
00214 CleanupStack::PushL(originatingEntry);
00215
00216 _LIT(KDescription,"An originating entry");
00217 originatingEntry->SetDescriptionL(KDescription);
00218
00219 TCalTime entryStartTime;
00220 entryStartTime.SetTimeLocalL(startTime);
00221 TCalTime entryEndTime;
00222 entryEndTime.SetTimeLocalL(endTime);
00223 originatingEntry->SetStartAndEndTimeL(entryStartTime, entryEndTime);
00224
00225
00226
00227 TCalRRule weeklyRptRule(TCalRRule::EWeekly);
00228 weeklyRptRule.SetDtStart(entryStartTime);
00229 weeklyRptRule.SetCount(3);
00230 weeklyRptRule.SetInterval(1);
00231
00232 RArray<TDay> days;
00233 CleanupClosePushL(days);
00234 days.AppendL(ESunday);
00235 weeklyRptRule.SetByDay(days);
00236 CleanupStack::PopAndDestroy(&days);
00237 originatingEntry->SetRRuleL(weeklyRptRule);
00238
00239
00240 RPointerArray<CCalEntry> array;
00241 CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &array));
00242 array.AppendL(originatingEntry);
00243 TInt success(0);
00244
00245
00246 iCalEntryView->StoreL(array, success);
00247
00248
00249 array.Close();
00250 CleanupStack::PopAndDestroy(&array);
00251 CleanupStack::PopAndDestroy(originatingEntry);
00252 }
00253
00254
00255
00256
00257 void CCalExample::AddmodifyingEntryL()
00258 {
00259 RPointerArray<CCalEntry> modifyingArray;
00260 CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &modifyingArray));
00261
00262 _LIT(KAddingMsg, "\n\nAdding a modifying entry...");
00263 iConsole->Printf ( KAddingMsg );
00264
00265
00266
00267 TTime recurrenceId(TDateTime(2006, EJanuary, 7, 14, 0, 0, 0));
00268 TCalTime recurrenceIdCal;
00269 recurrenceIdCal.SetTimeLocalL(recurrenceId);
00270
00271 const TDesC8& guidDes = KGuid;
00272 HBufC8* guid = guidDes.AllocL();
00273
00274
00275 CCalEntry* modifyingEntry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 1, recurrenceIdCal, CalCommon::EThisAndFuture);
00276 CleanupStack::PushL(modifyingEntry);
00277
00278
00279 _LIT(KChildDescription,"A modifying entry");
00280 modifyingEntry->SetDescriptionL(KChildDescription);
00281
00282 TTime childStartTime(TDateTime(2006, EJanuary, 8, 14, 0, 0, 0));
00283 TTime childEndTime(childStartTime + TTimeIntervalHours(1));
00284
00285 TCalTime childEntryStartTime;
00286 childEntryStartTime.SetTimeLocalL(childStartTime);
00287 TCalTime childEntryEndTime;
00288 childEntryEndTime.SetTimeLocalL(childEndTime);
00289 modifyingEntry->SetStartAndEndTimeL(childEntryStartTime, childEntryEndTime);
00290
00291 TCalRRule childRptRule(TCalRRule::EWeekly);
00292 childRptRule.SetDtStart(childEntryStartTime);
00293 childRptRule.SetCount(2);
00294 childRptRule.SetInterval(1);
00295
00296
00297 RArray<TDay> days;
00298 CleanupClosePushL(days);
00299 days.AppendL(EMonday);
00300 childRptRule.SetByDay(days);
00301 CleanupStack::PopAndDestroy(&days);
00302 modifyingEntry->SetRRuleL(childRptRule);
00303
00304
00305 modifyingArray.AppendL(modifyingEntry);
00306
00307 TInt success(0);
00308
00309
00310 iCalEntryView->StoreL(modifyingArray, success);
00311
00312
00313 CleanupStack::PopAndDestroy(modifyingEntry);
00314 modifyingArray.Reset();
00315 CleanupStack::PopAndDestroy(&modifyingArray);
00316 }
00317
00318
00319
00320 void CCalExample::FindInstanceL()
00321 {
00322 _LIT(KPressAKeyMsg, "\n\nPress any key to view the instances");
00323 iConsole->Printf(KPressAKeyMsg);
00324 iConsole->Getch ();
00325 _LIT(KProgressMsg, "\nCalendar instance view creation is in progress...");
00326 iConsole->Printf(KProgressMsg);
00327 CCalInstanceView* instanceView = CCalInstanceView::NewL(*iCalSession, *this);
00328 CleanupStack::PushL(instanceView);
00329 CActiveScheduler::Start();
00330
00331 RPointerArray<CCalInstance> instanceList;
00332 CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &instanceList));
00333 CalCommon::TCalViewFilter filter = CalCommon::EIncludeAll;
00334 TCalTime startDateForInstanceSearch;
00335 TCalTime endDateForInstanceSearch;
00336
00337
00338 startDateForInstanceSearch.SetTimeLocalL(TDateTime( 2006, EJanuary, 0, 12, 0, 0, 0));
00339 endDateForInstanceSearch.SetTimeLocalL(TDateTime( 2006, EJanuary, 30, 10, 0, 0, 0));
00340 CalCommon::TCalTimeRange searchTimeRange(startDateForInstanceSearch, endDateForInstanceSearch);
00341
00342
00343 instanceView->FindInstanceL(instanceList, filter, searchTimeRange);
00344
00345 _LIT(KInstancesFound,"\n\nFound %d instances:");
00346 iConsole->Printf(KInstancesFound,instanceList.Count());
00347
00348 TDateTime date;
00349 for(TInt i = 0; i<instanceList.Count(); i++)
00350 {
00351 TPtrC des = instanceList[i]->Entry().DescriptionL();
00352 _LIT(KEntryDesc,"\nDescription: %S");
00353 iConsole->Printf(KEntryDesc,&des);
00354
00355 TTime time = instanceList[i]->StartTimeL().TimeLocalL();
00356 TBuf<40> datetimeStr;
00357 _LIT(KFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S");
00358 time.FormatL(datetimeStr,KFormat);
00359
00360
00361 _LIT(KStartDate,"\nLocal instance start date/time: %S ");
00362 iConsole->Printf(KStartDate,&datetimeStr);
00363 }
00364
00365 CleanupStack::PopAndDestroy(&instanceList);
00366 CleanupStack::PopAndDestroy(instanceView);
00367 }
00368
00369
00370 void CCalExample::PrintEntryDetailsL()
00371 {
00372 _LIT(KPressAKeyMsg, "\nPress any key to view entry details");
00373 iConsole->Printf ( KPressAKeyMsg );
00374 iConsole->Getch ();
00375
00376 RPointerArray<CCalEntry> array;
00377 CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &array));
00378 iCalEntryView->FetchL(KGuid, array);
00379 for(TInt i=0; i<array.Count(); i++)
00380 {
00381 CCalEntry* entry = array[i];
00382 CleanupStack::PushL(entry);
00383
00384 TPtrC des = entry->DescriptionL();
00385 _LIT(KEntryDesc," \n\nDescription: %S");
00386 iConsole->Printf(KEntryDesc,&des);
00387
00388 TCalTime startTime = entry->StartTimeL();
00389 TCalTime endTime = entry->EndTimeL();
00390 TTime time = startTime.TimeLocalL();
00391
00392 TBuf<40> datetimeStr;
00393 _LIT(KFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S");
00394 time.FormatL(datetimeStr,KFormat);
00395
00396
00397 _LIT(KStartDate,"\nStart date/time: %S ");
00398 iConsole->Printf(KStartDate,&datetimeStr);
00399
00400
00401 time = endTime.TimeLocalL();
00402 time.FormatL(datetimeStr,KFormat);
00403 _LIT(KEndDate,"\nEnd date/time: %S");
00404 iConsole->Printf(KEndDate,&datetimeStr);
00405 CleanupStack::Pop(entry);
00406
00407
00408 RPointerArray<CCalCategory> categoryList = entry->CategoryListL();
00409 for( int j=0; j<categoryList.Count(); j++)
00410 {
00411 const TDesC& category = categoryList[j]->ExtendedCategoryName();
00412 HBufC* catbuf = category.AllocL();
00413 _LIT(KCatType,"\nCategory type: %S");
00414 iConsole->Printf(KCatType,catbuf);
00415 delete catbuf;
00416 }
00417
00418
00419 RPointerArray<CCalAttendee> attendeeList;
00420 attendeeList = entry->AttendeesL();
00421 for( int k=0; k<attendeeList.Count(); k++)
00422 {
00423 const TDesC16& address = attendeeList[k]->Address();
00424 HBufC16* addr = address.AllocL();
00425 _LIT(KAttendee,"\nAttendee %d: %S");
00426 iConsole->Printf(KAttendee,k+1, addr);
00427 delete addr;
00428 }
00429 }
00430 CleanupStack::PopAndDestroy(&array);
00431 }
00432
00433
00434 void CCalExample::DeleteEntryL()
00435 {
00436 _LIT(KPressAKeyMsg, "\n\nPress any key to delete the originating entry, (also deletes the modifying entry)");
00437 iConsole->Printf ( KPressAKeyMsg );
00438 iConsole->Getch ();
00439
00440 RPointerArray<CCalEntry> entryArray;
00441 CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &entryArray));
00442
00443
00444 iCalEntryView->FetchL(KGuid, entryArray);
00445 CCalEntry* entry = entryArray[0];
00446
00447
00448 iCalEntryView->DeleteL(*entry);
00449 CleanupStack::PopAndDestroy(&entryArray);
00450 }
00451
00452 LOCAL_C void MainL()
00453 {
00454 CCalExample* app = CCalExample::NewL();
00455 CleanupStack::PushL(app);
00456
00457
00458 app->AddEntryL();
00459 app->PrintEntryDetailsL();
00460
00461
00462 app->UpdateEntryL();
00463 app->PrintEntryDetailsL();
00464
00465
00466 app->AddOriginatingEntryL();
00467 app->PrintEntryDetailsL();
00468
00469
00470 app->FindInstanceL();
00471
00472
00473 app->AddmodifyingEntryL();
00474 app->PrintEntryDetailsL();
00475
00476
00477 app->FindInstanceL();
00478
00479
00480 app->DeleteEntryL();
00481
00482 CleanupStack::PopAndDestroy(app);
00483 }
00484
00485 GLDEF_C TInt E32Main()
00486 {
00487 __UHEAP_MARK;
00488
00489 CActiveScheduler* scheduler=new CActiveScheduler;
00490
00491
00492 if (scheduler)
00493 {
00494 CActiveScheduler::Install(scheduler);
00495
00496
00497 CTrapCleanup* cleanup = CTrapCleanup::New();
00498 if(cleanup)
00499 {
00500 TRAPD(err, MainL());
00501 if(err != KErrNone)
00502 {
00503 _LIT(KUserPanic,"Failed to complete");
00504 User::Panic(KUserPanic, err);
00505 }
00506 delete cleanup;
00507 }
00508 }
00509 delete scheduler;
00510
00511 __UHEAP_MARKEND;
00512 return KErrNone;
00513 }