application/src/PodcastFeedView.cpp
branchtwolistboxes
changeset 316 841ccfa933ac
parent 315 091fa3bf3295
child 317 5afc95a6ad83
equal deleted inserted replaced
315:091fa3bf3295 316:841ccfa933ac
    72 	}
    72 	}
    73 
    73 
    74 void CPodcastFeedView::LoadIcons()
    74 void CPodcastFeedView::LoadIcons()
    75 	{
    75 	{
    76 	iFeedIdForIconArray.Reset();
    76 	iFeedIdForIconArray.Reset();
    77 	iItemArray->Reset();
    77 
    78 	
       
    79 	DP("before icons");
       
    80 	CFbsBitmap* bitmap = NULL;
    78 	CFbsBitmap* bitmap = NULL;
    81 	CFbsBitmap* mask = NULL;
    79 	CFbsBitmap* mask = NULL;
    82 	_LIT(KAsterisk, "*");
    80 	_LIT(KAsterisk, "*");
    83 	// Load the bitmap for empty icon	
    81 	// Load the bitmap for empty icon	
    84 	TFileName fname;
    82 	TFileName fname;
    85 	fname.Copy(KAsterisk);
    83 	fname.Copy(KAsterisk);
    86 	TParsePtr parser(fname);
    84 	TParsePtr parser(fname);
    87 	iIconArray= new(ELeave) CArrayPtrFlat< CGulIcon >(1);
    85 	CArrayPtrFlat< CGulIcon > *iconArray= new(ELeave) CArrayPtrFlat< CGulIcon >(1);
    88 	CleanupStack::PushL( iIconArray );
    86 	CleanupStack::PushL( iconArray );
    89 
    87 
    90 	// Load svg.-image and mask with a single call
    88 	// Load svg.-image and mask with a single call
    91 		AknIconUtils::CreateIconL(bitmap,
    89 		AknIconUtils::CreateIconL(bitmap,
    92 		                          mask,
    90 		                          mask,
    93 		                          iEikonEnv->EikAppUi()->Application()->BitmapStoreName(),
    91 		                          iEikonEnv->EikAppUi()->Application()->BitmapStoreName(),
    99 	CleanupStack::PushL( bitmap );		
    97 	CleanupStack::PushL( bitmap );		
   100 	// Load the mask for feed icon	
    98 	// Load the mask for feed icon	
   101 	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
    99 	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
   102 	CleanupStack::PushL( mask );
   100 	CleanupStack::PushL( mask );
   103 	// Append the feed icon to icon array
   101 	// Append the feed icon to icon array
   104 	iIconArray->AppendL( CGulIcon::NewL( bitmap, mask ) );
   102 	iconArray->AppendL( CGulIcon::NewL( bitmap, mask ) );
   105 	CleanupStack::Pop(2); // bitmap, mask
   103 	CleanupStack::Pop(2); // bitmap, mask
   106 	iListContainer->SetListboxIcons(iIconArray);
   104 	iListContainer->SetListboxIcons(iconArray);
   107 	CleanupStack::Pop(iIconArray); // icons
   105 	CleanupStack::Pop(iconArray); // icons
   108 	}
   106 	}
   109 
   107 
   110 CPodcastFeedView::CPodcastFeedView(CPodcastModel& aPodcastModel):iPodcastModel(aPodcastModel)
   108 CPodcastFeedView::CPodcastFeedView(CPodcastModel& aPodcastModel):iPodcastModel(aPodcastModel)
   111 	{
   109 	{
   112 	iFirstActivateAfterLaunch = ETrue;
   110 	iFirstActivateAfterLaunch = ETrue;
   161 	// Something has changed, update the listbox item
   159 	// Something has changed, update the listbox item
   162 	TListItemProperties itemProps;			
   160 	TListItemProperties itemProps;			
   163 	itemProps.SetDimmed(EFalse);	
   161 	itemProps.SetDimmed(EFalse);	
   164 	iItemArray->Delete(aIndex);	
   162 	iItemArray->Delete(aIndex);	
   165 	iItemArray->InsertL(aIndex, iListboxFormatbuffer);
   163 	iItemArray->InsertL(aIndex, iListboxFormatbuffer);
   166 	iListContainer->SetTextArray(iItemArray);
   164 	iItemArrayShort->Delete(aIndex);	
       
   165 	iItemArrayShort->InsertL(aIndex, iListboxFormatbufferShort);
       
   166 
   167 	iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(aIndex, itemProps);
   167 	iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(aIndex, itemProps);
   168 	// If item is visible, redraw it
   168 	// If item is visible, redraw it
   169 	if (iListContainer->Listbox()->TopItemIndex() <= aIndex
   169 	if (iListContainer->Listbox()->TopItemIndex() <= aIndex
   170 			&& iListContainer->Listbox()->BottomItemIndex() >= aIndex)
   170 			&& iListContainer->Listbox()->BottomItemIndex() >= aIndex)
   171 		{
   171 		{
   289 	UpdateFeedInfoStatusL(aFeedUid, EFalse);
   289 	UpdateFeedInfoStatusL(aFeedUid, EFalse);
   290 	}
   290 	}
   291 
   291 
   292 void CPodcastFeedView::UpdateFeedInfoStatusL(TUint aFeedUid, TBool aIsUpdating)
   292 void CPodcastFeedView::UpdateFeedInfoStatusL(TUint aFeedUid, TBool aIsUpdating)
   293 	{
   293 	{
       
   294 	DP("CPodcastFeedView::UpdateFeedInfoStatusL BEGIN");
   294 	const RFeedInfoArray& feeds = iPodcastModel.FeedEngine().GetSortedFeeds();
   295 	const RFeedInfoArray& feeds = iPodcastModel.FeedEngine().GetSortedFeeds();
   295 
   296 
   296 	// Find the index for the feed i both the feed-array and the listbox 
   297 	// Find the index for the feed i both the feed-array and the listbox 
   297 	TInt feedsIdx = KErrNotFound;
   298 	TInt feedsIdx = KErrNotFound;
   298 	TInt listboxIdx = KErrNotFound;
   299 	TInt listboxIdx = KErrNotFound;
   322 			{
   323 			{
   323 			iItemIdArray.Remove(listboxIdx);
   324 			iItemIdArray.Remove(listboxIdx);
   324 			iItemIdArray.InsertL(aFeedUid, feedsIdx);
   325 			iItemIdArray.InsertL(aFeedUid, feedsIdx);
   325 			iItemArray->Delete(listboxIdx);
   326 			iItemArray->Delete(listboxIdx);
   326 			iItemArray->InsertL(feedsIdx, KNullDesC);
   327 			iItemArray->InsertL(feedsIdx, KNullDesC);
   327 			iListContainer->SetTextArray(iItemArray);
   328 			iItemArrayShort->Delete(listboxIdx);
       
   329 			iItemArrayShort->InsertL(feedsIdx, KNullDesC);
   328 			iListContainer->Listbox()->HandleItemAdditionL();
   330 			iListContainer->Listbox()->HandleItemAdditionL();
   329 			}
   331 			}
   330 		// Update the listbox info
   332 		// Update the listbox info
   331 		UpdateFeedInfoDataL(feeds[feedsIdx], feedsIdx, aIsUpdating);
   333 		UpdateFeedInfoDataL(feeds[feedsIdx], feedsIdx, aIsUpdating);
   332 		//TODO sort the listbox after update
   334 		//TODO sort the listbox after update
   336 		TInt maxIdx = Min(Max(feedsIdx, listboxIdx), iListContainer->Listbox()->BottomItemIndex());
   338 		TInt maxIdx = Min(Max(feedsIdx, listboxIdx), iListContainer->Listbox()->BottomItemIndex());
   337 		for (TInt k = minIdx; k <= maxIdx; k++)
   339 		for (TInt k = minIdx; k <= maxIdx; k++)
   338 			{
   340 			{
   339 			iListContainer->Listbox()->DrawItem(k);
   341 			iListContainer->Listbox()->DrawItem(k);
   340 			}
   342 			}
       
   343 		DP("CPodcastFeedView::UpdateFeedInfoStatusL END");
   341 	}
   344 	}
   342 
   345 
   343 void CPodcastFeedView::FormatFeedInfoListBoxItemL(CFeedInfo& aFeedInfo, TBool aIsUpdating)
   346 void CPodcastFeedView::FormatFeedInfoListBoxItemL(CFeedInfo& aFeedInfo, TBool aIsUpdating)
   344 	{
   347 	{
   345 	DP("CPodcastFeedView::FormatFeedInfoListBoxItemL");
   348 	DP("CPodcastFeedView::FormatFeedInfoListBoxItemL BEGIN");
   346 	TBuf<KMaxShortDateFormatSpec*2> updatedDate;
   349 	TBuf<KMaxShortDateFormatSpec*2> updatedDate;
   347 	TBuf<KMaxUnplayedFeedsLength> unplayedShows;
   350 	TBuf<KMaxUnplayedFeedsLength> unplayedShows;
   348 	TUint unplayedCount = 0;
   351 	TUint unplayedCount = 0;
   349 	TUint showCount = 0;
   352 	TUint showCount = 0;
   350 	TInt iconIndex = EFeedIcon;
   353 	TInt iconIndex = EFeedIcon;
   401 		// Hopefully temporary haxx to prevent double delete. I would prefer if
   404 		// Hopefully temporary haxx to prevent double delete. I would prefer if
   402 		// this could be solved with a little better design.
   405 		// this could be solved with a little better design.
   403 		CFbsBitmap* bmpCopy = new (ELeave) CFbsBitmap;
   406 		CFbsBitmap* bmpCopy = new (ELeave) CFbsBitmap;
   404 		CleanupStack::PushL(bmpCopy);
   407 		CleanupStack::PushL(bmpCopy);
   405 		bmpCopy->Duplicate(aFeedInfo.FeedIcon()->Handle());
   408 		bmpCopy->Duplicate(aFeedInfo.FeedIcon()->Handle());
   406 		iIconArray->AppendL( CGulIcon::NewL(AknIconUtils::CreateIconL(bmpCopy), NULL));
   409 		CArrayPtr<CGulIcon>* icons = iListContainer->ListboxIcons();
       
   410 
       
   411 		icons->AppendL( CGulIcon::NewL(AknIconUtils::CreateIconL(bmpCopy), NULL));
   407 		
   412 		
   408 		iFeedIdForIconArray.Append(aFeedInfo.Uid());
   413 		iFeedIdForIconArray.Append(aFeedInfo.Uid());
   409 		CleanupStack::Pop(bmpCopy);			
   414 		CleanupStack::Pop(bmpCopy);			
   410 		iconIndex = iIconArray->Count()-1;
   415 		iconIndex = icons->Count()-1;
   411 		}	
   416 		}	
   412 	else 
   417 	else 
   413 		{
   418 		{
   414 		iconIndex++;
   419 		iconIndex++;
   415 		}	
   420 		}	
   417 	if (unplayedShows.Length() > 0 && updatedDate.Length() > 0) {
   422 	if (unplayedShows.Length() > 0 && updatedDate.Length() > 0) {
   418 		unplayedShows.Insert(0,_L(", "));
   423 		unplayedShows.Insert(0,_L(", "));
   419 	}
   424 	}
   420 		
   425 		
   421 	iListboxFormatbuffer.Format(KFeedFormatPortrait(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
   426 	iListboxFormatbuffer.Format(KFeedFormatPortrait(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
       
   427 	iListboxFormatbufferShort.Format(KFeedFormatLandscape(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
       
   428 	DP("CPodcastFeedView::FormatFeedInfoListBoxItemL END");
   422 	}
   429 	}
   423 
   430 
   424 void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle, CPodcastModel& /*aPodcastModel*/)
   431 void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle, CPodcastModel& /*aPodcastModel*/)
   425 	{
   432 	{
   426 	if (aError == KErrNone) {
   433 	if (aError == KErrNone) {
   436 	
   443 	
   437 	TPtrC compareTo((*iItemArray)[aIndex]);
   444 	TPtrC compareTo((*iItemArray)[aIndex]);
   438 	
   445 	
   439 	if (iListboxFormatbuffer.Compare(compareTo) != 0) {
   446 	if (iListboxFormatbuffer.Compare(compareTo) != 0) {
   440 		iItemArray->Delete(aIndex);
   447 		iItemArray->Delete(aIndex);
       
   448 		iItemArrayShort->Delete(aIndex);
   441 		if(aIndex>= iItemArray->MdcaCount())
   449 		if(aIndex>= iItemArray->MdcaCount())
   442 				{
   450 				{
   443 				iItemArray->AppendL(iListboxFormatbuffer);
   451 				iItemArray->AppendL(iListboxFormatbuffer);
       
   452 				iItemArrayShort->AppendL(iListboxFormatbufferShort);
   444 				}
   453 				}
   445 			else
   454 			else
   446 				{
   455 				{
   447 				iItemArray->InsertL(aIndex, iListboxFormatbuffer);
   456 				iItemArray->InsertL(aIndex, iListboxFormatbuffer);
       
   457 				iItemArrayShort->InsertL(aIndex, iListboxFormatbufferShort);
   448 				}
   458 				}
   449 	}
   459 	}
   450 	iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(aIndex, itemProps);
   460 	iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(aIndex, itemProps);
   451 	}
   461 	}
   452 
   462 
   475 		
   485 		
   476 		// Ensure that there are as many elements in iItemArray as in FeedEngine
   486 		// Ensure that there are as many elements in iItemArray as in FeedEngine
   477 		while (iItemArray->Count() < nbrItems)
   487 		while (iItemArray->Count() < nbrItems)
   478 			{
   488 			{
   479 			iItemArray->AppendL(KNullDesC);
   489 			iItemArray->AppendL(KNullDesC);
       
   490 			iItemArrayShort->AppendL(KNullDesC);
   480 			TListItemProperties itemProps;
   491 			TListItemProperties itemProps;
   481 			iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(iItemArray->Count() - 1, itemProps);
   492 			iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(iItemArray->Count() - 1, itemProps);
   482 			}
   493 			}
   483 		while (iItemArray->Count() > nbrItems)
   494 		while (iItemArray->Count() > nbrItems)
   484 			{
   495 			{
   485 			iItemArray->Delete(iItemArray->Count() - 1);
   496 			iItemArray->Delete(iItemArray->Count() - 1);
       
   497 			iItemArrayShort->Delete(iItemArray->Count() - 1);		
   486 			}
   498 			}
   487 		//iListContainer->Listbox()->
   499 		//iListContainer->Listbox()->
   488 		iUpdater->StartUpdate(nbrItems);
   500 		iUpdater->StartUpdate(nbrItems);
   489 		}
   501 		}
   490 	else
   502 	else
   491 		{
   503 		{
   492 		// No feeds at all in the list , add dummy list item
   504 		// No feeds at all in the list , add dummy list item
   493 		TBuf<KMaxFeedNameLength> itemName;
   505 		TBuf<KMaxFeedNameLength> itemName;
   494 		iEikonEnv->ReadResourceL(itemName, R_PODCAST_FEEDS_NO_FEEDS);
   506 		iEikonEnv->ReadResourceL(itemName, R_PODCAST_FEEDS_NO_FEEDS);
   495 		iItemArray->Reset();
   507 		iItemArray->Reset();
       
   508 		iItemArrayShort->Reset();
   496 		iItemIdArray.Reset();
   509 		iItemIdArray.Reset();
   497 	
   510 	
   498 		TListItemProperties itemProps;
   511 		TListItemProperties itemProps;
   499 		itemProps.SetDimmed(ETrue);
   512 		itemProps.SetDimmed(ETrue);
   500 		itemProps.SetHiddenSelection(ETrue);								
   513 		itemProps.SetHiddenSelection(ETrue);								
   501 		iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(0, itemProps);
   514 		iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(0, itemProps);
   502 		}
   515 		}
   503 	iListContainer->SetTextArray(iItemArray);
       
   504 	iListContainer->Listbox()->HandleItemAdditionL();
   516 	iListContainer->Listbox()->HandleItemAdditionL();
   505 	DP("CPodcastFeedView::UpdateListboxItemsL END");
   517 	DP("CPodcastFeedView::UpdateListboxItemsL END");
   506 	}
   518 	}
   507 
   519 
   508 /** 
   520 /** 
   783 			message.Format(templ, &info->Title());					
   795 			message.Format(templ, &info->Title());					
   784 			if(ShowQueryMessageL(message))
   796 			if(ShowQueryMessageL(message))
   785 				{
   797 				{
   786 				iPodcastModel.FeedEngine().RemoveFeedL(iItemIdArray[index]);
   798 				iPodcastModel.FeedEngine().RemoveFeedL(iItemIdArray[index]);
   787 				iItemArray->Delete(index);
   799 				iItemArray->Delete(index);
       
   800 				iItemArrayShort->Delete(index);
   788 				iItemIdArray.Remove(index);
   801 				iItemIdArray.Remove(index);
   789 				iListContainer->Listbox()->HandleItemRemovalL();
   802 				iListContainer->Listbox()->HandleItemRemovalL();
   790 				iListContainer->Listbox()->DrawNow();
   803 				iListContainer->Listbox()->DrawNow();
   791 				}					
   804 				}					
   792 			}
   805 			}