engine/src/ShowEngine.cpp
branchsymbian1
changeset 145 cc0182a5da39
parent 67 9c24c921ec35
child 147 2e626f5a52c8
equal deleted inserted replaced
90:d0c0c3e6f7a1 145:cc0182a5da39
  1007 	sqlite3_stmt *st;
  1007 	sqlite3_stmt *st;
  1008 
  1008 
  1009 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
  1009 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
  1010 			&st, (const void**) NULL);
  1010 			&st, (const void**) NULL);
  1011 
  1011 
       
  1012 	if (rc == SQLITE_OK)
       
  1013 		{
       
  1014 		Cleanup_sqlite3_finalize_PushL(st);
       
  1015 		rc = sqlite3_step(st);
       
  1016 		if (rc != SQLITE_DONE)
       
  1017 			{
       
  1018 			User::Leave(KErrUnknown);
       
  1019 			}
       
  1020 		CleanupStack::PopAndDestroy(); // st
       
  1021 		}
       
  1022 	else
       
  1023 		{
       
  1024 		User::Leave(KErrCorrupt);
       
  1025 		}
       
  1026 	}
       
  1027 
       
  1028 void CShowEngine::DBSwapDownloadsL(TDownload aFirstDL, TDownload aSecondDL)
       
  1029 	{
       
  1030 	DP("CShowEngine::DBSwapDownloadsL");
       
  1031 	_LIT(KSqlStatement, "update downloads set uid=%d where dl_index=%d");
       
  1032 	
       
  1033 	iSqlBuffer.Format(KSqlStatement, aFirstDL.iUid, aSecondDL.iIndex);
       
  1034 	sqlite3_stmt *st;
       
  1035 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
       
  1036 			&st, (const void**) NULL);
       
  1037 	
       
  1038 	if (rc == SQLITE_OK)
       
  1039 		{
       
  1040 		Cleanup_sqlite3_finalize_PushL(st);
       
  1041 		rc = sqlite3_step(st);
       
  1042 		if (rc != SQLITE_DONE)
       
  1043 			{
       
  1044 			User::Leave(KErrUnknown);
       
  1045 			}
       
  1046 		CleanupStack::PopAndDestroy(); // st
       
  1047 		}
       
  1048 	else
       
  1049 		{
       
  1050 		User::Leave(KErrCorrupt);
       
  1051 		}
       
  1052 	
       
  1053 	iSqlBuffer.Format(KSqlStatement, aSecondDL.iUid, aFirstDL.iIndex);
       
  1054 	
       
  1055 	rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
       
  1056 			&st, (const void**) NULL);
       
  1057 	
  1012 	if (rc == SQLITE_OK)
  1058 	if (rc == SQLITE_OK)
  1013 		{
  1059 		{
  1014 		Cleanup_sqlite3_finalize_PushL(st);
  1060 		Cleanup_sqlite3_finalize_PushL(st);
  1015 		rc = sqlite3_step(st);
  1061 		rc = sqlite3_step(st);
  1016 		if (rc != SQLITE_DONE)
  1062 		if (rc != SQLITE_DONE)
  1385 				}
  1431 				}
  1386 			}
  1432 			}
  1387 		}
  1433 		}
  1388 	}
  1434 	}
  1389 
  1435 
       
  1436 EXPORT_C void CShowEngine::MoveDownloadUpL(TUint aUid)
       
  1437 	{
       
  1438 	DP("CShowEngine::MoveDownLoadUpL");
       
  1439 	_LIT(KSqlStatement, "select * from downloads");
       
  1440 	iSqlBuffer.Format(KSqlStatement);
       
  1441 
       
  1442 	sqlite3_stmt *st;
       
  1443 
       
  1444 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
       
  1445 			&st, (const void**) NULL);
       
  1446 
       
  1447 	if (rc == SQLITE_OK)
       
  1448 		{
       
  1449 		RArray<TDownload> downloads;
       
  1450 		CleanupClosePushL(downloads);
       
  1451 	
       
  1452 		rc = sqlite3_step(st);
       
  1453 		Cleanup_sqlite3_finalize_PushL(st);
       
  1454 		
       
  1455 		TInt selectedIdx = -1;
       
  1456 		while (rc == SQLITE_ROW && selectedIdx == -1)
       
  1457 			{
       
  1458 			TDownload download;
       
  1459 			
       
  1460 			download.iIndex = sqlite3_column_int(st, 0);
       
  1461 			download.iUid = sqlite3_column_int(st, 1);
       
  1462 			
       
  1463 			downloads.Append(download);
       
  1464 			
       
  1465 			if (download.iUid == aUid)
       
  1466 				{
       
  1467 				selectedIdx = downloads.Count()-1;
       
  1468 				}
       
  1469 			
       
  1470 			rc = sqlite3_step(st);
       
  1471 			}
       
  1472 		CleanupStack::PopAndDestroy();//st, downloads
       
  1473 		
       
  1474 		// If the selected download was found in the database
       
  1475 		if (selectedIdx != -1)
       
  1476 			{
       
  1477 			// Swap the specified download with the one above it
       
  1478 			TDownload selectedDownload = downloads[selectedIdx];
       
  1479 			TDownload previousDownload = downloads[selectedIdx - 1];
       
  1480 			
       
  1481 			// SQL - Update index (with index of selected download) where uid is of previous download
       
  1482 			// and update index (with index of previous download) where uid if of selected download
       
  1483 			DBSwapDownloadsL(selectedDownload, previousDownload);
       
  1484 			}
       
  1485 		else
       
  1486 			{
       
  1487 			User::Leave(KErrNotFound);
       
  1488 			}
       
  1489 		
       
  1490 		CleanupStack::PopAndDestroy(); // downloads
       
  1491 		}
       
  1492 	else
       
  1493 		{
       
  1494 		User::Leave(KErrCorrupt);
       
  1495 		}
       
  1496 	}
       
  1497 
       
  1498 EXPORT_C void CShowEngine::MoveDownloadDownL(TUint aUid)
       
  1499 	{
       
  1500 	DP("CShowEngine::MoveDownLoadDownL");
       
  1501 	
       
  1502 	// An upside-down list will result in the download moving down
       
  1503 	_LIT(KSqlStatement, "select * from downloads order by dl_index desc");
       
  1504 	iSqlBuffer.Format(KSqlStatement);
       
  1505 
       
  1506 	sqlite3_stmt *st;
       
  1507 
       
  1508 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
       
  1509 			&st, (const void**) NULL);
       
  1510 
       
  1511 	if (rc == SQLITE_OK)
       
  1512 		{
       
  1513 		RArray<TDownload> downloads;
       
  1514 		CleanupClosePushL(downloads);
       
  1515 	
       
  1516 		rc = sqlite3_step(st);
       
  1517 		Cleanup_sqlite3_finalize_PushL(st);
       
  1518 		
       
  1519 		TInt selectedIdx = -1;
       
  1520 		while (rc == SQLITE_ROW && selectedIdx == -1)
       
  1521 			{
       
  1522 			TDownload download;
       
  1523 			
       
  1524 			download.iIndex = sqlite3_column_int(st, 0);
       
  1525 			download.iUid = sqlite3_column_int(st, 1);
       
  1526 			
       
  1527 			downloads.Append(download);
       
  1528 			
       
  1529 			if (download.iUid == aUid)
       
  1530 				{
       
  1531 				selectedIdx = downloads.Count()-1;
       
  1532 				}
       
  1533 			
       
  1534 			rc = sqlite3_step(st);
       
  1535 			}
       
  1536 		CleanupStack::PopAndDestroy();//st, downloads
       
  1537 		
       
  1538 		// If the selected download was found in the database
       
  1539 		if (selectedIdx != -1)
       
  1540 			{
       
  1541 			// Swap the specified download with the one above it
       
  1542 			TDownload selectedDownload = downloads[selectedIdx];
       
  1543 			TDownload previousDownload = downloads[selectedIdx - 1];
       
  1544 			
       
  1545 			// SQL - Update index (with index of selected download) where uid is of previous download
       
  1546 			// and update index (with index of previous download) where uid if of selected download
       
  1547 			DBSwapDownloadsL(selectedDownload, previousDownload);
       
  1548 			}
       
  1549 		else
       
  1550 			{
       
  1551 			User::Leave(KErrNotFound);
       
  1552 			}
       
  1553 		
       
  1554 		CleanupStack::PopAndDestroy(); // downloads
       
  1555 		}
       
  1556 	else
       
  1557 		{
       
  1558 		User::Leave(KErrCorrupt);
       
  1559 		}
       
  1560 	}
       
  1561