internetradio2.0/dataprovidersrc/irlogodownloadengine.cpp
changeset 0 09774dfdd46b
child 3 ee64f059b8e1
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Engine to fetch the logos 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknnotewrappers.h> 
       
    20 
       
    21 #include "irlogodownloadengine.h"
       
    22 #include "irnetworkcontroller.h"
       
    23 #include "ircachemgmt.h"
       
    24 #include "irhttprequestdata.h"
       
    25 #include "irpreset.h"
       
    26 #include "irdebug.h"
       
    27 #include "irdataproviderconstants.h"
       
    28 #include "iractivenetworkobserver.h"
       
    29 
       
    30 
       
    31 
       
    32 _LIT(KLogoX, "?x=");
       
    33 _LIT(KLogoY, "&y=");
       
    34 const TInt KPresetsArrayMaxLength = 50;
       
    35 const TInt KLogoSize = 59;
       
    36 const TInt KParameterSize = 12;
       
    37 const TInt KTen = 10;
       
    38 const TInt KCacheAvailable = 4;
       
    39 const TInt KLogo = 4;
       
    40 const TInt KStatusOK = 200;
       
    41 const TInt KStatusMultipleChoices = 300;
       
    42 const TInt KStatusNotModified = 304;
       
    43 const TInt KStatusGatewayTimeout = 504;
       
    44 
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CIRLogoDownloadEngine::NewL()
       
    48 // Creates instance of CIRLogoDownloadEngine.
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C CIRLogoDownloadEngine* CIRLogoDownloadEngine::NewL()
       
    52 	{
       
    53 	IRLOG_DEBUG( "CIRLogoDownloadEngine::NewL - Entering" );
       
    54     CIRLogoDownloadEngine* self = new(ELeave) CIRLogoDownloadEngine();
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop(self);
       
    58     IRLOG_DEBUG( "CIRLogoDownloadEngine::NewL - Exiting" );
       
    59     return self;
       
    60 	}
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CIRLogoDownloadEngine::CIRLogoDownloadEngine()
       
    64 // Standard C++ constructor
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CIRLogoDownloadEngine::CIRLogoDownloadEngine()
       
    68 	{
       
    69 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CIRLogoDownloadEngine " );
       
    70 	//code here, if needed
       
    71 	}
       
    72 	
       
    73 	
       
    74 	
       
    75 // ---------------------------------------------------------------------------
       
    76 // CIRLogoDownloadEngine::~CIRLogoDownloadEngine()
       
    77 // Destructs instance of CIRLogoDownloadEngine.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 EXPORT_C CIRLogoDownloadEngine::~CIRLogoDownloadEngine()
       
    81 	{
       
    82 	IRLOG_DEBUG( "CIRLogoDownloadEngine::~CIRLogoDownloadEngine - Entering" );
       
    83     if(iReqBody)
       
    84     	{
       
    85     	delete iReqBody;
       
    86     	iReqBody = NULL;
       
    87     	}
       
    88     if(iRespBody)
       
    89     	{
       
    90     	delete iRespBody;
       
    91     	iRespBody = NULL;
       
    92     	}
       
    93 	CancelTransaction();
       
    94 	iLogoSession.Close();
       
    95 	
       
    96 	if(iCopyPreset)
       
    97 		{
       
    98 		delete iCopyPreset;
       
    99 		}
       
   100 	if(iCacheTempPreset)
       
   101 		{
       
   102 		delete iCacheTempPreset;			
       
   103 		}
       
   104 	if(iTempPreset)
       
   105 		{
       
   106 		delete iTempPreset;			
       
   107 		}
       
   108 	if(iPresetArray)
       
   109 		{
       
   110 		iPresetArray->ResetAndDestroy();
       
   111 		}
       
   112 	delete iPresetArray;
       
   113 	if(iObserverArray)
       
   114 		{
       
   115 		delete iObserverArray;
       
   116 		iObserverArray = NULL;
       
   117 		}
       
   118 	if(iReqFromArray)
       
   119 		{
       
   120 		delete iReqFromArray;
       
   121 		iReqFromArray = NULL;
       
   122 		}
       
   123 	if(iCachePresetArray)
       
   124 		{
       
   125 		iCachePresetArray->ResetAndDestroy();
       
   126 		}
       
   127 	delete iCachePresetArray;
       
   128 	if(iCacheObserverArray)
       
   129 		{
       
   130 		delete iCacheObserverArray;
       
   131 		iCacheObserverArray = NULL;
       
   132 		}
       
   133 	if(iCacheReqFromArray)
       
   134 		{
       
   135 		delete iCacheReqFromArray;
       
   136 		iCacheReqFromArray = NULL;
       
   137 		}
       
   138 	if(iIRNetworkControllerHandle)
       
   139     	{
       
   140     	iIRNetworkControllerHandle->DeleteActiveNetworkObserver(*this);
       
   141     	iIRNetworkControllerHandle->Close();
       
   142         }		
       
   143     if (iCache)
       
   144 	    {
       
   145 	    iCache->RemoveObserver(this);
       
   146 	    iCache->Close();
       
   147 	    }
       
   148 	if( iResponseHeaders )
       
   149 		{
       
   150         delete iResponseHeaders;
       
   151 		}
       
   152 	IRLOG_DEBUG( "CIRLogoDownloadEngine::~CIRLogoDownloadEngine - Exiting" );
       
   153 	}
       
   154 
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CIRLogoDownloadEngine::ConstructL()
       
   159 // 2nd phase construction
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CIRLogoDownloadEngine::ConstructL()
       
   163 	{
       
   164 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ConstructL - Entering" );
       
   165 	iPresetArray = new (ELeave) CArrayPtrFlat<CIRIsdsPreset>(KPresetsArrayMaxLength);
       
   166 	iObserverArray = new (ELeave) CArrayPtrFlat<MLogoDownloadObserver>(KPresetsArrayMaxLength);
       
   167 	iReqFromArray = new (ELeave) CArrayFixFlat<TInt>(KPresetsArrayMaxLength);
       
   168 	iCachePresetArray = new (ELeave) CArrayPtrFlat<CIRIsdsPreset>(KPresetsArrayMaxLength);
       
   169 	iCacheObserverArray = new (ELeave) CArrayPtrFlat<MLogoDownloadObserver>(KPresetsArrayMaxLength);
       
   170 	iCacheReqFromArray = new (ELeave) CArrayFixFlat<TInt>(KPresetsArrayMaxLength);
       
   171 	
       
   172 	iPresetArrayPos = 0;
       
   173 	iReqFromArrayPos = 0;
       
   174 	iObserverArrayPos = 0;
       
   175 	iCachePresetArrayPos = 0;
       
   176 	iCacheReqFromArrayPos = 0;
       
   177 	iCacheObserverArrayPos = 0;
       
   178 	iImageIndex = 0; //using temporarily till the isds provides urls
       
   179 
       
   180 	iPresetModifiedStatus = EFalse;
       
   181 	iFirstTime = ETrue;
       
   182 	iIRNetworkControllerHandle = CIRNetworkController::OpenL();
       
   183 	iIRNetworkControllerHandle->RegisterActiveNetworkObserverL(*this);
       
   184 	iCache = CIRCacheMgmt::OpenL(*this);
       
   185 	iCache->AddObserverL(this);
       
   186 	iResponseHeaders = new ( ELeave ) CIRHttpResponseData;
       
   187 
       
   188 	//change to use the new session for logo downloading
       
   189 	TRAPD( LeaveValue, iLogoSession.OpenL() );
       
   190     if ( LeaveValue != KErrNone )
       
   191         {
       
   192         // Most common error; no access point configured, and session creation
       
   193         // leaves with KErrNotFound.
       
   194         // Load a string from the resource file and add the error code to string
       
   195         User::Leave( LeaveValue );
       
   196         }
       
   197     IRLOG_DEBUG( "CIRLogoDownloadEngine::ConstructL - Exiting" );
       
   198 	}
       
   199 
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // CIRLogoDownloadEngine::IsRunning()
       
   203 // To know the status of downloading logo
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 EXPORT_C TBool CIRLogoDownloadEngine::IsRunning() const
       
   207 	{
       
   208 	IRLOG_DEBUG( "CIRLogoDownloadEngine::IsRunning" );
       
   209     return iRunning;
       
   210 	}
       
   211 
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CIRLogoDownloadEngine::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
       
   215 //                              const TDesC8& aHdrValue)
       
   216 // to set the headers of the http transaction
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CIRLogoDownloadEngine::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
       
   220 					 const TDesC8& aHdrValue) const
       
   221 	{
       
   222 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SetHeaderL - Entering" );
       
   223 	RStringF valStr = iLogoSession.StringPool().OpenFStringL(aHdrValue);
       
   224 	CleanupClosePushL(valStr);
       
   225 	THTTPHdrVal val(valStr);
       
   226 	aHeaders.SetFieldL(iLogoSession.StringPool().StringF(aHdrField, RHTTPSession::GetTable()), val);
       
   227 	CleanupStack::PopAndDestroy(&valStr); // valStr
       
   228 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SetHeaderL - Exiting" );
       
   229 	}
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CIRLogoDownloadEngine::SetFavDbInstance(CIRFavoritesDb* aFavDb)
       
   233 // To set the favorites db instance
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 EXPORT_C void CIRLogoDownloadEngine::SetFavDbInstance(CIRFavoritesDb* aFavDb)
       
   237 	{
       
   238 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SetFavDbInstance - Entering" );
       
   239 	iFavDb = aFavDb;
       
   240 	iFavDb->AddObserver( *this );
       
   241 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SetFavDbInstance - Exiting" );
       
   242 	}
       
   243 
       
   244 
       
   245 // ----------------------------------------------------------------------------------
       
   246 // CIRLogoDownloadEngine::SendRequestL(CIRIsdsPreset* aPreset,TInt aXValue,TInt aYValue)
       
   247 // API is called from the SearchResultsView for to download logo while doing Add to Favorites
       
   248 // ----------------------------------------------------------------------------------
       
   249 //
       
   250 EXPORT_C void CIRLogoDownloadEngine::SendRequestL(CIRIsdsPreset* aPreset,TInt aXValue,TInt aYValue)
       
   251 	{
       
   252 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendRequestL - Entering" );
       
   253 	if(!iCheckingCache)
       
   254 		{
       
   255 		++iImageIndex;
       
   256 		iCheckingCache = ETrue;
       
   257 		iCacheReqFrom = 0;
       
   258 		if(iCacheTempPreset)
       
   259 			{
       
   260 			delete iCacheTempPreset;				
       
   261 			}
       
   262 		iCacheTempPreset = NULL;
       
   263 		iCacheTempPreset = CIRIsdsPreset::NewL();
       
   264 		*iCacheTempPreset = *aPreset;
       
   265 
       
   266 		if(iCacheTempPreset->GetImgUrl().Length() != 0)
       
   267 			{
       
   268 			if((aXValue > 0)&&(aYValue > 0))
       
   269 				{
       
   270 				//Append the parameters(width,height) of the logo size to imgUrl
       
   271 				TInt size = iCacheTempPreset->GetImgUrl().Length() + KParameterSize;
       
   272 				RBuf urlWithSize;
       
   273 				urlWithSize.Create(size);
       
   274 				urlWithSize.Copy(iCacheTempPreset->GetImgUrl());
       
   275 				urlWithSize.Append(KLogoX);
       
   276 				urlWithSize.AppendNum(aXValue);
       
   277 				urlWithSize.Append(KLogoY);
       
   278 				urlWithSize.AppendNum(aYValue);
       
   279 				
       
   280 				//set the imgUrl with parameters to the preset
       
   281 				iCacheTempPreset->SetImgUrl(urlWithSize);
       
   282 				urlWithSize.Close();
       
   283 				}
       
   284 			//This method checks whether the logo is available
       
   285  			// for the request made
       
   286 			iForceGet = EFalse; 			
       
   287 			CheckCacheForLogoL(0);
       
   288 			}
       
   289 		else
       
   290 			{
       
   291 			//imgUrl doesnt exist in the Preset
       
   292 		    iCheckingCache = EFalse;
       
   293 			return;			
       
   294 			}
       
   295 
       
   296 		iCheckingCache = EFalse;
       
   297 		if(!iLogoCached)	
       
   298 			{
       
   299 			FetchLogoDataL(iCacheTempPreset);				
       
   300 			}
       
   301 		}
       
   302 	else
       
   303 		{
       
   304 		CIRIsdsPreset* tempPreset;
       
   305 		tempPreset = CIRIsdsPreset::NewL();
       
   306 		*tempPreset = *aPreset;
       
   307 		if(tempPreset->GetImgUrl().Length() != 0)
       
   308 			{
       
   309 			if((aXValue > 0)&&(aYValue > 0))
       
   310 				{
       
   311 				//Append the parameters(width,height) of the logo size to imgUrl
       
   312 				TInt size = tempPreset->GetImgUrl().Length() + KParameterSize;
       
   313 				RBuf urlWithSize;
       
   314 				urlWithSize.Create(size);
       
   315 				urlWithSize.Copy(tempPreset->GetImgUrl());
       
   316 				urlWithSize.Append(KLogoX);
       
   317 				urlWithSize.AppendNum(aXValue);
       
   318 				urlWithSize.Append(KLogoY);
       
   319 				urlWithSize.AppendNum(aYValue);
       
   320 				
       
   321 				//set the imgUrl with parameters to the preset
       
   322 				tempPreset->SetImgUrl(urlWithSize);
       
   323 				urlWithSize.Close();				
       
   324 				}
       
   325 			}
       
   326 		iCachePresetArray->AppendL(tempPreset);
       
   327  		iCacheReqFromArray->AppendL(0);	
       
   328 		}	
       
   329 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendRequestL - Exiting" );
       
   330 	}
       
   331 
       
   332 
       
   333 EXPORT_C TBool CIRLogoDownloadEngine::isLogoCachedL(CIRIsdsPreset* aPreset, TInt aXValue, TInt aYValue)
       
   334 {
       
   335     TInt cached = 0;
       
   336     
       
   337     if(iCacheTempPreset)
       
   338     {
       
   339         delete iCacheTempPreset;
       
   340         iCacheTempPreset = NULL;
       
   341     }
       
   342     
       
   343     iCacheTempPreset = CIRIsdsPreset::NewL();
       
   344     *iCacheTempPreset = *aPreset;
       
   345     iCacheReqMade = EFalse;
       
   346     
       
   347     if (iCacheTempPreset->GetImgUrl().Length() != 0)
       
   348     {
       
   349         if ((aXValue > 0) && (aYValue > 0))
       
   350         {
       
   351             //Append the parameters(width,height) of the logo size to imgUrl
       
   352             TInt size = iCacheTempPreset->GetImgUrl().Length() + KParameterSize;
       
   353             RBuf urlWithSize;
       
   354             urlWithSize.Create(size);
       
   355             urlWithSize.Copy(iCacheTempPreset->GetImgUrl());
       
   356             urlWithSize.Append(KLogoX);
       
   357             urlWithSize.AppendNum(aXValue);
       
   358             urlWithSize.Append(KLogoY);
       
   359             urlWithSize.AppendNum(aYValue);
       
   360 
       
   361             //set the imgUrl with parameters to the preset
       
   362             iCacheTempPreset->SetImgUrl(urlWithSize);
       
   363             urlWithSize.Close();
       
   364         }
       
   365     }
       
   366     
       
   367     iCache->CheckCacheL(KLogo,iCacheTempPreset->GetImgUrl(),EFalse,cached);
       
   368     
       
   369     return (CIRCacheMgmt::ECacheUseable == cached)?ETrue:EFalse;     
       
   370 }
       
   371 // ----------------------------------------------------------------------------------------------
       
   372 // CIRLogoDownloadEngine::SendRequestL(CIRIsdsPreset* aPreset,MLogoDownloadObserver* aLogoHandle,
       
   373 //													TInt aNPVReq,TInt aXValue,TInt aYValue)
       
   374 // API is called from several views for to download logo 
       
   375 // ----------------------------------------------------------------------------------------------
       
   376 //
       
   377 EXPORT_C void CIRLogoDownloadEngine::SendRequestL(CIRIsdsPreset* aPreset,
       
   378 			MLogoDownloadObserver* aLogoHandle,TInt aNPVReq,TInt aXValue,TInt aYValue)
       
   379 	{
       
   380 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendRequestL - Entering" );
       
   381 	if(aPreset->GetChannelType()==0)
       
   382 		{
       
   383 		aLogoHandle->PresetLogoDownloadedL(aPreset);
       
   384 		}
       
   385 	else if(!iCheckingCache)
       
   386 		{
       
   387 		++iImageIndex;
       
   388 		iCheckingCache = ETrue;
       
   389 		if(aNPVReq==2)
       
   390 			{
       
   391 			iCacheReqFrom=2;			
       
   392 			}
       
   393 		else
       
   394 			{
       
   395 			iCacheReqFrom=1;			
       
   396 			}
       
   397 
       
   398 		if(iCacheTempPreset)
       
   399 			{
       
   400 			delete iCacheTempPreset;
       
   401 			iCacheTempPreset = NULL;				
       
   402 			}
       
   403 		iCacheTempPreset = CIRIsdsPreset::NewL();
       
   404 		*iCacheTempPreset = *aPreset;
       
   405 		iCacheTempLogoHandle = aLogoHandle;
       
   406 		
       
   407 		if(iCacheTempPreset->GetImgUrl().Length() != 0)
       
   408 			{
       
   409 			if((aXValue > 0)&&(aYValue > 0))
       
   410 				{
       
   411 				//Append the parameters(width,height) of the logo size to imgUrl
       
   412 				TInt size = iCacheTempPreset->GetImgUrl().Length() + KParameterSize;
       
   413 				RBuf urlWithSize;
       
   414 				urlWithSize.Create(size);
       
   415 				urlWithSize.Copy(iCacheTempPreset->GetImgUrl());
       
   416 				urlWithSize.Append(KLogoX);
       
   417 				urlWithSize.AppendNum(aXValue);
       
   418 				urlWithSize.Append(KLogoY);
       
   419 				urlWithSize.AppendNum(aYValue);
       
   420 				
       
   421 				//set the imgUrl with parameters to the preset
       
   422 				iCacheTempPreset->SetImgUrl(urlWithSize);
       
   423 				urlWithSize.Close();
       
   424 				}
       
   425 			if(iCacheReqFrom==1 || iCacheReqFrom==2)
       
   426 				{
       
   427 				//This method checks whether the logo is available
       
   428 		 		// for the request made
       
   429 				iForceGet = EFalse;		 		
       
   430 				CheckCacheForLogoL(0);	
       
   431 				}
       
   432 /*			else if(iCacheReqFrom==2)
       
   433 				{
       
   434 				//the request has come from NowPlayingView(NPV)
       
   435 				//dont check for logo availability in cache
       
   436 				//download the logo freshly
       
   437 				iLogoCached=EFalse;								
       
   438 				}
       
   439 */			}
       
   440 		else
       
   441 			{
       
   442 			//imgUrl doesnt exist in the Preset
       
   443 		    iCheckingCache = EFalse;
       
   444 			return;			
       
   445 			}
       
   446 		
       
   447 		iCheckingCache = EFalse;
       
   448 		if(!iLogoCached)	
       
   449 			{
       
   450 			FetchLogoDataL(iCacheTempPreset,aLogoHandle,iCacheReqFrom);				
       
   451 			}
       
   452 		}
       
   453 	else
       
   454 		{
       
   455 		CIRIsdsPreset* tempPreset;
       
   456 		tempPreset = CIRIsdsPreset::NewL();
       
   457 		*tempPreset = *aPreset;
       
   458 		if(tempPreset->GetImgUrl().Length() != 0)
       
   459 			{
       
   460 			if((aXValue > 0)&&(aYValue > 0))
       
   461 				{
       
   462 				//Append the parameters(width,height) of the logo size to imgUrl
       
   463 				TInt size = tempPreset->GetImgUrl().Length() + KParameterSize;
       
   464 				RBuf urlWithSize;
       
   465 				urlWithSize.Create(size);
       
   466 				urlWithSize.Copy(tempPreset->GetImgUrl());
       
   467 				urlWithSize.Append(KLogoX);
       
   468 				urlWithSize.AppendNum(aXValue);
       
   469 				urlWithSize.Append(KLogoY);
       
   470 				urlWithSize.AppendNum(aYValue);
       
   471 				
       
   472 				//set the imgUrl with parameters to the preset
       
   473 				tempPreset->SetImgUrl(urlWithSize);
       
   474 				urlWithSize.Close();				
       
   475 				}
       
   476 			}
       
   477 		iCachePresetArray->AppendL(tempPreset);
       
   478  		iCacheObserverArray->AppendL(aLogoHandle);
       
   479  		if(aNPVReq == 2)
       
   480 	 		{
       
   481 	 		iCacheReqFromArray->AppendL(2);		
       
   482 	 		}
       
   483  		else
       
   484 	 		{
       
   485 	 		iCacheReqFromArray->AppendL(1);		
       
   486 	 		}
       
   487 		}
       
   488 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendRequestL - Exiting" );
       
   489 	}
       
   490 
       
   491 
       
   492 
       
   493 // ----------------------------------------------------------------------------------
       
   494 // CIRLogoDownloadEngine::GetCacheLogoL(TDesC& aUrl,TInt& aStatus)
       
   495 // takes the url as a parameter and returns the logo data which is in cache
       
   496 // this API is called form the search results for to display logo on the view
       
   497 // ----------------------------------------------------------------------------------
       
   498 //
       
   499 EXPORT_C void CIRLogoDownloadEngine::GetCacheLogoL(const TDesC& aUrl,TInt& aStatus)
       
   500 	{
       
   501 	IRLOG_DEBUG( "CIRLogoDownloadEngine::GetCacheLogoL - Entering" );
       
   502 	iSendingLogo=2;
       
   503 	iResult = 0;
       
   504 	iForceGet = EFalse;
       
   505 	//2 means, this API is called for the search results view
       
   506 	iCacheReqMade = ETrue;
       
   507 	iCache->CheckCacheL(KLogo,aUrl,iForceGet,iResult);		
       
   508 	aStatus = iResult;
       
   509 	IRLOG_DEBUG( "CIRLogoDownloadEngine::GetCacheLogoL - Exiting" );
       
   510 
       
   511 	}
       
   512 	
       
   513 	
       
   514 // ----------------------------------------------------------------------------------
       
   515 // CIRLogoDownloadEngine::SendCacheLogo()
       
   516 // sends the logo which is cached
       
   517 // ----------------------------------------------------------------------------------
       
   518 //
       
   519 EXPORT_C TDesC8& CIRLogoDownloadEngine::SendCacheLogo()
       
   520 	{
       
   521 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendCacheLogo" );
       
   522 	return iCache->iLogoData;
       
   523 	}
       
   524 
       
   525 
       
   526 
       
   527 
       
   528 // ------------------------------------------------------------------------
       
   529 // CIRLogoDownloadEngine::FetchLogoDataL(CIRIsdsPreset* aPreset)
       
   530 // API is used to download logo from isds/internet
       
   531 // called in the API SendRequestL(CIRIsdsPreset* aPreset)
       
   532 // ------------------------------------------------------------------------
       
   533 //
       
   534 void CIRLogoDownloadEngine::FetchLogoDataL(CIRIsdsPreset* aPreset)
       
   535 	{
       
   536 	IRLOG_DEBUG( "CIRLogoDownloadEngine::FetchLogoDataL - Entering" );
       
   537  	if(!iRunning)
       
   538 	 	{
       
   539 
       
   540 	  	iTempReqFrom = 0;//which means the request came from SearchView while doing Add to Favorite
       
   541 	 	if( iReqBody )
       
   542 		 	{
       
   543 		 	delete iReqBody;
       
   544 		    iReqBody = NULL;
       
   545 		 	}
       
   546 	    if( iRespBody )
       
   547 		    {
       
   548 		    delete iRespBody;
       
   549 		    iRespBody = NULL;
       
   550 		    }
       
   551 		if(iTempPreset)
       
   552 			{
       
   553 			delete iTempPreset;
       
   554 			iTempPreset = NULL;				
       
   555 			}
       
   556 		iTempPreset = CIRIsdsPreset::NewL();
       
   557 	    *iTempPreset = *aPreset;
       
   558    	    if(iTempPreset->GetImgUrl().Length() != 0)
       
   559 		    {
       
   560 	    	IssueLogoDownloadRequestL();
       
   561 		   	}
       
   562 	    else /*ImgUrl doesnt exist in the iTempPreset*/
       
   563 		    {
       
   564 	    	//simply ignore it
       
   565 		    }
       
   566 	    }
       
   567  	else
       
   568 	 	{
       
   569 	 	CIRIsdsPreset* tempPreset;
       
   570 	 	tempPreset = CIRIsdsPreset::NewL();
       
   571 	 	CleanupStack::PushL(tempPreset);
       
   572 	 	*tempPreset = *aPreset;
       
   573 	 	iPresetArray->AppendL(tempPreset);
       
   574 	 	CleanupStack::Pop(tempPreset);
       
   575  		iReqFromArray->AppendL(0);
       
   576 	 	}
       
   577  	IRLOG_DEBUG( "CIRLogoDownloadEngine::FetchLogoDataL - Exiting" );
       
   578 	}
       
   579 
       
   580 
       
   581 // -------------------------------------------------------------------------------------------------
       
   582 // CIRLogoDownloadEngine::FetchLogoDataL(CIRIsdsPreset* aPreset,MLogoDownloadObserver* aLogoHandle)
       
   583 // API is used to download logo from isds/internet
       
   584 // called in the API SendRequestL(CIRIsdsPreset* aPreset,MLogoDownloadObserver* aLogoHandle)
       
   585 // -------------------------------------------------------------------------------------------------
       
   586 //
       
   587 void CIRLogoDownloadEngine::FetchLogoDataL(CIRIsdsPreset* aPreset,
       
   588 				MLogoDownloadObserver* aLogoHandle,TInt aNPVReq)
       
   589 	{
       
   590 	IRLOG_DEBUG( "CIRLogoDownloadEngine::FetchLogoDataL - Entering" );
       
   591 	if(!iRunning)
       
   592 	 	{
       
   593 	 	if(aNPVReq==2)
       
   594 		 	{
       
   595 		 	iTempReqFrom = 2;//which means the request came from NowPlayingView	 		
       
   596 		 	}
       
   597 	 	else
       
   598 		 	{
       
   599 		 	iTempReqFrom = 1;//which means the request came from other than NowPlayingView	 		
       
   600 		 	}
       
   601 
       
   602 		iTempLogoHandle = aLogoHandle;
       
   603 		if( iReqBody )
       
   604 		 	{
       
   605 		 	delete iReqBody;
       
   606 		    iReqBody = NULL;
       
   607 		 	}
       
   608 	    if( iRespBody )
       
   609 		    {
       
   610 		    delete iRespBody;
       
   611 		    iRespBody = NULL;
       
   612 		    }
       
   613 		if(iTempPreset)
       
   614 			{
       
   615 			delete iTempPreset;
       
   616 			iTempPreset = NULL;				
       
   617 			}
       
   618 		iTempPreset = CIRIsdsPreset::NewL();
       
   619 	    *iTempPreset = *aPreset;
       
   620 	    if(iTempPreset->GetImgUrl().Length() != 0)
       
   621 		    {
       
   622 	    	IssueLogoDownloadRequestL();
       
   623 			}
       
   624 	    else /*ImgUrl doesnt exist in the iTempPreset*/
       
   625 		    {
       
   626 	    	//simply ignore it
       
   627 		    }
       
   628 	    }
       
   629  	else
       
   630 	 	{
       
   631 	 	CIRIsdsPreset* tempPreset;
       
   632 	 	tempPreset = CIRIsdsPreset::NewL();
       
   633 	 	CleanupStack::PushL(tempPreset);
       
   634 	 	*tempPreset = *aPreset;
       
   635 	 	iPresetArray->AppendL(tempPreset);
       
   636 	 	CleanupStack::Pop(tempPreset);
       
   637 		iObserverArray->AppendL(aLogoHandle);
       
   638 		if(aNPVReq==2)
       
   639 			{
       
   640 	 		iReqFromArray->AppendL(2);
       
   641 			}
       
   642 		else
       
   643 			{
       
   644 	 		iReqFromArray->AppendL(1);
       
   645 			}
       
   646 	 	}
       
   647 	IRLOG_DEBUG( "CIRLogoDownloadEngine::FetchLogoDataL - Exiting" );
       
   648 	}
       
   649 
       
   650 
       
   651 // ----------------------------------------------------------------------------------
       
   652 // CIRLogoDownloadEngine::CheckCacheForLogoL(TInt aValue)
       
   653 // Checks the cache whether the logo is available or not
       
   654 // ----------------------------------------------------------------------------------
       
   655 //
       
   656 void CIRLogoDownloadEngine::CheckCacheForLogoL(TInt aValue)
       
   657 	{
       
   658 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CheckCacheForLogoL - Entering" );
       
   659 	iSendingLogo=aValue;
       
   660 	iResult = 0;
       
   661 	if(iSendingLogo==0)//0 means, this API is called for the usecase of checking cache
       
   662 		{
       
   663 		iCacheReqMade = ETrue;
       
   664 		iCache->CheckCacheL(KLogo,iCacheTempPreset->GetImgUrl(),iForceGet,iResult);		
       
   665 		}
       
   666 	else if(iSendingLogo==1)//1 means, this API is called for the usecase of downloading logo
       
   667 		{
       
   668 		iCacheReqMade = ETrue;
       
   669 		iCache->CheckCacheL(KLogo,iTempPreset->GetImgUrl(),iForceGet,iResult);		
       
   670 		}
       
   671 	if((iResult == 0))//not available in the cache
       
   672 		{
       
   673 		iLogoCached = EFalse;
       
   674 		iIsConditionalGET = EFalse;
       
   675 		}
       
   676 	else if(iResult == -1)//cache is stale/not useable
       
   677 		{
       
   678 		iLogoCached = EFalse;
       
   679 		iIsConditionalGET = ETrue;			
       
   680 		}
       
   681 	else if(iResult == 1)//cache is useable
       
   682 		{
       
   683 		iLogoCached = ETrue;	
       
   684 		}
       
   685 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CheckCacheForLogoL - Exiting" );
       
   686 	}
       
   687 
       
   688 
       
   689 // ----------------------------------------------------------------------------------
       
   690 // CIRLogoDownloadEngine::IssueLogoDownloadRequest()
       
   691 // submits the transaction for to download the logo
       
   692 // ----------------------------------------------------------------------------------
       
   693 //
       
   694 void CIRLogoDownloadEngine::IssueLogoDownloadRequestL()
       
   695 	{
       
   696 	IRLOG_DEBUG( "CIRLogoDownloadEngine::IssueLogoDownloadRequestL - Entering" );
       
   697 	///////////////////////////////////////////////////////////////////////////////////
       
   698 	//This piece of code is for selecting the access point which is already
       
   699 	//set at the begining of the application.  To download the logo the same
       
   700 	//accesse point will be used.
       
   701 	
       
   702 	
       
   703 	
       
   704 		
       
   705 	
       
   706 	if(!iIRNetworkControllerHandle->GetNetworkStatus())
       
   707 		{
       
   708 		iIRNetworkControllerHandle->ChooseAccessPointL();
       
   709 		iLogoRequestPending = ETrue;
       
   710 		}
       
   711 	
       
   712 	else
       
   713 		{
       
   714 		if( iFirstTime )
       
   715 			{
       
   716 			iLogoSession.Close();
       
   717 			TRAPD( LeaveValue, iLogoSession.OpenL() );
       
   718 	    	if ( LeaveValue != KErrNone )
       
   719 	        {
       
   720 	        // Most common error; no access point configured, and session creation
       
   721 	        // leaves with KErrNotFound.
       
   722 	        // Load a string from the resource file and add the error code to string
       
   723 	        User::Leave( LeaveValue );
       
   724 	        }
       
   725 			// Set the HTTP connection properties
       
   726 		    RStringPool strP = iLogoSession.StringPool();
       
   727 		    RHTTPConnectionInfo connInfo = iLogoSession.ConnectionInfo();
       
   728 		    // RSocketServ Handle
       
   729 		    connInfo.SetPropertyL( strP.StringF( HTTP::EHttpSocketServ,
       
   730 				RHTTPSession::GetTable() ),
       
   731 				THTTPHdrVal( iIRNetworkControllerHandle->GetIRSocketServer().Handle() ) );
       
   732 
       
   733 		    // RConnection Handle
       
   734 		    TInt connPtr = REINTERPRET_CAST( TInt,
       
   735 				&( iIRNetworkControllerHandle->GetIRConnection() ) );
       
   736 		    connInfo.SetPropertyL( strP.StringF( HTTP::EHttpSocketConnection,
       
   737 				RHTTPSession::GetTable() ), THTTPHdrVal( connPtr ) );
       
   738 
       
   739 		    // HTTP Version ( Specify that i am using HTTP/1.1
       
   740 			connInfo.SetPropertyL( strP.StringF( HTTP::EVersion,
       
   741 				RHTTPSession::GetTable() ),
       
   742 				THTTPHdrVal( strP.StringF( HTTP::EHttp11, RHTTPSession::GetTable() ) ) );
       
   743 
       
   744 			// Set RHttpSession into NetworkController for logo byte counter
       
   745 			iIRNetworkControllerHandle->RegisterLogoDataTransferTrackerL( iLogoSession );
       
   746 
       
   747 			iFirstTime = EFalse;
       
   748 			}
       
   749 
       
   750 
       
   751 		HBufC8* buffertmp = HBufC8::NewLC( iTempPreset->GetImgUrl().Length() + 1 );
       
   752 		TPtr8 buffertmpPtr( buffertmp->Des() );
       
   753 		buffertmpPtr.Copy( iTempPreset->GetImgUrl() );
       
   754 
       
   755 		TUriParser8 uri;
       
   756 		uri.Parse(buffertmpPtr);
       
   757 		RStringF method = iLogoSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
       
   758 		iTransaction = iLogoSession.OpenTransactionL(uri, *this, method);
       
   759 		RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
       
   760 	    // Set the User-Agent header to UAProf string
       
   761 	    SetHeaderL( hdr, HTTP::EUserAgent,
       
   762 			   iIRNetworkControllerHandle->GetUAProfString()->Des() );
       
   763 
       
   764 		_LIT8(KAccept,"image/jpeg,image/png,image/gif");
       
   765 		SetHeaderL(hdr, HTTP::EAccept, KAccept);
       
   766 		SetHeaderL( hdr, HTTP::EAcceptLanguage, KAcceptLanguage );
       
   767 		
       
   768 		if(iIsConditionalGET)
       
   769 			{
       
   770 			RStringF valStr = iLogoSession.StringPool().OpenFStringL(iETag);
       
   771 			CleanupClosePushL(valStr);
       
   772 			THTTPHdrVal val(valStr);
       
   773 			hdr.SetFieldL(iLogoSession.StringPool().StringF(
       
   774 						HTTP::EIfNoneMatch, RHTTPSession::GetTable()), val);
       
   775 			CleanupStack::PopAndDestroy(&valStr); // valStr
       
   776 			}
       
   777 		CleanupStack::PopAndDestroy(buffertmp); // buffertmp
       
   778 		
       
   779 		//setting the member variable to zero
       
   780 		iRespBodySize = 0;
       
   781 		iTransaction.SubmitL();
       
   782 
       
   783 		iRunning = ETrue;
       
   784 		iLogoRequestPending = ETrue;
       
   785 		iState = ESendingEvent;
       
   786 		}
       
   787 	IRLOG_DEBUG( "CIRLogoDownloadEngine::IssueLogoDownloadRequestL - Exiting" );
       
   788 	}
       
   789 
       
   790 
       
   791 // ----------------------------------------------------------------------------------
       
   792 // CIRLogoDownloadEngine::CancelTransaction()
       
   793 // cancels the current transaction
       
   794 // ----------------------------------------------------------------------------------
       
   795 //
       
   796 EXPORT_C void CIRLogoDownloadEngine::CancelTransaction()
       
   797 	{
       
   798 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CancelTransaction - Entering" );
       
   799 	if(!iRunning)
       
   800 	    {
       
   801 		return;
       
   802 	    }
       
   803 	iTransaction.Close();
       
   804 	iRunning = EFalse;
       
   805 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CancelTransaction - Exiting" );
       
   806 	}
       
   807 
       
   808 
       
   809 // ----------------------------------------------------------------------------------
       
   810 // CIRLogoDownloadEngine::SendPresetWithLogoL()
       
   811 // sends the preset with logo to the requestors
       
   812 // ----------------------------------------------------------------------------------
       
   813 //
       
   814 EXPORT_C void CIRLogoDownloadEngine::SendPresetWithLogoL()
       
   815 	{
       
   816 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendPresetWithLogoL - Entering" );
       
   817 	//Logo has downloaded, so update the status of the variable iLogoRequestPending
       
   818 	iLogoRequestPending = EFalse;
       
   819 	//Remove the imgUrl with parameters from the Preset
       
   820 	//now set imgUrl without parameters in to the Preset
       
   821 	TInt sizeImgUrlWithPar = iTempPreset->GetImgUrl().Length();
       
   822 	TBool hasParameters = EFalse;
       
   823 	RBuf urlWithPar;
       
   824 	urlWithPar.Create(sizeImgUrlWithPar);
       
   825 	urlWithPar.Copy(iTempPreset->GetImgUrl());
       
   826 	RBuf tempBuf;
       
   827 	tempBuf.Create(sizeImgUrlWithPar);
       
   828 
       
   829 	TLex urlLex(urlWithPar);
       
   830 	for(;!urlLex.Eos();)
       
   831 		{
       
   832 		tempBuf.Zero();
       
   833 		while(urlLex.Peek() != '?' && !urlLex.Eos())		
       
   834 			{
       
   835 			tempBuf.Append(urlLex.Get());
       
   836 			}
       
   837 		if(urlLex.Peek() == '?')
       
   838 			{
       
   839 			hasParameters = ETrue;			
       
   840 			}
       
   841 		urlLex.Inc();	
       
   842 		}
       
   843 	
       
   844 	RBuf imgUrl;		
       
   845 	if(hasParameters)		
       
   846 		{
       
   847 		//let say urlWithPar has the value http://www.logos.com/images/test.pngx=100&y=100
       
   848 		//now the tempBuf contains the value  x=100&y=100
       
   849 		TInt sizeUrlParameters = tempBuf.Length();
       
   850 		sizeUrlParameters++; // now this integer contains the size of x=100&y=100 
       
   851 		TInt sizeImgUrl = sizeImgUrlWithPar - sizeUrlParameters;
       
   852 		
       
   853 		//Create a buffer to store the imgUrl without parameters
       
   854 		imgUrl.Create(sizeImgUrl);
       
   855 		imgUrl.Copy(urlWithPar.Left(sizeImgUrl));
       
   856 		iTempPreset->SetImgUrl(imgUrl);
       
   857 		}
       
   858 	else
       
   859 		{
       
   860 		//nothing to be done
       
   861 		//the imgUrl present in the preset is correct, no need to change anything
       
   862 		}
       
   863 
       
   864 	//set the downloaded logo to the preset with the API SetLogoData()
       
   865 	iTempPreset->SetLogoData(*iRespBody);
       
   866 	if(iTempReqFrom == 0)//which means the request came from SearchView while doing Add to Favorite
       
   867 		{
       
   868 		iFavDb->ReplacePresetL(*iTempPreset);
       
   869 		iPresetModifiedStatus = ETrue;
       
   870 		}
       
   871 	else if(iTempReqFrom == 1)//which menas the request came from a view other than NowPlayingView
       
   872 		{
       
   873 		iTempLogoHandle->PresetLogoDownloadedL(iTempPreset);
       
   874 		}
       
   875 	else if(iTempReqFrom == 2)//which menas the request came from NowPlayingView
       
   876 		{
       
   877 		//(1)logo has downloaded freshly
       
   878 		//(2)send the logo to the NPV through PresetLogoDownloadedL
       
   879 		//(3)check whether the preset exists in favdb; if so replace that with new logo
       
   880 		iTempLogoHandle->PresetLogoDownloadedL(iTempPreset);
       
   881 		//iFavDb->ReplacePresetL(*iTempPreset)
       
   882 		}
       
   883 		
       
   884     
       
   885 	iTempPreset->SetImgUrl(urlWithPar);	
       
   886 	//Cache the newly downloaded logo
       
   887 	iCache->CacheLogoL(*iRespBody,iTempPreset->GetImgUrl(),*iResponseHeaders);
       
   888 
       
   889 	//close all the buffers
       
   890 	imgUrl.Close();
       
   891 	tempBuf.Close();
       
   892 	urlWithPar.Close();
       
   893 	
       
   894 	iRunning = EFalse;
       
   895 	iState = EIdle;
       
   896 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendPresetWithLogoL - Exiting" );
       
   897 	}
       
   898 
       
   899 
       
   900 
       
   901 // ---------------------------------------------------------------------------------------
       
   902 // CIRLogoDownloadEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
       
   903 // callback API from MHTTPTransactionCallback
       
   904 // ---------------------------------------------------------------------------------------
       
   905 //
       
   906 void CIRLogoDownloadEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
       
   907 	{
       
   908 	IRLOG_DEBUG( "CIRLogoDownloadEngine::MHFRunL - Entering" );
       
   909 	switch (aEvent.iStatus)
       
   910 		{
       
   911 		case THTTPEvent::EGotResponseHeaders:
       
   912 			{
       
   913 		    RHTTPResponse resp = aTransaction.Response();
       
   914 		    TInt status = resp.StatusCode();
       
   915 		    iRespCode = status;
       
   916             ExtractResponseHeadersL(aTransaction);
       
   917 	        if(status >= KStatusOK &&  status < KStatusMultipleChoices)
       
   918 		    {
       
   919 	            THTTPHdrVal headerValue(0);
       
   920 	            RHTTPHeaders headers = resp.GetHeaderCollection();
       
   921 	            TInt error = headers.GetField(iLogoSession.StringPool().StringF(HTTP::EContentLength,
       
   922 	            				 RHTTPSession::GetTable()), 0, headerValue);
       
   923 	            iRespBodySize = 0;
       
   924 	            if (KErrNone == error)
       
   925 	            {
       
   926 	                iRespBodySize = headerValue.Int();
       
   927 	            }
       
   928                 iRespBody = HBufC8::NewL(iRespBodySize+1);
       
   929 		    }
       
   930 			else if( status == KStatusNotModified )//304 means, the content has not modified
       
   931 			    {
       
   932 			    if(iIsConditionalGET)
       
   933 				    {
       
   934 				    iIsConditionalGET = EFalse;
       
   935 				    iRunning = EFalse;
       
   936 				    //update the trust period 
       
   937 					//no problem if it leaves
       
   938 					TRAP_IGNORE(iCache->UpdateTrustPeriodL(KLogo,iTempPreset->GetImgUrl(),
       
   939 												*iResponseHeaders))
       
   940 					//do a forced get because the data is notmodifed in isds and 
       
   941 					//trustable
       
   942 					iForceGet = ETrue;
       
   943 					CheckCacheForLogoL(1);
       
   944 				    }
       
   945 		        }
       
   946 	        else if( status == KStatusGatewayTimeout )
       
   947 		        {
       
   948 				//implementation, if needed
       
   949 				CancelTransaction();
       
   950 				if(iTempReqFrom == 0)
       
   951 					{
       
   952 					//do nothing	
       
   953 					}
       
   954 				else
       
   955 					{
       
   956 					iTempLogoHandle->PresetLogoDownloadError(iTempPreset);					
       
   957 					}
       
   958 				ManagePresetArrayIndexL();
       
   959 				}
       
   960 
       
   961 			}
       
   962 			break;
       
   963 
       
   964 		case THTTPEvent::EGotResponseBodyData:
       
   965 			{
       
   966 			MHTTPDataSupplier* body = aTransaction.Response().Body();
       
   967 			TPtrC8 dataChunk;
       
   968 			body->GetNextDataPart(dataChunk);
       
   969 			if(iRespBodySize > 0)
       
   970 				{
       
   971 	            iRespBody->Des().Append((const TDesC8&)dataChunk);
       
   972 				}
       
   973 			else if(iRespBody)
       
   974 				{
       
   975 				//which means the body of the response has come
       
   976 				//but in the response headers Content-Length is missing
       
   977 				//for this usecase realloc the iRespBody with the data received					
       
   978 				HBufC8* buffertmp = HBufC8::NewLC( dataChunk.Length() + 1 );
       
   979         		TPtr8 buffertmpPtr( buffertmp->Des() );
       
   980         		buffertmpPtr.Copy( (const TDesC8&)dataChunk );
       
   981         		
       
   982    				TInt tempSize;
       
   983 				tempSize = iRespBody->Length() + dataChunk.Length();
       
   984 				
       
   985 				iRespBody = iRespBody->ReAllocL( tempSize );
       
   986 				TPtr8 ibufferPtr( iRespBody->Des() );
       
   987 				ibufferPtr.Append(buffertmpPtr);
       
   988 
       
   989 
       
   990         		
       
   991 				CleanupStack::PopAndDestroy(buffertmp); // buffertmp        		
       
   992 				}
       
   993 			body->ReleaseData();
       
   994 			}
       
   995 			break;
       
   996 
       
   997 		case THTTPEvent::EResponseComplete:
       
   998 			{
       
   999 			//No implementation
       
  1000 			}
       
  1001 			break;
       
  1002 
       
  1003 		case THTTPEvent::ESucceeded:
       
  1004 	        {
       
  1005 			iTransaction.Close();
       
  1006 			if(iIsConditionalGET)
       
  1007 				{
       
  1008 				iIsConditionalGET = EFalse;					
       
  1009 				}
       
  1010 		 
       
  1011 			iRunning = EFalse;
       
  1012 			//set the downloaded logo in the preset and send it back to the requestor
       
  1013 			SendPresetWithLogoL();
       
  1014 			ManagePresetArrayIndexL();
       
  1015 	        }
       
  1016 			break;
       
  1017 
       
  1018 		case THTTPEvent::EFailed:
       
  1019 			{
       
  1020 			aTransaction.Close();
       
  1021 			iRunning = EFalse;
       
  1022 			iState = EIdle;
       
  1023 			if( iRespCode == KStatusNotModified )//304 means, the content has not modified
       
  1024 				{
       
  1025 				//do nothing;					
       
  1026 				}
       
  1027 			else
       
  1028 				{
       
  1029 				if(iTempReqFrom == 0)
       
  1030 					{
       
  1031 					//do nothing
       
  1032 					}
       
  1033 				else
       
  1034 					{
       
  1035 					iTempLogoHandle->PresetLogoDownloadError(iTempPreset);					
       
  1036 					}
       
  1037 				}
       
  1038 			ManagePresetArrayIndexL();
       
  1039 			}
       
  1040 	        break;
       
  1041 
       
  1042 		default:
       
  1043 
       
  1044 			if (aEvent.iStatus < 0)
       
  1045 				{
       
  1046 				aTransaction.Close();
       
  1047 				iRunning = EFalse;
       
  1048 				iState = EIdle;
       
  1049 				if(iTempReqFrom == 0)
       
  1050 					{
       
  1051 					//do nothing
       
  1052 					}
       
  1053 				else
       
  1054 					{
       
  1055 					iTempLogoHandle->PresetLogoDownloadError(iTempPreset);					
       
  1056 					}
       
  1057 				ManagePresetArrayIndexL();
       
  1058 		        }
       
  1059 			break;
       
  1060 		}
       
  1061 	IRLOG_DEBUG( "CIRLogoDownloadEngine::MHFRunL - Exiting" );
       
  1062 	}
       
  1063 
       
  1064 
       
  1065 // ------------------------------------------------------------------------------------------------------------------
       
  1066 // CIRLogoDownloadEngine::MHFRunError(TInt /*aError*/, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/)
       
  1067 // callback API from MHTTPTransactionCallback
       
  1068 // ------------------------------------------------------------------------------------------------------------------
       
  1069 //
       
  1070 TInt CIRLogoDownloadEngine::MHFRunError(TInt /*aError*/, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/)
       
  1071 	{
       
  1072 	IRLOG_DEBUG( "CIRLogoDownloadEngine::MHFRunError - Entering" );
       
  1073 	aTransaction.Close();
       
  1074 	iRunning = EFalse;
       
  1075 	iState = EIdle;
       
  1076 	if(iIsConditionalGET)
       
  1077 		{
       
  1078 		iIsConditionalGET = EFalse;	
       
  1079 		}
       
  1080 	if(iTempReqFrom == 0)
       
  1081 		{
       
  1082 		//do nothing	
       
  1083 		}
       
  1084 	else
       
  1085 		{
       
  1086 		iTempLogoHandle->PresetLogoDownloadError(iTempPreset);		
       
  1087 		}
       
  1088 	TRAP_IGNORE(ManagePresetArrayIndexL())
       
  1089 	IRLOG_DEBUG( "CIRLogoDownloadEngine::MHFRunError - Exiting" );
       
  1090 	return KErrNone;
       
  1091 	}
       
  1092 
       
  1093 // --------------------------------------------------------------------
       
  1094 // CIRLogoDownloadEngine::GetNextDataPart(TPtrC8& aDataPart)
       
  1095 // callback API from MHTTPDataSupplier
       
  1096 // --------------------------------------------------------------------
       
  1097 TBool CIRLogoDownloadEngine::GetNextDataPart(TPtrC8& aDataPart)
       
  1098 	{
       
  1099 	IRLOG_DEBUG( "CIRLogoDownloadEngine::GetNextDataPart - Entering" );
       
  1100     aDataPart.Length();
       
  1101     iReqBody->Length();
       
  1102     aDataPart.Set(*iReqBody);
       
  1103 	IRLOG_DEBUG( "CIRLogoDownloadEngine::GetNextDataPart - Exiting" );
       
  1104 	return ETrue;
       
  1105 	}
       
  1106 
       
  1107 // --------------------------------------------------------------------
       
  1108 // CIRLogoDownloadEngine::ReleaseData()
       
  1109 // callback API from MHTTPDataSupplier
       
  1110 // --------------------------------------------------------------------
       
  1111 void CIRLogoDownloadEngine::ReleaseData()
       
  1112 	{
       
  1113 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ReleaseData" );
       
  1114    //No implementaion
       
  1115 	}
       
  1116 
       
  1117 
       
  1118 // --------------------------------------------------------------------
       
  1119 // CIRLogoDownloadEngine::Reset()
       
  1120 // callback API from MHTTPDataSupplier
       
  1121 // --------------------------------------------------------------------
       
  1122 TInt CIRLogoDownloadEngine::Reset()
       
  1123 	{
       
  1124 	IRLOG_DEBUG( "CIRLogoDownloadEngine::Reset" );
       
  1125 	return KErrNone;
       
  1126 	}
       
  1127 
       
  1128 
       
  1129 // --------------------------------------------------------------------
       
  1130 // CIRLogoDownloadEngine::OverallDataSize()
       
  1131 // callback API from MHTTPDataSupplier
       
  1132 // --------------------------------------------------------------------
       
  1133 TInt CIRLogoDownloadEngine::OverallDataSize()
       
  1134 	{
       
  1135 	IRLOG_DEBUG( "CIRLogoDownloadEngine::OverallDataSize" );
       
  1136 	return iReqBody->Length();
       
  1137 	}
       
  1138 
       
  1139 // ---------------------------------------------------------------------------
       
  1140 // CIRLogoDownloadEngine::ExtractResponseHeadersL( RHTTPTransaction aTransaction )
       
  1141 // Used to Extract the response headers.
       
  1142 // ---------------------------------------------------------------------------
       
  1143 //
       
  1144 
       
  1145 void CIRLogoDownloadEngine::ExtractResponseHeadersL(const RHTTPTransaction&
       
  1146 	aTransaction )
       
  1147     {
       
  1148     IRLOG_DEBUG( "CIRHttpDataProvider::ExtractResponseHeadersL - Entering" );
       
  1149     RHTTPResponse response = aTransaction.Response();
       
  1150     RHTTPHeaders respHeader = response.GetHeaderCollection();
       
  1151     THTTPHdrFieldIter iterator = respHeader.Fields();
       
  1152     RStringPool httpStringPool = aTransaction.Session().StringPool();
       
  1153     iterator.First();
       
  1154     HBufC8 *headerField = HBufC8::NewLC( KMaxHeaderNameLength +
       
  1155 		KMaxHeaderValueLength );
       
  1156     HBufC8 *fieldValBuf = HBufC8::NewLC( KMaxHeaderValueLength );
       
  1157     while ( iterator.AtEnd() == EFalse )
       
  1158         {
       
  1159         RStringTokenF fieldName = iterator();
       
  1160         RStringF fieldNameStr = httpStringPool.StringF( fieldName );
       
  1161         THTTPHdrVal fieldVal;
       
  1162         if ( respHeader.GetField( fieldNameStr, 0, fieldVal ) == KErrNone )
       
  1163             {
       
  1164             const TDesC8 &fieldNameDesC = fieldNameStr.DesC();
       
  1165             headerField->Des().Copy( fieldNameDesC.Left(
       
  1166 				KMaxHeaderNameLength ) );
       
  1167             fieldValBuf->Des().Zero();
       
  1168             switch ( fieldVal.Type() )
       
  1169                 {
       
  1170                 // the value is an integer
       
  1171                 //lint restore -e747:Significant prototype
       
  1172                 //coercion (arg. no. 1) int to long long  :
       
  1173                 case THTTPHdrVal::KTIntVal: fieldValBuf->Des().Num(
       
  1174 					fieldVal.Int() );
       
  1175                 break;
       
  1176                 // the value is a case-insensitive string
       
  1177                 case THTTPHdrVal::KStrFVal:
       
  1178                     {
       
  1179                     RStringF fieldValStr = httpStringPool.StringF(
       
  1180 						fieldVal.StrF() );
       
  1181                     const TDesC8 &fieldValDesC = fieldValStr.DesC();
       
  1182                     fieldValBuf->Des().Copy( fieldValDesC.Left(
       
  1183 						KMaxHeaderValueLength ) );
       
  1184                     }
       
  1185                 break;
       
  1186                 // the value is a case-sensitive string
       
  1187                 case THTTPHdrVal::KStrVal:
       
  1188                     {
       
  1189                     RString fieldValStr = httpStringPool.String(
       
  1190 						fieldVal.Str() );
       
  1191                     const TDesC8 &fieldValDesC = fieldValStr.DesC();
       
  1192                     fieldValBuf->Des().Copy( fieldValDesC.Left(
       
  1193 						KMaxHeaderValueLength ) );
       
  1194                     }
       
  1195                 break;
       
  1196                 // the value is a date/time
       
  1197                 case THTTPHdrVal::KDateVal:
       
  1198                     {
       
  1199                     TDateTime date = fieldVal.DateTime();
       
  1200                     TTime t( date );
       
  1201 //                    if ( iSetNonUAProfUserAgent )
       
  1202 //       					{
       
  1203        		            HttpDateHeaderReceived( *headerField ,t );
       
  1204 //       					}
       
  1205                     }
       
  1206                 break;
       
  1207                 // the value is type is unknown
       
  1208                 default:
       
  1209                     break;
       
  1210                 }
       
  1211             // Display HTTP header field name and value
       
  1212             headerField->Des().Append( KDPColon );
       
  1213             headerField->Des().Append( *fieldValBuf );
       
  1214             HttpHeaderReceived( *headerField );
       
  1215             }
       
  1216         ++iterator;
       
  1217         }
       
  1218     
       
  1219     CleanupStack::PopAndDestroy( fieldValBuf );
       
  1220     CleanupStack::PopAndDestroy( headerField );
       
  1221     IRLOG_DEBUG( "CIRLogoDownloadEngine::ExtractResponseHeadersL - Exiting." );
       
  1222     }
       
  1223 
       
  1224 
       
  1225 
       
  1226 // ---------------------------------------------------------------------------
       
  1227 //  CIRLogoDownloadEngine::HttpHeaderReceived( const TDesC8& aHeaderData )
       
  1228 //  indicate that an HTTP header is received.
       
  1229 // ---------------------------------------------------------------------------
       
  1230 //
       
  1231 void CIRLogoDownloadEngine::HttpHeaderReceived( const TDesC8& aHeaderData )
       
  1232     {
       
  1233     IRLOG_DEBUG( "CIRLogoDownloadEngine::HttpHeaderReceived - Entering." );
       
  1234 	_LIT8(KDelim,":");
       
  1235 	_LIT8(KContentType,"Content-Type");
       
  1236 	ExtractHeaderValue(aHeaderData,KContentType,KDelim,iResponseHeaders->
       
  1237 		iContentType);
       
  1238 	_LIT8(KMaxAge,"max-age");
       
  1239 	_LIT8(KDelimEqual,"=");
       
  1240 	ExtractHeaderValue(aHeaderData,KMaxAge,KDelimEqual,iResponseHeaders->
       
  1241 		iMaxAge);
       
  1242 	_LIT8(KContentLength,"Content-Length");
       
  1243 	ExtractHeaderValue(aHeaderData,KContentLength,KDelim,iResponseHeaders->
       
  1244 		iContentLength);
       
  1245 	_LIT8(KExpires,"Expires");
       
  1246 	ExtractHeaderValue(aHeaderData,KExpires,KDelim,iResponseHeaders->iExpires);
       
  1247 	_LIT8(KETag,"ETag");
       
  1248 	ExtractHeaderValue(aHeaderData,KETag,KDelim,iResponseHeaders->iETag);
       
  1249 	IRLOG_DEBUG( "CIRLogoDownloadEngine::HttpHeaderReceived - Exiting." );
       
  1250     }
       
  1251 
       
  1252 // ---------------------------------------------------------------------------
       
  1253 //  CIRLogoDownloadEngine::ExtractHeaderValue(const TDesC8& aHeaderData,const
       
  1254 //	TDesC8& aHeaderName,const TDesC8& aDelimeter,TDes8& aHolder) const
       
  1255 //  Used to build the CIRHttpResponseData
       
  1256 // ---------------------------------------------------------------------------
       
  1257 //
       
  1258 void CIRLogoDownloadEngine::ExtractHeaderValue(const TDesC8& aHeaderData,const
       
  1259 	TDesC8& aHeaderName,const TDesC8& aDelimeter,TDes8& aHolder) const
       
  1260 	{
       
  1261 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ExtractHeaderValue - Entering" );
       
  1262 	TInt position = aHeaderData.Find(aHeaderName);
       
  1263 	if( position >= 0)
       
  1264 		{
       
  1265 		TPtrC8 headerValue = aHeaderData.Mid(position);
       
  1266 		TInt delimeterPosition = headerValue.Find(aDelimeter);
       
  1267 		if( delimeterPosition != KErrNotFound )
       
  1268 			{
       
  1269 			delimeterPosition++;
       
  1270 			TPtrC8 value = headerValue.Mid(delimeterPosition);
       
  1271 			aHolder.Copy(value);
       
  1272 			aHolder.TrimAll();
       
  1273 			}
       
  1274 		}
       
  1275 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ExtractHeaderValue - Exiting." );
       
  1276 	}
       
  1277 
       
  1278 // ---------------------------------------------------------------------------
       
  1279 //  CIRLogoDownloadEngine::HttpDateHeaderReceived(const TDesC8 &aHeader,
       
  1280 //	const TTime& aTime )
       
  1281 //  Used to build the CIRHttpResponseData members
       
  1282 // ---------------------------------------------------------------------------
       
  1283 //
       
  1284 void CIRLogoDownloadEngine::HttpDateHeaderReceived(const TDesC8 &aHeader,
       
  1285 	const TTime& aTime )
       
  1286 	{
       
  1287 	IRLOG_DEBUG( "CIRLogoDownloadEngine::HttpDateHeaderReceived - Entering." );
       
  1288 	_LIT8(KDate,"Date");
       
  1289 	_LIT8(KLastModified,"Last-Modified");
       
  1290 	TInt position = aHeader.Find(KDate);
       
  1291 	if( position != KErrNotFound )
       
  1292 		{
       
  1293 		iResponseHeaders->iDate = aTime;
       
  1294 		return ;
       
  1295 		}
       
  1296 	position = aHeader.Find(KLastModified);
       
  1297 	if( position != KErrNotFound )
       
  1298 		{
       
  1299 		iResponseHeaders->iLastModified = aTime;
       
  1300 		}
       
  1301 	IRLOG_DEBUG( "CIRLogoDownloadEngine::HttpDateHeaderReceived - Exiting." );
       
  1302 	}
       
  1303 
       
  1304 
       
  1305 
       
  1306 
       
  1307 
       
  1308 // --------------------------------------------------------------------
       
  1309 // CIRLogoDownloadEngine::ManagePresetArrayIndexL()
       
  1310 // To make another download request if exists in the queue
       
  1311 // To update the iPresetArray current index
       
  1312 // --------------------------------------------------------------------
       
  1313 void CIRLogoDownloadEngine::ManagePresetArrayIndexL()
       
  1314 	{
       
  1315 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ManagePresetArrayIndexL - Entering" );
       
  1316 	TInt PresetArrayLength = iPresetArray->Count();
       
  1317 	if((PresetArrayLength>0) && (iPresetArrayPos < PresetArrayLength))
       
  1318 		{
       
  1319 		CIRIsdsPreset* tempPreset = CIRIsdsPreset::NewL();
       
  1320 		CleanupStack::PushL(tempPreset);
       
  1321     	*tempPreset = *(iPresetArray->At(iPresetArrayPos));
       
  1322     		if(iReqFromArrayPos < iReqFromArray->Count()  &&  iReqFromArray->At(iReqFromArrayPos) == 0 )
       
  1323         		{
       
  1324     			FetchLogoDataL(tempPreset);
       
  1325         		}
       
  1326         	else if(iObserverArrayPos < iObserverArray->Count())
       
  1327     	    	{
       
  1328     			FetchLogoDataL(tempPreset,iObserverArray->At(iObserverArrayPos),
       
  1329     							iReqFromArray->At(iReqFromArrayPos));
       
  1330     			++iObserverArrayPos;
       
  1331     	    	}
       
  1332 		++iPresetArrayPos;
       
  1333 		++iReqFromArrayPos;
       
  1334 //		delete tempPreset;
       
  1335 		CleanupStack::PopAndDestroy(tempPreset);
       
  1336 		}
       
  1337 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ManagePresetArrayIndexL - Exiting" );
       
  1338 	}
       
  1339 
       
  1340 
       
  1341 // --------------------------------------------------------------------
       
  1342 // CIRLogoDownloadEngine::ManageCachePresetArrayIndexL()
       
  1343 // To make another download request if exists in the queue
       
  1344 // To update the iCachePresetArray current index
       
  1345 // --------------------------------------------------------------------
       
  1346 void CIRLogoDownloadEngine::ManageCachePresetArrayIndexL()
       
  1347 	{
       
  1348 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ManageCachePresetArrayIndexL - Exiting" );
       
  1349  	TInt CachePresetArrayLength = iCachePresetArray->Count();
       
  1350 	if((CachePresetArrayLength>0) && (iCachePresetArrayPos < CachePresetArrayLength))
       
  1351 		{
       
  1352 		CIRIsdsPreset* tempPreset;
       
  1353 		tempPreset = CIRIsdsPreset::NewL();
       
  1354 		CleanupStack::PushL(tempPreset);
       
  1355 		*tempPreset = *(iCachePresetArray->At(iCachePresetArrayPos));
       
  1356 		
       
  1357 		if(iCacheReqFromArrayPos < iCacheReqFromArray->Count()  &&
       
  1358 					 iCacheReqFromArray->At(iCacheReqFromArrayPos) == 0 )
       
  1359     		{
       
  1360 			SendRequestL(tempPreset,KLogoSize,KLogoSize);
       
  1361     		}
       
  1362     	else if(iCacheObserverArrayPos < iCacheObserverArray->Count())
       
  1363 	    	{
       
  1364 			SendRequestL(tempPreset,iCacheObserverArray->At(iCacheObserverArrayPos),
       
  1365 					iCacheReqFromArray->At(iCacheReqFromArrayPos));
       
  1366 			++iCacheObserverArrayPos;
       
  1367 	    	}
       
  1368 		++iCachePresetArrayPos;
       
  1369 		++iCacheReqFromArrayPos;
       
  1370 //		delete tempPreset;
       
  1371 		CleanupStack::PopAndDestroy(tempPreset);
       
  1372  		}
       
  1373 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ManageCachePresetArrayIndexL - Exiting" );
       
  1374 	}
       
  1375 
       
  1376 // -----------------------------------------------------
       
  1377 // CIRLogoDownloadEngine::CacheError()
       
  1378 // Called from cachemgmt in case of an error
       
  1379 // callback API from MIRCacheObserver
       
  1380 // -----------------------------------------------------
       
  1381 void CIRLogoDownloadEngine::CacheError()
       
  1382  	{
       
  1383 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CacheError" );
       
  1384 
       
  1385  	//code here, if needed
       
  1386  	}
       
  1387 
       
  1388 // -----------------------------------------------------
       
  1389 // CIRLogoDownloadEngine::CacheFailed()
       
  1390 // Called from cachemgmt in case of cache failure
       
  1391 // callback API from MIRCacheObserver
       
  1392 // -----------------------------------------------------
       
  1393 void CIRLogoDownloadEngine::CacheFailed()
       
  1394  	{
       
  1395  	IRLOG_DEBUG( "CIRLogoDownloadEngine::CacheFailed" );
       
  1396  	//code here, if needed
       
  1397  	}
       
  1398 
       
  1399 // -----------------------------------------------------
       
  1400 // CIRLogoDownloadEngine::CacheInvalid()
       
  1401 // Called from cachemgmt in case cache is invalid
       
  1402 // callback API from MIRCacheObserver
       
  1403 // -----------------------------------------------------
       
  1404 void CIRLogoDownloadEngine::CacheInvalid()
       
  1405 	{
       
  1406 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CacheInvalid - Entering" );
       
  1407 	iETag = iCache->iETag;
       
  1408 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CacheInvalid - Exiting" );
       
  1409 	}
       
  1410 
       
  1411 // -----------------------------------------------------
       
  1412 // CIRLogoDownloadEngine::CachedStructureL(TInt aChoice)
       
  1413 // Called from cachemgmt data retrival is successful
       
  1414 // callback API from MIRCacheObserver
       
  1415 // -----------------------------------------------------
       
  1416 void CIRLogoDownloadEngine::CachedStructureL(TInt aChoice)
       
  1417  	{
       
  1418  	IRLOG_DEBUG( "CIRLogoDownloadEngine::CachedStructureL - Entering" );
       
  1419 	if(iCacheReqMade)
       
  1420 		{
       
  1421 		iCacheReqMade = EFalse;
       
  1422 		if(aChoice == KCacheAvailable)
       
  1423 			{
       
  1424 			
       
  1425 		 	TInt sizeImgUrlWithPmts = 0;
       
  1426 		 	//Remove the imgUrl with parameters from the Preset
       
  1427 			//now set imgUrl without parameters in to the Preset
       
  1428 			if(iSendingLogo==0)
       
  1429 				{
       
  1430 				sizeImgUrlWithPmts = iCacheTempPreset->GetImgUrl().Length();		
       
  1431 				}
       
  1432 			else if(iSendingLogo==1)
       
  1433 				{
       
  1434 				sizeImgUrlWithPmts = iTempPreset->GetImgUrl().Length();		
       
  1435 				}
       
  1436 			else if(iSendingLogo==2)
       
  1437 				{
       
  1438 				sizeImgUrlWithPmts = KTen;			
       
  1439 				}
       
  1440 			TBool hasParameters = EFalse;
       
  1441 			RBuf urlWithPar;
       
  1442 			urlWithPar.Create(sizeImgUrlWithPmts);
       
  1443 			if(iSendingLogo==0)
       
  1444 				{
       
  1445 				urlWithPar.Copy(iCacheTempPreset->GetImgUrl());
       
  1446 				}
       
  1447 			else if(iSendingLogo==1)
       
  1448 				{
       
  1449 				urlWithPar.Copy(iTempPreset->GetImgUrl());
       
  1450 				}
       
  1451 			else if(iSendingLogo==2)
       
  1452 				{
       
  1453 				_LIT(KNone,"");
       
  1454 				urlWithPar.Copy(KNone);
       
  1455 				}
       
  1456 				
       
  1457 			RBuf tempBuf;
       
  1458 			tempBuf.Create(sizeImgUrlWithPmts);
       
  1459 
       
  1460 			TLex urlLex(urlWithPar);
       
  1461 			for(;!urlLex.Eos();)
       
  1462 				{
       
  1463 				tempBuf.Zero();
       
  1464 				while(urlLex.Peek() != '?' && !urlLex.Eos())		
       
  1465 					{
       
  1466 					tempBuf.Append(urlLex.Get());
       
  1467 					}
       
  1468 				if(urlLex.Peek() == '?')
       
  1469 					{
       
  1470 					hasParameters = ETrue;			
       
  1471 					}
       
  1472 				urlLex.Inc();	
       
  1473 				}
       
  1474 			
       
  1475 			RBuf imgUrl;		
       
  1476 			if(hasParameters)		
       
  1477 				{
       
  1478 				//let say urlWithPar has the value http://www.logos.com/images/test.pngx=100&y=100
       
  1479 				//now the tempBuf contains the value  x=100&y=100
       
  1480 				TInt sizeUrlParameters = tempBuf.Length();
       
  1481 				sizeUrlParameters++; // now this integer contains the size of x=100&y=100 
       
  1482 				TInt sizeImgUrl = sizeImgUrlWithPmts - sizeUrlParameters;
       
  1483 				
       
  1484 				//Create a buffer to store the imgUrl without parameters
       
  1485 				imgUrl.Create(sizeImgUrl);
       
  1486 				imgUrl.Copy(urlWithPar.Left(sizeImgUrl));
       
  1487 				if(iSendingLogo==0)
       
  1488 					{
       
  1489 					iCacheTempPreset->SetImgUrl(imgUrl);			
       
  1490 					}
       
  1491 				else if(iSendingLogo==1)
       
  1492 					{
       
  1493 					iTempPreset->SetImgUrl(imgUrl);			
       
  1494 					}
       
  1495 				}
       
  1496 			else
       
  1497 				{
       
  1498 				//nothing to be done
       
  1499 				//the imgUrl present in the preset is correct, no need to change anything
       
  1500 				}
       
  1501 			
       
  1502 			
       
  1503 			
       
  1504 			if(iSendingLogo==0)
       
  1505 			 	{
       
  1506 			 	if(aChoice == KCacheAvailable)//logo is available in the cache
       
  1507 				 	{
       
  1508 					iCacheTempPreset->SetLogoData(iCache->iLogoData);	 		
       
  1509 				 	}
       
  1510 				if(iCacheReqFrom == 0)
       
  1511 					{
       
  1512 					iFavDb->ReplacePresetL(*iCacheTempPreset);
       
  1513 					iPresetModifiedStatus = ETrue;
       
  1514 					}
       
  1515 				else
       
  1516 					{
       
  1517 					iCacheTempLogoHandle->PresetLogoDownloadedL(iCacheTempPreset);
       
  1518 					}	
       
  1519 				
       
  1520 				
       
  1521 				ManageCachePresetArrayIndexL(); 	
       
  1522 			 	}
       
  1523 			else if(iSendingLogo==1)	
       
  1524 				{
       
  1525 			 	if(aChoice == KCacheAvailable)//logo is available in the cache
       
  1526 				 	{
       
  1527 					iTempPreset->SetLogoData(iCache->iLogoData);	 		
       
  1528 				 	}
       
  1529 				if(iTempReqFrom == 0)
       
  1530 					{
       
  1531 					iFavDb->ReplacePresetL(*iTempPreset);
       
  1532 					iPresetModifiedStatus = ETrue;
       
  1533 					}
       
  1534 				else
       
  1535 					{
       
  1536 					iTempLogoHandle->PresetLogoDownloadedL(iTempPreset);
       
  1537 					}		 	
       
  1538 					
       
  1539 			 	ManagePresetArrayIndexL();
       
  1540 			 	}
       
  1541 			else if(iSendingLogo==2)//logo request from the search results (while displaying logo)
       
  1542 				{
       
  1543 				//code here, if needed			
       
  1544 				}
       
  1545 
       
  1546 			//close all the buffers
       
  1547 			imgUrl.Close();
       
  1548 			tempBuf.Close();
       
  1549 			urlWithPar.Close();
       
  1550 			}
       
  1551 			
       
  1552 		}
       
  1553  	IRLOG_DEBUG( "CIRLogoDownloadEngine::CachedStructureL - Exiting" );
       
  1554  	}
       
  1555  	
       
  1556 // -----------------------------------------------------
       
  1557 // CIRLogoDownloadEngine::ReleaseResources()
       
  1558 // Releases the resources held by logo download engine
       
  1559 // Used to close the Http Session if already open
       
  1560 // -----------------------------------------------------
       
  1561 void CIRLogoDownloadEngine::ReleaseResources()
       
  1562 	{
       
  1563  	IRLOG_DEBUG( "CIRLogoDownloadEngine::ReleaseResources - Entering" );
       
  1564 	CancelTransaction();
       
  1565 	iLogoSession.Close();
       
  1566     iFirstTime = ETrue;
       
  1567  	IRLOG_DEBUG( "CIRLogoDownloadEngine::ReleaseResources - Exiting" );
       
  1568 	} 	
       
  1569 
       
  1570 
       
  1571 // ---------------------------------------------------------------------------
       
  1572 // CIRLogoDownloadEngine::HandlePresetChangedL( TInt aId, TUid aDataHandler, MPSPresetObserver::TPSReason aType )
       
  1573 // This is called by CIRFavoritesDb when values of presets stations has been changed	
       
  1574 // ---------------------------------------------------------------------------
       
  1575 //	
       
  1576 void CIRLogoDownloadEngine::HandlePresetChangedL( TInt aId, TUid aDataHandler,
       
  1577 					 MPSPresetObserver::TPSReason aReason )
       
  1578 	{
       
  1579  	IRLOG_DEBUG( "CIRLogoDownloadEngine::HandlePresetChangedL - Entering" );
       
  1580     if ( aDataHandler ==  KIRPreset  )
       
  1581         {
       
  1582         switch ( aReason )
       
  1583             {
       
  1584             case 0:  //MPSPresetObserver::EPSCreated
       
  1585                 {
       
  1586 /*d				CIRPreset* preset = NULL;
       
  1587                 preset = iFavDb->PresetById( aId );
       
  1588                 delete iCopyPreset;
       
  1589                 iCopyPreset = NULL;
       
  1590                 iCopyPreset = CIRIsdsPreset::NewL();
       
  1591                 preset->CopyPresetData(*iCopyPreset);
       
  1592                 if(iCopyPreset->GetChannelType()==1)
       
  1593 	                {
       
  1594 	                if(iCopyPreset->GetImgUrl().Length() != 0)
       
  1595 		                {
       
  1596 		                if(iCopyPreset->GetLogoData().Length() == 0)
       
  1597 			                {
       
  1598 			                SendRequestL(iCopyPreset);		                	
       
  1599 			                }
       
  1600 		                }
       
  1601 					else
       
  1602 						{
       
  1603 						//do nothing;
       
  1604 						}
       
  1605 	                }
       
  1606 d*/                }
       
  1607             	break;
       
  1608             case 1:  //MPSPresetObserver::EPSDeleted:
       
  1609             	break;
       
  1610             case 2:  //MPSPresetObserver::EPSModified:
       
  1611 	            {
       
  1612 	            if(!iFavDb->GetMoveStatus())
       
  1613 			        {
       
  1614 		            if(iPresetModifiedStatus)
       
  1615 			            {
       
  1616 						iPresetModifiedStatus = EFalse;		            	
       
  1617 			            }
       
  1618 		            else
       
  1619 			            {
       
  1620 						CIRPreset* preset = NULL;
       
  1621 		                preset = iFavDb->PresetById( aId );
       
  1622 		                delete iCopyPreset;
       
  1623 		                iCopyPreset = NULL;
       
  1624 		                iCopyPreset = CIRIsdsPreset::NewL();
       
  1625 		                preset->CopyPresetData(*iCopyPreset);
       
  1626 		                if(iCopyPreset->GetChannelType()==1)
       
  1627 			                {
       
  1628 			                if(iCopyPreset->GetImgUrl().Length() != 0)
       
  1629 				                {
       
  1630 				                SendRequestL(iCopyPreset,KLogoSize,KLogoSize);		                	
       
  1631 				                }
       
  1632 							else
       
  1633 								{
       
  1634 								//do nothing;
       
  1635 								}
       
  1636 			                }
       
  1637 			            }
       
  1638 			        }
       
  1639 	            }
       
  1640             	break;
       
  1641             default:
       
  1642             	break;
       
  1643             }
       
  1644         }
       
  1645  	IRLOG_DEBUG( "CIRLogoDownloadEngine::HandlePresetChangedL - Exiting" );
       
  1646 	}
       
  1647 
       
  1648 
       
  1649 // -----------------------------------------------------------------------------
       
  1650 // Notified by network controller when network is active, to reissue the request  
       
  1651 // NotifyActiveNetworkObserversL()
       
  1652 // -----------------------------------------------------------------------------
       
  1653 
       
  1654 void CIRLogoDownloadEngine::NotifyActiveNetworkObserversL(TIRNetworkEvent aEvent)
       
  1655 	{
       
  1656 	IRLOG_DEBUG( "CIRLogoDownloadEngine::NotifyActiveNetworkObserversL - Entering" );
       
  1657 	switch(aEvent)
       
  1658 		{
       
  1659 		case ENetworkConnectionDisconnected:
       
  1660 			{
       
  1661 			ReleaseResources();
       
  1662 			}
       
  1663 			break;
       
  1664 		case ENetworkConnectionEstablished:
       
  1665 			{
       
  1666 			if( iLogoRequestPending )
       
  1667 				{
       
  1668 				IssueLogoDownloadRequestL();
       
  1669 				}
       
  1670 			}
       
  1671 		}
       
  1672 	IRLOG_DEBUG( "CIRLogoDownloadEngine::NotifyActiveNetworkObserversL - Exiting" );
       
  1673 	}
       
  1674 
       
  1675  	
       
  1676 // -----------------------------------------------------------------------------
       
  1677 // Notified by network controller when user cancels network connection, to reset 
       
  1678 // the pending requests  
       
  1679 // ResetPendingRequests()
       
  1680 // -----------------------------------------------------------------------------
       
  1681 void CIRLogoDownloadEngine::ResetPendingRequests(TBool /*aValue*/)
       
  1682 	{
       
  1683 		
       
  1684 	}
       
  1685