application/src/PodcastFeedView.cpp
changeset 60 4d230e702aa3
parent 59 9569ea080d5a
child 65 bcd88ba95046
equal deleted inserted replaced
59:9569ea080d5a 60:4d230e702aa3
    27 #include <caknfileselectiondialog.h> 
    27 #include <caknfileselectiondialog.h> 
    28 #include <podcast.rsg>
    28 #include <podcast.rsg>
    29 #include <podcast.mbg>
    29 #include <podcast.mbg>
    30 #include <gulicon.h>
    30 #include <gulicon.h>
    31 #include <aknquerydialog.h>
    31 #include <aknquerydialog.h>
    32 #include <caknmemoryselectiondialog.h> 
       
    33 #include <caknfilenamepromptdialog.h> 
       
    34 #include <BAUTILS.H> 
    32 #include <BAUTILS.H> 
    35 #include <pathinfo.h> 
    33 #include <pathinfo.h> 
       
    34 #include <akncommondialogsdynmem.h> 
       
    35 #include "Podcatcher.pan"
    36 
    36 
    37 const TInt KMaxFeedNameLength = 100;
    37 const TInt KMaxFeedNameLength = 100;
    38 const TInt KMaxUnplayedFeedsLength =64;
    38 const TInt KMaxUnplayedFeedsLength =64;
    39 const TInt KADayInHours = 24;
    39 const TInt KADayInHours = 24;
    40 const TInt KDefaultGran = 5;
    40 const TInt KDefaultGran = 5;
   103 	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
   103 	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
   104 	CleanupStack::PushL( mask );
   104 	CleanupStack::PushL( mask );
   105 	// Append the feed icon to icon array
   105 	// Append the feed icon to icon array
   106 	icons->AppendL( CGulIcon::NewL( bitmap, mask ) );
   106 	icons->AppendL( CGulIcon::NewL( bitmap, mask ) );
   107 	CleanupStack::Pop(2); // bitmap, mask
   107 	CleanupStack::Pop(2); // bitmap, mask
   108 	
       
   109 	iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
   108 	iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
   110 	CleanupStack::Pop(icons); // icons
   109 	CleanupStack::Pop(icons); // icons
   111 
   110 
   112 	iListContainer->Listbox()->SetListBoxObserver(this);
   111 	iListContainer->Listbox()->SetListBoxObserver(this);
   113 	
   112 	
   126 	iPodcastModel.FeedEngine().RemoveObserver(this);
   125 	iPodcastModel.FeedEngine().RemoveObserver(this);
   127 	delete iFeedsFormat;
   126 	delete iFeedsFormat;
   128 	delete iNeverUpdated;
   127 	delete iNeverUpdated;
   129 	delete iStylusPopupMenu;
   128 	delete iStylusPopupMenu;
   130 	delete iUpdater;
   129 	delete iUpdater;
       
   130 	iFeedIdForIconArray.Close();
   131     }
   131     }
   132 
   132 
   133 void CPodcastFeedView::UpdateItemL(TInt aIndex)
   133 void CPodcastFeedView::UpdateItemL(TInt aIndex)
   134 	{
   134 	{
   135 	_LIT(KPanicCategory, "CPodcastFeedView::UpdateItemL");
   135 	__ASSERT_DEBUG(iListContainer->IsVisible(), Panic(EPodcatcherPanicFeedView));
   136 	__ASSERT_DEBUG(iListContainer->IsVisible(), User::Panic(KPanicCategory, 0));
   136 	__ASSERT_ALWAYS(iItemIdArray.Count() > aIndex, Panic(EPodcatcherPanicFeedView));
   137 	__ASSERT_ALWAYS(iItemIdArray.Count() > aIndex, User::Panic(KPanicCategory, 1));
       
   138 
   137 
   139 	const RFeedInfoArray& sortedItems = iPodcastModel.FeedEngine().GetSortedFeeds();
   138 	const RFeedInfoArray& sortedItems = iPodcastModel.FeedEngine().GetSortedFeeds();
   140 	__ASSERT_ALWAYS(sortedItems.Count() > aIndex, User::Panic(KPanicCategory, 2));
   139 	__ASSERT_ALWAYS(sortedItems.Count() > aIndex, Panic(EPodcatcherPanicFeedView));
   141 
   140 
   142 	// Update UID of for the feed at aIndex
   141 	// Update UID of for the feed at aIndex
   143 	iItemIdArray[aIndex] = sortedItems[aIndex]->Uid();
   142 	iItemIdArray[aIndex] = sortedItems[aIndex]->Uid();
   144 	
   143 	
   145 	// Prepare data to update the listbox item with
   144 	// Prepare data to update the listbox item with
   173 void CPodcastFeedView::DoActivateL(const TVwsViewId& aPrevViewId,
   172 void CPodcastFeedView::DoActivateL(const TVwsViewId& aPrevViewId,
   174 	                                  TUid aCustomMessageId,
   173 	                                  TUid aCustomMessageId,
   175 	                                  const TDesC8& aCustomMessage)
   174 	                                  const TDesC8& aCustomMessage)
   176 	{
   175 	{
   177 	CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage);
   176 	CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage);
   178 
   177 	
   179 	if (aPrevViewId.iViewUid == KUidPodcastShowsViewID)
   178 	if (aPrevViewId.iViewUid == KUidPodcastShowsViewID)
   180 		{
   179 		{
   181 		// back key from shows view
   180 		// back key from shows view
   182 		iViewingShows = EFalse;
   181 		iViewingShows = EFalse;
   183 		}
   182 		}
   184 	
   183 	
   185 	if (iViewingShows)
       
   186 		{
       
   187 		// go to shows view
       
   188 		AppUi()->ActivateLocalViewL(KUidPodcastShowsViewID,  TUid::Uid(0), KNullDesC8());
       
   189 		} 
       
   190 	else 
       
   191 		{
       
   192 		UpdateListboxItemsL();		
   184 		UpdateListboxItemsL();		
   193 		UpdateToolbar();
   185 		UpdateToolbar();
   194 
   186 
   195 		if (iFirstActivateAfterLaunch)
   187 	if (iFirstActivateAfterLaunch)
   196 			{
   188 		{
   197 			iFirstActivateAfterLaunch = EFalse;
   189 		iFirstActivateAfterLaunch = EFalse;
   198 			}
       
   199 		}
   190 		}
   200 	}
   191 	}
   201 
   192 
   202 void CPodcastFeedView::DoDeactivate()
   193 void CPodcastFeedView::DoDeactivate()
   203 	{
   194 	{
   210 	{
   201 	{
   211 	DP("CPodcastFeedView::HandleListBoxEventL BEGIN");
   202 	DP("CPodcastFeedView::HandleListBoxEventL BEGIN");
   212 
   203 
   213 	switch(aEventType)
   204 	switch(aEventType)
   214 		{
   205 		{
   215 		case EEventPenDownOnItem:
   206 #ifndef SYMBIAN1_UI
   216 			DP("PEN DOWN");
       
   217 			break;
       
   218 			
       
   219 //#ifndef SYMBIAN1_UI
       
   220 	case EEventItemClicked:
   207 	case EEventItemClicked:
   221 		DP("SINGLE TAP");
   208 #endif
   222 		break;
       
   223 //#endif
       
   224 	case EEventEnterKeyPressed:
   209 	case EEventEnterKeyPressed:
   225 	case EEventItemDoubleClicked:
   210 	case EEventItemDoubleClicked:
   226 	case EEventItemActioned:
   211 	case EEventItemActioned:
   227 		DP("DOUBLE TAP");
       
   228 			{
   212 			{
   229 			const RFeedInfoArray* sortedItems = NULL;
   213 			const RFeedInfoArray* sortedItems = NULL;
   230 			TInt index = iListContainer->Listbox()->CurrentItemIndex();
   214 			TInt index = iListContainer->Listbox()->CurrentItemIndex();
   231 			sortedItems = &iPodcastModel.FeedEngine().GetSortedFeeds();
   215 			sortedItems = &iPodcastModel.FeedEngine().GetSortedFeeds();
   232 
   216 
   233 			if(index >= 0 && index < sortedItems->Count())
   217 			if(index >= 0 && index < sortedItems->Count())
   234 				{
   218 				{
   235 				iPodcastModel.ActiveShowList().Reset();
       
   236 				iPodcastModel.SetActiveFeedInfo((*sortedItems)[index]);			
   219 				iPodcastModel.SetActiveFeedInfo((*sortedItems)[index]);			
   237 				iViewingShows = ETrue;
   220 				iViewingShows = ETrue;
   238 				AppUi()->ActivateLocalViewL(KUidPodcastShowsViewID,  TUid::Uid(0), KNullDesC8());
   221 				AppUi()->ActivateLocalViewL(KUidPodcastShowsViewID,  TUid::Uid(0), KNullDesC8());
   239 				}
   222 				}
   240 			}
   223 			}
   267 			{
   250 			{
   268 			if(aState == MFeedEngineObserver::EFeedManualUpdate)
   251 			if(aState == MFeedEngineObserver::EFeedManualUpdate)
   269 				{
   252 				{
   270 				TBuf<KMaxMessageLength> message;
   253 				TBuf<KMaxMessageLength> message;
   271 				iEikonEnv->ReadResourceL(message, R_PODCAST_CONNECTION_ERROR);
   254 				iEikonEnv->ReadResourceL(message, R_PODCAST_CONNECTION_ERROR);
   272 				ShowErrorMessage(message);
   255 				ShowErrorMessageL(message);
   273 				}
   256 				}
   274 			}
   257 			}
   275 			break;
   258 			break;
   276 		default: // Do nothing
   259 		default: // Do nothing
   277 			break;
   260 			break;
   342 		iEikonEnv->ReadResourceL(updatedDate, R_PODCAST_FEEDS_IS_UPDATING);
   325 		iEikonEnv->ReadResourceL(updatedDate, R_PODCAST_FEEDS_IS_UPDATING);
   343 		unplayedShows = KNullDesC();			
   326 		unplayedShows = KNullDesC();			
   344 		}
   327 		}
   345 	else
   328 	else
   346 		{
   329 		{
   347 		iPodcastModel.FeedEngine().GetStatsByFeed(aFeedInfo.Uid(), showCount, unplayedCount);	
   330 		// we will get a leave if there are no shows for this feed, for instance, which is fine
       
   331 		TRAP_IGNORE(iPodcastModel.FeedEngine().GetStatsByFeedL(aFeedInfo.Uid(), showCount, unplayedCount));	
   348 		
   332 		
   349 		if (unplayedCount) {
   333 		if (unplayedCount) {
   350 			unplayedShows.Format(*iFeedsFormat, unplayedCount);
   334 			unplayedShows.Format(*iFeedsFormat, unplayedCount);
   351 		} else {
   335 		} else {
   352 			unplayedShows.Zero();
   336 			unplayedShows.Zero();
   374 			}
   358 			}
   375 		
   359 		
   376 		if(aFeedInfo.LastError() != KErrNone)
   360 		if(aFeedInfo.LastError() != KErrNone)
   377 			{
   361 			{
   378 			GetFeedErrorText(unplayedShows, aFeedInfo.LastError());
   362 			GetFeedErrorText(unplayedShows, aFeedInfo.LastError());
       
   363 			updatedDate.Zero();
   379 			}
   364 			}
   380 		}
   365 		}
   381 	CArrayPtr<CGulIcon>* icons = iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->IconArray();
   366 	CArrayPtr<CGulIcon>* icons = iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->IconArray();
   382 	
   367 	iconIndex = iFeedIdForIconArray.Find(aFeedInfo.Uid());
   383 	if (aFeedInfo.FeedIconIndex() != -1) {
   368 	if(iconIndex == KErrNotFound && aFeedInfo.FeedIcon() != NULL && aFeedInfo.ImageFileName().Length() > 0 && 
   384 		iconIndex = aFeedInfo.FeedIconIndex();
   369 			aFeedInfo.FeedIcon()->SizeInPixels().iHeight > 0 &&
   385 	} else {
   370 			aFeedInfo.FeedIcon()->SizeInPixels().iWidth > 0)
   386 		if(aFeedInfo.FeedIcon() != NULL && 
   371 		{
   387 				aFeedInfo.FeedIcon()->SizeInPixels().iHeight > 0 &&
   372 		// Hopefully temporary haxx to prevent double delete. I would prefer if
   388 				aFeedInfo.FeedIcon()->SizeInPixels().iWidth > 0)
   373 		// this could be solved with a little better design.
   389 			{
   374 		CFbsBitmap* bmpCopy = new (ELeave) CFbsBitmap;
   390 			// Hopefully temporary haxx to prevent double delete. I would prefer if
   375 		CleanupStack::PushL(bmpCopy);
   391 			// this could be solved with a little better design.
   376 		bmpCopy->Duplicate(aFeedInfo.FeedIcon()->Handle());
   392 			CFbsBitmap* bmpCopy = new (ELeave) CFbsBitmap;
   377 		icons->AppendL( CGulIcon::NewL(bmpCopy, NULL));
   393 			CleanupStack::PushL(bmpCopy);
   378 		iFeedIdForIconArray.Append(aFeedInfo.Uid());
   394 			bmpCopy->Duplicate(aFeedInfo.FeedIcon()->Handle());
   379 		CleanupStack::Pop(bmpCopy);			
   395 			icons->AppendL( CGulIcon::NewL(bmpCopy, NULL));
   380 		iconIndex = icons->Count()-1;
   396 			CleanupStack::Pop(bmpCopy);
   381 		}	
   397 			iconIndex = icons->Count()-1;
   382 	else 
   398 			aFeedInfo.SetFeedIconIndex(iconIndex);
   383 		{
   399 			}
   384 		iconIndex++;
   400 		else {
   385 		}	
   401 			if(BaflUtils::FileExists(iEikonEnv->FsSession(), aFeedInfo.ImageFileName()))
   386 
   402 			{
   387 	if (unplayedShows.Length() > 0 && updatedDate.Length() > 0) {
   403 			// If this fails, no reason to worry
       
   404 			TRAP_IGNORE(iPodcastModel.ImageHandler().LoadFileAndScaleL(aFeedInfo.FeedIcon(), aFeedInfo.ImageFileName(), TSize(64,56), *this, aFeedInfo.Uid()));
       
   405 			}
       
   406 		}
       
   407 	}
       
   408 	
       
   409 	if (unplayedShows.Length() > 0) {
       
   410 		unplayedShows.Insert(0,_L(", "));
   388 		unplayedShows.Insert(0,_L(", "));
   411 	}
   389 	}
   412 	
   390 	
   413 	iListboxFormatbuffer.Format(KFeedFormat(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
   391 	iListboxFormatbuffer.Format(KFeedFormat(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
   414 	}
   392 	}
   415 
   393 
   416 void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle)
   394 void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle, CPodcastModel& /*aPodcastModel*/)
   417 	{
   395 	{
   418 	if (aError == KErrNone) {
   396 	if (aError == KErrNone) {
   419 	UpdateFeedInfoStatusL(aHandle, EFalse);
   397 		UpdateFeedInfoStatusL(aHandle, EFalse);
   420 	}
   398 		}
   421 	}
   399 	}
   422 
   400 
   423 void CPodcastFeedView::UpdateFeedInfoDataL(CFeedInfo* aFeedInfo, TInt aIndex, TBool aIsUpdating )
   401 void CPodcastFeedView::UpdateFeedInfoDataL(CFeedInfo* aFeedInfo, TInt aIndex, TBool aIsUpdating )
   424 	{			
   402 	{			
   425 	TListItemProperties itemProps;			
   403 	TListItemProperties itemProps;			
   550 			
   528 			
   551 			if (queueCount > 0 && !iPodcastModel.SettingsEngine().DownloadSuspended())
   529 			if (queueCount > 0 && !iPodcastModel.SettingsEngine().DownloadSuspended())
   552 				{
   530 				{
   553 				TBuf<KMaxMessageLength> message;
   531 				TBuf<KMaxMessageLength> message;
   554 				iEikonEnv->ReadResourceL(message, R_EXIT_SHOWS_DOWNLOADING);
   532 				iEikonEnv->ReadResourceL(message, R_EXIT_SHOWS_DOWNLOADING);
   555 				if(ShowQueryMessage(message))
   533 				if(ShowQueryMessageL(message))
   556 					{
   534 					{
   557 					// pass it on to AppUi, which will exit for us
   535 					// pass it on to AppUi, which will exit for us
   558 					CPodcastListView::HandleCommandL(aCommand);
   536 					CPodcastListView::HandleCommandL(aCommand);
   559 					}
   537 					}
   560 				} 
   538 				} 
   568 		default:
   546 		default:
   569 			CPodcastListView::HandleCommandL(aCommand);
   547 			CPodcastListView::HandleCommandL(aCommand);
   570 			break;
   548 			break;
   571 		}
   549 		}
   572 	
   550 	
   573 	iListContainer->SetLongTapDetected(EFalse); // in case we got here by long tapping
   551 	iListContainer->SetLongTapDetectedL(EFalse); // in case we got here by long tapping
   574 	UpdateToolbar();
   552 	UpdateToolbar();
   575 	}
   553 	}
   576 
   554 
   577 void CPodcastFeedView::UpdateToolbar(TBool aVisible)
   555 void CPodcastFeedView::UpdateToolbar(TBool aVisible)
   578 {
   556 {
   629 				UpdateListboxItemsL();
   607 				UpdateListboxItemsL();
   630 				
   608 				
   631 				// ask if users wants to update it now
   609 				// ask if users wants to update it now
   632 				TBuf<KMaxMessageLength> message;
   610 				TBuf<KMaxMessageLength> message;
   633 				iEikonEnv->ReadResourceL(message, R_ADD_FEED_SUCCESS);
   611 				iEikonEnv->ReadResourceL(message, R_ADD_FEED_SUCCESS);
   634 				if(ShowQueryMessage(message))
   612 				if(ShowQueryMessageL(message))
   635 					{
   613 					{
   636 					CFeedInfo *info = iPodcastModel.FeedEngine().GetFeedInfoByUid(newFeedInfo->Uid());
   614 					CFeedInfo *info = iPodcastModel.FeedEngine().GetFeedInfoByUid(newFeedInfo->Uid());
   637 					
   615 					
   638 					iPodcastModel.ActiveShowList().Reset();
       
   639 					iPodcastModel.SetActiveFeedInfo(info);			
   616 					iPodcastModel.SetActiveFeedInfo(info);			
   640 					AppUi()->ActivateLocalViewL(KUidPodcastShowsViewID,  TUid::Uid(0), KNullDesC8());
   617 					AppUi()->ActivateLocalViewL(KUidPodcastShowsViewID,  TUid::Uid(0), KNullDesC8());
   641 					iPodcastModel.FeedEngine().UpdateFeedL(newFeedInfo->Uid());
   618 					iPodcastModel.FeedEngine().UpdateFeedL(newFeedInfo->Uid());
   642 					}
   619 					}
   643 				}
   620 				}
   644 			else
   621 			else
   645 				{
   622 				{
   646 				TBuf<KMaxMessageLength> message;
   623 				TBuf<KMaxMessageLength> message;
   647 				iEikonEnv->ReadResourceL(message, R_ADD_FEED_EXISTS);
   624 				iEikonEnv->ReadResourceL(message, R_ADD_FEED_EXISTS);
   648 				ShowErrorMessage(message);
   625 				ShowErrorMessageL(message);
   649 				}		
   626 				}		
   650 			
   627 			
   651 			CleanupStack::PopAndDestroy(newFeedInfo);
   628 			CleanupStack::PopAndDestroy(newFeedInfo);
   652 			}
   629 			}
   653 		}
   630 		}
   674 				{
   651 				{
   675 				TBuf<KMaxMessageLength> dlgMessage;
   652 				TBuf<KMaxMessageLength> dlgMessage;
   676 				iEikonEnv->ReadResourceL(dlgMessage, R_ADD_FEED_REPLACE);
   653 				iEikonEnv->ReadResourceL(dlgMessage, R_ADD_FEED_REPLACE);
   677 
   654 
   678 				// Ask the user if it is OK to remove all shows
   655 				// Ask the user if it is OK to remove all shows
   679 				if ( ShowQueryMessage(dlgMessage))
   656 				if ( ShowQueryMessageL(dlgMessage))
   680 					{
   657 					{
   681 					PodcastUtils::FixProtocolsL(url);
   658 					PodcastUtils::FixProtocolsL(url);
   682 					
   659 					
   683 					//----- HACK ---- //
   660 					//----- HACK ---- //
   684 					CFeedInfo* temp = CFeedInfo::NewLC();
   661 					CFeedInfo* temp = CFeedInfo::NewLC();
   701 						UpdateListboxItemsL();
   678 						UpdateListboxItemsL();
   702 					} else {
   679 					} else {
   703 						// the feed existed. Object deleted in AddFeed.	
   680 						// the feed existed. Object deleted in AddFeed.	
   704 						TBuf<KMaxMessageLength> dlgMessage;
   681 						TBuf<KMaxMessageLength> dlgMessage;
   705 						iEikonEnv->ReadResourceL(dlgMessage, R_ADD_FEED_EXISTS);
   682 						iEikonEnv->ReadResourceL(dlgMessage, R_ADD_FEED_EXISTS);
   706 						ShowErrorMessage(dlgMessage);
   683 						ShowErrorMessageL(dlgMessage);
   707 					}
   684 					}
   708 					CleanupStack::PopAndDestroy(temp);
   685 					CleanupStack::PopAndDestroy(temp);
   709 				}
   686 				}
   710 			} else { // no url change, maybe title?
   687 			} else { // no url change, maybe title?
   711 				// Update the title
   688 				// Update the title
   712 				if (info->Title().Compare(title) != 0)
   689 				if (info->Title().Compare(title) != 0)
   713 				{
   690 				{
   714 					info->SetTitleL(title);
   691 					info->SetTitleL(title);
   715 					info->SetCustomTitle();	
   692 					info->SetCustomTitle();	
   716 					iPodcastModel.FeedEngine().UpdateFeed(info);
   693 					iPodcastModel.FeedEngine().UpdateFeedInfoL(info);
   717 					UpdateListboxItemsL();
   694 					UpdateListboxItemsL();
   718 				}
   695 				}
   719 			}
   696 			}
   720 		}
   697 		}
   721 		}
   698 		}
   732 			CFeedInfo *info = iPodcastModel.FeedEngine().GetFeedInfoByUid(iItemIdArray[index]);
   709 			CFeedInfo *info = iPodcastModel.FeedEngine().GetFeedInfoByUid(iItemIdArray[index]);
   733 			TBuf<KMaxMessageLength> templ;
   710 			TBuf<KMaxMessageLength> templ;
   734 			TBuf<KMaxMessageLength> message;
   711 			TBuf<KMaxMessageLength> message;
   735 			iEikonEnv->ReadResourceL(templ, R_PODCAST_REMOVE_FEED_PROMPT);
   712 			iEikonEnv->ReadResourceL(templ, R_PODCAST_REMOVE_FEED_PROMPT);
   736 			message.Format(templ, &info->Title());					
   713 			message.Format(templ, &info->Title());					
   737 			if(ShowQueryMessage(message))
   714 			if(ShowQueryMessageL(message))
   738 				{
   715 				{
   739 				iPodcastModel.FeedEngine().RemoveFeedL(iItemIdArray[index]);
   716 				iPodcastModel.FeedEngine().RemoveFeedL(iItemIdArray[index]);
   740 				iItemArray->Delete(index);
   717 				iItemArray->Delete(index);
   741 				iItemIdArray.Remove(index);
   718 				iItemIdArray.Remove(index);
   742 				iListContainer->Listbox()->HandleItemRemovalL();
   719 				iListContainer->Listbox()->HandleItemRemovalL();
   758 		}
   735 		}
   759 	}
   736 	}
   760 
   737 
   761 void CPodcastFeedView::HandleImportFeedsL()
   738 void CPodcastFeedView::HandleImportFeedsL()
   762 	{
   739 	{
   763 	CAknMemorySelectionDialog* memDlg = 
   740 	TFileName fileName;
   764 		CAknMemorySelectionDialog::NewL(ECFDDialogTypeNormal, ETrue);
   741 	fileName.Zero();
   765 	CleanupStack::PushL(memDlg);
   742 	TFileName startFolder;
   766 	CAknMemorySelectionDialog::TMemory memory = 
   743 	startFolder.Zero();
   767 		CAknMemorySelectionDialog::EPhoneMemory;
   744 	TInt types = AknCommonDialogsDynMem::EMemoryTypePhone | AknCommonDialogsDynMem::EMemoryTypeMMC |AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage| AknCommonDialogsDynMem::EMemoryTypeRemote;
   768 
   745 	
   769 	if (memDlg->ExecuteL(memory))
   746 	HBufC *title = iCoeEnv->AllocReadResourceLC(R_PODCAST_SELECT_OPML);
   770 		{
   747 	if (AknCommonDialogsDynMem::RunSelectDlgLD (types, fileName,
   771 		TFileName importName;
   748 			startFolder, NULL, NULL, *title))
   772 	
   749 		{
   773 		if (memory==CAknMemorySelectionDialog::EMemoryCard)
       
   774 		{
       
   775 			importName = PathInfo:: MemoryCardRootPath();
       
   776 		}
       
   777 		else
       
   778 		{
       
   779 			importName = PathInfo:: PhoneMemoryRootPath();
       
   780 		}
       
   781 
       
   782 		CAknFileSelectionDialog* dlg = CAknFileSelectionDialog::NewL(ECFDDialogTypeNormal, R_PODCAST_IMPORT_PODCAST);
       
   783 		CleanupStack::PushL(dlg);
       
   784 
       
   785 		dlg->SetDefaultFolderL(importName);
       
   786 		
   750 		
   787 		if(dlg->ExecuteL(importName))
   751 		if(fileName.Length()>0)
   788 			{
   752 			{
   789 			if(importName.Length()>0)
   753 			HBufC *waitText = iEikonEnv->AllocReadResourceLC(R_IMPORTING);
   790 				{
   754 			iOpmlState = EOpmlImporting;
   791 				HBufC *waitText = iEikonEnv->AllocReadResourceLC(R_IMPORTING);
   755 			ShowWaitDialogL(*waitText);
   792 				iOpmlState = EOpmlImporting;
   756 			CleanupStack::PopAndDestroy(waitText);	
   793 				ShowWaitDialogL(*waitText);
   757 
   794 				CleanupStack::PopAndDestroy(waitText);	
   758 			TRAPD(err, iPodcastModel.FeedEngine().ImportFeedsL(fileName));
   795 
   759 								
   796 				TRAPD(err, iPodcastModel.FeedEngine().ImportFeedsL(importName));
   760 			if (err != KErrNone) {
   797 									
   761 				TBuf<KMaxMessageLength> message;
   798 				if (err != KErrNone) {
   762 				iEikonEnv->ReadResourceL(message, R_IMPORT_FEED_FAILURE);
   799 					TBuf<KMaxMessageLength> message;
   763 				ShowErrorMessageL(message);
   800 					iEikonEnv->ReadResourceL(message, R_IMPORT_FEED_FAILURE);
   764 				}
   801 					ShowErrorMessage(message);
   765 			}
   802 					}
   766 
   803 				}
   767 		}
   804 				
   768 	CleanupStack::PopAndDestroy(title);
   805 			}
       
   806 		CleanupStack::PopAndDestroy(dlg);
       
   807 		}
       
   808 	CleanupStack::PopAndDestroy(memDlg);
       
   809 	}
   769 	}
   810 
   770 
   811 void CPodcastFeedView::HandleExportFeedsL()
   771 void CPodcastFeedView::HandleExportFeedsL()
   812 	{
   772 	{
   813 	CAknMemorySelectionDialog* memDlg = 
   773 	TFileName fileName;
   814 		CAknMemorySelectionDialog::NewL(ECFDDialogTypeSave, ETrue);
   774 	fileName.Copy(_L("feeds.opml"));
   815 	CleanupStack::PushL(memDlg);
   775 	TFileName startFolder;
   816 	CAknMemorySelectionDialog::TMemory memory = 
   776 	startFolder.Zero();
   817 		CAknMemorySelectionDialog::EPhoneMemory;
   777 	TInt types = AknCommonDialogsDynMem::EMemoryTypePhone | AknCommonDialogsDynMem::EMemoryTypeMMC |AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage| AknCommonDialogsDynMem::EMemoryTypeRemote;
   818 
   778 	
   819 	if (memDlg->ExecuteL(memory))
   779 	HBufC *title = iCoeEnv->AllocReadResourceLC(R_PODCAST_SELECT_FOLDER);
   820 		{
   780 	if (AknCommonDialogsDynMem::RunSaveDlgLD (types, fileName,
   821 		TFileName pathName;
   781 			startFolder, NULL, NULL, *title))
   822 		
   782 		{
   823 		if (memory==CAknMemorySelectionDialog::EMemoryCard)
   783 			TFileName temp;
   824 		{
   784 			TRAPD(err, iPodcastModel.FeedEngine().ExportFeedsL(temp));						
   825 			pathName = PathInfo::MemoryCardRootPath();
   785 			BaflUtils::CopyFile(iEikonEnv->FsSession(), temp, fileName);
   826 		}
   786 			BaflUtils::DeleteFile(iEikonEnv->FsSession(),temp);	
   827 		else
   787 			if (err == KErrNone) 
   828 		{
   788 				{
   829 			pathName = PathInfo::PhoneMemoryRootPath();
   789 				UpdateListboxItemsL();
   830 		}
   790 				TInt numFeeds = iPodcastModel.FeedEngine().GetSortedFeeds().Count();
   831 
       
   832 		CAknFileSelectionDialog* dlg = CAknFileSelectionDialog::NewL(ECFDDialogTypeSave, R_PODCAST_EXPORT_FEEDS);
       
   833 		CleanupStack::PushL(dlg);
       
   834 								
   791 								
   835 		if(dlg->ExecuteL(pathName))
   792 				TBuf<KMaxMessageLength> message;
   836 			{
   793 				TBuf<KMaxMessageLength> templ;
   837 			CAknFileNamePromptDialog *fileDlg = CAknFileNamePromptDialog::NewL(R_PODCAST_FILENAME_PROMPT_DIALOG);
   794 				iEikonEnv->ReadResourceL(templ, R_EXPORT_FEED_SUCCESS);
   838 			CleanupStack::PushL(fileDlg);
   795 				message.Format(templ, numFeeds);
   839 			fileDlg->SetPathL(pathName);
   796 				ShowOkMessageL(message);
   840 			TFileName fileName;
   797 				} 
   841 			if (fileDlg->ExecuteL(fileName) && fileName.Length() > 0)
   798 			else 
   842 				{
   799 				{
   843 				pathName.Append(fileName);
   800 				TBuf<KMaxMessageLength> message;
   844 				TFileName temp;
   801 				iEikonEnv->ReadResourceL(message, R_EXPORT_FEED_FAILURE);
   845 				TRAPD(err, iPodcastModel.FeedEngine().ExportFeedsL(temp));						
   802 				ShowErrorMessageL(message);
   846 				BaflUtils::CopyFile(iEikonEnv->FsSession(), temp, pathName);
   803 				}
   847 				BaflUtils::DeleteFile(iEikonEnv->FsSession(),temp);	
   804 		}
   848 				if (err == KErrNone) 
   805 	CleanupStack::PopAndDestroy(title);
   849 					{
   806 	}
   850 					UpdateListboxItemsL();
   807 
   851 					TInt numFeeds = iPodcastModel.FeedEngine().GetSortedFeeds().Count();
   808 void CPodcastFeedView::CheckResumeDownloadL()
   852 									
       
   853 					TBuf<KMaxMessageLength> message;
       
   854 					TBuf<KMaxMessageLength> templ;
       
   855 					iEikonEnv->ReadResourceL(templ, R_EXPORT_FEED_SUCCESS);
       
   856 					message.Format(templ, numFeeds);
       
   857 					ShowOkMessage(message);
       
   858 					} 
       
   859 				else 
       
   860 					{
       
   861 					TBuf<KMaxMessageLength> message;
       
   862 					iEikonEnv->ReadResourceL(message, R_EXPORT_FEED_FAILURE);
       
   863 					ShowErrorMessage(message);
       
   864 					}
       
   865 				}
       
   866 			CleanupStack::PopAndDestroy(fileDlg);
       
   867 			}
       
   868 		CleanupStack::PopAndDestroy(dlg);
       
   869 	}
       
   870 	CleanupStack::PopAndDestroy(memDlg);									
       
   871 	}
       
   872 
       
   873 void CPodcastFeedView::CheckResumeDownload()
       
   874 	{
   809 	{
   875 	// if there are shows queued for downloading, ask if we should resume now
   810 	// if there are shows queued for downloading, ask if we should resume now
   876 	RShowInfoArray showsDownloading;
   811 	RShowInfoArray showsDownloading;
   877 	iPodcastModel.ShowEngine().GetShowsDownloadingL(showsDownloading);
   812 	iPodcastModel.ShowEngine().GetShowsDownloadingL(showsDownloading);
   878 
   813 
   879 	if (showsDownloading.Count() > 0)
   814 	if (showsDownloading.Count() > 0)
   880 		{
   815 		{
   881 		TBuf<KMaxMessageLength> msg;
   816 		TBuf<KMaxMessageLength> msg;
   882 		iEikonEnv->ReadResourceL(msg, R_PODCAST_ENABLE_DOWNLOADS_PROMPT);
   817 		iEikonEnv->ReadResourceL(msg, R_PODCAST_ENABLE_DOWNLOADS_PROMPT);
   883 	
   818 	
   884 		if (ShowQueryMessage(msg))
   819 		if (ShowQueryMessageL(msg))
   885 			{
   820 			{
   886 			// need to suspend downloads before ResumeDownloadL will work :)
   821 			// need to suspend downloads before ResumeDownloadL will work :)
   887 			iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue);
   822 			iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue);
   888 			// resume downloading if user says yes
   823 			// resume downloading if user says yes
   889 			iPodcastModel.ShowEngine().ResumeDownloadsL();
   824 			iPodcastModel.ShowEngine().ResumeDownloadsL();
   899 	showsDownloading.ResetAndDestroy();
   834 	showsDownloading.ResetAndDestroy();
   900 	}
   835 	}
   901 
   836 
   902 void CPodcastFeedView::OpmlParsingComplete(TInt aError, TUint aNumFeedsImported)
   837 void CPodcastFeedView::OpmlParsingComplete(TInt aError, TUint aNumFeedsImported)
   903 	{
   838 	{
       
   839 	TRAP_IGNORE(OpmlParsingCompleteL(aError, aNumFeedsImported));
       
   840 	}
       
   841 
       
   842 void CPodcastFeedView::OpmlParsingCompleteL(TInt aError, TUint aNumFeedsImported)
       
   843 	{
   904 	DP("CPodcastFeedView::OpmlParsingComplete BEGIN");
   844 	DP("CPodcastFeedView::OpmlParsingComplete BEGIN");
   905 	
   845 	
   906 	switch (aError)
   846 	switch (aError)
   907 		{
   847 		{
   908 		case KErrCouldNotConnect:
   848 		case KErrCouldNotConnect:
   909 			{
   849 			{
   910 			TBuf<KMaxMessageLength> message;
   850 			TBuf<KMaxMessageLength> message;
   911 			iEikonEnv->ReadResourceL(message, R_PODCAST_CONNECTION_ERROR);
   851 			iEikonEnv->ReadResourceL(message, R_PODCAST_CONNECTION_ERROR);
   912 			ShowErrorMessage(message);
   852 			ShowErrorMessageL(message);
   913 			}
   853 			}
   914 			break;
   854 			break;
   915 		case KErrNone: 
   855 		case KErrNone: 
   916 		default:			// we don't do more error handling here, just show 0 imported feeds
   856 		default:			// we don't do more error handling here, just show 0 imported feeds
   917 		switch (iOpmlState)
   857 		switch (iOpmlState)
   927 				TBuf<KMaxMessageLength> message;
   867 				TBuf<KMaxMessageLength> message;
   928 				TBuf<KMaxMessageLength> templ;
   868 				TBuf<KMaxMessageLength> templ;
   929 				iEikonEnv->ReadResourceL(templ, R_IMPORT_FEED_SUCCESS);
   869 				iEikonEnv->ReadResourceL(templ, R_IMPORT_FEED_SUCCESS);
   930 				message.Format(templ, aNumFeedsImported);
   870 				message.Format(templ, aNumFeedsImported);
   931 				
   871 				
   932 				if(ShowQueryMessage(message))
   872 				if(ShowQueryMessageL(message))
   933 					{
   873 					{
   934 					HandleCommandL(EPodcastUpdateAllFeeds);
   874 					HandleCommandL(EPodcastUpdateAllFeeds);
   935 					}
   875 					}
   936 				}
   876 				}
   937 				break;
   877 				break;
   938 			case EOpmlSearching:
   878 			case EOpmlSearching:
   939 				delete iWaitDialog;
   879 				delete iWaitDialog;
       
   880 				iWaitDialog = NULL;
   940 				if (iPodcastModel.FeedEngine().GetSearchResults().Count() == 0)
   881 				if (iPodcastModel.FeedEngine().GetSearchResults().Count() == 0)
   941 					{
   882 					{
   942 					TBuf<KMaxMessageLength> message;
   883 					TBuf<KMaxMessageLength> message;
   943 					iEikonEnv->ReadResourceL(message, R_SEARCH_NORESULTS);
   884 					iEikonEnv->ReadResourceL(message, R_SEARCH_NORESULTS);
   944 					ShowErrorMessage(message);
   885 					ShowErrorMessageL(message);
   945 					}
   886 					}
   946 				else
   887 				else
   947 					{
   888 					{
   948 					AppUi()->ActivateLocalViewL(KUidPodcastSearchViewID,  TUid::Uid(0), KNullDesC8());
   889 					AppUi()->ActivateLocalViewL(KUidPodcastSearchViewID,  TUid::Uid(0), KNullDesC8());
   949 					}
   890 					}
   962 	iPodcastModel.FeedEngine().CancelUpdateAllFeeds();
   903 	iPodcastModel.FeedEngine().CancelUpdateAllFeeds();
   963 	}
   904 	}
   964 
   905 
   965 void CPodcastFeedView::GetFeedErrorText(TDes &aErrorMessage, TInt aErrorCode)
   906 void CPodcastFeedView::GetFeedErrorText(TDes &aErrorMessage, TInt aErrorCode)
   966 	{
   907 	{
   967 	iEikonEnv->GetErrorText(aErrorMessage, aErrorCode);
   908 	TRAP_IGNORE(((CPodcastAppUi*)AppUi())->GetErrorTextL(aErrorMessage,aErrorCode));
   968 	}
   909 	}
   969 
   910 
   970 void CPodcastFeedView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /* aPenEventScreenLocation */)
   911 void CPodcastFeedView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /* aPenEventScreenLocation */)
   971 {
   912 {
   972 	DP("CPodcastListView::HandleLongTapEventL BEGIN");
   913 	DP("CPodcastListView::HandleLongTapEventL BEGIN");
   973 
   914 
   974 	if (iUpdatingAllRunning) {
   915 	iListContainer->SetLongTapDetectedL(ETrue);
   975 		return; // we don't allow feed manipulation while update is running
       
   976 	}
       
   977 
       
   978 	iListContainer->SetLongTapDetected(ETrue);
       
   979 
   916 
   980 	const TInt KListboxDefaultHeight = 19; // for some reason it returns 19 for an empty listbox in S^1
   917 	const TInt KListboxDefaultHeight = 19; // for some reason it returns 19 for an empty listbox in S^1
   981 	TInt lbHeight = iListContainer->Listbox()->CalcHeightBasedOnNumOfItems(
   918 	TInt lbHeight = iListContainer->Listbox()->CalcHeightBasedOnNumOfItems(
   982 			iListContainer->Listbox()->Model()->NumberOfItems()) - KListboxDefaultHeight;
   919 			iListContainer->Listbox()->Model()->NumberOfItems()) - KListboxDefaultHeight;
   983 
   920 
   986 		iStylusPopupMenu->ShowMenu();
   923 		iStylusPopupMenu->ShowMenu();
   987 		iStylusPopupMenu->SetPosition(aPenEventLocation);
   924 		iStylusPopupMenu->SetPosition(aPenEventLocation);
   988     }
   925     }
   989 	DP("CPodcastListView::HandleLongTapEventL END");
   926 	DP("CPodcastListView::HandleLongTapEventL END");
   990 }
   927 }
       
   928 
       
   929 TBool CPodcastFeedView::ViewingShows()
       
   930 	{
       
   931 	return iViewingShows;
       
   932 	}