wlanutilities/wlansniffer/mainapplication/src/wsfmainview.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 CWsfMainView.
       
    15 *
       
    16 */
       
    17 
       
    18 //External Includes
       
    19 #include <coemain.h>
       
    20 #include <eikmenub.h>
       
    21 #include <aknViewAppUi.h>
       
    22 #include <wlansniffer.rsg>
       
    23 #include <featmgr.h>
       
    24 #include <rconnmon.h>
       
    25 #include <apgcli.h>
       
    26 
       
    27 //Internal Includes
       
    28 #include "wsfdocument.h"
       
    29 #include "wsfwlaninfoarrayvisitor.h"
       
    30 #include "wsfwlaninfoarray.h"
       
    31 #include "wsfmainview.h"
       
    32 #include "wsfmainviewmodel.h"
       
    33 #include "wsfmainviewcontainer.h"
       
    34 #include "wsfmainapplication.hrh"
       
    35 #include "wsfactivewaiter.h"
       
    36 #include "wsfappui.h"
       
    37 #include "wsfmodel.h"
       
    38 
       
    39 #include "wsflogger.h"
       
    40 
       
    41     
       
    42 // Standard construction sequence
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CWsfMainView::NewL
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CWsfMainView* CWsfMainView::NewL( TBool aIsEmbedded )
       
    49     {
       
    50     LOG_ENTERFN( "CWsfMainView::NewL" );
       
    51     CWsfMainView* self = CWsfMainView::NewLC( aIsEmbedded );
       
    52     CleanupStack::Pop( self );
       
    53     return self;
       
    54     } 
       
    55 
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CWsfMainView::NewLC
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CWsfMainView* CWsfMainView::NewLC( TBool aIsEmbedded )
       
    62     {
       
    63     LOG_ENTERFN( "CWsfMainView::NewLC" );
       
    64     CWsfMainView* self = new ( ELeave ) CWsfMainView;
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL( aIsEmbedded );
       
    67     return self;
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CWsfMainView::CWsfMainView
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CWsfMainView::CWsfMainView(): iBrowserIapId( KErrNotFound )
       
    76     {
       
    77     // no implementation required
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CWsfMainView::~CWsfMainView
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CWsfMainView::~CWsfMainView()
       
    86     {
       
    87     LOG_ENTERFN( "CWsfMainView::~CWsfMainView" );
       
    88     if ( iContainer )
       
    89         {
       
    90         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    91         }
       
    92 
       
    93     delete iContainer;
       
    94     delete iModel;
       
    95     }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CWsfMainView::ConstructL
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void CWsfMainView::ConstructL( TBool aIsEmbedded )
       
   103     {
       
   104     LOG_ENTERFN( "CWsfMainView::ConstructL" );
       
   105     TInt actView( NULL );
       
   106     
       
   107     if ( aIsEmbedded ) // started from CP
       
   108         {
       
   109         actView = R_SNIFFER_CP_MAINVIEW;
       
   110         }
       
   111     else
       
   112         {
       
   113         actView = R_SNIFFER_MAINVIEW;
       
   114         }
       
   115                 
       
   116     BaseConstructL( actView );
       
   117     iModel = CWsfMainViewModel::NewL();
       
   118     iController.SetModel( iModel );    
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CWsfMainView::Id
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TUid CWsfMainView::Id() const
       
   127     {
       
   128     return TUid::Uid( EMainViewId );  
       
   129     }
       
   130 
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CWsfMainView::HandleCommandL
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CWsfMainView::HandleCommandL( TInt aCommand )
       
   137     {
       
   138     switch ( aCommand )
       
   139         {
       
   140         case EAknSoftkeyOk:
       
   141             {
       
   142             break;
       
   143             }
       
   144         case EAknSoftkeyBack:
       
   145             {
       
   146             AppUi()->HandleCommandL( EAknCmdExit );
       
   147             break;
       
   148             }
       
   149         case EAknSoftkeyContextOptions:
       
   150             {
       
   151             LOG_WRITE( "CWsfMainView::HandleCommandL, Options" );
       
   152             MenuBar()->SetMenuTitleResourceId( R_SNIFFER_CONTEXT_MENUBAR );
       
   153             MenuBar()->SetMenuType( CEikMenuBar::EMenuContext );
       
   154             MenuBar()->TryDisplayMenuBarL();
       
   155             MenuBar()->SetMenuTitleResourceId( R_SNIFFER_MENUBAR );
       
   156             MenuBar()->SetMenuType( CEikMenuBar::EMenuOptions ); 
       
   157             break;
       
   158             }
       
   159         default:
       
   160             {
       
   161             AppUi()->HandleCommandL( aCommand );
       
   162             break;
       
   163             }
       
   164         }    
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CWsfMainView::DoActivateL
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CWsfMainView::DoActivateL( const TVwsViewId& /*aPrevViewId*/, 
       
   173                                 TUid /*aCustomMessageId*/, 
       
   174                                 const TDesC8& /*aCustomMessage*/)
       
   175     {
       
   176     LOG_ENTERFN( "CWsfMainView::DoActivateL" );
       
   177     if ( !iContainer )
       
   178         { 
       
   179         iContainer = CWsfMainViewContainer::NewL( ClientRect(), this );
       
   180         // set icons array to list        
       
   181         iContainer->SetMopParent( this );
       
   182         iContainer->SetPartner( iController );
       
   183         iContainer->ListBox()->SetListBoxObserver( this );
       
   184         AppUi()->AddToViewStackL( *this, iContainer );
       
   185         iController.SetContainer( iContainer );        
       
   186         }
       
   187    
       
   188     iContainer->MakeVisible( ETrue );     
       
   189     iController.RefreshL();
       
   190     MenuBar()->SetContextMenuTitleResourceId( R_SNIFFER_CONTEXT_MENUBAR );
       
   191     }
       
   192 
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CWsfMainView::DoDeactivate
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CWsfMainView::DoDeactivate()
       
   199     {
       
   200     LOG_ENTERFN( "CWsfMainView::DoDeactivate" );
       
   201     if ( iContainer )
       
   202         {
       
   203         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   204         iController.SetContainer( NULL );
       
   205         delete iContainer;
       
   206         iContainer = NULL;   
       
   207         }
       
   208     }
       
   209 
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // CWsfMainView::Controller
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 MWsfMainViewControllerIf& CWsfMainView::Controller()
       
   216     {
       
   217     return iController;
       
   218     }
       
   219     
       
   220     
       
   221 // ---------------------------------------------------------------------------
       
   222 // CWsfMainView::DynInitMenuPaneL
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CWsfMainView::DynInitMenuPaneL( TInt aResourceId, 
       
   226                                      CEikMenuPane* aMenuPane )
       
   227     {
       
   228     LOG_ENTERFN( "CWsfMainView::DynInitMenuPaneL" );
       
   229     LOG_WRITEF( "resource id = %d", aResourceId );
       
   230     iController.UpdateSelectedItemL();
       
   231     
       
   232     if ( aResourceId == R_SNIFFER_MENU )
       
   233         {
       
   234         LOG_WRITE( "CWsfMainView::DynInitMenuPaneL, R_SNIFFER_MENU" );
       
   235         const CWsfDocument* doc = static_cast<const CWsfDocument*>( 
       
   236                                                          AppUi()->Document() );
       
   237         TBool blacklistEmpty( !doc->WlanInfoBranding().BlackListItemCount() );
       
   238         TWsfWlanInfo *selectedItem = iController.SelectedItem();
       
   239         CWsfWlanInfoArray *infoArray = iModel->GetInfoArray();
       
   240         
       
   241         TBool connecting( doc->Model().IsConnecting() );
       
   242         
       
   243         if ( !selectedItem )
       
   244             {
       
   245             // no real items available, but hidden item is present
       
   246             aMenuPane->SetItemDimmed( ESnifferCmdStartBrowsing, EFalse );
       
   247             aMenuPane->SetItemDimmed( ESnifferCmdContinueBrowsing, ETrue );
       
   248             aMenuPane->SetItemDimmed( ESnifferCmdConnect, EFalse );
       
   249             aMenuPane->SetItemDimmed( ESnifferCmdDisconnect, ETrue );
       
   250             aMenuPane->SetItemDimmed( ESnifferCmdRefresh, connecting );
       
   251 			 
       
   252             // dim filtering if connecting or there are no WLAN networks 
       
   253 			// in coverage or there is only one network which is connected, 
       
   254 			// and the filtering list does not contain any networks marked
       
   255 			// to be filtered out.
       
   256             aMenuPane->SetItemDimmed( ESnifferCmdFilterWlans, 
       
   257                                       connecting ||
       
   258                                       !infoArray ||
       
   259                                       ( blacklistEmpty && 
       
   260                                         ( !infoArray->Count() || 
       
   261                                           ( infoArray->Count() == 1 && 
       
   262                                           (*infoArray)[0]->Connected() ) ) ) );
       
   263             aMenuPane->SetItemDimmed( ESnifferCmdDetails, ETrue );
       
   264             aMenuPane->SetItemDimmed( ESnifferCmdSettings, connecting );
       
   265             return;
       
   266             }
       
   267 
       
   268         TBool connected( selectedItem->Connected() );
       
   269         TBool connectedAndUsed( EFalse );
       
   270         if ( connected && iBrowserIapId == selectedItem->iIapId )
       
   271             {
       
   272             connectedAndUsed = ETrue;
       
   273             }
       
   274         TBool known( selectedItem->Known() );
       
   275         
       
   276         TBool selectedItemConnecting ( 
       
   277                 selectedItem->ConnectionStatus() == EConnecting );
       
   278         
       
   279         LOG_WRITEF( "connectedAndUsed = %d", connectedAndUsed );
       
   280         LOG_WRITEF( "connected = %d", connected );
       
   281         LOG_WRITEF( "known = %d", known );
       
   282         LOG_WRITEF( "selectedItemConnecting = %d", selectedItemConnecting );
       
   283         LOG_WRITEF( "connecting = %d", connecting );
       
   284         
       
   285         aMenuPane->SetItemDimmed( ESnifferCmdStartBrowsing, 
       
   286                                   connectedAndUsed || selectedItemConnecting );
       
   287         aMenuPane->SetItemDimmed( ESnifferCmdContinueBrowsing, 
       
   288                                   !connectedAndUsed || selectedItemConnecting );
       
   289 
       
   290         aMenuPane->SetItemDimmed( ESnifferCmdConnect, 
       
   291                                   connected || selectedItemConnecting );
       
   292         
       
   293         aMenuPane->SetItemDimmed( ESnifferCmdDisconnect, 
       
   294                                   !connected && !selectedItemConnecting); 
       
   295         
       
   296         aMenuPane->SetItemDimmed( ESnifferCmdRefresh, connecting ); 
       
   297       
       
   298         // dim filtering if connecting or there are no WLAN networks 
       
   299 		// in coverage or there is only one network which is connected, 
       
   300 		// and the filtering list does not contain any networks marked
       
   301 		// to be filtered out.
       
   302         aMenuPane->SetItemDimmed( ESnifferCmdFilterWlans, 
       
   303                                   connecting ||
       
   304                                   !infoArray ||
       
   305                                   ( blacklistEmpty && 
       
   306                                     ( !infoArray->Count() || 
       
   307                                       ( infoArray->Count() == 1 && 
       
   308                                         (*infoArray)[0]->Connected() ) ) ) );
       
   309         
       
   310         aMenuPane->SetItemDimmed( ESnifferCmdDetails, 
       
   311                                   connecting || 
       
   312                                   selectedItem->Hidden() && !known );
       
   313         aMenuPane->SetItemDimmed( ESnifferCmdSettings, connecting );
       
   314         }
       
   315     else if ( aResourceId == R_SNIFFER_CONTEXT_MENU )
       
   316         {
       
   317         LOG_WRITE( "CWsfMainView::DynInitMenuPaneL, R_SNIFFER_CONTEXT_MENU" );
       
   318         TWsfWlanInfo *selectedItem = iController.SelectedItem();
       
   319         
       
   320         // there must be always at least one item: "Other (unlisted)..."
       
   321         TBool connectedAndUsed( EFalse );
       
   322         TBool connected( EFalse );
       
   323         TBool known( EFalse );
       
   324         TBool hidden( ETrue );
       
   325         
       
   326         const CWsfDocument* doc = static_cast<const CWsfDocument*>( 
       
   327                                                          AppUi()->Document() );
       
   328         
       
   329         TBool connecting( doc->Model().IsConnecting() );
       
   330         TBool selectedItemConnecting( EFalse );
       
   331 
       
   332         
       
   333         if ( selectedItem )
       
   334             {
       
   335             // workaround: even if the model reports no elements, we know that
       
   336             // the hidden item must always be there
       
   337             connected = selectedItem->Connected();
       
   338             if ( connected && iBrowserIapId == selectedItem->iIapId )
       
   339                 {
       
   340                 connectedAndUsed = ETrue;
       
   341                 }
       
   342             known = selectedItem->Known();
       
   343             hidden = selectedItem->Hidden();
       
   344             selectedItemConnecting = 
       
   345                     ( selectedItem->ConnectionStatus() == EConnecting );
       
   346             }
       
   347 
       
   348         LOG_WRITEF( "connectedAndUsed = %d", connectedAndUsed );
       
   349         LOG_WRITEF( "connected = %d", connected );
       
   350         LOG_WRITEF( "known = %d", known );
       
   351         LOG_WRITEF( "selectedItemConnecting = %d", selectedItemConnecting );
       
   352         LOG_WRITEF( "connecting = %d", connecting );
       
   353 
       
   354         
       
   355         aMenuPane->SetItemDimmed( ESnifferCmdStartBrowsing, 
       
   356                                   connectedAndUsed || selectedItemConnecting );
       
   357         aMenuPane->SetItemDimmed( ESnifferCmdContinueBrowsing, 
       
   358                                  !connectedAndUsed || selectedItemConnecting );
       
   359 
       
   360         aMenuPane->SetItemDimmed( ESnifferCmdConnect, 
       
   361                                   connected || selectedItemConnecting  );
       
   362         aMenuPane->SetItemDimmed( ESnifferCmdDisconnect, 
       
   363                                   !connected && !selectedItemConnecting );  
       
   364         aMenuPane->SetItemDimmed( ESnifferCmdDetails, 
       
   365                                   connecting || hidden && !known );
       
   366         }
       
   367     }
       
   368 
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // CWsfMainView::HandleListBoxEventL
       
   372 // ---------------------------------------------------------------------------
       
   373 //
       
   374 void CWsfMainView::HandleListBoxEventL( CEikListBox* /*aListBox*/, 
       
   375                                         TListBoxEvent aEventType )
       
   376     {
       
   377     LOG_ENTERFN( "CWsfMainView::HandleListBoxEventL" );
       
   378     LOG_WRITEF( "aEventType = %d", aEventType );
       
   379     switch ( aEventType )
       
   380         {
       
   381         case EEventEnterKeyPressed:
       
   382         case EEventItemSingleClicked: 
       
   383             {
       
   384             HandleCommandL( EAknSoftkeyContextOptions );
       
   385             }
       
   386             break;
       
   387         default:
       
   388             break;
       
   389         }
       
   390     }    
       
   391     
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // CWsfMainView::SelectionKeyPressed
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 void CWsfMainView::SelectionKeyPressed()
       
   398     {
       
   399     iSelectionKey = ETrue;
       
   400     }
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // CWsfMainView::UpdateBrowserUsageInfoL
       
   404 // ---------------------------------------------------------------------------
       
   405 //
       
   406 void CWsfMainView::UpdateBrowserUsageInfoL()
       
   407     {
       
   408     LOG_ENTERFN( "CWsfMainView::UpdateBrowserUsageInfoL" );
       
   409     iBrowserIapId = BrowserIapIdL();
       
   410     }
       
   411 
       
   412     
       
   413 // ---------------------------------------------------------------------------
       
   414 // CWsfMainView::BrowserIapIdL
       
   415 // ---------------------------------------------------------------------------
       
   416 //
       
   417 TInt CWsfMainView::BrowserIapIdL()
       
   418     {
       
   419     LOG_ENTERFN( "CWsfMainView::BrowserIapIdL" );
       
   420     
       
   421     const TInt KBrowserUid = 0x10008D39;
       
   422     TUid id( TUid::Uid( KBrowserUid ) );
       
   423     
       
   424     // Check if the Browser application is already running.
       
   425     TApaTaskList taskList( iEikonEnv->WsSession() );
       
   426     TApaTask task = taskList.FindApp( id );
       
   427     TInt browserIapId( KErrNotFound );
       
   428     
       
   429 #ifndef __WINS__
       
   430 
       
   431     if ( task.Exists() )
       
   432         {
       
   433         LOG_WRITE( "The Browser is running." );
       
   434         // The Browser is already running.
       
   435         TWsfWlanInfo* firstItem = NULL;
       
   436         
       
   437         CWsfWlanInfoArray *infoArray = iModel->GetInfoArray();
       
   438         if ( infoArray )
       
   439             {
       
   440             firstItem = infoArray->At( 0 );
       
   441             }
       
   442         
       
   443         TBool connected( EFalse );
       
   444         if( firstItem )
       
   445             {
       
   446             // first item always holds the connected network
       
   447             connected = firstItem->Connected();
       
   448             }
       
   449         LOG_WRITEF("Selected network Connected? %d", connected);
       
   450 
       
   451         if ( connected )
       
   452             {
       
   453             RConnectionMonitor connectionMonitor;
       
   454             connectionMonitor.ConnectL();
       
   455             CleanupClosePushL( connectionMonitor );
       
   456             // We have to check if the Browser using the selected 
       
   457             // connection.
       
   458             // We have get the connectiond ID first.
       
   459             CWsfActiveWaiter* waiter = CWsfActiveWaiter::NewL();
       
   460             CleanupStack::PushL( waiter );
       
   461             
       
   462             // first call, need to get the connection parameters
       
   463             TUint connectionCount( 0 );
       
   464             
       
   465             connectionMonitor.GetConnectionCount( connectionCount, 
       
   466                                                   waiter->iStatus );
       
   467             waiter->WaitForRequest();
       
   468             
       
   469             // find the connection with WLAN bearer 
       
   470             // that will be the selected WLAN
       
   471             TUint connectionId( 0 );
       
   472             for ( TUint i = 1; i <= connectionCount; ++i )
       
   473                 {
       
   474                 TUint tmpConnectionId( 0 );
       
   475                 TUint subConnectionCount( 0 );
       
   476                 TConnMonBearerType bearerType( EBearerUnknown );
       
   477                 
       
   478                 connectionMonitor.GetConnectionInfo( i, 
       
   479                                                      tmpConnectionId, 
       
   480                                                      subConnectionCount );
       
   481                 connectionMonitor.GetIntAttribute( tmpConnectionId, 
       
   482                                                    0, 
       
   483                                                    KBearer, 
       
   484                                                    ( TInt& )bearerType, 
       
   485                                                    waiter->iStatus );
       
   486                 waiter->WaitForRequest();
       
   487                 if( bearerType == EBearerWLAN )
       
   488                     {
       
   489                     connectionId = tmpConnectionId;
       
   490                     break;
       
   491                     }
       
   492                 }
       
   493             // Now we have the connectiond ID.
       
   494             LOG_WRITEF( "connectionId: %d", connectionId );
       
   495             
       
   496             TConnMonClientEnumBuf clientBuf;
       
   497                 
       
   498             connectionMonitor.GetPckgAttribute( connectionId,
       
   499                                                 0,
       
   500                                                 KClientInfo,
       
   501                                                 clientBuf,
       
   502                                                 waiter->iStatus );
       
   503             waiter->WaitForRequest();
       
   504             TInt count( 0 );
       
   505             if ( !waiter->iStatus.Int() )
       
   506                 {
       
   507                 count = clientBuf().iCount;
       
   508                 }
       
   509 
       
   510             RApaLsSession appSess;
       
   511             TApaAppInfo appInfo;
       
   512 
       
   513             // The connection could be shared by several applications
       
   514             User::LeaveIfError( appSess.Connect() );
       
   515             // No need for CleanupClosePushL(appSess) cause nothing leaves.
       
   516 
       
   517             for ( TInt i = 0; i < count; i++ )
       
   518                 {
       
   519                 appInfo.iCaption.Zero();
       
   520                 TInt result = appSess.GetAppInfo( appInfo, 
       
   521                                                   clientBuf().iUid[i] );
       
   522                 
       
   523                 LOG_WRITEF( "result: %d", result ); 
       
   524                 LOG_WRITEF( "iClientInfo.iUid[i].iUid: %x", 
       
   525                              clientBuf().iUid[i].iUid );
       
   526                 
       
   527                 if ( clientBuf().iUid[i].iUid == KBrowserUid )
       
   528                     {
       
   529                     browserIapId = firstItem->iIapId;
       
   530                     }
       
   531                 }           
       
   532             appSess.Close();
       
   533             
       
   534             CleanupStack::PopAndDestroy( waiter );
       
   535             CleanupStack::PopAndDestroy( &connectionMonitor );
       
   536             }                
       
   537         }
       
   538     else 
       
   539         {
       
   540         LOG_WRITE( "No Browser running." );
       
   541         }
       
   542         
       
   543 #endif // __WINS__
       
   544     
       
   545     LOG_WRITEF( "browserIapId: %d", browserIapId );
       
   546     return browserIapId;
       
   547     }
       
   548 
       
   549 
       
   550 
       
   551 // End of file