×
Namespaces

Variants
Actions

Reading internet access points from the device

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: symbianyucca (27 Mar 2007)
Last edited: hamishwillee (12 Jan 2012)

Contents

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 <aknlists.h>		// CAknSinglePopupMenuStyleListBox
#include <CommDbConnPref.h>
#include <CommDb.h> // CCommsDatabase
TInt SelectIAPL()
{
CArrayFixFlat<TIapData>* iEApList=new (ELeave) CArrayFixFlat<TIapData>(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;
}

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


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).

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);
}
}
This page was last modified on 12 January 2012, at 06:00.
62 page views in the last 30 days.