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

📄 calendarapiexampleengine.cpp

📁 塞班3D游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		    {
            Panic(EWaitAlreadyStarted);
		    }
		}

	RPointerArray<CCalInstance> instanceArray;
	TTime nextDate(from);
	// decrease 'from' date by one day, so that 'from' date 
	//will be included in search.
	nextDate -= TTimeIntervalDays(1);
	TTime toDate(to);
	TCalTime fromCalTime;
	fromCalTime.SetTimeLocalL(from);
	TCalTime toCalTime;
	toCalTime.SetTimeLocalL(to);
	CalCommon::TCalTimeRange timeRange(fromCalTime, toCalTime);
	
	iInstanceView->FindInstanceL(instanceArray, CalCommon::EIncludeAnnivs, timeRange);

    //create new CCalHelperEntry for each CCalEntry.
    for (TInt i = 0; i < instanceArray.Count(); i++)
        {
        CCalHelperEntry* entry = CCalHelperEntry::NewLC(instanceArray[i]);
        User::LeaveIfError(iEntries.Append(entry));
        CleanupStack::Pop(entry);
        }
    //now all the instances are in iEntries List
    
    instanceArray.Reset();
    }

// ----------------------------------------------------
// CCalendarAPIexampleEngine::DeleteEntryL()
// deletes an anniversary from the agenda file
//
// Called from CCalendarAPIexampleEntriesView when
// the delete command has been selected
// And from CCalendarAPIexampleEntryView
// ----------------------------------------------------

void CCalendarAPIexampleEngine::DeleteEntryL(const TInt& aIndex)
    {
    //This is the case when user is adding an entry and desides
    //to cancel the addition
    if( aIndex == -1)
        {
        delete iEntry;
        iEntry = NULL;
        return;
        }
        
    if (aIndex < 0 || aIndex >= iEntries.Count())
        {
        Panic(KInvalidEntryIndex);
        }

    CCalHelperEntry* entry = iEntries[aIndex];
    
    CCalEntry* anniv = entry->Anniv();

	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);
		    }
		}

	iEntryView->DeleteL(*anniv);
	    
    iEntries.Remove(aIndex);

    delete entry; //now the CCalinstance is deleted if there's one
    }

// ----------------------------------------------------
// CCalendarAPIexampleSearchView::DoAddL()
// Resets models modify index, so that next call to 
// models EntryForModifycation will create a new entry.
// Activates the entry view.
//
// Called from CCalendarAPIexampleSearchView when
// the menu option for adding has been selected
// ----------------------------------------------------
// 		
void CCalendarAPIexampleEngine::DoAddL()
	{
    //Reset the modify index
    iModifyIndex = KUndefinedModifyIndex;
	
	iAppUi.ActivateView(KEntryViewId);	
	}

// ----------------------------------------------------
// CCalendarAPIexampleEngine::SaveL()
// Adds or updates the current entry to the agenda file.
//
// Called from CCalendarAPIexampleEntryView when the
// view is closed.
// ----------------------------------------------------	
void CCalendarAPIexampleEngine::DoSaveL()
    {
    //If iEntry is created in CreateEntryForModificationL then
    //there's a new anniversary being added. 
    //add a new anniversary
    
    if (iEntry) //this has been created in CreateEntryForModificationL
                //and the data has been stored by a call to iEntry.SetValuesL
        {
        if (iEntry->Modified())
            {
            iEntry->SaveValuesL();
            
            CCalEntry* anniv = iEntry->Anniv();

        	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(anniv);
        	TInt num;

        	iEntryView->StoreL(calEntryList, num);
        	
        	calEntryList.Reset();
        	
            }
        }
    //modify existing anniversary
    else
        {
        if (0 > iModifyIndex || iEntries.Count() <= iModifyIndex)
            {
            Panic(KInvalidModifyIndex);
            }
        //Get the entry which is being modified
        CCalHelperEntry* entry = iEntries[iModifyIndex];

        if (entry->Modified()) //are there any changes
            {
            if (entry->DateHasChanged())
                {                
                CCalEntry* updateAnniv = entry->Anniv();
                TTime startDate(entry->Date());
                TCalTime time;
                time.SetTimeLocalL(startDate);
                updateAnniv->SetStartAndEndTimeL(time,time);
                UpdateAnniversaryL(updateAnniv);
                }
            //the date of the entry hasn't changed, the entry is just updated.
            else 
                {
                entry->SaveValuesL();
                CCalEntry* updateAnniv = entry->Anniv();
                UpdateAnniversaryL(updateAnniv);
                }
            DoSearchL(iCurrentSearchType);
            }
        }
    }	
     
