Dual listbox solution now mostly works twolistboxes
authorSebastian Brannstrom <sebastianb@symbian.org>
Sun, 31 Oct 2010 12:16:04 +0000
branchtwolistboxes
changeset 314 e7776f6a2198
parent 313 0f30a75610de
child 315 091fa3bf3295
Dual listbox solution now mostly works
application/inc/PodcastFeedView.h
application/inc/PodcastListView.h
application/src/PodcastFeedView.cpp
application/src/PodcastListView.cpp
application/src/PodcastQueueView.cpp
application/src/PodcastSearchView.cpp
application/src/PodcastShowsView.cpp
--- a/application/inc/PodcastFeedView.h	Sun Oct 31 10:35:57 2010 +0000
+++ b/application/inc/PodcastFeedView.h	Sun Oct 31 12:16:04 2010 +0000
@@ -113,7 +113,7 @@
 		void HandleUpdateFeedL();
 		void GetFeedErrorText(TDes &aErrorMessage, TInt aErrorCode);
 		void OpmlParsingCompleteL(TInt aError, TUint aNumFeedsImported);
-		
+		void LoadIcons();
 	private:
 		CPodcastModel& iPodcastModel;		
 		TUint iFeedUpdating;
--- a/application/inc/PodcastListView.h	Sun Oct 31 10:35:57 2010 +0000
+++ b/application/inc/PodcastListView.h	Sun Oct 31 12:16:04 2010 +0000
@@ -77,6 +77,7 @@
         CAknDoubleLargeStyleListBox * iListboxPortrait;
         CEikColumnListBox * iListbox;
         TBool iLandscape;
+		CDesCArray* iItemArrayShort;
 	};
 
 
--- a/application/src/PodcastFeedView.cpp	Sun Oct 31 10:35:57 2010 +0000
+++ b/application/src/PodcastFeedView.cpp	Sun Oct 31 12:16:04 2010 +0000
@@ -67,6 +67,12 @@
 	{
 	DP("CPodcastFeedView::SizeChanged BEGIN");
 	iListContainer->Listbox()->SetListBoxObserver(this);
+	iListContainer->DrawNow();
+	DP("CPodcastFeedView::SizeChanged END");
+	}
+
+void CPodcastFeedView::LoadIcons()
+	{
 	iFeedIdForIconArray.Reset();
 	iItemArray->Reset();
 	
@@ -99,12 +105,6 @@
 	CleanupStack::Pop(2); // bitmap, mask
 	iListContainer->SetListboxIcons(iIconArray);
 	CleanupStack::Pop(iIconArray); // icons
-	
-	UpdateListboxItemsL();
-	iListContainer->SetTextArray(iItemArray);
-	iListContainer->SetListboxIcons(iIconArray);
-	iListContainer->Listbox()->DrawNow();
-	DP("CPodcastFeedView::SizeChanged END");
 	}
 
 CPodcastFeedView::CPodcastFeedView(CPodcastModel& aPodcastModel):iPodcastModel(aPodcastModel)
@@ -122,34 +122,8 @@
 	CPodcastListView::ConstructL();
 	iPodcastModel.FeedEngine().AddObserver(this);
 	SetEmptyTextL(R_PODCAST_NO_FEEDS);
-	SizeChanged();
-//	CFbsBitmap* bitmap = NULL;
-//	CFbsBitmap* mask = NULL;
-//	// Load the bitmap for empty icon	
-//	TFileName fname = KAsterisk;
-//	TParsePtr parser(fname);
 
-//	
-//	// Load svg.-image and mask with a single call
-//		AknIconUtils::CreateIconL(bitmap,
-//		                          mask,
-//		                          iEikonEnv->EikAppUi()->Application()->BitmapStoreName(),
-//		                          EMbmPodcastFeed,
-//		                          EMbmPodcastFeed_mask);
-//	    
-//	/*bitmap = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40);
-//	 * */
-//	CleanupStack::PushL( bitmap );		
-//	// Load the mask for feed icon	
-//	//mask = iEikonEnv->CreateBitmapL(KAsterisk,EMbmPodcastFeed_40x40m );	
-//	CleanupStack::PushL( mask );
-//	// Append the feed icon to icon array
-//	iIconArray->AppendL( CGulIcon::NewL( bitmap, mask ) );
-//	CleanupStack::Pop(2); // bitmap, mask
-//	iListContainer->SetListboxIcons(iIconArray);
-//	CleanupStack::Pop(iIconArray); // icons
-//
-//	iListContainer->Listbox()->SetListBoxObserver(this);
+	LoadIcons();
 	
     iUpdater = CPodcastFeedViewUpdater::NewL(*this);
 	DP("CPodcastFeedView::ConstructL END");
