wlanutilities/wlansniffer/mainapplication/src/wsfmaincontroller.cpp
changeset 19 10810c91db26
parent 3 ff3b37722600
child 22 498f36116140
equal deleted inserted replaced
3:ff3b37722600 19:10810c91db26
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of TWsfMainController.
       
    15 *
       
    16 */
       
    17 
       
    18 //  EXTERNAL INCLUDES
       
    19 #include <e32def.h>
       
    20 #include <wlansniffer.rsg>
       
    21 #include <utf.h>
       
    22 #include <apgcli.h>
       
    23 #include <AknQueryDialog.h>
       
    24 #include <StringLoader.h>
       
    25 
       
    26 #include <cmmanagerext.h>
       
    27 
       
    28 //  CLASS HEADER
       
    29 #include "wsfmaincontroller.h"
       
    30 
       
    31 //  INTERNAL INCLUDES
       
    32 #include "wsfmodel.h"
       
    33 #include "wsfwlaninfo.h"
       
    34 #include "wsfwlaninfoarray.h"
       
    35 #include "wsfappui.h"
       
    36 #include "wsfmainviewcontrollerif.h"
       
    37 #include "wsfdetailsviewcontrollerif.h"
       
    38 #include "wsfmainapplication.hrh"
       
    39 #include "wsfwlaninfoarrayvisitor.h"
       
    40 
       
    41 #include "wsflogger.h"
       
    42 
       
    43 //  LOCAL DEFINITIONS
       
    44 #ifdef _DEBUG
       
    45     _LIT( KMainControllerPanic, "TWsfMainController" );
       
    46     #define _ASSERTD( cond ) __ASSERT_DEBUG( (cond), \
       
    47             User::Panic( KMainControllerPanic, __LINE__) )
       
    48 #else
       
    49     #define _ASSERTD( cond ) {}
       
    50 #endif //_DEBUG
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // TWsfMainController::Initialize
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void TWsfMainController::Initialize( 
       
    57                             CWsfAppUi& aAppUi, 
       
    58                             CWsfModel& aModel, 
       
    59                             CWsfWlanInfoArrayVisitor &aWlanInfoBranding )
       
    60     {
       
    61     iAppUi = &aAppUi;
       
    62     iModel = &aModel;
       
    63     iWlanInfoBranding = &aWlanInfoBranding;
       
    64     iModel->SetConnecting( EFalse );
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // TWsfMainController::UpdateViewL
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void TWsfMainController::UpdateViewL()
       
    72     {
       
    73     LOG_ENTERFN( "TWsfMainController::UpdateViewL" ); 
       
    74     CWsfWlanInfoArray* array = iModel->GetWlanListL();
       
    75     array->SortArrayL( *iWlanInfoBranding );
       
    76  
       
    77     LOG_WRITEF( "ActiveViewL: %x", iModel->ActiveViewL().iUid );
       
    78     switch ( iModel->ActiveViewL().iUid )
       
    79         {
       
    80         case EMainViewId:
       
    81             {  
       
    82             _ASSERTD( iMainView );          
       
    83             iMainView->UpdateWlanListL( array );  
       
    84             break;
       
    85             }
       
    86 
       
    87         case EDetailsViewId:
       
    88             {
       
    89             _ASSERTD( iDetailsView );
       
    90             iDetailsView->WlanListChangedL( array );
       
    91             break;           
       
    92             }
       
    93         case EConnectedDetailsViewId:
       
    94             {
       
    95             iMainView->UpdateWlanListL( array );  
       
    96             iAppUi->UpdateConnectedDetailsL( array );
       
    97             break;           
       
    98             }
       
    99         default:
       
   100             {
       
   101             // Invalid view ID, make panic.
       
   102             _ASSERTD( 0 );   
       
   103             break;    
       
   104             }
       
   105         }
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // TWsfMainController::UpdateViewL
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void TWsfMainController::UpdateViewL( CWsfWlanInfoArray* aInfoArray )
       
   113     {
       
   114     LOG_ENTERFN( "TWsfMainController::UpdateViewL( aInfoArray ) " );
       
   115     LOG_WRITEF( "ActiveViewL: %x", iModel->ActiveViewL().iUid );    
       
   116     switch ( iModel->ActiveViewL().iUid )
       
   117         {
       
   118         case EMainViewId:
       
   119             {            
       
   120             iMainView->UpdateWlanListL( aInfoArray );  
       
   121             break;
       
   122             }
       
   123 
       
   124         case EDetailsViewId:
       
   125             {
       
   126             iDetailsView->WlanListChangedL( aInfoArray );
       
   127             break;           
       
   128             }
       
   129         case EConnectedDetailsViewId:
       
   130             {
       
   131             iMainView->UpdateWlanListL( aInfoArray );  
       
   132             iAppUi->UpdateConnectedDetailsL( aInfoArray );
       
   133             break;           
       
   134             }
       
   135         default:
       
   136             {
       
   137             // Invalid view ID, make panic.
       
   138             _ASSERTD( 0 );   
       
   139             break;    
       
   140             }
       
   141         }    
       
   142     }
       
   143 
       
   144 // Events from AppUi
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // TWsfMainController::ShowWlanListL
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void TWsfMainController::ShowWlanListL()
       
   151     {
       
   152     LOG_ENTERFN( "TWsfMainController::ShowWlanListL" ); 
       
   153     _ASSERTD( iAppUi );    
       
   154     _ASSERTD( iModel );
       
   155         
       
   156     iModel->SetActiveViewL( EMainViewId );
       
   157     iAppUi->ActivateMainViewL();
       
   158     }
       
   159         
       
   160 // ---------------------------------------------------------------------------
       
   161 // TWsfMainController::ShowDetailsL
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void TWsfMainController::ShowDetailsL()
       
   165    {
       
   166    LOG_ENTERFN( "TWsfMainController::ShowDetailsL" ); 
       
   167     _ASSERTD( iAppUi );    
       
   168     _ASSERTD( iModel );
       
   169     _ASSERTD( iModel->ActiveViewL().iUid != EDetailsViewId );
       
   170 
       
   171     TWsfWlanInfo* selectedWlan = iMainView->SelectedItem();
       
   172     
       
   173     if ( selectedWlan ) 
       
   174         {
       
   175         TBool connected = selectedWlan->Connected();
       
   176         
       
   177         if( connected ) // Connected Details View - Replaced with dialog
       
   178             {
       
   179             // Work around - Emulated view
       
   180             iModel->SetActiveViewL( EConnectedDetailsViewId );
       
   181             // Holds selected wlan Ssid
       
   182             HBufC8* ssid = selectedWlan->GetSsidAsUtf8LC(); 
       
   183         
       
   184             // Holds current wlan array 
       
   185             if ( !iInfoArray )
       
   186                 {
       
   187                 iInfoArray = iModel->GetWlanListL();
       
   188                 iInfoArray->SortArrayL( *iWlanInfoBranding );
       
   189                 }
       
   190             // Start and execute the Connected Details dialog
       
   191             // Set array and Ssid to detail view
       
   192             iAppUi->StartConnectedDetailsL( iInfoArray, *ssid );
       
   193             CleanupStack::PopAndDestroy( ssid ); 
       
   194             
       
   195             // After the dismissal of the Connected Details dialog, 
       
   196             // change back to the main view 
       
   197             ShowWlanListL();
       
   198             }
       
   199         else
       
   200             {
       
   201             iDetailsView = &( iAppUi->DetailsView( EDetailsViewId ) ); 
       
   202               iModel->SetActiveViewL( EDetailsViewId );
       
   203             iDetailsView->SetPartner( *this );
       
   204         
       
   205             // Holds selected wlan Ssid
       
   206             HBufC8* ssid = selectedWlan->GetSsidAsUtf8LC(); 
       
   207         
       
   208             // Holds current wlan array 
       
   209             if ( !iInfoArray )
       
   210                 {
       
   211                 iInfoArray = iModel->GetWlanListL();
       
   212                 iInfoArray->SortArrayL( *iWlanInfoBranding );
       
   213                 }
       
   214             //Set array and Ssid to detail view
       
   215             iDetailsView->SetWlanListL( iInfoArray, *ssid );
       
   216         
       
   217             CleanupStack::PopAndDestroy( ssid );        
       
   218             
       
   219             iAppUi->ActivateDetailsViewL( iModel->ActiveViewL() );
       
   220             }
       
   221         }
       
   222     }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // TWsfMainController::MainViewCreatedL
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void TWsfMainController::MainViewCreatedL()
       
   229     {
       
   230     LOG_ENTERFN( "TWsfMainController::MainViewCreatedL" );
       
   231     iMainView = &( iAppUi->MainView() ); 
       
   232     iMainView->SetPartner( *this );
       
   233     iModel->SetActiveViewL( EMainViewId );
       
   234     
       
   235     if ( !iModel->Refreshing() )
       
   236             { 
       
   237             iModel->SetRefreshState( ETrue );               
       
   238             }
       
   239      }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // TWsfMainController::WlanListChangedL
       
   243 // ---------------------------------------------------------------------------
       
   244 //  
       
   245 void TWsfMainController::WlanListChangedL()
       
   246     {
       
   247     LOG_ENTERFN( "TWsfMainController::WlanListChangedL" ); 
       
   248     
       
   249     if ( iModel->IsConnecting() )
       
   250         {
       
   251         LOG_WRITE( "We are connecting just return from here" );
       
   252         return;
       
   253         }
       
   254     
       
   255     if ( iModel->Refreshing() )
       
   256         {          
       
   257         iModel->SetRefreshState( EFalse );
       
   258         if ( iAppUi )
       
   259             {            
       
   260             iAppUi->HideWaitNoteL();
       
   261             iInfoArray = iModel->GetWlanListL();
       
   262             if ( !iInfoArray->Count() )
       
   263                 {        
       
   264                 iAppUi->ShowNoWlansFoundInfoL();       
       
   265                 }
       
   266             UpdateViewL();        
       
   267             }
       
   268         }
       
   269     }
       
   270     
       
   271 // ---------------------------------------------------------------------------
       
   272 // TWsfMainController::NotifyEngineError
       
   273 // ---------------------------------------------------------------------------
       
   274 //  
       
   275 void TWsfMainController::NotifyEngineError( TInt aError )
       
   276     {
       
   277     LOG_ENTERFN( "TWsfMainController::NotifyEngineError" );
       
   278     switch ( aError )
       
   279         {
       
   280         case KErrServerTerminated:
       
   281             {
       
   282             break;
       
   283             }
       
   284             
       
   285         default:
       
   286             {
       
   287             TRAP_IGNORE( iAppUi->ShowGlobalErrorNoteL( aError ) );
       
   288             }
       
   289         }
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // TWsfMainController::ScanDisabledL
       
   294 // ---------------------------------------------------------------------------
       
   295 //          
       
   296 void TWsfMainController::ScanDisabledL()
       
   297     {
       
   298     // no implementation required
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // TWsfMainController::ScanEnabledL
       
   303 // ---------------------------------------------------------------------------
       
   304 //  
       
   305 void TWsfMainController::ScanEnabledL()
       
   306     {
       
   307     // no implementation required
       
   308     }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // TWsfMainController::WlanConnectionActivatedL
       
   312 // ---------------------------------------------------------------------------
       
   313 // 
       
   314 void TWsfMainController::WlanConnectionActivatedL( 
       
   315                                                 const TDesC& aAccessPointName )
       
   316     {
       
   317     LOG_ENTERFN( "TWsfMainController::WlanConnectionActivatedL" ); 
       
   318     
       
   319     // update the model and refresh ui
       
   320     if ( iInfoArray )
       
   321         {
       
   322         TBool found = EFalse; 
       
   323         TWsfWlanInfo info;
       
   324         iModel->GetConnectedWlanDetailsL( info );
       
   325         if ( info.iIapId )
       
   326             {
       
   327             // find the entry for iapid
       
   328             // mark it connected - sort the array and refresh
       
   329             TWsfWlanInfo* temp = iInfoArray->Match( info.iIapId, 
       
   330                                                     iInfoArray->Count() );
       
   331             if ( temp )
       
   332                {
       
   333                found = ETrue;
       
   334                temp->iConnectionState = EConnected;
       
   335                iInfoArray->SortArrayL();
       
   336                UpdateViewL( iInfoArray );
       
   337                }
       
   338             }
       
   339 
       
   340         if ( !found )
       
   341             {
       
   342             // find the entry for aAccessPointName
       
   343             // mark it connected - sort the array and refresh
       
   344             TBuf8<KWlanMaxSsidLength> ssid;
       
   345             CnvUtfConverter::ConvertFromUnicodeToUtf8( ssid, aAccessPointName );
       
   346             
       
   347             TWsfWlanInfo* temp = iInfoArray->Match( ssid, iInfoArray->Count() );
       
   348             if ( temp )
       
   349                 {
       
   350                 temp->iConnectionState = EConnected;
       
   351                 iInfoArray->SortArrayL();
       
   352                 UpdateViewL( iInfoArray );
       
   353                 }
       
   354             }
       
   355         }
       
   356 
       
   357     //Update icon
       
   358     iModel->RefreshScanL();   
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // TWsfMainController::WlanConnectionClosedL
       
   363 // ---------------------------------------------------------------------------
       
   364 //         
       
   365 void TWsfMainController::WlanConnectionClosedL()
       
   366     {
       
   367     LOG_ENTERFN( "TWsfMainController::WlanConnectionClosedL" ); 
       
   368     // update the model and refresh ui
       
   369     if ( iInfoArray )
       
   370         {
       
   371         // check if the array has any items
       
   372         if ( iInfoArray->Count() )
       
   373             {
       
   374             TWsfWlanInfo* firstItem = iInfoArray->At( 0 );
       
   375             if ( firstItem && firstItem->Connected() )
       
   376                 {
       
   377                 firstItem->iConnectionState = ENotConnected;
       
   378                 TRAPD( error, iModel->CheckIsIapIdValidL( firstItem->iIapId ) );
       
   379                 if ( error )
       
   380                     {
       
   381                     LOG_WRITEF( "Iap Id is not valid - error=%d", error );
       
   382                     if ( firstItem->iRawSsid.Length() )
       
   383                         {
       
   384                         firstItem->iSsid.Copy( firstItem->iRawSsid );
       
   385                         }
       
   386                     firstItem->iIapId = 0;
       
   387                     }
       
   388                 iInfoArray->SortArrayL();
       
   389                 UpdateViewL( iInfoArray );                    
       
   390                 }
       
   391             }
       
   392         }
       
   393 
       
   394     // Abort current scan if exists so that we get 
       
   395     // newest scan results propagated to ui
       
   396     iModel->AbortScanningL();
       
   397     iModel->RefreshScanL();     
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // TWsfMainController::ConnectingFinishedL
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 void TWsfMainController::ConnectionCreationProcessFinishedL( TInt /*aResult*/ )
       
   405     {
       
   406     // no implementation required
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------------------------
       
   410 // TWsfMainController::ShowMenuBarL
       
   411 // ---------------------------------------------------------------------------
       
   412 //
       
   413 void TWsfMainController::ShowMenuBarL()
       
   414     {
       
   415     LOG_ENTERFN( "TWsfMainController::ShowMenuBarL" ); 
       
   416     iAppUi->ShowMenuBarL();
       
   417     }
       
   418     
       
   419 // --------------------------- Events from the details view ------------------
       
   420     
       
   421 // ---------------------------------------------------------------------------
       
   422 // TWsfMainController::CloseDetailsViewL
       
   423 // ---------------------------------------------------------------------------
       
   424 //    
       
   425 void TWsfMainController::CloseDetailsViewL()
       
   426     {
       
   427     LOG_ENTERFN( "TWsfMainController::CloseDetailsViewL" ); 
       
   428     ShowWlanListL();
       
   429     // After the Details View closed the mainview's 
       
   430     // WlanList will be refreshed.
       
   431     iModel->RefreshScanL();
       
   432     }
       
   433 
       
   434 // ------------------------------- Menu press handler ------------------------
       
   435 
       
   436 
       
   437 // ----------------------------------------------------------------------------
       
   438 // TWsfMainController::StartBrowsingL
       
   439 // ----------------------------------------------------------------------------
       
   440 //
       
   441 void TWsfMainController::StartBrowsingL()
       
   442     {
       
   443     LOG_ENTERFN( "TWsfMainController::StartBrowsingL" ); 
       
   444     if ( iAppUi->SuppressingKeyEvents() || iModel->IsConnectedL() && 
       
   445              ( !iMainView->SelectedItem() || 
       
   446                !iMainView->SelectedItem()->Connected() ) )
       
   447         {
       
   448         iAppUi->ShowErrorNoteL( R_QTN_WLAN_INFO_CONNECTION_ALREADY_ACTIVE );
       
   449         return;
       
   450         }
       
   451     
       
   452     // make sure we don't suppress our key events forever
       
   453     CleanupStack::PushL( TCleanupItem( ReleaseSuppressingKeyEvents, this ) );
       
   454     iAppUi->SetSuppressingKeyEvents( ETrue );
       
   455     
       
   456     TWsfWlanInfo* selectedItem = iMainView->SelectedItem();
       
   457     TWsfWlanInfo info;
       
   458 
       
   459     if ( selectedItem )
       
   460         {
       
   461         info = *selectedItem;
       
   462         }
       
   463     
       
   464     // Prevent connections to ad-hoc + WPA 
       
   465     if ( info.iNetMode == CMManager::EAdhoc 
       
   466             && info.iSecurityMode == CMManager::EWlanSecModeWpa )
       
   467         {
       
   468         iAppUi->ShowGlobalErrorNoteL( KErrNotSupported );
       
   469         return;
       
   470         }
       
   471 
       
   472     TInt result( KErrNone );
       
   473     
       
   474     if ( !info.Known() && !info.Connected() )
       
   475         {
       
   476         // if not known yet, create an IAP
       
   477         if ( iModel->CreateAccessPointL( info, EFalse ) )
       
   478             {
       
   479             // update iapID to list
       
   480             UpdateIapIdToInfoArray( info );
       
   481             
       
   482             // on success, test it and save it as well
       
   483             result = iModel->TestAccessPointL( info, ETrue, EFalse );
       
   484             }
       
   485         else
       
   486             {
       
   487             result = KErrGeneral;
       
   488             }
       
   489         }
       
   490     else if ( info.iIapId && !info.Connected() )
       
   491         {
       
   492         // hopefully we have a valid IAP id inside
       
   493         result = iModel->ConnectL( info.iIapId );
       
   494         }
       
   495     
       
   496     // pop cleanup item ReleaseSuppressingKeyEvents
       
   497     CleanupStack::Pop();
       
   498     iAppUi->SetSuppressingKeyEvents( EFalse );
       
   499 
       
   500     if ( !result )
       
   501         {
       
   502         TUint32 passedIap( info.iIapId );
       
   503 
       
   504         if ( info.Connected() && !passedIap )
       
   505             {
       
   506             // in case we have an EasyWLAN here
       
   507             RCmManagerExt cmmanager;
       
   508             cmmanager.OpenLC();
       
   509 
       
   510             passedIap = cmmanager.EasyWlanIdL();
       
   511             
       
   512             CleanupStack::PopAndDestroy( &cmmanager );
       
   513             }
       
   514         
       
   515         // launch the browser
       
   516         iModel->LaunchBrowserL( passedIap );
       
   517         }
       
   518     else if ( result == KErrCancel )
       
   519         {
       
   520         // connection creation was cancelled, refresh the view
       
   521         iModel->RefreshScanL();
       
   522         }
       
   523     
       
   524     }
       
   525 
       
   526     
       
   527 // ----------------------------------------------------------------------------
       
   528 // TWsfMainController::ConnectL
       
   529 // ----------------------------------------------------------------------------
       
   530 //
       
   531 void TWsfMainController::ConnectL()
       
   532     {
       
   533     LOG_ENTERFN( "TWsfMainController::ConnectL" ); 
       
   534     if ( iAppUi->SuppressingKeyEvents() || iModel->IsConnectedL() )
       
   535         {
       
   536         iAppUi->ShowErrorNoteL( R_QTN_WLAN_INFO_CONNECTION_ALREADY_ACTIVE );
       
   537         return;
       
   538         }
       
   539     
       
   540     // make sure we don't suppress our key events forever
       
   541     CleanupStack::PushL( TCleanupItem( ReleaseSuppressingKeyEvents, this ) );
       
   542     iAppUi->SetSuppressingKeyEvents( ETrue );
       
   543     
       
   544     TWsfWlanInfo* selectedItem = iMainView->SelectedItem();
       
   545     TWsfWlanInfo info;
       
   546 
       
   547     if ( selectedItem )
       
   548         {
       
   549         info = *selectedItem;
       
   550         }
       
   551     
       
   552     // Prevent connections to ad-hoc + WPA 
       
   553     if ( info.iNetMode == CMManager::EAdhoc 
       
   554             && info.iSecurityMode == CMManager::EWlanSecModeWpa )
       
   555         {
       
   556         iAppUi->ShowGlobalErrorNoteL( KErrNotSupported );
       
   557         return;
       
   558         }
       
   559         
       
   560     if ( !info.Known() )
       
   561         {
       
   562         // a new access point needs to be created
       
   563         if ( iModel->CreateAccessPointL( info, EFalse ) )
       
   564             {
       
   565             // update iapID to list
       
   566             UpdateIapIdToInfoArray( info );
       
   567 
       
   568             // on success, test it and save it as well
       
   569             // (testing actually creates the connection)
       
   570             if ( iModel->TestAccessPointL( info, ETrue, ETrue ) == KErrCancel )
       
   571                 {
       
   572                 // connection creation was cancelled, refresh the view
       
   573                 iModel->RefreshScanL();
       
   574                 }
       
   575             }
       
   576         }
       
   577     else if ( info.iIapId )
       
   578         {
       
   579         // hopefully we have a valid IAP id inside
       
   580         iModel->ConnectL( info.iIapId );
       
   581         }
       
   582 
       
   583     // pop cleanup item ReleaseSuppressingKeyEvents
       
   584     CleanupStack::Pop();
       
   585     iAppUi->SetSuppressingKeyEvents( EFalse );  
       
   586 
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------------------------
       
   590 // TWsfMainController::UpdateIapIdToInfoArray
       
   591 // ---------------------------------------------------------------------------
       
   592 //
       
   593 void TWsfMainController::UpdateIapIdToInfoArray( TWsfWlanInfo& aInfo )
       
   594     {
       
   595     LOG_ENTERFN( "TWsfMainController::UpdateIapIdToInfoArray" ); 
       
   596     TWsfWlanInfo* temp = iInfoArray->Match( aInfo.iSsid, iInfoArray->Count() );
       
   597     if ( temp && !aInfo.Hidden() )
       
   598         {
       
   599         LOG_WRITE( "Info found" );
       
   600         
       
   601         // Check that there aren't any IAPs with same id
       
   602         TWsfWlanInfo* wlanInfoWithSameIapId = iInfoArray->Match( aInfo.iIapId, 
       
   603                                                 iInfoArray->Count() );
       
   604         if ( wlanInfoWithSameIapId )
       
   605             {
       
   606             // info with same id found set its iap id to zero
       
   607             LOG_WRITE( "info with same id found" );
       
   608             wlanInfoWithSameIapId->iIapId = 0;
       
   609             }
       
   610         
       
   611         temp->iIapId = aInfo.iIapId;
       
   612         
       
   613         if ( aInfo.iNetworkName.Length() )
       
   614             {
       
   615             // Replace ssid as well since scanner does this same thing
       
   616             temp->iSsid.Copy( aInfo.iNetworkName );
       
   617             }
       
   618         }
       
   619     else
       
   620         {
       
   621         LOG_WRITE( "Info not found" );
       
   622         TWsfWlanInfo* createdInfo = new (ELeave) TWsfWlanInfo( aInfo );
       
   623         createdInfo->iVisibility = ETrue;
       
   624         createdInfo->iStrengthLevel = EWlanSignalStrengthMax;
       
   625         iInfoArray->AppendL( createdInfo );
       
   626         }
       
   627     }
       
   628     
       
   629 // ---------------------------------------------------------------------------
       
   630 // TWsfMainController::DisconnectL
       
   631 // ---------------------------------------------------------------------------
       
   632 //
       
   633 void TWsfMainController::DisconnectL()
       
   634     {
       
   635     LOG_ENTERFN( "TWsfMainController::DisconnectL" ); 
       
   636     if ( iModel->IsConnecting() )
       
   637         {
       
   638         LOG_WRITE( "Abort connecting" );
       
   639         iModel->AbortConnectingL();
       
   640         }
       
   641     else
       
   642         {
       
   643         LOG_WRITE( "Disconnect" );
       
   644         iModel->DisconnectL();
       
   645         }
       
   646     }
       
   647 
       
   648 // ---------------------------------------------------------------------------
       
   649 // TWsfMainController::RefreshL
       
   650 // ---------------------------------------------------------------------------
       
   651 //
       
   652 void TWsfMainController::RefreshL()
       
   653     {
       
   654     LOG_ENTERFN( "TWsfMainController::RefreshL" ); 
       
   655     TBool refreshing = iModel->RefreshScanL();
       
   656     if ( refreshing )
       
   657         {    
       
   658         iAppUi->StartWaitNoteL( ETrue );
       
   659         }
       
   660     }
       
   661 
       
   662 // ---------------------------------------------------------------------------
       
   663 // TWsfMainController::ContinueBrowsingL
       
   664 // ---------------------------------------------------------------------------
       
   665 //        
       
   666 void TWsfMainController::ContinueBrowsingL()
       
   667     {
       
   668     LOG_ENTERFN( "TWsfMainController::ContinueBrowsingL" ); 
       
   669     // pass selected WLAN info to engine
       
   670     TWsfWlanInfo *selectedItem = iMainView->SelectedItem();
       
   671 
       
   672     if ( selectedItem )
       
   673         {
       
   674         // Prevent connections to ad-hoc + WPA 
       
   675         if ( selectedItem->iNetMode == CMManager::EAdhoc 
       
   676                 && selectedItem->iSecurityMode == CMManager::EWlanSecModeWpa )
       
   677             {
       
   678             iAppUi->ShowGlobalErrorNoteL( KErrNotSupported );
       
   679             return;
       
   680             }
       
   681         
       
   682         TUint iapId = selectedItem->iIapId;
       
   683         iModel->ContinueBrowsingL( iapId );
       
   684         }
       
   685     }
       
   686 
       
   687 // ---------------------------------------------------------------------------
       
   688 // TWsfMainController::EngineRefreshing
       
   689 // ---------------------------------------------------------------------------
       
   690 //     
       
   691 TBool TWsfMainController::EngineRefreshing()
       
   692     {
       
   693     LOG_ENTERFN( "TWsfMainController::EngineRefreshing" );
       
   694     _ASSERTD( iModel );    
       
   695     return iModel->Refreshing();
       
   696     }
       
   697     
       
   698 // ---------------------------------------------------------------------------
       
   699 // TWsfMainController::AppLaunchCompleteL
       
   700 // ---------------------------------------------------------------------------
       
   701 // 
       
   702 void TWsfMainController::AppLaunchCompleteL()
       
   703     {
       
   704     LOG_ENTERFN( "TWsfMainController::AppLaunchCompleteL" ); 
       
   705     iAppUi->StartWaitNoteL( EFalse );
       
   706     iModel->EnableScanL();
       
   707     }
       
   708 
       
   709 // ---------------------------------------------------------------------------
       
   710 // TWsfMainController::AppSwitchedForegroundL
       
   711 // ---------------------------------------------------------------------------
       
   712 // 
       
   713 void TWsfMainController::AppSwitchedForegroundL()
       
   714     {
       
   715     LOG_ENTERFN( "TWsfMainController::AppSwitchedForegroundL" ); 
       
   716 
       
   717     //turn on scanning for our point of view
       
   718     iModel->EnableScanL();
       
   719 
       
   720     if ( !iModel->IsConnecting() )
       
   721         {
       
   722         LOG_WRITE( "Scan now" ); 
       
   723         TBool scan = iModel->RefreshScanL();
       
   724         if( !scan )
       
   725             {
       
   726             LOG_WRITE( "Set refresh state to true" );
       
   727             //if the refresh call was called when the server was
       
   728             //actually making a scan then the refresh state of the
       
   729             //model is turned to false, but in this case the scanning
       
   730             //wait note will stuck on the screen, That's why the
       
   731             //refresh state must be turned to true
       
   732             iModel->SetRefreshState( ETrue );
       
   733             }
       
   734         }
       
   735     }
       
   736 
       
   737 // ---------------------------------------------------------------------------
       
   738 // TWsfMainController::AppSwitchedBackgroundL
       
   739 // ---------------------------------------------------------------------------
       
   740 // 
       
   741 void TWsfMainController::AppSwitchedBackgroundL()
       
   742     {
       
   743     LOG_ENTERFN( "TWsfMainController::AppSwitchedBackgroundL" ); 
       
   744     iModel->DisableScanL();
       
   745     }
       
   746 
       
   747 
       
   748 // ---------------------------------------------------------------------------
       
   749 // TWsfMainController::BrowserLaunchCompleteL
       
   750 // ---------------------------------------------------------------------------
       
   751 // 
       
   752 void TWsfMainController::BrowserLaunchCompleteL()
       
   753     {
       
   754     LOG_ENTERFN( "TWsfMainController::BrowserLaunchCompleteL" );
       
   755     // no implementation required
       
   756     }
       
   757 
       
   758 
       
   759 // ---------------------------------------------------------------------------
       
   760 // TWsfMainController::BrowserExitL
       
   761 // ---------------------------------------------------------------------------
       
   762 // 
       
   763 void TWsfMainController::BrowserExitL()
       
   764     {
       
   765     LOG_ENTERFN( "TWsfMainController::BrowserExitL" ); 
       
   766     iModel->AbortScanningL();
       
   767     iModel->RefreshScanL();
       
   768     }
       
   769 
       
   770 
       
   771 // ---------------------------------------------------------------------------
       
   772 // TWsfMainController::BrowserLaunchFailed
       
   773 // ---------------------------------------------------------------------------
       
   774 //
       
   775 void  TWsfMainController::BrowserLaunchFailed( TInt aError )
       
   776     {
       
   777     LOG_ENTERFN( "TWsfMainController::BrowserLaunchFailed" ); 
       
   778     LOG_WRITEF( "error = %d", aError );
       
   779     switch ( aError )
       
   780         {
       
   781         case KErrCancel:
       
   782             {
       
   783             // user pressed cancel to connection creation
       
   784             break;
       
   785             }
       
   786         
       
   787         default:
       
   788             {
       
   789             break;
       
   790             }
       
   791         }
       
   792     }
       
   793 
       
   794 // ---------------------------------------------------------------------------
       
   795 // TWsfMainController::ConnectingL
       
   796 // ---------------------------------------------------------------------------
       
   797 //
       
   798 void TWsfMainController::ConnectingL( TUint32 aIapId )
       
   799     {
       
   800     LOG_ENTERFN( "TWsfMainController::ConnectingL" ); 
       
   801     iModel->SetConnecting( ETrue );
       
   802     
       
   803     // update the model and refresh ui
       
   804     if ( iInfoArray )
       
   805         {
       
   806         LOG_WRITEF( "Match array with iapID = %d", aIapId );
       
   807         // find the entry for aIapId
       
   808         // mark it connecting - sort the array and refresh
       
   809         TWsfWlanInfo* temp = iInfoArray->Match( aIapId, iInfoArray->Count() );
       
   810         if ( temp )
       
   811             {
       
   812             LOG_WRITEF( "Info found iapID = %d", aIapId );
       
   813             temp->iConnectionState = EConnecting;
       
   814             iInfoArray->SortArrayL();
       
   815             UpdateViewL( iInfoArray );
       
   816             }
       
   817         }
       
   818     }
       
   819 
       
   820 
       
   821 // ---------------------------------------------------------------------------
       
   822 // TWsfMainController::ConnectingFinishedL
       
   823 // ---------------------------------------------------------------------------
       
   824 //
       
   825 void TWsfMainController::ConnectingFinishedL( TInt aResult )
       
   826     {
       
   827     LOG_ENTERFN( "TWsfMainController::ConnectingFinishedL" ); 
       
   828     if ( iModel->IsConnecting() )
       
   829         {
       
   830         iModel->SetConnecting( EFalse );
       
   831         iModel->SetRefreshState( ETrue );
       
   832         iAppUi->HideWaitNoteL();
       
   833         }
       
   834     
       
   835     if ( aResult != KErrNone && aResult != KErrCancel )
       
   836         {
       
   837         LOG_WRITEF( "Connection failed with error=%d", aResult );
       
   838         if ( iInfoArray && iInfoArray->Count() && 
       
   839                 iInfoArray->At(0)->iConnectionState == EConnecting )
       
   840             {
       
   841             iInfoArray->At(0)->iConnectionState = ENotConnected;
       
   842             TRAPD( error, iModel->CheckIsIapIdValidL( 
       
   843                                                 iInfoArray->At(0)->iIapId ) );
       
   844             if ( error )
       
   845                 {
       
   846                 LOG_WRITEF( "Iap Id %d is not valid - error=%d", 
       
   847                             iInfoArray->At(0)->iIapId, error );
       
   848                 
       
   849                 if ( iInfoArray->At(0)->iRawSsid.Length() )
       
   850                     {
       
   851                     iInfoArray->At(0)->iSsid.Copy( 
       
   852                                                 iInfoArray->At(0)->iRawSsid );
       
   853                     }
       
   854                 
       
   855                 iInfoArray->At(0)->iIapId = 0;
       
   856                 }
       
   857             iInfoArray->SortArrayL();
       
   858             UpdateViewL( iInfoArray );
       
   859             iModel->AbortScanningL();
       
   860             iModel->RefreshScanL();
       
   861             }
       
   862         }
       
   863     }
       
   864 
       
   865     
       
   866 // ---------------------------------------------------------------------------
       
   867 // TWsfMainController::EditBlackListItemsL
       
   868 // ---------------------------------------------------------------------------
       
   869 //
       
   870 void TWsfMainController::EditBlackListItemsL()
       
   871     {
       
   872     LOG_ENTERFN( "TWsfMainController::EditBlackListItemsL" ); 
       
   873     _ASSERTD( iWlanInfoBranding );
       
   874     iWlanInfoBranding->EditBlackListL( *iInfoArray );
       
   875     iModel->RefreshScanL();    
       
   876     }
       
   877 
       
   878 // ---------------------------------------------------------------------------
       
   879 // TWsfMainController::DetailsScanL
       
   880 // ---------------------------------------------------------------------------
       
   881 //    
       
   882 void TWsfMainController::DetailsScanL()
       
   883     {
       
   884     LOG_ENTERFN( "TWsfMainController::DetailsScanL" ); 
       
   885     iModel->RefreshScanL();
       
   886     }    
       
   887 
       
   888 // ---------------------------------------------------------------------------
       
   889 // TWsfMainController::ReleaseSuppressingKeyEvents
       
   890 // ---------------------------------------------------------------------------
       
   891 //
       
   892 void TWsfMainController::ReleaseSuppressingKeyEvents( TAny* aPtr )
       
   893     {
       
   894     TWsfMainController* self = 
       
   895                         static_cast<TWsfMainController*>( aPtr );
       
   896     self->iAppUi->SetSuppressingKeyEvents( EFalse );
       
   897     self->iModel->SetConnecting( EFalse );
       
   898     TRAP_IGNORE( self->iModel->RefreshScanL() );
       
   899     }
       
   900       
       
   901 // End of file