internetradio2.0/uisrc/irhistorylistview.cpp
changeset 0 09774dfdd46b
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  view class for IRHistoryListView.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stringloader.h>
       
    19 #include <internetradio.rsg>
       
    20 
       
    21 #include "irui.h"
       
    22 #include "ir.hrh"
       
    23 #include "ircommon.h"
       
    24 #include "irdebug.h"
       
    25 #include "irbaseview.h"
       
    26 #include "irhistorylistview.h"
       
    27 #include "irhistorylistcontainer.h"
       
    28 #include "irapplication.h"
       
    29 #include "irsonghistoryinfo.h"
       
    30 #include "irsonghistoryengine.h"
       
    31 #include "irnowplayingwrapper.h"
       
    32 #include "irisdswrapper.h"
       
    33 #include <hlplch.h>
       
    34 
       
    35 //For Touch Toolbar
       
    36 #include <internetradio.mbg>
       
    37 #include <akntoolbar.h>
       
    38 #include <aknbutton.h>
       
    39 
       
    40 #ifdef MUSICSHOP_AVAILABLE
       
    41 #include <mpxfindinmusicshop.h> //For Find in Shop
       
    42 #include <apgcli.h>             //For Find in Shop
       
    43 #endif
       
    44 
       
    45 //to be removed after UT
       
    46 #include "irmetadata.h"
       
    47 #include "irdialoglauncher.h"
       
    48 
       
    49 #include "irnetworkcontroller.h" 	
       
    50 #include "iractivenetworkobserver.h"
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // C++ default constructor can NOT contain any code, that might leave.
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 
       
    58 CIRHistoryListView::CIRHistoryListView():iCallRequestPending(EFalse)
       
    59     {
       
    60     IRLOG_DEBUG( "CIRHistoryListView::CIRHistoryListView" );
       
    61     // Nothing here
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // EPOC default constructor can leave.
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 
       
    69 void CIRHistoryListView::ConstructL()
       
    70 {
       
    71 	IRLOG_DEBUG( "CIRHistoryListView::ConstructL - Entering" );
       
    72 	CIRBaseView::ConstructL(R_IR_HISTORY);
       
    73 	
       
    74 	MAknsSkinInstance * skin=AknsUtils::SkinInstance () ;
       
    75 	TRgb color;
       
    76 	TInt skinColor=AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors,
       
    77 				                                      EAknsCIQsnTextColorsCG6 );
       
    78 	if(color.Gray2()!=0)
       
    79 		{
       
    80 		CreateAndSetToolbarL(R_IR_HISTORY_WHITE_TOOLBAR);
       
    81 		}
       
    82 	else
       
    83 		{
       
    84 		CreateAndSetToolbarL(R_IR_HISTORY_BLACK_TOOLBAR);	
       
    85 		}
       
    86 	if( AknLayoutUtils::PenEnabled() && Toolbar() )
       
    87 		{
       
    88 		Toolbar()->SetToolbarObserver( this );
       
    89 		}
       
    90 	
       
    91 	iHistoryEngine = CIRSongHistoryEngine::NewL(*this);
       
    92   	GetAllListL();
       
    93 
       
    94   	//For Find in Shop
       
    95   	iMPXFindInShop = NULL;
       
    96 #ifdef MUSICSHOP_AVAILABLE  	
       
    97 	TRAPD(error, iMPXFindInShop = CMPXFindInMShop::NewL());
       
    98     if (error != KErrNotFound && error != KErrNone)
       
    99     {
       
   100        User::Leave(error);
       
   101     }
       
   102 #endif    
       
   103 
       
   104     iRequestPending = EFalse;
       
   105     iAddToFav= EFalse;
       
   106     iListenRequest = EFalse;
       
   107     IRLOG_DEBUG( "CIRHistoryListView::ConstructL - Exiting" );
       
   108 }
       
   109 // ---------------------------------------------------------------------------
       
   110 // Static constructor.
       
   111 // CIRHistoryListView::NewL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 CIRHistoryListView* CIRHistoryListView::NewL()
       
   115     {
       
   116     IRLOG_DEBUG("CIRHistoryListView::NewL - Entering" );
       
   117     CIRHistoryListView* self = CIRHistoryListView::NewLC();
       
   118     CleanupStack::Pop(self);
       
   119     IRLOG_DEBUG( "CIRHistoryListView::NewL - Exiting." );
       
   120     return self;
       
   121     }
       
   122 // ---------------------------------------------------------------------------
       
   123 // Two-phased constructor.
       
   124 // CIRHistoryListView::NewLC
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 CIRHistoryListView* CIRHistoryListView::NewLC()
       
   128     {
       
   129        
       
   130     IRLOG_DEBUG( "CIRHistoryListView::NewLC - Entering" );
       
   131     CIRHistoryListView* self = new (ELeave) CIRHistoryListView();
       
   132     CleanupStack::PushL(self);
       
   133     self->ConstructL();
       
   134     IRLOG_DEBUG( "CIRHistoryListView::NewLC - Exiting." );
       
   135     return self;
       
   136     }
       
   137 
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // Destructor
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 
       
   144 CIRHistoryListView::~CIRHistoryListView()
       
   145 	{
       
   146 	IRLOG_DEBUG( "CIRHistoryListView::~CIRHistoryListView - Entering" );
       
   147     if ( iContainer )
       
   148         {
       
   149         	AppUi()->RemoveFromViewStack( *this, iContainer );
       
   150         	iContainer->MakeVisible( EFalse );
       
   151         	delete iContainer;
       
   152         	iContainer=NULL;
       
   153         }
       
   154 
       
   155     iHistoryDataArr.ResetAndDestroy();
       
   156 
       
   157     if(iHistoryEngine)
       
   158         {
       
   159         	delete iHistoryEngine;
       
   160         	iHistoryEngine = NULL;
       
   161         }
       
   162 
       
   163 #ifdef MUSICSHOP_AVAILABLE
       
   164     if (iMPXFindInShop)
       
   165 		{
       
   166 			delete iMPXFindInShop;
       
   167 			iMPXFindInShop = NULL;
       
   168 		}
       
   169 #endif
       
   170 
       
   171 	if( AknLayoutUtils::PenEnabled() && Toolbar() )
       
   172 		{
       
   173 		Toolbar()->SetToolbarVisibility(EFalse, EFalse);
       
   174 		Toolbar()->SetToolbarObserver( NULL );
       
   175 		}
       
   176     IRLOG_DEBUG( "CIRHistoryListView::~CIRHistoryListView - Exiting" );
       
   177 	}
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // From class CAknView.
       
   181 // Returns view id.
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 
       
   185 TUid CIRHistoryListView::Id() const
       
   186     {
       
   187     IRLOG_DEBUG( "CIRHistoryListView::Id" );
       
   188     return KIRHistoryListViewId;
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // From class CAknView.
       
   193 // Handles view activation.
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 
       
   197 void CIRHistoryListView::DoActivateL( const TVwsViewId& aPrevViewId,
       
   198         TUid aCustomMessageId, const TDesC8& aCustomMessage )
       
   199     {
       
   200     IRLOG_DEBUG( "CIRHistoryListView::DoActivateL - Entering" );
       
   201     iUi->iPresentViewID = KIRHistoryListViewId;
       
   202     CIRUi* appUi = static_cast<CIRUi*>( AppUi() );
       
   203      if ( !iContainer )
       
   204 		{
       
   205 		iContainer = CIRHistoryListContainer::NewL(ClientRect(),*this,iHistoryDataArr );
       
   206 		iContainer->SetMopParent( this );
       
   207 		appUi->AddToViewStackL( *this, iContainer );
       
   208 		}
       
   209     else
       
   210        {
       
   211 		// we must notify a resource change in order to update the skin context
       
   212 		// This is a flaw of CEikFormattedCellListBox
       
   213 			iContainer->SetRect(ClientRect());
       
   214         	iContainer->HandleResourceChange(KEikDynamicLayoutVariantSwitch);
       
   215        }
       
   216 
       
   217     ConstructToolbarL();
       
   218     iContainer->ActivateL();
       
   219     iContainer->MakeVisible( ETrue );
       
   220     SetTitleL( R_IRAPP_HISTORY_TITLE );
       
   221     CIRBaseView::DoActivateL( aPrevViewId, aCustomMessageId, aCustomMessage );
       
   222     HandleStatusPaneSizeChange();
       
   223     iUi->iNetworkController->RegisterActiveNetworkObserverL(*this);
       
   224     EnableObserverL(EIRSystemEventObserver);
       
   225     IRLOG_DEBUG( "CIRHistoryListView::DoActivateL - Exiting" );
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // From class CAknView.
       
   230 // Handles view deactivation.
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 
       
   234 void CIRHistoryListView::DoDeactivate()
       
   235    {
       
   236    IRLOG_DEBUG( "CIRHistoryListView::DoDeactivate - Entering" );
       
   237     CIRUi* appUi = static_cast<CIRUi*>( AppUi() );
       
   238     if(&(appUi->SystemEventCollector()))
       
   239 	    {
       
   240 		DisableObserver(EIRSystemEventObserver);
       
   241 	    }
       
   242 
       
   243     if ( iContainer )
       
   244         {
       
   245         appUi->RemoveFromViewStack( *this, iContainer );
       
   246         iContainer->MakeVisible( EFalse );
       
   247         delete iContainer;
       
   248     	iContainer  = NULL;
       
   249         }
       
   250 
       
   251 	if( AknLayoutUtils::PenEnabled() && Toolbar() )
       
   252 		{
       
   253 		Toolbar()->SetToolbarVisibility(EFalse, EFalse);
       
   254 		Toolbar()->SetToolbarObserver( NULL );
       
   255 		}
       
   256     iUi->iNetworkController->DeleteActiveNetworkObserver(*this);
       
   257     IRLOG_DEBUG( "CIRHistoryListView::DoDeactivate - Exiting" );
       
   258    }
       
   259 
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // From class CAknView.
       
   263 // Command handling function.
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 
       
   267 void CIRHistoryListView::HandleCommandL( TInt aCommand )
       
   268     {
       
   269     IRLOG_DEBUG( "CIRHistoryListView::HandleCommandL - Entering" );
       
   270 	iCommand = aCommand;
       
   271     switch ( aCommand )
       
   272         {
       
   273        case EAknSoftkeyOptions:
       
   274             {
       
   275 
       
   276             Cba()->DrawDeferred();
       
   277             break;
       
   278             }
       
   279 
       
   280         case EAknSoftkeyCancel:
       
   281             {
       
   282             break;
       
   283             }
       
   284 
       
   285         case EClearCmd:
       
   286 			{
       
   287 			
       
   288 			RBuf sumvalue;
       
   289 			HBufC* textResource = StringLoader::LoadLC( R_IRAPP_HISTORY_QUERY );
       
   290 			sumvalue.Create(*textResource);
       
   291 			CIRDialogLauncher* queryNote = CIRDialogLauncher::NewL();
       
   292 			CleanupStack::PushL( queryNote );
       
   293 			TInt dlgValue;
       
   294 			queryNote->ShowQueryDialogDeletionL(sumvalue,dlgValue);
       
   295 			if(dlgValue)
       
   296 				{
       
   297 				ClearSongHistoryItemL();
       
   298 				}
       
   299 			CleanupStack::PopAndDestroy( queryNote );
       
   300 			CleanupStack::PopAndDestroy( textResource );
       
   301 			sumvalue.Close();
       
   302 			Toolbar()->DrawNow();
       
   303 
       
   304 			break;
       
   305 
       
   306 			}
       
   307         case EHelpCmd:
       
   308             {
       
   309 			if ( !iUi->CheckAndNotifyLowDiskSpaceL() )
       
   310 				{
       
   311 				HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), AppUi()->AppHelpContextL() );
       
   312 				}
       
   313           		break;
       
   314             }
       
   315 
       
   316         case EGotoNowPlayingViewCmd:
       
   317             {
       
   318             	iUi->SetHistory(ETrue);
       
   319 			    iUi->SavePrevIDL(KIRHistoryListViewId,aCommand);
       
   320 			    break;
       
   321             }
       
   322 
       
   323         case EListenCmd:
       
   324             {
       
   325 			if ( !iUi->CheckAndNotifyLowDiskSpaceL() )
       
   326 				{
       
   327 				iUi->SetListenFromPls(EFalse);
       
   328 				if( iUi->VerifyNetworkConnectivityL() )
       
   329 					{
       
   330 					iRequestPending = ETrue;
       
   331 					iListenRequest  = ETrue;
       
   332 					iAddToFav=EFalse;
       
   333 					break;
       
   334 					}
       
   335 				else
       
   336 					{
       
   337 	                iNowPlayingWrapper->SetView(EHistoryView);
       
   338 					TInt index=iContainer->GetCurrentFocussedNode();
       
   339 					iContainer->ListenUrlL(index );
       
   340 					}
       
   341 				}
       
   342 		        break;
       
   343             }
       
   344 
       
   345         case ESettingsCmd:
       
   346             {
       
   347 		        AppUi()->ActivateLocalViewL(KIRSettingsViewId);
       
   348            	    break;
       
   349             }
       
   350 
       
   351         case EAddtoFavouritesCmd:
       
   352             {
       
   353 				if ( iUi->CheckAndNotifyLowDiskSpaceL() )
       
   354 					{
       
   355 					break;
       
   356 					}
       
   357 				
       
   358 			   if(iContainer->IsdsOrNot())
       
   359 					{
       
   360 					if( iUi->VerifyNetworkConnectivityL() )
       
   361 						{
       
   362 						iRequestPending = ETrue;
       
   363 						iAddToFav = ETrue;
       
   364 						iListenRequest=EFalse;
       
   365 						break;
       
   366 						}
       
   367 					else 
       
   368 						{
       
   369 						iAddToFav = ETrue;
       
   370 	                    iContainer->AddStationToFavoritesL(aCommand);
       
   371 						}
       
   372 					}
       
   373 				else
       
   374 					{
       
   375 					iContainer->AddStationToFavoritesL(aCommand);
       
   376 					}
       
   377 			            
       
   378             }
       
   379         break;    
       
   380         case EFindInShop:
       
   381         	{
       
   382 			if ( !iUi->CheckAndNotifyLowDiskSpaceL() )
       
   383 				{
       
   384 				_LIT(KFind, "find");
       
   385 	        	FindInShopOptionL();
       
   386 	        	 
       
   387 	        	/**
       
   388 	        	 * Increment the Find In Store count by One
       
   389 	        	 */
       
   390 	        	iUi->FindInMusicStoreCounter();
       
   391 	        	iNowPlayingWrapper->UpdateNmsLogEventsL(KFind);
       
   392 				}
       
   393         	}
       
   394         break;
       
   395        	case EAddStationManuallyCmd:
       
   396 			{
       
   397 			if ( !iUi->CheckAndNotifyLowDiskSpaceL() )
       
   398 				{
       
   399 				iUi->SetEditStation(EFalse);
       
   400 				AppUi()->ActivateLocalViewL(KIRAddManuallyStationViewID);
       
   401 				}
       
   402 			}
       
   403 		break;
       
   404 
       
   405         default:
       
   406             {
       
   407             CIRBaseView::HandleCommandL( aCommand );
       
   408             break;
       
   409             }
       
   410         }
       
   411     IRLOG_DEBUG( "CIRHistoryListView::HandleCommandL - Exiting" );
       
   412     }
       
   413 
       
   414 
       
   415 
       
   416 // ---------------------------------------------------------------------------
       
   417 // From class CAknView.
       
   418 // Event handler for status pane size changes.
       
   419 // ---------------------------------------------------------------------------
       
   420 //
       
   421 void CIRHistoryListView::HandleStatusPaneSizeChange()
       
   422     {
       
   423     IRLOG_DEBUG( "CIRHistoryListView::HandleStatusPaneSizeChange - Entering" );
       
   424     // the client rect is also set here after screen orientation change
       
   425     if ( iContainer )
       
   426         {
       
   427         iContainer->SetRect( ClientRect() );
       
   428         }
       
   429     IRLOG_DEBUG( "CIRHistoryListView::HandleStatusPaneSizeChange - Exiting" );
       
   430     }
       
   431 
       
   432 // ---------------------------------------------------------------------------
       
   433 // CIRHistoryListView::NextSongReceivedL()
       
   434 // Adds the currently playing song to the history's array.
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 
       
   438 void CIRHistoryListView::NextSongReceivedL( const TDesC& /*aSongName*/,
       
   439                                             const TDesC& /*aArtistName*/,
       
   440                                             const TDesC& /*aChannelName*/, 
       
   441                                             const TDesC& /*aChannelUrl*/ )
       
   442 {
       
   443 	IRLOG_DEBUG( "CIRHistoryListView::NextSongReceivedL - Entering" );
       
   444 	iHistoryDataArr.ResetAndDestroy();
       
   445 
       
   446 	if(iContainer)
       
   447 	{
       
   448 		iContainer->ClearHistoryListL();
       
   449 	}
       
   450 
       
   451 	GetAllListL();
       
   452 	if(iContainer)
       
   453 	{
       
   454 		iContainer->UpdateAllL(iHistoryDataArr);
       
   455 	}
       
   456 	IRLOG_DEBUG( "CIRHistoryListView::NextSongReceivedL - Exiting" );
       
   457 }
       
   458 
       
   459 
       
   460 
       
   461 // ---------------------------------------------------------------------------
       
   462 // CIRHistoryListView::ChannelChangedL()
       
   463 // Moves the currently playing channel to the top.
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 void CIRHistoryListView::ChannelChangedL( const TDesC& /*aSongName*/,const TDesC& /*aArtistName*/,
       
   467 		 const TDesC& /*aChannelName*/, const TDesC& /*aChannelUrl*/ )
       
   468 {
       
   469 	IRLOG_DEBUG( "CIRHistoryListView::ChannelChangedL - Entering" );
       
   470 	iHistoryDataArr.ResetAndDestroy();
       
   471 
       
   472 	if(iContainer)
       
   473 	{
       
   474 		iContainer->ClearHistoryListL();
       
   475 	}
       
   476 
       
   477 	GetAllListL();
       
   478 	if(iContainer)
       
   479 	{
       
   480 		iContainer->UpdateAllL(iHistoryDataArr);
       
   481 	}
       
   482 	IRLOG_DEBUG( "CIRHistoryListView::ChannelChangedL - Exiting" );
       
   483 }
       
   484 
       
   485 
       
   486 // ---------------------------------------------------------------------------
       
   487 // CIRHistoryListView::RemoveSongEntry()
       
   488 // Removes the particular  from the List Array
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 TInt CIRHistoryListView::RemoveSongEntry(const TDesC & /*aSongName*/,
       
   492                                          const TDesC & /*aArtistName*/, 
       
   493                                          const TDesC & /*aChannelName*/,
       
   494                                          const TDesC& /*aChannelUrl*/)
       
   495  {
       
   496  	IRLOG_DEBUG( "CIRHistoryListView::RemoveSongEntry - Entering" );
       
   497     IRLOG_DEBUG( "CIRHistoryListView::RemoveSongEntry - Exiting" );
       
   498 	return KErrNone;
       
   499  }
       
   500 
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 // CIRHistoryListView::RemoveChannelEntry()
       
   504 // ---------------------------------------------------------------------------
       
   505 //
       
   506 TInt CIRHistoryListView::RemoveChannelEntry( const TDesC& /*aSongName*/, 
       
   507                                              const TDesC& /*aArtistName*/,
       
   508                                              const TDesC& /*aChannelName*/,
       
   509                                              const TDesC& /*aChannelUrl*/ )
       
   510 {
       
   511 	IRLOG_DEBUG( "CIRHistoryListView::RemoveChannelEntry" );
       
   512 	// No implementation required for DoubleStyleListbox as no seperate channel entries exist to be deleted.
       
   513 	return KErrNone;
       
   514 }
       
   515 
       
   516 
       
   517 // ---------------------------------------------------------------------------
       
   518 // CIRHistoryListView::NotifyDataChangeToUIError()
       
   519 // Not Implemented
       
   520 // ---------------------------------------------------------------------------
       
   521 //
       
   522 void CIRHistoryListView::NotifyDataChangeToUIError(TInt /*aError*/)
       
   523 {
       
   524 	IRLOG_DEBUG( "CIRHistoryListView::NotifyDataChangeToUIError" );
       
   525 }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // CIRHistoryListView::ClearSongHistoryItemL()
       
   529 // Clears the Song History array
       
   530 // ---------------------------------------------------------------------------
       
   531 //
       
   532 void CIRHistoryListView::ClearSongHistoryItemL()
       
   533 {
       
   534 	IRLOG_DEBUG( "CIRHistoryListView::ClearSongHistoryItemL - Entering" );
       
   535 	if(iHistoryEngine->ClearAllHistory() != KErrNone)
       
   536 	{
       
   537 		iHistoryDataArr.ResetAndDestroy();
       
   538 		iContainer->ClearHistoryListL();
       
   539 		Toolbar()->SetItemDimmed(EFindInShop,ETrue,ETrue);
       
   540 		Toolbar()->SetItemDimmed(EListenCmd,ETrue,ETrue);
       
   541 		GetAllListL();
       
   542 		if(iContainer)
       
   543 		{
       
   544 			iContainer->UpdateAllL(iHistoryDataArr);
       
   545 		}
       
   546 		IRLOG_DEBUG( "CIRHistoryListView::ClearSongHistoryItemL - Exiting" );
       
   547 		return;
       
   548 	}
       
   549 	iHistoryDataArr.ResetAndDestroy();
       
   550 
       
   551 	if(iContainer)
       
   552 	{
       
   553 		iContainer->ClearHistoryListL();
       
   554 		Toolbar()->SetItemDimmed(EFindInShop,ETrue,ETrue);
       
   555 		Toolbar()->SetItemDimmed(EListenCmd,ETrue,ETrue);
       
   556 		iContainer->UpdateAllL(iHistoryDataArr);
       
   557 	}
       
   558 	IRLOG_DEBUG( "CIRHistoryListView::ClearSongHistoryItemL - Exiting" );
       
   559 }
       
   560 
       
   561 
       
   562 // ---------------------------------------------------------------------------
       
   563 // CIRHistoryListView::GetAllList()
       
   564 // gets the List which was stored earlier
       
   565 //---------------------------------------------------------------------------
       
   566 void CIRHistoryListView::GetAllListL()
       
   567 {
       
   568 	IRLOG_DEBUG( "CIRHistoryListView::GetAllListL - Entering" );
       
   569 	TInt songCount = iHistoryEngine->GetHistoryCount();
       
   570 
       
   571 	if(songCount == 0)
       
   572 		{
       
   573 		IRLOG_DEBUG( "CIRHistoryListView::GetAllListL - Exiting" );
       
   574 		return;
       
   575 		}
       
   576 
       
   577 	for(TInt arrCount=0 ; arrCount<songCount ; arrCount++ )
       
   578 		{
       
   579 		CIRSongHistoryInfo *songHistory = CIRSongHistoryInfo::NewL();
       
   580 		CleanupStack::PushL( songHistory );
       
   581 		iHistoryDataArr.Append(songHistory);
       
   582 		CleanupStack::Pop(songHistory);
       
   583 		}
       
   584 
       
   585 	//to be implemented after getting the engine class..
       
   586 	iHistoryEngine->GetAllHistoryL(iHistoryDataArr);
       
   587 	IRLOG_DEBUG( "CIRHistoryListView::GetAllListL - Exiting" );
       
   588 }
       
   589 
       
   590 // ---------------------------------------------------------------------------
       
   591 // CIRHistoryListView::DynInitMenuPaneL()
       
   592 // Dynamically handles the Menu Pane
       
   593 //---------------------------------------------------------------------------
       
   594 void CIRHistoryListView::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
       
   595 	{
       
   596 	IRLOG_DEBUG( "CIRHistoryListView::DynInitMenuPaneL - Entering" );
       
   597 	if(aResourceId == R_IR_MENU_HISTORY)
       
   598 		{
       
   599 		if(!aMenuPane) User::Leave(KErrNotFound);
       
   600 			{
       
   601 			if (  iHistoryDataArr.Count() == 0 )
       
   602 				{
       
   603 				aMenuPane->SetItemDimmed( EClearCmd, ETrue );
       
   604 				}
       
   605 			else
       
   606 				{
       
   607 				aMenuPane->SetItemDimmed( EClearCmd, EFalse );
       
   608 				}
       
   609 			// Now Playing option
       
   610 			if(iNowPlayingWrapper->iPlaying)
       
   611 				{
       
   612 				aMenuPane->SetItemDimmed(EGotoNowPlayingViewCmd,EFalse);
       
   613 				}
       
   614 			else
       
   615 				{
       
   616 				aMenuPane->SetItemDimmed(EGotoNowPlayingViewCmd,ETrue);
       
   617 				}
       
   618             if(iContainer->ShowFocus()|| !(iHistoryDataArr.Count() ))
       
   619 	            {
       
   620 	            aMenuPane->SetItemDimmed(EAddtoFavouritesCmd,ETrue);
       
   621 	            }
       
   622             else
       
   623 	            {
       
   624 	            aMenuPane->SetItemDimmed(EAddtoFavouritesCmd,EFalse);
       
   625 	            }
       
   626 			}
       
   627 
       
   628 		}
       
   629 	IRLOG_DEBUG( "CIRHistoryListView::DynInitMenuPaneL - Exiting" );
       
   630 
       
   631 	}
       
   632 // ---------------------------------------------------------------------------
       
   633 // CIRHistoryListView::HandleMetaDataReceived()
       
   634 // Handles the change in metadata.
       
   635 //---------------------------------------------------------------------------
       
   636 
       
   637 void CIRHistoryListView::HandleMetaDataReceived( const CIRMetaData& aMetaData )
       
   638 {
       
   639 	IRLOG_DEBUG( "CIRHistoryListView::HandleMetaDataReceived - Entering" );
       
   640 	if( iHistoryEngine )
       
   641 	{
       
   642 		TRAPD( error, iHistoryEngine->HandleMetaDataReceivedL( aMetaData ) );
       
   643 		if( error )
       
   644 		{
       
   645 			IRLOG_DEBUG( "CIRHistoryListView::HandleMetaDataReceivedL - Failed." );
       
   646 		}
       
   647 	}
       
   648 	IRLOG_DEBUG( "CIRHistoryListView::HandleMetaDataReceived - Exiting" );
       
   649 }
       
   650 
       
   651 
       
   652 // ---------------------------------------------------------------------------
       
   653 // CIRHistoryListView::ConstructToolbarL()
       
   654 // Constructs Touch Toolbar
       
   655 //---------------------------------------------------------------------------
       
   656 
       
   657 void CIRHistoryListView::ConstructToolbarL()
       
   658 	{
       
   659 	IRLOG_DEBUG( "CIRHistoryListView::ConstructToolbarL - Entering" );
       
   660     if(Toolbar())
       
   661 	    {
       
   662 		if (  iHistoryDataArr.Count() == 0 )
       
   663 			{
       
   664 			Toolbar()->SetItemDimmed(EFindInShop,ETrue,ETrue);
       
   665 			Toolbar()->SetItemDimmed(EListenCmd,ETrue,ETrue);
       
   666 			}
       
   667 
       
   668 		if(iMPXFindInShop)
       
   669 			{
       
   670 			if(iContainer->GetButtonDimmed())
       
   671 				{
       
   672 				Toolbar()->SetItemDimmed(EFindInShop,ETrue,ETrue);
       
   673 				}
       
   674 			}
       
   675 		else
       
   676 			{
       
   677 			Toolbar()->SetItemDimmed(EFindInShop,ETrue,ETrue);
       
   678 			}
       
   679 		Toolbar()->SetToolbarVisibility( ETrue );
       
   680 		if(iContainer)
       
   681 			{
       
   682 		    iContainer->SetRect( ClientRect() );
       
   683 		    iContainer->DrawDeferred();
       
   684 			}
       
   685 	    }
       
   686 	IRLOG_DEBUG( "CIRHistoryListView::ConstructToolbarL - Exiting" );
       
   687 }
       
   688 
       
   689 // --------------------------------------------------------------------------
       
   690 // CIRHistoryListView::DynInitToolbarL()
       
   691 // Dynamically Updates the toolbar
       
   692 // --------------------------------------------------------------------------
       
   693 //
       
   694 void CIRHistoryListView::DynInitToolbarL( TInt /*aResourceId*/, CAknToolbar* /*aToolbar*/ )
       
   695 {
       
   696 	IRLOG_DEBUG( "CIRHistoryListView::DynInitToolbarL - Entering" );
       
   697 	
       
   698 	IRLOG_DEBUG( "CIRHistoryListView::DynInitToolbarL - Exiting" );
       
   699 }
       
   700 
       
   701 // --------------------------------------------------------------------------
       
   702 // CIRHistoryListView::OfferToolbarEventL
       
   703 // Handles key events
       
   704 // --------------------------------------------------------------------------
       
   705 //
       
   706 void CIRHistoryListView::OfferToolbarEventL( TInt aCommand )
       
   707 	{
       
   708 	IRLOG_DEBUG( "CIRHistoryListView::OfferToolbarEventL - Entering" );
       
   709 	HandleCommandL(aCommand);
       
   710 	IRLOG_DEBUG( "CIRHistoryListView::OfferToolbarEventL - Exiting" );
       
   711 	}
       
   712 
       
   713 
       
   714 
       
   715 
       
   716 // ---------------------------------------------------------------------------
       
   717 // void CIRHistoryListView::LaunchMusicShopL()
       
   718 // To Launch Find in Shop Option
       
   719 // ---------------------------------------------------------------------------
       
   720 //
       
   721 void CIRHistoryListView::LaunchMusicShopL()
       
   722 	{
       
   723 #ifdef MUSICSHOP_AVAILABLE
       
   724 	  IRLOG_DEBUG( "Entered CIRHistoryListView::LaunchMusicShopL() Entering" );
       
   725 
       
   726 	  TApaTaskList tasList( iCoeEnv->WsSession() );
       
   727 	  TApaTask task = tasList.FindApp( KUidMusicStore );
       
   728 
       
   729 	  if ( task.Exists() )
       
   730 		  {
       
   731 		    task.BringToForeground();
       
   732 		  }
       
   733 	  else
       
   734 		  {
       
   735 		    RApaLsSession session;
       
   736 		    if ( KErrNone == session.Connect() )
       
   737 			    {
       
   738 			      CleanupClosePushL( session );
       
   739 			      TThreadId threadId;
       
   740 			      session.CreateDocument( KNullDesC, KUidMusicStore, threadId );
       
   741 			      CleanupStack::PopAndDestroy(&session);
       
   742 			    }
       
   743 		  }
       
   744 
       
   745 	  IRLOG_DEBUG( "Leaving CIRHistoryListView::LaunchMusicShopL() Exiting" );
       
   746 #endif
       
   747    }
       
   748 
       
   749 // ---------------------------------------------------------------------------
       
   750 // CIRHistoryListView::DoFindInMusicShopL()
       
   751 // To Launch Find in Shop Option
       
   752 // ---------------------------------------------------------------------------
       
   753 //
       
   754 void CIRHistoryListView::DoFindInMusicShopL( const TDesC& aSongName,
       
   755                                              const TDesC& aArtistName,
       
   756                                              const TDesC& aAlbumName )
       
   757 	{
       
   758 	IRLOG_DEBUG( "Entered CIRHistoryListView::DoFindInMusicShopL() - Entering" );
       
   759 #ifdef MUSICSHOP_AVAILABLE
       
   760 	HBufC* url = NULL;
       
   761 	url = iMPXFindInShop->CreateSearchURLL( aSongName,
       
   762 	             							 aArtistName,
       
   763 	             							 aAlbumName,
       
   764 	             							 KNullDesC,     // Composer - Not used
       
   765 	              							 KNullDesC );   // Genre - Not used
       
   766 	CleanupStack::PushL(url);   // the pointer will be poped
       
   767 	RProperty::Set( KUidMusicStore,
       
   768 	KMShopCategoryId,
       
   769 	KFindInMShopKeyValid );  // Set Key to Valid
       
   770 
       
   771 	RProperty::Set( KUidMusicStore,
       
   772 	KMShopCategoryName,
       
   773 	*url );
       
   774 	LaunchMusicShopL();
       
   775 	if(url)
       
   776 		{
       
   777 		CleanupStack::PopAndDestroy(url);
       
   778 		}
       
   779 	REComSession::FinalClose();
       
   780 #else
       
   781     if(aSongName.Length() > 0 || aArtistName.Length() > 0 || aAlbumName.Length() > 0)
       
   782         {
       
   783         // do nothing, just remove build warnings.
       
   784         }
       
   785 	IRLOG_DEBUG( "Leaving CIRHistoryListView::DoFindInMusicShopL() - Exiting" );
       
   786 #endif
       
   787 	}
       
   788 
       
   789 // ---------------------------------------------------------------------------
       
   790 // CIRHistoryListView::FindInShopOption()
       
   791 // To Launch Find in Shop Option when selected from the toolbar
       
   792 // ---------------------------------------------------------------------------
       
   793 //
       
   794 
       
   795 void CIRHistoryListView:: FindInShopOptionL()
       
   796 	{
       
   797 	IRLOG_DEBUG( "CIRHistoryListView::FindInShopOptionL - Entering" );
       
   798 	TInt itemIndex = iContainer->GetCurrentFocussedLeaf();
       
   799 	if(itemIndex==-1)
       
   800 		{
       
   801 	    IRLOG_DEBUG( "CIRHistoryListView::FindInShopOptionL - Exiting" );
       
   802 		return;
       
   803 		}
       
   804 	if(itemIndex>=0 && itemIndex<iHistoryDataArr.Count())
       
   805 		{	
       
   806 		DoFindInMusicShopL(iHistoryDataArr[itemIndex]->GetSongInfo(),
       
   807 		iHistoryDataArr[itemIndex]->GetArtistInfo(),
       
   808 		KNullDesC);
       
   809 		}
       
   810 	IRLOG_DEBUG( "CIRHistoryListView::FindInShopOptionL - Exiting" );
       
   811 	}
       
   812 // ---------------------------------------------------------------------------
       
   813 //Notifies all observers whose network request is active
       
   814 // to reissue the request  
       
   815 //NotifyActiveNetworkObserversL()
       
   816 // ---------------------------------------------------------------------------
       
   817 
       
   818 void CIRHistoryListView::NotifyActiveNetworkObserversL(TIRNetworkEvent aEvent)
       
   819 	{
       
   820 	IRLOG_DEBUG( "CIRHistoryListView::NotifyActiveNetworkObserversL - Entering" );
       
   821 	
       
   822 	switch(aEvent)
       
   823 	{
       
   824 	case ENetworkConnectionDisconnected:
       
   825 		{
       
   826 		iNowPlayingWrapper->HandleNetworkDisconnected();
       
   827 		}
       
   828 		break;
       
   829 	case ENetworkConnectionEstablished:
       
   830 		{
       
   831 		if( !iUi->CheckAndNotifyLowDiskSpaceL() && iContainer )
       
   832 			{
       
   833 			if(iRequestPending || iUi->iNetworkController->IsHandingOverConnection())
       
   834 				{
       
   835 				if(iAddToFav)
       
   836 					{
       
   837 					iAddToFav=ETrue;
       
   838 					iListenRequest=EFalse;
       
   839 					iContainer->AddStationToFavoritesL(EAddtoFavouritesCmd);
       
   840 					}
       
   841 				else if(iListenRequest)
       
   842 					{
       
   843 					iAddToFav=EFalse;
       
   844 					iListenRequest=EFalse;
       
   845 					iNowPlayingWrapper->SetView(EHistoryView);
       
   846 					TInt index=iContainer->GetCurrentFocussedNode();
       
   847 					iContainer->ListenUrlL(index );
       
   848 					}
       
   849 				else
       
   850 					{
       
   851 						
       
   852 					}
       
   853 				}
       
   854 			}
       
   855 		if(iUi->iNetworkController->IsHandingOverConnection())
       
   856 			{
       
   857 			ResetPendingRequests(EFalse);
       
   858 			}
       
   859 		}
       
   860 	}
       
   861 
       
   862 	IRLOG_DEBUG( "CIRHistoryListView::NotifyActiveNetworkObserversL - Exiting" );
       
   863 	}
       
   864 	
       
   865 	
       
   866 
       
   867 // -----------------------------------------------------------------------------
       
   868 // Notified by network controller when user cancels network connection, to reset 
       
   869 // the pending requests  
       
   870 // ResetPendingRequests()
       
   871 // -----------------------------------------------------------------------------
       
   872 void CIRHistoryListView::ResetPendingRequests(TBool aValue)
       
   873 	{
       
   874 	iRequestPending = aValue;
       
   875 	iListenRequest  = aValue;
       
   876 	iAddToFav = aValue;
       
   877 	}
       
   878 
       
   879 	
       
   880 	
       
   881 	
       
   882 // ---------------------------------------------------------------------------
       
   883 // From class CAknView.
       
   884 // Foreground event handling function.
       
   885 // ---------------------------------------------------------------------------
       
   886 //
       
   887 void CIRHistoryListView::HandleForegroundEventL( TBool aForeground )
       
   888     {
       
   889 	IRLOG_DEBUG( "CIRHistoryListView::HandleForegroundEventL - Entering" );
       
   890 	CIRBaseView::HandleForegroundEventL( aForeground );
       
   891    
       
   892 	if ( aForeground )
       
   893 		{
       
   894 		if(iContainer)
       
   895 			{
       
   896 			MAknsSkinInstance * skin=AknsUtils::SkinInstance () ;
       
   897 		    TRgb color;
       
   898 		    TInt skinColor=AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors,
       
   899 		    				                                      EAknsCIQsnTextColorsCG6 );
       
   900 			if(color.Gray2()!=0)
       
   901 				{
       
   902 				CreateAndSetToolbarL(R_IR_HISTORY_WHITE_TOOLBAR);
       
   903 				}
       
   904 			else
       
   905 				{
       
   906 				CreateAndSetToolbarL(R_IR_HISTORY_BLACK_TOOLBAR);	
       
   907 				}
       
   908 	        if( AknLayoutUtils::PenEnabled() && Toolbar() )
       
   909 				{
       
   910 				Toolbar()->SetToolbarObserver( this );
       
   911 				}
       
   912 			ConstructToolbarL();
       
   913 			}
       
   914 		}
       
   915 	IRLOG_DEBUG( "CIRHistoryListView::HandleForegroundEventL" );
       
   916     }
       
   917 
       
   918 // ---------------------------------------------------------------------------
       
   919 // GetFindInShopInstance()
       
   920 // Get the FindInShop Instance is null or not.
       
   921 // ---------------------------------------------------------------------------
       
   922 //
       
   923 TBool CIRHistoryListView::GetFindInShopInstance()
       
   924 	{
       
   925 	TBool ret = EFalse;
       
   926 	if(iMPXFindInShop)
       
   927 		{
       
   928 		ret = ETrue;	
       
   929 		}
       
   930 	IRLOG_DEBUG( "CIRHistoryListView::GetFindInShopInstance" );
       
   931 	return ret;	
       
   932 	}
       
   933 // ---------------------------------------------------------
       
   934 // CIRHistoryListView::HandleSystemEventL
       
   935 // from base class MIRSystemEventObserver
       
   936 // ---------------------------------------------------------
       
   937 //
       
   938 void CIRHistoryListView::HandleSystemEventL(TIRSystemEventType aEventType)
       
   939 	{
       
   940 	IRLOG_DEBUG(" CIRHistoryListView::HandleSystemEventL - Entering");
       
   941 	
       
   942 	switch (aEventType)
       
   943 		{
       
   944 		case EIRCallActivated:
       
   945 			{
       
   946 			if( iUi->GetNetworkControllerInstance()->IdentifyConnectionType() != EWiFi )
       
   947 				{
       
   948 				if(iUi->iIsdsWrapper->iIsdsWaitDialog)
       
   949 					{
       
   950 					TRAP_IGNORE( iUi->iIsdsWrapper->DestroyWaitDialogL() );
       
   951 					}
       
   952 				if(!iCallRequestPending && iCommand==EAddtoFavouritesCmd)
       
   953 					{
       
   954 					iUi->iIsdsWrapper->IsdsCancelRequest();
       
   955 					iCallRequestPending = ETrue;
       
   956 					}
       
   957 				if(iUi->iIsdsWrapper->GetListenRequest())
       
   958 					{
       
   959 					iNowPlayingWrapper->DestroyWaitDialogL();
       
   960 					iUi->iIsdsWrapper->SetListenRequest(EFalse);
       
   961 					iUi->iIsdsWrapper->IsdsCancelRequest();
       
   962 					}
       
   963 				}
       
   964 			break;
       
   965 			}
       
   966 		case EIRCallDeactivated:
       
   967 			{
       
   968 			if(iCallRequestPending && iCommand==EAddtoFavouritesCmd)
       
   969 				{
       
   970 				iCallRequestPending = EFalse;
       
   971 				HandleCommandL(iCommand);
       
   972 				}
       
   973 			break;
       
   974 			}
       
   975 		default:
       
   976 			{
       
   977 			break;
       
   978 			}
       
   979 		}
       
   980 	IRLOG_DEBUG( "CIRHistoryListView::HandleSystemEventL - Exiting." );
       
   981 	}	
       
   982 // ---------------------------------------------------------------------------
       
   983 // RefreshHistoryL()
       
   984 // Refreshes the History view while Synchronisation.
       
   985 // ---------------------------------------------------------------------------
       
   986 //
       
   987 void CIRHistoryListView::RefreshHistoryL()
       
   988 {
       
   989 	IRLOG_DEBUG( "CIRHistoryListView::RefreshHistoryL - Entering" );
       
   990 	iHistoryDataArr.ResetAndDestroy();
       
   991 
       
   992 	if(iContainer)
       
   993 	{
       
   994 		iContainer->ClearHistoryListL();
       
   995 	}
       
   996 
       
   997 	GetAllListL();
       
   998 	if(iContainer)
       
   999 	{
       
  1000 		iContainer->UpdateAllL(iHistoryDataArr);
       
  1001 	}
       
  1002 	IRLOG_DEBUG( "CIRHistoryListView::RefreshHistoryL - Exiting" );
       
  1003 }
       
  1004 // ---------------------------------------------------------------------------
       
  1005 // HistoryEngineInstance()
       
  1006 // Gets the history Engine object Instance.
       
  1007 // ---------------------------------------------------------------------------
       
  1008 //
       
  1009 CIRSongHistoryEngine* CIRHistoryListView::HistoryEngineInstance()
       
  1010 {
       
  1011 	IRLOG_DEBUG( "CIRHistoryListView::HistoryEngineInstance - Exiting" );
       
  1012 	return iHistoryEngine ;
       
  1013 }