@@ -189,6 +163,7 @@
 	itemProps.SetDimmed(EFalse);	
 	iItemArray->Delete(aIndex);	
 	iItemArray->InsertL(aIndex, iListboxFormatbuffer);
+	iListContainer->SetTextArray(iItemArray);
 	iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(aIndex, itemProps);
 	// If item is visible, redraw it
 	if (iListContainer->Listbox()->TopItemIndex() <= aIndex
@@ -349,6 +324,7 @@
 			iItemIdArray.InsertL(aFeedUid, feedsIdx);
 			iItemArray->Delete(listboxIdx);
 			iItemArray->InsertL(feedsIdx, KNullDesC);
+			iListContainer->SetTextArray(iItemArray);
 			iListContainer->Listbox()->HandleItemAdditionL();
 			}
 		// Update the listbox info
@@ -442,14 +418,7 @@
 		unplayedShows.Insert(0,_L(", "));
 	}
 		
-	if (iListContainer->IsLandscape())
-		{
-		iListboxFormatbuffer.Format(KFeedFormatLandscape(), iconIndex, &(aFeedInfo.Title()));
-		}
-	else 
-		{
-		iListboxFormatbuffer.Format(KFeedFormatPortrait(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
-		}
+	iListboxFormatbuffer.Format(KFeedFormatPortrait(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
 	}
 
 void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle, CPodcastModel& /*aPodcastModel*/)
@@ -488,7 +457,6 @@
 	// No reason to do any work if it isn't going to show..
 	if(!iListContainer->IsVisible())
 		{
-		DP("not visible");
 		return;
 		}
 	
@@ -532,6 +500,7 @@
 		itemProps.SetHiddenSelection(ETrue);								
 		iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(0, itemProps);
 		}
+	iListContainer->SetTextArray(iItemArray);
 	iListContainer->Listbox()->HandleItemAdditionL();
 	DP("CPodcastFeedView::UpdateListboxItemsL END");
 	}
--- a/application/src/PodcastListView.cpp	Sun Oct 31 10:35:57 2010 +0000
+++ b/application/src/PodcastListView.cpp	Sun Oct 31 12:16:04 2010 +0000
@@ -65,34 +65,37 @@
 		                                              aRect, 
 		                                              ETrue );
 	
-	if (iListbox)
-		delete iListbox;
+	iItemArrayShort = new (ELeave)CDesCArrayFlat(KDefaultGran);
+
+	iListboxLandscape = new (ELeave) CAknSingleLargeStyleListBox;
+	iListboxLandscape->ConstructL(this, aListboxFlags);
+	iListboxLandscape->SetMopParent( this );
+	iListboxLandscape->SetContainerWindowL(*this);
+	iListboxLandscape->CreateScrollBarFrameL(ETrue);
+	iListboxLandscape->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
+	iListboxLandscape->SetSize(aRect.Size());
+	iListboxLandscape->MakeVisible(EFalse);
+
+	iListboxPortrait = new (ELeave) CAknDoubleLargeStyleListBox;
+	iListboxPortrait->ConstructL(this, aListboxFlags);
+	iListboxPortrait->SetMopParent( this );
+	iListboxPortrait->SetContainerWindowL(*this);
+	iListboxPortrait->CreateScrollBarFrameL(ETrue);
+	iListboxPortrait->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
+	iListboxPortrait->SetSize(aRect.Size());
+	iListboxPortrait->MakeVisible(EFalse);
 	
 	if (aRect.Width() > aRect.Height())
 		{
 		DP("Landscape mode");
 		iLandscape = ETrue;
-		iListboxLandscape = new (ELeave) CAknSingleLargeStyleListBox;
-		iListboxLandscape->ConstructL(this, aListboxFlags);
-		iListboxLandscape->SetMopParent( this );
-		iListboxLandscape->SetContainerWindowL(*this);
-		iListboxLandscape->CreateScrollBarFrameL(ETrue);
-		iListboxLandscape->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
-		iListboxLandscape->SetSize(aRect.Size());
+		iListbox = iListboxLandscape;
 		iListboxLandscape->MakeVisible(ETrue);
-		iListbox = iListboxLandscape;
 		}
 	else 
 		{
 		DP("Portrait mode");
 		iLandscape = EFalse;
-		iListboxPortrait = new (ELeave) CAknDoubleLargeStyleListBox;
-		iListboxPortrait->ConstructL(this, aListboxFlags);
-		iListboxPortrait->SetMopParent( this );
-		iListboxPortrait->SetContainerWindowL(*this);
-		iListboxPortrait->CreateScrollBarFrameL(ETrue);
-		iListboxPortrait->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
-		iListboxPortrait->SetSize(aRect.Size());
 		iListboxPortrait->MakeVisible(ETrue);
 		iListbox = (CEikColumnListBox*) iListboxPortrait;
 		}
