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

📄 calendarhelperentry.cpp

📁 塞班3D游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ----------------------------------------------------
//      CCalHelperEntry - a wrapper class for CCalEntry
// ----------------------------------------------------

// ================= MEMBER FUNCTIONS =======================

#include "CalendarHelperEntry.h"

#include <e32math.h>
#include <calalarm.h>
#include <CalInstance.h>
#include "CalendarAPIexample.pan"

#include <calentry.h>

// CONSTANTS
const TInt KMaxSync = 2;
const TInt KDefaultAlarmHour = 8;
const TInt KDefaultAnniversaryHour = 8;
const TInt KMinutesInHour = 60;
const TInt KUndefinedModifyIndex = -1;
const TInt KGuidLength = 30;

// Two-phased constructor.
CCalHelperEntry* CCalHelperEntry::NewL(CCalEntry* aAnniv)
    {
    CCalHelperEntry* self = CCalHelperEntry::NewLC(aAnniv);
    CleanupStack::Pop(self);
    return self;
    }

// Two-phased constructor.
CCalHelperEntry* CCalHelperEntry::NewLC(CCalEntry* aAnniv)
    {
    CCalHelperEntry* self = new (ELeave) CCalHelperEntry;
    CleanupStack::PushL(self);
    self->ConstructL(aAnniv);
    return self;
    }

// Two-phased constructor.
CCalHelperEntry* CCalHelperEntry::NewL(CCalInstance* aAnniv)
    {
    CCalHelperEntry* self = CCalHelperEntry::NewLC(aAnniv);
    CleanupStack::Pop(self);
    return self;
    }

// Two-phased constructor.
CCalHelperEntry* CCalHelperEntry::NewLC(CCalInstance* aAnniv)
    {
    CCalHelperEntry* self = new (ELeave) CCalHelperEntry;
    CleanupStack::PushL(self);
    self->ConstructL(aAnniv);
    return self;
    }


// ----------------------------------------------------
// Standard Symbian OS 2nd phase constructor
// Will initialize entry with values of parameter aAnniv,
// if parameter aAnniv is provided (not NULL).
// ----------------------------------------------------
//
void CCalHelperEntry::ConstructL(CCalInstance* aAnniv)
    {
    iInstance = aAnniv;
    ConstructL(&aAnniv->Entry());
    }

void CCalHelperEntry::ConstructL(CCalEntry* aAnniv)
    {
    // initialize today's date for anniversary date and alarm.
    TTime now;
    now.HomeTime();
    iDate = now.DateTime();
    
    if ( aAnniv )
        {            
        TTime starttime = aAnniv->StartTimeL().TimeLocalL();
        TDateTime time2 = starttime.DateTime();

        TTime endtime = aAnniv->StartTimeL().TimeLocalL();
        TDateTime time3 = endtime.DateTime();
        }
    
    iDate.SetHour(KDefaultAnniversaryHour);
    iDate.SetMinute(0);
    iDate.SetSecond(0);
    iDate.SetMicroSecond(0);
    
    iAlarmTime = now.DateTime();
    User::LeaveIfError(iAlarmTime.SetHour(KDefaultAlarmHour));
    User::LeaveIfError(iAlarmTime.SetMinute(0));
    User::LeaveIfError(iAlarmTime.SetSecond(0));
    User::LeaveIfError(iAlarmTime.SetMicroSecond(0));
    iAlarmDays = TTimeIntervalDays(0);
    
    iAlarmMinutes = TTimeIntervalMinutes(KDefaultAlarmHour*KMinutesInHour);

    if (!aAnniv)
        {
        return;
        }

    iAnniv = aAnniv;

    // read the name for the anniversary.
    TBuf<KMaxNameLength> name;
    name = aAnniv->SummaryL();
    iName = name;

    // read the date for the anniversary.
    iDate = aAnniv->StartTimeL().TimeLocalL().DateTime();

    iAlarmPtr = iAnniv->AlarmL();
    
    iAlarm = iAlarmPtr ? ETrue : EFalse;
    if (iAlarm)
    {

        iAlarmMinutes = -iAlarmPtr->TimeOffset().Int();
        iAlarmTime = iDate;
        TTime alarm = iAlarmTime;
        alarm += iAlarmMinutes;
        iAlarmTime = alarm.DateTime();
    }

    // read how the anniversary is to be synchronized.
    CCalEntry::TReplicationStatus annivReplStatus =
        aAnniv->ReplicationStatusL();
    if (annivReplStatus == CCalEntry::EOpen)
        {
        SetSynchronizationMethod(KSyncPublic);
        }
    else if (annivReplStatus == CCalEntry::EPrivate)
        {
        SetSynchronizationMethod(KSyncPrivate);
        }
    else
        {
        SetSynchronizationMethod(KSyncNo);
        }

    iModified = EFalse;
    }

// constructor
CCalHelperEntry::CCalHelperEntry()
    {
    }
    
// destructor
CCalHelperEntry::~CCalHelperEntry()
    {
    //If there's a CCalInstance then delete it. 
    //It deletes the corresponding CCalEntry object
    if( iInstance )   
        {
        delete iInstance;
        iInstance = NULL;
        }
    else //there only the CCalEntry
        {
     	if (iAnniv)
    		delete iAnniv;
    	iAnniv=NULL;
        }
	if (iAlarmPtr)
		delete iAlarmPtr;
	iAlarmPtr=NULL;
    }

// ----------------------------------------------------
// CCalHelperEntry::Anniv()
// Returns a pointer to the CCalEntry member variable of
// the entry.
// ----------------------------------------------------
//
CCalEntry* CCalHelperEntry::Anniv()
    {
    CCalEntry* anniv = iAnniv;
    return anniv;
    }

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

// ----------------------------------------------------
// CCalHelperEntry::Date()
// Returns the date of the entry.
// ----------------------------------------------------
//
TDateTime CCalHelperEntry::Date() const
    {
    return iDate;
    }

// ----------------------------------------------------
// CCalHelperEntry::Alarm()
// Returns the alarm status of the entry.
// ----------------------------------------------------
//
TBool CCalHelperEntry::Alarm() const
    {
    return iAlarm;
    }

// ----------------------------------------------------
// CCalHelperEntry::AlarmTime()
// Returns the alarm time of the entry.
// ----------------------------------------------------
//
TDateTime CCalHelperEntry::AlarmTime() const
    {
    return iAlarmTime;
    }

// ----------------------------------------------------
// CCalHelperEntry::SynchronizationMethod()
// Returns the syncronization method of the entry.
// ----------------------------------------------------
//
TInt CCalHelperEntry::SynchronizationMethod() const
    {
    return iSynchronizationMethod;
    }

// ----------------------------------------------------
// CCalHelperEntry::Modified()
// Returns whether entry has been modified or not.
// ----------------------------------------------------
//
TBool CCalHelperEntry::Modified() const
    {
    return iModified;
    }

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

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

// ----------------------------------------------------
// CCalHelperEntry::GetDaysAndMinutes()
// Calculates how many days and minutes aTime is from
// aFromTime.
// ----------------------------------------------------
//
void CCalHelperEntry::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);

⌨️ 快捷键说明

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