engine/src/ShowEngine.cpp
branchGCC_SURGE
changeset 192 b436ab77eac1
parent 172 c2a99fe1afd0
child 200 79076725bab9
equal deleted inserted replaced
150:7a313fb652c8 192:b436ab77eac1
   174 	{
   174 	{
   175 	}
   175 	}
   176 
   176 
   177 void CShowEngine::DownloadInfo(CHttpClient* aHttpClient, TInt aTotalBytes)
   177 void CShowEngine::DownloadInfo(CHttpClient* aHttpClient, TInt aTotalBytes)
   178 	{
   178 	{
   179 	DP1("About to download %d bytes", aTotalBytes);
   179 	DP1("CShowEngine::DownloadInfo, About to download %d bytes", aTotalBytes);
   180 	if (aHttpClient == iShowClient && iShowDownloading != NULL
       
   181 			&& aTotalBytes != -1)
       
   182 		{
       
   183 		iShowDownloading->SetShowSize(aTotalBytes);
       
   184 		}
       
   185 	}
   180 	}
   186 
   181 
   187 void CShowEngine::GetShowL(CShowInfo *info)
   182 void CShowEngine::GetShowL(CShowInfo *info)
   188 	{
   183 	{
   189 	CFeedInfo *feedInfo = iPodcastModel.FeedEngine().GetFeedInfoByUid(
   184 	CFeedInfo *feedInfo = iPodcastModel.FeedEngine().GetFeedInfoByUid(
  1002 	sqlite3_stmt *st;
   997 	sqlite3_stmt *st;
  1003 
   998 
  1004 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
   999 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
  1005 			&st, (const void**) NULL);
  1000 			&st, (const void**) NULL);
  1006 
  1001 
       
  1002 	if (rc == SQLITE_OK)
       
  1003 		{
       
  1004 		Cleanup_sqlite3_finalize_PushL(st);
       
  1005 		rc = sqlite3_step(st);
       
  1006 		if (rc != SQLITE_DONE)
       
  1007 			{
       
  1008 			User::Leave(KErrUnknown);
       
  1009 			}
       
  1010 		CleanupStack::PopAndDestroy(); // st
       
  1011 		}
       
  1012 	else
       
  1013 		{
       
  1014 		User::Leave(KErrCorrupt);
       
  1015 		}
       
  1016 	}
       
  1017 
       
  1018 void CShowEngine::DBSwapDownloadsL(TDownload aFirstDL, TDownload aSecondDL)
       
  1019 	{
       
  1020 	DP("CShowEngine::DBSwapDownloadsL");
       
  1021 	_LIT(KSqlStatement, "update downloads set uid=%u where dl_index=%d");
       
  1022 	
       
  1023 	iSqlBuffer.Format(KSqlStatement, aFirstDL.iUid, aSecondDL.iIndex);
       
  1024 	sqlite3_stmt *st;
       
  1025 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
       
  1026 			&st, (const void**) NULL);
       
  1027 	
       
  1028 	if (rc == SQLITE_OK)
       
  1029 		{
       
  1030 		Cleanup_sqlite3_finalize_PushL(st);
       
  1031 		rc = sqlite3_step(st);
       
  1032 		if (rc != SQLITE_DONE)
       
  1033 			{
       
  1034 			User::Leave(KErrUnknown);
       
  1035 			}
       
  1036 		CleanupStack::PopAndDestroy(); // st
       
  1037 		}
       
  1038 	else
       
  1039 		{
       
  1040 		User::Leave(KErrCorrupt);
       
  1041 		}
       
  1042 	
       
  1043 	iSqlBuffer.Format(KSqlStatement, aSecondDL.iUid, aFirstDL.iIndex);
       
  1044 	
       
  1045 	rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
       
  1046 			&st, (const void**) NULL);
       
  1047 	
  1007 	if (rc == SQLITE_OK)
  1048 	if (rc == SQLITE_OK)
  1008 		{
  1049 		{
  1009 		Cleanup_sqlite3_finalize_PushL(st);
  1050 		Cleanup_sqlite3_finalize_PushL(st);
  1010 		rc = sqlite3_step(st);
  1051 		rc = sqlite3_step(st);
  1011 		if (rc != SQLITE_DONE)
  1052 		if (rc != SQLITE_DONE)
  1380 				}
  1421 				}
  1381 			}
  1422 			}
  1382 		}
  1423 		}
  1383 	}
  1424 	}
  1384 
  1425 
       
  1426 EXPORT_C void CShowEngine::MoveDownloadUpL(TUint aUid)
       
  1427 	{
       
  1428 	DP("CShowEngine::MoveDownLoadUpL");
       
  1429 	_LIT(KSqlStatement, "select * from downloads");
       
  1430 	iSqlBuffer.Format(KSqlStatement);
       
  1431 
       
  1432 	sqlite3_stmt *st;
       
  1433 
       
  1434 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
       
  1435 			&st, (const void**) NULL);
       
  1436 
       
  1437 	if (rc == SQLITE_OK)
       
  1438 		{
       
  1439 		RArray<TDownload> downloads;
       
  1440 		CleanupClosePushL(downloads);
       
  1441 	
       
  1442 		rc = sqlite3_step(st);
       
  1443 		Cleanup_sqlite3_finalize_PushL(st);
       
  1444 		
       
  1445 		TInt selectedIdx = -1;
       
  1446 		while (rc == SQLITE_ROW && selectedIdx == -1)
       
  1447 			{
       
  1448 			TDownload download;
       
  1449 			
       
  1450 			download.iIndex = sqlite3_column_int(st, 0);
       
  1451 			download.iUid = sqlite3_column_int(st, 1);
       
  1452 			
       
  1453 			downloads.Append(download);
       
  1454 			
       
  1455 			if (download.iUid == aUid)
       
  1456 				{
       
  1457 				selectedIdx = downloads.Count()-1;
       
  1458 				}
       
  1459 			
       
  1460 			rc = sqlite3_step(st);
       
  1461 			}
       
  1462 		CleanupStack::PopAndDestroy();//st, downloads
       
  1463 		
       
  1464 		// If the selected download was found in the database
       
  1465 		if (selectedIdx != -1)
       
  1466 			{
       
  1467 			// Swap the specified download with the one above it
       
  1468 			TDownload selectedDownload = downloads[selectedIdx];
       
  1469 			TDownload previousDownload = downloads[selectedIdx - 1];
       
  1470 			
       
  1471 			// SQL - Update index (with index of selected download) where uid is of previous download
       
  1472 			// and update index (with index of previous download) where uid if of selected download
       
  1473 			DBSwapDownloadsL(selectedDownload, previousDownload);
       
  1474 			}
       
  1475 		else
       
  1476 			{
       
  1477 			User::Leave(KErrNotFound);
       
  1478 			}
       
  1479 		
       
  1480 		CleanupStack::PopAndDestroy(); // downloads
       
  1481 		}
       
  1482 	else
       
  1483 		{
       
  1484 		User::Leave(KErrCorrupt);
       
  1485 		}
       
  1486 	}
       
  1487 
       
  1488 EXPORT_C void CShowEngine::MoveDownloadDownL(TUint aUid)
       
  1489 	{
       
  1490 	DP("CShowEngine::MoveDownLoadDownL");
       
  1491 	
       
  1492 	// An upside-down list will result in the download moving down
       
  1493 	_LIT(KSqlStatement, "select * from downloads order by dl_index desc");
       
  1494 	iSqlBuffer.Format(KSqlStatement);
       
  1495 
       
  1496 	sqlite3_stmt *st;
       
  1497 
       
  1498 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
       
  1499 			&st, (const void**) NULL);
       
  1500 
       
  1501 	if (rc == SQLITE_OK)
       
  1502 		{
       
  1503 		RArray<TDownload> downloads;
       
  1504 		CleanupClosePushL(downloads);
       
  1505 	
       
  1506 		rc = sqlite3_step(st);
       
  1507 		Cleanup_sqlite3_finalize_PushL(st);
       
  1508 		
       
  1509 		TInt selectedIdx = -1;
       
  1510 		while (rc == SQLITE_ROW && selectedIdx == -1)
       
  1511 			{
       
  1512 			TDownload download;
       
  1513 			
       
  1514 			download.iIndex = sqlite3_column_int(st, 0);
       
  1515 			download.iUid = sqlite3_column_int(st, 1);
       
  1516 			
       
  1517 			downloads.Append(download);
       
  1518 			
       
  1519 			if (download.iUid == aUid)
       
  1520 				{
       
  1521 				selectedIdx = downloads.Count()-1;
       
  1522 				}
       
  1523 			
       
  1524 			rc = sqlite3_step(st);
       
  1525 			}
       
  1526 		CleanupStack::PopAndDestroy();//st, downloads
       
  1527 		
       
  1528 		// If the selected download was found in the database
       
  1529 		if (selectedIdx != -1)
       
  1530 			{
       
  1531 			// Swap the specified download with the one above it
       
  1532 			TDownload selectedDownload = downloads[selectedIdx];
       
  1533 			TDownload previousDownload = downloads[selectedIdx - 1];
       
  1534 			
       
  1535 			// SQL - Update index (with index of selected download) where uid is of previous download
       
  1536 			// and update index (with index of previous download) where uid if of selected download
       
  1537 			DBSwapDownloadsL(selectedDownload, previousDownload);
       
  1538 			}
       
  1539 		else
       
  1540 			{
       
  1541 			User::Leave(KErrNotFound);
       
  1542 			}
       
  1543 		
       
  1544 		CleanupStack::PopAndDestroy(); // downloads
       
  1545 		}
       
  1546 	else
       
  1547 		{
       
  1548 		User::Leave(KErrCorrupt);
       
  1549 		}
       
  1550 	}