Merge of fix for bug 2737 from Symbian1 branch
authorteknolog
Mon, 21 Jun 2010 12:04:03 +0100
changeset 151 17da6d3a5a4b
parent 144 b4be6bc78573
child 152 3402b2e2a66a
Merge of fix for bug 2737 from Symbian1 branch
application/data/PodcastClient_english.rls
application/data/PodcastQueueView.ra
application/inc/Podcast.hrh
application/inc/PodcastQueueView.h
application/inc/PodcastShowsView.h
application/src/PodcastQueueView.cpp
engine/BWINS/podcastengineu.def
engine/eabi/podcastengineu.def
engine/inc/ShowEngine.h
engine/src/ShowEngine.cpp
--- a/application/data/PodcastClient_english.rls	Thu Jun 03 16:44:35 2010 +0100
+++ b/application/data/PodcastClient_english.rls	Mon Jun 21 12:04:03 2010 +0100
@@ -143,6 +143,8 @@
 rls_string STRING_r_view_remove_all_downloads_cmd "Clear download queue"
 rls_string STRING_r_clear_query "Clear download queue?"
 rls_string STRING_r_view_remove_download_short_cmd "Remove"
+rls_string STRING_r_view_move_up_short_cmd "Move up"
+rls_string STRING_r_view_move_down_short_cmd "Move down"
 rls_string STRING_r_view_remove_download_cmd "Remove download"
 
 rls_string STRING_r_error_notfound "Error: Not found on server"
--- a/application/data/PodcastQueueView.ra	Thu Jun 03 16:44:35 2010 +0100
+++ b/application/data/PodcastQueueView.ra	Mon Jun 21 12:04:03 2010 +0100
@@ -124,6 +124,16 @@
 				{
 					txt = STRING_r_view_remove_download_short_cmd;
 					command = EPodcastRemoveDownload;
+				},
+			STYLUS_POPUP_MENU_ITEM
+				{
+					txt = STRING_r_view_move_up_short_cmd;
+					command = EPodcastMoveDownloadUp;
+				},
+			STYLUS_POPUP_MENU_ITEM
+				{
+					txt = STRING_r_view_move_down_short_cmd;
+					command = EPodcastMoveDownloadDown;
 				}
 		};
 	}
--- a/application/inc/Podcast.hrh	Thu Jun 03 16:44:35 2010 +0100
+++ b/application/inc/Podcast.hrh	Mon Jun 21 12:04:03 2010 +0100
@@ -44,6 +44,8 @@
 	EPodcastDownloadShow,
 	EPodcastDeleteShow,
 	EPodcastRemoveDownload,
+	EPodcastMoveDownloadUp,
+	EPodcastMoveDownloadDown,
 	EPodcastRemoveAllDownloads,
 	EPodcastSuspendDownloads,
 	EPodcastResumeDownloads,
--- a/application/inc/PodcastQueueView.h	Thu Jun 03 16:44:35 2010 +0100
+++ b/application/inc/PodcastQueueView.h	Mon Jun 21 12:04:03 2010 +0100
@@ -78,6 +78,8 @@
 	void HandleCommandL(TInt aCommand);
 	TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
 	void DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane);
+	
+	virtual void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation);
 	};
 
 #endif
--- a/application/inc/PodcastShowsView.h	Thu Jun 03 16:44:35 2010 +0100
+++ b/application/inc/PodcastShowsView.h	Mon Jun 21 12:04:03 2010 +0100
@@ -96,7 +96,7 @@
 	void DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane);
 	void FormatShowInfoListBoxItemL(CShowInfo& aShowInfo, TInt aSizeDownloaded = 0);
 
-	void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation);
+	virtual void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation);
 	void GetShowIcons(CShowInfo* aShowInfo, TInt& aIconIndex);
 	void CreateIconsL();
 
--- a/application/src/PodcastQueueView.cpp	Thu Jun 03 16:44:35 2010 +0100
+++ b/application/src/PodcastQueueView.cpp	Mon Jun 21 12:04:03 2010 +0100
@@ -255,6 +255,52 @@
 				}
 			}
 			break;
