wlanutilities/wlansniffer/mainapplication/src/wsfmainviewcontroller.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 TWsfMainViewController.
       
    15 *
       
    16 */
       
    17 
       
    18 //  INTERNAL INCLUDES
       
    19 #include "wsfmainviewcontroller.h"
       
    20 #include "wsfmainviewmodel.h"
       
    21 #include "wsfmainviewcontainer.h"
       
    22 #include "wsfwlaninfo.h"
       
    23 #include "wsfwlaninfoarray.h"
       
    24 
       
    25 #include "wsflogger.h"
       
    26 
       
    27 
       
    28 //  LOCAL DEFINITIONS
       
    29 #ifdef _DEBUG
       
    30     _LIT( KMainViewControllerPanic, "TWsfMainViewController"  );
       
    31     #define _ASSERTD( cond ) __ASSERT_DEBUG( (cond), \
       
    32             User::Panic( KMainViewControllerPanic, __LINE__) )
       
    33 #else
       
    34     #define _ASSERTD( cond ) {}
       
    35 #endif //_DEBUG
       
    36 
       
    37     
       
    38 // ---------------------------------------------------------------------------
       
    39 // TWsfMainViewController::SetModel
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 void TWsfMainViewController::SetModel( CWsfMainViewModel* aModel )
       
    43     {
       
    44     iModel = aModel;
       
    45     iValidItem = EFalse;
       
    46     }
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // TWsfMainViewController::SetContainer
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 void TWsfMainViewController::SetContainer( CWsfMainViewContainer* aContainer )
       
    54     {
       
    55     iContainer = aContainer;
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // TWsfMainViewController::UpdateHotSpotsL
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void TWsfMainViewController::UpdateHotSpotsL( CWsfWlanInfoArray* aWlanList )
       
    64     {
       
    65     LOG_ENTERFN( "TWsfMainViewController::UpdateHotSpotsL" );   
       
    66     // Format WLAN list which was passed as a parameter
       
    67     CDesCArray* formattedList = iModel->FormatWlanListL( aWlanList );
       
    68 
       
    69     if ( iContainer )
       
    70         {        
       
    71         // If some WLAN was already selected, don't lose the focus
       
    72         // By default show the first item (index == 0)
       
    73         TInt index = 0;
       
    74         TWsfWlanInfo* wlanInfo = aWlanList->Match( iModel->SelectedWlan(),
       
    75                                                    aWlanList->Count() );
       
    76         if ( wlanInfo )
       
    77             {            
       
    78             index = aWlanList->GetArrayIndex( wlanInfo );
       
    79             }
       
    80         iContainer->UpdateHotSpotsL( formattedList, index );
       
    81         } 
       
    82     }
       
    83 
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // TWsfMainViewController::UpdateNaviPaneL
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void TWsfMainViewController::UpdateNaviPaneL()
       
    90     {
       
    91     LOG_ENTERFN( "TWsfMainViewController::UpdateNaviPaneL" );   
       
    92     HBufC* naviText = iModel->FormatNaviPaneLC();
       
    93     iContainer->UpdateNaviPaneL( *naviText );
       
    94     CleanupStack::PopAndDestroy( naviText );   
       
    95     }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // TWsfMainViewController::UpdateWlanListL
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void TWsfMainViewController::UpdateWlanListL( CWsfWlanInfoArray* aWlanArray )
       
   103     {
       
   104     LOG_ENTERFN( "TWsfMainViewController::UpdateWlanListL" );   
       
   105     UpdateHotSpotsL( aWlanArray );
       
   106     UpdateNaviPaneL();
       
   107     }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // TWsfMainViewController::RefreshL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void TWsfMainViewController::RefreshL()
       
   115     {
       
   116     LOG_ENTERFN( "TWsfMainViewController::RefreshL" );   
       
   117     CDesCArray* formattedList =  iModel->GetWlanList();
       
   118     iContainer->UpdateHotSpotsL( formattedList, iModel->SelectedIndex() );  
       
   119     UpdateNaviPaneL();      
       
   120     }
       
   121 
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // TWsfMainViewController::SelectedItem
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 TWsfWlanInfo* TWsfMainViewController::SelectedItem()
       
   128     {
       
   129     LOG_ENTERFN( "TWsfMainViewController::SelectedItem" );
       
   130     
       
   131     return iValidItem? &iSelectedItem: NULL; 
       
   132     }
       
   133 
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // TWsfMainViewController::SetPartner
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void TWsfMainViewController::SetPartner( MWsfMainViewPartner& aPartner )
       
   140     {
       
   141     iPartner = &aPartner;
       
   142     }
       
   143 
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // TWsfMainViewController::UpdateSelectedItemL
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void TWsfMainViewController::UpdateSelectedItemL()
       
   150     {
       
   151     LOG_ENTERFN( "TWsfMainViewController::UpdateSelectedItemL" );   
       
   152 
       
   153     _ASSERTD( iModel && iContainer );
       
   154     
       
   155     TInt selectedItem = iContainer->SelectedItem();
       
   156     CWsfWlanInfoArray* array = iModel->GetInfoArray();
       
   157     if ( array )
       
   158         {       
       
   159         TWsfWlanInfo* item = array->At( selectedItem );
       
   160         if ( item )
       
   161             {
       
   162             iSelectedItem = *item;
       
   163             iValidItem = ETrue;
       
   164             }
       
   165         else
       
   166             {
       
   167             iValidItem = EFalse;
       
   168             }
       
   169         }
       
   170     
       
   171     // Store name of focused WLAN
       
   172     if ( iValidItem )
       
   173         {        
       
   174         HBufC8* ssid = iSelectedItem.GetSsidAsUtf8LC();
       
   175         iModel->SetSelectedWlan( ssid );
       
   176         CleanupStack::Pop( ssid );
       
   177         }
       
   178     
       
   179     }
       
   180 
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // TWsfMainViewController::HandleUpKeyPressedL
       
   184 // ---------------------------------------------------------------------------
       
   185 //    
       
   186 void TWsfMainViewController::HandleUpKeyPressedL()
       
   187     {
       
   188     LOG_ENTERFN( "TWsfMainViewController::HandleUpKeyPressedL" );   
       
   189     _ASSERTD( iModel );
       
   190     
       
   191     // Store just listbox index. Needed
       
   192     iModel->SetSelectedIndex( iContainer->SelectedItem() );    
       
   193     }
       
   194 
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // TWsfMainViewController::HandleDownKeyPressedL
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void TWsfMainViewController::HandleDownKeyPressedL()
       
   201     {
       
   202     LOG_ENTERFN( "TWsfMainViewController::HandleDownKeyPressedL" );   
       
   203     _ASSERTD( iModel );
       
   204 
       
   205     iModel->SetSelectedIndex( iContainer->SelectedItem() );
       
   206     }
       
   207 
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // TWsfMainViewController::HandleSelectionKeyPressedL
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void TWsfMainViewController::HandleSelectionKeyPressedL()
       
   214     {
       
   215     LOG_ENTERFN( "TWsfMainViewController::HandleSelectionKeyPressedL" );   
       
   216     _ASSERTD( iPartner );    
       
   217 
       
   218     iPartner->ShowMenuBarL();
       
   219     }
       
   220 
       
   221 // End of file
       
   222