@@ -117,7 +120,10 @@
     switch ( aIndex )
         {
         case 0:
-            return iListbox;
+        	if (iLandscape)
+        		return iListboxLandscape;
+        	else
+        		return iListboxPortrait;
         default:
             return NULL;
         }
@@ -147,15 +153,46 @@
 void CPodcastListContainer::SizeChanged()
 {
 	DP2("CPodcastListContainer::SizeChanged() BEGIN, width=%d, height=%d",Size().iWidth, Size().iHeight);
-	
-	if (iListbox == NULL)
-		return;
 
-	iListbox->SetSize(Size());
-	
+	//TBool nowLandscape = ETrue;//!iLandscape;
+	TBool nowLandscape = Size().iWidth > Size().iHeight;
+	//TBool orientationChanged = nowLandscape && !iLandscape;
+
+	iLandscape = nowLandscape;
+
 	if (iContainerListener)
 		iContainerListener->SizeChanged();
 	
+	if (nowLandscape)
+		{
+		iListboxPortrait->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff );
+		iListboxPortrait->UpdateScrollBarsL();
+		iListboxPortrait->MakeVisible(EFalse);
+		iListboxLandscape->MakeVisible(ETrue);
+		iListboxLandscape->SetFocus(ETrue, EDrawNow);
+		iListbox = iListboxLandscape;
+		iListboxLandscape->SetMopParent( this );
+		iListboxLandscape->SetContainerWindowL(*this);
+		iListboxLandscape->CreateScrollBarFrameL(ETrue);
+		iListboxLandscape->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
+		}
+	else
+		{
+		iListboxLandscape->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff );
+		iListboxLandscape->UpdateScrollBarsL();
+		iListboxPortrait->MakeVisible(ETrue);
+		iListboxLandscape->MakeVisible(EFalse);	
+		iListboxPortrait->SetFocus(ETrue, EDrawNow);
+		iListbox = (CEikColumnListBox*) iListboxPortrait;
+		iListboxPortrait->SetMopParent( this );
+		iListboxPortrait->SetContainerWindowL(*this);
+		iListboxPortrait->CreateScrollBarFrameL(ETrue);
+		iListboxPortrait->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
+		}
+
+	iListbox->SetSize(Size());
+    ActivateL();  		
+	DrawNow();
 	DP("CPodcastListContainer::SizeChanged END");
 }
 
@@ -167,10 +204,8 @@
 
 void CPodcastListContainer::SetListboxIcons(CArrayPtr< CGulIcon >* aIcons)
 {
-	if (iListboxLandscape == iListbox)
-		iListboxLandscape->ItemDrawer()->ColumnData()->SetIconArray(aIcons);
-	else
-		iListboxPortrait->ItemDrawer()->FormattedCellData()->SetIconArrayL(aIcons);
+	iListboxLandscape->ItemDrawer()->ColumnData()->SetIconArray(aIcons);
+	iListboxPortrait->ItemDrawer()->FormattedCellData()->SetIconArrayL(aIcons);
 }
 
 CArrayPtr<CGulIcon>* CPodcastListContainer::ListboxIcons()
