application/src/PodcastFeedView.cpp
changeset 74 af6475fdf8d6
parent 69 04c6ccce8e7e
child 76 223f270fa7ff
equal deleted inserted replaced
73:83752b9e3cb6 74:af6475fdf8d6
    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 
    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;
   741 		}
   741 		}
   742 	}
   742 	}
   743 
   743 
   744 void CPodcastFeedView::HandleImportFeedsL()
   744 void CPodcastFeedView::HandleImportFeedsL()
   745 	{
   745 	{
   746 	CAknMemorySelectionDialog* memDlg = 
   746 	TFileName fileName;
   747 		CAknMemorySelectionDialog::NewL(ECFDDialogTypeNormal, ETrue);
   747 	fileName.Zero();
   748 	CleanupStack::PushL(memDlg);
   748 	TFileName startFolder;
   749 	CAknMemorySelectionDialog::TMemory memory = 
   749 	startFolder.Zero();
   750 		CAknMemorySelectionDialog::EPhoneMemory;
   750 	TInt types = AknCommonDialogsDynMem::EMemoryTypePhone | AknCommonDialogsDynMem::EMemoryTypeMMC |AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage| AknCommonDialogsDynMem::EMemoryTypeRemote;
   751 
   751 	
   752 	if (memDlg->ExecuteL(memory))
   752 	HBufC *title = iCoeEnv->AllocReadResourceLC(R_PODCAST_SELECT_OPML);
   753 		{
   753 	if (AknCommonDialogsDynMem::RunSelectDlgLD (types, fileName,
   754 		TFileName importName;
   754 			startFolder, NULL, NULL, *title))
   755 	
   755 		{
   756 		if (memory==CAknMemorySelectionDialog::EMemoryCard)
       
   757 		{
       
   758 			importName = PathInfo:: MemoryCardRootPath();
       
   759 		}
       
   760 		else
       
   761 		{
       
   762 			importName = PathInfo:: PhoneMemoryRootPath();
       
   763 		}
       
   764 
       
   765 		CAknFileSelectionDialog* dlg = CAknFileSelectionDialog::NewL(ECFDDialogTypeNormal, R_PODCAST_IMPORT_PODCAST);
       
   766 		CleanupStack::PushL(dlg);
       
   767 
       
   768 		dlg->SetDefaultFolderL(importName);
       
   769 		
   756 		
   770 		if(dlg->ExecuteL(importName))
   757 		if(fileName.Length()>0)
   771 			{
   758 			{
   772 			if(importName.Length()>0)
   759 			HBufC *waitText = iEikonEnv->AllocReadResourceLC(R_IMPORTING);
   773 				{
   760 			iOpmlState = EOpmlImporting;
   774 				HBufC *waitText = iEikonEnv->AllocReadResourceLC(R_IMPORTING);
   761 			ShowWaitDialogL(*waitText);
   775 				iOpmlState = EOpmlImporting;
   762 			CleanupStack::PopAndDestroy(waitText);	
   776 				ShowWaitDialogL(*waitText);
   763 
   777 				CleanupStack::PopAndDestroy(waitText);	
   764 			TRAPD(err, iPodcastModel.FeedEngine().ImportFeedsL(fileName));
   778 
   765 								
   779 				TRAPD(err, iPodcastModel.FeedEngine().ImportFeedsL(importName));
   766 			if (err != KErrNone) {
   780 									
   767 				TBuf<KMaxMessageLength> message;
   781 				if (err != KErrNone) {
   768 				iEikonEnv->ReadResourceL(message, R_IMPORT_FEED_FAILURE);
   782 					TBuf<KMaxMessageLength> message;
   769 				ShowErrorMessageL(message);
   783 					iEikonEnv->ReadResourceL(message, R_IMPORT_FEED_FAILURE);
   770 				}
   784 					ShowErrorMessageL(message);
   771 			}
   785 					}
   772 
   786 				}
   773 		}
   787 				
   774 	CleanupStack::PopAndDestroy(title);
   788 			}
       
   789 		CleanupStack::PopAndDestroy(dlg);
       
   790 		}
       
   791 	CleanupStack::PopAndDestroy(memDlg);
       
   792 	}
   775 	}
   793 
   776 
   794 void CPodcastFeedView::HandleExportFeedsL()
   777 void CPodcastFeedView::HandleExportFeedsL()
   795 	{
   778 	{
   796 	CAknMemorySelectionDialog* memDlg = 
   779 	TFileName fileName;
   797 		CAknMemorySelectionDialog::NewL(ECFDDialogTypeSave, ETrue);
   780 	fileName.Copy(_L("feeds.opml"));
   798 	CleanupStack::PushL(memDlg);
   781 	TFileName startFolder;
   799 	CAknMemorySelectionDialog::TMemory memory = 
   782 	startFolder.Zero();
   800 		CAknMemorySelectionDialog::EPhoneMemory;
   783 	TInt types = AknCommonDialogsDynMem::EMemoryTypePhone | AknCommonDialogsDynMem::EMemoryTypeMMC |AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage| AknCommonDialogsDynMem::EMemoryTypeRemote;
   801 
   784 	
   802 	if (memDlg->ExecuteL(memory))
   785 	HBufC *title = iCoeEnv->AllocReadResourceLC(R_PODCAST_SELECT_FOLDER);
   803 		{
   786 	if (AknCommonDialogsDynMem::RunSaveDlgLD (types, fileName,
   804 		TFileName pathName;
   787 			startFolder, NULL, NULL, *title))
   805 		
   788 		{
   806 		if (memory==CAknMemorySelectionDialog::EMemoryCard)
   789 			TFileName temp;
   807 		{
   790 			TRAPD(err, iPodcastModel.FeedEngine().ExportFeedsL(temp));						
   808 			pathName = PathInfo::MemoryCardRootPath();
   791 			BaflUtils::CopyFile(iEikonEnv->FsSession(), temp, fileName);
   809 		}
   792 			BaflUtils::DeleteFile(iEikonEnv->FsSession(),temp);	
   810 		else
   793 			if (err == KErrNone) 
   811 		{
   794 				{
   812 			pathName = PathInfo::PhoneMemoryRootPath();
   795 				UpdateListboxItemsL();
   813 		}
   796 				TInt numFeeds = iPodcastModel.FeedEngine().GetSortedFeeds().Count();
   814 
       
   815 		CAknFileSelectionDialog* dlg = CAknFileSelectionDialog::NewL(ECFDDialogTypeSave, R_PODCAST_EXPORT_FEEDS);
       
   816 		CleanupStack::PushL(dlg);
       
   817 								
   797 								
   818 		if(dlg->ExecuteL(pathName))
   798 				TBuf<KMaxMessageLength> message;
   819 			{
   799 				TBuf<KMaxMessageLength> templ;
   820 			CAknFileNamePromptDialog *fileDlg = CAknFileNamePromptDialog::NewL(R_PODCAST_FILENAME_PROMPT_DIALOG);
   800 				iEikonEnv->ReadResourceL(templ, R_EXPORT_FEED_SUCCESS);
   821 			CleanupStack::PushL(fileDlg);
   801 				message.Format(templ, numFeeds);
   822 			fileDlg->SetPathL(pathName);
   802 				ShowOkMessageL(message);
   823 			TFileName fileName;
   803 				} 
   824 			if (fileDlg->ExecuteL(fileName) && fileName.Length() > 0)
   804 			else 
   825 				{
   805 				{
   826 				pathName.Append(fileName);
   806 				TBuf<KMaxMessageLength> message;
   827 				TFileName temp;
   807 				iEikonEnv->ReadResourceL(message, R_EXPORT_FEED_FAILURE);
   828 				TRAPD(err, iPodcastModel.FeedEngine().ExportFeedsL(temp));						
   808 				ShowErrorMessageL(message);
   829 				BaflUtils::CopyFile(iEikonEnv->FsSession(), temp, pathName);
   809 				}
   830 				BaflUtils::DeleteFile(iEikonEnv->FsSession(),temp);	
   810 		}
   831 				if (err == KErrNone) 
   811 	CleanupStack::PopAndDestroy(title);
   832 					{
       
   833 					UpdateListboxItemsL();
       
   834 					TInt numFeeds = iPodcastModel.FeedEngine().GetSortedFeeds().Count();
       
   835 									
       
   836 					TBuf<KMaxMessageLength> message;
       
   837 					TBuf<KMaxMessageLength> templ;
       
   838 					iEikonEnv->ReadResourceL(templ, R_EXPORT_FEED_SUCCESS);
       
   839 					message.Format(templ, numFeeds);
       
   840 					ShowOkMessageL(message);
       
   841 					} 
       
   842 				else 
       
   843 					{
       
   844 					TBuf<KMaxMessageLength> message;
       
   845 					iEikonEnv->ReadResourceL(message, R_EXPORT_FEED_FAILURE);
       
   846 					ShowErrorMessageL(message);
       
   847 					}
       
   848 				}
       
   849 			CleanupStack::PopAndDestroy(fileDlg);
       
   850 			}
       
   851 		CleanupStack::PopAndDestroy(dlg);
       
   852 	}
       
   853 	CleanupStack::PopAndDestroy(memDlg);									
       
   854 	}
   812 	}
   855 
   813 
   856 void CPodcastFeedView::CheckResumeDownloadL()
   814 void CPodcastFeedView::CheckResumeDownloadL()
   857 	{
   815 	{
   858 	// if there are shows queued for downloading, ask if we should resume now
   816 	// if there are shows queued for downloading, ask if we should resume now
   946 	iPodcastModel.FeedEngine().CancelUpdateAllFeeds();
   904 	iPodcastModel.FeedEngine().CancelUpdateAllFeeds();
   947 	}
   905 	}
   948 
   906 
   949 void CPodcastFeedView::GetFeedErrorText(TDes &aErrorMessage, TInt aErrorCode)
   907 void CPodcastFeedView::GetFeedErrorText(TDes &aErrorMessage, TInt aErrorCode)
   950 	{
   908 	{
   951 	iEikonEnv->GetErrorText(aErrorMessage, aErrorCode);
   909 	switch (aErrorCode)
       
   910 		{
       
   911 		case -1:
       
   912 			{
       
   913 			HBufC* error = iCoeEnv->AllocReadResourceLC(R_ERROR_INVALID_ADDRESS);
       
   914 			aErrorMessage.Copy(*error);
       
   915 			CleanupStack::PopAndDestroy(error);
       
   916 			}
       
   917 			break;
       
   918 		case 404:
       
   919 			{
       
   920 			HBufC* error = iCoeEnv->AllocReadResourceLC(R_ERROR_NOTFOUND);
       
   921 			aErrorMessage.Copy(*error);
       
   922 			CleanupStack::PopAndDestroy(error);
       
   923 			}
       
   924 			break;
       
   925 		default:
       
   926 			{
       
   927 			if (aErrorCode > 200)
       
   928 				{
       
   929 				HBufC* error = iCoeEnv->AllocReadResourceLC(R_ERROR_HTTP);
       
   930 				aErrorMessage.Format(*error, aErrorCode);
       
   931 				CleanupStack::PopAndDestroy(error);
       
   932 				}
       
   933 			else
       
   934 				{
       
   935 				HBufC* error = iCoeEnv->AllocReadResourceLC(R_ERROR_GENERAL);
       
   936 				aErrorMessage.Format(*error, aErrorCode);
       
   937 				CleanupStack::PopAndDestroy(error);
       
   938 				}
       
   939 			}
       
   940 			break;
       
   941 		}
   952 	}
   942 	}
   953 
   943 
   954 void CPodcastFeedView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /* aPenEventScreenLocation */)
   944 void CPodcastFeedView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /* aPenEventScreenLocation */)
   955 {
   945 {
   956 	DP("CPodcastListView::HandleLongTapEventL BEGIN");
   946 	DP("CPodcastListView::HandleLongTapEventL BEGIN");