wlanutilities/wlansniffer/aiplugin/src/wsfaiview.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 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 
       
   202     TRAPD( error, 
       
   203            iPublishObserver->PublishContentL( iPublishIconArray, iTextLabel ) );
       
   204     if ( error )
       
   205         {
       
   206         LOG_WRITEF( "Publish failed - %d error ignored", error );
       
   207         }
       
   208     }
       
   209 
       
   210 
       
   211 // --------------------------------------------------------------------------
       
   212 // CWsfAiView::SelectedItem()
       
   213 // --------------------------------------------------------------------------
       
   214 //
       
   215 TInt CWsfAiView::SelectedItem()
       
   216     {
       
   217     LOG_ENTERFN( "CWsfAiView::SelectedItem" );
       
   218     return 0;
       
   219     }
       
   220 
       
   221 
       
   222 // --------------------------------------------------------------------------
       
   223 // CWsfAiView::ForceRefreshingL()
       
   224 // --------------------------------------------------------------------------
       
   225 //
       
   226 void CWsfAiView::ForceRefreshingL()
       
   227     {
       
   228     LOG_ENTERFN( "CWsfAiView::ForceRefreshingL" );
       
   229     }
       
   230 
       
   231 
       
   232 // --------------------------------------------------------------------------
       
   233 // CWsfAiPlugin::SetRefreshingL
       
   234 // --------------------------------------------------------------------------
       
   235 //
       
   236 void CWsfAiView::StartConnectingAnimationL()
       
   237     {
       
   238     LOG_ENTERFN( "CWsfAiView::StartConnectingAnimationL" );
       
   239     iPublishObserver->StartConnectingL();    
       
   240     }
       
   241 
       
   242 
       
   243 // --------------------------------------------------------------------------
       
   244 // CWsfAiView::MultilineControl
       
   245 // --------------------------------------------------------------------------
       
   246 //
       
   247 TBool CWsfAiView::MultilineControl() 
       
   248     {
       
   249     LOG_ENTERFN( "CWsfAiView::MultilineControl" );
       
   250     return EFalse; 
       
   251     }
       
   252       
       
   253 
       
   254 // --------------------------------------------------------------------------
       
   255 // CWsfAiView::ParseStringL()
       
   256 // --------------------------------------------------------------------------
       
   257 //
       
   258 TBool CWsfAiView::ParseStringL( const TDesC& aString )
       
   259     {
       
   260     LOG_ENTERFN( "CWsfAiView::ParseStringL" );
       
   261     // start looking for '\t' digits and parse 
       
   262     // the icon identifiers and label text
       
   263 
       
   264     // if the data changes - ie - label text has changed 
       
   265     // - launch deferred update...
       
   266     TChar delimiter('\t');
       
   267     TWsfPluginIcons statusIcon;
       
   268     TWsfPluginIcons secureicon;
       
   269     TWsfPluginIcons strengthIcon;
       
   270     TInt firstTabPos = aString.Locate( delimiter );
       
   271     TInt secondTabPos = aString.Mid( 
       
   272                                 firstTabPos +1 ).Locate( 
       
   273                                         delimiter ) + firstTabPos + 1;
       
   274     TInt thirdTabPos = aString.Mid( 
       
   275                                 secondTabPos +1 ).Locate( 
       
   276                                         delimiter ) + secondTabPos + 1;
       
   277 
       
   278     // ok we have the tab positions read the values...
       
   279     //read the icons
       
   280     TLex( aString.Mid( 0, firstTabPos )).Val( (TInt&)statusIcon );
       
   281     TLex( aString.Mid(
       
   282         secondTabPos+1 , thirdTabPos - (secondTabPos+1) )
       
   283          ).Val( (TInt&) strengthIcon);
       
   284 
       
   285     TLex( aString.Mid(
       
   286         thirdTabPos+1 , aString.Length() - ( thirdTabPos + 1 ) )
       
   287         ).Val( (TInt&) secureicon );
       
   288 
       
   289     // and the label text
       
   290     TPtrC labelText = aString.Mid( firstTabPos+1, 
       
   291                                    secondTabPos - ( firstTabPos + 1 ) );
       
   292 
       
   293     iCurrentText.Copy( labelText );
       
   294 
       
   295     if ( !iStatusRefreshing )
       
   296         {
       
   297         iStatusRefreshing = StringLoader::LoadL( 
       
   298                 R_QTN_SNIFFER_PLUG_IN_REFRESHING );
       
   299         }
       
   300     iTextLabel->SetTextL( *iStatusRefreshing );
       
   301 
       
   302     iUpdateSecureIconDeferred = secureicon;
       
   303     iUpdateSignalStrengthIconDeferred = strengthIcon;
       
   304     iUpdateStatusIconDeferred = statusIcon;
       
   305     iSavedUpdateStatusIconDeferred = statusIcon;
       
   306         
       
   307     return ETrue;
       
   308     }
       
   309 
       
   310 
       
   311 // --------------------------------------------------------------------------
       
   312 // CWsfAiView::DoCompleteUpdateL()
       
   313 // --------------------------------------------------------------------------
       
   314 //
       
   315 void CWsfAiView::DoCompleteUpdateL()
       
   316     {
       
   317     LOG_ENTERFN( "CWsfAiView::DoCompleteUpdateL" );    
       
   318     // cancel the periodic
       
   319     iDeferredUpdater->Cancel();
       
   320 
       
   321     // update the label text
       
   322     iTextLabel->SetTextL( iCurrentText );
       
   323     iCurrentText = KNullDesC();
       
   324     
       
   325     iUpdateStatusIconDeferred = iSavedUpdateStatusIconDeferred;
       
   326     
       
   327     MakePublishIconsL();
       
   328     
       
   329     TRAPD( error, 
       
   330            iPublishObserver->PublishContentL( iPublishIconArray, iTextLabel ) );
       
   331     if ( error )
       
   332         {
       
   333         LOG_WRITEF( "Publish failed - %d error ignored", error );
       
   334         }
       
   335     
       
   336     iPublishObserver->SetRefreshingL( EFalse );
       
   337     }
       
   338 
       
   339 
       
   340 // --------------------------------------------------------------------------
       
   341 // CWsfAiView::DoCompleteUpdateL()
       
   342 // --------------------------------------------------------------------------
       
   343 //
       
   344 TInt CWsfAiView::DoCompleteUpdateL( TAny* aPtr )
       
   345     {
       
   346     LOG_ENTERFN( "CWsfAiView::DoCompleteUpdateL" );
       
   347     static_cast<CWsfAiView*>( aPtr )->DoCompleteUpdateL();
       
   348     return ETrue;
       
   349     }
       
   350 
       
   351 
       
   352 // --------------------------------------------------------------------------
       
   353 // CWsfAiView::DisplayEngineOffL()
       
   354 // --------------------------------------------------------------------------
       
   355 //
       
   356 void CWsfAiView::DisplayEngineOffL()
       
   357     {
       
   358     LOG_ENTERFN( "CWsfAiView::DisplayEngineOffL" );
       
   359     iDeferredUpdater->Cancel();
       
   360     iPublishObserver->SetRefreshingL( EFalse );
       
   361     
       
   362     if ( !iStatusScanningOff )
       
   363         {
       
   364         iStatusScanningOff = StringLoader::LoadL( 
       
   365                 R_QTN_SNIFFER_PLUG_IN_SCANNING_OFF );
       
   366         }
       
   367 
       
   368     iTextLabel->SetTextL( *iStatusScanningOff );
       
   369 
       
   370     iUpdateSecureIconDeferred = ETransparentIcon;
       
   371     iUpdateSignalStrengthIconDeferred = ETransparentIcon;
       
   372     iUpdateStatusIconDeferred = EWlanOffIcon;
       
   373     iPublishObserver->SetScanningState( EFalse );
       
   374     MakePublishIconsL();
       
   375     
       
   376     TRAPD( error, 
       
   377            iPublishObserver->PublishContentL( iPublishIconArray, iTextLabel ) );
       
   378     if ( error )
       
   379         {
       
   380         LOG_WRITEF( "Publish failed - %d error ignored", error );
       
   381         }
       
   382     }
       
   383 
       
   384 
       
   385 // --------------------------------------------------------------------------
       
   386 // CWsfAiView::ActivateRefreshTimer()
       
   387 // --------------------------------------------------------------------------
       
   388 //
       
   389 void CWsfAiView::ActivateRefreshTimer()
       
   390     {
       
   391     LOG_ENTERFN( "CWsfAiView::ActivateRefreshTimer" );
       
   392     iDeferredUpdater->Cancel();
       
   393     iDeferredUpdater->Start(
       
   394         TTimeIntervalMicroSeconds32( KDeferredWaitTime ),
       
   395         TTimeIntervalMicroSeconds32( KDeferredWaitTime ),
       
   396         *iDeferredUpdateCallBack );
       
   397     }
       
   398 
       
   399 
       
   400 // --------------------------------------------------------------------------
       
   401 // CWsfAiView::MakePublishIconsL()
       
   402 // --------------------------------------------------------------------------
       
   403 //
       
   404 void CWsfAiView::MakePublishIconsL()
       
   405     {
       
   406     LOG_ENTERFN( "CWsfAiView::MakePublishIconsL" );
       
   407     if ( iPublishIconArray )
       
   408         {
       
   409         iPublishIconArray->Reset();
       
   410         iPublishIconArray->AppendL( iUpdateStatusIconDeferred );
       
   411         iPublishIconArray->AppendL( iUpdateSecureIconDeferred );
       
   412         iPublishIconArray->AppendL( iUpdateSignalStrengthIconDeferred );
       
   413         }
       
   414     }
       
   415 
       
   416 
       
   417 // --------------------------------------------------------------------------
       
   418 // CWsfAiView::MakeTransparentPublishIconsL()
       
   419 // --------------------------------------------------------------------------
       
   420 //
       
   421 void CWsfAiView::MakeTransparentPublishIconsL()
       
   422     {
       
   423     LOG_ENTERFN( "CWsfAiView::MakeTransparentPublishIconsL" );
       
   424     TWsfPluginIcons tmp2, tmp3;
       
   425 
       
   426     tmp2 = iUpdateSecureIconDeferred;
       
   427     tmp3 = iUpdateSignalStrengthIconDeferred;
       
   428 
       
   429     iUpdateSecureIconDeferred = ETransparentIcon;
       
   430     iUpdateSignalStrengthIconDeferred = ETransparentIcon;
       
   431 
       
   432     MakePublishIconsL();
       
   433 
       
   434     iUpdateSecureIconDeferred = tmp2;
       
   435     iUpdateSignalStrengthIconDeferred = tmp3;
       
   436     }
       
   437 
       
   438 
       
   439 // --------------------------------------------------------------------------
       
   440 // CWsfAiView::UpdateViewL()
       
   441 // --------------------------------------------------------------------------
       
   442 //
       
   443 void CWsfAiView::UpdateViewL( MDesCArray* aItemTextArray )
       
   444 	{
       
   445 	LOG_ENTERFN( "CWsfAiView::UpdateViewL" );
       
   446 	TChar delimiter('\t');
       
   447     TWsfPluginIcons statusIcon;
       
   448     TWsfPluginIcons secureicon;
       
   449     TWsfPluginIcons strengthIcon;
       
   450     const TDesC& aString = aItemTextArray->MdcaPoint( 0 ) ;
       
   451     
       
   452     TInt firstTabPos = aString.Locate( delimiter );
       
   453     TInt secondTabPos = aString.Mid( 
       
   454                                 firstTabPos +1 ).Locate( 
       
   455                                         delimiter ) + firstTabPos + 1;
       
   456     TInt thirdTabPos = aString.Mid( 
       
   457                                 secondTabPos +1 ).Locate( 
       
   458                                         delimiter ) + secondTabPos + 1;
       
   459     
       
   460         //read the icons
       
   461     TLex( aString.Mid( 0, firstTabPos )).Val( (TInt&)statusIcon );
       
   462     TLex( aString.Mid(
       
   463         secondTabPos+1 , thirdTabPos - (secondTabPos+1) )
       
   464          ).Val( (TInt&) strengthIcon);
       
   465 
       
   466     TLex( aString.Mid(
       
   467         thirdTabPos+1 , aString.Length() - ( thirdTabPos + 1 ) )
       
   468         ).Val( (TInt&) secureicon );
       
   469     
       
   470     // and the label text
       
   471     TPtrC labelText = aString.Mid( firstTabPos+1, 
       
   472                                    secondTabPos - ( firstTabPos + 1 ) );
       
   473     
       
   474     iTextLabel->SetTextL( labelText );
       
   475             
       
   476     iUpdateStatusIconDeferred = statusIcon;
       
   477     
       
   478     MakeTransparentPublishIconsL();
       
   479     
       
   480 	iPublishObserver->PublishStatusIconL( iPublishIconArray, iTextLabel );
       
   481 	}
       
   482 
       
   483 // END OF FILE