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

📄 iapconnectremoveiapcontainer.cpp

📁 symbian中如何取得内部联网方式
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CIAPConnectRemoveIapContainer from 
*               IAPConnectRemoveIapContainer.cpp
*  Part of  : Internet Access Points Example v2.0
*  Created  : 01.09.2006 by Forum Nokia
*  Version  : 2.0
*  Copyright: Forum Nokia
* ============================================================================
*/

// INCLUDE FILES
#include "IAPConnectRemoveIapContainer.h"
#include "IAPConnect.hrh"
#include <aknlists.h>  //listbox
#include <barsread.h> 
#include <iapconnect.rsg>
#include <commdb.h> // CCommsDatabase
#include <ApSelect.h> //CApSelect
#include <badesca.h> // CDesArray

//CONSTANTS
_LIT(KListItemFormat, "%d\t%S");
const TInt KMaxIapListItemLength = 32;

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

// Destructor
CIAPConnectRemoveIapContainer::~CIAPConnectRemoveIapContainer()
    {
    delete iListBox;
    iIAPs.Close();
    }
    
// ---------------------------------------------------------
// CIAPConnectRemoveIapContainer::ConstructL()
// Symbian two phased constructor
// ---------------------------------------------------------
//
void CIAPConnectRemoveIapContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
    
    iListBox = new(ELeave) CAknSingleNumberStyleListBox;
 	iListBox->SetContainerWindowL(*this);

    iListBox->ConstructL( this, EAknListBoxSelectionList);

	GetIapListL();
	
	iListBox->CreateScrollBarFrameL(ETrue);
 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
    CEikScrollBarFrame::EOff,
    CEikScrollBarFrame::EAuto);
 
	iListBox -> SetFocusing(ETrue);
	
    SetRect(aRect);
    iListBox->SetExtent(TPoint(0,0), aRect.Size());
    iListBox->ActivateL();
    iListBox->DrawNow();
    ActivateL();
    }

// ---------------------------------------------------------
// CIAPConnectRemoveIapContainer::GetIapList()
// Get Iaps' names and id to list
// ---------------------------------------------------------
//
void CIAPConnectRemoveIapContainer::GetIapListL()
	{
   	
   	// open commdb
	CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
	CleanupStack::PushL(commDb);

	// open IAP table
	CCommsDbTableView* commView = 
        commDb->OpenIAPTableViewMatchingBearerSetLC(
            ECommDbBearerCSD|ECommDbBearerGPRS,
            ECommDbConnectionDirectionOutgoing);
	
	// open list
	CTextListBoxModel* model = iListBox->Model();
	CDesCArray* itemArray = static_cast<CDesCArray*> (model->ItemTextArray());
	
	//Delete old listitems 
	itemArray -> Reset();
	iIAPs.Reset();
	
	// search all IAPs
	if (commView->GotoFirstRecord() == KErrNone)
		{
		do
			{
			TIap iap;
			commView->ReadTextL(TPtrC(COMMDB_NAME), iap.iName);
			commView->ReadUintL(TPtrC(COMMDB_ID), iap.iId);
			
			
			TBuf<KMaxIapListItemLength> item;
			item.Format(KListItemFormat, iap.iId, &iap.iName);
			itemArray->AppendL(item);
			
			if (iIAPs.Append(iap) != KErrNone)
				{
				return;					
				}
			
			}
		while (commView->GotoNextRecord() == KErrNone);
		}
	CleanupStack::PopAndDestroy(commView);
	CleanupStack::PopAndDestroy(commDb);
	
	}

// ---------------------------------------------------------
// CIAPConnectRemoveIapContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CIAPConnectRemoveIapContainer::SizeChanged()
    {
    TRect rect = Rect();
    iListBox->SetExtent(TPoint(0,0), rect.Size());
	}

// ---------------------------------------------------------
// CIAPConnectRemoveIapContainer::CountComponentControls()
// Gets the number of controls contained in a compound control.
// ---------------------------------------------------------
//
TInt CIAPConnectRemoveIapContainer::CountComponentControls() const
    {
    if (iListBox)
    	{
    	return 1;
    	}
    else
    	{
    	return 0;
    	}
    }

// ---------------------------------------------------------
// CIAPConnectRemoveIapContainer::ComponentControl() 
// Gets the specified component of a compound control. 
// ---------------------------------------------------------
//
CCoeControl* CIAPConnectRemoveIapContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
        	return iListBox;
        default:
            return NULL;
        }
    }

// ---------------------------------------------------------
// CIAPConnectRemoveIapContainer::Draw() 
// Draw a control - called by window server.
// ---------------------------------------------------------
//
void CIAPConnectRemoveIapContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }


// ---------------------------------------------------------
// CIAPConnectRemoveIapContainer::OfferKeyEventL()
// Handles key events.
// ---------------------------------------------------------
//
TKeyResponse CIAPConnectRemoveIapContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent, TEventCode aType)
    {
	TKeyResponse res = EKeyWasNotConsumed;
   	res =  iListBox->OfferKeyEventL(aKeyEvent, aType);
    return res;
    }

// ---------------------------------------------------------
// CIAPConnectRemoveIapContainer::GetSelectedIapId()
// return selected Iap's id
// ---------------------------------------------------------
//
TUint32 CIAPConnectRemoveIapContainer::GetSelectedIapId()
	{
   	TUint index = iListBox -> CurrentItemIndex();
	return iIAPs[ index ].iId;
	}

// ---------------------------------------------------------
// CIAPConnectRemoveIapContainer::GetSelectedIapName
// return selected Iap's id
// ---------------------------------------------------------
//
TDesC& CIAPConnectRemoveIapContainer::GetSelectedIapName()
	{
		TUint index = iListBox -> CurrentItemIndex();
		return iIAPs[ index ].iName;
	}
	
// End of File  

⌨️ 快捷键说明

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