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

📄 callarray.cpp

📁 series60 应用程序开发的源代码 series60 应用程序开发的源代码
💻 CPP
字号:
/**
* 
* @brief Definition of CCallArray
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDES

//  Class include
#include "CallArray.h"

// System includes
#include <logwrap.h>    // CLogEvent 

// User includes
#include "PhoneBookEngine.h"    // CPhoneBookEngine

// Constants
_LIT(KListBoxNoNameFormat, "\t%S\t%S\t");
_LIT(KListBoxContactNameFormat, "\t%S\t%S  %S\t");
_LIT(KTimeFormat,"%:0%H%:1%T%:2%S");

const TInt KArrayOfLogEntriesGranularity = 5;

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

/** 
* Destructor.  Frees up memory for the iArray.
*/
CCallArray::~CCallArray()
{
    delete iArray;
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CCallArray using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
* 
* @param  aPhoneBookEngine reference to the phonebook engine
* @return The newly constructed CCallArray
*/
CCallArray* CCallArray::NewL(CPhoneBookEngine& aPhoneBookEngine)
{
    CCallArray* self = CCallArray::NewLC(aPhoneBookEngine);
    CleanupStack::Pop(self);
    return self;
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CCallArray using the constructor and ConstructL 
* method, leaving the constructed object on the CleanupStack before returning it.
* 
* @param  aPhoneBookEngine reference to the phonebook engine
* @return The newly constructed CCallArray
*/
CCallArray* CCallArray::NewLC(CPhoneBookEngine& aPhoneBookEngine)
{
    CCallArray* self = new (ELeave) CCallArray(aPhoneBookEngine);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
}
    
/**
* C++ constructor.  
* @param  aPhoneBookEngine reference to the phonebook engine
*/ 
CCallArray::CCallArray(CPhoneBookEngine& aPhoneBookEngine)
    :iPhoneBookEngine(aPhoneBookEngine)    
{
}

/**
* Symbian OS 2nd phase constructor.  
*/ 
void CCallArray::ConstructL()
{
    iArray = new (ELeave) CArrayFixFlat<TCallInfo>(KArrayOfLogEntriesGranularity); 
}

/**
* from MDesCArray, returns the number of items in the list
* @return number of items in array
*/ 
TInt CCallArray::MdcaCount() const
{
    return iArray->Count();
}

/**
* from MDesCArray, 
* This function returns the internal representation of the data to
* the descriptor format used by the CAknDoubleNumberStyleListBox
* @param aIndex the index of the entry required
* @return descriptor in the format used by  CAknDoubleNumberStyleListBox
*/
TPtrC CCallArray::MdcaPoint(TInt aIndex) const
{
    return (*iArray)[aIndex].iListBoxDescriptor;
}

/**
* This function adds a new element to the array of TCallInfos
* @param entry from the call log
*/
void CCallArray::AddEntryL(const CLogEvent& aEvent)
{
    TCallInfo entryParameters;
    TTimeIntervalSeconds timeInSeconds = aEvent.Duration();

    entryParameters.iDuration = timeInSeconds.Int();
    entryParameters.iContactId = aEvent.Contact();

    const TDesC& number = aEvent.Number();
    TInt maxLength = entryParameters.iTelephoneNumber.MaxLength();

    if (number.Length() > maxLength)
    {
        entryParameters.iTelephoneNumber = number.Left(maxLength);
    }
    else
    {
        entryParameters.iTelephoneNumber = aEvent.Number();
    }
            
    iArray->AppendL(entryParameters);
}

/**
* This function changes the internal representation of the data to
* the descriptor format used by the CAknDoubleNumberStyleListBox
* @param aMethod distinguishes what information the descriptor generated is
* to show.
*/
void CCallArray::CreateListBoxDescriptorsL(TAnalysis aMethod)
{
    for (TInt index = 0; index < iArray->Count(); index++)
    {
        TCallInfo& entryParameters = (*iArray)[index];    
        TBuf<64> secondLine;

        if (aMethod == ESummation)
        {
            TTime duration(0);
            TTimeIntervalSeconds timeInSeconds(entryParameters.iDuration);
            duration += timeInSeconds;
            duration.FormatL(secondLine, KTimeFormat);
        }
        else
        {
            secondLine.AppendNum(-1 * entryParameters.iCount);
        }

        // Ignore the contact ID from the log as the log may reference a contact that has been deleted.
        // (Also, a contact may have been created since the call that is not referenced in the log.)
        // It is left as an exercise for the reader to modify the code to update the log entry ;)
        entryParameters.iContactId = iPhoneBookEngine.GetContactIdL(entryParameters.iTelephoneNumber);

        if (entryParameters.iContactId == KNullContactId)
        {
            entryParameters.iListBoxDescriptor.Format(
                KListBoxNoNameFormat, 
                &entryParameters.iTelephoneNumber, 
                &secondLine);
        }
        else
        {
            iPhoneBookEngine.GetContactNameL(entryParameters.iName, entryParameters.iContactId);
            entryParameters.iListBoxDescriptor.Format(
                KListBoxContactNameFormat, 
                &entryParameters.iTelephoneNumber, 
                &secondLine, 
                &entryParameters.iName);
        }
    }
}

/**
* This function sorts the array by telephone number
* and counts the number of times the number is in the 
* array and the total duration of the calls. 
* @param aMethod how to sort the resultant array.
* @return the number of entries in the new array
*/
TInt CCallArray::AnalysisCallLogArrayL(TAnalysis aMethod)
{
    // Sort the array, based upon the telephone numbers
    TKeyArrayFix sortKey(_FOFF(TCallInfo, iTelephoneNumber), ECmpNormal);
    iArray->Sort(sortKey);

    //Combine and sum the entries in array
    TInt i = 0;

    TInt numberOfEntries = iArray->Count();

    for (TInt j = 1; j < numberOfEntries; j++)
    {
        if ((*iArray)[i].iTelephoneNumber == (*iArray)[j].iTelephoneNumber)
        {
            (*iArray)[i].iDuration += (*iArray)[j].iDuration;
            (*iArray)[i].iCount--;
        }
        else
        {
            i++;
            (*iArray)[i] = (*iArray)[j];
        }
    }

    // shrinking the array if the summation has reduced the number of entries
    iArray->ResizeL(i + 1);

    if (aMethod == ESummation)
    {
        // Resort the array, based upon the total call duration
        TKeyArrayFix sortKey(_FOFF(TCallInfo, iDuration), ECmpTInt);
        iArray->Sort(sortKey);
    }
    else
    {
        // Re-sort the array, based upon the number of times called
        TKeyArrayFix sortKey(_FOFF(TCallInfo, iCount), ECmpTInt);
        iArray->Sort(sortKey);
    }

    return i;
}

/**
* This function reduces the size of the array
* @param aCount The max number of entries in the array
* @return the number of entries in array
*/
TInt CCallArray::ReduceListL(TInt aCount)    
{
    TInt numEntries = iArray->Count();

    if (aCount <= numEntries)
    {
        iArray->ResizeL(aCount);
        return aCount;
    }
    else
    {
        return numEntries;
    }
}

/**
* This function returns a reference to the TCallInfo object 
* at aIndex in array
* @param aIndex of the required element
* @return reference to TCallInfo object held in  array
*/
TCallInfo& CCallArray::operator[](TInt aIndex) const
{
    return (*iArray)[aIndex];
}

// End of File

⌨️ 快捷键说明

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