application/src/PodcastFeedView.cpp
branchsymbian1
changeset 336 3d6c1417e8bd
parent 296 80f1da5ac28b
child 337 3b316e1eb723
equal deleted inserted replaced
296:80f1da5ac28b 336:3d6c1417e8bd
    31 #include <aknquerydialog.h>
    31 #include <aknquerydialog.h>
    32 #include <BAUTILS.H> 
    32 #include <BAUTILS.H> 
    33 #include <pathinfo.h> 
    33 #include <pathinfo.h> 
    34 #include <akncommondialogsdynmem.h> 
    34 #include <akncommondialogsdynmem.h> 
    35 #include "Podcatcher.pan"
    35 #include "Podcatcher.pan"
       
    36 #include <aknmessagequerydialog.h>
    36 
    37 
    37 const TInt KMaxFeedNameLength = 100;
    38 const TInt KMaxFeedNameLength = 100;
    38 const TInt KMaxUnplayedFeedsLength =64;
    39 const TInt KMaxUnplayedFeedsLength =64;
    39 const TInt KADayInHours = 24;
    40 const TInt KADayInHours = 24;
    40 #define KMaxMessageLength 200
    41 #define KMaxMessageLength 200
    41 #define KMaxTitleLength 100
    42 #define KMaxTitleLength 100
    42 
    43 
    43 _LIT(KFeedFormat, "%d\t%S\t%S%S");
    44 _LIT(KFeedFormatPortrait, "%d\t%S\t%S%S");
       
    45 _LIT(KFeedFormatLandscape, "%d\t%S");
    44 enum 
    46 enum 
    45 {
    47 {
    46  EFeedIcon
    48  EFeedIcon
    47 };
    49 };
    48 
    50 
   100 	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
   102 	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
   101 	CleanupStack::PushL( mask );
   103 	CleanupStack::PushL( mask );
   102 	// Append the feed icon to icon array
   104 	// Append the feed icon to icon array
   103 	icons->AppendL( CGulIcon::NewL( bitmap, mask ) );
   105 	icons->AppendL( CGulIcon::NewL( bitmap, mask ) );
   104 	CleanupStack::Pop(2); // bitmap, mask
   106 	CleanupStack::Pop(2); // bitmap, mask
   105 	iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
   107 	iListContainer->SetListboxIcons( icons );
   106 	CleanupStack::Pop(icons); // icons
   108 	CleanupStack::Pop(icons); // icons
   107 
       
   108 	iListContainer->Listbox()->SetListBoxObserver(this);
       
   109 	
   109 	
   110     iStylusPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint(0,0));
   110     iStylusPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint(0,0));
   111     TResourceReader reader;
   111     TResourceReader reader;
   112     iCoeEnv->CreateResourceReaderLC(reader,R_FEEDVIEW_POPUP_MENU);
   112     iCoeEnv->CreateResourceReaderLC(reader,R_FEEDVIEW_POPUP_MENU);
   113     iStylusPopupMenu->ConstructFromResourceL(reader);
   113     iStylusPopupMenu->ConstructFromResourceL(reader);
   137 
   137 
   138 	// Update UID of for the feed at aIndex
   138 	// Update UID of for the feed at aIndex
   139 	iItemIdArray[aIndex] = sortedItems[aIndex]->Uid();
   139 	iItemIdArray[aIndex] = sortedItems[aIndex]->Uid();
   140 	
   140 	
   141 	// Prepare data to update the listbox item with
   141 	// Prepare data to update the listbox item with
   142 	FormatFeedInfoListBoxItemL(*sortedItems[aIndex], EFalse);
   142 	FormatFeedInfoListBoxItemL(*sortedItems[aIndex], sortedItems[aIndex]->Uid() == iFeedUpdating);
   143 	
   143 	
   144 	// If nothing has changed, we are done here
   144 	// If nothing has changed, we are done here
   145 	if (iListboxFormatbuffer == iItemArray->MdcaPoint(aIndex))
   145 	if (iListboxFormatbuffer == iItemArray->MdcaPoint(aIndex))
   146 		{
   146 		{
   147 		return;
   147 		return;
   150 	// Something has changed, update the listbox item
   150 	// Something has changed, update the listbox item
   151 	TListItemProperties itemProps;			
   151 	TListItemProperties itemProps;			
   152 	itemProps.SetDimmed(EFalse);	
   152 	itemProps.SetDimmed(EFalse);	
   153 	iItemArray->Delete(aIndex);	
   153 	iItemArray->Delete(aIndex);	
   154 	iItemArray->InsertL(aIndex, iListboxFormatbuffer);
   154 	iItemArray->InsertL(aIndex, iListboxFormatbuffer);
   155 	iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(aIndex, itemProps);
   155 	iItemArrayShort->Delete(aIndex);	
       
   156 	iItemArrayShort->InsertL(aIndex, iListboxFormatbufferShort);
       
   157 
       
   158 	//iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(aIndex, itemProps);
   156 	// If item is visible, redraw it
   159 	// If item is visible, redraw it
   157 	if (iListContainer->Listbox()->TopItemIndex() <= aIndex
   160 	if (iListContainer->Listbox()->TopItemIndex() <= aIndex
   158 			&& iListContainer->Listbox()->BottomItemIndex() >= aIndex)
   161 			&& iListContainer->Listbox()->BottomItemIndex() > aIndex)
   159 		{
   162 		{
   160 		iListContainer->Listbox()->DrawItem(aIndex);
   163 		iListContainer->Listbox()->DrawItem(aIndex);
   161 		}
   164 		}
       
   165 	}
       
   166 
       
   167 void CPodcastFeedView::UpdateItemsComplete()
       
   168 	{
   162 	}
   169 	}
   163 
   170 
   164 TUid CPodcastFeedView::Id() const
   171 TUid CPodcastFeedView::Id() const
   165 	{
   172 	{
   166 	return KUidPodcastFeedViewID;
   173 	return KUidPodcastFeedViewID;
   168 		
   175 		
   169 void CPodcastFeedView::DoActivateL(const TVwsViewId& aPrevViewId,
   176 void CPodcastFeedView::DoActivateL(const TVwsViewId& aPrevViewId,
   170 	                                  TUid aCustomMessageId,
   177 	                                  TUid aCustomMessageId,
   171 	                                  const TDesC8& aCustomMessage)
   178 	                                  const TDesC8& aCustomMessage)
   172 	{
   179 	{
       
   180 	DP("CPodcastFeedView::DoActivateL BEGIN");
   173 	CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage);
   181 	CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage);
   174 	
   182 	
   175 	if (aPrevViewId.iViewUid == KUidPodcastShowsViewID)
   183 	if (aPrevViewId.iViewUid == KUidPodcastShowsViewID)
   176 		{
   184 		{
   177 		// back key from shows view
   185 		// back key from shows view
   179 		}
   187 		}
   180 	
   188 	
   181 		UpdateListboxItemsL();		
   189 		UpdateListboxItemsL();		
   182 		UpdateToolbar();
   190 		UpdateToolbar();
   183 
   191 
       
   192 	// when we receive a UID argument, this comes from search view after
       
   193 	// a new feed has been added
       
   194 	if (aCustomMessageId.iUid != 0)
       
   195 		{
       
   196 		TUint feedUid = aCustomMessageId.iUid;
       
   197 		ShowItem(feedUid);
       
   198 		TBuf<KMaxMessageLength> message;
       
   199 		iEikonEnv->ReadResourceL(message, R_ADD_FEED_SUCCESS);
       
   200 		if(ShowQueryMessageL(message))
       
   201 			{
       
   202 			iPodcastModel.FeedEngine().UpdateFeedL(feedUid);
       
   203 			}
       
   204 		}
       
   205 		
   184 	if (iFirstActivateAfterLaunch)
   206 	if (iFirstActivateAfterLaunch)
   185 		{
   207 		{
   186 		iFirstActivateAfterLaunch = EFalse;
   208 		iFirstActivateAfterLaunch = EFalse;
   187 		iListContainer->Listbox()->ScrollToMakeItemVisible(0);
   209 		}
   188 		}
   210 
       
   211 	DP("CPodcastFeedView::DoActivateL END");
   189 	}
   212 	}
   190 
   213 
   191 void CPodcastFeedView::DoDeactivate()
   214 void CPodcastFeedView::DoDeactivate()
   192 	{
   215 	{
   193 	iUpdater->StopUpdate();
   216 	iUpdater->StopUpdate();
   195 	}
   218 	}
   196 
   219 
   197 
   220 
   198 void CPodcastFeedView::HandleListBoxEventL(CEikListBox* /* aListBox */, TListBoxEvent aEventType)
   221 void CPodcastFeedView::HandleListBoxEventL(CEikListBox* /* aListBox */, TListBoxEvent aEventType)
   199 	{
   222 	{
   200 	DP("CPodcastFeedView::HandleListBoxEventL BEGIN");
   223 //	DP("CPodcastFeedView::HandleListBoxEventL BEGIN");
   201 
   224 
   202 	switch(aEventType)
   225 	switch(aEventType)
   203 		{
   226 		{
   204 	case EEventEnterKeyPressed:
   227 	case EEventEnterKeyPressed:
   205 	case EEventItemDoubleClicked:
   228 	case EEventItemDoubleClicked:
   218 			}
   241 			}
   219 		break;
   242 		break;
   220 	default:
   243 	default:
   221 		break;
   244 		break;
   222 		}
   245 		}
   223 	DP("CPodcastFeedView::HandleListBoxEventL END");
   246 //	DP("CPodcastFeedView::HandleListBoxEventL END");
   224 	}
   247 	}
   225 
   248 
   226 void CPodcastFeedView::FeedUpdateAllCompleteL(TFeedState /*aState*/)
   249 void CPodcastFeedView::FeedUpdateAllCompleteL(TFeedState /*aState*/)
   227 	{
   250 	{
   228 	iUpdatingRunning = EFalse;
   251 	DP("FeedUpdateAllCompleteL");
       
   252 	iFeedUpdating = 0;
   229 	UpdateToolbar();
   253 	UpdateToolbar();
   230 	}
   254 	}
   231 
   255 
   232 void CPodcastFeedView::FeedDownloadStartedL(TFeedState /*aState*/, TUint aFeedUid)
   256 void CPodcastFeedView::FeedDownloadStartedL(TFeedState /*aState*/, TUint aFeedUid)
   233 	{
   257 	{
   234 	// Update status text
   258 	// Update status text
   235 	iUpdatingRunning = ETrue;
   259 	iFeedUpdating = aFeedUid;
   236 	UpdateFeedInfoStatusL(aFeedUid, ETrue);
   260 	UpdateFeedInfoStatusL(aFeedUid, ETrue);
   237 	
   261 	
   238 	UpdateToolbar();
   262 	UpdateToolbar();
   239 	}
   263 	}
   240 
   264 
   258 	UpdateFeedInfoStatusL(aFeedUid, EFalse);
   282 	UpdateFeedInfoStatusL(aFeedUid, EFalse);
   259 	}
   283 	}
   260 
   284 
   261 void CPodcastFeedView::UpdateFeedInfoStatusL(TUint aFeedUid, TBool aIsUpdating)
   285 void CPodcastFeedView::UpdateFeedInfoStatusL(TUint aFeedUid, TBool aIsUpdating)
   262 	{
   286 	{
       
   287 	DP("CPodcastFeedView::UpdateFeedInfoStatusL BEGIN");
   263 	const RFeedInfoArray& feeds = iPodcastModel.FeedEngine().GetSortedFeeds();
   288 	const RFeedInfoArray& feeds = iPodcastModel.FeedEngine().GetSortedFeeds();
   264 
   289 
   265 	// Find the index for the feed i both the feed-array and the listbox 
   290 	// Find the index for the feed i both the feed-array and the listbox 
   266 	TInt feedsIdx = KErrNotFound;
   291 	TInt feedsIdx = KErrNotFound;
   267 	TInt listboxIdx = KErrNotFound;
   292 	TInt listboxIdx = KErrNotFound;
   291 			{
   316 			{
   292 			iItemIdArray.Remove(listboxIdx);
   317 			iItemIdArray.Remove(listboxIdx);
   293 			iItemIdArray.InsertL(aFeedUid, feedsIdx);
   318 			iItemIdArray.InsertL(aFeedUid, feedsIdx);
   294 			iItemArray->Delete(listboxIdx);
   319 			iItemArray->Delete(listboxIdx);
   295 			iItemArray->InsertL(feedsIdx, KNullDesC);
   320 			iItemArray->InsertL(feedsIdx, KNullDesC);
       
   321 			iItemArrayShort->Delete(listboxIdx);
       
   322 			iItemArrayShort->InsertL(feedsIdx, KNullDesC);
   296 			iListContainer->Listbox()->HandleItemAdditionL();
   323 			iListContainer->Listbox()->HandleItemAdditionL();
   297 			}
   324 			}
   298 		// Update the listbox info
   325 		// Update the listbox info
   299 		UpdateFeedInfoDataL(feeds[feedsIdx], feedsIdx, aIsUpdating);
   326 		UpdateFeedInfoDataL(feeds[feedsIdx], feedsIdx, aIsUpdating);
   300 		//TODO sort the listbox after update
   327 		//TODO sort the listbox after update
   304 		TInt maxIdx = Min(Max(feedsIdx, listboxIdx), iListContainer->Listbox()->BottomItemIndex());
   331 		TInt maxIdx = Min(Max(feedsIdx, listboxIdx), iListContainer->Listbox()->BottomItemIndex());
   305 		for (TInt k = minIdx; k <= maxIdx; k++)
   332 		for (TInt k = minIdx; k <= maxIdx; k++)
   306 			{
   333 			{
   307 			iListContainer->Listbox()->DrawItem(k);
   334 			iListContainer->Listbox()->DrawItem(k);
   308 			}
   335 			}
       
   336 		DP("CPodcastFeedView::UpdateFeedInfoStatusL END");
   309 	}
   337 	}
   310 
   338 
   311 void CPodcastFeedView::FormatFeedInfoListBoxItemL(CFeedInfo& aFeedInfo, TBool aIsUpdating)
   339 void CPodcastFeedView::FormatFeedInfoListBoxItemL(CFeedInfo& aFeedInfo, TBool aIsUpdating)
   312 	{
   340 	{
       
   341 	DP("CPodcastFeedView::FormatFeedInfoListBoxItemL BEGIN");
   313 	TBuf<KMaxShortDateFormatSpec*2> updatedDate;
   342 	TBuf<KMaxShortDateFormatSpec*2> updatedDate;
   314 	TBuf<KMaxUnplayedFeedsLength> unplayedShows;
   343 	TBuf<KMaxUnplayedFeedsLength> unplayedShows;
   315 	TUint unplayedCount = 0;
   344 	TUint unplayedCount = 0;
   316 	TUint showCount = 0;
   345 	TUint showCount = 0;
   317 	TInt iconIndex = EFeedIcon;
   346 	TInt iconIndex = EFeedIcon;
   357 			{
   386 			{
   358 			GetFeedErrorText(unplayedShows, aFeedInfo.LastError());
   387 			GetFeedErrorText(unplayedShows, aFeedInfo.LastError());
   359 			updatedDate.Zero();
   388 			updatedDate.Zero();
   360 			}
   389 			}
   361 		}
   390 		}
   362 	CArrayPtr<CGulIcon>* icons = iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->IconArray();
   391 	
   363 	iconIndex = iFeedIdForIconArray.Find(aFeedInfo.Uid());
   392 	iconIndex = iFeedIdForIconArray.Find(aFeedInfo.Uid());
       
   393 	DP1("    iconIndex = %d", iconIndex);
   364 	if(iconIndex == KErrNotFound && aFeedInfo.FeedIcon() != NULL && aFeedInfo.ImageFileName().Length() > 0 && 
   394 	if(iconIndex == KErrNotFound && aFeedInfo.FeedIcon() != NULL && aFeedInfo.ImageFileName().Length() > 0 && 
   365 			aFeedInfo.FeedIcon()->SizeInPixels().iHeight > 0 &&
   395 			aFeedInfo.FeedIcon()->SizeInPixels().iHeight > 0 &&
   366 			aFeedInfo.FeedIcon()->SizeInPixels().iWidth > 0)
   396 			aFeedInfo.FeedIcon()->SizeInPixels().iWidth > 0)
   367 		{
   397 		{
   368 		// Hopefully temporary haxx to prevent double delete. I would prefer if
   398 		// Hopefully temporary haxx to prevent double delete. I would prefer if
   369 		// this could be solved with a little better design.
   399 		// this could be solved with a little better design.
   370 		CFbsBitmap* bmpCopy = new (ELeave) CFbsBitmap;
   400 		CFbsBitmap* bmpCopy = new (ELeave) CFbsBitmap;
   371 		CleanupStack::PushL(bmpCopy);
   401 		CleanupStack::PushL(bmpCopy);
   372 		bmpCopy->Duplicate(aFeedInfo.FeedIcon()->Handle());
   402 		bmpCopy->Duplicate(aFeedInfo.FeedIcon()->Handle());
   373 		icons->AppendL( CGulIcon::NewL(bmpCopy, NULL));
   403 		CArrayPtr<CGulIcon>* icons = iListContainer->ListboxIcons();
       
   404 
       
   405 		icons->AppendL( CGulIcon::NewL(AknIconUtils::CreateIconL(bmpCopy), NULL));
       
   406 		
   374 		iFeedIdForIconArray.Append(aFeedInfo.Uid());
   407 		iFeedIdForIconArray.Append(aFeedInfo.Uid());
   375 		CleanupStack::Pop(bmpCopy);			
   408 		CleanupStack::Pop(bmpCopy);			
   376 		iconIndex = icons->Count()-1;
   409 		iconIndex = icons->Count()-1;
   377 		}	
   410 		}	
   378 	else 
   411 	else 
   381 		}	
   414 		}	
   382 
   415 
   383 	if (unplayedShows.Length() > 0 && updatedDate.Length() > 0) {
   416 	if (unplayedShows.Length() > 0 && updatedDate.Length() > 0) {
   384 		unplayedShows.Insert(0,_L(", "));
   417 		unplayedShows.Insert(0,_L(", "));
   385 	}
   418 	}
   386 	
   419 		
   387 	iListboxFormatbuffer.Format(KFeedFormat(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
   420 	iListboxFormatbuffer.Format(KFeedFormatPortrait(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
       
   421 	iListboxFormatbufferShort.Format(KFeedFormatLandscape(), iconIndex, &(aFeedInfo.Title()));
       
   422 	DP("CPodcastFeedView::FormatFeedInfoListBoxItemL END");
   388 	}
   423 	}
   389 
   424 
   390 void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle, CPodcastModel& /*aPodcastModel*/)
   425 void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle, CPodcastModel& /*aPodcastModel*/)
   391 	{
   426 	{
   392 	if (aError == KErrNone) {
   427 	if (aError == KErrNone) {
   393 		UpdateFeedInfoStatusL(aHandle, EFalse);
   428 		UpdateFeedInfoStatusL(aHandle, EFalse);
   394 		}
   429 		}
   395 	}
   430 	}
   396 
   431 
   397 void CPodcastFeedView::UpdateFeedInfoDataL(CFeedInfo* aFeedInfo, TInt aIndex, TBool aIsUpdating )
   432 void CPodcastFeedView::UpdateFeedInfoDataL(CFeedInfo* aFeedInfo, TInt aIndex, TBool aIsUpdating )
   398 	{			
   433 	{
       
   434 	DP("CPodcastFeedView::UpdateFeedInfoDataL BEGIN");
   399 	TListItemProperties itemProps;			
   435 	TListItemProperties itemProps;			
   400 	itemProps.SetDimmed(aIsUpdating);	
   436 	itemProps.SetDimmed(aIsUpdating);	
   401 	FormatFeedInfoListBoxItemL(*aFeedInfo, aIsUpdating);
   437 	FormatFeedInfoListBoxItemL(*aFeedInfo, aIsUpdating);
   402 	
   438 	
   403 	TPtrC compareTo((*iItemArray)[aIndex]);
   439 	TPtrC compareTo((*iItemArray)[aIndex]);
   404 	
   440 	
   405 	if (iListboxFormatbuffer.Compare(compareTo) != 0) {
   441 	if (iListboxFormatbuffer.Compare(compareTo) != 0) {
   406 		iItemArray->Delete(aIndex);
   442 		iItemArray->Delete(aIndex);
       
   443 		iItemArrayShort->Delete(aIndex);
   407 		if(aIndex>= iItemArray->MdcaCount())
   444 		if(aIndex>= iItemArray->MdcaCount())
   408 				{
   445 				{
   409 				iItemArray->AppendL(iListboxFormatbuffer);
   446 				iItemArray->AppendL(iListboxFormatbuffer);
       
   447 				iItemArrayShort->AppendL(iListboxFormatbufferShort);
   410 				}
   448 				}
   411 			else
   449 			else
   412 				{
   450 				{
   413 				iItemArray->InsertL(aIndex, iListboxFormatbuffer);
   451 				iItemArray->InsertL(aIndex, iListboxFormatbuffer);
   414 				}
   452 				iItemArrayShort->InsertL(aIndex, iListboxFormatbufferShort);
   415 	}
   453 				}
   416 	iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(aIndex, itemProps);
   454 	}
       
   455 	//iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(aIndex, itemProps);
       
   456 	DP("CPodcastFeedView::UpdateFeedInfoDataL END");
   417 	}
   457 	}
   418 
   458 
   419 
   459 
   420 void CPodcastFeedView::UpdateListboxItemsL()
   460 void CPodcastFeedView::UpdateListboxItemsL()
   421 	{
   461 	{
   441 		
   481 		
   442 		// Ensure that there are as many elements in iItemArray as in FeedEngine
   482 		// Ensure that there are as many elements in iItemArray as in FeedEngine
   443 		while (iItemArray->Count() < nbrItems)
   483 		while (iItemArray->Count() < nbrItems)
   444 			{
   484 			{
   445 			iItemArray->AppendL(KNullDesC);
   485 			iItemArray->AppendL(KNullDesC);
       
   486 			iItemArrayShort->AppendL(KNullDesC);
   446 			TListItemProperties itemProps;
   487 			TListItemProperties itemProps;
   447 			iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(iItemArray->Count() - 1, itemProps);
   488 			//iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(iItemArray->Count() - 1, itemProps);
   448 			}
   489 			}
   449 		while (iItemArray->Count() > nbrItems)
   490 		while (iItemArray->Count() > nbrItems)
   450 			{
   491 			{
   451 			iItemArray->Delete(iItemArray->Count() - 1);
   492 			iItemArray->Delete(iItemArray->Count() - 1);
       
   493 			iItemArrayShort->Delete(iItemArray->Count() - 1);		
   452 			}
   494 			}
   453 		iUpdater->StartUpdate(nbrItems);
   495 		iUpdater->StartUpdate(nbrItems);
   454 		}
   496 		}
   455 	else
   497 	else
   456 		{
   498 		{
   457 		// No feeds at all in the list , add dummy list item
   499 		// No feeds at all in the list , add dummy list item
   458 		TBuf<KMaxFeedNameLength> itemName;
   500 		TBuf<KMaxFeedNameLength> itemName;
   459 		iEikonEnv->ReadResourceL(itemName, R_PODCAST_FEEDS_NO_FEEDS);
   501 		iEikonEnv->ReadResourceL(itemName, R_PODCAST_FEEDS_NO_FEEDS);
   460 		iItemArray->Reset();
   502 		iItemArray->Reset();
       
   503 		iItemArrayShort->Reset();
   461 		iItemIdArray.Reset();
   504 		iItemIdArray.Reset();
   462 	
   505 	
   463 		TListItemProperties itemProps;
   506 		TListItemProperties itemProps;
   464 		itemProps.SetDimmed(ETrue);
   507 		itemProps.SetDimmed(ETrue);
   465 		itemProps.SetHiddenSelection(ETrue);								
   508 		itemProps.SetHiddenSelection(ETrue);								
   466 		iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(0, itemProps);
   509 		//iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(0, itemProps);
   467 		}
   510 		}
   468 	iListContainer->Listbox()->HandleItemAdditionL();
   511 	iListContainer->Listbox()->HandleItemAdditionL();
   469 	DP("CPodcastFeedView::UpdateListboxItemsL END");
   512 	DP("CPodcastFeedView::UpdateListboxItemsL END");
   470 	}
   513 	}
   471 
   514 
   478 	{
   521 	{
   479 	DP("CPodcastFeedView::HandleCommandL BEGIN");
   522 	DP("CPodcastFeedView::HandleCommandL BEGIN");
   480 
   523 
   481 	switch(aCommand)
   524 	switch(aCommand)
   482 		{
   525 		{
   483         case EPodcastHide:
       
   484 			AppUi()->HandleCommandL(EEikCmdExit);
       
   485 			break;
       
   486 		case EPodcastAddFeed:
   526 		case EPodcastAddFeed:
   487 			HandleAddFeedL();
   527 			HandleAddFeedL();
   488 			break;
   528 			break;
   489 		case EPodcastImportFeeds:
   529 		case EPodcastImportFeeds:
   490 			HandleImportFeedsL();
   530 			HandleImportFeedsL();
   508 			{
   548 			{
   509 			HandleUpdateFeedL();
   549 			HandleUpdateFeedL();
   510 			}break;
   550 			}break;
   511 		case EPodcastCancelUpdateAllFeeds:
   551 		case EPodcastCancelUpdateAllFeeds:
   512 			{
   552 			{
   513 			if(iUpdatingRunning)
   553 			if(iFeedUpdating)
   514 				{
   554 				{
   515 				iPodcastModel.FeedEngine().CancelUpdateAllFeeds();
   555 				iPodcastModel.FeedEngine().CancelUpdateAllFeeds();
   516 				}
   556 				}
   517 			}break;
   557 			}break;
   518 		case EAknSoftkeyExit:
   558 		case EPodcastShowInfo:
   519 			{
   559 			DisplayFeedInfoDialogL();
   520 			RShowInfoArray dlQueue;
       
   521 			iPodcastModel.ShowEngine().GetShowsDownloadingL(dlQueue);
       
   522 			TUint queueCount = dlQueue.Count();
       
   523 			dlQueue.ResetAndDestroy();
       
   524 			dlQueue.Close();
       
   525 			
       
   526 			if (queueCount > 0 && !iPodcastModel.SettingsEngine().DownloadSuspended())
       
   527 				{
       
   528 				TBuf<KMaxMessageLength> message;
       
   529 				iEikonEnv->ReadResourceL(message, R_EXIT_SHOWS_DOWNLOADING);
       
   530 				if(ShowQueryMessageL(message))
       
   531 					{
       
   532 					// pass it on to AppUi, which will exit for us
       
   533 					CPodcastListView::HandleCommandL(aCommand);
       
   534 					}
       
   535 				} 
       
   536 			else
       
   537 				{
       
   538 					// nothing in queue, or downloading suspended
       
   539 					CPodcastListView::HandleCommandL(aCommand);
       
   540 				}
       
   541 			}
       
   542 			break;
   560 			break;
   543 		default:
   561 		default:
   544 			CPodcastListView::HandleCommandL(aCommand);
   562 			CPodcastListView::HandleCommandL(aCommand);
   545 			break;
   563 			break;
   546 		}
   564 		}
   548 	iListContainer->SetLongTapDetectedL(EFalse); // in case we got here by long tapping
   566 	iListContainer->SetLongTapDetectedL(EFalse); // in case we got here by long tapping
   549 	UpdateToolbar();
   567 	UpdateToolbar();
   550 	DP("CPodcastFeedView::HandleCommandL END");
   568 	DP("CPodcastFeedView::HandleCommandL END");
   551 	}
   569 	}
   552 
   570 
       
   571 void CPodcastFeedView::DisplayFeedInfoDialogL()
       
   572 	{
       
   573 	const RFeedInfoArray* sortedItems = NULL;
       
   574 	TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
   575 	sortedItems = &iPodcastModel.FeedEngine().GetSortedFeeds();
       
   576 
       
   577 	if(index >= 0 && index < sortedItems->Count())
       
   578 		{
       
   579 		CFeedInfo *info = (*sortedItems)[index];
       
   580 		HBufC* description = info->Description().AllocL();
       
   581 		HBufC* title = info->Title().AllocL();
       
   582 		CAknMessageQueryDialog* note = new ( ELeave ) CAknMessageQueryDialog( description, title );
       
   583 							
       
   584 		note->PrepareLC( R_SHOW_INFO_NOTE ); // Adds to CleanupStack
       
   585 		note->RunLD();
       
   586 		}
       
   587 	}
   553 void CPodcastFeedView::UpdateToolbar(TBool aVisible)
   588 void CPodcastFeedView::UpdateToolbar(TBool aVisible)
   554 {
   589 {
   555 	DP("CPodcastFeedView::UpdateToolbar BEGIN");
   590 	DP("CPodcastFeedView::UpdateToolbar BEGIN");
   556 	CAknToolbar* toolbar = Toolbar();
   591 	CAknToolbar* toolbar = Toolbar();
   557 	
   592 	
   558 	if (toolbar)
   593 	if (toolbar)
   559 		{
   594 		{
   560 		if (iListContainer->IsVisible()) {
   595 		if (iListContainer->IsVisible()) {
   561 			toolbar->SetToolbarVisibility(aVisible);
   596 			toolbar->SetToolbarVisibility(aVisible);
   562 		}
   597 		}
   563 		toolbar->HideItem(EPodcastUpdateAllFeeds, iUpdatingRunning, ETrue);
   598 		toolbar->HideItem(EPodcastUpdateAllFeeds, iFeedUpdating, ETrue);
   564 		toolbar->HideItem(EPodcastCancelUpdateAllFeeds, !iUpdatingRunning, ETrue );
   599 		toolbar->HideItem(EPodcastCancelUpdateAllFeeds, !iFeedUpdating, ETrue );
   565 		toolbar->SetItemDimmed(EPodcastAddFeed, iUpdatingRunning, ETrue );
   600 		toolbar->SetItemDimmed(EPodcastAddFeed, iFeedUpdating, ETrue );
   566 		toolbar->SetItemDimmed(EPodcastSettings, iUpdatingRunning, ETrue );
   601 		toolbar->SetItemDimmed(EPodcastSettings, iFeedUpdating, ETrue );
   567 		}
   602 		}
   568 	DP("CPodcastFeedView::UpdateToolbar END");
   603 	DP("CPodcastFeedView::UpdateToolbar END");
   569 }
   604 }
   570 
   605 
   571 void CPodcastFeedView::HandleAddFeedL()
   606 void CPodcastFeedView::HandleAddFeedL()
   594 			// Search selected
   629 			// Search selected
   595 			HandleAddFeedSearchL();
   630 			HandleAddFeedSearchL();
   596 			}	
   631 			}	
   597 		}
   632 		}
   598 	CleanupStack::PopAndDestroy( array );		
   633 	CleanupStack::PopAndDestroy( array );		
       
   634 	}
       
   635 
       
   636 void CPodcastFeedView::ShowItem(TUint aUid)
       
   637 	{
       
   638 	TInt listIndex = -1;
       
   639 	for (TUint i=0;i<iItemIdArray.Count();i++)
       
   640 		{
       
   641 		if (iItemIdArray[i] == aUid)
       
   642 			{
       
   643 			listIndex = i;
       
   644 			}
       
   645 		}
       
   646 		
       
   647 	if (listIndex != -1)
       
   648 		iListContainer->Listbox()->ScrollToMakeItemVisible(listIndex);
       
   649 
   599 	}
   650 	}
   600 
   651 
   601 void CPodcastFeedView::HandleAddFeedUrlL()
   652 void CPodcastFeedView::HandleAddFeedUrlL()
   602 	{
   653 	{
   603 	TBuf<KFeedUrlLength> url;
   654 	TBuf<KFeedUrlLength> url;
   628 			// ask if users wants to update it now
   679 			// ask if users wants to update it now
   629 			TBuf<KMaxMessageLength> message;
   680 			TBuf<KMaxMessageLength> message;
   630 			iEikonEnv->ReadResourceL(message, R_ADD_FEED_SUCCESS);
   681 			iEikonEnv->ReadResourceL(message, R_ADD_FEED_SUCCESS);
   631 			if(ShowQueryMessageL(message))
   682 			if(ShowQueryMessageL(message))
   632 				{
   683 				{
   633 				CFeedInfo *info = iPodcastModel.FeedEngine().GetFeedInfoByUid(newFeedInfo->Uid());
   684 				ShowItem(newFeedInfo->Uid());
   634 				
       
   635 				iPodcastModel.SetActiveFeedInfo(info);			
       
   636 				AppUi()->ActivateLocalViewL(KUidPodcastShowsViewID,  TUid::Uid(0), KNullDesC8());
       
   637 				iPodcastModel.FeedEngine().UpdateFeedL(newFeedInfo->Uid());
   685 				iPodcastModel.FeedEngine().UpdateFeedL(newFeedInfo->Uid());
   638 				}
   686 				}
   639 			}
   687 			}
   640 		else
   688 		else
   641 			{
   689 			{
   760 			message.Format(templ, &info->Title());					
   808 			message.Format(templ, &info->Title());					
   761 			if(ShowQueryMessageL(message))
   809 			if(ShowQueryMessageL(message))
   762 				{
   810 				{
   763 				iPodcastModel.FeedEngine().RemoveFeedL(iItemIdArray[index]);
   811 				iPodcastModel.FeedEngine().RemoveFeedL(iItemIdArray[index]);
   764 				iItemArray->Delete(index);
   812 				iItemArray->Delete(index);
       
   813 				iItemArrayShort->Delete(index);
   765 				iItemIdArray.Remove(index);
   814 				iItemIdArray.Remove(index);
   766 				iListContainer->Listbox()->HandleItemRemovalL();
   815 				iListContainer->Listbox()->HandleItemRemovalL();
   767 				iListContainer->Listbox()->DrawNow();
   816 				iListContainer->Listbox()->DrawNow();
   768 				}					
   817 				}					
   769 			}
   818 			}
   881 	showsDownloading.ResetAndDestroy();
   930 	showsDownloading.ResetAndDestroy();
   882 	}
   931 	}
   883 
   932 
   884 void CPodcastFeedView::CheckConfirmExit()
   933 void CPodcastFeedView::CheckConfirmExit()
   885 	{
   934 	{
       
   935 	DP("CPodcastFeedView::CheckConfirmExit");
   886 	RShowInfoArray showsDownloading;
   936 	RShowInfoArray showsDownloading;
   887 	iPodcastModel.ShowEngine().GetShowsDownloadingL(showsDownloading);
   937 	iPodcastModel.ShowEngine().GetShowsDownloadingL(showsDownloading);
   888 
   938 	TUint count = showsDownloading.Count();
   889 	if (showsDownloading.Count() > 0 && !iPodcastModel.SettingsEngine().DownloadSuspended())
   939 	showsDownloading.ResetAndDestroy();
       
   940 	showsDownloading.Close();
       
   941 
       
   942 	if (count > 0 && !iPodcastModel.SettingsEngine().DownloadSuspended())
   890 		{
   943 		{
   891 		TBuf<256> msg;
   944 		TBuf<256> msg;
   892 		iEikonEnv->ReadResourceL(msg, R_EXIT_SHOWS_DOWNLOADING);
   945 		iEikonEnv->ReadResourceL(msg, R_EXIT_SHOWS_DOWNLOADING);
   893 		
   946 		
   894 		if (!ShowQueryMessageL(msg))
   947 		if (!ShowQueryMessageL(msg))
   952 					iEikonEnv->ReadResourceL(message, R_SEARCH_NORESULTS);
  1005 					iEikonEnv->ReadResourceL(message, R_SEARCH_NORESULTS);
   953 					ShowErrorMessageL(message);
  1006 					ShowErrorMessageL(message);
   954 					}
  1007 					}
   955 				else
  1008 				else
   956 					{
  1009 					{
       
  1010 					iToolbar->SetToolbarVisibility(EFalse);
   957 					AppUi()->ActivateLocalViewL(KUidPodcastSearchViewID,  TUid::Uid(0), KNullDesC8());
  1011 					AppUi()->ActivateLocalViewL(KUidPodcastSearchViewID,  TUid::Uid(0), KNullDesC8());
   958 					}
  1012 					}
   959 				iOpmlState = EOpmlIdle;
  1013 				iOpmlState = EOpmlIdle;
   960 				break;
  1014 				break;
   961 			default:
  1015 			default:
   986 	TInt lbHeight = iListContainer->Listbox()->CalcHeightBasedOnNumOfItems(
  1040 	TInt lbHeight = iListContainer->Listbox()->CalcHeightBasedOnNumOfItems(
   987 			iListContainer->Listbox()->Model()->NumberOfItems()) - KListboxDefaultHeight;
  1041 			iListContainer->Listbox()->Model()->NumberOfItems()) - KListboxDefaultHeight;
   988 
  1042 
   989     if(iStylusPopupMenu && aPenEventLocation.iY < lbHeight)
  1043     if(iStylusPopupMenu && aPenEventLocation.iY < lbHeight)
   990     {
  1044     {
       
  1045     	TInt index = iListContainer->Listbox()->CurrentItemIndex();
       
  1046     	
       
  1047 		CFeedInfo *info = iPodcastModel.FeedEngine().GetSortedFeeds()[index];
       
  1048 		
       
  1049 		iStylusPopupMenu->SetItemDimmed(EPodcastShowInfo, info->Description().Length() == 0);
       
  1050 
   991 		iStylusPopupMenu->ShowMenu();
  1051 		iStylusPopupMenu->ShowMenu();
   992 		iStylusPopupMenu->SetPosition(aPenEventLocation);
  1052 		iStylusPopupMenu->SetPosition(aPenEventLocation);
   993     }
  1053     }
   994 	DP("CPodcastListView::HandleLongTapEventL END");
  1054 	DP("CPodcastListView::HandleLongTapEventL END");
   995 }
  1055 }