wlanutilities/wlansniffer/mainapplication/src/wsfmainviewcontroller.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 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     iModel->FormatWlanListL( aWlanList );
       
    68     CDesCArray* formattedList = iModel->GetWlanList();
       
    69 
       
    70     if ( iContainer )
       
    71         {        
       
    72         // If some WLAN was already selected, don't lose the focus
       
    73         // By default show the first item (index == 0)
       
    74         TInt index = 0;
       
    75         TWsfWlanInfo* wlanInfo = aWlanList->Match( iModel->SelectedWlan(),
       
    76                                                    aWlanList->Count() );
       
    77         if ( wlanInfo )
       
    78             {            
       
    79             index = aWlanList->GetArrayIndex( wlanInfo );
       
    80             }
       
    81         iContainer->UpdateHotSpotsL( formattedList, index );
       
    82         } 
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // TWsfMainViewController::UpdateNaviPaneL
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void TWsfMainViewController::UpdateNaviPaneL()
       
    91     {
       
    92     LOG_ENTERFN( "TWsfMainViewController::UpdateNaviPaneL" );   
       
    93     HBufC* naviText = iModel->FormatNaviPaneLC();
       
    94     iContainer->UpdateNaviPaneL( *naviText );
       
    95     CleanupStack::PopAndDestroy( naviText );   
       
    96     }
       
    97 
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // TWsfMainViewController::UpdateWlanListL
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void TWsfMainViewController::UpdateWlanListL( CWsfWlanInfoArray* aWlanArray )
       
   104     {
       
   105     LOG_ENTERFN( "TWsfMainViewController::UpdateWlanListL" );   
       
   106     UpdateHotSpotsL( aWlanArray );
       
   107     UpdateNaviPaneL();
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // TWsfMainViewController::UpdateWlanListInBackgroundL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void TWsfMainViewController::UpdateWlanListInBackgroundL(
       
   115         CWsfWlanInfoArray* aWlanArray )
       
   116     {
       
   117     LOG_ENTERFN( "TWsfMainViewController::UpdateWlanListInBackgroundL" );   
       
   118     iModel->FormatWlanListL( aWlanArray );
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // TWsfMainViewController::RefreshL
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void TWsfMainViewController::RefreshL()
       
   126     {
       
   127     LOG_ENTERFN( "TWsfMainViewController::RefreshL" );   
       
   128     CDesCArray* formattedList =  iModel->GetWlanList();
       
   129     iContainer->UpdateHotSpotsL( formattedList, iModel->SelectedIndex() );  
       
   130     UpdateNaviPaneL();      
       
   131     }
       
   132 
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // TWsfMainViewController::SelectedItem
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 TWsfWlanInfo* TWsfMainViewController::SelectedItem()
       
   139     {
       
   140     LOG_ENTERFN( "TWsfMainViewController::SelectedItem" );
       
   141     
       
   142     return iValidItem? &iSelectedItem: NULL; 
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // TWsfMainViewController::SetPartner
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void TWsfMainViewController::SetPartner( MWsfMainViewPartner& aPartner )
       
   151     {
       
   152     iPartner = &aPartner;
       
   153     }
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // TWsfMainViewController::UpdateSelectedItemL
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void TWsfMainViewController::UpdateSelectedItemL()
       
   161     {
       
   162     LOG_ENTERFN( "TWsfMainViewController::UpdateSelectedItemL" );   
       
   163 
       
   164     _ASSERTD( iModel && iContainer );
       
   165     
       
   166     TInt selectedItem = iContainer->SelectedItem();
       
   167     CWsfWlanInfoArray* array = iModel->GetInfoArray();
       
   168     if ( array )
       
   169         {
       
   170         TWsfWlanInfo* item = NULL;
       
   171         if ( selectedItem < array->Count() )
       
   172             {
       
   173             item = array->At( selectedItem );
       
   174             }
       
   175         
       
   176         if ( item )
       
   177             {
       
   178             iSelectedItem = *item;
       
   179             iValidItem = ETrue;
       
   180             }
       
   181         else
       
   182             {
       
   183             iValidItem = EFalse;
       
   184             }
       
   185         }
       
   186     
       
   187     // Store name of focused WLAN
       
   188     if ( iValidItem )
       
   189         {        
       
   190         HBufC8* ssid = iSelectedItem.GetSsidAsUtf8LC();
       
   191         iModel->SetSelectedWlan( ssid );
       
   192         CleanupStack::Pop( ssid );
       
   193         }
       
   194     
       
   195     }
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // TWsfMainViewController::HandleUpKeyPressedL
       
   200 // ---------------------------------------------------------------------------
       
   201 //    
       
   202 void TWsfMainViewController::HandleUpKeyPressedL()
       
   203     {
       
   204     LOG_ENTERFN( "TWsfMainViewController::HandleUpKeyPressedL" );   
       
   205     _ASSERTD( iModel );
       
   206     
       
   207     // Store just listbox index. Needed
       
   208     iModel->SetSelectedIndex( iContainer->SelectedItem() );    
       
   209     }
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // TWsfMainViewController::HandleDownKeyPressedL
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void TWsfMainViewController::HandleDownKeyPressedL()
       
   217     {
       
   218     LOG_ENTERFN( "TWsfMainViewController::HandleDownKeyPressedL" );   
       
   219     _ASSERTD( iModel );
       
   220 
       
   221     iModel->SetSelectedIndex( iContainer->SelectedItem() );
       
   222     }
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // TWsfMainViewController::HandleSelectionKeyPressedL
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void TWsfMainViewController::HandleSelectionKeyPressedL()
       
   230     {
       
   231     LOG_ENTERFN( "TWsfMainViewController::HandleSelectionKeyPressedL" );   
       
   232     _ASSERTD( iPartner );    
       
   233 
       
   234     iPartner->ShowMenuBarL();
       
   235     }
       
   236 
       
   237 // End of file
       
   238