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

📄 calendarapiexampleengine.cpp

📁 塞班3D游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
* ============================================================================
*  Name     : CCalendarAPIexampleEngine from CalendarAPIexampleEngine.h
*  Part of  : Thread
*  Created  : 12/06/2006 by Forum Nokia
*  Version  : 2.0
*  Copyright: Nokia Corporation
* ============================================================================
*/

// INCLUDE FILES
#include <calsession.h>	//CCalSession
#include <calentryview.h>
#include <CalInstance.h>
#include <calinstanceview.h>
#include <txtfmlyr.h>	//CParaFormatLayer
#include <calalarm.h>	//CCalAlarm 
#include <CalendarAPIexample.rsg>
#include "CalendarAPIexampleEngine.h"
#include "CalendarAPIexample.hrh"

#include "CalendarAPIexampleEntryView.h"
#include "CalendarAPIexampleEntryContainer.h"
#include "CalendarAPIexampleEntriesView.h"
#include "CalendarAPIexampleSearchView.h" 

#include "CalendarAPIexample.pan"

#include "CalendarAPIexampleEntryView.h"

// CONSTANTS
const TInt KProgressFinalValue = 100;
_LIT(KDefaultTodoListName, "TODO");

#define KDefaultEventDisplayTime TTimeIntervalMinutes(660)
#define KDefaultAnnivDisplayTime TTimeIntervalMinutes(900)
#define KDefaultDayNoteDisplayTime TTimeIntervalMinutes(1000)

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

// constructor
CCalendarAPIexampleEngine::CCalendarAPIexampleEngine(
                                            MCalenderEngineObserverUI& aAppUi)
    : iAppUi(aAppUi)
	{
	
	
	}
	
// destructor
CCalendarAPIexampleEngine::~CCalendarAPIexampleEngine()
	{
	
    if( iWait )
        {
        if( iWait->IsStarted() )
		    {
		    iWait->AsyncStop();
		    //it's not propably safe to delete right after this
		    }
        delete iWait;
        iWait = NULL;   
        }
	if (iEntryView)
		{
		delete iEntryView;
		iEntryView = 0;
		}
		
	if (iInstanceView)
		{
		delete iInstanceView;
		iInstanceView = 0;
		}

    iEntries.ResetAndDestroy();
    
    delete iEntry;
    iEntry = NULL;

	delete iProgressDialog;		
	iProgressDialog = NULL;
		 
	if (iCalSession)
		{
		delete iCalSession;
		iCalSession = 0;
		}
	}
	
	
// Two-phased constructor.
CCalendarAPIexampleEngine* CCalendarAPIexampleEngine::NewL(
                                            MCalenderEngineObserverUI& aAppUi)
	{
	CCalendarAPIexampleEngine* self = 
	    new (ELeave) CCalendarAPIexampleEngine(aAppUi);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
	}
	
// Symbian OS default constructor can leave.	
void CCalendarAPIexampleEngine::ConstructL()
	{
    iModifyIndex = KUndefinedModifyIndex;
	
	// allocate and construct server
	iCalSession = CCalSession::NewL();		
	
	const TDesC& file = iCalSession->DefaultFileNameL();
	// connect to the cal server
	TRAPD(err,iCalSession->OpenL(file) );	
	if( err == KErrNotFound)
	    {
	    iCalSession->CreateCalFileL(file);
	    iCalSession->OpenL(file);
	    }
	else
	    {
	    User::LeaveIfError(err);   
	    }

	iWait = new (ELeave) CActiveSchedulerWait;
	}

/*******************OBSERVER functions***********************/
	
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::Progress()
// Monitors the progress of agenda model operations.
// Creates a progress dialog when first called and 
// updates its status on later calls. Note that if the 
// agenda models operation completes quickly, for 
// instance when opening a small file, then Progress() 
// will probably not be called at all.
// ----------------------------------------------------
//					
void CCalendarAPIexampleEngine::Progress(TInt aPercentageCompleted)
	{
	if (!iProgressDialog)
		{
		
		TRAPD
			(	
			error,
	    	iProgressDialog = new (ELeave) CAknProgressDialog(
	    	        REINTERPRET_CAST(CEikDialog**, &iProgressDialog), ETrue);
	    	iProgressDialog->PrepareLC(R_CALENDARAPIEXAMPLE_PROGRESS_NOTE);
			iProgressInfo = iProgressDialog->GetProgressInfoL();
	    	iProgressDialog->RunLD();
	    	)
	    if (KErrNone == error)
	    	{
		    iProgressInfo->SetFinalValue(KProgressFinalValue);
		    iProgressInfo->SetAndDraw(aPercentageCompleted);
	    	}
	    else
	    	{
	    	delete iProgressDialog;
	    	iProgressDialog = NULL;
	    	}
		}
	else
		{
		iProgressInfo->SetAndDraw(aPercentageCompleted);
		}
	}

