Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3464251
  • 博文数量: 1450
  • 博客积分: 11163
  • 博客等级: 上将
  • 技术积分: 11101
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-25 14:40
文章分类

全部博文(1450)

文章存档

2017年(5)

2014年(2)

2013年(3)

2012年(35)

2011年(39)

2010年(88)

2009年(395)

2008年(382)

2007年(241)

2006年(246)

2005年(14)

分类: C/C++

2009-04-22 18:59:50

 

From Forum Nokia Wiki

Contents

[]

[edit] Access point (IAP) selection dialog

UI Libraries used:

LIBRARY  avkon.lib 
LIBRARY  eikcoctl.lib

Add this to your header file:

class TIapData
{
public:
	TBuf<128> iName;
	TUint32 iIap;
 
};

These are the additional headers files required:

#include 		// CAknSinglePopupMenuStyleListBox
#include 
#include 		// CCommsDatabase
TInt SelectIAPL()
{
	CArrayFixFlat* iEApList=new (ELeave) CArrayFixFlat(2) ;
	TInt stack=0;
	// Make listitems. and PUSH it
	CAknSinglePopupMenuStyleListBox* list = new(ELeave) CAknSinglePopupMenuStyleListBox;
	CleanupStack::PushL(list);stack++; 
 
	// Create popup list and PUSH it.
	CAknPopupList* popupList = CAknPopupList::NewL(list,
		R_AVKON_SOFTKEYS_OK_CANCEL, AknPopupLayouts::EMenuWindow);
	CleanupStack::PushL(popupList);stack++; 
 
	CDesCArrayFlat* items = new (ELeave) CDesCArrayFlat(5);
	CleanupStack::PushL(items);stack++; 
	// initialize listbox.
	list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
	list->CreateScrollBarFrameL(ETrue);
	list->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,
		CEikScrollBarFrame::EAuto);
 
 
	TBuf<52> iapfromtable;
	TInt err = KErrNone;
 
	CCommsDatabase* iCommsDB=CCommsDatabase::NewL(EDatabaseTypeIAP);
	CleanupStack::PushL(iCommsDB);stack++; 
#ifdef __SERIES60_3X__
	CCommsDbTableView* gprsTable = iCommsDB->OpenIAPTableViewMatchingBearerSetLC(
		ECommDbBearerGPRS|ECommDbBearerWLAN|ECommDbBearerVirtual,
		ECommDbConnectionDirectionOutgoing); 
#else
	CCommsDbTableView* gprsTable = iCommsDB->OpenIAPTableViewMatchingBearerSetLC(
		ECommDbBearerGPRS|ECommDbBearerVirtual,
		ECommDbConnectionDirectionOutgoing); 
#endif
	User::LeaveIfError(gprsTable->GotoFirstRecord());
	TInt i=0;
	TUint32 id;
	TIapData eap;	
 
	TInt cur =0; //current value
	do
	{
		gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
		gprsTable->ReadUintL(TPtrC(COMMDB_ID), id);
		items->AppendL(iapfromtable);
		eap.iIap = id;
		eap.iName.Copy(iapfromtable);
		iEApList->AppendL(eap);
 
		err = gprsTable->GotoNextRecord();
		i++;
	}
	while (err == KErrNone);
	CleanupStack::PopAndDestroy(2); stack--; 
 
	// Set listitems.
	CTextListBoxModel* model = list->Model();
	model->SetItemTextArray(items);
	model->SetOwnershipType(ELbmOwnsItemArray);
	CleanupStack::Pop();    
 
	popupList->SetTitleL(_L("IAP"));
	list->SetListBoxObserver(popupList);
	TInt popupOk = popupList->ExecuteLD();
	CleanupStack::Pop();    
	TInt iap=0;
	if (popupOk)
	{	
		TInt index = list->CurrentItemIndex();
		iap=(*iEApList)[index].iIap;
 
	}
	CleanupStack::PopAndDestroy();  
	iEApList->Reset();
	delete iEApList;
	return iap;
}

