internetradio2.0/uisrc/irplsview.cpp
changeset 3 ee64f059b8e1
parent 2 2e1adbfc62af
child 4 3f2d53f144fe
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
     1 /*
       
     2 * Copyright (c) 2006-2007 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 pls list
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <hlplch.h>
       
    20 
       
    21 #include <internetradio.rsg>
       
    22 #include <internetradio.mbg>
       
    23 
       
    24 #include "ir.hrh"
       
    25 #include "ircommon.h"
       
    26 #include "irdebug.h"
       
    27 #include "irplsview.h"
       
    28 #include "irplscontainer.h"
       
    29 #include "irui.h"
       
    30 #include "irbaseview.h"
       
    31 #include "irsettings.h"
       
    32 #include "irnowplayingwrapper.h"
       
    33 #include "irisdspreset.h"
       
    34 #include <eikclbd.h>
       
    35 #include <akntoolbar.h>
       
    36 
       
    37 #include "irnetworkcontroller.h" 	
       
    38 #include "iractivenetworkobserver.h"
       
    39 
       
    40 //-----------------------------------------------------------------------------
       
    41 //  CIRPlsView::NewL
       
    42 //  Creates a new instance of pls view
       
    43 //-----------------------------------------------------------------------------
       
    44 //
       
    45 CIRPlsView* CIRPlsView::NewL(const TRect& aRect)
       
    46     {
       
    47 	IRLOG_DEBUG( "CIRPlsView::NewL - Entering" );
       
    48     CIRPlsView* self = CIRPlsView::NewLC(aRect);
       
    49     CleanupStack::Pop(self);
       
    50 	IRLOG_DEBUG( "CIRPlsView::NewL - Exiting." );
       
    51     return self;
       
    52     }
       
    53 
       
    54 //-----------------------------------------------------------------------------
       
    55 //  CIRPlsView::NewLC
       
    56 //  Creates a new instance of pls view and leaves it on the cleanup stack.
       
    57 //-----------------------------------------------------------------------------
       
    58 //
       
    59 CIRPlsView* CIRPlsView::NewLC(const TRect& aRect)
       
    60     {
       
    61     IRLOG_DEBUG( "CIRPlsView::NewLC - Entering" );
       
    62     CIRPlsView* self = new (ELeave) CIRPlsView;
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL(aRect);
       
    65 	IRLOG_DEBUG( "CIRPlsView::NewLC - Exiting." );
       
    66     return self;
       
    67     }
       
    68 
       
    69 //----------------------------------------------------------------------------- 
       
    70 //  CIRPlsView::CIRPlsView()
       
    71 //  Default constructor
       
    72 //-----------------------------------------------------------------------------
       
    73 //
       
    74 CIRPlsView::CIRPlsView():iContainer(NULL) 
       
    75     {
       
    76 	IRLOG_DEBUG( "CIRPlsView::CIRPlsView" );
       
    77 	SetCurrentTopItem(0);
       
    78     }
       
    79 
       
    80 //----------------------------------------------------------------------------- 
       
    81 //  CIRPlsView::~CIRPlsView()
       
    82 //  Destructor
       
    83 //-----------------------------------------------------------------------------
       
    84 //
       
    85 CIRPlsView::~CIRPlsView()
       
    86     {
       
    87 	IRLOG_DEBUG( "CIRPlsView::~CIRPlsView - Entering" );
       
    88     if ( iContainer )
       
    89         {
       
    90         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    91         delete iContainer;
       
    92     	}
       
    93 	if( AknLayoutUtils::PenEnabled() && Toolbar() )
       
    94 		{
       
    95 		Toolbar()->SetToolbarVisibility(EFalse, EFalse);
       
    96 		Toolbar()->SetToolbarObserver( NULL );
       
    97 		}
       
    98 	IRLOG_DEBUG( "CIRPlsView::~CIRPlsView - Exiting." );
       
    99     }
       
   100 
       
   101 //-----------------------------------------------------------------------------
       
   102 //  CIRPlsView::ConstructL
       
   103 //  Second phase constructor
       
   104 //-----------------------------------------------------------------------------
       
   105 //
       
   106 void CIRPlsView::ConstructL(const TRect& /*aRect*/)
       
   107 	{
       
   108 	IRLOG_DEBUG( "CIRPlsView::ConstructL - Entering" );
       
   109     CIRBaseView::ConstructL(R_IR_PLSVIEW);
       
   110 	MAknsSkinInstance * skin=AknsUtils::SkinInstance () ;
       
   111     TRgb color;
       
   112     TInt skinColor=AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors,
       
   113     				                                      EAknsCIQsnTextColorsCG6 );
       
   114 	if(color.Gray2()!=0)
       
   115 		{
       
   116 		CreateAndSetToolbarL(R_NOW_PLSLIST_WHITE_TOOLBAR);
       
   117 		}
       
   118 	else
       
   119 		{
       
   120 		CreateAndSetToolbarL(R_NOW_PLSLIST_BLACK_TOOLBAR);	
       
   121 		}
       
   122 	if( AknLayoutUtils::PenEnabled() && Toolbar() )
       
   123 		{
       
   124 		Toolbar()->SetToolbarObserver( this );
       
   125 		}
       
   126 	SetCurrentFocus(0);
       
   127 	iRequestPending = EFalse;
       
   128 	IRLOG_DEBUG( "CIRPlsView::ConstructL - Exiting." );
       
   129 	}
       
   130 
       
   131 	
       
   132 //-----------------------------------------------------------------------------
       
   133 //  TUid CIRPlsView::Id()
       
   134 //  This returns the view ID
       
   135 //-----------------------------------------------------------------------------
       
   136 //
       
   137 TUid CIRPlsView::Id() const
       
   138     {
       
   139     IRLOG_DEBUG( "CIRPlsView::Id" );
       
   140     return KIRPlsViewID;
       
   141     }
       
   142     
       
   143 // ----------------------------------------------------------------------------
       
   144 //  This is called when a view needs to be activated. 
       
   145 //  This creates container with its controls.
       
   146 //  It also receives messages sent to the view.
       
   147 //  aPrevViewId is passed s.t. we can return to the previous view.
       
   148 //  aCustomMessageId is an ID for the message.
       
   149 //  aCustomMessage is the actual message.
       
   150 // ----------------------------------------------------------------------------
       
   151 //
       
   152 void CIRPlsView::DoActivateL(const TVwsViewId& aPrevViewId,TUid /*aCustomMessageId*/,
       
   153    const TDesC8& aCustomMessage)
       
   154 	{
       
   155 	IRLOG_DEBUG( "CIRPlsView::DoActivateL - Entering" );
       
   156 	iUi->iPresentViewID = KIRPlsViewID;
       
   157     if ( !iContainer )
       
   158 		{
       
   159 		iContainer =CIRPlsContainer::NewL(ClientRect(),*this);
       
   160 		iContainer->SetMopParent( this );
       
   161 		AppUi()->AddToViewStackL( *this, iContainer );
       
   162 		}
       
   163     else
       
   164        {
       
   165 	    // we must notify a resource change in order to update the skin context
       
   166 	    // This is a flaw of CEikFormattedCellListBox
       
   167 		iContainer->SetRect(ClientRect());
       
   168     	iContainer->HandleResourceChange(KEikDynamicLayoutVariantSwitch);
       
   169        }
       
   170 	ConstructToolbarL();
       
   171     iContainer->ActivateL();
       
   172     iContainer->MakeVisible( ETrue );
       
   173     SetTitleL( R_IRAPP_FEATURE_FILE_TITLE );
       
   174     CIRBaseView::DoActivateL( aPrevViewId, TUid::Uid(1), aCustomMessage );
       
   175     HandleStatusPaneSizeChange();
       
   176     iUi->iNetworkController->RegisterActiveNetworkObserverL(*this);
       
   177     IRLOG_DEBUG( "CIRPlsView::DoActivateL - Exiting" );
       
   178 	}
       
   179 	
       
   180 // ----------------------------------------------------------------------------
       
   181 // CIRPlsView::DoDeactivate()
       
   182 // This is called when a view needs to be deactivated. 
       
   183 // This destroys container with its controls.
       
   184 // ----------------------------------------------------------------------------
       
   185 //
       
   186 void CIRPlsView::DoDeactivate()
       
   187 	{
       
   188 	IRLOG_DEBUG( "CIRPlsView::DoDeactivate - Entering" );
       
   189 	if ( iContainer )
       
   190 		{
       
   191 	    SetCurrentFocus(iContainer->GetCurrentItemIndex());
       
   192 		SetCurrentTopItem(iContainer->GetListBoxTopIndex());
       
   193         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   194         delete iContainer;
       
   195  		iContainer = NULL;
       
   196 		}
       
   197 	if( AknLayoutUtils::PenEnabled() && Toolbar() )
       
   198 		{
       
   199 		Toolbar()->SetToolbarVisibility(EFalse, EFalse);
       
   200 		Toolbar()->SetToolbarObserver( NULL );
       
   201 		}
       
   202     iUi->iNetworkController->DeleteActiveNetworkObserver(*this);
       
   203 	IRLOG_DEBUG( "CIRPlsView::DoDeactivate - Exiting." );
       
   204 	}
       
   205 	
       
   206 // ----------------------------------------------------------------------------
       
   207 //  CIRPlsView::HandleCommandL(TInt aCommand) 
       
   208 //  Command handling function
       
   209 // ----------------------------------------------------------------------------
       
   210 //	
       
   211 void CIRPlsView::HandleCommandL(TInt aCommand)
       
   212 	{
       
   213 	IRLOG_DEBUG( "CIRPlsView::HandleCommandL - Entering" );
       
   214 	iCurrentFocus = iContainer->GetCurrentItemIndex();	
       
   215     
       
   216     // handle the corresponding command selected by the user through options.
       
   217 	switch(aCommand)
       
   218 		{
       
   219 	
       
   220 		case EListenCmd:
       
   221 			{
       
   222 			iUi->SetListenFromPls(ETrue);
       
   223 			if( iUi->VerifyNetworkConnectivityL() )
       
   224 				{
       
   225 				iRequestPending = ETrue;
       
   226 				break;
       
   227 				}
       
   228 			else
       
   229 				{
       
   230 				SetCurrentFocus(iContainer->GetCurrentItemIndex());
       
   231 				iContainer->ListenToStationL(); 
       
   232 				}
       
   233 			   
       
   234      		}
       
   235 		    break;
       
   236 
       
   237 		case ESaveCmd:
       
   238 			{  
       
   239 			if( !iUi->CheckAndNotifyLowDiskSpaceL() )
       
   240 				{
       
   241      			iContainer->SaveL();
       
   242 				}
       
   243 			}	
       
   244 			break;
       
   245 			
       
   246 		case ESaveAllCmd:
       
   247 			{
       
   248 			if( !iUi->CheckAndNotifyLowDiskSpaceL() )
       
   249 				{
       
   250 				iContainer->SaveAllL();
       
   251 				}
       
   252 		 	}
       
   253 			break;
       
   254 			
       
   255 		case EGotoNowPlayingViewCmd:
       
   256 		    {
       
   257 		    SetCurrentFocus(iContainer->GetCurrentItemIndex());
       
   258 			iUi->SetHistory(EFalse);
       
   259 			iUi->SavePrevIDL(KIRMainChoiceViewID,aCommand); 
       
   260 		    }
       
   261 		    break;
       
   262 		    
       
   263 		case ESettingsCmd:
       
   264 		    {
       
   265 		    SetCurrentFocus(iContainer->GetCurrentItemIndex());
       
   266 		    AppUi()->ActivateLocalViewL(KIRSettingsViewId);
       
   267 		    }
       
   268 		    break;
       
   269 		    
       
   270 	    case EHelpCmd:
       
   271 			{
       
   272 			if( !iUi->CheckAndNotifyLowDiskSpaceL() )
       
   273 				{
       
   274 				SetCurrentFocus(iContainer->GetCurrentItemIndex());
       
   275 	            HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   276 	            			 AppUi()->AppHelpContextL() );
       
   277 				}
       
   278 			}
       
   279             break;
       
   280             
       
   281 		case EGotoMainView:
       
   282 			{
       
   283 			_LIT8(KNull,"");
       
   284 			AppUi()->ActivateLocalViewL( KIRMainChoiceViewID ,KMainViewLaunch ,KNull);
       
   285 			}
       
   286 	    	break;   
       
   287 		default:
       
   288 			{
       
   289 			CIRBaseView::HandleCommandL( EAknSoftkeyExit );	
       
   290 			}
       
   291 
       
   292 		}
       
   293 	IRLOG_DEBUG( "CIRPlsView::HandleCommandL - Exiting." );
       
   294 	}
       
   295 	
       
   296 // ----------------------------------------------------------------------------
       
   297 // CIRPlsView::DynInitMenuPaneL()
       
   298 // Dynamically handles menu pane.
       
   299 // ----------------------------------------------------------------------------
       
   300 //
       
   301 void CIRPlsView::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
       
   302 	{
       
   303 	IRLOG_DEBUG( "CIRPlsView::DynInitMenuPaneL - Entering" );
       
   304 	// Pls view options menu  
       
   305 	CIRUi* appUi = static_cast<CIRUi*>( AppUi() );  
       
   306 	if(aResourceId == R_IR_MENU_PLS  )
       
   307 		{
       
   308         	if(!aMenuPane) User::Leave(KErrNotFound);
       
   309         	{   
       
   310 				// Now Playing option
       
   311 				if(iNowPlayingWrapper->iPlaying)
       
   312 					{
       
   313 					 aMenuPane->SetItemDimmed(EGotoNowPlayingViewCmd,EFalse);
       
   314 					}
       
   315 				else
       
   316 					{
       
   317 					 aMenuPane->SetItemDimmed(EGotoNowPlayingViewCmd,ETrue);
       
   318 					}
       
   319 				if(iUi->IsFirstTime())
       
   320 					{
       
   321 					aMenuPane->SetItemDimmed(EGotoMainView,ETrue);	
       
   322 					}
       
   323 				else
       
   324 					{
       
   325 					aMenuPane->SetItemDimmed(EGotoMainView,EFalse);	
       
   326 					}
       
   327         	}
       
   328 		}
       
   329 	IRLOG_DEBUG( "CIRPlsView::DynInitMenuPaneL - Exiting." );
       
   330 	}
       
   331 	
       
   332 // ---------------------------------------------------------------------------
       
   333 // CIRPlsView::ConstructToolbarL()
       
   334 // Coonstructs the toolbar for the view.
       
   335 // ---------------------------------------------------------------------------
       
   336 //    
       
   337 void CIRPlsView::ConstructToolbarL()
       
   338 	{
       
   339 	IRLOG_DEBUG( "CIRPlsView::ConstructToolbarL - Entering." );
       
   340 
       
   341 	TInt count = (iUi->iURLs.Count());
       
   342     if(Toolbar())
       
   343 	    {
       
   344 		if((count==0))
       
   345 			{
       
   346 			Toolbar()->SetItemDimmed(ESaveCmd,ETrue,ETrue);
       
   347 			Toolbar()->SetItemDimmed(EListenCmd,ETrue,ETrue);
       
   348 			}
       
   349 		else
       
   350 			{
       
   351 			Toolbar()->SetItemDimmed(ESaveCmd,EFalse,ETrue);
       
   352 			Toolbar()->SetItemDimmed(EListenCmd,EFalse,ETrue);
       
   353 			}
       
   354 		if((count<=2))
       
   355 			{
       
   356 			Toolbar()->SetItemDimmed(ESaveAllCmd,ETrue,ETrue);
       
   357 			}
       
   358 		else
       
   359 			{
       
   360 			Toolbar()->SetItemDimmed(ESaveAllCmd,EFalse,ETrue);
       
   361 			}
       
   362 		Toolbar()->SetToolbarVisibility( ETrue );
       
   363 
       
   364 	    // Update rect, as changes in toolbar visibility also affect layout.
       
   365 	    if(iContainer)
       
   366 		    {
       
   367 		    iContainer->SetRect( ClientRect() );
       
   368 		    iContainer->DrawDeferred();
       
   369 		    }
       
   370 	    }
       
   371 	IRLOG_DEBUG( "CIRPlsView::ConstructToolbarL - Exiting." );
       
   372 	}
       
   373 // ---------------------------------------------------------------------------
       
   374 // CIRPlsView::ConstructToolbarL()
       
   375 // Dynamically initialises a tool bar..
       
   376 // ---------------------------------------------------------------------------
       
   377 //    
       
   378 void CIRPlsView::DynInitToolbarL( TInt /*aResourceId*/, CAknToolbar* /*aToolbar*/ )
       
   379 	{
       
   380 	IRLOG_DEBUG( "CIRPlsView::DynInitToolbarL - Entering." );
       
   381 	IRLOG_DEBUG( "CIRPlsView::DynInitToolbarL - Exiting." );
       
   382     }
       
   383 		
       
   384 // ---------------------------------------------------------------------------
       
   385 // CIRMainView::OfferToolbarEventL()
       
   386 // catch the selection key event and perform the operation according to it...
       
   387 // ---------------------------------------------------------------------------
       
   388 void CIRPlsView::OfferToolbarEventL
       
   389         ( TInt aCommand )
       
   390 	{
       
   391 	IRLOG_DEBUG( "CIRPlsView::OfferToolbarEventL - Entering." );
       
   392 	HandleCommandL(aCommand);
       
   393 	IRLOG_DEBUG( "CIRPlsView::OfferToolbarEventL - Exiting." );
       
   394 	}
       
   395 // ---------------------------------------------------------------------------
       
   396 // CIRPlsView::HandleStatusPaneSizeChange()
       
   397 // 
       
   398 // ---------------------------------------------------------------------------
       
   399 //	
       
   400 void CIRPlsView::HandleStatusPaneSizeChange()
       
   401     {
       
   402     IRLOG_DEBUG( "CIRPlsView::HandleStatusPaneSizeChange - Entering." );
       
   403     // the client rect is also set here after screen orientation change
       
   404     if (iContainer )
       
   405         {
       
   406         iContainer->SetRect( ClientRect() );
       
   407         }
       
   408     IRLOG_DEBUG( "CIRPlsView::HandleStatusPaneSizeChange - Exiting." );
       
   409     }
       
   410 // ---------------------------------------------------------------------------
       
   411 // From class CAknView.
       
   412 // Foreground event handling function.
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 void CIRPlsView::HandleForegroundEventL( TBool aForeground )
       
   416 	{
       
   417 	IRLOG_DEBUG( "CIRMainView::HandleForegroundEventL - Entering" );
       
   418 	CIRBaseView::HandleForegroundEventL( aForeground );
       
   419 	if(aForeground)
       
   420 	{
       
   421 	if(iContainer)
       
   422 		{
       
   423 		MAknsSkinInstance * skin=AknsUtils::SkinInstance () ;
       
   424 	    TRgb color;
       
   425 	    TInt skinColor=AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors,
       
   426 	    				                                      EAknsCIQsnTextColorsCG6 );
       
   427 		if(color.Gray2()!=0)
       
   428 			{
       
   429 			CreateAndSetToolbarL(R_NOW_PLSLIST_WHITE_TOOLBAR);
       
   430 			}
       
   431 		else
       
   432 			{
       
   433 			CreateAndSetToolbarL(R_NOW_PLSLIST_BLACK_TOOLBAR);	
       
   434 			}
       
   435         if( AknLayoutUtils::PenEnabled() && Toolbar() )
       
   436 			{
       
   437 			Toolbar()->SetToolbarObserver( this );
       
   438 			}
       
   439 		ConstructToolbarL();
       
   440 	    //iUi->iNetworkController->RegisterActiveNetworkObserver(this)
       
   441 	    //iListen = ETrue
       
   442 	    iContainer->DrawDeferred();
       
   443         Toolbar()->DrawDeferred();
       
   444 		iContainer->SecondPls();
       
   445 		}
       
   446 	}
       
   447 	IRLOG_DEBUG( "CIRMainView::HandleForegroundEventL - Exiting." );
       
   448 	}		
       
   449 
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 //Notifies all observers whose network request is active
       
   453 // to reissue the request  
       
   454 //NotifyActiveNetworkObserversL()
       
   455 // ---------------------------------------------------------------------------
       
   456 
       
   457 void CIRPlsView::NotifyActiveNetworkObserversL(TIRNetworkEvent aEvent)
       
   458 	{
       
   459 	IRLOG_DEBUG( "CIRPlsView::NotifyActiveNetworkObserversL - Entering." );
       
   460 	
       
   461 	switch(aEvent)
       
   462 	{
       
   463 	case ENetworkConnectionDisconnected:
       
   464 		{
       
   465 		iNowPlayingWrapper->HandleNetworkDisconnected();
       
   466 		}
       
   467 		break;
       
   468 	case ENetworkConnectionEstablished:
       
   469 		{
       
   470 		if(iContainer)
       
   471 			{
       
   472 			if(iRequestPending || iUi->iNetworkController->IsHandingOverConnection())
       
   473 				{
       
   474 				SetCurrentFocus(iContainer->GetCurrentItemIndex());
       
   475 				iContainer->ListenToStationL(); 
       
   476 				}
       
   477 			}
       
   478 		ResetPendingRequests(EFalse);
       
   479 		}
       
   480 	}
       
   481 
       
   482 	IRLOG_DEBUG( "CIRPlsView::NotifyActiveNetworkObserversL - Exiting." );
       
   483 	}
       
   484 	
       
   485 	
       
   486 // -----------------------------------------------------------------------------
       
   487 // Notified by network controller when user cancels network connection, to reset 
       
   488 // the pending requests  
       
   489 // ResetPendingRequests()
       
   490 // -----------------------------------------------------------------------------
       
   491 void CIRPlsView::ResetPendingRequests(TBool aValue)
       
   492 	{
       
   493 	iRequestPending = aValue;
       
   494 	}
       
   495 
       
   496 	
       
   497 
       
   498 // CIRPlsView :: SecondConstruct()
       
   499 // To again initialise when Second pls file is opened.
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 void CIRPlsView::SecondConstruct()
       
   503 	{
       
   504 	SetCurrentFocus(0);
       
   505 	SetCurrentTopItem(0);
       
   506 	iRequestPending = EFalse;
       
   507 	}