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