CPodcastQueueView now inherits CPodcastShowsView instead of CPodcastListView. This removes the duplicated code between the two classes.
authorteknolog
Sat, 24 Apr 2010 22:26:43 +0100
changeset 121 1cc7501102a8
parent 120 31d05afa1a52
child 122 dd31cab34e27
CPodcastQueueView now inherits CPodcastShowsView instead of CPodcastListView. This removes the duplicated code between the two classes.
application/inc/PodcastQueueView.h
application/inc/PodcastShowsView.h
application/src/PodcastQueueView.cpp
application/src/PodcastShowsView.cpp
--- a/application/inc/PodcastQueueView.h	Sat Apr 24 21:46:17 2010 +0100
+++ b/application/inc/PodcastQueueView.h	Sat Apr 24 22:26:43 2010 +0100
@@ -28,10 +28,9 @@
 #include "FeedEngine.h"
 #include "PodcastModel.h"
 #include "Podcast.hrh"
-#include "PodcastListView.h"
+#include "PodcastShowsView.h"
 
-class CPodcastQueueView : public CPodcastListView, public MEikListBoxObserver, 
-	public MFeedEngineObserver, public MShowEngineObserver
+class CPodcastQueueView : public CPodcastShowsView
 	{
 public: 
 	static CPodcastQueueView* NewL(CPodcastModel& aPodcastModel);
@@ -68,18 +67,8 @@
 
 	void UpdateListboxItemsL();
 
-	// From // MEikListBoxObserverClass
+	// From MEikListBoxObserverClass
 	void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
-	// From showengine observer
-	void ShowListUpdatedL();  	
-	void ShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt aBytesTotal);	
-	void DownloadQueueUpdatedL(TInt aDownloadingShows, TInt aQueuedShows);
-	void ShowDownloadFinishedL(TUint aShowUid, TInt aError) ;
-	// from MFeedEngineObserver
-	void FeedDownloadStartedL(TFeedState aState,TUint aFeedUid);
-	void FeedDownloadFinishedL(TFeedState aState,TUint aFeedUid, TInt aError);
-	void FeedUpdateAllCompleteL(TFeedState aState);
-	void OpmlParsingComplete(TInt /*aError*/, TUint /*aNumFeedsImported*/) {}
 
 	/** 
 	 * Command handling function intended for overriding by sub classes. 
@@ -88,22 +77,7 @@
 	 */
 	void HandleCommandL(TInt aCommand);
 	TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
-
-	void UpdateFeedUpdateStateL();
-	void UpdateShowItemL(TUint aUid, TInt aSizeDownloaded);
-	void UpdateShowItemDataL(CShowInfo* aShowInfo,TInt aIndex, TInt aSizeDownloaded = KErrNotFound);
 	void DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane);
-	void FormatShowInfoListBoxItemL(CShowInfo& aShowInfo, TInt aSizeDownloaded = 0);
-
-private:
-	void GetShowIcons(CShowInfo* aShowInfo, TInt& aIconIndex);
-	
-private:
-	
-	CPodcastModel& iPodcastModel;
-	TBool iProgressAdded;	
-	TInt iLastImageHandlerError;
-	TBool iSetTitlebarImage;
 	};
 
 #endif
--- a/application/inc/PodcastShowsView.h	Sat Apr 24 21:46:17 2010 +0100
+++ b/application/inc/PodcastShowsView.h	Sat Apr 24 22:26:43 2010 +0100
@@ -97,9 +97,10 @@
 	void FormatShowInfoListBoxItemL(CShowInfo& aShowInfo, TInt aSizeDownloaded = 0);
 
 	void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation);
+	void GetShowIcons(CShowInfo* aShowInfo, TInt& aIconIndex);
+	void CreateIconsL();
 
 private:
-	void GetShowIcons(CShowInfo* aShowInfo, TInt& aIconIndex);
 	void DisplayShowInfoDialogL();
 	void HandleSetShowPlayedL(TBool aPlayed);
 	void HandleDeleteShowL();
@@ -107,10 +108,9 @@
 	void HandleSetShowPlayed(TBool aPlayed);
 	void HandleDeleteShow();
 	void UpdateViewTitleL();
-	void CreateIconsL();
 	void GetShowErrorText(TDes &aErrorMessage, TInt aErrorCode);
 	
-private:
+protected:
 	
 	CPodcastModel& iPodcastModel;
 	TBool iProgressAdded;	
--- a/application/src/PodcastQueueView.cpp	Sat Apr 24 21:46:17 2010 +0100
+++ b/application/src/PodcastQueueView.cpp	Sat Apr 24 22:26:43 2010 +0100
@@ -31,49 +31,9 @@
 #include <barsread.h>
 #include <aknnotedialog.h>
 #include <aknmessagequerydialog.h>
