hotspotfw/hsbrowser/src/hsbrowserloadeventobserver.cpp
changeset 0 56b72877c1cb
child 8 c2bc3f8c7777
equal deleted inserted replaced
-1:000000000000 0:56b72877c1cb
       
     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         	{
       
    96         	DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() EEventNewContentDisplayed" );            
       
    97             }        
       
    98         case TBrCtlDefs::EEventNewContentStart:
       
    99             {
       
   100             DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() EEventNewContentStart" );            
       
   101             if ( iDoIct )
       
   102             	{
       
   103             	DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() Start testing internet connectivity.");
       
   104             	iDoIct = EFalse;
       
   105 				TRAPD( err, TestInternetConnectivityL() );
       
   106 				if ( err != KErrNone )
       
   107 					{
       
   108 					DEBUG1( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() err=%d.", err );
       
   109 					}
       
   110            	    }
       
   111             break;
       
   112             }
       
   113         case TBrCtlDefs::EEventLoadFinished://EEventUrlLoadingFinished:
       
   114             {
       
   115             DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() EEventUrlLoadingFinished" );
       
   116             // We've finished loading one element of page
       
   117             iContainer->UpdateNaviPane( CHsBrowserContainer::ELoadingFinished );
       
   118             break;
       
   119             }
       
   120         case TBrCtlDefs::EEventTitleAvailable:
       
   121             {
       
   122             DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() EEventTitleAvailable" );
       
   123             UpdateNameL();
       
   124             break;
       
   125             }
       
   126         default:
       
   127         	{
       
   128             break;
       
   129         	}
       
   130         }   // end of switch
       
   131         
       
   132     UpdateDoIctFlagL();
       
   133     
       
   134     if ( iContainer )
       
   135     	{
       
   136         iContainer->DrawNow();
       
   137         iContainer->MakeVisible( ETrue );    	
       
   138     	}   
       
   139     }
       
   140     
       
   141 // ---------------------------------------------------------
       
   142 // CHsBrowserLoadEventObserver::CHsBrowserLoadEventObserver
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 CHsBrowserLoadEventObserver::CHsBrowserLoadEventObserver(
       
   146     CHsBrowserContainer* aContainer ) : 
       
   147     iContainer( aContainer ),
       
   148     iIcts( NULL ),
       
   149     iDoIct( EFalse ),
       
   150     iIsFirstLoad( ETrue )
       
   151     {
       
   152     DEBUG( "CHsBrowserLoadEventObserver::CHsBrowserLoadEventObserver()" );
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------
       
   156 // CHsBrowserLoadEventObserver::ConstructL
       
   157 // ---------------------------------------------------------
       
   158 //
       
   159 void 
       
   160 CHsBrowserLoadEventObserver::ConstructL()
       
   161     {
       
   162     DEBUG( "CHsBrowserLoadEventObserver::ConstructL()" );
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------
       
   166 // CHsBrowserLoadEventObserver::UpdateNaviLabel()
       
   167 // ----------------------------------------------------
       
   168 //
       
   169 void CHsBrowserLoadEventObserver::UpdateNaviLabel( const TDesC& aName )
       
   170     {
       
   171     DEBUG( "CHsBrowserLoadEventObserver::UpdateNaviLabel()" );
       
   172     if ( iContainer )
       
   173         {
       
   174         TRAPD( err, iContainer->NaviLabel()->SetTextL( aName ) );
       
   175         if ( err == KErrNone )
       
   176         	{
       
   177         	iContainer->NaviLabel()->DrawDeferred( );
       
   178         	}
       
   179         else
       
   180           	{
       
   181             DEBUG1( "CHsBrowserLoadEventObserver::UpdateNaviLabel() err=%d", err );
       
   182             }
       
   183         }
       
   184     }
       
   185 
       
   186 // ----------------------------------------------------
       
   187 // CHsBrowserLoadEventObserver::UpdateFastSwapNameL()
       
   188 // ----------------------------------------------------
       
   189 //
       
   190 void CHsBrowserLoadEventObserver::UpdateFastSwapNameL( const TDesC& aName )
       
   191 	{
       
   192     DEBUG( "CHsBrowserLoadEventObserver::UpdateFastSwapNameL()" );
       
   193 
       
   194     RApaLsSession appArcSession;
       
   195     TInt err = KErrNone;
       
   196     TApaAppInfo info;
       
   197     
       
   198     err = appArcSession.Connect(); // connect to AppArc server
       
   199     if( KErrNone == err )
       
   200     	{
       
   201     	CleanupClosePushL( appArcSession );
       
   202     	appArcSession.GetAppInfo( info, KUidHsBrowserApp );
       
   203 
       
   204     	if ( aName.Length() > KApaMaxAppCaption )
       
   205     		{
       
   206     		TPtrC shortName = aName.Left( KApaMaxAppCaption );
       
   207     		err = appArcSession.SetAppShortCaption( shortName, ELangNone, KUidHsBrowserApp );
       
   208     		}
       
   209     	else
       
   210     		{
       
   211     		err = appArcSession.SetAppShortCaption( aName, ELangNone, KUidHsBrowserApp );
       
   212     		}
       
   213     	if ( err != KErrNone )
       
   214     		{
       
   215     		DEBUG1( "CHsBrowserLoadEventObserver::UpdateFastSwapNameL() err=%d", err );
       
   216     		}
       
   217     	CleanupStack::PopAndDestroy( &appArcSession );	
       
   218     	}
       
   219 	}
       
   220 
       
   221 // ----------------------------------------------------
       
   222 // CHsBrowserLoadEventObserver::UpdateNameL()
       
   223 // ----------------------------------------------------
       
   224 //
       
   225 void CHsBrowserLoadEventObserver::UpdateNameL()
       
   226     {
       
   227     DEBUG( "CHsBrowserLoadEventObserver::UpdateNameL()" );
       
   228     CBrCtlInterface* brCtlInterface = NULL;
       
   229     if ( iContainer )
       
   230     	{
       
   231     	brCtlInterface = iContainer->BrCtlInterface();
       
   232     	}
       
   233     if ( !brCtlInterface )
       
   234     	{
       
   235     	return;
       
   236     	}    
       
   237     HBufC* title = brCtlInterface->PageInfoLC( TBrCtlDefs::EPageInfoTitle );
       
   238     if ( title )
       
   239     	{
       
   240     	UpdateFastSwapNameL( *title );
       
   241    	    CHsBrowserModel* model = iContainer->Model();
       
   242         if ( model )
       
   243         	{
       
   244         	model->SetPageTitle( *title );
       
   245             iContainer->UpdateNaviPane( CHsBrowserContainer::EPageTitleAvailable );
       
   246             }
       
   247         }
       
   248     CleanupStack::PopAndDestroy( title );
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CHsBrowserLoadEventObserver::TestInternetConnectivityL
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CHsBrowserLoadEventObserver::TestInternetConnectivityL()
       
   256     {
       
   257 	DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() 7" );
       
   258 	
       
   259 	if ( !iContainer )
       
   260 		{
       
   261 	    DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() iContainer=NULL" );
       
   262 	    return;	
       
   263 		}
       
   264     CHsBrowserModel* model = iContainer->Model();
       
   265     if ( !model )
       
   266    	    {
       
   267    	    DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() model=NULL" );
       
   268    	    return;
       
   269    	    }
       
   270     CHsBrowserIctsObserver* observer = iContainer->HsBrowserIctsObserver();
       
   271     if ( !observer )
       
   272         {
       
   273         DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() observer=NULL" );
       
   274         return;
       
   275         }
       
   276     DEBUG1( "CHsBrowserLoadEventObserver::TestInternetConnectivity() iap=%d", model->IapId() );
       
   277     DEBUG1( "CHsBrowserLoadEventObserver::TestInternetConnectivity() netid=%d", model->NetId() );
       
   278     if ( !iIcts )
       
   279         {
       
   280         iIcts = CIctsClientInterface::NewL( model->IapId(), model->NetId(), *observer );
       
   281         }
       
   282     else
       
   283         {
       
   284         // stop previously started polling
       
   285         iIcts->StopPolling();
       
   286         }
       
   287     // Start polling
       
   288     DEBUG( "CHsBrowserLoadEventObserver::TestInternetConnectivity() starting ICT" );
       
   289     iIcts->StartPolling( KTotalPollingTime, KExecutionTimeInterval );
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CHsBrowserLoadEventObserver::UpdateDoIctFlagL
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 void CHsBrowserLoadEventObserver::UpdateDoIctFlagL()
       
   297 	{
       
   298 	DEBUG( "CHsBrowserLoadEventObserver::UpdateDoIctFlagL()" );
       
   299     CBrCtlInterface* brCtlInterface = NULL;
       
   300     CHsBrowserModel* model = NULL;
       
   301     if ( iContainer )
       
   302     	{
       
   303     	brCtlInterface = iContainer->BrCtlInterface();
       
   304     	model = iContainer->Model();
       
   305     	}
       
   306     if ( brCtlInterface && model )
       
   307     	{
       
   308         // get url
       
   309         HBufC* url = brCtlInterface->PageInfoLC( TBrCtlDefs::EPageInfoUrl );
       
   310         if ( url )
       
   311         	{
       
   312             DEBUG1( "url=%S", url );        
       
   313             if ( url->Compare( *model->Url() ) == 0 )
       
   314                { // match
       
   315                iDoIct = ETrue;
       
   316                DEBUG( "CHsBrowserLoadEventObserver::HandleBrowserLoadEventL() iDoIct = ETrue." );
       
   317                }
       
   318     	    }	
       
   319         else
       
   320         	{
       
   321         	DEBUG( "CHsBrowserLoadEventObserver::UpdateDoIctFlagL() url=NULL" );
       
   322         	}
       
   323         CleanupStack::PopAndDestroy( url );
       
   324     	}
       
   325 	}
       
   326 
       
   327 // End of File