+		case EPodcastMoveDownloadUp:
+			{
+			TInt index = iListContainer->Listbox()->CurrentItemIndex();
+			TBool resumeAfterMove = EFalse;
+			if (index == 1 && !iPodcastModel.SettingsEngine().DownloadSuspended())
+				{
+				iPodcastModel.ShowEngine().SuspendDownloads();
+				resumeAfterMove = ETrue;
+				}
+			
+			if (index >= 0 && index < iPodcastModel.ActiveShowList().Count())
+				{
+				TRAP_IGNORE(iPodcastModel.ShowEngine().MoveDownloadUpL(iPodcastModel.ActiveShowList()[index]->Uid()));
+				}
+			
+			if(resumeAfterMove)
+				{
+				iPodcastModel.ShowEngine().ResumeDownloadsL();
+				}
+				
+			UpdateListboxItemsL();
+			}
+			break;
+		case EPodcastMoveDownloadDown:
+			{
+			TInt index = iListContainer->Listbox()->CurrentItemIndex();
+			TBool resumeAfterMove = EFalse;
+			if (index == 0 && !iPodcastModel.SettingsEngine().DownloadSuspended())
+				{
+				iPodcastModel.ShowEngine().SuspendDownloads();
+				resumeAfterMove = ETrue;
+				}
+			
+			if (index >= 0 && index < iPodcastModel.ActiveShowList().Count())
+				{
+				TRAP_IGNORE(iPodcastModel.ShowEngine().MoveDownloadDownL(iPodcastModel.ActiveShowList()[index]->Uid()));
+				}
+			
+			if(resumeAfterMove)
+				{
+				iPodcastModel.ShowEngine().ResumeDownloadsL();
+				}
+			
+			UpdateListboxItemsL();
+			}
+			break;
 		case EPodcastSuspendDownloads:
 			{
 			iPodcastModel.ShowEngine().SuspendDownloads();
@@ -300,3 +346,29 @@
 		toolbar->SetItemDimmed(EPodcastRemoveDownload, itemCnt == 0, ETrue);		
 	}
 }
+
+void CPodcastQueueView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /* aPenEventScreenLocation */)
+{
+	DP("CPodcastQueueView::HandleLongTapEventL BEGIN");
+	iListContainer->SetLongTapDetectedL(ETrue);
+	
+	const TInt KListboxDefaultHeight = 19; // for some reason it returns 19 for an empty listbox in S^1
+	TInt lbHeight = iListContainer->Listbox()->CalcHeightBasedOnNumOfItems(
+			iListContainer->Listbox()->Model()->NumberOfItems()) - KListboxDefaultHeight;
+
+    if(iStylusPopupMenu && aPenEventLocation.iY < lbHeight)
+    {
+		TBool dimDown = (iListContainer->Listbox()->CurrentItemIndex() >= iPodcastModel.ActiveShowList().Count() - 1 ?
+				ETrue : EFalse);
+		TBool dimUp = (iListContainer->Listbox()->CurrentItemIndex() <= 0 ?
+				ETrue : EFalse);
+		
+		iStylusPopupMenu->SetItemDimmed(EPodcastMoveDownloadDown, dimDown);
+		iStylusPopupMenu->SetItemDimmed(EPodcastMoveDownloadUp, dimUp);
+		
+		iStylusPopupMenu->ShowMenu();
+		iStylusPopupMenu->SetPosition(aPenEventLocation);
+    }
+    
+	DP("CPodcastQueueView::HandleLongTapEventL END");
+}
--- a/engine/BWINS/podcastengineu.def	Thu Jun 03 16:44:35 2010 +0100
+++ b/engine/BWINS/podcastengineu.def	Mon Jun 21 12:04:03 2010 +0100
@@ -163,4 +163,6 @@
 	?DropDB@CPodcastModel@@QAEXXZ @ 162 NONAME ; void CPodcastModel::DropDB(void)
 	?CheckForDeletedShows@CShowEngine@@QAEXI@Z @ 163 NONAME ; void CShowEngine::CheckForDeletedShows(unsigned int)
 	?IsVideoShow@PodcastUtils@@SAHAAVTDesC16@@@Z @ 164 NONAME ; int PodcastUtils::IsVideoShow(class TDesC16 &)
