wlanutilities/wlansniffer/mainapplication/src/wsfmainviewmodel.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 CWsfMainViewModel.
       
    15 *
       
    16 */
       
    17 
       
    18 //  EXTERNAL INCLUDES
       
    19 #include <badesca.h>
       
    20 #include <coemain.h>
       
    21 #include <StringLoader.h>
       
    22 #include <wlansniffer.rsg>
       
    23 
       
    24 //  CLASS HEADER
       
    25 #include "wsfmainviewmodel.h"
       
    26 
       
    27 //  INTERNAL INCLUDES
       
    28 #include "wsfwlaninfo.h"
       
    29 #include "wsfwlaninfoarray.h"
       
    30 #include "wsfmainviewinternals.h"
       
    31 
       
    32 #include "wsflogger.h"
       
    33 
       
    34 
       
    35 //  LOCAL DEFINITIONS
       
    36 
       
    37 // Listbox item format for open networks
       
    38 _LIT( KVisibleItemFormat1Icon, "%d\t%S\t%S\t%d" );
       
    39 
       
    40 // Listbox item format for secured networks
       
    41 _LIT( KVisibleItemFormat2Icons, "%d\t%S\t%S\t%d\t%d" );
       
    42 
       
    43 // Listbox item format for "Other (unlisted)" item
       
    44 _LIT( KHiddenItemFormat, "\t%S" );
       
    45 
       
    46 // Maximal length of listbox item strings
       
    47 const TInt KListBoxItemMaxLength = 128;
       
    48 
       
    49 // Listbox granularity
       
    50 const TUint KWlanListGranularity = 4;
       
    51 
       
    52 
       
    53 
       
    54 //  CONSTRUCTION AND DESTRUCTION
       
    55 // ---------------------------------------------------------------------------
       
    56 // CWsfMainViewModel::NewL
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CWsfMainViewModel* CWsfMainViewModel::NewL()
       
    60     {
       
    61     LOG_ENTERFN( "CWsfMainViewModel::NewL" );
       
    62     CWsfMainViewModel* self = CWsfMainViewModel::NewLC();
       
    63     CleanupStack::Pop( self );
       
    64     return self;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CWsfMainViewModel::NewLC
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CWsfMainViewModel* CWsfMainViewModel::NewLC()
       
    72     {
       
    73     LOG_ENTERFN( "CWsfMainViewModel::NewLC" );
       
    74     CWsfMainViewModel* self = new( ELeave ) CWsfMainViewModel;
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     return self;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CWsfMainViewModel::~CWsfMainViewModel
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CWsfMainViewModel::~CWsfMainViewModel()
       
    85     {
       
    86     LOG_ENTERFN( "CWsfMainViewModel::~CWsfMainViewModel" );
       
    87     delete iFormattedWlanList;
       
    88     delete iSelectedWlan;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CWsfMainViewModel::CWsfMainViewModel
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 CWsfMainViewModel::CWsfMainViewModel(): iCoeEnv( CCoeEnv::Static() )
       
    96     {
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CWsfMainViewModel::ConstructL
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CWsfMainViewModel::ConstructL()
       
   104     {
       
   105     LOG_ENTERFN( "CWsfMainViewModel::ConstructL" );
       
   106     iFormattedWlanList = new (ELeave) CDesCArrayFlat( KWlanListGranularity );
       
   107     iSelectedWlan = KNullDesC8().AllocL();
       
   108     
       
   109     // add the hidden wlan item to the list by default
       
   110     TWsfWlanInfo dummy;
       
   111     HBufC* hidden = HBufC::NewLC( KListBoxItemMaxLength );
       
   112     TPtr ptr( hidden->Des() );
       
   113 
       
   114     FormatHiddenWlanItemL( dummy, ptr );
       
   115     iFormattedWlanList->AppendL( *hidden );
       
   116     
       
   117     CleanupStack::PopAndDestroy( hidden );
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CWsfMainViewModel::GetWlanList
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 CDesCArrayFlat* CWsfMainViewModel::GetWlanList()
       
   125     {
       
   126     return iFormattedWlanList;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CWsfMainViewModel::GetInfoArray
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 CWsfWlanInfoArray* CWsfMainViewModel::GetInfoArray()
       
   134     {
       
   135     return iWlanInfoArray;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CWsfMainViewModel::SetSelectedWlan
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CWsfMainViewModel::SetSelectedWlan( HBufC8* aSsid )
       
   143     {
       
   144     delete iSelectedWlan;
       
   145     iSelectedWlan = aSsid;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CWsfMainViewModel::SelectedWlan
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 const TDesC8& CWsfMainViewModel::SelectedWlan()
       
   153     {
       
   154     return *iSelectedWlan;
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CWsfMainViewModel::SetSelectedIndex
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CWsfMainViewModel::SetSelectedIndex( TInt aIndex )
       
   162     {
       
   163     iListboxIndex = aIndex;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CWsfMainViewModel::SelectedIndex
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 TInt CWsfMainViewModel::SelectedIndex()
       
   171     {
       
   172     return iListboxIndex;
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CWsfMainViewModel::FormatNaviPaneLC
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 HBufC* CWsfMainViewModel::FormatNaviPaneLC()
       
   180     {
       
   181     LOG_ENTERFN( "CWsfMainViewModel::FormatNaviPaneLC" );
       
   182     HBufC* textOfNaviPane = NULL;
       
   183 
       
   184     if ( !iVisibleWlans )
       
   185         {
       
   186         textOfNaviPane =  KNullDesC().AllocLC();
       
   187         }
       
   188 
       
   189     else if ( iVisibleWlans == 1 )
       
   190         {
       
   191         textOfNaviPane = StringLoader::LoadLC(
       
   192             R_QTN_SNIFFER_NAVI_ONE_WLAN_NW_AVAILABLE, iCoeEnv );
       
   193         }
       
   194     else
       
   195         {
       
   196         textOfNaviPane = StringLoader::LoadLC(
       
   197                                 R_QTN_SNIFFER_NAVI_MANY_WLAN_NWS_AVAILABLE, 
       
   198                                 iVisibleWlans, 
       
   199                                 iCoeEnv );
       
   200         }
       
   201     return textOfNaviPane;
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CWsfMainViewModel::FormatWlanListL
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 CDesCArrayFlat* CWsfMainViewModel::FormatWlanListL( 
       
   209                                             CWsfWlanInfoArray* aWlanList )
       
   210     {
       
   211     LOG_ENTERFN( "CWsfMainViewModel::FormatWlanListL" );
       
   212     //Function expects that items in list are already in proper order
       
   213     iVisibleWlans = 0;
       
   214     iWlanInfoArray = aWlanList;
       
   215     iFormattedWlanList->Reset();
       
   216     HBufC* item = HBufC::NewLC( KListBoxItemMaxLength );
       
   217     TPtr ptr( item->Des() );
       
   218     for (TInt i = 0; i < aWlanList->Count(); ++i )
       
   219         {
       
   220         TWsfWlanInfo* wlanInfo = aWlanList->At( i );
       
   221 
       
   222         // Hidden WLAN item is appended later for unknown hidden networks
       
   223         if ( wlanInfo->Hidden() && !wlanInfo->iIapId )
       
   224             {
       
   225             continue;
       
   226             }
       
   227         else
       
   228             {
       
   229             ++iVisibleWlans;
       
   230             }
       
   231 
       
   232         // known hidden wlans are also "visible"
       
   233         ptr.Zero();
       
   234         FormatVisibleWlanItemL( *wlanInfo, ptr );
       
   235         iFormattedWlanList->AppendL( ptr );
       
   236         }
       
   237 
       
   238     // now add "Other (unlisted)..." for hidden networks (always visible)
       
   239     // make up a dummy wlaninfo
       
   240     TWsfWlanInfo dummy;
       
   241     
       
   242     ptr.Zero();
       
   243     FormatHiddenWlanItemL( dummy, ptr );
       
   244     iFormattedWlanList->AppendL( ptr );
       
   245 
       
   246     CleanupStack::PopAndDestroy ( item );
       
   247     return iFormattedWlanList;
       
   248     }
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // CWsfMainViewModel::FormatHiddenWlanItemL
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 void CWsfMainViewModel::FormatHiddenWlanItemL( TWsfWlanInfo& /*aWlan*/, 
       
   255                                                TDes& aItem )
       
   256     {
       
   257     LOG_ENTERFN( "CWsfMainViewModel::FormatHiddenWlanItemL" );
       
   258     HBufC* primaryText = StringLoader::LoadLC( R_QTN_SNIFFER_HIDDEN_WLAN );
       
   259 
       
   260     // Only Hidden WLAN text is shown.
       
   261     // All icons are transparent
       
   262     aItem.Format( KHiddenItemFormat, primaryText );
       
   263 
       
   264     CleanupStack::PopAndDestroy( primaryText );
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CWsfMainViewModel::FormatVisibleWlanItemL
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void CWsfMainViewModel::FormatVisibleWlanItemL( TWsfWlanInfo& aWlan, 
       
   272                                                 TDes& aItem )
       
   273     {
       
   274     LOG_ENTERFN( "CWsfMainViewModel::FormatVisibleWlanItemL" );
       
   275     // Icon in first column is transparent by default
       
   276     // Known / Connected / None
       
   277     TInt column1Icon = KTransparentIcon;   // qgn_transparent.svg
       
   278 
       
   279     if ( aWlan.BrandId() )
       
   280            {
       
   281            column1Icon = KTransparentIcon + aWlan.BrandId();
       
   282            }
       
   283     else if ( aWlan.Connected() )
       
   284         {
       
   285         column1Icon = KConnectedNWIcon;    // qgn_prop_cmon_wlan_conn.svg
       
   286         }
       
   287     else if ( aWlan.Known() )
       
   288         {
       
   289         column1Icon = KKnownNWIcon;        // qgn_prop_wlan_bearer.svg
       
   290         }
       
   291 
       
   292     //Ssid as primary text
       
   293     HBufC* primaryText( NULL );
       
   294     
       
   295     if ( aWlan.iNetworkName.Length() ) // If there is IAP
       
   296         {
       
   297         primaryText = aWlan.GetIapNameAsUnicodeLC();
       
   298         }
       
   299     else // If there no IAP
       
   300         {
       
   301         primaryText = aWlan.GetSsidAsUnicodeLC();
       
   302         }
       
   303 
       
   304     //Secondary Text, "Known" if IAP is already defined. Else "Unknown"
       
   305     TInt resId = R_QTN_SNIFFER_UNKNOWN;
       
   306     if ( aWlan.ConnectionStatus() == EConnected )
       
   307         {
       
   308         resId = R_QTN_SNIFFER_CONNECTED;
       
   309         }
       
   310     else if ( aWlan.ConnectionStatus() == EConnecting ) 
       
   311         {
       
   312         resId = R_QTN_SNIFFER_CONNECTING;
       
   313         }
       
   314     else if ( aWlan.Known() ) 
       
   315         {
       
   316         resId = R_QTN_SNIFFER_KNOWN;
       
   317         }
       
   318 
       
   319     HBufC* secondaryText = StringLoader::LoadLC( resId );
       
   320 
       
   321 
       
   322     //Column 3
       
   323     //Show secure icon if network is secure. By default show transparant icon.
       
   324     TInt column4Icon = aWlan.Secure() ? KSecureNetworkIcon : KTransparentIcon;
       
   325 
       
   326 
       
   327     // Signal strenght for column 4
       
   328     // No signal icon is set by default
       
   329     TInt column3Icon = KNoSignalIcon;    //qgn_transparent.svg
       
   330 
       
   331     switch ( aWlan.SignalStrength() )
       
   332         {
       
   333         case EPoor:
       
   334             {
       
   335             column3Icon = KPoorSignal;      //qgn_indi_wlan_signal_low_add.svg
       
   336             break;
       
   337             }
       
   338         case EAverage:
       
   339             {
       
   340             column3Icon = KAverageSignal;   //qgn_indi_wlan_signal_med_add.svg
       
   341             break;
       
   342             }
       
   343         case EExcelent:
       
   344             {
       
   345             column3Icon = KExcelentSignal;  //qgn_indi_wlan_signal_good_add.svg
       
   346             break;
       
   347             }
       
   348 
       
   349         case ENoSignal:
       
   350         default:
       
   351             {
       
   352             column3Icon = KNoSignalIcon;     //qgn_indi_wlan_signal_no_wlan.svg
       
   353             break;
       
   354             }
       
   355         }
       
   356 
       
   357     if ( column4Icon == KTransparentIcon )
       
   358         {
       
   359         aItem.Format( KVisibleItemFormat1Icon, column1Icon,
       
   360                                         primaryText,
       
   361                                         secondaryText,
       
   362                                         column3Icon );
       
   363         }
       
   364     else
       
   365         {
       
   366         aItem.Format( KVisibleItemFormat2Icons, column1Icon,
       
   367                                         primaryText,
       
   368                                         secondaryText,
       
   369                                         column3Icon,
       
   370                                         column4Icon );
       
   371         }
       
   372 
       
   373     CleanupStack::PopAndDestroy( secondaryText );
       
   374     CleanupStack::PopAndDestroy( primaryText );
       
   375     }
       
   376 
       
   377 // End of file
       
   378