application/src/PodcastSettingsView.cpp
branch3rded
changeset 177 269e3f3e544a
parent 176 1c8b56cb6409
child 390 d7abecc9d189
--- a/application/src/PodcastSettingsView.cpp	Sat Jul 10 13:35:21 2010 +0100
+++ b/application/src/PodcastSettingsView.cpp	Sun Jul 11 11:36:24 2010 +0100
@@ -24,8 +24,8 @@
 #include <aknnavide.h> 
 #include <podcast.rsg>
 #include "SettingsEngine.h"
-
-//#include <akncommondialogsdynmem.h> 
+#include <caknfileselectiondialog.h> 
+#include <caknmemoryselectiondialog.h> 
 #include <pathinfo.h>
 #include <aknquerydialog.h>
 
@@ -46,36 +46,36 @@
 		{	
 		CArrayPtr< CAknEnumeratedText > * enumeratedArr = EnumeratedTextArray();
 		CArrayPtr< HBufC > * poppedUpTextArray = PoppedUpTextArray();
-		enumeratedArr->ResetAndDestroy();
-		poppedUpTextArray->ResetAndDestroy();		
 			
 		CDesCArrayFlat *iapArray = iPodcastModel.IAPNames();
 
 		TBool valueExists = EFalse;
 		DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
 		for (int i=0;i<iapArray->Count();i++) {
-		HBufC *buf = (*iapArray)[i].AllocL();
-		poppedUpTextArray->AppendL(buf);
-
-		TInt iapId = iPodcastModel.IAPIds()[i].iIapId;
-		DP2("IAP name='%S', id=%d", buf, iapId);
-
-		if (iapId == ExternalValue()) {
-		valueExists = ETrue;
-		}
-		// both arrays destroy themselves, so we need two copies to prevent USER 44
-		HBufC *buf2 = (*iapArray)[i].AllocL();
-
-		CAknEnumeratedText *enumerated = new CAknEnumeratedText(iapId, buf2);
-		enumeratedArr->AppendL(enumerated);
+			HBufC *buf = (*iapArray)[i].AllocL();
+			poppedUpTextArray->AppendL(buf);
+	
+			TInt iapId = iPodcastModel.IAPIds()[i].iIapId;
+			DP2("IAP name='%S', id=%d", buf, iapId);
+	
+			if (iapId == ExternalValue() || ExternalValue() == 0 || ExternalValue() == -1)
+				{
+				valueExists = ETrue;
+				}
+			
+			// both arrays destroy themselves, so we need two copies to prevent USER 44
+			HBufC *buf2 = (*iapArray)[i].AllocL();
+	
+			CAknEnumeratedText *enumerated = new CAknEnumeratedText(iapId, buf2);
+			enumeratedArr->AppendL(enumerated);
 		}
 
 		DP1("valueExists=%d", valueExists);
 		if (!valueExists && iPodcastModel.IAPIds().Count() > 0 ) {
-		DP1("Setting iIap=%d", iPodcastModel.IAPIds()[0].iIapId);
-		iIap = iPodcastModel.IAPIds()[0].iIapId;
-		LoadL();
-		DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
+			DP1("Setting iIap=%d", iPodcastModel.IAPIds()[0].iIapId);
+			iIap = iPodcastModel.IAPIds()[0].iIapId;
+			LoadL();
+			DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
 		}
 
 		TRAPD(err, HandleTextArrayUpdateL());
@@ -121,91 +121,91 @@
 };
 
 
