⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendarapiexampledocument.cpp

📁 该源码实现个人日程管理以及备忘功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	delete iAnniv;
	}
	
// ----------------------------------------------------
// CEntry::Anniv()
// Returns a pointer to the CAgnAnniv member variable of
// the entry.
// NOTICE: caller becomes the owner of the pointer and
// must remember to delete it.
// ----------------------------------------------------
//	
CAgnAnniv* CEntry::Anniv() 
	{
	CAgnAnniv* anniv = iAnniv;
	iAnniv = NULL;
	return anniv;
	}

// ----------------------------------------------------
// CEntry::Name()
// Returns the name of the entry.
// ----------------------------------------------------
//		
TBuf<KMaxNameLength> CEntry::Name() const
	{
	return iName;
	}

// ----------------------------------------------------
// CEntry::Age()
// Returns the age of the entry.
// ----------------------------------------------------
//			
TInt CEntry::Age() const
	{
	return iAge;
	}
	
// ----------------------------------------------------
// CEntry::Date()
// Returns the date of the entry.
// ----------------------------------------------------
//			
TDateTime CEntry::Date() const
	{
	return iDate;
	}

// ----------------------------------------------------
// CEntry::Alarm()
// Returns the alarm status of the entry.
// ----------------------------------------------------
//		
TBool CEntry::Alarm() const
	{
	return iAlarm;
	}
	
// ----------------------------------------------------
// CEntry::AlarmTime()
// Returns the alarm time of the entry.
// ----------------------------------------------------
//			
TDateTime CEntry::AlarmTime() const
	{
	return iAlarmTime;
	}
	
// ----------------------------------------------------
// CEntry::SynchronizationMethod()
// Returns the syncronization method of the entry.
// ----------------------------------------------------
//			
TInt CEntry::SynchronizationMethod() const
	{
	return iSynchronizationMethod;
	}
	
// ----------------------------------------------------
// CEntry::Modified()
// Returns whether entry has been modified or not.
// ----------------------------------------------------
//			
TBool CEntry::Modified() const
	{
	return iModified;
	}

// ----------------------------------------------------
// CEntry::DateHasChanged()
// Returns whether the date of the entry has been 
// modified or not.
// ----------------------------------------------------
//				
TBool CEntry::DateHasChanged() const
	{
	return iDateModified;
	}	

// ----------------------------------------------------
// CEntry::ResetTimeL()
// Sets given dates time to midnight.
// ----------------------------------------------------
//
void CEntry::ResetTimeL(TDateTime& aDate) const
	{
	User::LeaveIfError(aDate.SetHour(0));
	User::LeaveIfError(aDate.SetMinute(0));
	User::LeaveIfError(aDate.SetSecond(0));
	User::LeaveIfError(aDate.SetMicroSecond(0));	
	}

// ----------------------------------------------------
// CEntry::GetDaysAndMinutes()
// Calculates how many days and minutes aTime is from
// aFromTime.
// ----------------------------------------------------
//	
void CEntry::GetDaysAndMinutesL(const TDateTime& aTime, 
								const TDateTime& aFromTime,
								TTimeIntervalDays& aDays, 
								TTimeIntervalMinutes& aMinutes) const
	{
	// Create modifiable TDateTime (aTime cannot be modified, because it's const). 
	TDateTime modifiableTime = aTime;
	// Reset the modifiableTime. This will set the dates time to midnight.
	ResetTimeL(modifiableTime);
	// Create new TTime object. This is a reset aTime in TTime format. (modifiableTime has no more use)
	TTime resetTime(modifiableTime);
	
	// Create modifiable TDateTime (aFromTime cannot be modified, because it's const).
	TDateTime modifiableFromTime = aFromTime;
	// Reset the modifiableTime. This will set the dates time to midnight.
	ResetTimeL(modifiableFromTime);
	// Create new TTime object. This is a reset aFromTime in TTime format. (modifiableFromTime has no more use)
	TTime resetFromTime(modifiableFromTime);

	// Create a TTime object from aTime that is not reset.
	TTime unresetTime(aTime);

	// calculate the difference of days between aTime and aFromTime when their 
	// time is reset and only dates are different.
	aDays = resetFromTime.DaysFrom(resetTime);

	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;
	}
	
// ----------------------------------------------------
// CEntry::SetValuesL()
// Sets given values to entry. Return true if values 
// are valid and false if not.
// ----------------------------------------------------
//
TBool CEntry::SetValuesL(	const TDesC& aName,
							const TInt& aAge,
							const TDateTime& aDate,
							const TBool& aAlarm,
							const TDateTime& aAlarmTime,
							const TInt& aSync)
	{	
	TTime newAlarmTime(aAlarmTime);
	TTime currentAlarmTime(iAlarmTime);

	if (aAlarm)
		{
		if (newAlarmTime != currentAlarmTime)
			{
			TTimeIntervalDays days;
			TTimeIntervalMinutes minutes;
			GetDaysAndMinutesL(aAlarmTime, aDate, days, minutes);
			
			// Alarm cannot occur after the entry date.
			if (0 > days.Int() || 0 > minutes.Int())
				{
				return EFalse;
				}
			
			iAlarmTime = aAlarmTime;
			iAlarmDays = days;
			iAlarmMinutes = minutes;	
			iModified = ETrue;
			}
		}
		
	SetName(aName);
	SetDate(aDate);
	SetAge(aAge);
	SetSynchronizationMethod(aSync);
	SetAlarm(aAlarm);
	return ETrue;
	}