-#include "Podcast.hrh"
 
 #define KMaxMessageLength 200
 
-#define KPodcastImageWidth 160
-#define KPodcastImageHeight 120
-#define KPodcastDialogOffset 2
-
-#define KOneHundredPercent 100
-
-const TInt KSizeBufLen = 64;
-const TInt KDefaultGran = 5;
-_LIT(KSizeDownloadingOf, "%.1f/%.1f MB");
-_LIT(KShowsSizeFormatS60, "%.1f MB");
-
-_LIT(KShowFormat, "%d\t%S\t%S %S\t");
-_LIT(KShowErrorFormat, "%d\t%S\t%S\t");
-_LIT(KShowQueueFormat, "%d\t%S\t%S%S\t");
-
-
-// these must correspond with TShowsIconIndex
-
-const TUint KShowIconArrayIds[] =
-	{
-			EMbmPodcastAudio,
-			EMbmPodcastAudio_mask,
-			EMbmPodcastAudio_new,
-			EMbmPodcastAudio_new_mask,
-			EMbmPodcastAudio_queued,
-			EMbmPodcastAudio_queued_mask,
-			EMbmPodcastAudio_downloading,
-			EMbmPodcastAudio_downloading_mask,
-			EMbmPodcastAudio_downloaded,
-			EMbmPodcastAudio_downloaded_mask,
-			EMbmPodcastAudio_downloaded_new,
-			EMbmPodcastAudio_downloaded_new_mask,
-			EMbmPodcastAudio_failed,
-			EMbmPodcastAudio_failed_mask,
-			EMbmPodcastAudio_suspended,
-			EMbmPodcastAudio_suspended_mask,
-			0,
-			0
-	};
 
 CPodcastQueueView* CPodcastQueueView::NewL(CPodcastModel& aPodcastModel)
 	{
@@ -91,7 +51,7 @@
 	}
 
 CPodcastQueueView::CPodcastQueueView(CPodcastModel& aPodcastModel) :
-	iPodcastModel(aPodcastModel)
+	CPodcastShowsView(aPodcastModel)
 	{
 	}
 
@@ -99,33 +59,14 @@
 	{
 	BaseConstructL(R_PODCAST_QUEUEVIEW);
 	CPodcastListView::ConstructL();
-	CArrayPtr< CGulIcon>* icons = new(ELeave) CArrayPtrFlat< CGulIcon>(1);
-	CleanupStack::PushL(icons);
-	TInt pos = 0;
-	while (KShowIconArrayIds[pos] > 0)
-		{
-		// Load the bitmap for play icon	
-		CFbsBitmap* bitmap= NULL;//iEikonEnv->CreateBitmapL( _L("*"), KIconArrayIds[pos]);
-		CFbsBitmap* mask=  NULL;////iEikonEnv->CreateBitmapL( _L("*"), KIconArrayIds[pos+1] );
-		AknIconUtils::CreateIconL(bitmap,
-					                          mask,
-					                          iEikonEnv->EikAppUi()->Application()->BitmapStoreName(),
-					                          KShowIconArrayIds[pos],
-					                          KShowIconArrayIds[pos+1]);	
-		CleanupStack::PushL(bitmap);
-		// Load the mask for play icon			
-		CleanupStack::PushL(mask);
-		// Append the play icon to icon array
-		icons->AppendL(CGulIcon::NewL(bitmap, mask) );
-		CleanupStack::Pop(2); // bitmap, mask
-		pos+=2;
-		}
-	iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons);
-	CleanupStack::Pop(icons); // icons
+
+	CreateIconsL();
+		
 	iListContainer->Listbox()->SetListBoxObserver(this);
 	
 	iPodcastModel.FeedEngine().AddObserver(this);
 	iPodcastModel.ShowEngine().AddObserver(this);
+	
 
 	// no popup options apply to S^1
 #ifndef SYMBIAN1_UI