-class CConnectionSetting: public CAknEnumeratedTextPopupSettingItem 
-{ 
-public:
-	CConnectionSetting(TInt aResourceId, TInt& aValue, CPodcastModel &aPodcastModel) :
-		CAknEnumeratedTextPopupSettingItem(aResourceId, aValue), iPodcastModel(aPodcastModel)
-		{
-		}
-
-	~CConnectionSetting()
-		{
-		}
-
-	void RefreshConnectionListL()
-		{	
-		CArrayPtr< CAknEnumeratedText > * enumeratedArr = EnumeratedTextArray();
-		CArrayPtr< HBufC > * poppedUpTextArray = PoppedUpTextArray();						
-			
-		CDesCArrayFlat *snapArray = iPodcastModel.SNAPNames();
-
-		TBool valueExists = EFalse;
-		DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
-		for (int i=0;i<snapArray->Count();i++) {
-			HBufC *buf = (*snapArray)[i].AllocL();
-			poppedUpTextArray->InsertL(EConnectionUseNetwork+i,buf);
-
-			TInt snapId = iPodcastModel.SNAPIds()[i].iIapId;
-			DP2("SNAP name='%S', id=%d", buf, snapId);
-	
-			if (snapId == ExternalValue()) {
-			valueExists = ETrue;
-		}
-		// both arrays destroy themselves, so we need two copies to prevent USER 44
-		HBufC *buf2 = (*snapArray)[i].AllocL();
-
-		CAknEnumeratedText *enumerated = new CAknEnumeratedText(EConnectionUseNetwork+i, buf2);
-		enumeratedArr->InsertL(EConnectionUseNetwork+i, enumerated);
-		}
-
-		DP1("valueExists=%d", valueExists);
-		if (!valueExists && iPodcastModel.SNAPIds().Count() > 0 ) {
-		DP1("Setting i=%d", iPodcastModel.SNAPIds()[0].iIapId);	
-		LoadL();
-		DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
-		}
-
-		TRAPD(err, HandleTextArrayUpdateL());
-
-		if (err != KErrNone) {
-		DP1("Leave in HandleTextArrayUpdateL, err=%d", err);
-		}
-		}
-
-	void CompleteConstructionL()
-		{
-		DP("CIapSetting::CompleteConstructionL BEGIN");
-		CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();
-		RefreshConnectionListL();
-		DP("CIapSetting::CompleteConstructionL END");
-		}
-
-	void EditItemL(TBool aCalledFromMenu)
-		{
-		DP("CIapSetting::EditItemL BEGIN");
-		LoadL();
-		CAknEnumeratedTextPopupSettingItem::EditItemL(aCalledFromMenu);
-		StoreL();		
-		DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
-		DP("CIapSetting::EditItemL END");
-		}
-
-	void HandleSettingPageEventL(CAknSettingPage* aSettingPage, TAknSettingPageEvent aEventType)
-		{
-		DP("CIapSetting::HandleSettingPageEventL BEGIN");
-		CAknSettingItem::HandleSettingPageEventL(aSettingPage, aEventType);
-		/*if (aEventType == EEventSettingOked) 
-			{
-			DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
-			StoreL();
-			}*/
-		DP("CIapSetting::HandleSettingPageEventL END");
-		}
-
-protected:
-  	CPodcastModel& iPodcastModel;  
-};
+//class CConnectionSetting: public CAknEnumeratedTextPopupSettingItem 
+//{ 
+//public:
+//	CConnectionSetting(TInt aResourceId, TInt& aValue, CPodcastModel &aPodcastModel) :
+//		CAknEnumeratedTextPopupSettingItem(aResourceId, aValue), iPodcastModel(aPodcastModel)
+//		{
+//		}
+//
+//	~CConnectionSetting()
+//		{
+//		}
+//
+//	void RefreshConnectionListL()
+//		{	
+//		CArrayPtr< CAknEnumeratedText > * enumeratedArr = EnumeratedTextArray();
+//		CArrayPtr< HBufC > * poppedUpTextArray = PoppedUpTextArray();						
+//			
+//		CDesCArrayFlat *snapArray = iPodcastModel.SNAPNames();
+//
+//		TBool valueExists = EFalse;
+//		DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
+//		for (int i=0;i<snapArray->Count();i++) {
+//			HBufC *buf = (*snapArray)[i].AllocL();
+//			poppedUpTextArray->InsertL(EConnectionUseNetwork+i,buf);
+//
+//			TInt snapId = iPodcastModel.SNAPIds()[i].iIapId;
+//			DP2("SNAP name='%S', id=%d", buf, snapId);
+//	
+//			if (snapId == ExternalValue()) {
+//			valueExists = ETrue;
+//		}
+//		// both arrays destroy themselves, so we need two copies to prevent USER 44
+//		HBufC *buf2 = (*snapArray)[i].AllocL();
+//
+//		CAknEnumeratedText *enumerated = new CAknEnumeratedText(EConnectionUseNetwork+i, buf2);
+//		enumeratedArr->InsertL(EConnectionUseNetwork+i, enumerated);
+//		}
+//
+//		DP1("valueExists=%d", valueExists);
+//		if (!valueExists && iPodcastModel.SNAPIds().Count() > 0 ) {
+//		DP1("Setting i=%d", iPodcastModel.SNAPIds()[0].iIapId);	
+//		LoadL();
+//		DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
+//		}
+//
+//		TRAPD(err, HandleTextArrayUpdateL());
+//
+//		if (err != KErrNone) {
+//		DP1("Leave in HandleTextArrayUpdateL, err=%d", err);
+//		}
+//		}
+//
+//	void CompleteConstructionL()
+//		{
+//		DP("CIapSetting::CompleteConstructionL BEGIN");
+//		CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();
+//		RefreshConnectionListL();
+//		DP("CIapSetting::CompleteConstructionL END");
+//		}
+//
+//	void EditItemL(TBool aCalledFromMenu)
+//		{
+//		DP("CIapSetting::EditItemL BEGIN");
+//		LoadL();
+//		CAknEnumeratedTextPopupSettingItem::EditItemL(aCalledFromMenu);
+//		StoreL();		
+//		DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
+//		DP("CIapSetting::EditItemL END");
+//		}
+//
+//	void HandleSettingPageEventL(CAknSettingPage* aSettingPage, TAknSettingPageEvent aEventType)
+//		{
+//		DP("CIapSetting::HandleSettingPageEventL BEGIN");
+//		CAknSettingItem::HandleSettingPageEventL(aSettingPage, aEventType);
+//		/*if (aEventType == EEventSettingOked) 
+//			{
+//			DP2("InternalValue=%d, ExternalValue=%d", InternalValue(), ExternalValue());
+//			StoreL();
+//			}*/
+//		DP("CIapSetting::HandleSettingPageEventL END");
+//		}
+//
+//protected:
+//  	CPodcastModel& iPodcastModel;  
+//};
 
 class CPodcastSettingItemList:public CAknSettingItemList
 	{
@@ -226,33 +226,8 @@
 		se.SetBaseDir(iShowDir);
 		DP1("Base Dir: %S", &iShowDir);
 		se.SetUpdateAutomatically((TAutoUpdateSetting)iAutoUpdate);
-		DP1("Update automatically: %d", iAutoUpdate);		
-		switch(iConnection)
-			{
-			case EConnectionDefault:
-				{
-				DP("Specific IAP: 0 Ask user");
-				se.SetSpecificIAP(0);	
-				}break;
-			case EConnectionAlwaysAsk:
-				{
-				DP("Specific IAP: -1 Ask user");
-				se.SetSpecificIAP(-1);		
-				}break;
-			
-			case EConnectionUseIap:
-				{		
-				DP1("Specific NETWORK: %d", iIap);		
-				se.SetSpecificIAP((iIap|KUseIAPFlag));	
-				}break;
-			default:
-			case EConnectionUseNetwork:
-				{
-				DP1("Specific IAP: %d", iIap);		
-				TInt snapIndex = iConnection-EConnectionUseNetwork;
-				se.SetSpecificIAP(iPodcastModel.SNAPIds()[snapIndex].iIapId);	
-				}break;
-			}		
+		DP1("Update automatically: %d", iAutoUpdate);
+		se.SetSpecificIAP(iIap);	
 		
 		DP1("Download automatically: %d", iAutoDownload);
 		se.SetDownloadAutomatically(iAutoDownload);
@@ -270,15 +245,15 @@
 		{
 		DP("UpdateSettingVisibility BEGIN");
 		LoadSettingsL();
-		TBool dimAutoUpdate = iConnection == EConnectionAlwaysAsk;
-		TBool dimIAP = iConnection < EConnectionUseIap;
+		TBool dimAutoUpdate = iIap == EConnectionAlwaysAsk;
+//		TBool dimIAP = EFalse; //iConnection < EConnectionUseIap;
 	
 		iSettingAutoUpdate->SetHidden(dimAutoUpdate);
-		iSettingIAP->SetHidden(dimIAP);
-		if(!dimIAP)
-			{
-			iSettingIAP->RefreshConnectionListL();
-			}
+//		iSettingIAP->SetHidden(dimIAP);
+//		if(!dimIAP)
+//			{
+//			iSettingIAP->RefreshConnectionListL();
+//			}
 		ListBox()->ScrollToMakeItemVisible(0);
 		
 		TRAP_IGNORE(HandleChangeInItemArrayOrVisibilityL());
@@ -287,41 +262,49 @@
 
 	void  EditItemL (TInt aIndex, TBool aCalledFromMenu)
 		{
-		DP("EditItemL BEGIN");
-//		if (aIndex == 0) {
-//			TFileName selectedFolder;
-//			selectedFolder.Copy(iShowDir);
-//			TFileName startFolder;
-//			startFolder.Zero();
-//			TInt types = AknCommonDialogsDynMem::EMemoryTypePhone | AknCommonDialogsDynMem::EMemoryTypeMMC |AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage| AknCommonDialogsDynMem::EMemoryTypeRemote;
-//			
-//			HBufC *title = iCoeEnv->AllocReadResourceLC(R_PODCAST_SELECT_FOLDER);
-//			if (AknCommonDialogsDynMem::RunFolderSelectDlgLD (types, selectedFolder,
-//					startFolder, NULL, NULL, *title))
-//				{
-//				_LIT(KPodcastsDir, "Podcasts");
-//				TInt pos = selectedFolder.Find(KPodcastsDir);
-//				if (pos == KErrNotFound || pos != selectedFolder.Length()-9)
-//					{
-//					// append "Podcasts" if the folder isn't already called this
-//					selectedFolder.Append(KPodcastsDir);
-//					}
-//				
-//				if (selectedFolder[selectedFolder.Length()-1] != '\\')
-//					{
-//					selectedFolder.Append(_L("\\"));
-//					}
-//				
-//				iShowDir.Copy(selectedFolder);
-//				LoadSettingsL();
-//				}
-//			CleanupStack::PopAndDestroy(title);
-//			}
-//		else {
-//			CAknSettingItemList::EditItemL(aIndex,aCalledFromMenu);
-//		}
-//			StoreSettingsL();
-//			UpdateSettingVisibility();
+		if (aIndex == 0) {
+			CAknMemorySelectionDialog* memDlg = 
+				CAknMemorySelectionDialog::NewL(ECFDDialogTypeNormal, ETrue);
+			CleanupStack::PushL(memDlg);
+			CAknMemorySelectionDialog::TMemory memory = 
+				CAknMemorySelectionDialog::EPhoneMemory;
+	
+			if (memDlg->ExecuteL(memory))
+				{
+				TFileName importName;
+			
+				if (memory==CAknMemorySelectionDialog::EMemoryCard)
+				{
+					importName = PathInfo:: MemoryCardRootPath();
+				}
+				else
+				{
+					importName = PathInfo:: PhoneMemoryRootPath();
+				}
+	
+				CAknFileSelectionDialog* dlg = CAknFileSelectionDialog::NewL(ECFDDialogTypeSave, R_PODCAST_SHOWDIR_SELECTOR);
+				HBufC* select = iEikonEnv->AllocReadResourceLC(R_PODCAST_SOFTKEY_SELECT);
+				dlg->SetLeftSoftkeyFileL(*select);
+				CleanupStack::PopAndDestroy(select);
+				CleanupStack::PushL(dlg);
+	
+				dlg->SetDefaultFolderL(importName);
+				
+				if(dlg->ExecuteL(importName))
+					{
+					importName.Append(_L("Podcasts"));
+					iShowDir.Copy(importName);
+					LoadSettingsL();
+					}
+				CleanupStack::PopAndDestroy(dlg);
+				}
+			CleanupStack::PopAndDestroy(memDlg);								
+			}
+		else {
+			CAknSettingItemList::EditItemL(aIndex,aCalledFromMenu);
+		}
+				StoreSettingsL();
+			UpdateSettingVisibility();
 		DP("EditItemL END");
 		}
 	
@@ -342,37 +325,37 @@
 		iAutoUpdate = se.UpdateAutomatically();
 		iIap = se.SpecificIAP();
 		
-		if( iIap == 0)
-			{
-			iConnection = EConnectionDefault;
-			}
-		else if ( iIap == -1)
-			{
-			iConnection = EConnectionAlwaysAsk;	
-			}
-		else if ( (iIap & KUseIAPFlag))
-			{
-			iConnection = EConnectionUseIap;
-			iIap = iIap& KUseIAPMask;
-			}
-		else
-			{
-			TInt snapIndex = 0;
-			TInt cnt = iPodcastModel.SNAPIds().Count();
-			while(snapIndex < cnt && ((TInt)iPodcastModel.SNAPIds()[snapIndex].iIapId) != iIap)
-				{
-				snapIndex++;
-				}
-			
-			if(snapIndex != cnt)
-				{
-				iConnection = EConnectionUseNetwork+snapIndex;
-				}
-			else
-				{
-				iConnection = EConnectionAlwaysAsk;
-				}
-			}
+//		if( iIap == 0)
+//			{
+//			iConnection = EConnectionDefault;
+//			}
+//		else if ( iIap == -1)
+//			{
+//			iConnection = EConnectionAlwaysAsk;	
+//			}
+//		else if ( (iIap & KUseIAPFlag))
+//			{
+//			iConnection = EConnectionUseIap;
+//			iIap = iIap& KUseIAPMask;
+//			}
+//		else
+//			{
+//			TInt snapIndex = 0;
+//			TInt cnt = iPodcastModel.SNAPIds().Count();
+//			while(snapIndex < cnt && ((TInt)iPodcastModel.SNAPIds()[snapIndex].iIapId) != iIap)
+//				{
+//				snapIndex++;
+//				}
+//			
+//			if(snapIndex != cnt)
+//				{
+//				iConnection = EConnectionUseI+snapIndex;
+//				}
+//			else
+//				{
+//				iConnection = EConnectionAlwaysAsk;
+//				}
+//			}
 									
 		iAutoDownload = se.DownloadAutomatically();
 			
@@ -387,10 +370,10 @@
 				iSettingAutoUpdate = new (ELeave) CAknEnumeratedTextPopupSettingItem(aSettingId, iAutoUpdate);
 				return iSettingAutoUpdate;
 				break;
-			case EPodcastSettingConnection:
-				DP("EPodcastSettingConnection");
-				return new (ELeave) CConnectionSetting (aSettingId, iConnection, iPodcastModel);
-				break;
+//			case EPodcastSettingConnection:
+//				DP("EPodcastSettingConnection");
+//				return new (ELeave) CConnectionSetting (aSettingId, iConnection, iPodcastModel);
+//				break;
 			case EPodcastSettingIAPList:
 				DP("EPodcastSettingIAPList");
 				iSettingIAP = new (ELeave) CIapSetting (aSettingId, iIap, iPodcastModel);
@@ -417,7 +400,7 @@
 	TInt iAutoDownload;
 	CAknSettingItem *iSettingAutoDownload; 
 
-	TInt iConnection;
+//	TInt iConnection;
 	
 	TInt iIap;
 	CIapSetting *iSettingIAP;