00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <calsession.h>
00032 #include <calentryview.h>
00033 #include <CalInstance.h>
00034 #include <calinstanceview.h>
00035 #include <txtfmlyr.h>
00036 #include <calalarm.h>
00037 #include <CalendarAPIexample.rsg>
00038 #include "CalendarAPIexampleEngine.h"
00039 #include "CalendarAPIexample.hrh"
00040
00041 #include "CalendarAPIexampleEntryView.h"
00042 #include "CalendarAPIexampleEntryContainer.h"
00043 #include "CalendarAPIexampleEntriesView.h"
00044 #include "CalendarAPIexampleSearchView.h"
00045
00046 #include "CalendarAPIexample.pan"
00047
00048 #include "CalendarAPIexampleEntryView.h"
00049
00050
00051 const TInt KProgressFinalValue = 100;
00052
00053 #define KDefaultEventDisplayTime TTimeIntervalMinutes(660)
00054 #define KDefaultAnnivDisplayTime TTimeIntervalMinutes(900)
00055 #define KDefaultDayNoteDisplayTime TTimeIntervalMinutes(1000)
00056
00057
00058
00059
00060 CCalendarAPIexampleEngine::CCalendarAPIexampleEngine(
00061 MCalenderEngineObserverUI& aAppUi)
00062 : iAppUi(aAppUi)
00063 {
00064
00065
00066 }
00067
00068
00069 CCalendarAPIexampleEngine::~CCalendarAPIexampleEngine()
00070 {
00071
00072 if( iWait )
00073 {
00074 if( iWait->IsStarted() )
00075 {
00076 iWait->AsyncStop();
00077
00078 }
00079 delete iWait;
00080 iWait = NULL;
00081 }
00082 if (iEntryView)
00083 {
00084 delete iEntryView;
00085 iEntryView = 0;
00086 }
00087
00088 if (iInstanceView)
00089 {
00090 delete iInstanceView;
00091 iInstanceView = 0;
00092 }
00093
00094 iEntries.ResetAndDestroy();
00095
00096 delete iEntry;
00097 iEntry = NULL;
00098
00099 delete iProgressDialog;
00100 iProgressDialog = NULL;
00101
00102 if (iCalSession)
00103 {
00104 delete iCalSession;
00105 iCalSession = 0;
00106 }
00107 }
00108
00109
00110
00111 CCalendarAPIexampleEngine* CCalendarAPIexampleEngine::NewL(
00112 MCalenderEngineObserverUI& aAppUi)
00113 {
00114 CCalendarAPIexampleEngine* self =
00115 new (ELeave) CCalendarAPIexampleEngine(aAppUi);
00116 CleanupStack::PushL(self);
00117 self->ConstructL();
00118 CleanupStack::Pop(self);
00119 return self;
00120 }
00121
00122
00123 void CCalendarAPIexampleEngine::ConstructL()
00124 {
00125 iModifyIndex = KUndefinedModifyIndex;
00126
00127
00128 iCalSession = CCalSession::NewL();
00129
00130 const TDesC& file = iCalSession->DefaultFileNameL();
00131
00132 TRAPD(err,iCalSession->OpenL(file) );
00133 if( err == KErrNotFound)
00134 {
00135 iCalSession->CreateCalFileL(file);
00136 iCalSession->OpenL(file);
00137 }
00138 else
00139 {
00140 User::LeaveIfError(err);
00141 }
00142
00143 iWait = new (ELeave) CActiveSchedulerWait;
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 void CCalendarAPIexampleEngine::Progress(TInt aPercentageCompleted)
00159 {
00160 if (!iProgressDialog)
00161 {
00162
00163 TRAPD
00164 (
00165 error,
00166 iProgressDialog = new (ELeave) CAknProgressDialog(
00167 REINTERPRET_CAST(CEikDialog**, &iProgressDialog), ETrue);
00168 iProgressDialog->PrepareLC(R_CALENDARAPIEXAMPLE_PROGRESS_NOTE);
00169 iProgressInfo = iProgressDialog->GetProgressInfoL();
00170 iProgressDialog->RunLD();
00171 )
00172 if (KErrNone == error)
00173 {
00174 iProgressInfo->SetFinalValue(KProgressFinalValue);
00175 iProgressInfo->SetAndDraw(aPercentageCompleted);
00176 }
00177 else
00178 {
00179 delete iProgressDialog;
00180 iProgressDialog = NULL;
00181 }
00182 }
00183 else
00184 {
00185 iProgressInfo->SetAndDraw(aPercentageCompleted);
00186 }
00187 }
00188
00194 void CCalendarAPIexampleEngine::Completed(TInt )
00195 {
00196 if (iCreatingEntryView)
00197 {
00198 if( iWait->IsStarted() )
00199 {
00200 iWait->AsyncStop();
00201 }
00202 else
00203 {
00204 Panic(EWaitNotStarted);
00205 }
00206 iCreatingEntryView = EFalse;
00207 }
00208
00209 if (iProgressDialog)
00210 {
00211 iProgressInfo->SetAndDraw(100);
00212 TRAPD
00213 (
00214 error,
00215 iProgressDialog->ProcessFinishedL();
00216 )
00217 iProgressInfo = NULL;
00218 iProgressDialog = NULL;
00219 }
00220 }
00221
00226 TBool CCalendarAPIexampleEngine::NotifyProgress()
00227 {
00228 return ETrue;
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 void CCalendarAPIexampleEngine::AddAnniversaryL(CCalEntry* aAnniv)
00243 {
00244 if (!iEntryView)
00245 {
00246 iEntryView = CCalEntryView::NewL(*iCalSession, *this);
00247 iCreatingEntryView = ETrue;
00248
00249
00250
00251 if( !iWait->IsStarted() )
00252 {
00253 iWait->Start();
00254 }
00255 else
00256 {
00257 Panic(EWaitAlreadyStarted);
00258 }
00259 }
00260
00261 RPointerArray<CCalEntry> calEntryList;
00262 calEntryList.Append(aAnniv);
00263 TInt num;
00264
00265 iEntryView->StoreL(calEntryList, num);
00266
00267 calEntryList.Reset();
00268
00269 }
00270
00271
00272
00273
00274
00275
00276
00277 void CCalendarAPIexampleEngine::UpdateAnniversaryL( CCalEntry* aAnniv)
00278 {
00279 if (!iEntryView)
00280 {
00281 iEntryView = CCalEntryView::NewL(*iCalSession, *this);
00282 iCreatingEntryView = ETrue;
00283
00284
00285
00286 if( !iWait->IsStarted() )
00287 {
00288 iWait->Start();
00289 }
00290 else
00291 {
00292 Panic(EWaitAlreadyStarted);
00293 }
00294 }
00295 RPointerArray<CCalEntry> calEntryList;
00296 calEntryList.Append(aAnniv);
00297 TInt num;
00298
00299 iEntryView->UpdateL(calEntryList, num);
00300
00301 calEntryList.Reset();
00302 }
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 void CCalendarAPIexampleEngine::DoSearchL(const TSearchType& aType)
00314 {
00315 iEntries.ResetAndDestroy();
00316
00317 iCurrentSearchType = aType;
00318 TTime now;
00319 now.HomeTime();
00320 TDateTime from = now.DateTime();
00321 User::LeaveIfError(from.SetHour(0));
00322 User::LeaveIfError(from.SetMinute(0));
00323 User::LeaveIfError(from.SetSecond(0));
00324 User::LeaveIfError(from.SetMicroSecond(0));
00325
00326
00327 switch (aType)
00328 {
00329 case EWeek:
00330 now += TTimeIntervalDays(7);
00331 break;
00332 case EMonth:
00333 now += TTimeIntervalMonths(1);
00334 break;
00335 case ESixMonths:
00336 now += TTimeIntervalMonths(6);
00337 break;
00338 case EYear:
00339 now += TTimeIntervalYears(1);
00340 break;
00341 }
00342
00343 TDateTime to = now.DateTime();
00344
00345 if (!iInstanceView)
00346 {
00347 iInstanceView = CCalInstanceView::NewL(*iCalSession, *this);
00348 iCreatingEntryView = ETrue;
00349
00350
00351
00352 if( !iWait->IsStarted() )
00353 {
00354 iWait->Start();
00355 }
00356 else
00357 {
00358 Panic(EWaitAlreadyStarted);
00359 }
00360 }
00361
00362 RPointerArray<CCalInstance> instanceArray;
00363 TTime nextDate(from);
00364
00365
00366 nextDate -= TTimeIntervalDays(1);
00367 TTime toDate(to);
00368 TCalTime fromCalTime;
00369 fromCalTime.SetTimeLocalL(from);
00370 TCalTime toCalTime;
00371 toCalTime.SetTimeLocalL(to);
00372 CalCommon::TCalTimeRange timeRange(fromCalTime, toCalTime);
00373
00374 iInstanceView->FindInstanceL(instanceArray, CalCommon::EIncludeAnnivs, timeRange);
00375
00376
00377 for (TInt i = 0; i < instanceArray.Count(); i++)
00378 {
00379 CCalHelperEntry* entry = CCalHelperEntry::NewLC(instanceArray[i]);
00380 User::LeaveIfError(iEntries.Append(entry));
00381 CleanupStack::Pop(entry);
00382 }
00383
00384
00385 instanceArray.Reset();
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 void CCalendarAPIexampleEngine::DeleteEntryL(const TInt& aIndex)
00398 {
00399
00400
00401 if( aIndex == -1)
00402 {
00403 delete iEntry;
00404 iEntry = NULL;
00405 return;
00406 }
00407
00408 if (aIndex < 0 || aIndex >= iEntries.Count())
00409 {
00410 Panic(KInvalidEntryIndex);
00411 }
00412
00413 CCalHelperEntry* entry = iEntries[aIndex];
00414
00415 CCalEntry* anniv = entry->Anniv();
00416
00417 if (!iEntryView)
00418 {
00419 iEntryView = CCalEntryView::NewL(*iCalSession, *this);
00420 iCreatingEntryView = ETrue;
00421
00422
00423
00424
00425 if( !iWait->IsStarted() )
00426 {
00427 iWait->Start();
00428 }
00429 else
00430 {
00431 Panic(EWaitAlreadyStarted);
00432 }
00433 }
00434
00435 iEntryView->DeleteL(*anniv);
00436
00437 iEntries.Remove(aIndex);
00438
00439 delete entry;
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452 void CCalendarAPIexampleEngine::DoAddL()
00453 {
00454
00455 iModifyIndex = KUndefinedModifyIndex;
00456
00457 iAppUi.ActivateView(KEntryViewId);
00458 }
00459
00460
00461
00462
00463
00464
00465
00466
00467 void CCalendarAPIexampleEngine::DoSaveL()
00468 {
00469
00470
00471
00472
00473 if (iEntry)
00474
00475 {
00476 if (iEntry->Modified())
00477 {
00478 iEntry->SaveValuesL();
00479
00480 CCalEntry* anniv = iEntry->Anniv();
00481
00482 if (!iEntryView)
00483 {
00484 iEntryView = CCalEntryView::NewL(*iCalSession, *this);
00485 iCreatingEntryView = ETrue;
00486
00487
00488
00489 if( !iWait->IsStarted() )
00490 {
00491 iWait->Start();
00492 }
00493 else
00494 {
00495 Panic(EWaitAlreadyStarted);
00496 }
00497 }
00498
00499 RPointerArray<CCalEntry> calEntryList;
00500 calEntryList.Append(anniv);
00501 TInt num;
00502
00503 iEntryView->StoreL(calEntryList, num);
00504
00505 calEntryList.Reset();
00506
00507 }
00508 }
00509
00510 else
00511 {
00512 if (0 > iModifyIndex || iEntries.Count() <= iModifyIndex)
00513 {
00514 Panic(KInvalidModifyIndex);
00515 }
00516
00517 CCalHelperEntry* entry = iEntries[iModifyIndex];
00518
00519 if (entry->Modified())
00520 {
00521 if (entry->DateHasChanged())
00522 {
00523 CCalEntry* updateAnniv = entry->Anniv();
00524 TTime startDate(entry->Date());
00525 TCalTime time;
00526 time.SetTimeLocalL(startDate);
00527 updateAnniv->SetStartAndEndTimeL(time,time);
00528 UpdateAnniversaryL(updateAnniv);
00529 }
00530
00531 else
00532 {
00533 entry->SaveValuesL();
00534 CCalEntry* updateAnniv = entry->Anniv();
00535 UpdateAnniversaryL(updateAnniv);
00536 }
00537 DoSearchL(iCurrentSearchType);
00538 }
00539 }
00540 }
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 void CCalendarAPIexampleEngine::SetModifyIndex(const TInt& aIndex)
00553 {
00554 if (aIndex < 0 || aIndex >= iEntries.Count())
00555 {
00556 Panic(KInvalidModifyIndex);
00557 }
00558
00559 iModifyIndex = aIndex;
00560 }
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574 void CCalendarAPIexampleEngine::CreateEntryForModificationL(TBool& aModify)
00575 {
00576 delete iEntry;
00577 iEntry = NULL;
00578
00579
00580 if (iModifyIndex < 0)
00581 {
00582 aModify = EFalse;
00583 CCalEntry* nulli = NULL;
00584
00585 iEntry = CCalHelperEntry::NewL(nulli);
00586 }
00587 else
00588 {
00589 aModify = ETrue;
00590 }
00591
00592 if (iModifyIndex >= iEntries.Count())
00593 {
00594 Panic(KInvalidModifyIndex);
00595 }
00596 }
00597
00598 TInt CCalendarAPIexampleEngine::EntryCount() const
00599 {
00600 return iEntries.Count();
00601 }
00602
00603 TBool CCalendarAPIexampleEngine::SetValuesToNewEntry( const TDesC& aName,
00604 const TDateTime& aDate,
00605 const TBool& aAlarm,
00606 const TDateTime& aAlarmTime,
00607 const TInt& aSynchronizationMethod)
00608
00609 {
00610 CCalHelperEntry *entry=NULL;
00611 if( iEntry )
00612 {
00613 entry = iEntry;
00614 }
00615
00616 else
00617 entry = iEntries[iModifyIndex];
00618
00619 return entry->SetValues(aName,aDate,aAlarm,aAlarmTime,aSynchronizationMethod);
00620
00621 }
00622
00623 void CCalendarAPIexampleEngine::GetValuesToSet(TDes& aName, TTime& aDate,
00624 TBool& aAlarm, TTime& aAlarmTime,
00625 TInt& aSync)
00626 {
00627 CCalHelperEntry *entry=NULL;
00628 if( iEntry )
00629 {
00630 entry = iEntry;
00631 }
00632 else
00633 entry = iEntries[iModifyIndex];
00634
00635
00636 aName = entry->Name();
00637 aDate = entry->Date();
00638 aAlarm = entry->Alarm();
00639 aAlarmTime = entry->AlarmTime();
00640 aSync = entry->SynchronizationMethod();
00641 }
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653 CCalHelperEntry& CCalendarAPIexampleEngine::Entry(const TInt& aIndex)
00654 {
00655 if (0 > aIndex || iEntries.Count() <= aIndex)
00656 {
00657 Panic(EOutOfEntriesArray);
00658 }
00659
00660 return *iEntries[aIndex];
00661 }
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673 TInt CCalendarAPIexampleEngine::ModifyIndex() const
00674 {
00675 return iModifyIndex;
00676 }
00677
00678 void CCalendarAPIexampleEngine::ExecuteDeletionL()
00679 {
00680 DeleteEntryL(ModifyIndex());
00681
00682
00683 if (EntryCount() == 0)
00684 {
00685 iAppUi.ActivateView(KSearchViewId);
00686 }
00687
00688 else
00689 {
00690 iAppUi.ActivateView(KEntriesViewId);
00691 }
00692 }
00693
00694
00695