@@ -153,21 +94,6 @@
 		if (activeShow != NULL) {
 			DP1("aKeyEvent.iCode=%d", aKeyEvent.iCode);
 			switch (aKeyEvent.iCode) {
-			case 117: 
-			case '*':
-			case EKeySpace:
-				if (activeShow->PlayState() == EPlayed) {
-					HandleCommandL(EPodcastMarkAsUnplayed);
-				} else {
-					HandleCommandL(EPodcastMarkAsPlayed);
-				}
-				break;
-			case 106:
-			case '#':
-				if (activeShow->DownloadState() == ENotDownloaded) {
-					HandleCommandL(EPodcastDownloadShow);
-				}
-				break;
 			case EKeyBackspace:
 			case EKeyDelete:
 				HandleCommandL(EPodcastRemoveDownload);
@@ -214,78 +140,6 @@
 	CPodcastListView::DoDeactivate();
 	}
 
-// Engine callback when new shows are available
-void CPodcastQueueView::ShowListUpdatedL()
-	{
-	UpdateListboxItemsL();
-	}
-
-void CPodcastQueueView::ShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt /*aBytesTotal*/)
-	{
-	if (!iListContainer->IsVisible())
-		{
-		return;
-		}
-		
-	CShowInfo *info = iPodcastModel.ShowEngine().ShowDownloading();
-	if (info) 
-		{
-		UpdateShowItemL(info->Uid(), aBytesOfCurrentDownload);
-		}
-	}
-
-void CPodcastQueueView::ShowDownloadFinishedL(TUint /*aShowUid*/, TInt aError)
-	{
-	if (iListContainer->IsVisible()) 
-		{
-	
-		iProgressAdded = EFalse;
-	
-		iPodcastModel.GetShowsDownloadingL();
-		UpdateListboxItemsL();
-		UpdateToolbar();
-		
-		switch(aError)
-			{
-			case KErrCouldNotConnect:
-				{
-				TBuf<KMaxMessageLength> message;
-				iEikonEnv->ReadResourceL(message, R_PODCAST_CONNECTION_ERROR);
-				ShowErrorMessageL(message);
-				}
-				break;
-			default: // Do nothing
-				break;
-			}
-		}
-	}
-
-
-void CPodcastQueueView::FeedDownloadStartedL(TFeedState /*aState*/, TUint aFeedUid)
-	{
-	// TODO make use of the fact that we know that the feed download is
-	// started instead of checking feed engine states in UpdateFeedUpdateStateL.
-	if (iPodcastModel.ActiveFeedInfo() != NULL
-			&& iPodcastModel.ActiveFeedInfo()->Uid() == aFeedUid)
-		{
-		UpdateFeedUpdateStateL();
-		UpdateToolbar();
-		}	
-	}
-
-void CPodcastQueueView::FeedDownloadFinishedL(TFeedState /*aState*/, TUint aFeedUid, TInt /*aError*/)
-	{
-	DP("CPodcastQueueView::FeedDownloadFinishedL BEGIN");
-	// TODO make use of the fact that we know that the feed download is
-	// finished instead of checking feed engine states in UpdateFeedUpdateStateL.
-	if (iPodcastModel.ActiveFeedInfo() != NULL
-			&& iPodcastModel.ActiveFeedInfo()->Uid() == aFeedUid)
-		{
-		UpdateFeedUpdateStateL();
-		}
-	DP("CPodcastQueueView::FeedDownloadFinishedL END");
-	}
-
 void CPodcastQueueView::HandleListBoxEventL(CEikListBox* /*aListBox*/,
 		TListBoxEvent aEventType)
 	{
@@ -304,135 +158,6 @@
 		UpdateToolbar();
 	}
 