+	?MoveDownloadUpL@CShowEngine@@QAEXI@Z @ 165 NONAME ; void CShowEngine::MoveDownloadUpL(unsigned int)
+	?MoveDownloadDownL@CShowEngine@@QAEXI@Z @ 166 NONAME ; void CShowEngine::MoveDownloadDownL(unsigned int)
 
--- a/engine/eabi/podcastengineu.def	Thu Jun 03 16:44:35 2010 +0100
+++ b/engine/eabi/podcastengineu.def	Mon Jun 21 12:04:03 2010 +0100
@@ -199,4 +199,6 @@
 	_ZTV9CShowInfo @ 198 NONAME
 	_ZN11CShowEngine20CheckForDeletedShowsEj @ 199 NONAME
 	_ZN12PodcastUtils11IsVideoShowER7TDesC16 @ 200 NONAME
+	_ZN11CShowEngine15MoveDownloadUpLEj @ 201 NONAME
+	_ZN11CShowEngine17MoveDownloadDownLEj @ 202 NONAME
 
--- a/engine/inc/ShowEngine.h	Thu Jun 03 16:44:35 2010 +0100
+++ b/engine/inc/ShowEngine.h	Mon Jun 21 12:04:03 2010 +0100
@@ -31,6 +31,12 @@
 #include "mpxcollectionhelper.h"
 #include "mpxcollectionhelperobserver.h"
 
+struct TDownload
+	{
+	TUint iIndex;
+	TUint iUid;
+	};
+
 class CShowEngine : public CBase, public MHttpClientObserver, public MMetaDataReaderObserver,
 					public MMPXCollectionHelperObserver
 {
@@ -75,6 +81,8 @@
 
 	IMPORT_C void CheckForDeletedShows(TUint aFeedUid);
 	IMPORT_C CMetaDataReader& MetaDataReader();
+	IMPORT_C void MoveDownloadUpL(TUint aUid);
+	IMPORT_C void MoveDownloadDownL(TUint aUid);
 
 private:
 	// from HttpClientObserver, dont have to be public
@@ -127,6 +135,7 @@
 	TUint DBGetDownloadsCountL();
 	void DBAddDownloadL(TUint aUid);
 	CShowInfo* DBGetNextDownloadL();
+	void DBSwapDownloadsL(TDownload aFirstDL, TDownload aSecondDL);
 	
 private:
 	CHttpClient* iShowClient;			
--- a/engine/src/ShowEngine.cpp	Thu Jun 03 16:44:35 2010 +0100
+++ b/engine/src/ShowEngine.cpp	Mon Jun 21 12:04:03 2010 +0100
@@ -1020,6 +1020,52 @@
 		}
 	}
 
+void CShowEngine::DBSwapDownloadsL(TDownload aFirstDL, TDownload aSecondDL)
+	{
+	DP("CShowEngine::DBSwapDownloadsL");
+	_LIT(KSqlStatement, "update downloads set uid=%u where dl_index=%d");
+	
+	iSqlBuffer.Format(KSqlStatement, aFirstDL.iUid, aSecondDL.iIndex);
+	sqlite3_stmt *st;
+	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
+			&st, (const void**) NULL);
+	
+	if (rc == SQLITE_OK)
+		{
+		Cleanup_sqlite3_finalize_PushL(st);
+		rc = sqlite3_step(st);
+		if (rc != SQLITE_DONE)
+			{
+			User::Leave(KErrUnknown);
+			}
+		CleanupStack::PopAndDestroy(); // st
+		}
+	else
+		{
+		User::Leave(KErrCorrupt);
+		}
+	
+	iSqlBuffer.Format(KSqlStatement, aSecondDL.iUid, aFirstDL.iIndex);
+	
+	rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
+			&st, (const void**) NULL);
+	
+	if (rc == SQLITE_OK)
+		{
+		Cleanup_sqlite3_finalize_PushL(st);
+		rc = sqlite3_step(st);
+		if (rc != SQLITE_DONE)
+			{
+			User::Leave(KErrUnknown);
+			}
+		CleanupStack::PopAndDestroy(); // st
+		}
+	else
+		{
+		User::Leave(KErrCorrupt);
+		}
+	}
+
 EXPORT_C CShowInfo* CShowEngine::GetNextShowByTrackL(CShowInfo* aShowInfo)
 	{
 	CShowInfo* nextShow = NULL;
@@ -1382,3 +1428,128 @@
 		}
 	}
 
