wlanutilities/wlanindicatorplugin/src/wlanindicatorpluginimplementation.cpp
branchRCL_3
changeset 12 981afc7d3841
parent 0 56b72877c1cb
child 17 024ee8b21fe2
equal deleted inserted replaced
11:8b0eae1b1d71 12:981afc7d3841
    28 #include <data_caging_path_literals.hrh>
    28 #include <data_caging_path_literals.hrh>
    29 #include <StringLoader.h>
    29 #include <StringLoader.h>
    30 #include <rconnmon.h>
    30 #include <rconnmon.h>
    31 #include <cmmanager.h>
    31 #include <cmmanager.h>
    32 #include <cmconnectionmethod.h>
    32 #include <cmconnectionmethod.h>
    33 #include <wlanmgmtclient.h>
       
    34 #include <wlanscaninfo.h>
       
    35 #include <cdblen.h>
       
    36 #include <commdb.h>
       
    37 #include <WlanCdbCols.h>
       
    38 #include <utf.h>
    33 #include <utf.h>
    39 #include <wlanindicator.rsg>
    34 #include <wlanindicator.rsg>
    40 #include "wlanindicatorpluginimplementation.h"
    35 #include "wlanindicatorpluginimplementation.h"
    41 
    36 
    42 
    37 
    75 
    70 
    76     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
    71     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
    77     iResource = iCoeEnv->AddResourceFileL( fileName );
    72     iResource = iCoeEnv->AddResourceFileL( fileName );
    78     
    73     
    79     iConnMonitor.ConnectL();
    74     iConnMonitor.ConnectL();
    80     
    75         
    81     iWlanMgmtClient = CWlanMgmtClient::NewL();
       
    82     
       
    83     }
    76     }
    84 
    77 
    85 // -----------------------------------------------------------------------------
    78 // -----------------------------------------------------------------------------
    86 // CWlanIndicatorPluginImplementation::NewL
    79 // CWlanIndicatorPluginImplementation::NewL
    87 // Two-phased constructor.
    80 // Two-phased constructor.
   105 CWlanIndicatorPluginImplementation::~CWlanIndicatorPluginImplementation()
    98 CWlanIndicatorPluginImplementation::~CWlanIndicatorPluginImplementation()
   106     {
    99     {
   107     iCoeEnv->DeleteResourceFile( iResource );
   100     iCoeEnv->DeleteResourceFile( iResource );
   108  
   101  
   109     iConnMonitor.Close();
   102     iConnMonitor.Close();
   110                
   103                    
   111     delete iWlanMgmtClient;
       
   112     
       
   113     }
   104     }
   114 
   105 
   115 
   106 
   116 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
   117 // CWlanIndicatorPluginImplementation::HandleIndicatorTapL
   108 // CWlanIndicatorPluginImplementation::HandleIndicatorTapL
   147 // CWlanIndicatorPluginImplementation::TextL( const TInt aUid, TInt& aTextType )
   138 // CWlanIndicatorPluginImplementation::TextL( const TInt aUid, TInt& aTextType )
   148 // ---------------------------------------------------------------------------
   139 // ---------------------------------------------------------------------------
   149 //    
   140 //    
   150 HBufC* CWlanIndicatorPluginImplementation::TextL( const TInt aUid,
   141 HBufC* CWlanIndicatorPluginImplementation::TextL( const TInt aUid,
   151                                                  TInt& aTextType )
   142                                                  TInt& aTextType )
   152     {   
   143     {
       
   144     
   153     HBufC* textBuf = NULL;
   145     HBufC* textBuf = NULL;
   154     
   146     
   155     switch ( aUid )
   147     switch ( aUid )
   156         {
   148         {
   157         case EAknIndicatorWlanAvailable:
   149         case EAknIndicatorWlanAvailable:
   188 //
   180 //
   189 HBufC* CWlanIndicatorPluginImplementation::CreateWlanNetworksFoundTextL()
   181 HBufC* CWlanIndicatorPluginImplementation::CreateWlanNetworksFoundTextL()
   190     {
   182     {
   191     
   183     
   192     HBufC* dynText = NULL;
   184     HBufC* dynText = NULL;
   193     HBufC* knownNetworkName = NULL;   
   185 
   194     TInt availableCount( 0 );
   186     // "qtn_uni_ind_wlan_avail_unknown_many    WLAN networks found"
   195 
   187     dynText = StringLoader::LoadL (
   196     knownNetworkName = AvailableNetworksInfoL( availableCount );
   188             R_QTN_UNI_IND_WLAN_AVAIL_UNKNOWN_MANY, iCoeEnv );
   197     
       
   198     CleanupStack::PushL( knownNetworkName ); 
       
   199     
       
   200     if ( !knownNetworkName )
       
   201         {
       
   202         if ( availableCount == 1 )
       
   203             {
       
   204             // dynText: "qtn_uni_ind_wlan_avail_unknown        WLAN network found"
       
   205             dynText = StringLoader::LoadL (
       
   206                     R_QTN_UNI_IND_WLAN_AVAIL_UNKNOWN, iCoeEnv );
       
   207             }
       
   208         else
       
   209             {
       
   210             // dynText: "qtn_uni_ind_wlan_avail_unknown_many    WLAN networks found"
       
   211             dynText = StringLoader::LoadL (
       
   212                     R_QTN_UNI_IND_WLAN_AVAIL_UNKNOWN_MANY, iCoeEnv );            
       
   213             }
       
   214         }
       
   215     else
       
   216         {
       
   217         // dynText: "qtn_uni_ind_wlan_avail_known        '%U' found"
       
   218         dynText = StringLoader::LoadL ( 
       
   219                 R_QTN_UNI_IND_WLAN_AVAIL_KNOWN, *knownNetworkName, iCoeEnv );
       
   220                        
       
   221         }
       
   222     
       
   223     CleanupStack::PopAndDestroy( knownNetworkName );
       
   224 
   189 
   225     return dynText;
   190     return dynText;
   226     }
   191     }
   227 
   192 
   228 
   193 
   250     CleanupStack::PopAndDestroy( connectedNetworkName );
   215     CleanupStack::PopAndDestroy( connectedNetworkName );
   251             
   216             
   252     return dynText;
   217     return dynText;
   253     }       
   218     }       
   254 
   219 
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // CWlanIndicatorPluginImplementation::AvailableNetworksInfoL()
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 HBufC* CWlanIndicatorPluginImplementation::AvailableNetworksInfoL(
       
   261     TInt& aAvailableCount )
       
   262     {
       
   263     
       
   264     HBufC* knownNetworkName = NULL; 
       
   265  
       
   266     // get available iaps
       
   267     RArray<TUint> availableIaps;
       
   268     TInt iapError( 0 );
       
   269     iapError = iWlanMgmtClient->GetAvailableIaps( availableIaps );
       
   270         
       
   271     if ( iapError == KErrNone )
       
   272         {
       
   273         // if there are known networks, get the name of the first one
       
   274         // in an alphabetical order
       
   275         if ( availableIaps.Count() )
       
   276             {
       
   277             // get all network names and put them into a sorted array
       
   278         
       
   279             // use one TWliWlanInfo struct to point to each IAP in a loop
       
   280             TWliWlanInfo* availableInfo = new ( ELeave ) TWliWlanInfo();
       
   281             CleanupStack::PushL( availableInfo );
       
   282         
       
   283             // descriptor array with granularity 2
       
   284             CDesCArray* networkNames = new (ELeave)CDesCArrayFlat( 2 );
       
   285             CleanupStack::PushL( networkNames );
       
   286       
       
   287             for ( TInt i = 0; i < availableIaps.Count() ; i++ )
       
   288                 {
       
   289                 availableInfo->iIapId = availableIaps[i];
       
   290                 GetWlanInfoFromIapL( *availableInfo );
       
   291             
       
   292                 // insert the name into the proper place
       
   293                 // in alphabetical order
       
   294                 networkNames->InsertIsqL(
       
   295                     ( availableInfo->iNetworkName ), ECmpFolded );
       
   296                 }
       
   297         
       
   298             knownNetworkName = ( networkNames->MdcaPoint(0) ).AllocL();
       
   299         
       
   300             CleanupStack::PopAndDestroy( networkNames );
       
   301             CleanupStack::PopAndDestroy( availableInfo );
       
   302                
       
   303             }
       
   304             
       
   305         else // unknown networks only        
       
   306             {
       
   307             CWlanScanInfo* scanInfo = CWlanScanInfo::NewL();                    
       
   308 
       
   309             TInt scanError( 0 );
       
   310             scanError = iWlanMgmtClient->GetScanResults( *scanInfo );
       
   311             if ( scanError == KErrNone )
       
   312                 {
       
   313                 // Find if we have 1 or more networks available,
       
   314                 // we don't have to know the exact amount
       
   315                 scanInfo->Next() ? aAvailableCount = 2 : aAvailableCount = 1;
       
   316                 }
       
   317             
       
   318             delete scanInfo;
       
   319         
       
   320             }
       
   321         }    
       
   322     
       
   323     availableIaps.Close();
       
   324     
       
   325     return knownNetworkName;
       
   326 
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // CWlanIndicatorPluginImplementation::GetWlanInfoFromIapL()
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 void CWlanIndicatorPluginImplementation::GetWlanInfoFromIapL( TWliWlanInfo& aWlanInfo )
       
   334     {
       
   335     CCommsDatabase* commsDb = CCommsDatabase::NewL();    
       
   336     CleanupStack::PushL( commsDb );
       
   337     
       
   338     CCommsDbTableView* commsDbIapTableView = commsDb->OpenViewMatchingUintLC(
       
   339         TPtrC( IAP ), TPtrC( COMMDB_ID ), aWlanInfo.iIapId );
       
   340 
       
   341     User::LeaveIfError( commsDbIapTableView->GotoFirstRecord() );
       
   342 
       
   343     commsDbIapTableView->ReadTextL( TPtrC( COMMDB_NAME ), aWlanInfo.iNetworkName );
       
   344     
       
   345     CleanupStack::PopAndDestroy( commsDbIapTableView );
       
   346     CleanupStack::PopAndDestroy( commsDb );
       
   347     }
       
   348 
   220 
   349 // ---------------------------------------------------------------------------
   221 // ---------------------------------------------------------------------------
   350 // CWlanIndicatorPluginImplementation::ConnectionNameL()
   222 // CWlanIndicatorPluginImplementation::ConnectionNameL()
   351 // ---------------------------------------------------------------------------
   223 // ---------------------------------------------------------------------------
   352 //
   224 //