application/src/PodcastFeedView.cpp
branchtwolistboxes
changeset 313 0f30a75610de
parent 312 2faae209e72b
child 314 e7776f6a2198
equal deleted inserted replaced
312:2faae209e72b 313:0f30a75610de
    38 const TInt KMaxUnplayedFeedsLength =64;
    38 const TInt KMaxUnplayedFeedsLength =64;
    39 const TInt KADayInHours = 24;
    39 const TInt KADayInHours = 24;
    40 #define KMaxMessageLength 200
    40 #define KMaxMessageLength 200
    41 #define KMaxTitleLength 100
    41 #define KMaxTitleLength 100
    42 
    42 
    43 _LIT(KFeedFormat, "%d\t%S\t%S%S");
    43 _LIT(KFeedFormatPortrait, "%d\t%S\t%S%S");
       
    44 //_LIT(KFeedFormatPortrait, "%d\t%S");
       
    45 _LIT(KFeedFormatLandscape, "%d\t%S");
    44 enum 
    46 enum 
    45 {
    47 {
    46  EFeedIcon
    48  EFeedIcon
    47 };
    49 };
    48 
    50 
    59     CleanupStack::PushL( self );
    61     CleanupStack::PushL( self );
    60     self->ConstructL();
    62     self->ConstructL();
    61     return self;
    63     return self;
    62     }
    64     }
    63 
    65 
    64 CPodcastFeedView::CPodcastFeedView(CPodcastModel& aPodcastModel):iPodcastModel(aPodcastModel)
    66 void CPodcastFeedView::SizeChanged()
    65 	{
    67 	{
    66 	iFirstActivateAfterLaunch = ETrue;
    68 	DP("CPodcastFeedView::SizeChanged BEGIN");
    67 	}
    69 	iListContainer->Listbox()->SetListBoxObserver(this);
    68 #define KAsterisk iEikonEnv->EikAppUi()->Application()->BitmapStoreName()
    70 	iFeedIdForIconArray.Reset();
    69 void CPodcastFeedView::ConstructL()
    71 	iItemArray->Reset();
    70 	{
    72 	
    71 	DP("CPodcastFeedView::ConstructL BEGIN");
    73 	DP("before icons");
    72 	//_LIT(KAsterisk, "*");
       
    73 	BaseConstructL(R_PODCAST_FEEDVIEW);
       
    74 	iNeverUpdated = iEikonEnv->AllocReadResourceL(R_PODCAST_FEEDS_NEVER_UPDATED);
       
    75 	iFeedsFormat = iEikonEnv->AllocReadResourceL(R_PODCAST_FEEDS_STATUS_FORMAT);
       
    76 	CPodcastListView::ConstructL();
       
    77 	iPodcastModel.FeedEngine().AddObserver(this);
       
    78 	CArrayPtr< CGulIcon >* icons = new(ELeave) CArrayPtrFlat< CGulIcon >(1);
       
    79 	CleanupStack::PushL( icons );
       
    80 	
       
    81 	CFbsBitmap* bitmap = NULL;
    74 	CFbsBitmap* bitmap = NULL;
    82 	CFbsBitmap* mask = NULL;
    75 	CFbsBitmap* mask = NULL;
       
    76 	_LIT(KAsterisk, "*");
    83 	// Load the bitmap for empty icon	
    77 	// Load the bitmap for empty icon	
    84 	TFileName fname = KAsterisk;
    78 	TFileName fname;
       
    79 	fname.Copy(KAsterisk);
    85 	TParsePtr parser(fname);
    80 	TParsePtr parser(fname);
    86 
    81 	iIconArray= new(ELeave) CArrayPtrFlat< CGulIcon >(1);
    87 	SetEmptyTextL(R_PODCAST_NO_FEEDS);
    82 	CleanupStack::PushL( iIconArray );
    88 	
    83 
    89 	// Load svg.-image and mask with a single call
    84 	// Load svg.-image and mask with a single call
    90 		AknIconUtils::CreateIconL(bitmap,
    85 		AknIconUtils::CreateIconL(bitmap,
    91 		                          mask,
    86 		                          mask,
    92 		                          iEikonEnv->EikAppUi()->Application()->BitmapStoreName(),
    87 		                          iEikonEnv->EikAppUi()->Application()->BitmapStoreName(),
    93 		                          EMbmPodcastFeed,
    88 		                          EMbmPodcastFeed,
    98 	CleanupStack::PushL( bitmap );		
    93 	CleanupStack::PushL( bitmap );		
    99 	// Load the mask for feed icon	
    94 	// Load the mask for feed icon	
   100 	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
    95 	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
   101 	CleanupStack::PushL( mask );
    96 	CleanupStack::PushL( mask );
   102 	// Append the feed icon to icon array
    97 	// Append the feed icon to icon array
   103 	icons->AppendL( CGulIcon::NewL( bitmap, mask ) );
    98 	iIconArray->AppendL( CGulIcon::NewL( bitmap, mask ) );
   104 	CleanupStack::Pop(2); // bitmap, mask
    99 	CleanupStack::Pop(2); // bitmap, mask
   105 	iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
   100 	iListContainer->SetListboxIcons(iIconArray);
   106 	CleanupStack::Pop(icons); // icons
   101 	CleanupStack::Pop(iIconArray); // icons
   107 
   102 	
   108 	iListContainer->Listbox()->SetListBoxObserver(this);
   103 	UpdateListboxItemsL();
       
   104 	iListContainer->SetTextArray(iItemArray);
       
   105 	iListContainer->SetListboxIcons(iIconArray);
       
   106 	iListContainer->Listbox()->DrawNow();
       
   107 	DP("CPodcastFeedView::SizeChanged END");
       
   108 	}
       
   109 
       
   110 CPodcastFeedView::CPodcastFeedView(CPodcastModel& aPodcastModel):iPodcastModel(aPodcastModel)
       
   111 	{
       
   112 	iFirstActivateAfterLaunch = ETrue;
       
   113 	}
       
   114 #define KAsterisk iEikonEnv->EikAppUi()->Application()->BitmapStoreName()
       
   115 void CPodcastFeedView::ConstructL()
       
   116 	{
       
   117 	DP("CPodcastFeedView::ConstructL BEGIN");
       
   118 	//_LIT(KAsterisk, "*");
       
   119 	BaseConstructL(R_PODCAST_FEEDVIEW);
       
   120 	iNeverUpdated = iEikonEnv->AllocReadResourceL(R_PODCAST_FEEDS_NEVER_UPDATED);
       
   121 	iFeedsFormat = iEikonEnv->AllocReadResourceL(R_PODCAST_FEEDS_STATUS_FORMAT);
       
   122 	CPodcastListView::ConstructL();
       
   123 	iPodcastModel.FeedEngine().AddObserver(this);
       
   124 	SetEmptyTextL(R_PODCAST_NO_FEEDS);
       
   125 	SizeChanged();
       
   126 //	CFbsBitmap* bitmap = NULL;
       
   127 //	CFbsBitmap* mask = NULL;
       
   128 //	// Load the bitmap for empty icon	
       
   129 //	TFileName fname = KAsterisk;
       
   130 //	TParsePtr parser(fname);
       
   131 
       
   132 //	
       
   133 //	// Load svg.-image and mask with a single call
       
   134 //		AknIconUtils::CreateIconL(bitmap,
       
   135 //		                          mask,
       
   136 //		                          iEikonEnv->EikAppUi()->Application()->BitmapStoreName(),
       
   137 //		                          EMbmPodcastFeed,
       
   138 //		                          EMbmPodcastFeed_mask);
       
   139 //	    
       
   140 //	/*bitmap = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40);
       
   141 //	 * */
       
   142 //	CleanupStack::PushL( bitmap );		
       
   143 //	// Load the mask for feed icon	
       
   144 //	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
       
   145 //	CleanupStack::PushL( mask );
       
   146 //	// Append the feed icon to icon array
       
   147 //	iIconArray->AppendL( CGulIcon::NewL( bitmap, mask ) );
       
   148 //	CleanupStack::Pop(2); // bitmap, mask
       
   149 //	iListContainer->SetListboxIcons(iIconArray);
       
   150 //	CleanupStack::Pop(iIconArray); // icons
       
   151 //
       
   152 //	iListContainer->Listbox()->SetListBoxObserver(this);
   109 	
   153 	
   110     iUpdater = CPodcastFeedViewUpdater::NewL(*this);
   154     iUpdater = CPodcastFeedViewUpdater::NewL(*this);
   111 	DP("CPodcastFeedView::ConstructL END");
   155 	DP("CPodcastFeedView::ConstructL END");
   112 	}
   156 	}
   113     
   157     
   320 			}
   364 			}
   321 	}
   365 	}
   322 
   366 
   323 void CPodcastFeedView::FormatFeedInfoListBoxItemL(CFeedInfo& aFeedInfo, TBool aIsUpdating)
   367 void CPodcastFeedView::FormatFeedInfoListBoxItemL(CFeedInfo& aFeedInfo, TBool aIsUpdating)
   324 	{
   368 	{
       
   369 	DP("CPodcastFeedView::FormatFeedInfoListBoxItemL");
   325 	TBuf<KMaxShortDateFormatSpec*2> updatedDate;
   370 	TBuf<KMaxShortDateFormatSpec*2> updatedDate;
   326 	TBuf<KMaxUnplayedFeedsLength> unplayedShows;
   371 	TBuf<KMaxUnplayedFeedsLength> unplayedShows;
   327 	TUint unplayedCount = 0;
   372 	TUint unplayedCount = 0;
   328 	TUint showCount = 0;
   373 	TUint showCount = 0;
   329 	TInt iconIndex = EFeedIcon;
   374 	TInt iconIndex = EFeedIcon;
   369 			{
   414 			{
   370 			GetFeedErrorText(unplayedShows, aFeedInfo.LastError());
   415 			GetFeedErrorText(unplayedShows, aFeedInfo.LastError());
   371 			updatedDate.Zero();
   416 			updatedDate.Zero();
   372 			}
   417 			}
   373 		}
   418 		}
   374 	CArrayPtr<CGulIcon>* icons = iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->IconArray();
   419 	
   375 	iconIndex = iFeedIdForIconArray.Find(aFeedInfo.Uid());
   420 	iconIndex = iFeedIdForIconArray.Find(aFeedInfo.Uid());
   376 	if(iconIndex == KErrNotFound && aFeedInfo.FeedIcon() != NULL && aFeedInfo.ImageFileName().Length() > 0 && 
   421 	if(iconIndex == KErrNotFound && aFeedInfo.FeedIcon() != NULL && aFeedInfo.ImageFileName().Length() > 0 && 
   377 			aFeedInfo.FeedIcon()->SizeInPixels().iHeight > 0 &&
   422 			aFeedInfo.FeedIcon()->SizeInPixels().iHeight > 0 &&
   378 			aFeedInfo.FeedIcon()->SizeInPixels().iWidth > 0)
   423 			aFeedInfo.FeedIcon()->SizeInPixels().iWidth > 0)
   379 		{
   424 		{
   380 		// Hopefully temporary haxx to prevent double delete. I would prefer if
   425 		// Hopefully temporary haxx to prevent double delete. I would prefer if
   381 		// this could be solved with a little better design.
   426 		// this could be solved with a little better design.
   382 		CFbsBitmap* bmpCopy = new (ELeave) CFbsBitmap;
   427 		CFbsBitmap* bmpCopy = new (ELeave) CFbsBitmap;
   383 		CleanupStack::PushL(bmpCopy);
   428 		CleanupStack::PushL(bmpCopy);
   384 		bmpCopy->Duplicate(aFeedInfo.FeedIcon()->Handle());
   429 		bmpCopy->Duplicate(aFeedInfo.FeedIcon()->Handle());
   385 		icons->AppendL( CGulIcon::NewL(AknIconUtils::CreateIconL(bmpCopy), NULL));
   430 		iIconArray->AppendL( CGulIcon::NewL(AknIconUtils::CreateIconL(bmpCopy), NULL));
   386 		
   431 		
   387 		iFeedIdForIconArray.Append(aFeedInfo.Uid());
   432 		iFeedIdForIconArray.Append(aFeedInfo.Uid());
   388 		CleanupStack::Pop(bmpCopy);			
   433 		CleanupStack::Pop(bmpCopy);			
   389 		iconIndex = icons->Count()-1;
   434 		iconIndex = iIconArray->Count()-1;
   390 		}	
   435 		}	
   391 	else 
   436 	else 
   392 		{
   437 		{
   393 		iconIndex++;
   438 		iconIndex++;
   394 		}	
   439 		}	
   395 
   440 
   396 	if (unplayedShows.Length() > 0 && updatedDate.Length() > 0) {
   441 	if (unplayedShows.Length() > 0 && updatedDate.Length() > 0) {
   397 		unplayedShows.Insert(0,_L(", "));
   442 		unplayedShows.Insert(0,_L(", "));
   398 	}
   443 	}
   399 	
   444 		
   400 	iListboxFormatbuffer.Format(KFeedFormat(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
   445 	if (iListContainer->IsLandscape())
       
   446 		{
       
   447 		iListboxFormatbuffer.Format(KFeedFormatLandscape(), iconIndex, &(aFeedInfo.Title()));
       
   448 		}
       
   449 	else 
       
   450 		{
       
   451 		iListboxFormatbuffer.Format(KFeedFormatPortrait(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
       
   452 		}
   401 	}
   453 	}
   402 
   454 
   403 void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle, CPodcastModel& /*aPodcastModel*/)
   455 void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle, CPodcastModel& /*aPodcastModel*/)
   404 	{
   456 	{
   405 	if (aError == KErrNone) {
   457 	if (aError == KErrNone) {
   434 	{
   486 	{
   435 	DP("CPodcastFeedView::UpdateListboxItemsL BEGIN");
   487 	DP("CPodcastFeedView::UpdateListboxItemsL BEGIN");
   436 	// No reason to do any work if it isn't going to show..
   488 	// No reason to do any work if it isn't going to show..
   437 	if(!iListContainer->IsVisible())
   489 	if(!iListContainer->IsVisible())
   438 		{
   490 		{
       
   491 		DP("not visible");
   439 		return;
   492 		return;
   440 		}
   493 		}
   441 	
   494 	
   442 	TInt nbrItems = iPodcastModel.FeedEngine().GetSortedFeeds().Count();
   495 	TInt nbrItems = iPodcastModel.FeedEngine().GetSortedFeeds().Count();
   443 	if (nbrItems > 0)
   496 	if (nbrItems > 0)
   461 			}
   514 			}
   462 		while (iItemArray->Count() > nbrItems)
   515 		while (iItemArray->Count() > nbrItems)
   463 			{
   516 			{
   464 			iItemArray->Delete(iItemArray->Count() - 1);
   517 			iItemArray->Delete(iItemArray->Count() - 1);
   465 			}
   518 			}
       
   519 		//iListContainer->Listbox()->
   466 		iUpdater->StartUpdate(nbrItems);
   520 		iUpdater->StartUpdate(nbrItems);
   467 		}
   521 		}
   468 	else
   522 	else
   469 		{
   523 		{
   470 		// No feeds at all in the list , add dummy list item
   524 		// No feeds at all in the list , add dummy list item
   512 		case EPodcastDeleteFeed:
   566 		case EPodcastDeleteFeed:
   513 			HandleRemoveFeedL();
   567 			HandleRemoveFeedL();
   514 			break;
   568 			break;
   515 		case EPodcastUpdateAllFeeds:
   569 		case EPodcastUpdateAllFeeds:
   516 			{
   570 			{
   517 			iPodcastModel.FeedEngine().UpdateAllFeedsL();
   571 			SwitchListbox();
   518 			UpdateToolbar();
   572 			//iPodcastModel.FeedEngine().UpdateAllFeedsL();
       
   573 			//UpdateToolbar();
   519 			}break;
   574 			}break;
   520 		case EPodcastUpdateFeed:
   575 		case EPodcastUpdateFeed:
   521 			{
   576 			{
   522 			HandleUpdateFeedL();
   577 			HandleUpdateFeedL();
   523 			}break;
   578 			}break;