hotspotfw/hsbrowser/src/hsbrowserloadeventobserver.cpp
branchRCL_3
changeset 25 f28ada11abbf
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
       
     1 /*
       
     2 * Copyright (c) 2007 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:   Handle load progress events
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32cmn.h>
       
    22 #include <eikenv.h>
       
    23 #include <aknappui.h>
       
    24 #include <akntitle.h>
       
    25 #include <aknnavilabel.h>
       
    26 #include <apgcli.h>
       
    27 #include <ictsclientinterface.h>
       
    28 #include "hotspotclientserver.h"
       
    29 
       
    30 #include "hsbrowsercontainer.h"
       
    31 #include "hsbrowserloadeventobserver.h"
       
    32 #include "hsbrowserictsobserver.h"
       
    33 #include "hsbrowsermodel.h"
       
    34 #include "hsbrowsercommon.h"
       
    35 #include "am_debug.h"
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // CHsBrowserLoadEventObserver::NewL
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 CHsBrowserLoadEventObserver* 
       
    44 CHsBrowserLoadEventObserver::NewL( CHsBrowserContainer* aContainer )
       
    45     {
       
    46     DEBUG( "CHsBrowserLoadEventObserver::NewL()" );
       
    47     CHsBrowserLoadEventObserver* self = new(ELeave)
       
    48 	    CHsBrowserLoadEventObserver( aContainer );
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop( self );
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------
       
    56 // CHsBrowserLoadEventObserver::~CHsBrowserLoadEventObserver
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 CHsBrowserLoadEventObserver::~CHsBrowserLoadEventObserver()
       
    60     {
       
    61     DEBUG( "CHsBrowserLoadEventObserver::~CHsBrowserLoadEventObserver()" );
       
    62     if ( iIcts )
       
    63         {
       
    64         delete iIcts;	
       
    65         }
       
    66     
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // CHsBrowserLoadEventObserver::HandleBrowserLoadEventL
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 void CHsBrowserLoadEventObserver::HandleBrowserLoadEventL(
       
    74     TBrCtlDefs::TBrCtlLoadEvent aLoadEvent,
       
    75     TUint /* aSize */, 
       
    76     TUint16 /* aTransactionId */ ) 
       
    77     {
       
    78     DEBUG1( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() event=%d", aLoadEvent );
       
    79 
       
    80     switch( aLoadEvent )
       
    81         {
       
    82         case TBrCtlDefs::EEventUrlLoadingStart:
       
    83         	{
       
    84         	if ( !iIsFirstLoad )
       
    85         		{
       
    86         		iContainer->UpdateNaviPane( CHsBrowserContainer::ELoadingUrl );
       
    87         		}
       
    88         	else
       
    89         		{
       
    90         		iIsFirstLoad = EFalse;
       
    91         		}
       
    92             // no break, fall through
       
    93         	}
       
    94 		case TBrCtlDefs::EEventNewContentDisplayed:
       
    95         case TBrCtlDefs::EEventNewContentStart:
       
    96             {
       
    97             DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() EEventNewContentStart" );            
       
    98             if ( iDoIct )
       
    99             	{
       
   100             	DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() Start testing internet connectivity.");
       
   101             	iDoIct = EFalse;
       
   102 				TRAPD( err, TestInternetConnectivityL() );
       
   103 				if ( err != KErrNone )
       
   104 					{
       
   105 					DEBUG1( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() err=%d.", err );
       
   106 					}
       
   107            	    }
       
   108             break;
       
   109             }
       
   110         case TBrCtlDefs::EEventLoadFinished://EEventUrlLoadingFinished:
       
   111             {
       
   112             DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() EEventUrlLoadingFinished" );
       
   113             // We've finished loading one element of page
       
   114             iContainer->UpdateNaviPane( CHsBrowserContainer::ELoadingFinished );
       
   115             break;
       
   116             }
       
   117         case TBrCtlDefs::EEventTitleAvailable:
       
   118             {
       
   119             DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() EEventTitleAvailable" );
       
   120             UpdateNameL();
       
   121             break;
       
   122             }
       
   123         default:
       
   124         	{
       
   125             break;
       
   126         	}
       
   127         }   // end of switch
       
   128         
       
   129     UpdateDoIctFlagL();
       
   130     
       
   131     if ( iContainer )
       
   132     	{
       
   133         iContainer->DrawNow();
       
   134         iContainer->MakeVisible( ETrue );    	
       
   135     	}   
       
   136     }
       
   137     
       
   138 // ---------------------------------------------------------
       
   139 // CHsBrowserLoadEventObserver::CHsBrowserLoadEventObserver
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 CHsBrowserLoadEventObserver::CHsBrowserLoadEventObserver(
       
   143     CHsBrowserContainer* aContainer ) : 
       
   144     iContainer( aContainer ),
       
   145     iIcts( NULL ),
       
   146     iDoIct( EFalse ),
       
   147     iIsFirstLoad( ETrue )
       
   148     {
       
   149     DEBUG( "CHsBrowserLoadEventObserver::CHsBrowserLoadEventObserver()" );
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------
       
   153 // CHsBrowserLoadEventObserver::ConstructL
       
   154 // ---------------------------------------------------------
       
   155 //
       
   156 void 
       
   157 CHsBrowserLoadEventObserver::ConstructL()
       
   158     {
       
   159     DEBUG( "CHsBrowserLoadEventObserver::ConstructL()" );
       
   160     }
       
   161 
       
   162 // ----------------------------------------------------
       
   163 // CHsBrowserLoadEventObserver::UpdateNaviLabel()
       
   164 // ----------------------------------------------------
       
   165 //
       
   166 void CHsBrowserLoadEventObserver::UpdateNaviLabel( const TDesC& aName )
       
   167     {
       
   168     DEBUG( "CHsBrowserLoadEventObserver::UpdateNaviLabel()" );
       
   169     if ( iContainer )
       
   170         {
       
   171         TRAPD( err, iContainer->NaviLabel()->SetTextL( aName ) );
       
   172         if ( err == KErrNone )
       
   173         	{
       
   174         	iContainer->NaviLabel()->DrawDeferred( );
       
   175         	}
       
   176         else
       
   177           	{
       
   178             DEBUG1( "CHsBrowserLoadEventObserver::UpdateNaviLabel() err=%d", err );
       
   179             }
       
   180         }
       
   181     }
       
   182 
       
   183 // ----------------------------------------------------
       
   184 // CHsBrowserLoadEventObserver::UpdateFastSwapNameL()
       
   185 // ----------------------------------------------------
       
   186 //
       
   187 void CHsBrowserLoadEventObserver::UpdateFastSwapNameL( const TDesC& aName )
       
   188 	{
       
   189     DEBUG( "CHsBrowserLoadEventObserver::UpdateFastSwapNameL()" );
       
   190 
       
   191     RApaLsSession appArcSession;
       
   192     TInt err = KErrNone;
       
   193     TApaAppInfo info;
       
   194     
       
   195     err = appArcSession.Connect(); // connect to AppArc server
       
   196     if( KErrNone == err )
       
   197     	{
       
   198     	CleanupClosePushL( appArcSession );
       
   199     	appArcSession.GetAppInfo( info, KUidHsBrowserApp );
       
   200 
       
   201     	if ( aName.Length() > KApaMaxAppCaption )
       
   202     		{
       
   203     		TPtrC shortName = aName.Left( KApaMaxAppCaption );
       
   204     		err = appArcSession.SetAppShortCaption( shortName, ELangNone, KUidHsBrowserApp );
       
   205     		}
       
   206     	else
       
   207     		{
       
   208     		err = appArcSession.SetAppShortCaption( aName, ELangNone, KUidHsBrowserApp );
       
   209     		}
       
   210     	if ( err != KErrNone )
       
   211     		{
       
   212     		DEBUG1( "CHsBrowserLoadEventObserver::UpdateFastSwapNameL() err=%d", err );
       
   213     		}
       
   214     	CleanupStack::PopAndDestroy( &appArcSession );	
       
   215     	}
       
   216 	}
       
   217 
       
   218 // ----------------------------------------------------
       
   219 // CHsBrowserLoadEventObserver::UpdateNameL()
       
   220 // ----------------------------------------------------
       
   221 //
       
   222 void CHsBrowserLoadEventObserver::UpdateNameL()
       
   223     {
       
   224     DEBUG( "CHsBrowserLoadEventObserver::UpdateNameL()" );
       
   225     CBrCtlInterface* brCtlInterface = NULL;
       
   226     if ( iContainer )
       
   227     	{
       
   228     	brCtlInterface = iContainer->BrCtlInterface();
       
   229     	}
       
   230     if ( !brCtlInterface )
       
   231     	{
       
   232     	return;
       
   233     	}    
       
   234     HBufC* title = brCtlInterface->PageInfoLC( TBrCtlDefs::EPageInfoTitle );
       
   235     if ( title )
       
   236     	{
       
   237     	UpdateFastSwapNameL( *title );
       
   238    	    CHsBrowserModel* model = iContainer->Model();
       
   239         if ( model )
       
   240         	{
       
   241         	model->SetPageTitle( *title );
       
   242             iContainer->UpdateNaviPane( CHsBrowserContainer::EPageTitleAvailable );
       
   243             }
       
   244         }
       
   245     CleanupStack::PopAndDestroy( title );
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CHsBrowserLoadEventObserver::TestInternetConnectivityL
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CHsBrowserLoadEventObserver::TestInternetConnectivityL()
       
   253     {
       
   254 	DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() 7" );
       
   255 	
       
   256 	if ( !iContainer )
       
   257 		{
       
   258 	    DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() iContainer=NULL" );
       
   259 	    return;	
       
   260 		}
       
   261     CHsBrowserModel* model = iContainer->Model();
       
   262     if ( !model )
       
   263    	    {
       
   264    	    DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() model=NULL" );
       
   265    	    return;
       
   266    	    }
       
   267     CHsBrowserIctsObserver* observer = iContainer->HsBrowserIctsObserver();
       
   268     if ( !observer )
       
   269         {
       
   270         DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() observer=NULL" );
       
   271         return;
       
   272         }
       
   273     DEBUG1( "CHsBrowserLoadEventObserver::TestInternetConnectivity() iap=%d", model->IapId() );
       
   274     DEBUG1( "CHsBrowserLoadEventObserver::TestInternetConnectivity() netid=%d", model->NetId() );
       
   275     if ( !iIcts )
       
   276         {
       
   277         iIcts = CIctsClientInterface::NewL( model->IapId(), model->NetId(), *observer );
       
   278         }
       
   279     else
       
   280         {
       
   281         // stop previously started polling
       
   282         iIcts->StopPolling();
       
   283         }
       
   284     // Start polling
       
   285     DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() starting ICT" );
       
   286     iIcts->StartPolling( KTotalPollingTime, KExecutionTimeInterval );
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CHsBrowserLoadEventObserver::UpdateDoIctFlagL
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CHsBrowserLoadEventObserver::UpdateDoIctFlagL()
       
   294 	{
       
   295 	DEBUG( "CHsBrowserLoadEventObserver::UpdateDoIctFlagL()" );
       
   296     CBrCtlInterface* brCtlInterface = NULL;
       
   297     CHsBrowserModel* model = NULL;
       
   298     if ( iContainer )
       
   299     	{
       
   300     	brCtlInterface = iContainer->BrCtlInterface();
       
   301     	model = iContainer->Model();
       
   302     	}
       
   303     if ( brCtlInterface && model )
       
   304     	{
       
   305         // get url
       
   306         HBufC* url = brCtlInterface->PageInfoLC( TBrCtlDefs::EPageInfoUrl );
       
   307         if ( url )
       
   308         	{
       
   309             DEBUG1( "url=%S", url );        
       
   310             if ( url->Compare( *model->Url() ) == 0 )
       
   311                { // match
       
   312                iDoIct = ETrue;
       
   313                DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() iDoIct = ETrue." );
       
   314                }
       
   315     	    }	
       
   316         else
       
   317         	{
       
   318         	DEBUG( "CHsBrowserLoadEventObserver::UpdateDoIctFlagL() url=NULL" );
       
   319         	}
       
   320         CleanupStack::PopAndDestroy( url );
       
   321     	}
       
   322 	}
       
   323 
       
   324 // End of File