+EXPORT_C void CShowEngine::MoveDownloadUpL(TUint aUid)
+	{
+	DP("CShowEngine::MoveDownLoadUpL");
+	_LIT(KSqlStatement, "select * from downloads");
+	iSqlBuffer.Format(KSqlStatement);
+
+	sqlite3_stmt *st;
+
+	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
+			&st, (const void**) NULL);
+
+	if (rc == SQLITE_OK)
+		{
+		RArray<TDownload> downloads;
+		CleanupClosePushL(downloads);
+	
+		rc = sqlite3_step(st);
+		Cleanup_sqlite3_finalize_PushL(st);
+		
+		TInt selectedIdx = -1;
+		while (rc == SQLITE_ROW && selectedIdx == -1)
+			{
+			TDownload download;
+			
+			download.iIndex = sqlite3_column_int(st, 0);
+			download.iUid = sqlite3_column_int(st, 1);
+			
+			downloads.Append(download);
+			
+			if (download.iUid == aUid)
+				{
+				selectedIdx = downloads.Count()-1;
+				}
+			
+			rc = sqlite3_step(st);
+			}
+		CleanupStack::PopAndDestroy();//st, downloads
+		
+		// If the selected download was found in the database
+		if (selectedIdx != -1)
+			{
+			// Swap the specified download with the one above it
+			TDownload selectedDownload = downloads[selectedIdx];
+			TDownload previousDownload = downloads[selectedIdx - 1];
+			
+			// SQL - Update index (with index of selected download) where uid is of previous download
+			// and update index (with index of previous download) where uid if of selected download
+			DBSwapDownloadsL(selectedDownload, previousDownload);
+			}
+		else
+			{
+			User::Leave(KErrNotFound);
+			}
+		
+		CleanupStack::PopAndDestroy(); // downloads
+		}
+	else
+		{
+		User::Leave(KErrCorrupt);
+		}
+	}
+
+EXPORT_C void CShowEngine::MoveDownloadDownL(TUint aUid)
+	{
+	DP("CShowEngine::MoveDownLoadDownL");
+	
+	// An upside-down list will result in the download moving down
+	_LIT(KSqlStatement, "select * from downloads order by dl_index desc");
+	iSqlBuffer.Format(KSqlStatement);
+
+	sqlite3_stmt *st;
+
+	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
+			&st, (const void**) NULL);
+
+	if (rc == SQLITE_OK)
+		{
+		RArray<TDownload> downloads;
+		CleanupClosePushL(downloads);
+	
+		rc = sqlite3_step(st);
+		Cleanup_sqlite3_finalize_PushL(st);
+		
+		TInt selectedIdx = -1;
+		while (rc == SQLITE_ROW && selectedIdx == -1)
+			{
+			TDownload download;
+			
+			download.iIndex = sqlite3_column_int(st, 0);
+			download.iUid = sqlite3_column_int(st, 1);
+			
+			downloads.Append(download);
+			
+			if (download.iUid == aUid)
+				{
+				selectedIdx = downloads.Count()-1;
+				}
+			
+			rc = sqlite3_step(st);
+			}
+		CleanupStack::PopAndDestroy();//st, downloads
+		
+		// If the selected download was found in the database
+		if (selectedIdx != -1)
+			{
+			// Swap the specified download with the one above it
+			TDownload selectedDownload = downloads[selectedIdx];
+			TDownload previousDownload = downloads[selectedIdx - 1];
+			
+			// SQL - Update index (with index of selected download) where uid is of previous download
+			// and update index (with index of previous download) where uid if of selected download
+			DBSwapDownloadsL(selectedDownload, previousDownload);
+			}
+		else
+			{
+			User::Leave(KErrNotFound);
+			}
+		
+		CleanupStack::PopAndDestroy(); // downloads
+		}
+	else
+		{
+		User::Leave(KErrCorrupt);
+		}
+	}
\ No newline at end of file