// ----------------------------------------------------
// CCalendarAPIexampleEngine::SetModifyIndex()
// Sets the modify index. Panics with KInvalidModifyIndex
// if parameter aIndex is negative or greater than the
// number of entries.
//
// Called only from CCalendarAPIexampleEntriesView when the
// Edit command has been selected
// ----------------------------------------------------
//
void CCalendarAPIexampleEngine::SetModifyIndex(const TInt& aIndex)
    {
    if (aIndex < 0 || aIndex >= iEntries.Count())
        {
        Panic(KInvalidModifyIndex);
        }

    iModifyIndex = aIndex;
    }     

// ----------------------------------------------------
// CCalendarAPIexampleEngine::CreateEntryForModificationL()
// Returns an entry for modification. Creates a new
// entry if iModifyIndex hasn't been set. Panics with
// KInvalidModifyIndex if iModifyIndex is greater than
// the number of entries.
//
// Called from CCalendarAPIexampleEntryView when
// the container is created. 
// ----------------------------------------------------
//

void CCalendarAPIexampleEngine::CreateEntryForModificationL(TBool& aModify)
    {
    delete iEntry;
    iEntry = NULL;

    //No selected entry, create a new one for adding an entry.
    if (iModifyIndex < 0)
        {
        aModify = EFalse;
        CCalEntry* nulli = NULL;
        
        iEntry = CCalHelperEntry::NewL(nulli);
        }

    if (iModifyIndex >= iEntries.Count())
        {
        Panic(KInvalidModifyIndex);
        }

    aModify = ETrue;
    }
    
TInt CCalendarAPIexampleEngine::EntryCount() const
    {
    return iEntries.Count();
    }   

TBool CCalendarAPIexampleEngine::SetValuesToNewEntry( const TDesC& aName,
                        const TDateTime& aDate,
                        const TBool& aAlarm,
                        const TDateTime& aAlarmTime,
                        const TInt& aSynchronizationMethod)

    {
    CCalHelperEntry *entry=NULL;
    if( iEntry )
        {
        entry = iEntry;
        }
        
    else 
       entry = iEntries[iModifyIndex];    
    
    return entry->SetValues(aName,aDate,aAlarm,aAlarmTime,aSynchronizationMethod);
       
    }

void CCalendarAPIexampleEngine::GetValuesToSet(TDes& aName, TTime& aDate,
                   TBool& aAlarm, TTime& aAlarmTime,
                            TInt& aSync)
    {
    CCalHelperEntry *entry=NULL;
    if( iEntry )
        {
        entry = iEntry;
        }        
    else 
        entry = iEntries[iModifyIndex];


    aName = entry->Name();
    aDate = entry->Date();
    aAlarm = entry->Alarm();
    aAlarmTime = entry->AlarmTime();
    aSync = entry->SynchronizationMethod();    
    }

// ----------------------------------------------------
// CCalendarAPIexampleEngine::Entry()
// returns a reference to an entry for reading the values
// of the entry. Panics with EOutOfEntriesArray if parameter
// aIndex is negative or greater than the number of entries
//
// Called ONLY from CCalendarAPIexampleEntriesContainer when
// populating the list box
// ----------------------------------------------------
//
CCalHelperEntry& CCalendarAPIexampleEngine::Entry(const TInt& aIndex)
    {
    if (0 > aIndex || iEntries.Count() <= aIndex)
        {
        Panic(EOutOfEntriesArray);
        }

    return *iEntries[aIndex];
    }


// ----------------------------------------------------
// CCalendarAPIexampleEngine::ModifyIndex()
// Returns the modify index.
//
// Called only from CCalendarAPIexampleEntryView
// When deleting the entry.
// ----------------------------------------------------
//

TInt CCalendarAPIexampleEngine::ModifyIndex() const
    {
    return iModifyIndex;
    }
    
void CCalendarAPIexampleEngine::ExecuteDeletionL()
    {		
	DeleteEntryL(ModifyIndex());
	
	// If no more entries exist in the listbox, activate search view.
	if (EntryCount() == 0)
		{
		iAppUi.ActivateView(KSearchViewId);
		}
	// activate entries view
	else
		{
		iAppUi.ActivateView(KEntriesViewId);
		}    
    }
/*******END OF CalendarEngineCommandsInterface functions**********************/

// End of file

⌨️ 快捷键说明

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