wlanutilities/wlansniffer/aiplugin/src/wsfaiview.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 CWsfAiView
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  EXTERNAL INCLUDES
       
    20 #include <AknsUtils.h>
       
    21 #include <AknUtils.h>
       
    22 #include <aknlists.h>
       
    23 #include <eikfrlbd.h>
       
    24 #include <eikclbd.h>
       
    25 #include <wsfaipluginrsc.rsg>
       
    26 #include <eikimage.h>
       
    27 #include <eiklabel.h>
       
    28 #include <gulicon.h>
       
    29 #include <AknIconUtils.h>
       
    30 #include <aknlayoutscalable_avkon.cdl.h>
       
    31 #include <gdi.h>
       
    32 #include <aknlayout.cdl.h>
       
    33 #include <skinlayout.cdl.h>
       
    34 #include <AknBidiTextUtils.h>
       
    35 #include <StringLoader.h>
       
    36 
       
    37 //  INTERNAL INCLUDES
       
    38 #include "wsfaiview.h"
       
    39 #include "wsfaipublishobserver.h"
       
    40 #include "wsflogger.h"
       
    41 
       
    42 //  LOCAL DEFINITIONS
       
    43 // one second in milliseconds
       
    44 LOCAL_D const TInt KDeferredWaitTime = 1000 * 1000;
       
    45 LOCAL_D const TInt KAIPublishIconArrayGranularity = 3;
       
    46 
       
    47 // index value to suppress 1 second refreshing state
       
    48 LOCAL_D const TInt KSuppressRefreshIndex = 1024;
       
    49 
       
    50 
       
    51 // --------------------------------------------------------------------------
       
    52 // CWsfAiView::NewL()
       
    53 // --------------------------------------------------------------------------
       
    54 //
       
    55 CWsfAiView* CWsfAiView::NewL( MWsfAiPublishObserver& aPublishObserver )
       
    56     {
       
    57     CWsfAiView *thisPtr = NewLC( aPublishObserver );
       
    58     CleanupStack::Pop( thisPtr );
       
    59     return thisPtr;
       
    60     }
       
    61 
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CWsfAiView::NewLC()
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 CWsfAiView* CWsfAiView::NewLC( MWsfAiPublishObserver& aPublishObserver )
       
    68     {
       
    69     CWsfAiView *thisPtr = new (ELeave) CWsfAiView( aPublishObserver );
       
    70     CleanupStack::PushL( thisPtr );
       
    71     thisPtr->ConstructL();
       
    72     return thisPtr;
       
    73     }
       
    74 
       
    75 
       
    76 // --------------------------------------------------------------------------
       
    77 // CWsfAiView::~CWsfAiView()
       
    78 // --------------------------------------------------------------------------
       
    79 //
       
    80 CWsfAiView::~CWsfAiView()
       
    81     {
       
    82     delete iPublishIconArray;
       
    83     delete iDeferredUpdateCallBack;
       
    84     delete iTextLabel;
       
    85 
       
    86     if ( iDeferredUpdater )
       
    87         {
       
    88         iDeferredUpdater->Cancel();
       
    89         delete iDeferredUpdater;
       
    90         }
       
    91     
       
    92     if ( iStatusScanningOff )
       
    93         {
       
    94         delete iStatusScanningOff;
       
    95         }
       
    96     if ( iStatusRefreshing )
       
    97         {
       
    98         delete iStatusRefreshing;
       
    99         }
       
   100     if ( iStatusConnecting )
       
   101         {
       
   102         delete iStatusConnecting;
       
   103         }
       
   104     }
       
   105 
       
   106 
       
   107 // --------------------------------------------------------------------------
       
   108 // CWsfAiView::CWsfAiView()
       
   109 // --------------------------------------------------------------------------
       
   110 //
       
   111 CWsfAiView::CWsfAiView( MWsfAiPublishObserver& aPublishObserver ) :
       
   112     iUpdateSecureIconDeferred( ETransparentIcon ),
       
   113     iUpdateSignalStrengthIconDeferred( ETransparentIcon ),
       
   114     iUpdateStatusIconDeferred( ETransparentIcon ),
       
   115     iSavedUpdateStatusIconDeferred( ETransparentIcon ),
       
   116     iPublishObserver( &aPublishObserver )
       
   117     {
       
   118     }
       
   119 
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CWsfAiView::ConstructL()
       
   123 // --------------------------------------------------------------------------
       
   124 //
       
   125 void CWsfAiView::ConstructL()
       
   126     {
       
   127     LOG_ENTERFN( "CWsfAiView::ConstructL" );
       
   128     iEnv = CCoeEnv::Static();
       
   129 
       
   130     iDeferredUpdateCallBack = new ( ELeave )
       
   131         TCallBack( CWsfAiView::DoCompleteUpdateL, this );
       
   132     iDeferredUpdater = CPeriodic::NewL( CActive::EPriorityStandard );
       
   133 
       
   134     iPublishIconArray = new ( ELeave ) CArrayFixFlat<TInt>( 
       
   135                                             KAIPublishIconArrayGranularity );
       
   136 
       
   137     iTextLabel = new (ELeave) CEikLabel;
       
   138     if ( !iStatusScanningOff )
       
   139         {
       
   140         iStatusScanningOff = StringLoader::LoadL( 
       
   141                 R_QTN_SNIFFER_PLUG_IN_SCANNING_OFF );
       
   142         }
       
   143     iTextLabel->SetTextL( *iStatusScanningOff );
       
   144 
       
   145     iUpdateStatusIconDeferred = EWlanOffIcon;
       
   146     }
       
   147 
       
   148 
       
   149 // --------------------------------------------------------------------------
       
   150 // CWsfAiView::UpdateHotSpotsL()
       
   151 // --------------------------------------------------------------------------
       
   152 //
       
   153 void CWsfAiView::UpdateHotSpotsL( MDesCArray* aItemTextArray,
       
   154                                   TInt aCurrentItem )
       
   155     {
       
   156     LOG_ENTERFN( "CWsfAiView::UpdateHotSpotsL" );
       
   157     if ( ParseStringL( aItemTextArray->MdcaPoint( 0 ) ) )
       
   158         {
       
   159         if ( aCurrentItem != KSuppressRefreshIndex )
       
   160             {
       
   161             // init the deferred callback
       
   162             ActivateRefreshTimer();
       
   163             }
       
   164         else
       
   165             {
       
   166             // immediate callback (no Refreshing text)
       
   167             DoCompleteUpdateL();
       
   168             return;
       
   169             }
       
   170         }
       
   171     if ( !iStatusRefreshing )
       
   172         {
       
   173         iStatusRefreshing = StringLoader::LoadL( 
       
   174                 R_QTN_SNIFFER_PLUG_IN_REFRESHING );
       
   175         }
       
   176 
       
   177     if ( !iStatusConnecting )
       
   178         {
       
   179         iStatusConnecting = StringLoader::LoadL( 
       
   180                 R_QTN_SNIFFER_PLUG_IN_CONNECTING );
       
   181         }
       
   182 
       
   183     TInt resultRefreshing = iTextLabel->Text()->Compare( *iStatusRefreshing );
       
   184     TInt resultConnecting = iCurrentText.Compare( *iStatusConnecting );
       
   185     
       
   186     if ( !resultConnecting )
       
   187         {
       
   188         MakeTransparentPublishIconsL();  // all icons transparent
       
   189         }
       
   190     else if ( !resultRefreshing )
       
   191         {
       
   192         iPublishObserver->SetRefreshingL( ETrue );
       
   193         MakeTransparentPublishIconsL();  // all icons transparent
       
   194         }
       
   195     else
       
   196         {
       
   197         MakePublishIconsL(); // icons based on the member info
       
   198         }
       
   199 
       
   200     iPublishObserver->SetScanningState( ETrue );
       
   201     iPublishObserver->PublishContentL( iPublishIconArray, iTextLabel );
       
   202     }
       
   203 
       
   204 
       
   205 // --------------------------------------------------------------------------
       
   206 // CWsfAiView::SelectedItem()
       
   207 // --------------------------------------------------------------------------
       
   208 //
       
   209 TInt CWsfAiView::SelectedItem()
       
   210     {
       
   211     LOG_ENTERFN( "CWsfAiView::SelectedItem" );
       
   212     return 0;
       
   213     }
       
   214 
       
   215 
       
   216 // --------------------------------------------------------------------------
       
   217 // CWsfAiView::ForceRefreshingL()
       
   218 // --------------------------------------------------------------------------
       
   219 //
       
   220 void CWsfAiView::ForceRefreshingL()
       
   221     {
       
   222     LOG_ENTERFN( "CWsfAiView::ForceRefreshingL" );
       
   223     }
       
   224 
       
   225 // --------------------------------------------------------------------------
       
   226 // CWsfAiPlugin::SetRefreshingL
       
   227 // --------------------------------------------------------------------------
       
   228 //
       
   229 void CWsfAiView::StartConnectingAnimationL()
       
   230     {
       
   231     iPublishObserver->StartConnectingL();    
       
   232     }
       
   233 
       
   234 // --------------------------------------------------------------------------
       
   235 // CWsfAiView::MultilineControl
       
   236 // --------------------------------------------------------------------------
       
   237 //
       
   238 TBool CWsfAiView::MultilineControl() 
       
   239     {
       
   240     LOG_ENTERFN( "CWsfAiView::MultilineControl" );
       
   241     return EFalse; 
       
   242     }
       
   243       
       
   244 
       
   245 // --------------------------------------------------------------------------
       
   246 // CWsfAiView::ParseStringL()
       
   247 // --------------------------------------------------------------------------
       
   248 //
       
   249 TBool CWsfAiView::ParseStringL( const TDesC& aString )
       
   250     {
       
   251     LOG_ENTERFN( "CWsfAiView::ParseStringL" );
       
   252     // start looking for '\t' digits and parse 
       
   253     // the icon identifiers and label text
       
   254 
       
   255     // if the data changes - ie - label text has changed 
       
   256     // - launch deferred update...
       
   257     TChar delimiter('\t');
       
   258     TWsfPluginIcons statusIcon;
       
   259     TWsfPluginIcons secureicon;
       
   260     TWsfPluginIcons strengthIcon;
       
   261     TInt firstTabPos = aString.Locate( delimiter );
       
   262     TInt secondTabPos = aString.Mid( 
       
   263                                 firstTabPos +1 ).Locate( 
       
   264                                         delimiter ) + firstTabPos + 1;
       
   265     TInt thirdTabPos = aString.Mid( 
       
   266                                 secondTabPos +1 ).Locate( 
       
   267                                         delimiter ) + secondTabPos + 1;
       
   268 
       
   269     // ok we have the tab positions read the values...
       
   270 
       
   271     TInt secVal = 0;
       
   272     //read the icons
       
   273     TLex( aString.Mid( 0, firstTabPos )).Val( (TInt&)statusIcon );
       
   274     TLex( aString.Mid(
       
   275         secondTabPos+1 , thirdTabPos - (secondTabPos+1) )
       
   276          ).Val( (TInt&) strengthIcon);
       
   277 
       
   278     TLex( aString.Mid(
       
   279         thirdTabPos+1 , aString.Length() - ( thirdTabPos + 1 ) )
       
   280         ).Val( (TInt&) secureicon );
       
   281     
       
   282     secVal = secureicon;
       
   283     HBufC* secureString = NULL;
       
   284 
       
   285     iPublishObserver->SetStrengthAndSecure( NULL, secureString );
       
   286     if ( secVal == ESecureNetworkIcon )
       
   287         {
       
   288         delete secureString;
       
   289         secureString = NULL;
       
   290         }
       
   291 
       
   292     // and the label text
       
   293     TPtrC labelText = aString.Mid( firstTabPos+1, 
       
   294                                    secondTabPos - ( firstTabPos + 1 ) );
       
   295 
       
   296     iCurrentText.Copy( labelText );
       
   297 
       
   298     if ( !iStatusRefreshing )
       
   299         {
       
   300         iStatusRefreshing = StringLoader::LoadL( 
       
   301                 R_QTN_SNIFFER_PLUG_IN_REFRESHING );
       
   302         }
       
   303     iTextLabel->SetTextL( *iStatusRefreshing );
       
   304 
       
   305     iUpdateSecureIconDeferred = secureicon;
       
   306     iUpdateSignalStrengthIconDeferred = strengthIcon;
       
   307     iUpdateStatusIconDeferred = statusIcon;
       
   308     iSavedUpdateStatusIconDeferred = statusIcon;
       
   309         
       
   310     return ETrue;
       
   311     }
       
   312 
       
   313 
       
   314 // --------------------------------------------------------------------------
       
   315 // CWsfAiView::DoCompleteUpdateL()
       
   316 // --------------------------------------------------------------------------
       
   317 //
       
   318 void CWsfAiView::DoCompleteUpdateL()
       
   319     {
       
   320     LOG_ENTERFN( "CWsfAiView::DoCompleteUpdateL" );    
       
   321     // cancel the periodic
       
   322     iDeferredUpdater->Cancel();
       
   323 
       
   324     // update the label text
       
   325     iTextLabel->SetTextL( iCurrentText );
       
   326     iCurrentText = KNullDesC();
       
   327     
       
   328     iUpdateStatusIconDeferred = iSavedUpdateStatusIconDeferred;
       
   329     
       
   330     MakePublishIconsL();
       
   331     iPublishObserver->PublishContentL( iPublishIconArray, iTextLabel );
       
   332     iPublishObserver->SetRefreshingL( EFalse );
       
   333     }
       
   334 
       
   335 
       
   336 // --------------------------------------------------------------------------
       
   337 // CWsfAiView::DoCompleteUpdateL()
       
   338 // --------------------------------------------------------------------------
       
   339 //
       
   340 TInt CWsfAiView::DoCompleteUpdateL( TAny* aPtr )
       
   341     {
       
   342     LOG_ENTERFN( "CWsfAiView::DoCompleteUpdateL" );
       
   343     static_cast<CWsfAiView*>( aPtr )->DoCompleteUpdateL();
       
   344     return ETrue;
       
   345     }
       
   346 
       
   347 
       
   348 // --------------------------------------------------------------------------
       
   349 // CWsfAiView::DisplayEngineOffL()
       
   350 // --------------------------------------------------------------------------
       
   351 //
       
   352 void CWsfAiView::DisplayEngineOffL()
       
   353     {
       
   354     LOG_ENTERFN( "CWsfAiView::DisplayEngineOffL" );
       
   355     iDeferredUpdater->Cancel();
       
   356     iPublishObserver->SetRefreshingL( EFalse );
       
   357     
       
   358     if ( !iStatusScanningOff )
       
   359         {
       
   360         iStatusScanningOff = StringLoader::LoadL( 
       
   361                 R_QTN_SNIFFER_PLUG_IN_SCANNING_OFF );
       
   362         }
       
   363 
       
   364     iTextLabel->SetTextL( *iStatusScanningOff );
       
   365 
       
   366     iUpdateSecureIconDeferred = ETransparentIcon;
       
   367     iUpdateSignalStrengthIconDeferred = ETransparentIcon;
       
   368     iUpdateStatusIconDeferred = EWlanOffIcon;
       
   369     iPublishObserver->SetScanningState( EFalse );
       
   370     MakePublishIconsL();
       
   371     iPublishObserver->PublishContentL( iPublishIconArray, iTextLabel );
       
   372     }
       
   373 
       
   374 
       
   375 // --------------------------------------------------------------------------
       
   376 // CWsfAiView::ActivateRefreshTimer()
       
   377 // --------------------------------------------------------------------------
       
   378 //
       
   379 void CWsfAiView::ActivateRefreshTimer()
       
   380     {
       
   381     LOG_ENTERFN( "CWsfAiView::ActivateRefreshTimer" );
       
   382     iDeferredUpdater->Cancel();
       
   383     iDeferredUpdater->Start(
       
   384         TTimeIntervalMicroSeconds32( KDeferredWaitTime ),
       
   385         TTimeIntervalMicroSeconds32( KDeferredWaitTime ),
       
   386         *iDeferredUpdateCallBack );
       
   387     }
       
   388 
       
   389 
       
   390 // --------------------------------------------------------------------------
       
   391 // CWsfAiView::MakePublishIconsL()
       
   392 // --------------------------------------------------------------------------
       
   393 //
       
   394 void CWsfAiView::MakePublishIconsL()
       
   395     {
       
   396     LOG_ENTERFN( "CWsfAiView::MakePublishIconsL" );
       
   397     if ( iPublishIconArray )
       
   398         {
       
   399         iPublishIconArray->Reset();
       
   400         iPublishIconArray->AppendL( iUpdateStatusIconDeferred );
       
   401         iPublishIconArray->AppendL( iUpdateSecureIconDeferred );
       
   402         iPublishIconArray->AppendL( iUpdateSignalStrengthIconDeferred );
       
   403         }
       
   404 
       
   405     }
       
   406 
       
   407 
       
   408 // --------------------------------------------------------------------------
       
   409 // CWsfAiView::MakeTransparentPublishIconsL()
       
   410 // --------------------------------------------------------------------------
       
   411 //
       
   412 void CWsfAiView::MakeTransparentPublishIconsL()
       
   413     {
       
   414     LOG_ENTERFN( "CWsfAiView::MakeTransparentPublishIconsL" );
       
   415     TWsfPluginIcons tmp2, tmp3;
       
   416 
       
   417     tmp2 = iUpdateSecureIconDeferred;
       
   418     tmp3 = iUpdateSignalStrengthIconDeferred;
       
   419 
       
   420     iUpdateSecureIconDeferred = ETransparentIcon;
       
   421     iUpdateSignalStrengthIconDeferred = ETransparentIcon;
       
   422 
       
   423     MakePublishIconsL();
       
   424 
       
   425     iUpdateSecureIconDeferred = tmp2;
       
   426     iUpdateSignalStrengthIconDeferred = tmp3;
       
   427     }
       
   428 
       
   429 void CWsfAiView::UpdateViewL( MDesCArray* aItemTextArray )
       
   430 	{
       
   431 	LOG_ENTERFN( "CWsfAiView::UpdateViewL" );
       
   432 	TChar delimiter('\t');
       
   433     TWsfPluginIcons statusIcon;
       
   434     TWsfPluginIcons secureicon;
       
   435     TWsfPluginIcons strengthIcon;
       
   436     const TDesC& aString = aItemTextArray->MdcaPoint( 0 ) ;
       
   437     
       
   438     TInt firstTabPos = aString.Locate( delimiter );
       
   439     TInt secondTabPos = aString.Mid( 
       
   440                                 firstTabPos +1 ).Locate( 
       
   441                                         delimiter ) + firstTabPos + 1;
       
   442     TInt thirdTabPos = aString.Mid( 
       
   443                                 secondTabPos +1 ).Locate( 
       
   444                                         delimiter ) + secondTabPos + 1;
       
   445     
       
   446         //read the icons
       
   447     TLex( aString.Mid( 0, firstTabPos )).Val( (TInt&)statusIcon );
       
   448     TLex( aString.Mid(
       
   449         secondTabPos+1 , thirdTabPos - (secondTabPos+1) )
       
   450          ).Val( (TInt&) strengthIcon);
       
   451 
       
   452     TLex( aString.Mid(
       
   453         thirdTabPos+1 , aString.Length() - ( thirdTabPos + 1 ) )
       
   454         ).Val( (TInt&) secureicon );
       
   455             
       
   456     iUpdateStatusIconDeferred = statusIcon;
       
   457     
       
   458     MakeTransparentPublishIconsL();
       
   459     
       
   460 	iPublishObserver->PublishStatusIconL( iPublishIconArray, iTextLabel );
       
   461 	}
       
   462 
       
   463 // END OF FILE