wlanutilities/wlansniffer/mainapplication/src/wsfmainviewmodel.cpp
branchRCL_3
changeset 25 f28ada11abbf
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
       
     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 void CWsfMainViewModel::FormatWlanListL( CWsfWlanInfoArray* aWlanList )
       
   209     {
       
   210     LOG_ENTERFN( "CWsfMainViewModel::FormatWlanListL" );
       
   211     //Function expects that items in list are already in proper order
       
   212     iVisibleWlans = 0;
       
   213     iWlanInfoArray = aWlanList;
       
   214     iFormattedWlanList->Reset();
       
   215     HBufC* item = HBufC::NewLC( KListBoxItemMaxLength );
       
   216     TPtr ptr( item->Des() );
       
   217     for (TInt i = 0; i < aWlanList->Count(); ++i )
       
   218         {
       
   219         TWsfWlanInfo* wlanInfo = aWlanList->At( i );
       
   220 
       
   221         // Hidden WLAN item is appended later for unknown hidden networks
       
   222         if ( wlanInfo->Hidden() && !wlanInfo->iIapId )
       
   223             {
       
   224             continue;
       
   225             }
       
   226         else
       
   227             {
       
   228             ++iVisibleWlans;
       
   229             }
       
   230 
       
   231         // known hidden wlans are also "visible"
       
   232         ptr.Zero();
       
   233         FormatVisibleWlanItemL( *wlanInfo, ptr );
       
   234         iFormattedWlanList->AppendL( ptr );
       
   235         }
       
   236 
       
   237     // now add "Other (unlisted)..." for hidden networks (always visible)
       
   238     // make up a dummy wlaninfo
       
   239     TWsfWlanInfo dummy;
       
   240     
       
   241     ptr.Zero();
       
   242     FormatHiddenWlanItemL( dummy, ptr );
       
   243     iFormattedWlanList->AppendL( ptr );
       
   244 
       
   245     CleanupStack::PopAndDestroy ( item );
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CWsfMainViewModel::FormatHiddenWlanItemL
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CWsfMainViewModel::FormatHiddenWlanItemL( TWsfWlanInfo& /*aWlan*/, 
       
   253                                                TDes& aItem )
       
   254     {
       
   255     LOG_ENTERFN( "CWsfMainViewModel::FormatHiddenWlanItemL" );
       
   256     HBufC* primaryText = StringLoader::LoadLC( R_QTN_SNIFFER_HIDDEN_WLAN );
       
   257 
       
   258     // Only Hidden WLAN text is shown.
       
   259     // All icons are transparent
       
   260     aItem.Format( KHiddenItemFormat, primaryText );
       
   261 
       
   262     CleanupStack::PopAndDestroy( primaryText );
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // CWsfMainViewModel::FormatVisibleWlanItemL
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 void CWsfMainViewModel::FormatVisibleWlanItemL( TWsfWlanInfo& aWlan, 
       
   270                                                 TDes& aItem )
       
   271     {
       
   272     LOG_ENTERFN( "CWsfMainViewModel::FormatVisibleWlanItemL" );
       
   273     // Icon in first column is transparent by default
       
   274     // Known / Connected / None
       
   275     TInt column1Icon = KTransparentIcon;   // qgn_transparent.svg
       
   276 
       
   277     if ( aWlan.BrandId() )
       
   278            {
       
   279            column1Icon = KTransparentIcon + aWlan.BrandId();
       
   280            }
       
   281     else if ( aWlan.Connected() )
       
   282         {
       
   283         column1Icon = KConnectedNWIcon;    // qgn_prop_cmon_wlan_conn.svg
       
   284         }
       
   285     else if ( aWlan.Known() )
       
   286         {
       
   287         column1Icon = KKnownNWIcon;        // qgn_prop_wlan_bearer.svg
       
   288         }
       
   289 
       
   290     //Ssid as primary text
       
   291     HBufC* primaryText( NULL );
       
   292     
       
   293     if ( aWlan.iNetworkName.Length() ) // If there is IAP
       
   294         {
       
   295         primaryText = aWlan.GetIapNameAsUnicodeLC();
       
   296         }
       
   297     else // If there no IAP
       
   298         {
       
   299         primaryText = aWlan.GetSsidAsUnicodeLC();
       
   300         }
       
   301 
       
   302     //Secondary Text, "Known" if IAP is already defined. Else "Unknown"
       
   303     TInt resId = R_QTN_SNIFFER_UNKNOWN;
       
   304     if ( aWlan.ConnectionStatus() == EConnected )
       
   305         {
       
   306         resId = R_QTN_SNIFFER_CONNECTED;
       
   307         }
       
   308     else if ( aWlan.ConnectionStatus() == EConnecting ) 
       
   309         {
       
   310         resId = R_QTN_SNIFFER_CONNECTING;
       
   311         }
       
   312     else if ( aWlan.Known() ) 
       
   313         {
       
   314         resId = R_QTN_SNIFFER_KNOWN;
       
   315         }
       
   316 
       
   317     HBufC* secondaryText = StringLoader::LoadLC( resId );
       
   318 
       
   319 
       
   320     //Column 3
       
   321     //Show secure icon if network is secure. By default show transparant icon.
       
   322     TInt column4Icon = aWlan.Secure() ? KSecureNetworkIcon : KTransparentIcon;
       
   323 
       
   324 
       
   325     // Signal strenght for column 4
       
   326     // No signal icon is set by default
       
   327     TInt column3Icon = KNoSignalIcon;    //qgn_transparent.svg
       
   328 
       
   329     switch ( aWlan.SignalStrength() )
       
   330         {
       
   331         case EPoor:
       
   332             {
       
   333             column3Icon = KPoorSignal;      //qgn_indi_wlan_signal_low_add.svg
       
   334             break;
       
   335             }
       
   336         case EAverage:
       
   337             {
       
   338             column3Icon = KAverageSignal;   //qgn_indi_wlan_signal_med_add.svg
       
   339             break;
       
   340             }
       
   341         case EExcelent:
       
   342             {
       
   343             column3Icon = KExcelentSignal;  //qgn_indi_wlan_signal_good_add.svg
       
   344             break;
       
   345             }
       
   346 
       
   347         case ENoSignal:
       
   348         default:
       
   349             {
       
   350             column3Icon = KNoSignalIcon;     //qgn_indi_wlan_signal_no_wlan.svg
       
   351             break;
       
   352             }
       
   353         }
       
   354 
       
   355     if ( column4Icon == KTransparentIcon )
       
   356         {
       
   357         aItem.Format( KVisibleItemFormat1Icon, column1Icon,
       
   358                                         primaryText,
       
   359                                         secondaryText,
       
   360                                         column3Icon );
       
   361         }
       
   362     else
       
   363         {
       
   364         aItem.Format( KVisibleItemFormat2Icons, column1Icon,
       
   365                                         primaryText,
       
   366                                         secondaryText,
       
   367                                         column3Icon,
       
   368                                         column4Icon );
       
   369         }
       
   370 
       
   371     CleanupStack::PopAndDestroy( secondaryText );
       
   372     CleanupStack::PopAndDestroy( primaryText );
       
   373     }
       
   374 
       
   375 // End of file
       
   376