wlanutilities/wlansniffer/mainapplication/src/wsfappui.cpp
branchRCL_3
changeset 24 63be7eb3fc78
parent 23 b852595f5cbe
child 25 f28ada11abbf
equal deleted inserted replaced
23:b852595f5cbe 24:63be7eb3fc78
     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 CWsfAppUi.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <avkon.hrh>
       
    19 #include <aknnotewrappers.h> 
       
    20 #include <eikmenub.h> 
       
    21 #include <hlplch.h>
       
    22 #include <featmgr.h>
       
    23 #include <StringLoader.h>
       
    24 #include <cmmanager.h>
       
    25 #include <cmconnectionmethod.h>
       
    26 #include <centralrepository.h>
       
    27 #include <ErrorUI.h>
       
    28 #include <wlansniffer.rsg>
       
    29 #include <ConnectionUiUtilities.h>
       
    30 
       
    31 #include "wlansettingsui.h"
       
    32 #include "wsfappui.h"
       
    33 #include "wsfmainview.h"
       
    34 #include "wsfdetailsview.h"
       
    35 #include "wsfmainviewcontrollerif.h"
       
    36 #include "wsfdetailsviewcontrollerif.h"
       
    37 #include "wsfmainuiobserver.h"
       
    38 #include "wsfmainapplication.hrh"
       
    39 #include "wsfdocument.h"
       
    40 #include "wsfconnecteddetailsdialog.h"
       
    41 #include "wsfconnecteddetailsmodel.h"
       
    42 #include "wsfmodel.h"
       
    43 #include "wsflogger.h"
       
    44 
       
    45 //  LOCAL DEFINITIONS
       
    46 #ifdef _DEBUG
       
    47     _LIT( KAppUi, "CWsfAppUi" );
       
    48     #define _ASSERTD( cond ) __ASSERT_DEBUG( (cond), \
       
    49             User::Panic( KAppUi, __LINE__) )
       
    50 #else
       
    51     #define _ASSERTD( cond ) {}
       
    52 #endif //_DEBUG
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CWsfAppUi::ConstructL
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 void CWsfAppUi::ConstructL()
       
    59     {
       
    60     LOG_CREATE;
       
    61     LOG_WRITE( "Constructing Wlan Sniffer" );
       
    62     LOG_ENTERFN( "CWsfAppUi::ConstructL" );
       
    63     
       
    64     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
    65     
       
    66     // Initialize feature manager
       
    67     FeatureManager::InitializeLibL();
       
    68     iFeatureManagerInitialized = ETrue;
       
    69     
       
    70     iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
    71     
       
    72     // check if the app. launched in embedded mode
       
    73     TBool isEmbeddedApp = IsEmbedded();
       
    74     LOG_WRITEF( "IsEmbedded(): %d", isEmbeddedApp );
       
    75      
       
    76     //Create mainview
       
    77     LOG_WRITE( "Creating main view" );
       
    78     CWsfMainView* mainView = CWsfMainView::NewLC( isEmbeddedApp );
       
    79     LOG_WRITE( "Adding main view" );    
       
    80     AddViewL( mainView );           // transfer ownership to CAknViewAppUi
       
    81     CleanupStack::Pop( mainView );
       
    82     LOG_WRITE( "main view creating done" );
       
    83     SetDefaultViewL( *mainView );
       
    84     iObserver->MainViewCreatedL();
       
    85 
       
    86     //Create details view (not connected)
       
    87     LOG_WRITE( "Create details view (not connected)" );    
       
    88     CWsfDetailsView* detailsView = CWsfDetailsView::NewLC();    
       
    89     LOG_WRITE( "Adding details view (not connected)" );    
       
    90     AddViewL( detailsView );        // transfer ownership to CAknViewAppUi
       
    91     CleanupStack::Pop( detailsView );
       
    92     LOG_WRITE( "details view (not connected) creating done" );
       
    93     
       
    94     ActivateMainViewL();
       
    95 
       
    96     iIdle->Start( TCallBack( AppLaunchCompleteL, this ) );
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CWsfAppUi::CWsfAppUi
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CWsfAppUi::CWsfAppUi():
       
   105     iConnectedDetailsDialog( NULL ),
       
   106     iForeground( ETrue ),
       
   107     iFeatureManagerInitialized( EFalse )
       
   108     {
       
   109     // no implementation required
       
   110     }
       
   111 
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CWsfAppUi::~CWsfAppUi
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 CWsfAppUi::~CWsfAppUi()
       
   118     {
       
   119     if ( iWaitDialog )
       
   120         {
       
   121         iWaitDialog->SetCallback( NULL );
       
   122         TRAP_IGNORE( iWaitDialog->ProcessFinishedL() );
       
   123         }
       
   124 
       
   125     if ( iFeatureManagerInitialized )
       
   126         {
       
   127         FeatureManager::UnInitializeLib();
       
   128         }
       
   129     
       
   130     delete iIdle;
       
   131     delete iConnectedDetailsDialog;
       
   132     LOG_WRITE( "CWsfAppUi::~CWsfAppUi" );
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CWsfAppUi::HandleCommandL
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CWsfAppUi::HandleCommandL( TInt aCommand )
       
   141     {
       
   142     LOG_ENTERFN( "CWsfAppUi::HandleCommandL" );
       
   143     switch ( aCommand )
       
   144         {
       
   145         case EEikCmdExit:
       
   146         case EAknCmdExit:
       
   147         case EAknSoftkeyExit:
       
   148             {
       
   149             if ( iAppLaunchCompleted )
       
   150                 {
       
   151                 Exit();
       
   152                 }
       
   153             break;
       
   154             }
       
   155 
       
   156         case ESnifferCmdStartBrowsing:
       
   157             {
       
   158             iObserver->StartBrowsingL();
       
   159             break;       
       
   160             }
       
   161 
       
   162         case ESnifferCmdContinueBrowsing:
       
   163             {
       
   164             iObserver->ContinueBrowsingL();
       
   165             break;       
       
   166             }
       
   167 
       
   168         case ESnifferCmdShowWlans:
       
   169             {
       
   170             iObserver->ShowWlanListL();
       
   171             break;       
       
   172             }
       
   173             
       
   174         case ESnifferCmdConnect:
       
   175             {
       
   176             iObserver->ConnectL();
       
   177             break;           
       
   178             }
       
   179         case ESnifferCmdDisconnect:
       
   180             {
       
   181             iObserver->DisconnectL();
       
   182             break;                           
       
   183             }        
       
   184         case ESnifferCmdRefresh:
       
   185             {
       
   186             iObserver->RefreshL();  
       
   187             break;  
       
   188             }
       
   189         case ESnifferCmdDetails:
       
   190             {
       
   191             iObserver->ShowDetailsL();
       
   192             break;    
       
   193             }
       
   194         case ESnifferCmdFilterWlans:
       
   195             {
       
   196             iObserver->EditBlackListItemsL();
       
   197             break;    
       
   198             }
       
   199         case ESnifferCmdSettings:
       
   200             {
       
   201             // launch settings dialog
       
   202             CWlanSettingsUi* wlanSettings = 
       
   203                                  CWlanSettingsUi::NewL( *iEikonEnv );
       
   204             CleanupStack::PushL( wlanSettings );
       
   205             iForeground = EFalse;
       
   206             wlanSettings->RunSettingsL();
       
   207             iForeground = ETrue;
       
   208             CleanupStack::PopAndDestroy( wlanSettings );
       
   209             break;
       
   210             }
       
   211         case EAknCmdHelp:
       
   212             {
       
   213             if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   214                 {
       
   215                 HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), 
       
   216                                                      AppHelpContextL() );
       
   217                 }
       
   218             break;
       
   219             }
       
   220         
       
   221         default:
       
   222             {                             
       
   223             break;
       
   224             }            
       
   225         }
       
   226     }
       
   227 
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // CWsfAppUi::SetUiObserver
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 void CWsfAppUi::SetUiObserver( MWsfMainUiObserver* aObserver )
       
   234     {
       
   235     iObserver = aObserver;
       
   236     }
       
   237 
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CWsfAppUi::HandleResourceChangeL
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CWsfAppUi::HandleResourceChangeL( TInt aType )
       
   244     {
       
   245     CAknAppUi::HandleResourceChangeL( aType );
       
   246     }
       
   247 
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // CWsfAppUi::HandleForegroundEventL
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void CWsfAppUi::HandleForegroundEventL( TBool aForeground )
       
   254     {
       
   255     LOG_ENTERFN( "CWsfAppUi::HandleForegroundEventL" );
       
   256     //Application switched to foreground.
       
   257     if ( aForeground )
       
   258         {
       
   259         CWsfMainView* mainView = static_cast<CWsfMainView*>( 
       
   260                                             View( TUid::Uid( EMainViewId ) ) );
       
   261         if ( mainView )
       
   262             {
       
   263             TRAPD( err, mainView->UpdateBrowserUsageInfoL() );
       
   264             if ( err )
       
   265                 {
       
   266                 LOG_WRITEF( "Browser iap usage update failed - err=%d", err );
       
   267                 }
       
   268             }
       
   269     
       
   270         if ( iObserver )
       
   271             {
       
   272             iObserver->AppSwitchedForegroundL();
       
   273             }
       
   274         }
       
   275     else
       
   276         {
       
   277         if ( iObserver )
       
   278             {            
       
   279             iObserver->AppSwitchedBackgroundL();
       
   280             }
       
   281             
       
   282         }
       
   283         
       
   284     CAknViewAppUi::HandleForegroundEventL( aForeground );
       
   285     }
       
   286 
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CWsfAppUi::ActivateDetailsViewL
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 void CWsfAppUi::ActivateDetailsViewL( TUid aDetailsViewId )
       
   293     {
       
   294     ActivateLocalViewL( aDetailsViewId );
       
   295     LOG_WRITE( "CWsfAppUi::ActivateDetailsViewL" );
       
   296     }
       
   297 
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CWsfAppUi::ActivateMainViewL
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 void CWsfAppUi::ActivateMainViewL()
       
   304     {
       
   305     ActivateLocalViewL( TUid::Uid( EMainViewId ) );
       
   306     LOG_WRITE( "CWsfAppUi::ActivateMainViewL" );    
       
   307     }
       
   308 
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // CWsfAppUi::MainView
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 MWsfMainViewControllerIf& CWsfAppUi::MainView()
       
   315     {   
       
   316     CWsfMainView* mainView = static_cast<CWsfMainView*>( 
       
   317                                   View( TUid::Uid( EMainViewId ) ) ); 
       
   318     return mainView->Controller();
       
   319     }
       
   320 
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // CWsfAppUi::DetailsView
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 MWsfDetailsViewControllerIf& CWsfAppUi::DetailsView( TInt aDetailsViewType )
       
   327     {
       
   328     CWsfDetailsView* detailsView = static_cast<CWsfDetailsView*>( 
       
   329                                    View( TUid::Uid( aDetailsViewType ) ) ); 
       
   330     return detailsView->Controller();
       
   331     }
       
   332 
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CWsfAppUi::StartWaitNoteL
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 void CWsfAppUi::StartWaitNoteL( TBool aVisibilityDelayOff )
       
   339     {
       
   340     LOG_ENTERFN( "CWsfAppUi::StartWaitNoteL" );
       
   341     // wait dialog shown only if engine updating
       
   342     // the wlan list
       
   343     if( iObserver->EngineRefreshing() )
       
   344         {
       
   345         iWaitDialog = new (ELeave) CAknWaitDialog( 
       
   346                               reinterpret_cast<CEikDialog**>( &iWaitDialog ), 
       
   347                               aVisibilityDelayOff );
       
   348         iWaitDialog->SetCallback( this );
       
   349         iWaitDialog->ExecuteLD( R_WAITNOTE_SEARCHING_WLANS );
       
   350         }
       
   351     }
       
   352 
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // CWsfAppUi::HideWaitNoteL
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 void CWsfAppUi::HideWaitNoteL()
       
   359     {
       
   360     LOG_ENTERFN( "CWsfAppUi::HideWaitNoteL" );
       
   361     if ( iWaitDialog )
       
   362         {        
       
   363         iWaitDialog->ProcessFinishedL();
       
   364         iWaitDialog = NULL;
       
   365         }
       
   366     }
       
   367 
       
   368 
       
   369 // ---------------------------------------------------------------------------
       
   370 // CWsfAppUi::DialogDismissedL
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 void CWsfAppUi::DialogDismissedL( TInt aButtonId )
       
   374     {
       
   375     LOG_ENTERFN( "CWsfAppUi::DialogDismissedL" );
       
   376     iWaitDialog = NULL;
       
   377     
       
   378     if ( aButtonId == EEikBidCancel )
       
   379         {
       
   380         // dialog was cancelled by the user
       
   381         
       
   382         if ( Doc()->Model().IsConnecting() )
       
   383             {
       
   384             // connecting wait note was active
       
   385             LOG_WRITE( "cancelling 'connecting' wait note" );
       
   386             Doc()->Model().AbortConnectingL();
       
   387             Doc()->Model().SetConnecting( EFalse );
       
   388             }
       
   389         else
       
   390             {
       
   391             // searching for wlan wait note was active
       
   392             LOG_WRITE( "cancelling 'searching for wlan' wait note" );
       
   393             Doc()->Model().AbortScanningL();
       
   394             Doc()->Model().SetRefreshState( EFalse );
       
   395             }
       
   396         }
       
   397     }
       
   398 
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // CWsfAppUi::ShowMenuBarL
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 void CWsfAppUi::ShowMenuBarL()
       
   405     {
       
   406     CWsfMainView* mainview = static_cast<CWsfMainView*>( iView );
       
   407     mainview->SelectionKeyPressed();
       
   408     iView->MenuBar()->TryDisplayMenuBarL();
       
   409     }
       
   410     
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // CWsfAppUi::ShowNoWlansFoundInfoL
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 void CWsfAppUi::ShowNoWlansFoundInfoL()
       
   417     {
       
   418     LOG_ENTERFN( "CWsfAppUi::ShowNoWlansFoundInfoL" );
       
   419     
       
   420     CConnectionUiUtilities* connUiUtils = CConnectionUiUtilities::NewL();                                
       
   421     connUiUtils->NoWLANNetworksAvailableNote();
       
   422     delete connUiUtils;
       
   423     }
       
   424     
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // CWsfAppUi::ShowErrorNoteL
       
   428 // ---------------------------------------------------------------------------
       
   429 //
       
   430 void CWsfAppUi::ShowErrorNoteL( TInt aResourceId )
       
   431     {
       
   432     LOG_ENTERFN( "CWsfAppUi::ShowErrorNoteL" );
       
   433     HBufC* txt = StringLoader::LoadLC( aResourceId );
       
   434     
       
   435     CAknErrorNote* errorNote = new (ELeave) CAknErrorNote;
       
   436     errorNote->ExecuteLD( *txt );
       
   437     
       
   438     CleanupStack::PopAndDestroy( txt );
       
   439     }
       
   440 
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 // CWsfAppUi::ShowGlobalErrorNoteL
       
   444 // ---------------------------------------------------------------------------
       
   445 //
       
   446 void CWsfAppUi::ShowGlobalErrorNoteL( TInt aError )
       
   447     {
       
   448     LOG_ENTERFN( "CWsfAppUi::ShowGlobalErrorNoteL" );
       
   449     CErrorUI* errorUi = CErrorUI::NewLC( *CCoeEnv::Static() );
       
   450     errorUi->ShowGlobalErrorNoteL( aError );
       
   451     CleanupStack::PopAndDestroy( errorUi );
       
   452     }
       
   453 
       
   454 
       
   455 // ---------------------------------------------------------------------------
       
   456 // CWsfAppUi::AppLaunchCompleteL
       
   457 // ---------------------------------------------------------------------------
       
   458 //
       
   459 TInt CWsfAppUi::AppLaunchCompleteL( TAny* aObject )
       
   460     {
       
   461     LOG_ENTERFN( "CWsfAppUi::AppLaunchCompleteL" );
       
   462     _ASSERTD( aObject );
       
   463     CWsfAppUi* appUi = static_cast<CWsfAppUi*>( aObject );
       
   464     appUi->iAppLaunchCompleted = ETrue;
       
   465     appUi->StartWaitNoteL( EFalse );
       
   466     return 0;   // Return false (zero) value not be called again. (Stops timer)
       
   467     }
       
   468 
       
   469 
       
   470 // ---------------------------------------------------------------------------
       
   471 // CWsfAppUi::IsEmbedded
       
   472 // ---------------------------------------------------------------------------
       
   473 //
       
   474 TBool CWsfAppUi::IsEmbedded() const
       
   475     {
       
   476     LOG_ENTERFN( "CWsfAppUi::IsEmbedded" );
       
   477     return iEikonEnv->StartedAsServerApp();
       
   478     }    
       
   479     
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // CWsfAppUi::Doc
       
   483 // ---------------------------------------------------------------------------
       
   484 //
       
   485 CWsfDocument* CWsfAppUi::Doc()
       
   486      {
       
   487      return static_cast<CWsfDocument*>( Document() );
       
   488      }
       
   489 
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CWsfAppUi::Foreground
       
   493 // ---------------------------------------------------------------------------
       
   494 //
       
   495 TBool CWsfAppUi::Foreground()
       
   496     {
       
   497     return iForeground;
       
   498     }
       
   499 
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 // CWsfAppUi::StartConnectedDetailsL
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 void CWsfAppUi::StartConnectedDetailsL( CWsfWlanInfoArray* aWlanArray, 
       
   506                                         const TDesC8& aSelectedWlanSsid )
       
   507     {
       
   508     LOG_ENTERFN( "CWsfAppUi::StartConnectedDetailsL" );
       
   509     CWsfConnectedDetailsModel* model = CWsfConnectedDetailsModel::NewLC();
       
   510     iConnectedDetailsDialog = CWsfConnectedDetailsDialog::NewL();
       
   511     iConnectedDetailsDialog->SetListModel(model);
       
   512     iConnectedDetailsDialog->Controller().SetWlanListL( aWlanArray, 
       
   513                                                         aSelectedWlanSsid );
       
   514     iConnectedDetailsDialog->ExecuteLD( R_QTN_CONNECTED_DETAILS_DIALOG );
       
   515     iConnectedDetailsDialog = NULL;
       
   516     CleanupStack::PopAndDestroy(model);
       
   517     }
       
   518     
       
   519     
       
   520 // ---------------------------------------------------------------------------
       
   521 // CWsfAppUi::UpdateConnectedDetailsL
       
   522 // ---------------------------------------------------------------------------
       
   523 //
       
   524 void CWsfAppUi::UpdateConnectedDetailsL( CWsfWlanInfoArray* aWlanArray )
       
   525     {
       
   526     LOG_ENTERFN( "CWsfAppUi::UpdateConnectedDetailsL" );
       
   527     if ( iConnectedDetailsDialog != NULL )
       
   528         {
       
   529         iConnectedDetailsDialog->Controller().WlanListChangedL( aWlanArray );
       
   530         }
       
   531     }    
       
   532 
       
   533 
       
   534 // ---------------------------------------------------------------------------
       
   535 // CWsfAppUi::SuppressingKeyEvents
       
   536 // ---------------------------------------------------------------------------
       
   537 //
       
   538 TBool CWsfAppUi::SuppressingKeyEvents() const
       
   539     {
       
   540     return iSuppressingKeyEvents;
       
   541     }
       
   542 
       
   543 
       
   544 // ---------------------------------------------------------------------------
       
   545 // CWsfAppUi::SetSuppressingKeyEvents
       
   546 // ---------------------------------------------------------------------------
       
   547 //
       
   548 void CWsfAppUi::SetSuppressingKeyEvents( TBool aSuppressing )
       
   549     {
       
   550     iSuppressingKeyEvents = aSuppressing;
       
   551     }
       
   552 
       
   553 // End of file