@@ -183,14 +218,34 @@
 
 void CPodcastListContainer::SetTextArray(CDesCArray* aArray)
 	{
-	iListbox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
-	iListbox->Model()->SetItemTextArray(aArray);
+	DP1("SetTextArray, aArray.Count=%d", aArray->Count());
+	iItemArrayShort->Reset();
+	DP("after reset");
+	for (int i=0;i<aArray->Count();i++)
+		{
+		TBuf<1024> line;
+		line.Copy((*aArray)[i]);
+		TInt tpos = line.LocateReverse('\t');
+		if (tpos != -1)
+			{
+			line = line.Left(tpos);
+			}
+		
+		//DP1("line: %S", line);
+		iItemArrayShort->AppendL(line);
+		}
+	
+	iListboxLandscape->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
+	iListboxLandscape->Model()->SetItemTextArray(iItemArrayShort);
+	iListboxPortrait->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
+	iListboxPortrait->Model()->SetItemTextArray(aArray);
 	}
 
 CPodcastListContainer::~CPodcastListContainer()
 {
 	delete iListbox;
 	delete iBgContext;
+	delete iItemArrayShort;
 }
 
 void CPodcastListView::SwitchListbox()
@@ -272,19 +327,19 @@
 {    
 	TBool wasVisible = iListContainer->IsVisible();
 
-	if (wasVisible)
-		{
-		AppUi()->ActivateLocalViewL(KUidPodcastSearchViewID,  TUid::Uid(0), KNullDesC8);
-		
-		DoDeactivate();
-		}
-	
-	ResetContainer();
-
-	if (wasVisible)
-		{
-		AppUi()->ActivateLocalViewL(ViewId().iViewUid,  TUid::Uid(0), KNullDesC8);
-		}
+//	if (wasVisible)
+//		{
+//		AppUi()->ActivateLocalViewL(KUidPodcastSearchViewID,  TUid::Uid(0), KNullDesC8);
+//		
+//		DoDeactivate();
+//		}
+//	
+//	ResetContainer();
+//
+//	if (wasVisible)
+//		{
+//		AppUi()->ActivateLocalViewL(ViewId().iViewUid,  TUid::Uid(0), KNullDesC8);
+//		}
     
 	if ( iListContainer )
 	{
--- a/application/src/PodcastQueueView.cpp	Sun Oct 31 10:35:57 2010 +0000
+++ b/application/src/PodcastQueueView.cpp	Sun Oct 31 12:16:04 2010 +0000
@@ -208,6 +208,7 @@
 					itemProps.SetDimmed(ETrue);
 					itemProps.SetHiddenSelection(ETrue);
 					}
+				iListContainer->SetTextArray(iItemArray);
 				iListContainer->Listbox()->HandleItemAdditionL();
 				}				
 			}
--- a/application/src/PodcastSearchView.cpp	Sun Oct 31 10:35:57 2010 +0000
+++ b/application/src/PodcastSearchView.cpp	Sun Oct 31 12:16:04 2010 +0000
@@ -200,6 +200,7 @@
 		itemProps.SetHiddenSelection(ETrue);								
 		iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(0, itemProps);
 		}
+	iListContainer->SetTextArray(iItemArray);
 	iListContainer->Listbox()->HandleItemAdditionL();
 	DP("CPodcastSearchView::UpdateListboxItemsL END");
 	}
--- a/application/src/PodcastShowsView.cpp	Sun Oct 31 10:35:57 2010 +0000
+++ b/application/src/PodcastShowsView.cpp	Sun Oct 31 12:16:04 2010 +0000
@@ -37,7 +37,7 @@
 _LIT(KSizeDownloadingOf, "%.1f/%.1f MB");
 _LIT(KShowsSizeFormatS60, "%.1f MB");
 
-_LIT(KShowFormat, "%d\t%S\t%S%S\t");
+_LIT(KShowFormat, "%d\t%S\t%S%S");
 
 // these must correspond with TShowsIconIndex
 
@@ -478,6 +478,8 @@
 		{
 		iItemArray->InsertL(aIndex, iListboxFormatbuffer);
 		}
+	
+	iListContainer->SetTextArray(iItemArray);
 }
 
 void CPodcastShowsView::UpdateShowItemL(TUint aUid, TInt aSizeDownloaded)
@@ -559,6 +561,7 @@
 					itemProps.SetDimmed(ETrue);
 					itemProps.SetHiddenSelection(ETrue);
 					}
+				iListContainer->SetTextArray(iItemArray);
 				iListContainer->Listbox()->HandleItemAdditionL();
 				}				
 			}