engine/src/ShowEngine.cpp
branch3rded
changeset 343 9c56bf585696
parent 279 5a44ec2f6f4d
child 390 d7abecc9d189
equal deleted inserted replaced
281:1cae65a87b5e 343:9c56bf585696
   160 	}
   160 	}
   161 
   161 
   162 void CShowEngine::Progress(CHttpClient* /*aHttpClient */, TInt aBytes,
   162 void CShowEngine::Progress(CHttpClient* /*aHttpClient */, TInt aBytes,
   163 		TInt aTotalBytes)
   163 		TInt aTotalBytes)
   164 	{	
   164 	{	
   165 	iShowDownloading->SetShowSize(aTotalBytes);
   165 	//iShowDownloading->SetShowSize(aTotalBytes);
   166 	TRAP_IGNORE(NotifyShowDownloadUpdatedL(aBytes, aTotalBytes));
   166 	TRAP_IGNORE(NotifyShowDownloadUpdatedL(aBytes, aTotalBytes));
   167 	}
   167 	}
   168 
   168 
   169 void CShowEngine::Disconnected(CHttpClient* /*aClient */)
   169 void CShowEngine::Disconnected(CHttpClient* /*aClient */)
   170 	{
   170 	{
   188 	relPath.Append('\\');
   188 	relPath.Append('\\');
   189 
   189 
   190 	TFileName fileName;
   190 	TFileName fileName;
   191 	PodcastUtils::FileNameFromUrl(info->Url(), fileName);
   191 	PodcastUtils::FileNameFromUrl(info->Url(), fileName);
   192 	
   192 	
   193 	TFileName extension;
       
   194 	extension.Copy(fileName.Mid(fileName.LocateReverse('.')));
       
   195 	DP1("extension=%S", &extension);
       
   196 		
       
   197 	TFileName newFilename;
   193 	TFileName newFilename;
   198 	newFilename.Format(_L("%u%S"), info->Uid(), &extension);
   194 	
   199 	DP1("newFilename=%S", &newFilename);
   195 	TInt periodPos = fileName.LocateReverse('.');
       
   196 
       
   197 	if (periodPos != -1)
       
   198 		{
       
   199 		// file extension (most likely) found
       
   200 		TFileName extension;
       
   201 		extension.Copy(fileName.Mid(periodPos));
       
   202 		DP1("extension=%S", &extension);
       
   203 			
       
   204 		newFilename.Format(_L("%u%S"), info->Uid(), &extension);
       
   205 		DP1("newFilename=%S", &newFilename);
       
   206 		} 
       
   207 	else
       
   208 		{
       
   209 		// no extension found, we'll have to rely on magic numbers
       
   210 		newFilename.Format(_L("%u"), info->Uid());
       
   211 		}
   200 			
   212 			
   201 	relPath.Append(newFilename);
   213 	relPath.Append(newFilename);
   202 	PodcastUtils::EnsureProperPathName(relPath);
   214 	PodcastUtils::EnsureProperPathName(relPath);
   203 
   215 
   204 	// complete file path is base dir + rel path
   216 	// complete file path is base dir + rel path
   246 
   258 
   247 void CShowEngine::CompleteL(CHttpClient* /*aHttpClient*/, TInt aError)
   259 void CShowEngine::CompleteL(CHttpClient* /*aHttpClient*/, TInt aError)
   248 	{
   260 	{
   249 	if (iShowDownloading != NULL)
   261 	if (iShowDownloading != NULL)
   250 		{
   262 		{
   251 		DP2("CShowEngine::CompleteL file=%S, aError=%d", &iShowDownloading->FileName(), aError);		
   263 		DP2("CShowEngine::CompleteL file=%S, aError=%d", &iShowDownloading->FileName(), aError);
       
   264 		
   252 		if(aError != KErrCouldNotConnect)
   265 		if(aError != KErrCouldNotConnect)
   253 			{
   266 			{
   254 			if(aError == KErrDisconnected && iPodcastModel.SettingsEngine().DownloadSuspended())
   267 			if(aError == KErrDisconnected && iPodcastModel.SettingsEngine().DownloadSuspended())
   255 				{
   268 				{
   256 				// no error if disconnect happened because of suspended downloading
   269 				// no error if disconnect happened because of suspended downloading
   272 					}
   285 					}
   273 				else if (mimeType.Left(5) == KMimeVideo)
   286 				else if (mimeType.Left(5) == KMimeVideo)
   274 					{
   287 					{
   275 					iShowDownloading->SetShowType(EVideoPodcast);
   288 					iShowDownloading->SetShowType(EVideoPodcast);
   276 					}
   289 					}
       
   290 				 
       
   291 				// setting file size	
       
   292 				TEntry entry;
       
   293 				TInt err = iPodcastModel.FsSession().Entry(iShowDownloading->FileName(), entry);
       
   294 				if (err == KErrNone)
       
   295 					{
       
   296 					iShowDownloading->SetShowSize(entry.iSize);
       
   297 					}
   277 
   298 
   278 				iShowDownloading->SetDownloadState(EDownloaded);
   299 				iShowDownloading->SetDownloadState(EDownloaded);
   279 				DBUpdateShowL(*iShowDownloading);
   300 				DBUpdateShowL(*iShowDownloading);
   280 				DBRemoveDownloadL(iShowDownloading->Uid());
   301 				DBRemoveDownloadL(iShowDownloading->Uid());
   281 				AddShowToMpxCollection(*iShowDownloading);				
   302 				AddShowToMpxCollection(*iShowDownloading);				
   284 				delete iShowDownloading;
   305 				delete iShowDownloading;
   285 				iShowDownloading = NULL;
   306 				iShowDownloading = NULL;
   286 				}
   307 				}
   287 			else
   308 			else
   288 				{
   309 				{
       
   310 				 if (aError == HTTPStatus::ERequestedRangeNotSatisfiable)
       
   311 					{
       
   312 					DP("ERequestedRangeNotSatisfiable, resetting download");
       
   313 					// file size got messed up, so delete downloaded file an re-queue
       
   314 					BaflUtils::DeleteFile(iPodcastModel.FsSession(),iShowDownloading->FileName());
       
   315 					iShowDownloading->SetDownloadState(EQueued);
       
   316 					DBUpdateShowL(*iShowDownloading);
       
   317 					}
   289 				// 400 and 500 series errors are serious errors on which probably another download will fail
   318 				// 400 and 500 series errors are serious errors on which probably another download will fail
   290 				if(aError >= HTTPStatus::EBadRequest && aError <= HTTPStatus::EBadRequest+200)
   319 				 else if (aError>= HTTPStatus::EBadRequest && aError <= HTTPStatus::EBadRequest+200)
   291 					{
   320 					{
   292 					iShowDownloading->SetDownloadState(EFailedDownload);
   321 					iShowDownloading->SetDownloadState(EFailedDownload);
   293 					DBUpdateShowL(*iShowDownloading);
   322 					DBUpdateShowL(*iShowDownloading);
   294 					DBRemoveDownloadL(iShowDownloading->Uid());
   323 					DBRemoveDownloadL(iShowDownloading->Uid());
   295 					NotifyShowFinishedL(aError);
   324 					NotifyShowFinishedL(aError);