📄 alarmorganiserenginebase.cpp
字号:
/**
*
* @brief Definition of CAlarmOrganiserEngineBase
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDES
// Class include
#include "AlarmOrganiserEngineBase.h"
// System includes
#include <eikenv.h> // CEikonEnv
#include <AlarmOrganiser.rsg> // R_AGENDA_FILE
// User includes
#include "AlarmOrganiserMixins.h" // MAlarmOrganiserEngineMixin
// Constants
const TInt KMinutesPerHour = 60;
#define KDefaultTimeForEvents TTimeIntervalMinutes(9 * KMinutesPerHour)
#define KDefaultTimeForAnnivs TTimeIntervalMinutes(13 * KMinutesPerHour)
#define KDefaultTimeForDayNote TTimeIntervalMinutes(13 * KMinutesPerHour)
const TInt KArrayGranularity = 5;
const TInt KNumberOfAlarms = 10;
const TInt KInvalidCAgnEntryType = 1;
_LIT(KAlarmOrganiserPanic, "CAlarmOrganiserAlarm");
// = ================ MEMBER FUNCTIONS ====================== =
/**
* C++ constructor
* @param aAlarmed to include alarmed entries or not.
* @param aAlarmOrganiserEngineMixin the engines observer
*/
CAlarmOrganiserEngineBase::CAlarmOrganiserEngineBase(TBool aAlarmed, MAlarmOrganiserEngineMixin& aAlarmOrganiserEngineMixin)
:iAlarmed(aAlarmed), iObserver(aAlarmOrganiserEngineMixin)
{
}
/**
* Destructor.
*/
CAlarmOrganiserEngineBase::~CAlarmOrganiserEngineBase()
{
delete iModel;
if (iAgendaServer)
{
// Shut down the agenda server, carefully
if (iAgendaServer->FileLoaded())
{
iAgendaServer->CloseAgenda();
}
iAgendaServer->Close();
delete iAgendaServer;
}
iArray.ResetAndDestroy();
if (iDescriptorArray)
{
iDescriptorArray->Reset();
delete iDescriptorArray;
}
}
/**
* Symbian OS 2nd phase constructor.
* connects to the agenda server, creates and opens the agenda model
*/
void CAlarmOrganiserEngineBase::ConstructL()
{
iAgendaServer = RAgendaServ::NewL();
iAgendaServer->Connect();
// Create a CAgnModel. A CAgnModel must have an associated user interface view,
// which is passed as an argument to CAgnModel::NewL()
iModel = CAgnModel::NewL(this);
iModel->SetServer(iAgendaServer);
iModel->SetMode(CAgnEntryModel::EClient);
// Open the instance model asynchronously.
HBufC* agendaFile = CEikonEnv::Static()->AllocReadResourceL(R_AGENDA_FILE);
CleanupStack::PushL(agendaFile);
iModel->OpenL(*agendaFile, KDefaultTimeForEvents, KDefaultTimeForAnnivs, KDefaultTimeForDayNote, &iObserver, EFalse);
CleanupStack::PopAndDestroy(agendaFile);
iAgendaServer->WaitUntilLoaded();
iDescriptorArray = new (ELeave) CDesCArrayFlat(KArrayGranularity);
}
/**
* Populates an array with the next n outstanding alarms
* @para aNumberOfAlarms the number of alarms to include in list
*/
void CAlarmOrganiserEngineBase::GetAlarmsL(TInt aNumberOfAlarms)
{
// Get the current date and time.
TTime day;
day.HomeTime(); // now
// Create a day list of entries for today.
CAgnDayList<TAgnInstanceId>* dayList = CAgnDayList<TAgnInstanceId>::NewL(day.DateTime());
CleanupStack::PushL(dayList);
// Filter entries with alarms out, if required.
TAgnFilter filter;
filter.SetIncludeAlarmedOnly(iAlarmed);
TInt numberOfAlarms = 0;
// Repeat while the day is valid.
while (day != Time::NullTTime())
{
// Fill the day list.
iModel->PopulateDayInstanceListL(dayList, filter, day.DateTime());
// Get the number of instances in the list
TInt count = dayList->Count();
for (TInt ii = 0; ii < count; ii++)
{
// Add each instance from the day list.
if (AddL((*dayList)[ii]))
{
numberOfAlarms++;
// If we've reached the target capacity then return now.
if (numberOfAlarms == aNumberOfAlarms)
{
CleanupStack::PopAndDestroy(dayList);
return;
}
}
}
// Get the next day that has an entry (appointment or anniversary).
// [To start the search at the beginning of the range for agenda entries,
// use AgnDateTime::MinDateAsTTime() in parameter three.]
day = iModel->NextDayWithInstance(day, filter, day);
dayList->Reset(); // empty the list
dayList->SetDay(day); // set the daylist to the new day.
}
CleanupStack::PopAndDestroy(dayList);
}
/**
* Inherited from MAgnModelStateCallBack, called when the models state changes
* @param aState the models current state
*/
void CAlarmOrganiserEngineBase::StateCallBack(CAgnEntryModel::TState aState)
{
if (aState == CAgnEntryModel::EOk)
{
// GetAlarmsL can leave, trap the leave
// and pass the error to be handled by the engine observer.
TRAPD(error, GetAlarmsL(KNumberOfAlarms););
iObserver.EngineCallBack(error);
}
}
/**
* This function removes an alarm from an entry
* @param aIndexOfAlarm index of entry to remove alarm from
*/
void CAlarmOrganiserEngineBase::RemoveAlarmL(TInt aIndexOfAlarm)
{
// get entry from array
CAgnEntry* entry = iArray[aIndexOfAlarm];
// Clear the alarm
entry->ClearAlarm();
// Update the entry in agenda model
iModel->UpdateInstanceL(entry, ECurrentInstance);
// Update the engine entries and cause the view to redraw.
iArray.ResetAndDestroy();
iDescriptorArray->Reset();
StateCallBack(CAgnEntryModel::EOk);
}
/**
* This function adds an alarm to an entry
* @param aIndexOfAlarm index of entry add alarm to
*/
void CAlarmOrganiserEngineBase::AddAlarmL(TInt aIndexOfAlarm)
{
// get entry from array
CAgnEntry* entry = iArray[aIndexOfAlarm];
// Set the alarm time, based upon the type of entry
switch (entry->Type())
{
case CAgnEntry::EAnniv:
case CAgnEntry::EAppt:
case CAgnEntry::EEvent:
{
TTime time = entry->InstanceStartDate();
TInt hours = time.DateTime().Hour();
TInt minutes = time.DateTime().Minute();
entry->SetAlarm(0, minutes + KMinutesPerHour * hours);
break;
}
case CAgnEntry::ETodo:
{
CAgnTodo* todo = entry->CastToTodo();
todo->SetAlarm(0, 0);
todo->SetAlarmFromStartDate();
break;
}
default:
{
#ifdef _DEBUG
// We should never reach this point, so panic
User::Panic(KAlarmOrganiserPanic, KInvalidCAgnEntryType);
#endif // _DEBUG
}
}
// Update the entry in the agenda model
iModel->UpdateInstanceL(entry, ECurrentInstance);
// Update the engine entries and cause the view to redraw.
iArray.ResetAndDestroy();
iDescriptorArray->Reset();
StateCallBack(CAgnEntryModel::EOk);
}
/**
* this function returns the descriptor array describing how the entries should be displayed
* @return descriptor array
*/
CDesCArray* CAlarmOrganiserEngineBase::ListBoxArray() const
{
return iDescriptorArray;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -