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

📄 callcontainer.cpp

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

// INCLUDES

//  Class include
#include "CallContainer.h"

// System includes
#include <AknWaitDialog.h>        // CAknWaitDialog
#include <aknlists.h>            // CAknDoubleNumberStyleListBox
#include <CallSummary.rsg>        // R_EMPTY_LIST_TEXT
#include <CPbkContactItem.h>    // CPbkContactItem 

// User includes
#include "CallArray.h"            // CCallArray
#include "CallLogEngine.h"        // CCallLogEngine
#include "PhoneBookEngine.h"    // CPhoneBookEngine

// CONSTANTS

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

/**
* Symbian OS 2 phase constructor.
* Constructs the CCallContainer using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
* 
* @param aRect The rectangle for this window
* @param aDirectionId what type of calls to filter from log i.e incoming
* @param  aPhoneBookEngine reference to the phonebook engine
* @return The newly constructed CCallContainer
*/
CCallContainer* CCallContainer::NewL(const TRect& aRect, TInt aDirectionId, CPhoneBookEngine& aPhoneBookEngine)
{
    CCallContainer* self = CCallContainer::NewLC(aRect, aDirectionId, aPhoneBookEngine);
    CleanupStack::Pop(self);
    return self;
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CCallContainer using the constructor and ConstructL 
* method, leaving the constructed object on the CleanupStack before returning it.
* 
* @param aRect The rectangle for this window
* @param aDirectionId what type of calls to filter from log i.e incoming
* @param  aPhoneBookEngine reference to the phonebook engine
* @return The newly constructed CCallContainer
*/
CCallContainer* CCallContainer::NewLC(const TRect& aRect, TInt aDirectionId, CPhoneBookEngine& aPhoneBookEngine)
{
    CCallContainer* self = new (ELeave) CCallContainer(aPhoneBookEngine);
    CleanupStack::PushL(self);
    self->ConstructL(aRect, aDirectionId);
    return self;
}

/**
* C++ constructor
* @param  aPhoneBookEngine reference to the phonebook engine
*/
CCallContainer::CCallContainer(CPhoneBookEngine& aPhoneBookEngine)
    :iPhoneBookEngine(aPhoneBookEngine)
{
}

/**
* Symbian OS 2nd phase constructor.  Creates a Window for the controls, which it contains.
* Constructs a label and adds it to the window, which it then activates.
* @param aRect The rectangle for this window
* @param aDirectionId what type of calls to filter from log i.e incoming
*/ 
void CCallContainer::ConstructL(const TRect& aRect, TInt aDirectionId)
{    
    CreateWindowL();
    SetRect(aRect);

    // Create the List Box
    iListBox = new (ELeave) CAknDoubleStyleListBox();
    iListBox->ConstructL(this, EAknListBoxSelectionList);
    iListBox->SetContainerWindowL(*this);
    iListBox->CreateScrollBarFrameL(ETrue);
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
    iListBox->SetRect(Rect());

    // Show the empty list box text rather than the default "no data"    
    HBufC* emptyListText = iEikonEnv->AllocReadResourceLC(R_EMPTY_LIST_TEXT);
    iListBox->View()->SetListEmptyTextL(*emptyListText);
    CleanupStack::PopAndDestroy (emptyListText);

    // Show busy dialog if required.
    ShowBusyDialogL();

    //  Create log Engine
    iCallArray = CCallArray::NewL(iPhoneBookEngine);
    iCallLogEngine = CCallLogEngine::NewL(*this, *iCallArray, aDirectionId);
    
    ActivateL();
}

/**
*
* Called by framework when the view size is changed.
* Resizes iListBox accordingly.
*
*/
void CCallContainer::SizeChanged()
{
    if (iListBox)
    {
        iListBox->SetRect(Rect());
    }
}

/**
* Called by the framework in compound controls    
* @return The number of controls in this CCallContainer
*/
TInt CCallContainer::CountComponentControls() const
{
    return 1;
}

/**
* Called by the framework in compound controls    
* @param The index of the control to return
* @return The control for aIndex
*/
CCoeControl* CCallContainer::ComponentControl(TInt aIndex) const
{
    if (aIndex != 0)
    {
        return NULL;
    }
    else 
    {
        return iListBox;
    }
}

/** 
* Destructor.  
*/
CCallContainer::~CCallContainer()
{
    delete iListBox;
    delete iCallArray;
    delete iCallLogEngine;

    CancelBusyDialog(); // deletes iBusyNote if it exists.
}

/**
* Called by the framework to draw this control.  Clears the area in 
* aRect.
* @param aRect in which to draw
*/
void CCallContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.Clear(aRect);
}

/** 
* from MCallLogEngineObserver
* Called from CCallLogEngine, when call array
* has been populated with events from the log engine
*/
void CCallContainer::CallArrayCreatedL()
{
    iCallArray->AnalysisCallLogArrayL(CCallArray::ESummation);
    iCallArray->CreateListBoxDescriptorsL(CCallArray::ESummation);
    SetListBoxArray();

    // Cancel busy message
    CancelBusyDialog();
}

/** 
* from MCallLogEngineObserver
* Called from CCallLogEngine, when
* there are no events in the log engine to
* populate the call array
*/
void CCallContainer::CallArrayEmptyL()
{
    // Cancel busy message
    CancelBusyDialog();
}

/** 
* from MCallLogEngineObserver
* Called from CCallLogEngine, if there has
* been an error making an asynchronous request
*/
void CCallContainer::CallLogErrorL()
{
    // Cancel busy message
    CancelBusyDialog();
}

/** 
* This functions sets the data displayed in the list box
* to the array created by CCallLogEngine
*/
void CCallContainer::SetListBoxArray()
{
    CTextListBoxModel* model = iListBox->Model();
    // sets the model data
    model->SetItemTextArray(iCallArray);
    model->SetOwnershipType(ELbmDoesNotOwnItemArray);
    iListBox->Reset();
    DrawNow();
}

/**
* from CoeControl
* Called by  framework to handle key-presses. Directs key up arrow and down arrow 
* key presses to the list box.
* @param aKeyEvent the key event
* @param aType the type of key event: EEventKey, EEventKeyUp or EEventKeyDown
* @return indicates whether or not the key event was used by this control
*/
TKeyResponse CCallContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent, TEventCode aType)
{
    TChar charCode(aKeyEvent.iCode);
    switch (charCode) // The code of key event is...
    {
        // Switches tab
        case EKeyLeftArrow: // Left key.
        case EKeyRightArrow: // Right Key.
            break;
        default:
        {
            if (iListBox)
            {
                return iListBox->OfferKeyEventL(aKeyEvent, aType);
            }
        }
    }
    return EKeyWasNotConsumed;
}

/**
* Tests whether there is a currently selected listbox entry and if
* it doesn't have an associated contact in the contact database
* @return should we show the contact menu?
*/
TBool CCallContainer::ShowContactMenu() const
{
    TInt index = iListBox->CurrentItemIndex();
    
    if (index == -1)
    {
        return EFalse;    // There is no selected entry.
    }

    // If the selected entry has a contact return EFalse.
    return !(*iCallArray)[index].HasContact();
}

/**
* Tests whether the currently selected listbox entry 
* has an associated speed dial entry.
* @return should we show the speed dial menu?
*/
TBool CCallContainer::ShowSpeedDialMenuL() const
{
    // Get contact id of currently selected contact
    TContactItemId contactId;
    if (!GetListBoxSelectionContact(contactId))
    {
        return EFalse;    // No selection; don't show menu.
    }

    if (contactId == -1)
    {
        return ETrue;    // Selected item does not have an associated contact; show menu.
    }

    // Get a copy of the contact item using the contact id.
    CPbkContactItem* contact = iPhoneBookEngine.ReadContactLC(contactId);
    TInt numElements = (*contact).CardFields().Count();

    for (TInt i = 0; i < numElements; i++)
    {
        if ((*contact).CardFields()[i].ItemField().IsSpeedDial())
        {
            CleanupStack::PopAndDestroy(contact);
            return EFalse;    // Speed dial already assigned; don't show menu.
        }
    }

    // Else speed dial not assigned; show menu.
    CleanupStack::PopAndDestroy(contact);
    return ETrue;
}

/**
* Returns  the currently selected listbox entry's telephone number
* @param aSelectionNumber a reference to the selected entry telephone number
* @return does the call succeed? (is there a selected entry?)
*/
TBool CCallContainer::GetSelectionNumber(TDes& aSelectionNumber) const
{
    TInt index = iListBox->CurrentItemIndex();

    if (index == -1)
    {
        return EFalse;    // There is no selected entry.
    }

    // Return the selected number.
    aSelectionNumber = (*iCallArray)[index].iTelephoneNumber;
    return ETrue;
}

/** 
* Returns the contact Id for the currently selected listbox entry
* @param aContactItemId a reference to the selected entry's contact Id
* @return does the call succeed? (is there a selected entry?)
*/
TBool CCallContainer::GetListBoxSelectionContact(TContactItemId& aContactItemId) const
{
    TInt index = iListBox->CurrentItemIndex();

    if (index == -1)
    {
        return EFalse;    // There is no selected entry.
    }

    // Return the selected contact Id.
    aContactItemId = (*iCallArray)[index].iContactId;
    return ETrue;
}

/**
* Returns a reference to the information about the currently
* selected entry.
* @param aCallInfo a reference to the selected entry's call info
* @return does the call succeed? (is there a selected entry?)
*/
TBool CCallContainer::GetListBoxSelectionCallInfo(TCallInfo& aCallInfo) const
{
    TInt index = iListBox->CurrentItemIndex();

    if (index == -1)
    {
        return EFalse;    // There is no selected entry.
    }

    // Return the call info.
    aCallInfo = (*iCallArray)[index];
    return ETrue;
}

/**
* Sets the call info for the selected entry.
* @param aCallInfo a reference to the selected entry's call info.
*/
void CCallContainer::SetListBoxSelectionCallInfo(const TCallInfo& aCallInfo)
{
    TInt index = iListBox->CurrentItemIndex();

    if (index == -1)
    {
        return;    // There is no selected entry.
    }

    // Return the call info.
    (*iCallArray)[index] = aCallInfo;
}

/**
* Cancels the busy note
*/
void CCallContainer::CancelBusyDialog()
{
    // Test that the note exists first as it may be cancelled from more than one place.

    if (iBusyNote)
    {
        // Trap any error as CancelBusyDialog can not leave.
        TRAPD(error, iBusyNote->ProcessFinishedL(););    // Deletes the dialog and nulls the pointer pointing to it.
    }
}

/**
* shows the busy note
*/
void CCallContainer::ShowBusyDialogL()
{
    // This function creates and shows a wait dialog. 
    // There is a delay of ~1.5 seconds before it is shown, 
    // so if the processing is performed quickly, the user will never see it.

    CancelBusyDialog();    // Cancel any already showing dialog.

    // By passing the address of its pointer into its constructor, the dialog possesses 
    // the power to delete itself and nullify the pointer pointing to it. Therefore iBusyNote
    // must not be able to go out of scope!
    iBusyNote = new (ELeave) CAknWaitDialog((REINTERPRET_CAST(CEikDialog**, &iBusyNote)));
    iBusyNote->ExecuteLD(R_BUSY_NOTE);
}

// End of File

⌨️ 快捷键说明

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