📄 calendarhelperentry.cpp
字号:
TTimeIntervalMinutes minutes;
// calucate the difference of minutes between aTime and aFromTime. This is
// done by just comparing the time of aTime to midnight.
User::LeaveIfError(unresetTime.MinutesFrom(resetTime, minutes));
aMinutes = minutes;
}
// ----------------------------------------------------
// CCalHelperEntry::SetValuesL()
// Sets given values to entry. Return true if values
// are valid and false if not.
// ----------------------------------------------------
// This is called by CCalendarAPIexampleEntryItemList
// SaveL once the modifications are done using
// CCalendarAPIexampleEntryView
TBool CCalHelperEntry::SetValues( const TDesC& aName,
const TDateTime& aDate,
const TBool& aAlarm,
const TDateTime& aAlarmTime,
const TInt& aSync)
{
SetDate(aDate); //sets the hours to 8
SetName(aName);
SetSynchronizationMethod(aSync);
SetAlarm(aAlarm);
if (aAlarm)
{
// Event time from ENTRY
TTime startTime = iDate;
// Alarm cannot occur after the entry date.
// We have set the anniversary time to 8:00 but actually ignore it
// Alarm time from FORM
TDateTime alarmDay = iDate;
//This doesn't work in the last day of month!
//alarmDay.SetDay( alarmDay.Day() + 1 );
alarmDay.SetHour(0);
alarmDay.SetMinute(0);
alarmDay.SetMicroSecond(0);
//TDateTime theNextDay = alarmDay
TTimeIntervalDays oneDay(1);
TTime time = alarmDay;
time += oneDay;
//oneDay
alarmDay = time.DateTime();
TTime alarmTime = aAlarmTime;
TTimeIntervalMinutes minutes;
alarmTime.MinutesFrom( alarmDay, minutes );
if (minutes.Int() > 0)
{
return EFalse;
}
//Now we should check that the alarm time is not in the past:
TTime now;
now.HomeTime();
//iDate = now.DateTime();
now.MinutesFrom(alarmTime, minutes);
if (minutes.Int() > 0)
{
return EFalse;
}
TTime date = iDate;
alarmTime = aAlarmTime;
alarmTime.MinutesFrom(date, minutes);
iAlarmTime = aAlarmTime;
iAlarmMinutes = minutes;
iModified = ETrue;
}
return ETrue;
}
// ----------------------------------------------------
// CCalHelperEntry::SetName()
// Sets given name to entry. If name has changed,
// iModified is set to true;
// ----------------------------------------------------
//
void CCalHelperEntry::SetName(const TDesC& aName)
{
if (aName != iName)
{
iName = aName;
iModified = ETrue;
}
}
// ----------------------------------------------------
// CCalHelperEntry::SetDate()
// Sets given date to entry. If date has changed,
// iModified is set to true;
// ----------------------------------------------------
//
void CCalHelperEntry::SetDate(const TDateTime& aDate)
{
// TDateTime cannot be used for comparison, local TTime variables needed.
TTime currentDate(iDate);
TTime newDate(aDate);
if (newDate != currentDate)
{
iDate = aDate;
iDate.SetHour(KDefaultAnniversaryHour);
iModified = ETrue;
iDateModified = ETrue;
}
}
// ----------------------------------------------------
// CCalHelperEntry::SetAlarm()
// Sets the alarm state of the entry. If name alarm state
// changed, iModified is set to true.
// ----------------------------------------------------
//
void CCalHelperEntry::SetAlarm(const TBool& aAlarm)
{
if (aAlarm != iAlarm)
{
iAlarm = aAlarm;
iModified = ETrue;
}
}
// ----------------------------------------------------
// CCalHelperEntry::SetSynchronizationMethod()
// Sets the synchronization state of the entry. If state
// has changed, iModified is set to true. Synchronization
// method defines how the anniversary is synchronized
// e.g. with PC.
// ----------------------------------------------------
//
void CCalHelperEntry::SetSynchronizationMethod(const TInt& aSynchronizationMethod)
{
if (aSynchronizationMethod != iSynchronizationMethod)
{
iSynchronizationMethod = aSynchronizationMethod;
iModified = ETrue;
}
}
// ----------------------------------------------------
// CCalHelperEntry::CreateAnnivL()
// Creates a new CCalEntry object and initializes it with
// the date of the entry.
// ----------------------------------------------------
//
CCalEntry* CCalHelperEntry::CreateAnnivL()
{
// Create unique ID.
TTime now;
now.HomeTime();
TInt64 seed = now.Int64();
TInt randNum = Math::Rand( seed );
HBufC8* guid = HBufC8::NewLC(KGuidLength);
guid->Des().Num( randNum );
//CCalEntry::EMethodNone means that there's no group scheduling
CCalEntry* anniv = CCalEntry::NewL( CCalEntry::EAnniv, guid,
CCalEntry::EMethodNone, 0 );
CleanupStack::Pop( guid );
CleanupStack::PushL(anniv);
TTime startDate(iDate);
TCalTime time;
time.SetTimeLocalL(startDate);
anniv->SetStartAndEndTimeL(time, time);
if (iAlarm) //if there is a alarm
{
delete iAlarmPtr;
iAlarmPtr=NULL;
iAlarmPtr = CCalAlarm::NewL();
iAlarmPtr->SetTimeOffset(-iAlarmMinutes.Int());
anniv->SetAlarmL(iAlarmPtr);
}
CleanupStack::Pop(anniv);
return anniv;
}
// ----------------------------------------------------
// CCalHelperEntry::SaveValuesL()
// Sets the values of the entry to its member CCalEntry object.
// If member CCalEntry object doesn't exist, it is created.
// ----------------------------------------------------
// This is called by DoSaveL of the engine.
void CCalHelperEntry::SaveValuesL()
{
TBool created = EFalse;
if (iModified)
{
if (!iAnniv) //This is the case when creating a new entry
{ //The values are gotten from CCalendarAPIexampleEntryContainer
// and CCalendarAPIexampleEntryView.
// The engine has called this
// so there's a iEntry created in the engine.
// (created by a call to CreateEntryForModificationL)
// now we need store the given data.
//the created CCalHelperEntry goes to engines iEntry.iAnniv
iAnniv = CreateAnnivL();
created = ETrue;
}
SaveValuesToAnnivL(iAnniv);
if( !created )
{
delete iAlarmPtr;
iAlarmPtr = NULL;
if( !iAlarm )
{
//remove the alarm
iAnniv->SetAlarmL(NULL);
}
else
{
//Create a new alarm
iAlarmPtr = CCalAlarm::NewL();
iAlarmPtr->SetTimeOffset(-iAlarmMinutes.Int());
iAnniv->SetAlarmL(iAlarmPtr);
}
}
iModified = EFalse;
iDateModified = EFalse;
}
}
// ----------------------------------------------------
// CCalHelperEntry::SaveValuesToAnnivL()
// Sets the values of the entry to given CCalEntry object.
// ----------------------------------------------------
//
void CCalHelperEntry::SaveValuesToAnnivL(CCalEntry* aAnniv)
{
aAnniv->SetSummaryL(iName);
CCalEntry::TReplicationStatus sync;
switch (iSynchronizationMethod)
{
case KSyncPublic:
sync=CCalEntry::EOpen;
break;
case KSyncPrivate:
sync=CCalEntry::EPrivate;
break;
case KSyncNo:
sync=CCalEntry::ERestricted;
break;
default:
Panic(KInvalidSyncValue);
break;
}
aAnniv->SetReplicationStatusL(sync);
}
// ----------------------------------------------------
// CCalHelperEntry::NewAnnivLC()
// Creates a new CCalEntry object and initializes it
// with the data of the entry.
// ----------------------------------------------------
//
CCalEntry* CCalHelperEntry::NewAnnivLC()
{
CCalEntry* anniv = CreateAnnivL();
CleanupStack::PushL(anniv);
SaveValuesToAnnivL(anniv);
return anniv;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -