internetradio2.0/activeidlesrc/iractiveidle.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
     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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aicontentobserver.h>
       
    20 #include <aiutility.h>
       
    21 #include <aknutils.h>
       
    22 #include <apgcli.h>
       
    23 #include <bautils.h>
       
    24 #include <data_caging_path_literals.hrh>
       
    25 #include <e32property.h>
       
    26 #include <stringloader.h>
       
    27 #include <iractiveidle.rsg>
       
    28 #include <features.hrh>
       
    29 #include <eikenv.h> 
       
    30 #include <apgtask.h>
       
    31 #include "irmetadata.h"
       
    32 #include "irpubsubkeys.h"
       
    33 #include "ir.hrh"
       
    34 #include "iractiveidle.h"
       
    35 #include "iractiveidleeng.h"
       
    36 #include "iractiveidlestatedetector.h"
       
    37 #include "irdebug.h"
       
    38 #include "irplugincontentmodel.h"
       
    39 
       
    40 
       
    41 
       
    42 #include <eikenv.h>
       
    43 
       
    44 const TInt KIRMinVolumeLevel = 0;
       
    45 const TInt KIRMaxVolumeLevel  = 10;
       
    46 const TInt KIRPublishIndex = 1; // Always 1 in this plugin
       
    47 const TInt KIRActiveIdleGranularity = 3;
       
    48 
       
    49 _LIT( KIRActiveIdleResourceFileName, "iractiveidle.rsc" ); /** Filename of the Internet Radio Active Idle resource file. */
       
    50 _LIT( KIRPluginName, "iRAPP Plugin");
       
    51 _LIT(KSeparatorDot,". ");
       
    52 //_LIT(KSeparatorHyphen," - ")
       
    53 //_LIT(KSeparatorColon," : ")
       
    54 _LIT8( KIRSpace, " " );
       
    55 _LIT8( KIRCommandLineActiveIdle, "-a" );
       
    56 _LIT8( KIRCommandLineActiveIdleCommandStartNowPlayingView, "startnowplaying" );
       
    57 
       
    58 
       
    59 // ======== MEMBER FUNCTIONS ========
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CIRActiveIdle::CIRActiveIdle()
       
    63 // Constructor.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CIRActiveIdle::CIRActiveIdle()
       
    67     {
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CIRActiveIdle::ConstructL()
       
    72 // Second-phase constructor.
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CIRActiveIdle::ConstructL()
       
    76     {
       
    77     IRLOG_DEBUG( "CIRActiveIdle::ConstructL" );
       
    78     InitializeResourceLoadingL();
       
    79     iInfo.iUid = KUidIRPlugin;
       
    80     iInfo.iName.Copy( KIRPluginName );
       
    81     iContent = AiUtility::CreateContentItemArrayIteratorL( KAiIRContent );
       
    82     iResources = AiUtility::CreateContentItemArrayIteratorL( KAiIRResources );
       
    83     iEvents  = AiUtility::CreateContentItemArrayIteratorL( KAiIREvents );
       
    84     iMetaData = CIRMetaData::NewL();
       
    85     iRunningState = EIRPSApplicationUninitialized;
       
    86     IRLOG_DEBUG( "CIRActiveIdle::ConstructL - Exiting." );
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CIRActiveIdle::NewL()
       
    91 // Two-phased constructor.
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CIRActiveIdle* CIRActiveIdle::NewL()
       
    95     {
       
    96     IRLOG_DEBUG( "CIRActiveIdle::NewL" );
       
    97     CIRActiveIdle* self = new( ELeave ) CIRActiveIdle;
       
    98     CleanupStack::PushL( self );
       
    99     self->ConstructL();
       
   100     CleanupStack::Pop( self );
       
   101     IRLOG_DEBUG( "CIRActiveIdle::NewL - Exiting." );
       
   102     return self;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CIRActiveIdle::~CIRActiveIdle()
       
   107 // Destructor
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 CIRActiveIdle::~CIRActiveIdle()
       
   111     {
       
   112     IRLOG_DEBUG( "CIRActiveIdle::~CIRActiveIdle" );
       
   113     if ( iActiveIdleResourceOffset > 0 )
       
   114         {
       
   115         CCoeEnv::Static()->DeleteResourceFile( iActiveIdleResourceOffset );
       
   116         }
       
   117     iObservers.Close();
       
   118     Release( iContent );
       
   119     Release( iResources );
       
   120     Release( iEvents );
       
   121 
       
   122     delete iMetaData;
       
   123     delete iIRTerminationDetector;
       
   124     delete iEngine;
       
   125     IRLOG_DEBUG( "CIRActiveIdle::~CIRActiveIdle - Exiting." );
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CIRActiveIdle::InitializeResourceLoadingL()
       
   130 // Initialize resource file for loading resources.
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CIRActiveIdle::InitializeResourceLoadingL()
       
   134     {
       
   135     IRLOG_DEBUG( "CIRActiveIdle::InitializeResourceLoadingL" );
       
   136 
       
   137     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   138     RFs fs( coeEnv->FsSession() );
       
   139     TFileName fileName; 
       
   140     TFileName baseResource;
       
   141     TFindFile finder( fs );
       
   142     TLanguage language( ELangNone );
       
   143     
       
   144     TParsePtrC parse( KIRActiveIdleResourceFileName );
       
   145     _LIT( resourceFileWildExt, ".r*" );
       
   146 
       
   147     // Make sure to find all resource files, not only .rsc files as it may be so
       
   148     // that there is only .r01, .r02, etc. files available
       
   149     fileName.Copy( parse.Name() );
       
   150     fileName.Append( resourceFileWildExt );
       
   151 
       
   152     // TFindFile applies search order that is from 
       
   153     // drive Y to A, then Z
       
   154     CDir* entries = NULL;
       
   155     TInt err = finder.FindWildByDir( fileName , KDC_RESOURCE_FILES_DIR, entries );
       
   156     delete entries;
       
   157     entries = NULL;
       
   158     TBool found = EFalse;
       
   159     while ( !found && err == KErrNone )
       
   160         {
       
   161         // Found file
       
   162         fileName.Zero();
       
   163         TParsePtrC foundPath( finder.File() );
       
   164         fileName.Copy( foundPath.DriveAndPath() );
       
   165         fileName.Append( KIRActiveIdleResourceFileName );
       
   166         BaflUtils::NearestLanguageFile( fs, fileName, language );
       
   167         if ( language != ELangNone && BaflUtils::FileExists( fs, fileName ) )
       
   168             {
       
   169             found = ETrue;
       
   170             iActiveIdleResourceOffset = coeEnv->AddResourceFileL( fileName );
       
   171             }
       
   172         else
       
   173             {
       
   174             if ( language == ELangNone &&
       
   175                  !baseResource.Compare( KNullDesC ) &&
       
   176                  BaflUtils::FileExists( fs, fileName ) )
       
   177                 {
       
   178                 baseResource.Copy( fileName );
       
   179                 }
       
   180             err = finder.FindWild( entries );
       
   181             delete entries;
       
   182             entries = NULL;
       
   183             }
       
   184         }
       
   185 
       
   186     if ( !found && baseResource.Compare( KNullDesC ) )
       
   187         {
       
   188         // If we found *.rsc then better to use that than nothing
       
   189         if ( BaflUtils::FileExists( fs, baseResource ) )
       
   190             {
       
   191             iActiveIdleResourceOffset = coeEnv->AddResourceFileL( baseResource );
       
   192             }
       
   193         }
       
   194 
       
   195 
       
   196 
       
   197     IRLOG_DEBUG( "CIRActiveIdle::InitializeResourceLoadingL - Exiting." );
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CIRActiveIdle::LoadResourcesL()
       
   202 // Loads the required resources
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CIRActiveIdle::LoadResourcesL()
       
   206     {
       
   207     IRLOG_DEBUG( "CIRActiveIdle::LoadResourcesL" );
       
   208 
       
   209     if ( !iIRTerminationDetector )
       
   210         {
       
   211         iIRTerminationDetector = new (ELeave) CIRActiveIdleStateDetector( *this );
       
   212         }
       
   213 
       
   214     if ( !iEngine )
       
   215         {
       
   216         iEngine = CIRActiveIdleEng::NewL( *this );
       
   217         iEngine->SecondConstructL();
       
   218         }
       
   219     IRLOG_DEBUG( "CIRActiveIdle::LoadResourcesL - Exiting." );
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CIRActiveIdle::Resume()
       
   224 // Now it is allowed to actively publish data to observers.
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CIRActiveIdle::Resume( TAiTransitionReason /*aReason*/ )
       
   228     {
       
   229     IRLOG_DEBUG( "CIRActiveIdle::Resume" );
       
   230     TRAP_IGNORE( LoadResourcesL() )
       
   231     IRLOG_DEBUG( "CIRActiveIdle::Resume - Exiting." );
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // CIRActiveIdle::Suspend()
       
   236 // Not allowed to consume CPU resources, e.g MUST stop each timer,
       
   237 // cancel outstanding asynchronous operations, etc.
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CIRActiveIdle::Suspend( TAiTransitionReason /*aReason*/ )
       
   241     {
       
   242     IRLOG_DEBUG( "CIRActiveIdle::Suspend" );
       
   243 
       
   244     if ( iIRTerminationDetector )
       
   245         {
       
   246         iIRTerminationDetector->Cancel();
       
   247         }
       
   248 
       
   249     delete iEngine;
       
   250     iEngine = NULL;
       
   251     IRLOG_DEBUG( "CIRActiveIdle::Suspend - Exiting." );
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // CIRActiveIdle::Stop
       
   256 // Must free all memory and CPU resources and close all open files.
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CIRActiveIdle::Stop( TAiTransitionReason /*aReason*/ )
       
   260     {
       
   261     IRLOG_DEBUG( "CIRActiveIdle::Stop" );
       
   262     delete iIRTerminationDetector;
       
   263     iIRTerminationDetector = NULL;
       
   264     delete iEngine;
       
   265     iEngine = NULL;
       
   266     IRLOG_DEBUG( "CIRActiveIdle::Stop - Exiting." );
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // CIRActiveIdle::SubscribeL
       
   271 // Adds the content observer / subscriber to plug-in.
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 void CIRActiveIdle::SubscribeL( MAiContentObserver& aObserver )
       
   275     {
       
   276     IRLOG_DEBUG( "CIRActiveIdle::SubscribeL" );
       
   277     iObservers.AppendL( &aObserver );
       
   278     IRLOG_DEBUG( "CIRActiveIdle::SubscribeL - Exiting." );
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CIRActiveIdle::ConfigureL
       
   283 // Configures the plug-in.
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 void CIRActiveIdle::ConfigureL( RAiSettingsItemArray& /*aSettings*/ )
       
   287     {
       
   288     }
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // CIRActiveIdle::Extension
       
   292 // Returns interface extension. In S60 3.2 only event & property extensions
       
   293 // are supported.
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 TAny* CIRActiveIdle::Extension( TUid aUid )
       
   297     {
       
   298     IRLOG_DEBUG( "CIRActiveIdle::Extension" );
       
   299     TAny* ret = NULL;
       
   300     if ( aUid == KExtensionUidProperty )
       
   301     	{
       
   302         ret = static_cast<MAiPropertyExtension*>( this );
       
   303     	}
       
   304     else if ( aUid == KExtensionUidEventHandler )
       
   305     	{
       
   306         ret = static_cast<MAiEventHandlerExtension*>( this );
       
   307     	}
       
   308     else
       
   309         {
       
   310         ret = NULL;
       
   311         }
       
   312     IRLOG_DEBUG( "CIRActiveIdle::Extension - Exiting." );
       
   313     return ret;
       
   314     }
       
   315 
       
   316 // ----------------------------------------------------------------------------
       
   317 // CIRActiveIdle::GetPropertyL
       
   318 // Reads a plugin property.
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 TAny* CIRActiveIdle::GetPropertyL( TInt aProperty )
       
   322 	{
       
   323 	IRLOG_DEBUG( "CIRActiveIdle::GetPropertyL" );
       
   324     switch ( aProperty )
       
   325     	{
       
   326     	case EAiPublisherInfo:
       
   327             return &iInfo;
       
   328 
       
   329     	case EAiPublisherContent:
       
   330             return static_cast<MAiContentItemIterator*>( iContent );
       
   331 
       
   332     	case EAiPublisherResources:
       
   333             return static_cast<MAiContentItemIterator*>( iResources );
       
   334 
       
   335     	case EAiPublisherEvents:
       
   336             return static_cast<MAiContentItemIterator*>( iEvents );
       
   337 
       
   338     	default:
       
   339     	    break;
       
   340     	}
       
   341     User::Leave( KErrNotSupported );
       
   342     IRLOG_DEBUG( "CIRActiveIdle::GetPropertyL - Exiting." );
       
   343     return NULL;
       
   344 	}
       
   345 
       
   346 // ----------------------------------------------------------------------------
       
   347 // CIRActiveIdle::SetPropertyL
       
   348 // Sets a plugin property
       
   349 // ----------------------------------------------------------------------------
       
   350 //
       
   351 void CIRActiveIdle::SetPropertyL( TInt aProperty, TAny* aValue )
       
   352 	{
       
   353 	IRLOG_DEBUG( "CIRActiveIdle::SetPropertyL" );
       
   354     if ( aValue )
       
   355     	{
       
   356         switch ( aProperty )
       
   357         	{
       
   358         	case EAiPublisherInfo:
       
   359             	{
       
   360             	const TAiPublisherInfo* info =
       
   361                     static_cast<const TAiPublisherInfo*>( aValue );
       
   362             	iInfo.iUid.iUid = info->iUid.iUid;
       
   363             	iInfo.iName.Copy( info->iName );
       
   364                 break;
       
   365             	}
       
   366         	default:
       
   367                 break;
       
   368         	}
       
   369     	}
       
   370     else
       
   371     	{
       
   372     	User::Leave(KErrGeneral);
       
   373     	}
       
   374     IRLOG_DEBUG( "CIRActiveIdle::SetPropertyL - Exiting." );
       
   375 	}
       
   376 
       
   377 // ----------------------------------------------------------------------------
       
   378 // CIRActiveIdle::HandleEvent
       
   379 // Invoked by the framework when plug-in must handle an event
       
   380 // ----------------------------------------------------------------------------
       
   381 //
       
   382 void CIRActiveIdle::HandleEvent( TInt aEvent, const TDesC& /*aParam*/ )
       
   383 	{
       
   384 	IRLOG_DEBUG( "CIRActiveIdle::HandleEvent" );
       
   385 	switch ( aEvent )
       
   386     	{
       
   387        	case EAiIREventVolInc:
       
   388        	    break;
       
   389        	case EAiIREventVolDec:
       
   390        	    break;
       
   391        	case EAiIREventLaunchRadio:
       
   392     	    {
       
   393     	    TRAP_IGNORE( StartApplicationL( KUidActiveInternetRadioApp,
       
   394     	    								 KNullDesC8 ) )
       
   395     	    break;
       
   396     	    }
       
   397     	default:
       
   398             break;
       
   399     	}
       
   400     IRLOG_DEBUG( "CIRActiveIdle::HandleEvent - Exiting." );
       
   401 	}
       
   402 
       
   403 
       
   404 // ---------------------------------------------------------------------------
       
   405 // CIRActiveIdle::Clean
       
   406 // Cleans all data fields from the plugin
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 void CIRActiveIdle::Clean()
       
   410 	{
       
   411 	IRLOG_DEBUG( "CIRActiveIdle::Clean" );
       
   412     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   413     	{
       
   414         MAiContentObserver* observer = iObservers[i];
       
   415         observer->StartTransaction( reinterpret_cast<TInt32>( this ) );
       
   416         observer->Clean( *this, EAiIRContentVolume, KIRPublishIndex );
       
   417         observer->Clean( *this, EAiIRContentOneLineInfoCaption, KIRPublishIndex );
       
   418         observer->Clean( *this, EAiIRContentAppIcon, KIRPublishIndex );
       
   419         observer->Clean( *this, EAiIRContentPresetCaption, KIRPublishIndex );
       
   420         observer->Clean( *this, EAiIRContentArtistCaption, KIRPublishIndex );
       
   421         observer->Clean( *this, EAiIRContentTrackCaption, KIRPublishIndex );
       
   422         observer->Commit( reinterpret_cast<TInt32>( this ) );
       
   423     	}
       
   424     IRLOG_DEBUG( "CIRActiveIdle::Clean - Exiting." );
       
   425 	}
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // CIRActiveIdle::StartApplicationL
       
   429 // Launches an application.
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 void CIRActiveIdle::StartApplicationL( const TUid& aUid, const TDesC8& aCommandLine )
       
   433 	{
       
   434 	IRLOG_DEBUG( "CIRActiveIdle::StartApplicationL" );
       
   435 	
       
   436 	TApaTaskList taskList( CCoeEnv::Static()->WsSession() );
       
   437 	TApaTask task = taskList.FindApp( KUidActiveInternetRadioApp );
       
   438 	
       
   439 //   _LIT8(KNull,"")	
       
   440 	if ( task.Exists() )
       
   441 		{
       
   442 		
       
   443 		TPtrC8 activeIdleCmdId( KIRCommandLineActiveIdle );
       
   444     	TPtrC8 spacePtr( KIRSpace );
       
   445     
       
   446 		TPtrC8 startNowPlayingCmdvalue(
       
   447 	    KIRCommandLineActiveIdleCommandStartNowPlayingView );
       
   448 
       
   449 	    HBufC8* buf = HBufC8::NewLC(activeIdleCmdId.Length()
       
   450 	    			 + spacePtr.Length() + startNowPlayingCmdvalue.Length());
       
   451 	    TPtr8 tail( buf->Des() );
       
   452 	    
       
   453 	       
       
   454 	    tail.Append( activeIdleCmdId );
       
   455 	    tail.Append( spacePtr );
       
   456 	    tail.Append( startNowPlayingCmdvalue );
       
   457 	    task.SendMessage(KUidActiveInternetRadioApp,tail);
       
   458         task.BringToForeground();
       
   459         
       
   460         CleanupStack::PopAndDestroy( buf );
       
   461 		
       
   462 		}
       
   463 	else
       
   464 		{
       
   465 		RApaLsSession apaSession;
       
   466 	    CleanupClosePushL( apaSession );
       
   467 
       
   468 	    User::LeaveIfError( apaSession.Connect() );
       
   469 	    User::LeaveIfError( apaSession.GetAllApps() );
       
   470 
       
   471 	    TApaAppInfo appInfo;
       
   472 	    User::LeaveIfError( apaSession.GetAppInfo( appInfo, aUid ) );
       
   473 
       
   474 		CApaCommandLine* startParams = CApaCommandLine::NewLC();
       
   475 		startParams->SetExecutableNameL( appInfo.iFullName );
       
   476 		startParams->SetCommandL( EApaCommandRun );
       
   477 		startParams->SetTailEndL( aCommandLine );
       
   478 		User::LeaveIfError( apaSession.StartApp( *startParams ) );
       
   479 		CleanupStack::PopAndDestroy( 2, &apaSession );
       
   480 		}	
       
   481 	IRLOG_DEBUG( "CIRActiveIdle::StartApplicationL - Exiting." );
       
   482 	}
       
   483 
       
   484 
       
   485 // ---------------------------------------------------------------------------
       
   486 // CIRActiveIdle::HandleChannelChangeL
       
   487 // Handles channel change
       
   488 // ---------------------------------------------------------------------------
       
   489 //
       
   490 void CIRActiveIdle::HandleChannelChangeL()
       
   491 	{
       
   492 	IRLOG_DEBUG( "CIRActiveIdle::HandleChannelChangeL" );
       
   493 	RProperty::Get ( KUidActiveInternetRadioApp, KIRPSDataChannel,
       
   494 					 iChannelName );
       
   495 	RProperty::Get ( KUidActiveInternetRadioApp, KIRPSPresetIndex,
       
   496 					 iPresetIndex);
       
   497 
       
   498 	IRLOG_DEBUG3( "CIRActiveIdle::HandleChannelChangeL - iChannelName=%S, iPresetIndex=%d", &iChannelName, iPresetIndex );
       
   499 
       
   500 	HBufC* stringholder = NULL;
       
   501 	
       
   502 
       
   503 	CDesCArray* array = new (ELeave) CDesCArrayFlat(KIRActiveIdleGranularity);
       
   504 	CleanupStack::PushL( array );
       
   505 	
       
   506 	MDesCArray* list = STATIC_CAST(MDesCArray*,array);
       
   507 
       
   508 	CArrayFix<TInt>* presetCounts = new (ELeave) CArrayFixFlat<TInt>( 2 );
       
   509 	CleanupStack::PushL( presetCounts );
       
   510 	CEikonEnv* env = CEikonEnv::Static();      
       
   511 	if(iPresetIndex != 0)
       
   512 		{
       
   513 		 if(iMetaData->Artist() == KNullDesC && iMetaData->Song() == KNullDesC)
       
   514 			 {
       
   515              array->AppendL( iChannelName );
       
   516              presetCounts->AppendL( iPresetIndex );
       
   517 			 stringholder = StringLoader::LoadLC( R_IRAPP_ACTIVEIDLE_NOSTATIONDATA,*list,
       
   518 													 *presetCounts ,env );
       
   519 			 }
       
   520 		 else
       
   521 			 {
       
   522 			array->AppendL( iMetaData->Artist() ); //First string
       
   523 		    array->AppendL( iMetaData->Song() );
       
   524 		    array->AppendL( iChannelName );
       
   525 			presetCounts->AppendL( iPresetIndex );
       
   526 			stringholder = StringLoader::LoadLC( R_IRAPP_ACTIVEIDLE_STATIONDATA,*list,
       
   527 													 *presetCounts ,env );
       
   528 			 }
       
   529 			
       
   530 		}
       
   531 	else
       
   532 		{
       
   533 			array->AppendL( iMetaData->Artist() ); //First string
       
   534 		    array->AppendL( iMetaData->Song() );
       
   535 		    array->AppendL( iChannelName );
       
   536 	        stringholder = StringLoader::LoadLC( R_IRAPP_AI_NOINDEX_STATIONDATA,*list);
       
   537 		}
       
   538 	
       
   539 
       
   540     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   541 		{
       
   542 	    MAiContentObserver* observer = iObservers[i];
       
   543 
       
   544 	    observer->StartTransaction( reinterpret_cast<TInt32>( this ) );
       
   545 
       
   546 	    observer->Publish( *this, EAiIRContentOneLineInfoCaption, *stringholder,
       
   547 	    					 KIRPublishIndex );
       
   548 	    observer->Commit( reinterpret_cast<TInt32>( this ) );
       
   549 		}
       
   550 
       
   551 	CleanupStack::PopAndDestroy(stringholder);
       
   552 	CleanupStack::PopAndDestroy( presetCounts );
       
   553 
       
   554 	// Pop and delete strings array
       
   555 	CleanupStack::PopAndDestroy();
       
   556 	IRLOG_DEBUG( "CIRActiveIdle::HandleChannelChangeL - Exiting." );	IRLOG_DEBUG( "CIRActiveIdle::HandleChannelChangeL - Exiting." );
       
   557 	}
       
   558 
       
   559 
       
   560 // ---------------------------------------------------------------------------
       
   561 // CIRActiveIdle::HandleMetaDataReceivedL
       
   562 // Handles meta data changes
       
   563 // ---------------------------------------------------------------------------
       
   564 //
       
   565 void CIRActiveIdle::HandleMetaDataReceivedL( const CIRMetaData& aMetaData )
       
   566     {
       
   567 	IRLOG_DEBUG( "CIRActiveIdle::HandleMetaDataReceivedL" );
       
   568 	iMetaData->SetL( aMetaData );
       
   569 	RProperty::Get ( KUidActiveInternetRadioApp, KIRPSDataChannel,
       
   570 					 iChannelName );
       
   571 	RProperty::Get ( KUidActiveInternetRadioApp, KIRPSPresetIndex,
       
   572 					 iPresetIndex);
       
   573 
       
   574 	IRLOG_DEBUG3( "CIRActiveIdle::HandleChannelChangeL - iChannelName=%S, iPresetIndex=%d", &iChannelName, iPresetIndex );
       
   575 
       
   576 	HBufC* stringholder = NULL;
       
   577 
       
   578 	CDesCArray* array = new (ELeave) CDesCArrayFlat(KIRActiveIdleGranularity);
       
   579 	CleanupStack::PushL( array );
       
   580 	
       
   581 	MDesCArray* list = STATIC_CAST(MDesCArray*,array);
       
   582 
       
   583 	CArrayFix<TInt>* presetCounts = new (ELeave) CArrayFixFlat<TInt>( 2 );
       
   584 	CleanupStack::PushL( presetCounts );
       
   585 	CEikonEnv* env = CEikonEnv::Static();      
       
   586 	if(iPresetIndex != 0)
       
   587 		{
       
   588 		 if(iMetaData->Artist() == KNullDesC && iMetaData->Song() == KNullDesC)
       
   589 			 {
       
   590              array->AppendL( iChannelName );
       
   591              presetCounts->AppendL( iPresetIndex );
       
   592 			 stringholder = StringLoader::LoadLC( R_IRAPP_ACTIVEIDLE_NOSTATIONDATA,*list,
       
   593 													 *presetCounts ,env );
       
   594 			 }
       
   595 		 else
       
   596 			 {
       
   597 			array->AppendL( iMetaData->Artist() ); //First string
       
   598 		    array->AppendL( iMetaData->Song() );
       
   599 		    array->AppendL( iChannelName );
       
   600 			presetCounts->AppendL( iPresetIndex );
       
   601 			stringholder = StringLoader::LoadLC( R_IRAPP_ACTIVEIDLE_STATIONDATA,*list,
       
   602 													 *presetCounts ,env );
       
   603 			 }
       
   604 			
       
   605 		}
       
   606 	else
       
   607 		{
       
   608 			array->AppendL( iMetaData->Artist() ); //First string
       
   609 		    array->AppendL( iMetaData->Song() );
       
   610 		    array->AppendL( iChannelName );
       
   611 	        stringholder = StringLoader::LoadLC( R_IRAPP_AI_NOINDEX_STATIONDATA,*list);
       
   612 		}
       
   613 	
       
   614 
       
   615     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   616 		{
       
   617 	    MAiContentObserver* observer = iObservers[i];
       
   618 
       
   619 	    observer->StartTransaction( reinterpret_cast<TInt32>( this ) );
       
   620 
       
   621 	    observer->Publish( *this, EAiIRContentOneLineInfoCaption, *stringholder,
       
   622 	    					 KIRPublishIndex );
       
   623 
       
   624 	    observer->Commit( reinterpret_cast<TInt32>( this ) );
       
   625 		}
       
   626 
       
   627 	CleanupStack::PopAndDestroy(stringholder);
       
   628 	CleanupStack::PopAndDestroy( presetCounts );
       
   629 
       
   630 	// Pop and delete strings array
       
   631 	CleanupStack::PopAndDestroy();
       
   632 		
       
   633     IRLOG_DEBUG( "CIRActiveIdle::HandleMetaDataReceivedL - Exiting." );
       
   634 	}
       
   635 
       
   636 // ---------------------------------------------------------------------------
       
   637 // CIRActiveIdle::HandlePlayStopL
       
   638 // Handles data change in Stop State
       
   639 // ---------------------------------------------------------------------------
       
   640 //
       
   641 void CIRActiveIdle::HandlePlayStopL( TIRStopPlayState aState )
       
   642 	{
       
   643 	IRLOG_DEBUG( "CIRActiveIdle::HandlePlayStopL" );
       
   644 	RProperty::Get( KUidActiveInternetRadioApp, KIRPSDataChannel, iChannelName );
       
   645 	RProperty::Get(KUidActiveInternetRadioApp, KIRPSPresetIndex, iPresetIndex);
       
   646     HBufC* oneLineInfoCaption = NULL;
       
   647 	HBufC* presetCaption = NULL;
       
   648 
       
   649 	// Checks if the channel is in favourites and if it is displays
       
   650 	// the channel name with the preset index.
       
   651 	if ( iPresetIndex == 0 )
       
   652         {
       
   653         oneLineInfoCaption = iChannelName.AllocLC();
       
   654         presetCaption = iChannelName.AllocLC();
       
   655         }
       
   656 	else
       
   657         {
       
   658         TBuf<KMAXLENGTH> oneLineInfoBuffer;
       
   659         oneLineInfoBuffer.AppendNum(iPresetIndex);
       
   660         oneLineInfoBuffer.Append(KSeparatorDot);
       
   661 	    oneLineInfoBuffer.Append(iChannelName);
       
   662 	    oneLineInfoBuffer.Trim();
       
   663 	    oneLineInfoCaption = oneLineInfoBuffer.AllocLC();
       
   664         TBuf<KMAXLENGTH> presetBuffer;
       
   665 	    presetBuffer.AppendNum(iPresetIndex);
       
   666 	    presetBuffer.Append(KSeparatorDot);
       
   667 	    presetBuffer.Append(iChannelName);
       
   668 	    presetBuffer.Trim();
       
   669    	    presetCaption = presetBuffer.AllocLC();
       
   670         }
       
   671 
       
   672 	
       
   673 	
       
   674     if ( aState != EIRStateUninitialized )
       
   675         {
       
   676     	for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   677     		{
       
   678             MAiContentObserver* observer = iObservers[i];
       
   679 
       
   680             observer->StartTransaction( reinterpret_cast<TInt32>( this ) );
       
   681 
       
   682             observer->Publish( *this, EAiIRContentPresetCaption, *presetCaption,
       
   683             					KIRPublishIndex );
       
   684 
       
   685             if ( aState == EIRStatePlay )
       
   686                 {
       
   687     	        observer->Publish( *this, EAiIRContentAppIcon, EAiIRResourceIRPlayingIcon,
       
   688     	        					KIRPublishIndex );
       
   689                 }
       
   690             else
       
   691                 {
       
   692     	        observer->Publish( *this, EAiIRContentAppIcon, EAiIRResourceIRStoppedIcon,
       
   693     	        					KIRPublishIndex );
       
   694      	        observer->Publish( *this, EAiIRContentOneLineInfoCaption, *oneLineInfoCaption,
       
   695      	        					KIRPublishIndex );
       
   696                 }
       
   697 
       
   698             observer->Commit( reinterpret_cast<TInt32>( this ) );
       
   699     		}
       
   700         }
       
   701 
       
   702 	CleanupStack::PopAndDestroy( presetCaption );
       
   703 	CleanupStack::PopAndDestroy( oneLineInfoCaption );
       
   704 	IRLOG_DEBUG( "CIRActiveIdle::HandlePlayStopL - Exiting." );
       
   705 	}
       
   706 
       
   707 // ---------------------------------------------------------------------------
       
   708 // CIRActiveIdle::HandleVolumeChangeL
       
   709 // Handles volume change
       
   710 // ---------------------------------------------------------------------------
       
   711 //
       
   712 void CIRActiveIdle::HandleVolumeChangeL( const TInt aVolume )
       
   713 	  {
       
   714 	IRLOG_DEBUG( "CIRActiveIdle::HandleVolumeChangeL" );
       
   715 	if ( aVolume >= KIRMinVolumeLevel && aVolume <= KIRMaxVolumeLevel )
       
   716 	    {
       
   717         TInt resourceId( EAiIRResourceVol1 );
       
   718     	switch ( aVolume )
       
   719     	    {
       
   720     	    case EVolumeLevel0:
       
   721     	        {
       
   722     	        resourceId = EAiIRResourceVol0;
       
   723     	        break;
       
   724     	        }
       
   725     	    case EVolumeLevel1:
       
   726     	        {
       
   727     	        resourceId = EAiIRResourceVol1;
       
   728     	        break;
       
   729     	        }
       
   730     	    case EVolumeLevel2:
       
   731     	        {
       
   732     	        resourceId = EAiIRResourceVol2;
       
   733     	        break;
       
   734     	        }
       
   735     	    case EVolumeLevel3:
       
   736     	        {
       
   737     	        resourceId = EAiIRResourceVol3;
       
   738     	        break;
       
   739     	        }
       
   740     	    case EVolumeLevel4:
       
   741     	        {
       
   742     	        resourceId = EAiIRResourceVol4;
       
   743     	        break;
       
   744     	        }
       
   745     	    case EVolumeLevel5:
       
   746     	        {
       
   747     	        resourceId = EAiIRResourceVol5;
       
   748     	        break;
       
   749     	        }
       
   750     	    case EVolumeLevel6:
       
   751     	        {
       
   752     	        resourceId = EAiIRResourceVol6;
       
   753     	        break;
       
   754     	        }
       
   755     	    case EVolumeLevel7:
       
   756     	        {
       
   757     	        resourceId = EAiIRResourceVol7;
       
   758     	        break;
       
   759     	        }
       
   760     	    case EVolumeLevel8:
       
   761     	        {
       
   762     	        resourceId = EAiIRResourceVol8;
       
   763     	        break;
       
   764     	        }
       
   765     	    case EVolumeLevel9:
       
   766     	        {
       
   767     	        resourceId = EAiIRResourceVol9;
       
   768     	        break;
       
   769     	        }
       
   770     	    case EVolumeLevel10:
       
   771     	        {
       
   772     	        resourceId = EAiIRResourceVol10;
       
   773     	        break;
       
   774     	        }
       
   775     	    default:
       
   776     	        break;
       
   777     	    }
       
   778         for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   779         	{
       
   780             MAiContentObserver* observer = iObservers[i];
       
   781             //Initiates content publishing transaction.
       
   782             observer->StartTransaction( reinterpret_cast<TInt32>( this ) );
       
   783             //Informs that content identified by reference resourceId must be
       
   784             //published to UI control identified by selector
       
   785      	    //EAiIRContentVolume
       
   786     		observer->Publish( *this, EAiIRContentVolume, resourceId, KIRPublishIndex );
       
   787     	    //Requests framework that content publishing transaction must be
       
   788     	    //finalized and content should be rendered to the screen.
       
   789     	    //Displays the volume level onto the Active Idle content area.
       
   790         	observer->Commit( reinterpret_cast<TInt32>( this ) );
       
   791         	}
       
   792 	    }
       
   793 	else
       
   794 		{
       
   795 		User::Leave(KErrGeneral);
       
   796 		}
       
   797     IRLOG_DEBUG( "CIRActiveIdle::HandleVolumeChangeL - Exiting." );
       
   798 
       
   799 	}
       
   800 
       
   801 // ---------------------------------------------------------------------------
       
   802 // CIRActiveIdle::HandleApplicationRunningStateChangeL
       
   803 // Handles changes in Internet Radio application running state.
       
   804 // ---------------------------------------------------------------------------
       
   805 //
       
   806 void CIRActiveIdle::HandleApplicationRunningStateChangeL(
       
   807         const TIRPSApplicationRunningState aRunningState )
       
   808     {
       
   809     IRLOG_DEBUG( "CIRActiveIdle::HandleApplicationRunningStateChangeL" );
       
   810     if ( iRunningState != aRunningState )
       
   811         {
       
   812         switch ( aRunningState )
       
   813             {
       
   814             case EIRPSApplicationUninitialized:
       
   815                 {
       
   816                 break;
       
   817                 }
       
   818             //called when application starts
       
   819             case EIRPSApplicationRunning:
       
   820                 {
       
   821                 for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   822                     {
       
   823                     MAiContentObserver* observer = iObservers[i];
       
   824                     //Initiates content publishing transaction.
       
   825                     observer->StartTransaction(reinterpret_cast<TInt32>(
       
   826                                                  this ) );
       
   827                     //Invoked by the plug-in to inform that content identified
       
   828                     //by reference EAiIRResourceIRStoppedIcon must be published
       
   829                     //to UI crtl identified by selector EAiIRContentAppIcon.
       
   830                     // Full Page Idle: shows IR icon.
       
   831                     // Navigation Bar Idle: updates title text and switches correct layout.
       
   832                     // App has just started, publish initially to stopped state.
       
   833                     observer->Publish( *this, EAiIRContentAppIcon, EAiIRResourceIRStoppedIcon,
       
   834                     					 KIRPublishIndex );
       
   835                     observer->Publish( *this, EAiIRContentOneLineInfoCaption,KNullDesC,
       
   836                     					KIRPublishIndex );
       
   837 
       
   838                     observer->Commit( reinterpret_cast<TInt32>( this ) );
       
   839                     }
       
   840 
       
   841                 if ( iIRTerminationDetector )
       
   842                     {
       
   843                     iIRTerminationDetector->StartListeningL();
       
   844                     }
       
   845                 break;
       
   846                 }
       
   847             // called when the application exits
       
   848             case EIRPSApplicationClosing:
       
   849                 {
       
   850                 Clean();
       
   851                 break;
       
   852                 }
       
   853             default:
       
   854                 break;
       
   855             }
       
   856         iRunningState = aRunningState;
       
   857         }
       
   858     IRLOG_DEBUG( "CIRActiveIdle::HandleApplicationRunningStateChangeL - Exiting." );
       
   859     }
       
   860 
       
   861 // ---------------------------------------------------------------------------
       
   862 // CIRActiveIdle::HandleBufferingStateL
       
   863 // Handles changes in Internet Radio buffering state
       
   864 // ---------------------------------------------------------------------------
       
   865 //
       
   866 
       
   867 void CIRActiveIdle::HandleBufferingStateL(TIRBufferingState aState )
       
   868 	{
       
   869 		if (EIRStateBufferingStart == aState)
       
   870 		{
       
   871 		    // do nothing, just remove build warning
       
   872 		}
       
   873 	}