In network connection selection, we usually traverse existing access points in the user's mobile phone, and then select an appropriate access point to connect to the network. Because the number of existing access points in each mobile phone is different, dynamic reading and existing access points are required. Therefore, you can inherit caknenumeratedtextpopupsettingitem, overload the completeconstructionl () method, and implement it in caknsettingitemlist,
Lib commdb. Lib
Accesspointsettingitem. h
# Include <aknsettingitemlist. h>
Class caccesspointsettingitem: Public caknenumeratedtextpopupsettingitem
{
Public:
Caccesspointsettingitem (tint aidentifier, tint & avalue );
// Load the IAP data
Tint loadiaplistl ();
Void loadl ();
PRIVATE:
Void createandexecutesettingpagel ();
Void completeconstructionl ();
PRIVATE:
Tint & ivalue;
};
Caccesspointsettingitem. cpp
# Include <commdb. h>
# Include "aaccesspointsettingitem. H"
Caccesspointsettingitem: cmobbleraccesspointsettingitem (tint aidentifier, tint & avalue)
: Caknenumeratedtextpopupsettingitem (aidentifier, avalue), ivalue (avalue)
{
}
// We must check whether the target value, ivalue, is in the loaded array or not.
// If not, it definitely causes a panic -- "setting item Lis 6 ".
// In that case, we will choose the first item as the default one.
Void caccesspointsettingitem: loadl ()
{
Carrayptr <caknenumeratedtext> * Texts (enumeratedtextarray ());
Tint selectedindex (indexfromvalue (ivalue ));
If (selectedindex <0) // No match found.
{
If (texts-> count ()> 0)
{
// Choose the first item as default one.
Caknenumeratedtext * Item (texts-> at (0 ));
// Reset external value to the default one.
Setexternalvalue (item-> enumerationvalue ());
}
}
Caknenumeratedtextpopupsettingitem: loadl ();
}
Tint caccesspointsettingitem: loadiaplistl ()
{
Tint firstiapid (kerrnotfound );
Carrayptr <caknenumeratedtext> * Texts = This-> enumeratedtextarray ();
// The destinations API does not exist
// So list all the connection points
// Add all the access points to the list
Ccommsdatabase * commdb (ccommsdatabase: newl (edatabasetypeiap ));
Cleanupstack: pushl (commdb );
// Open IAP table
Ccommsdbtableview * commview (commdb-> openiaptableviewmatchingbearersetlc (
Ecommdbbearergprs | ecommdbbearerwlan,
Ecommdbconnectiondireoutoutgoing ));
// Search all IAPS
For (tint error (commview-> gotofirstrecord (); error = kerrnone; Error
= Commview-> gotonextrecord ())
{
Tbuf <kcommsdbsvrmaxcolumnnamelength> iapname;
Tuint32 iapid;
Commview-> readtextl (tptrc (commdb_name), iapname );
Commview-> readuintl (tptrc (commdb_id), iapid );
Hbufc * Text (iapname. alloclc ());
Caknenumeratedtext * enumtext (New (eleave) caknenumeratedtext (iapid,
Text ));
Cleanupstack: Pop (text );
Cleanupstack: pushl (enumtext );
Enumeratedtextarray ()-> appendl (enumtext );
Cleanupstack: Pop (enumtext );
If (firstiapid = kerrnotfound)
{
Firstiapid = iapid;
}
}
Cleanupstack: popanddestroy (commview );
Cleanupstack: popanddestroy (commdb );
Return firstiapid;
}
Void caccesspointsettingitem: createandexecutesettingpagel ()
{
Caknsettingpage * DLG (createsettingpagel ());
Setsettingpage (DLG );
Settingpage ()-> setsettingpageobserver (this );
Settingpage ()-> setsettingtextl (settingname ());
Settingpage ()-> executeld (caknsettingpage: eupdatewhenchanged );
Setsettingpage (0 );
}
Void caccesspointsettingitem: completeconstructionl ()
{
Caknenumeratedtextpopupsettingitem: completeconstructionl ();
}
Constructing resources in RSS
Resource avkon_popup_setting_texts r_popup_setting_texts_enum
{
Setting_texts_resource = r_texts_enum;
}
Resource array r_texts_enum
{
Items =
{
Avkon_enumerated_text
{
Value = 0;
TEXT = "";
}
};
}
Resource avkon_setting_page r_setting_page_enum
{
Type = eaknctpopupsettinglist;
Editor_resource_id = r_popup_setting_list_enum;
}
Resource popup_setting_list r_popup_setting_list_enum
{
Flags = 0;
}
Call in ccoecontrol
Caknsettingitemlist * iitemlist;
Tint tempiapid (0 );
Const tdesc & text (_ L ("accesspoint "));
Caccesspointsettingitem * Item (New (eleave) caccesspointsettingitem (0, tempiapid ));
Cleanupstack: pushl (item );
Item-> constructl (isnumberedstyle, icount, text, icons, r_setting_page_enum,-1, 0, r_popup_setting_texts_enum );
Carrayptr <caknenumeratedtext> * textss (item-> enumeratedtextarray ());
Textss-> resetanddestroy ();
Tint firstiapid (item-> loadiaplistl ());
// Load list of IAPS
Item-> load ();
//> Append list
Iitemlist-> settingitemarray ()-> appendl (item );
Cleanupstack: Pop (item );