/** Progress callback.

This calls the observing class when the current operation is finished.

@param aError The error if the operation failed, or KErrNone if successful. */
void CCalendarAPIexampleEngine::Completed(TInt )
	{
	if (iCreatingEntryView)
		{		
		if( iWait->IsStarted() )
		    {
		    iWait->AsyncStop();
		    }
		else
		    {
            Panic(EWaitNotStarted);
		    }
		iCreatingEntryView = EFalse;		
		}
		
	if (iProgressDialog)
		{
		iProgressInfo->SetAndDraw(100);
		TRAPD
			(
			error,
			iProgressDialog->ProcessFinishedL();
			)
		iProgressInfo = NULL;
		iProgressDialog = NULL;
		}
	}

/** Asks the observing class whether progress callbacks are required.

@return If the observing class returns EFalse, then the Progress() function 
        will not be called. */
TBool CCalendarAPIexampleEngine::NotifyProgress()
	{		
	return ETrue;
	}
/****************END OF OBSERVER functions***********************/


/************************HELPER functions***********************/

// ----------------------------------------------------
// CCalendarAPIexampleEngine::AddAnniversaryL()
// adds an anniversary to the agenda file
// ----------------------------------------------------
//	
//A Helper, only called from SaveL
//
void CCalendarAPIexampleEngine::AddAnniversaryL(CCalEntry* aAnniv) 
	{
	if (!iEntryView)
		{
		iEntryView = CCalEntryView::NewL(*iCalSession, *this); 
		iCreatingEntryView = ETrue;
		
		//After scheduler starting, the call back will be 
		//called when the task is completed.
		if( !iWait->IsStarted() )
		    {
            iWait->Start();
		    }
		else
		    {
            Panic(EWaitAlreadyStarted);
		    }
		}

	RPointerArray<CCalEntry> calEntryList;
	calEntryList.Append(aAnniv);
	TInt num;

	iEntryView->StoreL(calEntryList, num);
	
	calEntryList.Reset();
	
	}

// ----------------------------------------------------
// CCalendarAPIexampleEngine::UpdateAnniversaryL()
// updates an anniversary
// ----------------------------------------------------
//	A helper, only called from SaveL
//
void CCalendarAPIexampleEngine::UpdateAnniversaryL(	CCalEntry* aAnniv) 
	{
	if (!iEntryView)
		{
		iEntryView = CCalEntryView::NewL(*iCalSession, *this); 
		iCreatingEntryView = ETrue;
		
		//After scheduler starting, the call back will be called when the task is completed.
		//CActiveScheduler::Start();
		if( !iWait->IsStarted() )
		    {
            iWait->Start();
		    }
		else
		    {
            Panic(EWaitAlreadyStarted);
		    }
		}
	RPointerArray<CCalEntry> calEntryList;
	calEntryList.Append(aAnniv);
	TInt num;

	iEntryView->UpdateL(calEntryList, num);

	calEntryList.Reset();
	}

/************MCalendarEngineCommandsInterface functions***********************/

// ----------------------------------------------------
// CCalendarAPIexampleEngine::DoSearchL()
// Searches all anniversaries in given time interval.
// ----------------------------------------------------
// Called from CCalendarAPIexampleSearchView::DoSearchL()
// and also from DoSaveL if anniversaries are modified
//
void CCalendarAPIexampleEngine::DoSearchL(const TSearchType& aType)
    {
    iEntries.ResetAndDestroy(); 

    iCurrentSearchType = aType;
    TTime now;
    now.HomeTime();
    TDateTime from = now.DateTime();
    User::LeaveIfError(from.SetHour(0));
    User::LeaveIfError(from.SetMinute(0));
    User::LeaveIfError(from.SetSecond(0));
    User::LeaveIfError(from.SetMicroSecond(0));

    //set the time interval
    switch (aType)
        {
        case EWeek:
            now += TTimeIntervalDays(7);
            break;
        case EMonth:
            now += TTimeIntervalMonths(1);
            break;
        case ESixMonths:
            now += TTimeIntervalMonths(6);
            break;
        case EYear:
            now += TTimeIntervalYears(1);
            break;
        }

    TDateTime to = now.DateTime();

	if (!iInstanceView)
		{
		iInstanceView = CCalInstanceView::NewL(*iCalSession, *this); 
		iCreatingEntryView = ETrue;
		
		//After scheduler starting, the call back will be 
		//called when the task is completed.
		if( !iWait->IsStarted() )
		    {
            iWait->Start();
		    }
		else

⌨️ 快捷键说明

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