application/src/PodcastShowsView.cpp
changeset 2 29cda98b007e
child 3 3326ac3c89fa
equal deleted inserted replaced
1:5f8e5adbbed9 2:29cda98b007e
       
     1 /*
       
     2 * Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
       
     3 *
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of the License "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * EmbedDev AB - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description:
       
    16 *
       
    17 */
       
    18 
       
    19 #include "PodcastShowsView.h"
       
    20 #include "PodcastAppUi.h"
       
    21 #include "ShowEngine.h"
       
    22 #include "SettingsEngine.h"
       
    23 #include "PodcastApp.h"
       
    24 #include "imagehandler.h"
       
    25 #include "constants.h"
       
    26 
       
    27 #include <akntitle.h>
       
    28 #include <podcast.rsg>
       
    29 #include <podcast.mbg>
       
    30 #include <gulicon.h>
       
    31 #include <barsread.h>
       
    32 #include <aknnotedialog.h>
       
    33 #include <aknmessagequerydialog.h>
       
    34 
       
    35 #define KMaxMessageLength 200
       
    36 
       
    37 #define KPodcastImageWidth 160
       
    38 #define KPodcastImageHeight 120
       
    39 #define KPodcastDialogOffset 2
       
    40 
       
    41 #define KOneHundredPercent 100
       
    42 
       
    43 const TInt KSizeBufLen = 64;
       
    44 const TInt KDefaultGran = 5;
       
    45 _LIT(KSizeDownloadingOf, "%.1f/%.1f MB");
       
    46 _LIT(KShowsSizeFormatS60, "%.1f MB");
       
    47 
       
    48 _LIT(KShowFormat, "%d\t%S\t%S %S\t");
       
    49 _LIT(KShowErrorFormat, "%d\t%S\t%S\t");
       
    50 _LIT(KShowQueueFormat, "%d\t%S\t%S%S\t");
       
    51 
       
    52 // these must correspond with TShowsIconIndex
       
    53 
       
    54 const TUint KShowIconArrayIds[] =
       
    55 	{
       
    56 			EMbmPodcastAudio,
       
    57 			EMbmPodcastAudio_mask,
       
    58 			EMbmPodcastAudio_new,
       
    59 			EMbmPodcastAudio_new_mask,
       
    60 			EMbmPodcastAudio_queued,
       
    61 			EMbmPodcastAudio_queued_mask,
       
    62 			EMbmPodcastAudio_downloading,
       
    63 			EMbmPodcastAudio_downloading_mask,
       
    64 			EMbmPodcastAudio_downloaded,
       
    65 			EMbmPodcastAudio_downloaded_mask,
       
    66 			EMbmPodcastAudio_downloaded_new,
       
    67 			EMbmPodcastAudio_downloaded_new_mask,
       
    68 			EMbmPodcastAudio_failed,
       
    69 			EMbmPodcastAudio_failed_mask,
       
    70 			EMbmPodcastAudio_suspended,
       
    71 			EMbmPodcastAudio_suspended_mask,
       
    72 			0,
       
    73 			0
       
    74 	};
       
    75 
       
    76 /** 
       
    77  *  This is an interal class to display a message query dialog with an image at the bottm
       
    78  */
       
    79 class CPodcastImageMessageQueryDialog:public CAknMessageQueryDialog
       
    80 	{
       
    81 	public:
       
    82 		/**
       
    83 		 * C++ default constructor.
       
    84 		 *
       
    85 		 * @param aMessage Dialog box text.
       
    86 		 * @param aHeader Header for the dialog.
       
    87 		 * @deprecated 
       
    88 		 */ 
       
    89 		CPodcastImageMessageQueryDialog(TDesC* aMessage, TDesC* aHeader):CAknMessageQueryDialog(aMessage, aHeader)
       
    90     		{
       
    91 
       
    92     		}    
       
    93 
       
    94 		~CPodcastImageMessageQueryDialog()
       
    95 			{
       
    96 
       
    97 			}
       
    98 
       
    99 		void SetSizeAndPosition(const TSize& aSize)
       
   100 			{
       
   101 			CAknMessageQueryDialog::SetSizeAndPosition(aSize);
       
   102 
       
   103 			TPoint pos = Position();		 
       
   104 			TSize size = Size();
       
   105 
       
   106 			CAknDialog::SetSizeAndPosition(aSize);		 		 
       
   107 
       
   108 			pos.iY-=((aSize.iHeight-size.iHeight)-KPodcastDialogOffset);
       
   109 			SetPosition(pos);	
       
   110 			SetSize(aSize);
       
   111 			}
       
   112 
       
   113 	};
       
   114 
       
   115 CPodcastShowsView* CPodcastShowsView::NewL(CPodcastModel& aPodcastModel)
       
   116 	{
       
   117 	CPodcastShowsView* self = CPodcastShowsView::NewLC(aPodcastModel);
       
   118 	CleanupStack::Pop(self);
       
   119 	return self;
       
   120 	}
       
   121 
       
   122 CPodcastShowsView* CPodcastShowsView::NewLC(CPodcastModel& aPodcastModel)
       
   123 	{
       
   124 	CPodcastShowsView* self = new ( ELeave ) CPodcastShowsView(aPodcastModel);
       
   125 	CleanupStack::PushL(self);
       
   126 	self->ConstructL();
       
   127 	return self;
       
   128 	}
       
   129 
       
   130 CPodcastShowsView::CPodcastShowsView(CPodcastModel& aPodcastModel) :
       
   131 	iPodcastModel(aPodcastModel)
       
   132 	{
       
   133 	}
       
   134 
       
   135 void CPodcastShowsView::ConstructL()
       
   136 	{
       
   137 	BaseConstructL(R_PODCAST_SHOWSVIEW);
       
   138 	CPodcastListView::ConstructL();
       
   139 	
       
   140 	CreateIconsL();
       
   141 	
       
   142 	iListContainer->Listbox()->SetListBoxObserver(this);
       
   143 	
       
   144 	iPodcastModel.FeedEngine().AddObserver(this);
       
   145 	iPodcastModel.ShowEngine().AddObserver(this);
       
   146 	
       
   147 	iStylusPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint(0,0));
       
   148 	TResourceReader reader;
       
   149 	iCoeEnv->CreateResourceReaderLC(reader,R_SHOWVIEW_POPUP_MENU);
       
   150 	iStylusPopupMenu->ConstructFromResourceL(reader);
       
   151 
       
   152 	CleanupStack::PopAndDestroy();	
       
   153 	}
       
   154 
       
   155 void CPodcastShowsView::CreateIconsL()
       
   156 	{
       
   157 	CArrayPtr< CGulIcon>* icons = new(ELeave) CArrayPtrFlat< CGulIcon>(1);
       
   158 	CleanupStack::PushL(icons);
       
   159 	TInt pos = 0;
       
   160 	while (KShowIconArrayIds[pos] > 0)
       
   161 		{
       
   162 		// Load the bitmap for play icon	
       
   163 		CFbsBitmap* bitmap= NULL;//iEikonEnv->CreateBitmapL( _L("*"), KIconArrayIds[pos]);
       
   164 		CFbsBitmap* mask=  NULL;////iEikonEnv->CreateBitmapL( _L("*"), KIconArrayIds[pos+1] );
       
   165 		AknIconUtils::CreateIconL(bitmap,
       
   166 					                          mask,
       
   167 					                          iEikonEnv->EikAppUi()->Application()->BitmapStoreName(),
       
   168 					                          KShowIconArrayIds[pos],
       
   169 					                          KShowIconArrayIds[pos+1]);	
       
   170 		CleanupStack::PushL(bitmap);		
       
   171 		CleanupStack::PushL(mask);
       
   172 		
       
   173 		// Append the play icon to icon array
       
   174 		icons->AppendL(CGulIcon::NewL(bitmap, mask) );
       
   175 		CleanupStack::Pop(2); // bitmap, mask
       
   176 		pos+=2;
       
   177 		}
       
   178 		
       
   179 	iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons);
       
   180 	CleanupStack::Pop(icons); // icons
       
   181 	}
       
   182 
       
   183 TKeyResponse CPodcastShowsView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   184 	{
       
   185 	if (aType == EEventKey)
       
   186 		{
       
   187 		CShowInfo *activeShow = NULL;
       
   188 
       
   189 		TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
   190 		if(index >= 0 && index < iPodcastModel.ActiveShowList().Count())
       
   191 		{
       
   192 			activeShow = iPodcastModel.ActiveShowList()[index];
       
   193 		}
       
   194 		
       
   195 		if (activeShow != NULL) {
       
   196 			DP1("aKeyEvent.iCode=%d", aKeyEvent.iCode);
       
   197 			switch (aKeyEvent.iCode) {
       
   198 			case 117: 
       
   199 			case '*':
       
   200 			case EKeySpace:
       
   201 				if (activeShow->PlayState() == EPlayed) {
       
   202 					HandleCommandL(EPodcastMarkAsUnplayed);
       
   203 				} else {
       
   204 					HandleCommandL(EPodcastMarkAsPlayed);
       
   205 				}
       
   206 				break;
       
   207 			case 106:
       
   208 			case '#':
       
   209 				if (activeShow->DownloadState() == ENotDownloaded) {
       
   210 					HandleCommandL(EPodcastDownloadShow);
       
   211 				}
       
   212 				break;
       
   213 			case EKeyBackspace:
       
   214 			case EKeyDelete:
       
   215 					HandleCommandL(EPodcastDeleteShow);
       
   216 				break;
       
   217 			default:
       
   218 				break;
       
   219 			}
       
   220 			UpdateToolbar();
       
   221 		}
       
   222 	}
       
   223 		return CPodcastListView::OfferKeyEventL(aKeyEvent, aType);
       
   224 	}
       
   225 
       
   226 CPodcastShowsView::~CPodcastShowsView()
       
   227 	{
       
   228 	iPodcastModel.ShowEngine().RemoveObserver(this);
       
   229 	iPodcastModel.FeedEngine().RemoveObserver(this);
       
   230 	
       
   231     if(iStylusPopupMenu)
       
   232         delete iStylusPopupMenu, iStylusPopupMenu = NULL;
       
   233 	}
       
   234 
       
   235 
       
   236 TUid CPodcastShowsView::Id() const
       
   237 	{
       
   238 	return KUidPodcastShowsViewID;
       
   239 	}
       
   240 
       
   241 void CPodcastShowsView::DoActivateL(const TVwsViewId& aPrevViewId,
       
   242 		TUid aCustomMessageId, const TDesC8& aCustomMessage)
       
   243 	{
       
   244 	DP("CPodcastShowsView::DoActivateL BEGIN");
       
   245 	
       
   246 	UpdateViewTitleL();
       
   247 	
       
   248 	CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage);
       
   249 	iPreviousView = TVwsViewId(KUidPodcast, KUidPodcastFeedViewID);
       
   250 	
       
   251 	UpdateFeedUpdateStateL();
       
   252 	UpdateToolbar();
       
   253 	DP("CPodcastShowsView::DoActivateL END");
       
   254 	}
       
   255 
       
   256 void CPodcastShowsView::DoDeactivate()
       
   257 	{
       
   258 	CAknTitlePane* titlePane = static_cast<CAknTitlePane*>
       
   259 		     ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   260 	
       
   261 //	titlePane->SetSmallPicture(NULL, NULL, ETrue);
       
   262 	titlePane->SetPicture(NULL, NULL);
       
   263 	titlePane->SetTextToDefaultL();
       
   264 	CPodcastListView::DoDeactivate();
       
   265 	}
       
   266 
       
   267 // Engine callback when new shows are available
       
   268 void CPodcastShowsView::ShowListUpdatedL()
       
   269 	{
       
   270 	UpdateListboxItemsL();
       
   271 	}
       
   272 
       
   273 void CPodcastShowsView::ShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt /*aBytesTotal*/)
       
   274 	{
       
   275 	if (!iListContainer->IsVisible())
       
   276 		{
       
   277 		return;
       
   278 		}
       
   279 	
       
   280 	CShowInfo *info = iPodcastModel.ShowEngine().ShowDownloading();
       
   281 	if (info) 
       
   282 		{
       
   283 		UpdateShowItemL(info->Uid(), aBytesOfCurrentDownload);
       
   284 		}		
       
   285 	}
       
   286 
       
   287 void CPodcastShowsView::ShowDownloadFinishedL(TUint /*aShowUid*/, TInt aError)
       
   288 	{
       
   289 	iProgressAdded = EFalse;
       
   290 	
       
   291 	switch(aError)
       
   292 		{
       
   293 		case KErrCouldNotConnect:
       
   294 			{
       
   295 			TBuf<KMaxMessageLength> message;
       
   296 			iEikonEnv->ReadResourceL(message, R_PODCAST_CONNECTION_ERROR);
       
   297 			ShowErrorMessage(message);
       
   298 			}
       
   299 			break;
       
   300 		default: // Do nothing
       
   301 			break;
       
   302 		}
       
   303 	}
       
   304 
       
   305 
       
   306 void CPodcastShowsView::FeedDownloadStartedL(TFeedState /*aState*/, TUint aFeedUid)
       
   307 	{
       
   308 	// TODO make use of the fact that we know that the feed download is
       
   309 	// started instead of checking feed engine states in UpdateFeedUpdateStateL.
       
   310 	if (iPodcastModel.ActiveFeedInfo() != NULL
       
   311 			&& iPodcastModel.ActiveFeedInfo()->Uid() == aFeedUid)
       
   312 		{
       
   313 		TRAP_IGNORE(UpdateFeedUpdateStateL());
       
   314 		UpdateToolbar();
       
   315 		}	
       
   316 	}
       
   317 
       
   318 void CPodcastShowsView::FeedDownloadFinishedL(TFeedState /*aState*/, TUint aFeedUid, TInt /*aError*/)
       
   319 	{
       
   320 	DP("CPodcastShowsView::FeedDownloadFinishedL BEGIN");
       
   321 	// TODO make use of the fact that we know that the feed download is
       
   322 	// finished instead of checking feed engine states in UpdateFeedUpdateStateL.
       
   323 	if (iPodcastModel.ActiveFeedInfo() != NULL
       
   324 			&& iPodcastModel.ActiveFeedInfo()->Uid() == aFeedUid)
       
   325 		{
       
   326 		TRAP_IGNORE(UpdateFeedUpdateStateL());
       
   327 		TRAP_IGNORE(UpdateViewTitleL());
       
   328 		}
       
   329 	DP("CPodcastShowsView::FeedDownloadFinishedL END");
       
   330 	}
       
   331 
       
   332 void CPodcastShowsView::HandleListBoxEventL(CEikListBox* /*aListBox*/,
       
   333 		TListBoxEvent aEventType)
       
   334 	{
       
   335 	switch (aEventType)
       
   336 		{
       
   337 		case EEventEnterKeyPressed:		
       
   338 		case EEventItemActioned:
       
   339 		case EEventItemDoubleClicked:
       
   340 			{
       
   341 			RShowInfoArray &fItems = iPodcastModel.ActiveShowList();
       
   342 			TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
   343 			if (index>=0 && index< fItems.Count())
       
   344 				{
       
   345 				DP2("Handle event for podcast %S, downloadState is %d", &(fItems[index]->Title()), fItems[index]->DownloadState());
       
   346 				CShowInfo *showInfo = fItems[index];
       
   347 				
       
   348 				switch (showInfo->DownloadState()) {
       
   349 				case ENotDownloaded:
       
   350 					HandleCommandL(EPodcastDownloadShow);
       
   351 					break;
       
   352 				case EQueued:
       
   353 					AppUi()->ActivateLocalViewL(KUidPodcastQueueViewID,  TUid::Uid(0), KNullDesC8());
       
   354 					((CPodcastAppUi*)AppUi())->SetActiveTab(KTabIdQueue);
       
   355 					break;
       
   356 				case EDownloaded:
       
   357 					#pragma message("LAPER Replace activate playview with activate playback in mpx")
       
   358 					break;
       
   359 				default:
       
   360 					break;
       
   361 					}
       
   362 				}
       
   363 			}
       
   364 			break;
       
   365 		default:
       
   366 			break;
       
   367 		}
       
   368 		UpdateToolbar();
       
   369 	}
       
   370 
       
   371 void CPodcastShowsView::GetShowIcons(CShowInfo* aShowInfo, TInt& aIconIndex)
       
   372 	{
       
   373 	TBool dlStop = iPodcastModel.SettingsEngine().DownloadSuspended();
       
   374 	TUint showDownloadingUid = iPodcastModel.ShowEngine().ShowDownloading() ? iPodcastModel.ShowEngine().ShowDownloading()->Uid() : 0;
       
   375 	
       
   376 	if (showDownloadingUid == aShowInfo->Uid())
       
   377 		{
       
   378 		aIconIndex = dlStop ? ESuspendedShowIcon : EDownloadingShowIcon;		
       
   379 		}
       
   380 	else
       
   381 		{
       
   382 		switch (aShowInfo->DownloadState())
       
   383 			{
       
   384 			case EDownloaded:
       
   385 				if (aShowInfo->PlayState() == ENeverPlayed) {
       
   386 					aIconIndex = EDownloadedNewShowIcon;
       
   387 				} else {
       
   388 					aIconIndex = EDownloadedShowIcon;
       
   389 				}
       
   390 				break;
       
   391 			case ENotDownloaded:
       
   392 				if (aShowInfo->PlayState() == ENeverPlayed) {
       
   393 					aIconIndex = ENewShowIcon;
       
   394 				} else {
       
   395 					aIconIndex = EShowIcon;
       
   396 				}
       
   397 				break;
       
   398 			case EQueued:
       
   399 				aIconIndex = dlStop ? ESuspendedShowIcon : EQuedShowIcon;
       
   400 				break;
       
   401 			case EDownloading:
       
   402 				aIconIndex = dlStop ? ESuspendedShowIcon : EDownloadingShowIcon;		
       
   403 				break;
       
   404 			case EFailedDownload:
       
   405 				aIconIndex = EFailedShowIcon;
       
   406 				break;
       
   407 			}
       
   408 		}
       
   409 	}
       
   410 	
       
   411 
       
   412 void CPodcastShowsView::UpdateFeedUpdateStateL()
       
   413 	{
       
   414 	TBool listboxDimmed = EFalse;
       
   415 
       
   416 	if (iPodcastModel.FeedEngine().ClientState() != EIdle && iPodcastModel.ActiveFeedInfo()
       
   417 			!= NULL && iPodcastModel.FeedEngine().ActiveClientUid() == iPodcastModel.ActiveFeedInfo()->Uid())
       
   418 		{
       
   419 		listboxDimmed = ETrue;
       
   420 		}
       
   421 
       
   422 	if ((iListContainer->Listbox()->IsDimmed() && !listboxDimmed) || (!iListContainer->Listbox()->IsDimmed() && listboxDimmed))
       
   423 		{
       
   424 		iListContainer->Listbox()->SetDimmed(listboxDimmed);
       
   425 		}
       
   426 	UpdateListboxItemsL();
       
   427 	UpdateToolbar();
       
   428 	}
       
   429 
       
   430 void CPodcastShowsView::FormatShowInfoListBoxItemL(CShowInfo& aShowInfo, TInt aSizeDownloaded)
       
   431 	{
       
   432 	TBuf<32> infoSize;
       
   433 	TInt iconIndex = 0;	
       
   434 	TBuf<KMaxShortDateFormatSpec*2> showDate;
       
   435 	GetShowIcons(&aShowInfo, iconIndex);	
       
   436 	
       
   437 	if(aSizeDownloaded > 0)
       
   438 		{
       
   439 		if (aShowInfo.ShowSize() > 0)
       
   440 			{
       
   441 				infoSize.Format(KSizeDownloadingOf(), ((float) aSizeDownloaded / (float) KSizeMb),
       
   442 						((float)aShowInfo.ShowSize() / (float)KSizeMb));
       
   443 			}
       
   444 		else
       
   445 			{
       
   446 			infoSize.Format(KShowsSizeFormatS60(), (float)aSizeDownloaded / (float)KSizeMb);
       
   447 			}
       
   448 		}
       
   449 	else if (aShowInfo.ShowSize() > 0)
       
   450 		{
       
   451 		infoSize.Format(KShowsSizeFormatS60(), (float)aShowInfo.ShowSize() / (float)KSizeMb);
       
   452 		} 
       
   453 	else {
       
   454 		infoSize = KNullDesC();	
       
   455 	}
       
   456 
       
   457 	if (aShowInfo.PubDate().Int64() == 0)
       
   458 		{
       
   459 		showDate = KNullDesC();
       
   460 		}
       
   461 	else
       
   462 		{
       
   463 		aShowInfo.PubDate().FormatL(showDate, KDateFormatShort());
       
   464 		}
       
   465 
       
   466 	if(aShowInfo.LastError() != KErrNone)
       
   467 		{
       
   468 		TBuf<KSizeBufLen> errorBuffer;
       
   469 		GetShowErrorText(errorBuffer, aShowInfo.LastError());
       
   470 		iListboxFormatbuffer.Format(KShowErrorFormat(), iconIndex, &aShowInfo.Title(), &errorBuffer);
       
   471 		}
       
   472 	else	
       
   473 		{
       
   474 		if (infoSize.Length() > 0) {
       
   475 			infoSize.Insert(0,_L(", "));
       
   476 		}
       
   477 		
       
   478 		iListboxFormatbuffer.Format(KShowFormat(), iconIndex, &aShowInfo.Title(), &showDate, &infoSize);
       
   479 		}
       
   480 	}
       
   481 
       
   482 void CPodcastShowsView::GetShowErrorText(TDes &aErrorMessage, TInt aErrorCode)
       
   483 	{
       
   484 	iEikonEnv->GetErrorText(aErrorMessage, aErrorCode);
       
   485 	}
       
   486 
       
   487 void CPodcastShowsView::UpdateShowItemDataL(CShowInfo* aShowInfo,TInt aIndex, TInt aSizeDownloaded)
       
   488 {
       
   489 	FormatShowInfoListBoxItemL(*aShowInfo, aSizeDownloaded);
       
   490 	iItemArray->Delete(aIndex);
       
   491 	if(aIndex>= iItemArray->MdcaCount())
       
   492 		{
       
   493 		iItemArray->AppendL(iListboxFormatbuffer);
       
   494 		}
       
   495 	else
       
   496 		{
       
   497 		iItemArray->InsertL(aIndex, iListboxFormatbuffer);
       
   498 		}
       
   499 }
       
   500 
       
   501 void CPodcastShowsView::UpdateShowItemL(TUint aUid, TInt aSizeDownloaded)
       
   502 {
       
   503 	RShowInfoArray& array = iPodcastModel.ActiveShowList();
       
   504 	
       
   505 	for (int i=0;i<array.Count();i++) {
       
   506 		if (array[i]->Uid() == aUid) {
       
   507 			UpdateShowItemDataL(array[i], i, aSizeDownloaded);
       
   508 			if (iListContainer->Listbox()->TopItemIndex() <= i &&
       
   509 				iListContainer->Listbox()->BottomItemIndex() >= i) {
       
   510 					iListContainer->Listbox()->DrawItem(i);
       
   511 			}
       
   512 		}
       
   513 	}
       
   514 }
       
   515 
       
   516 void CPodcastShowsView::UpdateListboxItemsL()
       
   517 	{
       
   518 	if (iListContainer->IsVisible())
       
   519 		{
       
   520 		TListItemProperties itemProps;
       
   521 		TInt len = 0;
       
   522 
       
   523 		iPodcastModel.GetShowsByFeed(iPodcastModel.ActiveFeedInfo()->Uid());
       
   524 
       
   525 		RShowInfoArray &fItems = iPodcastModel.ActiveShowList();
       
   526 		len = fItems.Count();
       
   527 
       
   528 		if (iListContainer->Listbox() != NULL)
       
   529 			{
       
   530 			TBool allUidsMatch = EFalse;
       
   531 
       
   532 			if (len == iListContainer->Listbox()->Model()->NumberOfItems())
       
   533 				{
       
   534 				allUidsMatch = ETrue;
       
   535 				TUint itemId = 0;
       
   536 				for (TInt loop = 0; loop< len; loop++)
       
   537 					{
       
   538 					itemId = iItemIdArray[loop];
       
   539 					if (fItems[loop]->Uid() != itemId)
       
   540 						{
       
   541 						allUidsMatch = EFalse;
       
   542 						break;
       
   543 						}
       
   544 					}
       
   545 				}
       
   546 
       
   547 			if (allUidsMatch && len > 0)
       
   548 				{
       
   549 				for (TInt loop = 0; loop< len; loop++)
       
   550 					{					
       
   551 					UpdateShowItemDataL(fItems[loop], loop);	
       
   552 					}
       
   553 				}
       
   554 			else
       
   555 				{
       
   556 				iListContainer->Listbox()->ItemDrawer()->ClearAllPropertiesL();
       
   557 				iListContainer->Listbox()->Reset();
       
   558 				iItemIdArray.Reset();
       
   559 				iItemArray->Reset();
       
   560 
       
   561 				if (len > 0)
       
   562 					{
       
   563 					for (TInt i=0; i<len; i++)
       
   564 						{
       
   565 						CShowInfo *si = fItems[i];
       
   566 						FormatShowInfoListBoxItemL(*si);
       
   567 						iItemIdArray.Append(si->Uid());						
       
   568 						iItemArray->AppendL(iListboxFormatbuffer);
       
   569 						}
       
   570 					}
       
   571 				else
       
   572 					{
       
   573 					iItemArray->Reset();
       
   574 					iItemIdArray.Reset();
       
   575 					
       
   576 					itemProps.SetDimmed(ETrue);
       
   577 					itemProps.SetHiddenSelection(ETrue);
       
   578 					}
       
   579 				iListContainer->Listbox()->HandleItemAdditionL();
       
   580 				}				
       
   581 			}
       
   582 		}
       
   583 	}
       
   584 
       
   585 /** 
       
   586  * Command handling function intended for overriding by sub classes. 
       
   587  * Default implementation is empty.  
       
   588  * @param aCommand ID of the command to respond to. 
       
   589  */
       
   590 void CPodcastShowsView::HandleCommandL(TInt aCommand)
       
   591 	{
       
   592 	switch (aCommand)
       
   593 		{
       
   594 		case EPodcastMarkAsPlayed:
       
   595 			SetShowPlayed(ETrue);
       
   596 			break;
       
   597 		case EPodcastMarkAsUnplayed:
       
   598 			SetShowPlayed(EFalse);
       
   599 			break;
       
   600 		case EPodcastMarkAllPlayed:
       
   601 			iPodcastModel.MarkSelectionPlayed();
       
   602 			UpdateListboxItemsL();
       
   603 			break;
       
   604 		case EPodcastDeleteShow:
       
   605 			DeleteShow();
       
   606 			break;
       
   607 		case EPodcastDownloadShow:
       
   608 			{
       
   609 			TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
   610 			if (index >= 0 && index < iPodcastModel.ActiveShowList().Count())
       
   611 				{
       
   612 				iPodcastModel.ShowEngine().AddDownloadL(*iPodcastModel.ActiveShowList()[index]);
       
   613 				UpdateShowItemL(iPodcastModel.ActiveShowList()[index]->Uid(),-1);
       
   614 				}
       
   615 			}
       
   616 			break;
       
   617 		case EPodcastUpdateFeed:
       
   618 			{
       
   619 
       
   620 			if (iPodcastModel.ActiveFeedInfo()->Url().Length()>0)
       
   621 				{
       
   622 				TRAPD(error, iPodcastModel.FeedEngine().UpdateFeedL(iPodcastModel.ActiveFeedInfo()->Uid()));
       
   623 
       
   624 				if (error != KErrNone)
       
   625 					{
       
   626 					HBufC
       
   627 							* str =
       
   628 							iEikonEnv->AllocReadResourceLC(R_PODCAST_FEEDS_UPDATE_ERROR);
       
   629 					User::InfoPrint(*str);
       
   630 					CleanupStack::PopAndDestroy(str);
       
   631 					}
       
   632 				}
       
   633 			}
       
   634 			break;
       
   635 		case EPodcastCancelUpdateAllFeeds:
       
   636 			iPodcastModel.FeedEngine().CancelUpdateAllFeeds();
       
   637 			break;
       
   638 		case EPodcastShowInfo:
       
   639 			{
       
   640 			DisplayShowInfoDialogL();
       
   641 			}break;
       
   642 		default:
       
   643 			CPodcastListView::HandleCommandL(aCommand);
       
   644 			break;
       
   645 		}
       
   646 	UpdateToolbar();
       
   647 	}
       
   648 	
       
   649 void CPodcastShowsView::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
       
   650 {
       
   651 	if(aResourceId == R_PODCAST_SHOWSVIEW_MENU)
       
   652 		{
       
   653 		TBool updatingState = iPodcastModel.FeedEngine().ClientState() != EIdle && iPodcastModel.FeedEngine().ActiveClientUid() == iPodcastModel.ActiveFeedInfo()->Uid();
       
   654 		aMenuPane->SetItemDimmed(EPodcastMarkAllPlayed, updatingState);
       
   655 		}
       
   656 }
       
   657 	
       
   658 void CPodcastShowsView::ImageOperationCompleteL(TInt aError)
       
   659 	{
       
   660 	iLastImageHandlerError = aError;
       
   661 	if(iSetTitlebarImage)
       
   662 		{
       
   663 		iSetTitlebarImage = EFalse;
       
   664 		if(aError == KErrNone)
       
   665 			{
       
   666 			CAknTitlePane* titlePane = static_cast<CAknTitlePane*>
       
   667 						 ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   668 			titlePane->SetSmallPicture(iPodcastModel.ImageHandler().ScaledBitmap(), NULL, ETrue);
       
   669 			}
       
   670 		else
       
   671 			{
       
   672 			iPodcastModel.ImageHandler().ScaledBitmap();
       
   673 			}
       
   674 			
       
   675 		}
       
   676 	else
       
   677 		{
       
   678 		CActiveScheduler::Stop();
       
   679 		}
       
   680 	}
       
   681 	
       
   682 void CPodcastShowsView::DisplayShowInfoDialogL()
       
   683 	{
       
   684 	TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
   685 	if (index >= 0 && index < iPodcastModel.ActiveShowList().Count())
       
   686 		{
       
   687 		CShowInfo* info = iPodcastModel.ActiveShowList()[index];
       
   688 		TUint32 feedUid = info->FeedUid();							
       
   689 		CFeedInfo* feedInfo = iPodcastModel.FeedEngine().GetFeedInfoByUid(feedUid);
       
   690 		
       
   691 		CPodcastImageMessageQueryDialog* note = new ( ELeave ) CPodcastImageMessageQueryDialog( (TDesC*)&info->Description(), (TDesC*)&info->Title() );
       
   692 							
       
   693 		note->PrepareLC( R_SHOW_INFO_NOTE ); // Adds to CleanupStack
       
   694 		
       
   695 		if(feedInfo && feedInfo->ImageFileName().Length()>0)
       
   696 			{
       
   697 			CFbsBitmap * bitmap = new (ELeave) CFbsBitmap;
       
   698 			CleanupStack::PushL(bitmap);
       
   699 			
       
   700 			TRAPD(loaderror, iPodcastModel.ImageHandler().LoadFileAndScaleL(bitmap, feedInfo->ImageFileName(), TSize(KPodcastImageWidth, KPodcastImageHeight), *this));
       
   701 			
       
   702 			if(loaderror == KErrNone)
       
   703 				{
       
   704 				CActiveScheduler::Start();
       
   705 				if(iLastImageHandlerError == KErrNone)
       
   706 					{	
       
   707 					CEikImage* image = static_cast<CEikImage*>(note->ControlOrNull(EPodcastShowInfoImage));
       
   708 					image->SetBitmap(bitmap);
       
   709 					CleanupStack::Pop(bitmap);
       
   710 					bitmap = NULL;
       
   711 					}
       
   712 				else
       
   713 					{				
       
   714 					CleanupStack::PopAndDestroy(bitmap);
       
   715 					bitmap = NULL;
       
   716 					}
       
   717 				}
       
   718 			else
       
   719 				{
       
   720 				CleanupStack::PopAndDestroy(bitmap);
       
   721 				bitmap = NULL;
       
   722 				}
       
   723 			}												
       
   724 		
       
   725 		note->RunLD(); 
       
   726 		}
       
   727 	}
       
   728 
       
   729 void CPodcastShowsView::UpdateToolbar()
       
   730 {
       
   731 	CAknToolbar* toolbar = Toolbar();
       
   732 	
       
   733 	RShowInfoArray &fItems = iPodcastModel.ActiveShowList();
       
   734 	TInt itemCnt = fItems.Count();
       
   735 
       
   736 	TBool hideDownloadShowCmd = EFalse;
       
   737 	TBool dimDownloadShowCmd = EFalse;
       
   738 	TBool hideSetPlayed = EFalse;
       
   739 	TBool updatingState = iPodcastModel.FeedEngine().ClientState() != EIdle && 
       
   740 			iPodcastModel.FeedEngine().ActiveClientUid() == iPodcastModel.ActiveFeedInfo()->Uid();
       
   741 	
       
   742 	if(iListContainer->Listbox() != NULL)
       
   743 	{
       
   744 		TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
   745 		
       
   746 		if(index>= 0 && index < itemCnt)
       
   747 		{
       
   748 			switch(fItems[index]->DownloadState())
       
   749 				{
       
   750 				case ENotDownloaded:
       
   751 				case EFailedDownload:
       
   752 					hideDownloadShowCmd = EFalse;
       
   753 					dimDownloadShowCmd = EFalse;
       
   754 					break;
       
   755 				case EQueued:
       
   756 				case EDownloading:
       
   757 					hideDownloadShowCmd = EFalse;
       
   758 					dimDownloadShowCmd = ETrue;
       
   759 					break;
       
   760 				case EDownloaded:
       
   761 					hideDownloadShowCmd = ETrue;
       
   762 					break;
       
   763 				}
       
   764 				
       
   765 			if(fItems[index]->PlayState() == EPlayed) {
       
   766 				hideSetPlayed = ETrue;
       
   767 			}
       
   768 		}
       
   769 	}
       
   770 	
       
   771 	toolbar->HideItem(EPodcastUpdateFeed, updatingState, ETrue ); 
       
   772 	toolbar->HideItem(EPodcastCancelUpdateAllFeeds, !updatingState, ETrue );
       
   773 	
       
   774 	if (hideDownloadShowCmd) {
       
   775 		toolbar->HideItem(EPodcastDownloadShow, ETrue, ETrue );
       
   776 		toolbar->HideItem(EPodcastDeleteShow, EFalse, ETrue);
       
   777 		toolbar->SetItemDimmed(EPodcastDeleteShow, updatingState, ETrue);
       
   778 	} else {
       
   779 		toolbar->HideItem(EPodcastDownloadShow, EFalse, ETrue );
       
   780 		toolbar->HideItem(EPodcastDeleteShow, ETrue, ETrue);
       
   781 		toolbar->SetItemDimmed(EPodcastDownloadShow, updatingState || dimDownloadShowCmd, ETrue);	
       
   782 	}
       
   783 	
       
   784 	if (hideSetPlayed) {
       
   785 		toolbar->HideItem(EPodcastMarkAsPlayed, ETrue, ETrue );
       
   786 		toolbar->HideItem(EPodcastMarkAsUnplayed, EFalse, ETrue );
       
   787 		toolbar->SetItemDimmed(EPodcastMarkAsUnplayed, updatingState, ETrue);
       
   788 	} else {
       
   789 		toolbar->HideItem(EPodcastMarkAsPlayed, EFalse, ETrue );
       
   790 		toolbar->HideItem(EPodcastMarkAsUnplayed, ETrue, ETrue );
       
   791 		toolbar->SetItemDimmed(EPodcastMarkAsPlayed, updatingState, ETrue);
       
   792 	}
       
   793 }
       
   794 
       
   795 void CPodcastShowsView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /* aPenEventScreenLocation */)
       
   796 {
       
   797 	DP("CPodcastShowsView::HandleLongTapEventL BEGIN");
       
   798 	
       
   799     if(iStylusPopupMenu)
       
   800     {
       
   801 		TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
   802 		if (index >= 0 && index < iPodcastModel.ActiveShowList().Count())
       
   803 			{
       
   804 			CShowInfo *info = iPodcastModel.ActiveShowList()[index];
       
   805 			TBool hideDownloadShowCmd = info->DownloadState() != ENotDownloaded;
       
   806 			TBool hideDeleteShowCmd = info->DownloadState() != EDownloaded;
       
   807 			TBool hideMarkOld = info->PlayState() == EPlayed;
       
   808 			
       
   809 			iStylusPopupMenu->SetItemDimmed(EPodcastMarkAsPlayed, hideMarkOld);
       
   810 			iStylusPopupMenu->SetItemDimmed(EPodcastMarkAsUnplayed, !hideMarkOld);
       
   811 						
       
   812 			iStylusPopupMenu->SetItemDimmed(EPodcastDownloadShow, hideDownloadShowCmd);
       
   813 			iStylusPopupMenu->SetItemDimmed(EPodcastDeleteShow, hideDeleteShowCmd);
       
   814 			}
       
   815 
       
   816 		iStylusPopupMenu->ShowMenu();
       
   817 		iStylusPopupMenu->SetPosition(aPenEventLocation);
       
   818     }
       
   819 	DP("CPodcastShowsView::HandleLongTapEventL END");
       
   820 }
       
   821 
       
   822 void CPodcastShowsView::SetShowPlayed(TBool aPlayed)
       
   823 	{
       
   824 
       
   825 	TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
   826 				
       
   827 	if (index >= 0 && index < iPodcastModel.ActiveShowList().Count())
       
   828 		{
       
   829 		CShowInfo *info = iPodcastModel.ActiveShowList()[index];
       
   830 		info->SetPlayState(aPlayed ? EPlayed : ENeverPlayed);
       
   831 		iPodcastModel.ShowEngine().UpdateShow(*info);
       
   832 		UpdateShowItemDataL(iPodcastModel.ActiveShowList()[index], index, 0);
       
   833 		iListContainer->Listbox()->DrawItem(index);					
       
   834 		}
       
   835 	}
       
   836 
       
   837 void CPodcastShowsView::DeleteShow()
       
   838 	{
       
   839 	TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
   840 
       
   841 	if (index >= 0 && index < iPodcastModel.ActiveShowList().Count())
       
   842 		{
       
   843 		CShowInfo *info = iPodcastModel.ActiveShowList()[index];
       
   844 		TBuf<KMaxMessageLength> msg;
       
   845 		TBuf<KMaxMessageLength> templ;
       
   846 		iEikonEnv->ReadResourceL(templ, R_PODCAST_DELETE_SHOW_PROMPT);
       
   847 		msg.Format(templ, &(info->Title()));
       
   848 		if (ShowQueryMessage(msg))
       
   849 			{
       
   850 			iPodcastModel.ShowEngine().DeleteShowL(iPodcastModel.ActiveShowList()[index]->Uid());
       
   851 			
       
   852 			// and mark as played, and not downloaded
       
   853 			
       
   854 			info->SetDownloadState(ENotDownloaded);
       
   855 			info->SetPlayState(EPlayed);
       
   856 			iPodcastModel.ShowEngine().UpdateShow(*info);
       
   857 			
       
   858 			UpdateShowItemDataL(iPodcastModel.ActiveShowList()[index], index, 0);
       
   859 			iListContainer->Listbox()->DrawItem(index);					
       
   860 			}
       
   861 		}
       
   862 	}
       
   863 
       
   864 void CPodcastShowsView::DownloadQueueUpdatedL(TInt /*aDownloadingShows*/, TInt /*aQueuedShows*/)
       
   865 	{
       
   866 	//((CPodcastAppUi*)AppUi())->UpdateQueueTab(aDownloadingShows+aQueuedShows);
       
   867 	}
       
   868 
       
   869 void CPodcastShowsView::FeedUpdateAllCompleteL(TFeedState /*aState*/)
       
   870 	{
       
   871 	UpdateListboxItemsL();
       
   872 	UpdateToolbar();
       
   873 	}
       
   874 
       
   875 void CPodcastShowsView::UpdateViewTitleL()
       
   876 	{
       
   877 	DP("CPodcastShowsView::UpdateViewTitleL BEGIN");
       
   878 	 CAknTitlePane* titlePane = static_cast<CAknTitlePane*>
       
   879 		      ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   880 		 
       
   881 		TBool updatingState = iPodcastModel.FeedEngine().ClientState() != EIdle && 
       
   882 				iPodcastModel.FeedEngine().ActiveClientUid() == iPodcastModel.ActiveFeedInfo()->Uid();
       
   883 
       
   884 		if (updatingState) {
       
   885 			SetEmptyTextL(R_PODCAST_EMPTY_LIST_UPDATING);		
       
   886 		} else {
       
   887 			SetEmptyTextL(R_PODCAST_EMPTY_LIST);
       
   888 		}
       
   889 		
       
   890 		if(iPodcastModel.ActiveFeedInfo())
       
   891 			{
       
   892 			if (iPodcastModel.ActiveFeedInfo()->Title() != KNullDesC)
       
   893 				{
       
   894 				titlePane->SetTextL( iPodcastModel.ActiveFeedInfo()->Title(), ETrue );
       
   895 				}
       
   896 			}
       
   897 		else
       
   898 			{
       
   899 			titlePane->SetPicture(NULL, NULL);
       
   900 			titlePane->SetTextToDefaultL();
       
   901 			}
       
   902 		
       
   903 	DP("CPodcastShowsView::UpdateViewTitleL END");
       
   904 	}