-void CPodcastQueueView::GetShowIcons(CShowInfo* aShowInfo, TInt& aIconIndex)
-	{
-	TBool dlStop = iPodcastModel.SettingsEngine().DownloadSuspended();
-
-	switch (aShowInfo->DownloadState())
-		{
-		case EDownloaded:
-			if (aShowInfo->PlayState() == ENeverPlayed) {
-				aIconIndex = EDownloadedNewShowIcon;
-			} else {
-				aIconIndex = EDownloadedShowIcon;
-			}
-			break;
-		case ENotDownloaded:
-			if (aShowInfo->PlayState() == ENeverPlayed) {
-				aIconIndex = ENewShowIcon;
-			} else {
-				aIconIndex = EShowIcon;
-			}
-			break;
-		case EQueued:
-			aIconIndex = dlStop ? ESuspendedShowIcon : EQuedShowIcon;
-			break;
-		case EDownloading:
-			aIconIndex = dlStop ? ESuspendedShowIcon : EDownloadingShowIcon;		
-			break;
-		case EFailedDownload:
-			aIconIndex = EFailedShowIcon;
-			break;
-		}
-	}
-
-void CPodcastQueueView::UpdateFeedUpdateStateL()
-	{
-	TBool listboxDimmed = EFalse;
-
-	if (iPodcastModel.FeedEngine().ClientState() != EIdle && iPodcastModel.ActiveFeedInfo()
-			!= NULL && iPodcastModel.FeedEngine().ActiveClientUid() == iPodcastModel.ActiveFeedInfo()->Uid())
-		{
-		listboxDimmed = ETrue;
-		}
-
-	if ((iListContainer->Listbox()->IsDimmed() && !listboxDimmed) || (!iListContainer->Listbox()->IsDimmed() && listboxDimmed))
-		{
-		iListContainer->Listbox()->SetDimmed(listboxDimmed);
-		}
-	UpdateListboxItemsL();
-	UpdateToolbar();
-	}
-
-void CPodcastQueueView::FormatShowInfoListBoxItemL(CShowInfo& aShowInfo, TInt aSizeDownloaded)
-	{
-	TBuf<32> infoSize;
-	TInt iconIndex = 0;	
-	TBuf<KMaxShortDateFormatSpec*2> showDate;
-	GetShowIcons(&aShowInfo, iconIndex);	
-	
-	if(aSizeDownloaded > 0)
-		{
-		if (aShowInfo.ShowSize() > 0)
-			{
-				infoSize.Format(KSizeDownloadingOf(), ((float) aSizeDownloaded / (float) KSizeMb),
-						((float)aShowInfo.ShowSize() / (float)KSizeMb));
-			}
-		else
-			{
-			infoSize.Format(KShowsSizeFormatS60(), (float)aSizeDownloaded / (float)KSizeMb);
-			}
-		}
-	else if (aShowInfo.ShowSize() > 0)
-		{
-		infoSize.Format(KShowsSizeFormatS60(), (float)aShowInfo.ShowSize() / (float)KSizeMb);
-		} 
-	else {
-		infoSize = KNullDesC();	
-	}
-
-	if (aShowInfo.PubDate().Int64() == 0)
-		{
-		showDate = KNullDesC();
-		}
-	else
-		{
-		aShowInfo.PubDate().FormatL(showDate, KDateFormatShort());
-		}
-	
-	if(aShowInfo.LastError() != KErrNone)
-		{
-		TRAP_IGNORE(((CPodcastAppUi*)AppUi())->GetErrorTextL(infoSize, aShowInfo.LastError()));
-		showDate.Zero();
-		}
-		
-	if (infoSize.Length() > 0 && showDate.Length() > 0)
-		{
-		infoSize.Insert(0,_L(", "));
-		}
-
-	iListboxFormatbuffer.Format(KShowQueueFormat(), iconIndex, &aShowInfo.Title(), &showDate, &infoSize);
-	}
-
-void CPodcastQueueView::UpdateShowItemDataL(CShowInfo* aShowInfo,TInt aIndex, TInt aSizeDownloaded)
-{
-	FormatShowInfoListBoxItemL(*aShowInfo, aSizeDownloaded);
-	iItemArray->Delete(aIndex);
-	if(aIndex>= iItemArray->MdcaCount())
-		{
-		iItemArray->AppendL(iListboxFormatbuffer);
-		}
-	else
-		{
-		iItemArray->InsertL(aIndex, iListboxFormatbuffer);
-		}
-}
-
-void CPodcastQueueView::UpdateShowItemL(TUint aUid, TInt aSizeDownloaded)
-{
-	RShowInfoArray& array = iPodcastModel.ActiveShowList();
-	
-	for (int i=0;i<array.Count();i++) {
-		if (array[i]->Uid() == aUid) {
-			UpdateShowItemDataL(array[i], i, aSizeDownloaded);
-			if (iListContainer->Listbox()->TopItemIndex() <= i &&
-				iListContainer->Listbox()->BottomItemIndex() >= i) {
-					iListContainer->Listbox()->DrawItem(i);
-			}
-		}
-	}
-}
-
 void CPodcastQueueView::UpdateListboxItemsL()
 	{
 	if (iListContainer->IsVisible())
@@ -578,14 +303,3 @@
 		toolbar->SetItemDimmed(EPodcastRemoveDownload, itemCnt == 0, ETrue);		
 	}
 }
-
-void CPodcastQueueView::DownloadQueueUpdatedL(TInt /*aDownloadingShows*/, TInt /*aQueuedShows*/)
-	{
-		UpdateListboxItemsL();
-	}
-
-void CPodcastQueueView::FeedUpdateAllCompleteL(TFeedState /*aState*/)
-	{
-	UpdateListboxItemsL();
-	UpdateToolbar();
-	}
--- a/application/src/PodcastShowsView.cpp	Sat Apr 24 21:46:17 2010 +0100
+++ b/application/src/PodcastShowsView.cpp	Sat Apr 24 22:26:43 2010 +0100
@@ -34,14 +34,6 @@
 
 #define KMaxMessageLength 200
 
-#define KPodcastImageWidth 160
-#define KPodcastImageHeight 120
-#define KPodcastDialogOffset 2
-
-#define KOneHundredPercent 100
-
-const TInt KSizeBufLen = 64;
-const TInt KDefaultGran = 5;
 _LIT(KSizeDownloadingOf, "%.1f/%.1f MB");
 _LIT(KShowsSizeFormatS60, "%.1f MB");