wlanutilities/wlansniffer/aiplugin/src/wsfaiplugin.cpp
branchRCL_3
changeset 55 f28ada11abbf
equal deleted inserted replaced
54:63be7eb3fc78 55: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 CWsfAiPlugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  EXTERNAL INCLUDES
       
    21 #include <aicontentobserver.h>
       
    22 #include <aiutility.h>
       
    23 #include <apgcli.h>
       
    24 #include <wsfaipluginrsc.rsg>
       
    25 
       
    26 #include <e32std.h>
       
    27 #include <ecom/ecom.h>
       
    28 #include <ecom/implementationproxy.h>
       
    29 
       
    30 #include <f32file.h>
       
    31 #include <AknsConstants.h>
       
    32 #include <AknUtils.h>
       
    33 #include <StringLoader.h>
       
    34 #include <bautils.h>
       
    35 #include <avkon.rsg>
       
    36 #include <apgtask.h>
       
    37 #include <eiklabel.h>
       
    38 
       
    39 #include <data_caging_path_literals.hrh> // KDC_APP_BITMAP_DIR
       
    40 
       
    41 //  INTERNAL INCLUDES
       
    42 #include "wsfaiplugin.h"
       
    43 #include "wsfaipluginuids.hrh"
       
    44 #include "wsfaiplugincontentmodel.h"
       
    45 #include "wsfaimodel.h"
       
    46 #include "wsfmodel.h"
       
    47 #include "wsfaiview.h"
       
    48 #include "wsficonarraycreator.h"
       
    49 #include "wsfdbobserver.h"
       
    50 #include "wsflogger.h"
       
    51 #include "wsfactivewrappers.h"
       
    52 
       
    53 
       
    54 // define icon id for Navigation Bar icon
       
    55 LOCAL_D const TUid KUidSnifferApp = {0x10281CAA};
       
    56 LOCAL_D const TInt KRefreshStepTime = 200 * 1000;
       
    57 LOCAL_D const TInt KConnectingStepTime = 200 * 1000;
       
    58 
       
    59 
       
    60 
       
    61 // --------------------------------------------------------------------------
       
    62 // CWsfAiPlugin::NewL
       
    63 // --------------------------------------------------------------------------
       
    64 //
       
    65 CWsfAiPlugin* CWsfAiPlugin::NewL()
       
    66     {
       
    67     LOG_ENTERFN( "CWsfAiPlugin::NewL" );
       
    68     CWsfAiPlugin* self = new (ELeave) CWsfAiPlugin;
       
    69 
       
    70     CleanupStack::PushL(self);
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop(self);
       
    73 
       
    74     return self;
       
    75     }
       
    76 
       
    77 
       
    78 // --------------------------------------------------------------------------
       
    79 // CWsfAiPlugin::~CWsfAiPlugin
       
    80 // --------------------------------------------------------------------------
       
    81 //
       
    82 CWsfAiPlugin::~CWsfAiPlugin()
       
    83     {
       
    84     LOG_ENTERFN( "CWsfAiPlugin::~CWsfAiPlugin" );
       
    85     // Cancel periodic animation update
       
    86     if ( iAnimationPeriodic )
       
    87         {
       
    88         LOG_WRITE( "Cancel animation update" );
       
    89         iAnimationPeriodic->Cancel();
       
    90         delete iAnimationPeriodic;
       
    91         iAnimationPeriodic = NULL;
       
    92         }
       
    93     
       
    94     delete iDbObserver;
       
    95     
       
    96     delete iActiveWrappers;
       
    97     
       
    98     delete iModel;
       
    99     delete iAiModel;
       
   100     delete iUi;
       
   101     
       
   102     if ( iMskActivate )
       
   103         {
       
   104         delete iMskActivate;
       
   105         }
       
   106     
       
   107     if ( iConnectedTo )
       
   108         {
       
   109         delete iConnectedTo;
       
   110         }
       
   111     
       
   112     if ( iKnownNetworkFound )
       
   113         {
       
   114         delete iKnownNetworkFound;
       
   115         }
       
   116     
       
   117     iEnv->DeleteResourceFile( iResourceFileOffset );
       
   118 
       
   119     iObservers.Close();
       
   120 
       
   121     Release( iContent );
       
   122     Release( iEvents );
       
   123     }
       
   124 
       
   125 
       
   126 // --------------------------------------------------------------------------
       
   127 // CWsfAiPlugin::CWsfAiPlugin
       
   128 // --------------------------------------------------------------------------
       
   129 //
       
   130 CWsfAiPlugin::CWsfAiPlugin()
       
   131     {
       
   132     iEnv = CEikonEnv::Static();
       
   133     }
       
   134 
       
   135 
       
   136 // --------------------------------------------------------------------------
       
   137 // CWsfAiPlugin::ConstructL
       
   138 // --------------------------------------------------------------------------
       
   139 //
       
   140 void CWsfAiPlugin::ConstructL()
       
   141     {
       
   142     LOG_ENTERFN( "CWsfAiPlugin::ConstructL" );
       
   143     AllocateResourcesL();
       
   144     
       
   145     iContent = AiUtility::CreateContentItemArrayIteratorL( 
       
   146                                                     KAiWizardContent );
       
   147     iEvents = AiUtility::CreateContentItemArrayIteratorL( KAiWizardEvents );
       
   148     
       
   149     // create the engine first...
       
   150     iModel = CWsfModel::NewL( iController, EFalse );
       
   151 
       
   152     // then model
       
   153     iAiModel = CWsfAiModel::NewL();
       
   154     iUi = CWsfAiView::NewL( *this );
       
   155     
       
   156     iActiveWrappers = CWsfActiveWrappers::NewL( iModel, iController );
       
   157     
       
   158     iDbObserver = CWsfDbObserver::NewL();
       
   159     
       
   160     iController.SetUi( *static_cast<CWsfAiView*>( iUi ) );
       
   161     
       
   162     iController.InitializeL( iEnv, iModel, iAiModel, iDbObserver, 
       
   163 							 iActiveWrappers );
       
   164     }
       
   165 
       
   166 
       
   167 // --------------------------------------------------------------------------
       
   168 // CWsfAiPlugin::PublishContentL
       
   169 // --------------------------------------------------------------------------
       
   170 //
       
   171 void CWsfAiPlugin::PublishContentL( CArrayFix<TInt>* aPublishIconArray, 
       
   172                                     CEikLabel* aText1 )
       
   173     {
       
   174     LOG_ENTERFN( "CWsfAiPlugin::PublishContentL" );
       
   175     TInt leftBoundary( 0 );
       
   176     TInt rightBoundary( 0 );
       
   177     TChar boundary('\'');
       
   178     HBufC* localCurrentStatusText( NULL );
       
   179     
       
   180     HBufC* localCurrentNetworkStatus( NULL );
       
   181     HBufC* localCurrentNetworkName( NULL );
       
   182 
       
   183     HBufC* localFullText = ( aText1->Text() )->AllocLC();
       
   184 
       
   185     // Locate ' chars from the full string
       
   186     TPtrC fullText = localFullText->Des();
       
   187     leftBoundary = fullText.Locate( boundary );    // char = '
       
   188     rightBoundary = fullText.LocateReverse( boundary );
       
   189 
       
   190     // if we have status name then we parse it
       
   191     if ( leftBoundary != rightBoundary && 
       
   192          leftBoundary != KErrNotFound && 
       
   193          rightBoundary != KErrNotFound )
       
   194         {
       
   195         LOG_WRITE( "status name exists" );
       
   196         TPtrC begin = fullText.Mid( leftBoundary, 
       
   197                                     rightBoundary - leftBoundary + 1 );
       
   198         localCurrentStatusText = begin.AllocLC();
       
   199         localCurrentNetworkName = begin.AllocLC();
       
   200 
       
   201         TPtrC end = fullText.Mid( rightBoundary + 1 );
       
   202        }
       
   203     else
       
   204         {
       
   205         LOG_WRITE( "status name does not exist" );
       
   206         localCurrentStatusText = fullText.AllocLC();
       
   207         }
       
   208     
       
   209     //Connected
       
   210     if ( localCurrentNetworkName )
       
   211         {
       
   212         if ( iAiModel->Connected() )
       
   213             {
       
   214             LOG_WRITE( "ai model is connected" );
       
   215             if ( !iConnectedTo )
       
   216                 {
       
   217                 iConnectedTo = StringLoader::LoadL( 
       
   218                         R_QTN_SNIFFER_PLUG_IN_CONNECTED_TO );
       
   219                 }
       
   220             localCurrentNetworkStatus = iConnectedTo;
       
   221             }
       
   222         else
       
   223             {
       
   224             if ( !iKnownNetworkFound )
       
   225                 {
       
   226                 iKnownNetworkFound = StringLoader::LoadL( 
       
   227                         R_QTN_SNIFFER_PLUG_IN_WLAN_NETWORK_FOUND );
       
   228                 }
       
   229             LOG_WRITE( "there is known network" );
       
   230             localCurrentNetworkStatus = iKnownNetworkFound;
       
   231             }
       
   232         }
       
   233     else
       
   234         {
       
   235         LOG_WRITE( "use current status text" );
       
   236         localCurrentNetworkStatus = localCurrentStatusText;
       
   237         }
       
   238 
       
   239     TBool published( EFalse );
       
   240     TInt iconId( 0 );
       
   241 
       
   242     ClearL();   // Clear all WLAN Wizard content from the AI2
       
   243 
       
   244     for ( iCurrentObserverIndex = 0; 
       
   245           iCurrentObserverIndex < iObservers.Count(); 
       
   246           ++iCurrentObserverIndex )
       
   247         {
       
   248         LOG_WRITEF( "Start publish - index = %d", iCurrentObserverIndex );
       
   249         
       
   250         MAiContentObserver* observer = iObservers[iCurrentObserverIndex];
       
   251         observer->StartTransaction( reinterpret_cast<TInt32>( this ) );
       
   252         // make sure we cancel the tracsaction if leaves
       
   253         CleanupStack::PushL( TCleanupItem( PublishCleanup, this ) );
       
   254 
       
   255         if ( localCurrentStatusText )
       
   256             {
       
   257             LOG_WRITE( "Publish -> status icon" );
       
   258             // Publish Status icon: EAiWizardContentStatusIcon
       
   259             iconId = aPublishIconArray->At( 0 );
       
   260             published = PublishIconL( observer, 
       
   261                                       EAiWizardContentStatusIcon,
       
   262                                       iconId ) || published;
       
   263             }
       
   264 
       
   265         LOG_WRITE( "Publish -> Strength icon" );
       
   266         // Publish Strength icon: EAiWizardContentStrengthIcon
       
   267         iconId = aPublishIconArray->At( 2 );
       
   268         published = PublishIconL( observer, 
       
   269                                   EAiWizardContentStrengthIcon,
       
   270                                   iconId ) || published;
       
   271 
       
   272         LOG_WRITE( "Publish -> secure icon" );
       
   273         // Publish Secure icon: EAiWizardContentSecureIcon
       
   274         iconId = aPublishIconArray->At( 1 );
       
   275         published = PublishIconL( observer, 
       
   276                                   EAiWizardContentSecureIcon,
       
   277                                   iconId ) || published;
       
   278         
       
   279         if ( localCurrentNetworkName )
       
   280             {
       
   281             LOG_WRITE( "Publish -> localCurrentNetworkName" );
       
   282             // Publish NetworkName text: EAiWizardContentNetworkName
       
   283             published = PublishText( observer, 
       
   284                                      EAiWizardContentNetworkName,
       
   285                                      *localCurrentNetworkName ) || published;
       
   286             }
       
   287         
       
   288         if ( localCurrentNetworkStatus )
       
   289             {
       
   290             LOG_WRITE( "Publish -> localCurrentNetworkStatus" );
       
   291             // Publish NetworkName text: EAiWizardContentNetworkName
       
   292             published = PublishText( observer, 
       
   293                                      EAiWizardContentNetworkStatus,
       
   294                                      *localCurrentNetworkStatus ) || published;
       
   295             }
       
   296         
       
   297         // If we published something then commit, 
       
   298         // otherwise cancel transaction
       
   299         if ( published )
       
   300             {
       
   301             LOG_WRITE( "Commit" );
       
   302             observer->Commit( reinterpret_cast<TInt32>( this ) );
       
   303             published = EFalse;
       
   304             }
       
   305         else
       
   306             {
       
   307             LOG_WRITE( "Cancel transaction" );
       
   308             observer->CancelTransaction( reinterpret_cast<TInt32>( this ) );
       
   309             }
       
   310         CleanupStack::Pop( 1 ); // PublishCleanup()
       
   311         }
       
   312     
       
   313     LOG_WRITE( "Publishing ready" );
       
   314     
       
   315     if ( localCurrentNetworkName ) 
       
   316         {
       
   317         CleanupStack::PopAndDestroy( localCurrentNetworkName );
       
   318         }
       
   319     
       
   320     if ( localCurrentStatusText ) 
       
   321         {
       
   322         CleanupStack::PopAndDestroy( localCurrentStatusText );
       
   323         }
       
   324 
       
   325     CleanupStack::PopAndDestroy( localFullText );
       
   326     }
       
   327 
       
   328 
       
   329 // --------------------------------------------------------------------------
       
   330 // CWsfAiPlugin::AllocateResourcesL
       
   331 // --------------------------------------------------------------------------
       
   332 //
       
   333 void CWsfAiPlugin::AllocateResourcesL()
       
   334     {
       
   335     LOG_ENTERFN( "CWsfAiPlugin::AllocateResourcesL" );
       
   336     // create resourcefile 
       
   337     TFileName resourceFile;
       
   338     resourceFile.Append( KResourceDrive );
       
   339     resourceFile.Append( KDC_RESOURCE_FILES_DIR );
       
   340     resourceFile.Append( KResourceFile );
       
   341 
       
   342     BaflUtils::NearestLanguageFile( iEnv->FsSession(), resourceFile );
       
   343     iResourceFileOffset = iEnv->AddResourceFileL( resourceFile );    
       
   344     }
       
   345 
       
   346 // --------------------------------------------------------------------------
       
   347 // CWsfAiPlugin::Start
       
   348 // --------------------------------------------------------------------------
       
   349 //
       
   350 void CWsfAiPlugin::Start( TStartReason /*aReason*/ )
       
   351     {
       
   352     LOG_ENTERFN( "CWsfAiPlugin::Start");
       
   353     iController.StartupRefresh();
       
   354     }
       
   355 
       
   356 // --------------------------------------------------------------------------
       
   357 // CWsfAiPlugin::Stop
       
   358 // --------------------------------------------------------------------------
       
   359 //
       
   360 void CWsfAiPlugin::Stop( TStopReason /*aReason*/ )
       
   361     {
       
   362     LOG_ENTERFN( "CWsfAiPlugin::Stop" );
       
   363     TRAP_IGNORE( iController.DeInitializeL() );
       
   364     if ( iAnimationPeriodic )
       
   365         {
       
   366         LOG_WRITE( "Cancel animation update" );
       
   367         iAnimationPeriodic->Cancel();
       
   368         delete iAnimationPeriodic;
       
   369         iAnimationPeriodic = NULL;
       
   370         }
       
   371     }
       
   372 
       
   373 // --------------------------------------------------------------------------
       
   374 // CWsfAiPlugin::Resume
       
   375 // --------------------------------------------------------------------------
       
   376 //
       
   377 void CWsfAiPlugin::Resume( TResumeReason aReason )
       
   378     {
       
   379     LOG_ENTERFN( "CWsfAiPlugin::Resume" );
       
   380     if( aReason == EForeground ) 
       
   381         {
       
   382         // HS came to foreground -> make refresh scan
       
   383         if ( !iAiModel->Connected() && !iModel->IsConnecting() )
       
   384             {
       
   385             LOG_WRITE( "Call Refresh scan" );
       
   386         	iActiveWrappers->RefreshScan();
       
   387             }
       
   388         else
       
   389             {
       
   390             LOG_WRITE( "Connected no need to refresh scan results" );
       
   391             }
       
   392         }
       
   393     }
       
   394 
       
   395 // --------------------------------------------------------------------------
       
   396 // CWsfAiPlugin::Suspend
       
   397 // --------------------------------------------------------------------------
       
   398 //
       
   399 void CWsfAiPlugin::Suspend( TSuspendReason aReason )
       
   400     {
       
   401     LOG_ENTERFN( "CWsfAiPlugin::Suspend" );
       
   402     
       
   403     if( aReason == EBackground )
       
   404         {
       
   405         if ( iAnimationPeriodic )
       
   406             {
       
   407             LOG_WRITE( "Cancel animation update" );
       
   408             iAnimationPeriodic->Cancel();
       
   409             delete iAnimationPeriodic;
       
   410             iAnimationPeriodic = NULL;
       
   411             }
       
   412         }
       
   413     }
       
   414 
       
   415 // --------------------------------------------------------------------------
       
   416 // CWsfAiPlugin::SubscribeL
       
   417 // --------------------------------------------------------------------------
       
   418 //
       
   419 void CWsfAiPlugin::SubscribeL( MAiContentObserver& aObserver )
       
   420     {
       
   421     LOG_ENTERFN( "CWsfAiPlugin::Subscribe" );
       
   422     iObservers.AppendL( &aObserver );
       
   423     }
       
   424 
       
   425 
       
   426 // --------------------------------------------------------------------------
       
   427 // CWsfAiPlugin::ConfigureL
       
   428 // --------------------------------------------------------------------------
       
   429 //
       
   430 void CWsfAiPlugin::ConfigureL( RAiSettingsItemArray& /*aSettings*/ )
       
   431     {
       
   432     LOG_ENTERFN( "CWsfAiPlugin::ConfigureL" );
       
   433     }
       
   434 
       
   435 // --------------------------------------------------------------------------
       
   436 // CWsfAiPlugin::GetPropertyL
       
   437 // --------------------------------------------------------------------------
       
   438 //
       
   439 TAny* CWsfAiPlugin::GetProperty( TProperty aProperty )
       
   440     {
       
   441     if( aProperty == EPublisherContent )
       
   442         {
       
   443         return iContent;
       
   444         }
       
   445     else if( aProperty == EPublisherEvents )
       
   446         {
       
   447         return iEvents;
       
   448         }
       
   449 
       
   450     return NULL;
       
   451     }
       
   452 
       
   453 // --------------------------------------------------------------------------
       
   454 // CWsfAiPlugin::HandleEvent
       
   455 // --------------------------------------------------------------------------
       
   456 //
       
   457 void CWsfAiPlugin::HandleEvent( TInt aEvent, const TDesC& /*aParam*/ )
       
   458     {
       
   459     LOG_ENTERFN( "CWsfAiPlugin::HandleEvent" );
       
   460     switch ( aEvent )
       
   461         {
       
   462         case EAiWizardEventLaunchApplication:
       
   463             {
       
   464             TRAP_IGNORE( LaunchApplicationL() );
       
   465             break;
       
   466             }
       
   467             
       
   468         case EAiWizardGainFocusInfoArea:
       
   469             {
       
   470             iInfoAreaFocus = ETrue;
       
   471             TRAP_IGNORE( SetMskL() );
       
   472             break;
       
   473             }
       
   474             
       
   475         case EAiWizardLostFocusInfoArea:
       
   476             {
       
   477             iInfoAreaFocus = EFalse;
       
   478             break;            
       
   479             }
       
   480             
       
   481         case EAiWizardOpenMenu:
       
   482             {
       
   483             if ( !iRefreshing )
       
   484                 {
       
   485                 TRAP_IGNORE( iController.HandleSelectionKeyL() );
       
   486                 }
       
   487             break;
       
   488             }
       
   489             
       
   490         default:
       
   491             {
       
   492             }
       
   493         }
       
   494     }
       
   495 
       
   496 
       
   497 // --------------------------------------------------------------------------
       
   498 // CWsfAiPlugin::ClearL
       
   499 // --------------------------------------------------------------------------
       
   500 //
       
   501 void CWsfAiPlugin::ClearL()
       
   502     {
       
   503     LOG_ENTERFN( "CWsfAiPlugin::ClearL" );
       
   504     for ( TInt i = 0; i < iObservers.Count(); ++i )
       
   505         {
       
   506         MAiContentObserver* observer = iObservers[i];
       
   507 
       
   508         observer->StartTransaction( reinterpret_cast<TInt32>( this ) );
       
   509 
       
   510         observer->Clean( *this, EAiWizardContentStatusIcon, 
       
   511                                 EAiWizardContentStatusIcon );
       
   512         observer->Clean( *this, EAiWizardContentStrengthIcon, 
       
   513                                 EAiWizardContentStrengthIcon );
       
   514         observer->Clean( *this, EAiWizardContentSecureIcon, 
       
   515                                 EAiWizardContentSecureIcon );
       
   516         observer->Clean( *this, EAiWizardContentNetworkName, 
       
   517                                 EAiWizardContentNetworkName );
       
   518         
       
   519         observer->Commit( reinterpret_cast<TInt32>( this ) );
       
   520         }
       
   521     }
       
   522 
       
   523 
       
   524 // --------------------------------------------------------------------------
       
   525 // CWsfAiPlugin::SetScanningState
       
   526 // --------------------------------------------------------------------------
       
   527 //
       
   528 void CWsfAiPlugin::SetScanningState( TBool aScanState )
       
   529     {
       
   530     LOG_ENTERFN( "CWsfAiPlugin::SetScanningState" );
       
   531     iScanState = aScanState;
       
   532     TRAP_IGNORE( SetMskL() );
       
   533     }
       
   534 
       
   535 
       
   536 // --------------------------------------------------------------------------
       
   537 // CWsfAiPlugin::SetRefreshingL
       
   538 // --------------------------------------------------------------------------
       
   539 //
       
   540 void CWsfAiPlugin::SetRefreshingL( TBool aRefreshing )
       
   541     {
       
   542     LOG_ENTERFN( "CWsfAiPlugin::SetRefreshingL" );
       
   543     if( iRefreshing != aRefreshing )
       
   544         {
       
   545         LOG_WRITEF( "iRefreshing = %d and aRefreshing = %d ", 
       
   546                      iRefreshing, aRefreshing );
       
   547         if( aRefreshing )
       
   548             {
       
   549             if ( iAnimationPeriodic )
       
   550                 {
       
   551                 iAnimationPeriodic->Cancel();
       
   552                 delete iAnimationPeriodic;
       
   553                 iAnimationPeriodic = NULL;
       
   554                 }
       
   555             iPublishNetworkStatusText = ETrue;
       
   556             iAiModel->InitializeRefreshAnimation();
       
   557             iAnimationPeriodic = CPeriodic::NewL(
       
   558                     CActive::EPriorityStandard );
       
   559                         
       
   560             iAnimationPeriodic->Start(
       
   561                     TTimeIntervalMicroSeconds32( KRefreshStepTime ),
       
   562                     TTimeIntervalMicroSeconds32( KRefreshStepTime ),
       
   563                     TCallBack( 
       
   564                             CWsfAiPlugin::DoRefreshingStepL,
       
   565                             this
       
   566                             ) );
       
   567             }
       
   568         else
       
   569             {
       
   570             if ( iAnimationPeriodic )
       
   571                 {
       
   572                 iAnimationPeriodic->Cancel();
       
   573                 delete iAnimationPeriodic;
       
   574                 iAnimationPeriodic = NULL;                
       
   575                 }
       
   576             }
       
   577         }
       
   578     iRefreshing = aRefreshing;
       
   579     }
       
   580 
       
   581 
       
   582 // --------------------------------------------------------------------------
       
   583 // CWsfAiPlugin::SetRefreshingL
       
   584 // --------------------------------------------------------------------------
       
   585 //
       
   586 void CWsfAiPlugin::StartConnectingL()
       
   587     {
       
   588     LOG_ENTERFN( "CWsfAiPlugin::StartConnectingL" );
       
   589     
       
   590     if ( iAnimationPeriodic )
       
   591         {
       
   592         iAnimationPeriodic->Cancel();
       
   593         delete iAnimationPeriodic;
       
   594         iAnimationPeriodic = NULL;
       
   595         }
       
   596 
       
   597     iPublishNetworkStatusText = ETrue;
       
   598     iAiModel->InitializeConnectingAnimation();
       
   599     iAnimationPeriodic = CPeriodic::NewL(
       
   600                                     CActive::EPriorityStandard );
       
   601                 
       
   602     iAnimationPeriodic->Start(
       
   603             TTimeIntervalMicroSeconds32( KConnectingStepTime ),
       
   604             TTimeIntervalMicroSeconds32( KConnectingStepTime ),
       
   605             TCallBack( 
       
   606                     CWsfAiPlugin::DoConnectingStepL,
       
   607                     this
       
   608                     ) );
       
   609     }
       
   610 
       
   611 
       
   612 // --------------------------------------------------------------------------
       
   613 // CWsfAiPlugin::NewL
       
   614 // --------------------------------------------------------------------------
       
   615 //
       
   616 void CWsfAiPlugin::LaunchApplicationL()
       
   617     {
       
   618     LOG_ENTERFN( "CWsfAiPlugin::LaunchApplication" );
       
   619     RApaLsSession appArcSession;
       
   620 
       
   621     // connect to AppArc server
       
   622     User::LeaveIfError( appArcSession.Connect() );
       
   623     CleanupClosePushL( appArcSession );
       
   624 
       
   625 
       
   626     // check if the app is already running ... and brings it to foreground.
       
   627     TUid id( TUid::Uid( KUidSnifferApp.iUid ) );
       
   628     TApaTaskList taskList( iEnv->WsSession() );
       
   629     TApaTask task = taskList.FindApp( id );
       
   630 
       
   631     if ( task.Exists() )
       
   632         {
       
   633         task.BringToForeground();
       
   634            }
       
   635     else
       
   636         {
       
   637         TThreadId threadId;
       
   638         User::LeaveIfError( appArcSession.StartDocument( 
       
   639                                         KNullDesC, 
       
   640                                         TUid::Uid( KUidSnifferApp.iUid ),
       
   641                                         threadId ) );
       
   642         }
       
   643         
       
   644     CleanupStack::PopAndDestroy( &appArcSession ); //appArcSession
       
   645     }
       
   646 
       
   647 
       
   648 // --------------------------------------------------------------------------
       
   649 // CWsfAiPlugin::SetMskL
       
   650 // --------------------------------------------------------------------------
       
   651 //
       
   652 void CWsfAiPlugin::SetMskL()
       
   653     {
       
   654     LOG_ENTERFN( "CWsfAiPlugin::SetMsk" );
       
   655     
       
   656     if ( AknLayoutUtils::PenEnabled() )
       
   657         {
       
   658         // MSK not updated in touch products
       
   659         return;
       
   660         }
       
   661     
       
   662     CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   663     
       
   664     if( cba )
       
   665         {
       
   666         if ( iAiModel->ScanningOn() || iAiModel->Connected() )
       
   667             {
       
   668             // Show context menu icon
       
   669             cba->SetCommandL( CEikButtonGroupContainer::EMiddleSoftkeyPosition, 
       
   670                           EAknSoftkeyContextOptions, 
       
   671                           KNullDesC );
       
   672             }
       
   673         else
       
   674             {
       
   675             if ( !iMskActivate )
       
   676                 {
       
   677                 iMskActivate = StringLoader::LoadL( R_QTN_MSK_SNIFFER_ACTIVATE );
       
   678                 }
       
   679             // Show 'Activate'
       
   680             cba->SetCommandL( CEikButtonGroupContainer::EMiddleSoftkeyPosition, 
       
   681                           EAknSoftkeyOk, 
       
   682                           *iMskActivate );
       
   683             }
       
   684         cba->DrawDeferred();
       
   685     	}
       
   686     }
       
   687 
       
   688 
       
   689 // --------------------------------------------------------------------------
       
   690 // CWsfAiPlugin::PublishText
       
   691 // --------------------------------------------------------------------------
       
   692 //
       
   693 TBool CWsfAiPlugin::PublishText( MAiContentObserver* aObserver,
       
   694                                  TWsfAiWizardContentIds aContentId,
       
   695                                  const TDesC16& aText )
       
   696     {
       
   697     LOG_ENTERFN( "CWsfAiPlugin::PublishText" );
       
   698     TBool published( EFalse );
       
   699     TInt error( 0 );
       
   700     if ( aObserver->CanPublish( *this, aContentId, aContentId ) )
       
   701         {
       
   702         error = aObserver->Publish( *this,
       
   703                                     aContentId,
       
   704                                     aText,
       
   705                                     aContentId );
       
   706 
       
   707         if ( error == KErrNone )
       
   708             {
       
   709             published = ETrue;
       
   710             }
       
   711         }
       
   712     return published;
       
   713     }
       
   714 
       
   715 
       
   716 // --------------------------------------------------------------------------
       
   717 // CWsfAiPlugin::PublishIconL
       
   718 // --------------------------------------------------------------------------
       
   719 //
       
   720 TBool CWsfAiPlugin::PublishIconL( MAiContentObserver* aObserver,
       
   721                                   TWsfAiWizardContentIds aContentId,
       
   722                                   TInt aIconId )
       
   723     {
       
   724     LOG_ENTERFN( "CWsfAiPlugin::PublishIcon" );
       
   725     TBool published( EFalse );
       
   726     TInt error( 0 );
       
   727     if ( aObserver->CanPublish( *this, aContentId, aContentId ) )
       
   728         {
       
   729         error = aObserver->PublishPtr( 
       
   730                               *this,
       
   731                               aContentId,
       
   732                               CWsfIconArrayCreator::GetIconLC( aIconId ),
       
   733                               aContentId );
       
   734 
       
   735         CleanupStack::Pop(); // pop the icon
       
   736 
       
   737         if ( error == KErrNone )
       
   738             {
       
   739             published = ETrue;
       
   740             }
       
   741         }
       
   742     return published;
       
   743     }
       
   744 
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // CWsfAiPlugin::PublishCleanup
       
   748 // ---------------------------------------------------------------------------
       
   749 //
       
   750 void CWsfAiPlugin::PublishCleanup( TAny* aPtr )
       
   751     {
       
   752     LOG_ENTERFN( "CWsfAiPlugin::PublishCleanup" );
       
   753     CWsfAiPlugin* self = static_cast<CWsfAiPlugin*>( aPtr );
       
   754     
       
   755     if ( self && self->iCurrentObserverIndex < self->iObservers.Count() )
       
   756         {
       
   757         LOG_WRITE( "Cancel transaction" );
       
   758         self->iObservers[self->iCurrentObserverIndex]
       
   759                      ->CancelTransaction( reinterpret_cast<TInt32>( self ) );
       
   760         }
       
   761     }
       
   762 
       
   763 
       
   764 // ---------------------------------------------------------------------------
       
   765 // CWsfAiPlugin::DoRefreshingStepL
       
   766 // ---------------------------------------------------------------------------
       
   767 //
       
   768 TInt CWsfAiPlugin::DoRefreshingStepL( TAny* ptr )
       
   769 	{
       
   770 	LOG_ENTERFN( "CWsfAiPlugin::DoRefreshingStepL( ptr )" );
       
   771 	static_cast<CWsfAiPlugin*>( ptr )->DoRefreshingStepL();
       
   772 	return ETrue;
       
   773 	}
       
   774 
       
   775 // ---------------------------------------------------------------------------
       
   776 // CWsfAiPlugin::DoRefreshingStepL
       
   777 // ---------------------------------------------------------------------------
       
   778 //
       
   779 void CWsfAiPlugin::DoRefreshingStepL()
       
   780 	{
       
   781 	LOG_ENTERFN( "CWsfAiPlugin::DoRefreshingStepL" );
       
   782 	
       
   783 	if ( !iAiModel->ScanningOn() )
       
   784 	    {
       
   785 	    LOG_WRITE( "Disable refreshing" );
       
   786 	    if ( iAnimationPeriodic )
       
   787 	        {
       
   788 	        LOG_WRITE( "Cancel animation update" );
       
   789 	        iAnimationPeriodic->Cancel();
       
   790 	        delete iAnimationPeriodic;
       
   791 	        iAnimationPeriodic = NULL;
       
   792 	        }
       
   793 	    iRefreshing = EFalse;
       
   794 	    }
       
   795 	else
       
   796 	    {
       
   797 	    iAiModel->AnimateRefresh();
       
   798 	    iController.RefreshRefreshingL();
       
   799 	    }	
       
   800 	}
       
   801 
       
   802 // ---------------------------------------------------------------------------
       
   803 // CWsfAiPlugin::DoConnectingStepL
       
   804 // ---------------------------------------------------------------------------
       
   805 //
       
   806 TInt CWsfAiPlugin::DoConnectingStepL( TAny* ptr )
       
   807     {
       
   808     LOG_ENTERFN( "CWsfAiPlugin::DoConnectingStepL( ptr )" );
       
   809     static_cast<CWsfAiPlugin*>( ptr )->DoConnectingStepL();
       
   810     return ETrue;
       
   811     }
       
   812 
       
   813 // ---------------------------------------------------------------------------
       
   814 // CWsfAiPlugin::DoConnectingStepL
       
   815 // ---------------------------------------------------------------------------
       
   816 //
       
   817 void CWsfAiPlugin::DoConnectingStepL()
       
   818     {
       
   819     LOG_ENTERFN( "CWsfAiPlugin::DoConnectingStepL" );
       
   820     
       
   821     if ( !iModel->IsConnecting() )
       
   822         {
       
   823         LOG_WRITE( "Disable refreshing" );
       
   824         if ( iAnimationPeriodic )
       
   825             {
       
   826             LOG_WRITE( "Cancel animation update" );
       
   827             iAnimationPeriodic->Cancel();
       
   828             delete iAnimationPeriodic;
       
   829             iAnimationPeriodic = NULL;
       
   830             }
       
   831         }
       
   832     else
       
   833         {
       
   834         iAiModel->AnimateConnecting();
       
   835         iController.RefreshConnectingL();
       
   836         }   
       
   837     }
       
   838 
       
   839 // ---------------------------------------------------------------------------
       
   840 // CWsfAiPlugin::PublishStatusIconL
       
   841 // ---------------------------------------------------------------------------
       
   842 //
       
   843 void CWsfAiPlugin::PublishStatusIconL( CArrayFix<TInt>* aPublishIconArray, 
       
   844                                        CEikLabel* aText1 )
       
   845     {
       
   846     LOG_ENTERFN( "CWsfAiPlugin::PublishStatusIconL" );
       
   847     TBool published( EFalse );
       
   848     TInt iconId( 0 );
       
   849 
       
   850     ClearL();   // Clear all WLAN Wizard content from the AI2
       
   851 
       
   852     for ( iCurrentObserverIndex = 0; 
       
   853           iCurrentObserverIndex < iObservers.Count(); 
       
   854           ++iCurrentObserverIndex )
       
   855         {
       
   856         MAiContentObserver* observer = iObservers[iCurrentObserverIndex];
       
   857         
       
   858         // Publish Status icon: EAiWizardContentStatusIcon
       
   859         iconId = aPublishIconArray->At( 0 );
       
   860         published = PublishIconL( observer, 
       
   861                                   EAiWizardContentStatusIcon,
       
   862                                   iconId ) || published;
       
   863         
       
   864         if ( iPublishNetworkStatusText && aText1 )
       
   865             {
       
   866             iPublishNetworkStatusText = EFalse;
       
   867             HBufC *statusText = aText1->Text()->AllocLC();
       
   868             published = PublishText( observer, 
       
   869                                      EAiWizardContentNetworkStatus,
       
   870                                      *statusText ) || published;
       
   871             CleanupStack::PopAndDestroy( statusText );
       
   872             }
       
   873         
       
   874         // If we published something then commit, 
       
   875         // otherwise cancel transaction
       
   876         if ( published )
       
   877             {
       
   878             published = EFalse;
       
   879             }
       
   880         }
       
   881     }
       
   882 
       
   883 
       
   884 // End of File.