[edit] Reading all access points from the device

The following code reads all access points from the device disregarding their type. This is preferred unless there is some grave reason why you would force the user to select e.g. from GPRS connections.


TFileName iapName;
TUint32 iapID;
TInt err; 
 
// open the IAP communications database
CCommsDatabase* commDB = CCommsDatabase::NewL();
CleanupStack::PushL(commDB);
 
// Open the IAP table
CCommsDbTableView* view = commDB->OpenTableLC(TPtrC(IAP));
 
// Point to the first entry
if (view->GotoFirstRecord() == KErrNone)
{
	do
	{
		view->ReadTextL(TPtrC(COMMDB_NAME), iapName);
		view->ReadUintL(TPtrC(COMMDB_ID), iapID);
 
		// Store name and ID to where you want to
	} while (err = view->GotoNextRecord(), err == KErrNone);
}
 
CleanupStack::PopAndDestroy(); // view
CleanupStack::PopAndDestroy(); // commDB


[edit] Reading GPRS/CSD internet access points from the device

Following code sample shows how to retrieve all set GPRS or CSD internet access point from the device.


CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(commDb);
 
CCommsDbTableView* commView = commDb->OpenIAPTableViewMatchingBearerSetLC(
  ECommDbBearerCSD|ECommDbBearerGPRS, ECommDbConnectionDirectionOutgoing);
 
TFileName TmpName;	
 
if (commView->GotoFirstRecord() == KErrNone)
{
	do
	{
		TmpName.Zero();
		commView->ReadTextL(TPtrC(COMMDB_NAME),TmpName);
		
		// Add TmpName to CDesCArray for example
		// it has the IAP's human readable name
		
		TUint32 IapNum;
		commView->ReadUintL(TPtrC(COMMDB_ID),IapNum);
		
		// Add IapNum into other array, 
		// it has the ID for the accesspoint used with connection
		
	}while (commView->GotoNextRecord() == KErrNone);
}
 
CleanupStack::PopAndDestroy(2);//commView,commDb


With the code the TmpName variable will held the internet access point name you could show to user for selection, and the IapNum variable holds the internet access point identifier you could then use with the RConnection when making a silent connection. Note that when making a silent connection you also need to call the SetDialogPreference()-function with ECommDbDialogPrefDoNotPrompt for the connection preferences (TCommDbConnPref).

[edit] Retrieving Proxy Server Name from IAP

The code below shows how to retrieve proxy server name and the port number from a certain IAP.


//
// The tableView variable here is the instance of CCommsDbTableView
// Normally you call CCommsDatabase::OpenTableLC() to get the instance of
// CCommsDbTableView.
// (See also the other examples above.)
//
 
// Firstly, we need to get the IAPService and IAPServiceType 
// of our IAP in order to find out the proxy information.
TUint32 iapService;
HBufC* iapServiceType;
tableView->ReadUintL(TPtrC(IAP_SERVICE), iapService);
iapServiceType = tableView->ReadLongTextLC(TPtrC(IAP_SERVICE_TYPE));
        
// Check whether this IAP uses proxy or not.
TBool isProxyEnabled = EFalse;
CCommsDbTableView* proxyTableView = commsDb->OpenViewOnProxyRecordLC(
        iapService, *iapServiceType);
if (KErrNone == proxyTableView->GotoFirstRecord())
    {
    proxyTableView->ReadBoolL(TPtrC(PROXY_USE_PROXY_SERVER), isProxyEnabled);
 
    // If proxy is enabled then do something.
    if (isProxyEnabled)
        {
        proxyServerName = proxyTableView->ReadLongTextLC(TPtrC(PROXY_SERVER_NAME));
        proxyTableView->ReadUintL(TPtrC(PROXY_PORT_NUMBER), proxyPortNumber);
	
        // Do whatever you want with proxyServerName and proxyPortNumber.
        	
        CleanupStack::PopAndDestroy(proxyServerName);
        }
    }
阅读(598) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~