application/src/PodcastQueueView.cpp
changeset 121 1cc7501102a8
parent 117 3b59b88b089e
child 126 c2f1ea38ec70
equal deleted inserted replaced
120:31d05afa1a52 121:1cc7501102a8
    29 #include <podcast.mbg>
    29 #include <podcast.mbg>
    30 #include <gulicon.h>
    30 #include <gulicon.h>
    31 #include <barsread.h>
    31 #include <barsread.h>
    32 #include <aknnotedialog.h>
    32 #include <aknnotedialog.h>
    33 #include <aknmessagequerydialog.h>
    33 #include <aknmessagequerydialog.h>
    34 #include "Podcast.hrh"
       
    35 
    34 
    36 #define KMaxMessageLength 200
    35 #define KMaxMessageLength 200
    37 
    36 
    38 #define KPodcastImageWidth 160
       
    39 #define KPodcastImageHeight 120
       
    40 #define KPodcastDialogOffset 2
       
    41 
       
    42 #define KOneHundredPercent 100
       
    43 
       
    44 const TInt KSizeBufLen = 64;
       
    45 const TInt KDefaultGran = 5;
       
    46 _LIT(KSizeDownloadingOf, "%.1f/%.1f MB");
       
    47 _LIT(KShowsSizeFormatS60, "%.1f MB");
       
    48 
       
    49 _LIT(KShowFormat, "%d\t%S\t%S %S\t");
       
    50 _LIT(KShowErrorFormat, "%d\t%S\t%S\t");
       
    51 _LIT(KShowQueueFormat, "%d\t%S\t%S%S\t");
       
    52 
       
    53 
       
    54 // these must correspond with TShowsIconIndex
       
    55 
       
    56 const TUint KShowIconArrayIds[] =
       
    57 	{
       
    58 			EMbmPodcastAudio,
       
    59 			EMbmPodcastAudio_mask,
       
    60 			EMbmPodcastAudio_new,
       
    61 			EMbmPodcastAudio_new_mask,
       
    62 			EMbmPodcastAudio_queued,
       
    63 			EMbmPodcastAudio_queued_mask,
       
    64 			EMbmPodcastAudio_downloading,
       
    65 			EMbmPodcastAudio_downloading_mask,
       
    66 			EMbmPodcastAudio_downloaded,
       
    67 			EMbmPodcastAudio_downloaded_mask,
       
    68 			EMbmPodcastAudio_downloaded_new,
       
    69 			EMbmPodcastAudio_downloaded_new_mask,
       
    70 			EMbmPodcastAudio_failed,
       
    71 			EMbmPodcastAudio_failed_mask,
       
    72 			EMbmPodcastAudio_suspended,
       
    73 			EMbmPodcastAudio_suspended_mask,
       
    74 			0,
       
    75 			0
       
    76 	};
       
    77 
    37 
    78 CPodcastQueueView* CPodcastQueueView::NewL(CPodcastModel& aPodcastModel)
    38 CPodcastQueueView* CPodcastQueueView::NewL(CPodcastModel& aPodcastModel)
    79 	{
    39 	{
    80 	CPodcastQueueView* self = CPodcastQueueView::NewLC(aPodcastModel);
    40 	CPodcastQueueView* self = CPodcastQueueView::NewLC(aPodcastModel);
    81 	CleanupStack::Pop(self);
    41 	CleanupStack::Pop(self);
    89 	self->ConstructL();
    49 	self->ConstructL();
    90 	return self;
    50 	return self;
    91 	}
    51 	}
    92 
    52 
    93 CPodcastQueueView::CPodcastQueueView(CPodcastModel& aPodcastModel) :
    53 CPodcastQueueView::CPodcastQueueView(CPodcastModel& aPodcastModel) :
    94 	iPodcastModel(aPodcastModel)
    54 	CPodcastShowsView(aPodcastModel)
    95 	{
    55 	{
    96 	}
    56 	}
    97 
    57 
    98 void CPodcastQueueView::ConstructL()
    58 void CPodcastQueueView::ConstructL()
    99 	{
    59 	{
   100 	BaseConstructL(R_PODCAST_QUEUEVIEW);
    60 	BaseConstructL(R_PODCAST_QUEUEVIEW);
   101 	CPodcastListView::ConstructL();
    61 	CPodcastListView::ConstructL();
   102 	CArrayPtr< CGulIcon>* icons = new(ELeave) CArrayPtrFlat< CGulIcon>(1);
    62 
   103 	CleanupStack::PushL(icons);
    63 	CreateIconsL();
   104 	TInt pos = 0;
    64 		
   105 	while (KShowIconArrayIds[pos] > 0)
       
   106 		{
       
   107 		// Load the bitmap for play icon	
       
   108 		CFbsBitmap* bitmap= NULL;//iEikonEnv->CreateBitmapL( _L("*"), KIconArrayIds[pos]);
       
   109 		CFbsBitmap* mask=  NULL;////iEikonEnv->CreateBitmapL( _L("*"), KIconArrayIds[pos+1] );
       
   110 		AknIconUtils::CreateIconL(bitmap,
       
   111 					                          mask,
       
   112 					                          iEikonEnv->EikAppUi()->Application()->BitmapStoreName(),
       
   113 					                          KShowIconArrayIds[pos],
       
   114 					                          KShowIconArrayIds[pos+1]);	
       
   115 		CleanupStack::PushL(bitmap);
       
   116 		// Load the mask for play icon			
       
   117 		CleanupStack::PushL(mask);
       
   118 		// Append the play icon to icon array
       
   119 		icons->AppendL(CGulIcon::NewL(bitmap, mask) );
       
   120 		CleanupStack::Pop(2); // bitmap, mask
       
   121 		pos+=2;
       
   122 		}
       
   123 	iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons);
       
   124 	CleanupStack::Pop(icons); // icons
       
   125 	iListContainer->Listbox()->SetListBoxObserver(this);
    65 	iListContainer->Listbox()->SetListBoxObserver(this);
   126 	
    66 	
   127 	iPodcastModel.FeedEngine().AddObserver(this);
    67 	iPodcastModel.FeedEngine().AddObserver(this);
   128 	iPodcastModel.ShowEngine().AddObserver(this);
    68 	iPodcastModel.ShowEngine().AddObserver(this);
       
    69 	
   129 
    70 
   130 	// no popup options apply to S^1
    71 	// no popup options apply to S^1
   131 #ifndef SYMBIAN1_UI
    72 #ifndef SYMBIAN1_UI
   132 	iStylusPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint(0,0));
    73 	iStylusPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint(0,0));
   133 	TResourceReader reader;
    74 	TResourceReader reader;
   151 		}
    92 		}
   152 		
    93 		
   153 		if (activeShow != NULL) {
    94 		if (activeShow != NULL) {
   154 			DP1("aKeyEvent.iCode=%d", aKeyEvent.iCode);
    95 			DP1("aKeyEvent.iCode=%d", aKeyEvent.iCode);
   155 			switch (aKeyEvent.iCode) {
    96 			switch (aKeyEvent.iCode) {
   156 			case 117: 
       
   157 			case '*':
       
   158 			case EKeySpace:
       
   159 				if (activeShow->PlayState() == EPlayed) {
       
   160 					HandleCommandL(EPodcastMarkAsUnplayed);
       
   161 				} else {
       
   162 					HandleCommandL(EPodcastMarkAsPlayed);
       
   163 				}
       
   164 				break;
       
   165 			case 106:
       
   166 			case '#':
       
   167 				if (activeShow->DownloadState() == ENotDownloaded) {
       
   168 					HandleCommandL(EPodcastDownloadShow);
       
   169 				}
       
   170 				break;
       
   171 			case EKeyBackspace:
    97 			case EKeyBackspace:
   172 			case EKeyDelete:
    98 			case EKeyDelete:
   173 				HandleCommandL(EPodcastRemoveDownload);
    99 				HandleCommandL(EPodcastRemoveDownload);
   174 				break;
   100 				break;
   175 			default:
   101 			default:
   212 void CPodcastQueueView::DoDeactivate()
   138 void CPodcastQueueView::DoDeactivate()
   213 	{
   139 	{
   214 	CPodcastListView::DoDeactivate();
   140 	CPodcastListView::DoDeactivate();
   215 	}
   141 	}
   216 
   142 
   217 // Engine callback when new shows are available
       
   218 void CPodcastQueueView::ShowListUpdatedL()
       
   219 	{
       
   220 	UpdateListboxItemsL();
       
   221 	}
       
   222 
       
   223 void CPodcastQueueView::ShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt /*aBytesTotal*/)
       
   224 	{
       
   225 	if (!iListContainer->IsVisible())
       
   226 		{
       
   227 		return;
       
   228 		}
       
   229 		
       
   230 	CShowInfo *info = iPodcastModel.ShowEngine().ShowDownloading();
       
   231 	if (info) 
       
   232 		{
       
   233 		UpdateShowItemL(info->Uid(), aBytesOfCurrentDownload);
       
   234 		}
       
   235 	}
       
   236 
       
   237 void CPodcastQueueView::ShowDownloadFinishedL(TUint /*aShowUid*/, TInt aError)
       
   238 	{
       
   239 	if (iListContainer->IsVisible()) 
       
   240 		{
       
   241 	
       
   242 		iProgressAdded = EFalse;
       
   243 	
       
   244 		iPodcastModel.GetShowsDownloadingL();
       
   245 		UpdateListboxItemsL();
       
   246 		UpdateToolbar();
       
   247 		
       
   248 		switch(aError)
       
   249 			{
       
   250 			case KErrCouldNotConnect:
       
   251 				{
       
   252 				TBuf<KMaxMessageLength> message;
       
   253 				iEikonEnv->ReadResourceL(message, R_PODCAST_CONNECTION_ERROR);
       
   254 				ShowErrorMessageL(message);
       
   255 				}
       
   256 				break;
       
   257 			default: // Do nothing
       
   258 				break;
       
   259 			}
       
   260 		}
       
   261 	}
       
   262 
       
   263 
       
   264 void CPodcastQueueView::FeedDownloadStartedL(TFeedState /*aState*/, TUint aFeedUid)
       
   265 	{
       
   266 	// TODO make use of the fact that we know that the feed download is
       
   267 	// started instead of checking feed engine states in UpdateFeedUpdateStateL.
       
   268 	if (iPodcastModel.ActiveFeedInfo() != NULL
       
   269 			&& iPodcastModel.ActiveFeedInfo()->Uid() == aFeedUid)
       
   270 		{
       
   271 		UpdateFeedUpdateStateL();
       
   272 		UpdateToolbar();
       
   273 		}	
       
   274 	}
       
   275 
       
   276 void CPodcastQueueView::FeedDownloadFinishedL(TFeedState /*aState*/, TUint aFeedUid, TInt /*aError*/)
       
   277 	{
       
   278 	DP("CPodcastQueueView::FeedDownloadFinishedL BEGIN");
       
   279 	// TODO make use of the fact that we know that the feed download is
       
   280 	// finished instead of checking feed engine states in UpdateFeedUpdateStateL.
       
   281 	if (iPodcastModel.ActiveFeedInfo() != NULL
       
   282 			&& iPodcastModel.ActiveFeedInfo()->Uid() == aFeedUid)
       
   283 		{
       
   284 		UpdateFeedUpdateStateL();
       
   285 		}
       
   286 	DP("CPodcastQueueView::FeedDownloadFinishedL END");
       
   287 	}
       
   288 
       
   289 void CPodcastQueueView::HandleListBoxEventL(CEikListBox* /*aListBox*/,
   143 void CPodcastQueueView::HandleListBoxEventL(CEikListBox* /*aListBox*/,
   290 		TListBoxEvent aEventType)
   144 		TListBoxEvent aEventType)
   291 	{
   145 	{
   292 	switch (aEventType)
   146 	switch (aEventType)
   293 		{
   147 		{
   301 		default:
   155 		default:
   302 			break;
   156 			break;
   303 		}
   157 		}
   304 		UpdateToolbar();
   158 		UpdateToolbar();
   305 	}
   159 	}
   306 
       
   307 void CPodcastQueueView::GetShowIcons(CShowInfo* aShowInfo, TInt& aIconIndex)
       
   308 	{
       
   309 	TBool dlStop = iPodcastModel.SettingsEngine().DownloadSuspended();
       
   310 
       
   311 	switch (aShowInfo->DownloadState())
       
   312 		{
       
   313 		case EDownloaded:
       
   314 			if (aShowInfo->PlayState() == ENeverPlayed) {
       
   315 				aIconIndex = EDownloadedNewShowIcon;
       
   316 			} else {
       
   317 				aIconIndex = EDownloadedShowIcon;
       
   318 			}
       
   319 			break;
       
   320 		case ENotDownloaded:
       
   321 			if (aShowInfo->PlayState() == ENeverPlayed) {
       
   322 				aIconIndex = ENewShowIcon;
       
   323 			} else {
       
   324 				aIconIndex = EShowIcon;
       
   325 			}
       
   326 			break;
       
   327 		case EQueued:
       
   328 			aIconIndex = dlStop ? ESuspendedShowIcon : EQuedShowIcon;
       
   329 			break;
       
   330 		case EDownloading:
       
   331 			aIconIndex = dlStop ? ESuspendedShowIcon : EDownloadingShowIcon;		
       
   332 			break;
       
   333 		case EFailedDownload:
       
   334 			aIconIndex = EFailedShowIcon;
       
   335 			break;
       
   336 		}
       
   337 	}
       
   338 
       
   339 void CPodcastQueueView::UpdateFeedUpdateStateL()
       
   340 	{
       
   341 	TBool listboxDimmed = EFalse;
       
   342 
       
   343 	if (iPodcastModel.FeedEngine().ClientState() != EIdle && iPodcastModel.ActiveFeedInfo()
       
   344 			!= NULL && iPodcastModel.FeedEngine().ActiveClientUid() == iPodcastModel.ActiveFeedInfo()->Uid())
       
   345 		{
       
   346 		listboxDimmed = ETrue;
       
   347 		}
       
   348 
       
   349 	if ((iListContainer->Listbox()->IsDimmed() && !listboxDimmed) || (!iListContainer->Listbox()->IsDimmed() && listboxDimmed))
       
   350 		{
       
   351 		iListContainer->Listbox()->SetDimmed(listboxDimmed);
       
   352 		}
       
   353 	UpdateListboxItemsL();
       
   354 	UpdateToolbar();
       
   355 	}
       
   356 
       
   357 void CPodcastQueueView::FormatShowInfoListBoxItemL(CShowInfo& aShowInfo, TInt aSizeDownloaded)
       
   358 	{
       
   359 	TBuf<32> infoSize;
       
   360 	TInt iconIndex = 0;	
       
   361 	TBuf<KMaxShortDateFormatSpec*2> showDate;
       
   362 	GetShowIcons(&aShowInfo, iconIndex);	
       
   363 	
       
   364 	if(aSizeDownloaded > 0)
       
   365 		{
       
   366 		if (aShowInfo.ShowSize() > 0)
       
   367 			{
       
   368 				infoSize.Format(KSizeDownloadingOf(), ((float) aSizeDownloaded / (float) KSizeMb),
       
   369 						((float)aShowInfo.ShowSize() / (float)KSizeMb));
       
   370 			}
       
   371 		else
       
   372 			{
       
   373 			infoSize.Format(KShowsSizeFormatS60(), (float)aSizeDownloaded / (float)KSizeMb);
       
   374 			}
       
   375 		}
       
   376 	else if (aShowInfo.ShowSize() > 0)
       
   377 		{
       
   378 		infoSize.Format(KShowsSizeFormatS60(), (float)aShowInfo.ShowSize() / (float)KSizeMb);
       
   379 		} 
       
   380 	else {
       
   381 		infoSize = KNullDesC();	
       
   382 	}
       
   383 
       
   384 	if (aShowInfo.PubDate().Int64() == 0)
       
   385 		{
       
   386 		showDate = KNullDesC();
       
   387 		}
       
   388 	else
       
   389 		{
       
   390 		aShowInfo.PubDate().FormatL(showDate, KDateFormatShort());
       
   391 		}
       
   392 	
       
   393 	if(aShowInfo.LastError() != KErrNone)
       
   394 		{
       
   395 		TRAP_IGNORE(((CPodcastAppUi*)AppUi())->GetErrorTextL(infoSize, aShowInfo.LastError()));
       
   396 		showDate.Zero();
       
   397 		}
       
   398 		
       
   399 	if (infoSize.Length() > 0 && showDate.Length() > 0)
       
   400 		{
       
   401 		infoSize.Insert(0,_L(", "));
       
   402 		}
       
   403 
       
   404 	iListboxFormatbuffer.Format(KShowQueueFormat(), iconIndex, &aShowInfo.Title(), &showDate, &infoSize);
       
   405 	}
       
   406 
       
   407 void CPodcastQueueView::UpdateShowItemDataL(CShowInfo* aShowInfo,TInt aIndex, TInt aSizeDownloaded)
       
   408 {
       
   409 	FormatShowInfoListBoxItemL(*aShowInfo, aSizeDownloaded);
       
   410 	iItemArray->Delete(aIndex);
       
   411 	if(aIndex>= iItemArray->MdcaCount())
       
   412 		{
       
   413 		iItemArray->AppendL(iListboxFormatbuffer);
       
   414 		}
       
   415 	else
       
   416 		{
       
   417 		iItemArray->InsertL(aIndex, iListboxFormatbuffer);
       
   418 		}
       
   419 }
       
   420 
       
   421 void CPodcastQueueView::UpdateShowItemL(TUint aUid, TInt aSizeDownloaded)
       
   422 {
       
   423 	RShowInfoArray& array = iPodcastModel.ActiveShowList();
       
   424 	
       
   425 	for (int i=0;i<array.Count();i++) {
       
   426 		if (array[i]->Uid() == aUid) {
       
   427 			UpdateShowItemDataL(array[i], i, aSizeDownloaded);
       
   428 			if (iListContainer->Listbox()->TopItemIndex() <= i &&
       
   429 				iListContainer->Listbox()->BottomItemIndex() >= i) {
       
   430 					iListContainer->Listbox()->DrawItem(i);
       
   431 			}
       
   432 		}
       
   433 	}
       
   434 }
       
   435 
   160 
   436 void CPodcastQueueView::UpdateListboxItemsL()
   161 void CPodcastQueueView::UpdateListboxItemsL()
   437 	{
   162 	{
   438 	if (iListContainer->IsVisible())
   163 	if (iListContainer->IsVisible())
   439 		{
   164 		{
   576 		toolbar->HideItem(EPodcastSuspendDownloads,iPodcastModel.SettingsEngine().DownloadSuspended(), ETrue);
   301 		toolbar->HideItem(EPodcastSuspendDownloads,iPodcastModel.SettingsEngine().DownloadSuspended(), ETrue);
   577 		toolbar->HideItem(EPodcastResumeDownloads,!iPodcastModel.SettingsEngine().DownloadSuspended(), ETrue);	
   302 		toolbar->HideItem(EPodcastResumeDownloads,!iPodcastModel.SettingsEngine().DownloadSuspended(), ETrue);	
   578 		toolbar->SetItemDimmed(EPodcastRemoveDownload, itemCnt == 0, ETrue);		
   303 		toolbar->SetItemDimmed(EPodcastRemoveDownload, itemCnt == 0, ETrue);		
   579 	}
   304 	}
   580 }
   305 }
   581 
       
   582 void CPodcastQueueView::DownloadQueueUpdatedL(TInt /*aDownloadingShows*/, TInt /*aQueuedShows*/)
       
   583 	{
       
   584 		UpdateListboxItemsL();
       
   585 	}
       
   586 
       
   587 void CPodcastQueueView::FeedUpdateAllCompleteL(TFeedState /*aState*/)
       
   588 	{
       
   589 	UpdateListboxItemsL();
       
   590 	UpdateToolbar();
       
   591 	}