// ----------------------------------------------------
// CEntry::SetName()
// Sets given name to entry. If name has changed,
// iModified is set to true;
// ----------------------------------------------------
//	
void CEntry::SetName(const TDesC& aName)
	{
	if (aName != iName)
		{
		iName = aName;
		iModified = ETrue;
		}
	}

// ----------------------------------------------------
// CEntry::SetDate()
// Sets given date to entry. If date has changed,
// iModified is set to true;
// ----------------------------------------------------
//			
void CEntry::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;
		iModified = ETrue;
		iDateModified = ETrue;
		}
	}
	
// ----------------------------------------------------
// CEntry::SetAge()
// Sets given age to entry. If age has changed,
// iModified is set to true;
// ----------------------------------------------------
//	
void CEntry::SetAge(const TInt& aAge)
	{
	if (iAge != aAge)
		{
		iAge = aAge;
		iModified = ETrue;
		}
	}
	
// ----------------------------------------------------
// CEntry::SetAlarm()
// Sets the alarm state of the entry. If name alarm state 
// changed, iModified is set to true.
// ----------------------------------------------------
//	
void CEntry::SetAlarm(const TBool& aAlarm)
	{
	if (aAlarm != iAlarm)
		{
		iAlarm = aAlarm;
		iModified = ETrue;
		}
	}
	
// ----------------------------------------------------
// CEntry::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 CEntry::SetSynchronizationMethod(const TInt& aSynchronizationMethod)
	{
	if (aSynchronizationMethod != iSynchronizationMethod)
		{
		iSynchronizationMethod = aSynchronizationMethod;
		iModified = ETrue;		
		}
	}
	
// ----------------------------------------------------
// CEntry::CreateAnnivL()
// Creates a new CAgnAnniv object and initializes it with 
// the date of the entry.
// ----------------------------------------------------
//	
CAgnAnniv* CEntry::CreateAnnivL()
	{
	CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
	CleanupStack::PushL(paraFormatLayer);
	CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
	CleanupStack::PushL(charFormatLayer);
	CAgnAnniv* anniv = CAgnAnniv::NewL(paraFormatLayer,charFormatLayer);
	CleanupStack::PushL(anniv);

	//repetition ou pas ?
	//Repeat anniversary yearly.
	//CAgnRptDef* repeat = CAgnRptDef::NewL();
	//CleanupStack::PushL(repeat);
	//TAgnYearlyByDateRpt yearlyByDate;
	//repeat->SetYearlyByDate(yearlyByDate);
	//repeat->SetRepeatForever(ETrue);
	//repeat->SetInterval(1);
	//TTime startDate(iDate);
	//repeat->SetStartDate(startDate);
	//anniv->SetRptDefL(repeat);
	
	anniv->SetStartAndEndDate(iDate);
	
	//CleanupStack::PopAndDestroy(repeat);
	CleanupStack::Pop(anniv);
	CleanupStack::PopAndDestroy(charFormatLayer);
	CleanupStack::PopAndDestroy(paraFormatLayer);	
	
	return anniv;
	}

// ----------------------------------------------------
// CEntry::SaveValuesL()
// Sets the values of the entry to its member CAgnAnniv object.
// If member CAgnAnniv object doesn't exist, it is created. 
// ----------------------------------------------------
//	
void CEntry::SaveValuesL()
	{
	if (iModified)
		{
		if (!iAnniv)
			{
			iAnniv = CreateAnnivL();
			}
		
		SaveValuesToAnnivL(iAnniv);		
		
		iModified = EFalse;
		iDateModified = EFalse;
		}
	}
	
// ----------------------------------------------------
// CEntry::SaveValuesToAnnivL()
// Sets the values of the entry to given CAgnAnniv object.
// ----------------------------------------------------
//	
void CEntry::SaveValuesToAnnivL(CAgnAnniv* aAnniv)
	{
	aAnniv->RichTextL()->Reset();
	aAnniv->RichTextL()->InsertL(0, iName);		
	//aAnniv->SetBaseYear(TTimeIntervalYears(iDate.Year()-iAge)); YC Recommanded
	aAnniv->SetBaseYear(TTimeIntervalYears(iDate.Year()));

	aAnniv->SetHasAlarm(iAlarm);
	if (iAlarm)
		{
		aAnniv->SetAlarm(iAlarmDays, iAlarmMinutes);
		}
		
	TAgnReplicationData sync;
	switch (iSynchronizationMethod)
		{
		case KSyncPublic:
			sync.SetStatus(TAgnReplicationData::EOpen);
			break;
		case KSyncPrivate:
			sync.SetStatus(TAgnReplicationData::EPrivate);
			break;
		case KSyncNo:
			sync.SetStatus(TAgnReplicationData::ERestricted);
			break;
		default:
			Panic(KInvalidSyncValue);
			break;
		}
	aAnniv->SetReplicationData(sync);
	
	}

// ----------------------------------------------------
// CEntry::NewAnnivLC()
// Creates a new CAgnAnniv object and initializes it 
// with the data of the entry.
// ----------------------------------------------------
//	
CAgnAnniv* CEntry::NewAnnivLC()
	{
	CAgnAnniv* anniv = CreateAnnivL();
	CleanupStack::PushL(anniv);
	SaveValuesToAnnivL(anniv);	
	return anniv;
	}

// End of File  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -