wlanutilities/wlansniffer/mainapplication/src/wsfappui.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 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( *CEikonEnv::Static() );
       
   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::HandleCommandL
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void CWsfAppUi::HandleForegroundEventL( TBool aForeground )
       
   254     {
       
   255     LOG_ENTERFN( "CWsfAppUi::HandleForegroundEventL" );
       
   256     //Application switched to foreground.
       
   257     if ( aForeground )
       
   258         {
       
   259         if ( iObserver )
       
   260             {
       
   261             iObserver->AppSwitchedForegroundL();
       
   262             }
       
   263         }
       
   264     else
       
   265         {
       
   266         if ( iObserver )
       
   267             {            
       
   268             iObserver->AppSwitchedBackgroundL();
       
   269             }
       
   270             
       
   271         }
       
   272         
       
   273     CAknViewAppUi::HandleForegroundEventL( aForeground );
       
   274     }
       
   275 
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // CWsfAppUi::ActivateDetailsViewL
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void CWsfAppUi::ActivateDetailsViewL( TUid aDetailsViewId )
       
   282     {
       
   283     ActivateLocalViewL( aDetailsViewId );
       
   284     LOG_WRITE( "CWsfAppUi::ActivateDetailsViewL" );
       
   285     }
       
   286 
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CWsfAppUi::ActivateMainViewL
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 void CWsfAppUi::ActivateMainViewL()
       
   293     {
       
   294     ActivateLocalViewL( TUid::Uid( EMainViewId ) );
       
   295     LOG_WRITE( "CWsfAppUi::ActivateMainViewL" );    
       
   296     }
       
   297 
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CWsfAppUi::MainView
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 MWsfMainViewControllerIf& CWsfAppUi::MainView()
       
   304     {   
       
   305     CWsfMainView* mainView = static_cast<CWsfMainView*>( 
       
   306                                   View( TUid::Uid( EMainViewId ) ) ); 
       
   307     return mainView->Controller();
       
   308     }
       
   309 
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CWsfAppUi::DetailsView
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 MWsfDetailsViewControllerIf& CWsfAppUi::DetailsView( TInt aDetailsViewType )
       
   316     {
       
   317     CWsfDetailsView* detailsView = static_cast<CWsfDetailsView*>( 
       
   318                                    View( TUid::Uid( aDetailsViewType ) ) ); 
       
   319     return detailsView->Controller();
       
   320     }
       
   321 
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // CWsfAppUi::StartWaitNoteL
       
   325 // ---------------------------------------------------------------------------
       
   326 //
       
   327 void CWsfAppUi::StartWaitNoteL( TBool aVisibilityDelayOff )
       
   328     {
       
   329     LOG_ENTERFN( "CWsfAppUi::StartWaitNoteL" );
       
   330     // wait dialog shown only if engine updating
       
   331     // the wlan list
       
   332     if( iObserver->EngineRefreshing() )
       
   333         {
       
   334         iWaitDialog = new (ELeave) CAknWaitDialog( 
       
   335                               reinterpret_cast<CEikDialog**>( &iWaitDialog ), 
       
   336                               aVisibilityDelayOff );
       
   337         iWaitDialog->SetCallback( this );
       
   338         iWaitDialog->ExecuteLD( R_WAITNOTE_SEARCHING_WLANS );
       
   339         }
       
   340     }
       
   341 
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 // CWsfAppUi::HideWaitNoteL
       
   345 // ---------------------------------------------------------------------------
       
   346 //
       
   347 void CWsfAppUi::HideWaitNoteL()
       
   348     {
       
   349     LOG_ENTERFN( "CWsfAppUi::HideWaitNoteL" );
       
   350     if ( iWaitDialog )
       
   351         {        
       
   352         iWaitDialog->ProcessFinishedL();
       
   353         iWaitDialog = NULL;
       
   354         }
       
   355     }
       
   356 
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 // CWsfAppUi::DialogDismissedL
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CWsfAppUi::DialogDismissedL( TInt aButtonId )
       
   363     {
       
   364     LOG_ENTERFN( "CWsfAppUi::DialogDismissedL" );
       
   365     iWaitDialog = NULL;
       
   366     
       
   367     if ( aButtonId == EEikBidCancel )
       
   368         {
       
   369         // dialog was cancelled by the user
       
   370         
       
   371         if ( Doc()->Model().IsConnecting() )
       
   372             {
       
   373             // connecting wait note was active
       
   374             LOG_WRITE( "cancelling 'connecting' wait note" );
       
   375             Doc()->Model().AbortConnectingL();
       
   376             Doc()->Model().SetConnecting( EFalse );
       
   377             }
       
   378         else
       
   379             {
       
   380             // searching for wlan wait note was active
       
   381             LOG_WRITE( "cancelling 'searching for wlan' wait note" );
       
   382             Doc()->Model().AbortScanningL();
       
   383             Doc()->Model().SetRefreshState( EFalse );
       
   384             }
       
   385         }
       
   386     }
       
   387 
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CWsfAppUi::ShowMenuBarL
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void CWsfAppUi::ShowMenuBarL()
       
   394     {
       
   395     CWsfMainView* mainview = static_cast<CWsfMainView*>( iView );
       
   396     mainview->SelectionKeyPressed();
       
   397     iView->MenuBar()->TryDisplayMenuBarL();
       
   398     }
       
   399     
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CWsfAppUi::ShowNoWlansFoundInfoL
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 void CWsfAppUi::ShowNoWlansFoundInfoL()
       
   406     {
       
   407     LOG_ENTERFN( "CWsfAppUi::ShowNoWlansFoundInfoL" );
       
   408     
       
   409     CConnectionUiUtilities* connUiUtils = CConnectionUiUtilities::NewL();                                
       
   410     connUiUtils->NoWLANNetworksAvailableNote();
       
   411     delete connUiUtils;
       
   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