You Are Here:

Community: Wiki

This page was last modified on 17 September 2009, at 06:55.

Reading internet access points from the device

From Forum Nokia Wiki

Contents

Access point (IAP) selection dialog

Reviewer Approved   

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);
}
}

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fFileE3aMicrokernelE5fArchitectureE2eGIFX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx5E2E0000X
RDF Facets: qfnZuserE5FtagQSxcommdbX qfnZuserE5FtagQSxiapX