browserutilities/browserdialogsprovider/Src/BrowserDialogsProvider.cpp
changeset 8 7c90e6132015
parent 0 dd21522fd290
child 27 60c5402cb945
equal deleted inserted replaced
0:dd21522fd290 8:7c90e6132015
    52 #include <MGFetch.h> // Media Fetch
    52 #include <MGFetch.h> // Media Fetch
    53 // General
    53 // General
    54 #include <StringLoader.h>				// strings
    54 #include <StringLoader.h>				// strings
    55 #include <f32file.h>
    55 #include <f32file.h>
    56 #include <THttpFields.h>
    56 #include <THttpFields.h>
       
    57 #include <textresolver.h>
    57 
    58 
    58 // Resources
    59 // Resources
    59 #include <coneresloader.h>
    60 #include <coneresloader.h>
    60 #include <BrowserDialogsProvider.rsg>
    61 #include <BrowserDialogsProvider.rsg>
    61 #include <ErrorRes.rsg>
       
    62 
    62 
    63 // Data Caging
    63 // Data Caging
    64 #include <data_caging_path_literals.hrh>    
    64 #include <data_caging_path_literals.hrh>    
    65 
    65 
    66 // CONSTANTS
    66 // CONSTANTS
    69 const TInt KBrCtlGBFormat = 10;
    69 const TInt KBrCtlGBFormat = 10;
    70 const TInt KBrCtlMegabyte = 1000;	// although 1MB=1024 kB, treat as 1000kb for user simplicity
    70 const TInt KBrCtlMegabyte = 1000;	// although 1MB=1024 kB, treat as 1000kb for user simplicity
    71 
    71 
    72 // DLL resource file name with path
    72 // DLL resource file name with path
    73 _LIT( KBrowserDialogsProviderDirAndFile, "z:BrowserDialogsProvider.rsc" );// resource
    73 _LIT( KBrowserDialogsProviderDirAndFile, "z:BrowserDialogsProvider.rsc" );// resource
    74 _LIT( KErrorResDirAndFile, "z:ErrorRes.rsc" );  // error resource
       
    75 
    74 
    76 //Mime Types
    75 //Mime Types
    77 _LIT( KMimeTypeImage, "image/*" );
    76 _LIT( KMimeTypeImage, "image/*" );
    78 _LIT( KMimeTypeAudio, "audio/*" );
    77 _LIT( KMimeTypeAudio, "audio/*" );
    79 _LIT( KMimeTypeVideo, "video/*" );
    78 _LIT( KMimeTypeVideo, "video/*" );
    89 CBrowserDialogsProvider::CBrowserDialogsProvider( 
    88 CBrowserDialogsProvider::CBrowserDialogsProvider( 
    90 								MBrowserDialogsProviderObserver* aObserver )
    89 								MBrowserDialogsProviderObserver* aObserver )
    91 :   iCoeEnv( *CCoeEnv::Static() ), 
    90 :   iCoeEnv( *CCoeEnv::Static() ), 
    92     iObserver( aObserver ),
    91     iObserver( aObserver ),
    93     iResourceLoader( iCoeEnv ),    
    92     iResourceLoader( iCoeEnv ),    
    94     iResourceOpened( EFalse ),    
    93     iResourceOpened( EFalse )
    95     iErrResourceLoader( iCoeEnv ),    
       
    96     iErrResourceOpened( EFalse )    
       
    97 	{
    94 	{
    98 	}
    95 	}
    99 
    96 
   100 //-----------------------------------------------------------------------------
    97 //-----------------------------------------------------------------------------
   101 //	CBrowserDialogsProvider* CBrowserDialogsProvider::NewL
    98 //	CBrowserDialogsProvider* CBrowserDialogsProvider::NewL
   130 //
   127 //
   131 //-----------------------------------------------------------------------------
   128 //-----------------------------------------------------------------------------
   132 CBrowserDialogsProvider::~CBrowserDialogsProvider()
   129 CBrowserDialogsProvider::~CBrowserDialogsProvider()
   133 	{
   130 	{
   134 	iResourceLoader.Close();
   131 	iResourceLoader.Close();
   135 	iErrResourceLoader.Close();
       
   136 
   132 
   137 	// Delete any dialogs
   133 	// Delete any dialogs
   138 	CancelAll();
   134 	CancelAll();
   139 	
   135 	
   140 	// Clean up tooltip
   136 	// Clean up tooltip
   150 //
   146 //
   151 //-----------------------------------------------------------------------------
   147 //-----------------------------------------------------------------------------
   152 EXPORT_C void CBrowserDialogsProvider::DialogNotifyErrorL( TInt aErrCode )
   148 EXPORT_C void CBrowserDialogsProvider::DialogNotifyErrorL( TInt aErrCode )
   153 	{
   149 	{
   154     TInt httpErr = KBrCtlHttpErrorsOffset - aErrCode;
   150     TInt httpErr = KBrCtlHttpErrorsOffset - aErrCode;
   155 
   151 	CTextResolver* textresolver = CTextResolver::NewLC(); 
       
   152 	TPtrC msg;
       
   153 		
   156     switch ( httpErr )
   154     switch ( httpErr )
   157         {
   155         {
   158         case EHttpMultipleChoices: 
   156         case EHttpMultipleChoices: 
   159         case EHttpMovedPermanently:
   157         case EHttpMovedPermanently:
   160         case EHttpMovedTemporarily:
   158         case EHttpMovedTemporarily:
   161         case EHttpTemporaryRedirect:
   159         case EHttpTemporaryRedirect:
   162             {
   160             {
   163             // Handle the redirect error dialog
   161             // Id for r_nw_stat_too_many_redirects is -20019, browser errors start at -20000 
   164             HBufC* msg = NULL;
   162             msg.Set( textresolver->ResolveErrorString( KErrTooManyRedirects ));  
   165             msg = StringLoader::LoadLC( R_NW_STAT_TOO_MANY_REDIRECTS );
       
   166             DialogNoteL( *msg );
       
   167     		CleanupStack::PopAndDestroy();	// msg
       
   168             break;
   163             break;
   169             }
   164             }
   170         default:
   165         default:
   171             {
   166             {
   172             // Handle all others as system error dialog
   167             // Handle all others as system error dialog
   173         	iCoeEnv.HandleError( aErrCode );
   168             msg.Set( textresolver->ResolveErrorString( aErrCode ));            
   174         	break;
   169         	  break;
   175             }
   170             }
   176         }   // end of switch
   171         }   // end of switch
   177 	
   172 	
       
   173        DialogNoteL( msg );
       
   174        CleanupStack::PopAndDestroy(); //textresolver
       
   175        
   178 	if ( iObserver )
   176 	if ( iObserver )
   179     	{
   177     	{
   180     	iObserver->ReportDialogEventL( 
   178     	iObserver->ReportDialogEventL( 
   181     	                            MBrowserDialogsProviderObserver::ENotifyError,
   179     	                            MBrowserDialogsProviderObserver::ENotifyError,
   182     	                            aErrCode );
   180     	                            aErrCode );
   190 //-----------------------------------------------------------------------------
   188 //-----------------------------------------------------------------------------
   191 EXPORT_C void CBrowserDialogsProvider::DialogNotifyHttpErrorL(
   189 EXPORT_C void CBrowserDialogsProvider::DialogNotifyHttpErrorL(
   192 								TInt aErrCode, const TDesC& /*aUri*/ )
   190 								TInt aErrCode, const TDesC& /*aUri*/ )
   193 	{
   191 	{
   194     TInt httpErr = KBrCtlHttpErrorsOffset - aErrCode;
   192     TInt httpErr = KBrCtlHttpErrorsOffset - aErrCode;
       
   193     CTextResolver* textresolver = CTextResolver::NewLC(); 
       
   194 	TPtrC msg;	
   195 
   195 
   196     switch ( httpErr )
   196     switch ( httpErr )
   197         {
   197         {
   198         case EHttpMultipleChoices: 
   198         case EHttpMultipleChoices: 
   199         case EHttpMovedPermanently:
   199         case EHttpMovedPermanently:
   200         case EHttpMovedTemporarily:
   200         case EHttpMovedTemporarily:
   201         case EHttpTemporaryRedirect:
   201         case EHttpTemporaryRedirect:
   202             {
   202             {
   203             // Handle the redirect error dialog
   203             // Handle the redirect error dialog browser errors start from -20000 ,id for r_nw_stat_malformed_url is -20019.
   204             HBufC* msg = NULL;
   204 			msg.Set( textresolver->ResolveErrorString( KErrTooManyRedirects ));  
   205             msg = StringLoader::LoadLC( R_NW_STAT_TOO_MANY_REDIRECTS );
   205 			DialogNoteL( msg );
   206             DialogNoteL( *msg );
   206             break;     
   207     		CleanupStack::PopAndDestroy();	// msg
       
   208             break;
       
   209             }
   207             }
       
   208         case EHttpBadGateway:
       
   209 	        {
       
   210     	    // Handle the unresolved dns name error dialog
       
   211     	    HBufC* msg = NULL;
       
   212         	msg = StringLoader::LoadLC( R_BROWSER_NOT_VALID_DNS_NAME);
       
   213 			DialogNoteL( *msg );			
       
   214 			CleanupStack::PopAndDestroy();	// msg
       
   215 			break;
       
   216         	}
   210         default:
   217         default:
   211             {
   218             {
   212             // Handle all others as system error dialog
   219             // Handle all others as system error dialog
   213         	iCoeEnv.HandleError( aErrCode );
   220             msg.Set( textresolver->ResolveErrorString( aErrCode ));     
   214         	break;
   221 			DialogNoteL( msg );
       
   222             break;
   215             }
   223             }
   216         }   // end of switch
   224         }   // end of switch			 
       
   225     CleanupStack::PopAndDestroy(); //textresolver    
   217 	
   226 	
   218     if ( iObserver )
   227     if ( iObserver )
   219         {
   228         {
   220         iObserver->ReportDialogEventL( 
   229         iObserver->ReportDialogEventL( 
   221                                 MBrowserDialogsProviderObserver::ENotifyHttpError,
   230                                 MBrowserDialogsProviderObserver::ENotifyHttpError,
  1218         else
  1227         else
  1219             {
  1228             {
  1220             User::Leave( error );
  1229             User::Leave( error );
  1221             }
  1230             }
  1222         }
  1231         }
  1223 
       
  1224     if ( !iErrResourceOpened )
       
  1225         {
       
  1226         // Add error resource file.
       
  1227         TParse* errfp = new(ELeave) TParse(); 
       
  1228 
       
  1229         TInt err = errfp->Set( KErrorResDirAndFile, 
       
  1230                                &KDC_RESOURCE_FILES_DIR, 
       
  1231                                NULL ); 
       
  1232         if ( err != KErrNone)
       
  1233             {
       
  1234             User::Leave( err );
       
  1235             }   
       
  1236     
       
  1237         TFileName errResourceFileName = errfp->FullName();
       
  1238         delete errfp;
       
  1239 
       
  1240         TRAPD( error, iErrResourceLoader.OpenL( errResourceFileName ) );
       
  1241         if ( !error )
       
  1242             {
       
  1243             iErrResourceOpened = ETrue;
       
  1244             }
       
  1245         else
       
  1246             {
       
  1247             User::Leave( error );
       
  1248             }
       
  1249         }
       
  1250     }
  1232     }
  1251 
  1233 
  1252 
  1234 
  1253 // -----------------------------------------------------------------------------
  1235 // -----------------------------------------------------------------------------
  1254 // CBrowserDialogsProvider::DriveReady
  1236 // CBrowserDialogsProvider::DriveReady