fmradio/fmradio/src/fmradiomusicstorehandler.cpp
changeset 0 f3d95d9c00ab
child 7 95ac6b0f7f5b
equal deleted inserted replaced
-1:000000000000 0:f3d95d9c00ab
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation for music store integration.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <apgcli.h>
       
    19 #include <apgtask.h>
       
    20 #include <centralrepository.h>
       
    21 #include <e32base.h>
       
    22 #include <e32property.h>
       
    23 #include <eikenv.h>
       
    24 #include <eikmenup.h>
       
    25 #include <eikmenub.h>
       
    26 #include <fmradio.rsg>
       
    27 #include <mpxfindinmusicshop.h>
       
    28 #include <mpxfindinmusicshopcommon.h>   //for p&s keys
       
    29 
       
    30 #include "fmradio.hrh"
       
    31 #include "fmradiomusicstorehandler.h"
       
    32 #include "debug.h"
       
    33 
       
    34 // Some debug flags
       
    35 
       
    36 // If defined, forces Operator specific music shop to be enabled,
       
    37 // regardless if it is supported or not. For debugging purposes
       
    38 #undef FORCE_OPERATOR_MUSIC_SHOP
       
    39 
       
    40 // Following constants are from mpxmusicplayer_101FFCDC.crml
       
    41 const TUid KCRUidMPXMPSettings = {0x101FFCDC}; // UID for Music Store Settings CenRep
       
    42 const TUint32 KMPXMusicStoreUID = 0x3;
       
    43 const TUint32 KOperatorMusicStore = 0x4;
       
    44 const TUint32 KOperatorMusicStoreType = 0x5;
       
    45 const TUint32 KOperatorMusicStoreDisplayName = 0x6;
       
    46 const TUint32 KOperatorMusicStoreNativeUid = 0x7;
       
    47 const TUint32 KOperatorMusicStoreWebPage = 0x9;
       
    48 const TUint32 KOperatorMusicStoreURI = 0xA;
       
    49 const TInt TUInt32HexLength = 8;
       
    50 
       
    51 // ----------------------------------------------------
       
    52 // CFMRadioMusicStoreHandler::CMusicStoreHandler
       
    53 // C++ class constructor.
       
    54 // ----------------------------------------------------
       
    55 //
       
    56 CFMRadioMusicStoreHandler::CFMRadioMusicStoreHandler( TInt aResourceId )
       
    57 : iResourceId( aResourceId )
       
    58     {
       
    59     // Nothing to do
       
    60     }
       
    61 
       
    62 // ----------------------------------------------------
       
    63 // CFMRadioMusicStoreHandler::~CMusicStoreHandler
       
    64 // Default destructor.
       
    65 // ----------------------------------------------------
       
    66 //
       
    67 CFMRadioMusicStoreHandler::~CFMRadioMusicStoreHandler()
       
    68     {
       
    69     iOperatorMusicStoreName.Close();
       
    70     iOperatorStoreWebsite.Close();
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------
       
    74 // CFMRadioMusicStoreHandler::NewL
       
    75 // Two-phased class constructor.
       
    76 // ----------------------------------------------------
       
    77 //
       
    78 CFMRadioMusicStoreHandler* CFMRadioMusicStoreHandler::NewL( TInt aResourceId )
       
    79     {
       
    80     CFMRadioMusicStoreHandler* self = new (ELeave) CFMRadioMusicStoreHandler( aResourceId );
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     CleanupStack::Pop( self );
       
    84     return self;
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------
       
    88 // CFMRadioMusicStoreHandler::NewL
       
    89 // Second phase class constructor.
       
    90 // ----------------------------------------------------
       
    91 //
       
    92 void CFMRadioMusicStoreHandler::ConstructL()
       
    93     {
       
    94     iCoeEnv = CEikonEnv::Static();
       
    95     CRepository* repository = CRepository::NewL( KCRUidMPXMPSettings );
       
    96     CleanupStack::PushL( repository );
       
    97     
       
    98     RBuf8 uidDes;
       
    99     uidDes.CleanupClosePushL();
       
   100     uidDes.CreateL( TUInt32HexLength );
       
   101     TInt error = KErrNone;
       
   102     error = repository->Get( KMPXMusicStoreUID, uidDes );
       
   103     
       
   104     // Check for availability of Nokia Music store
       
   105     if ( !error )
       
   106         {
       
   107         iMusicStoreUID = Uint32Presentation( uidDes );
       
   108         iMusicStoreAppInstalled = IsAppInstalledL( TUid::Uid( iMusicStoreUID ) );
       
   109         }
       
   110 
       
   111     if ( NokiaMusicStoreAvailable() )
       
   112         {
       
   113         InitializeMusicStore( TUid::Uid( iMusicStoreUID ) );
       
   114         }
       
   115 
       
   116     // Check if operator provided a music store
       
   117     TFMRadioOperatorAppType appType = CheckOperatorMusicStoreTypeL( *repository );
       
   118     if ( appType != EFMRadioAppNotAvailable )
       
   119         {
       
   120         // Get the name of the music store
       
   121         const TInt initialNameLength = 11;
       
   122         iOperatorMusicStoreName.CreateL( initialNameLength );
       
   123         TInt realLength = KErrNotFound;
       
   124         error = repository->Get( KOperatorMusicStoreDisplayName, iOperatorMusicStoreName, realLength );
       
   125         if ( error == KErrOverflow )
       
   126             {
       
   127             iOperatorMusicStoreName.ReAllocL( realLength );
       
   128             error = repository->Get( KOperatorMusicStoreDisplayName, iOperatorMusicStoreName );
       
   129             }
       
   130         User::LeaveIfError( error );
       
   131 #ifdef FORCE_OPERATOR_MUSIC_SHOP
       
   132         if ( !iOperatorMusicStoreName.Length() )
       
   133             {
       
   134             _LIT( KHardCodedName, "O'MusicShop" ); // length <= initialNameLength
       
   135             iOperatorMusicStoreName.Copy( KHardCodedName );
       
   136             }
       
   137 #endif
       
   138 
       
   139         // Get application type specific parameters
       
   140         InitializeParametersL( *repository, appType );
       
   141         }
       
   142     CleanupStack::PopAndDestroy( 2 ); // uidDes, repository
       
   143     }
       
   144 
       
   145 // ----------------------------------------------------
       
   146 // CFMRadioMusicStoreHandler::CheckOperatorMusicStoreTypeL
       
   147 // ----------------------------------------------------
       
   148 //
       
   149 CFMRadioMusicStoreHandler::TFMRadioOperatorAppType CFMRadioMusicStoreHandler::CheckOperatorMusicStoreTypeL(
       
   150         CRepository& aRepository )
       
   151     {
       
   152     TFMRadioOperatorAppType appType = EFMRadioAppNotAvailable;
       
   153     // Check if operator provided a music store
       
   154     TBool operatorStorePresent = EFalse;
       
   155     TInt error = aRepository.Get( KOperatorMusicStore, operatorStorePresent );
       
   156     if ( error != KErrNotFound )
       
   157         {
       
   158         User::LeaveIfError( error );
       
   159         }
       
   160     if ( operatorStorePresent )
       
   161         {
       
   162         TInt appTypeCR;
       
   163         error = aRepository.Get( KOperatorMusicStoreType, appTypeCR );
       
   164         User::LeaveIfError( error );
       
   165         if ( appTypeCR == 0 ) // 0 = Native app
       
   166             {
       
   167             appType = EFMRadioNativeApp;
       
   168             }
       
   169         else    // 1 = Java app
       
   170             {
       
   171             appType = EFMRadioJavaApp;
       
   172             }
       
   173          }
       
   174 
       
   175     // The code assumes that if both application and website is available then
       
   176     // website is preferred type
       
   177     TInt website;
       
   178     error = aRepository.Get( KOperatorMusicStoreWebPage, website );
       
   179     User::LeaveIfError( error );
       
   180 #ifdef FORCE_OPERATOR_MUSIC_SHOP
       
   181     website = ETrue;
       
   182 #endif
       
   183     if ( website )
       
   184         {
       
   185         appType = EFMRadioWebsite;
       
   186         }
       
   187 
       
   188     return appType;
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------
       
   192 // CFMRadioMusicStoreHandler::InitializeParametersL
       
   193 // ----------------------------------------------------
       
   194 //
       
   195 void CFMRadioMusicStoreHandler::InitializeParametersL(
       
   196         CRepository& aRepository,
       
   197         TFMRadioOperatorAppType aAppType )
       
   198     {
       
   199     TInt error = KErrNone;
       
   200     switch ( aAppType )
       
   201         {
       
   202         case EFMRadioNativeApp:
       
   203             {
       
   204             RBuf8 operatorUidDes;
       
   205             operatorUidDes.CleanupClosePushL();
       
   206             operatorUidDes.CreateL( TUInt32HexLength );
       
   207             
       
   208             TInt error = KErrNone;
       
   209             error = aRepository.Get( KOperatorMusicStoreNativeUid, operatorUidDes );
       
   210             
       
   211             if ( !error )
       
   212                 {
       
   213                 iOperatorStoreNativeUID = Uint32Presentation( operatorUidDes );
       
   214                 // It is assumed that both Nokia Music Shop and operator specific music store use
       
   215                 // same kind of interface to communicate
       
   216                 InitializeMusicStore( TUid::Uid( iOperatorStoreNativeUID ) );
       
   217                 }
       
   218             CleanupStack::PopAndDestroy( &operatorUidDes );
       
   219             break;
       
   220             }
       
   221         case EFMRadioJavaApp:
       
   222             // Java application not supported currently
       
   223             break;
       
   224         case EFMRadioWebsite:
       
   225             {
       
   226             const TInt initialSize = 5;
       
   227             TInt realLength = KErrNotFound;
       
   228             iOperatorStoreWebsite.Create( initialSize );
       
   229             error = aRepository.Get( KOperatorMusicStoreURI, iOperatorStoreWebsite, realLength );
       
   230             if ( error == KErrOverflow )
       
   231                 {
       
   232                 iOperatorStoreWebsite.ReAllocL( realLength );
       
   233                 error = aRepository.Get( KOperatorMusicStoreURI, iOperatorStoreWebsite );
       
   234                 }
       
   235             User::LeaveIfError( error );
       
   236 #ifdef FORCE_OPERATOR_MUSIC_SHOP
       
   237             if ( !iOperatorStoreWebsite.Length() )
       
   238                 {
       
   239                 _LIT( KHardCodedName, "http://www.google.com/" );
       
   240                 iOperatorStoreWebsite.ReAllocL( KHardCodedName().Length() );
       
   241                 iOperatorStoreWebsite.Copy( KHardCodedName );
       
   242                 }
       
   243 #endif
       
   244             break;
       
   245             }
       
   246         default:
       
   247             break;
       
   248         }
       
   249     }
       
   250 
       
   251 // ----------------------------------------------------
       
   252 // CFMRadioMusicStoreHandler::InitializeMusicShop
       
   253 // ----------------------------------------------------
       
   254 //
       
   255 void CFMRadioMusicStoreHandler::InitializeMusicStore( TUid aMusicstoreUid )
       
   256     {
       
   257     //MusicShop CenRep initialization values
       
   258     _LIT_SECURITY_POLICY_C1(KMPlayerRemoteReadPolicy, ECapabilityReadUserData);
       
   259     _LIT_SECURITY_POLICY_C1(KMPlayerRemoteWritePolicy, ECapabilityWriteUserData);
       
   260     TInt retval(KErrNone);
       
   261     // P/S key for music shop
       
   262     retval = RProperty::Define( aMusicstoreUid,
       
   263             KMShopCategoryId,
       
   264             RProperty::EInt,
       
   265             KMPlayerRemoteReadPolicy,
       
   266             KMPlayerRemoteWritePolicy );
       
   267 
       
   268     if( retval != KErrAlreadyExists)
       
   269         {
       
   270         RProperty::Set( aMusicstoreUid,
       
   271                 KMShopCategoryId,
       
   272                 KFindInMShopKeyInValid );  // initialize Find In Musicshop was not called
       
   273 
       
   274         RProperty::Define( aMusicstoreUid,
       
   275                 KMShopCategoryName,
       
   276                 RProperty::ELargeText,
       
   277                 KMPlayerRemoteReadPolicy,
       
   278                 KMPlayerRemoteWritePolicy );
       
   279         }
       
   280     }
       
   281 
       
   282 // ----------------------------------------------------
       
   283 // CFMRadioMusicStoreHandler::GetUint32Presentation
       
   284 // ----------------------------------------------------
       
   285 //
       
   286 TUint32 CFMRadioMusicStoreHandler::Uint32Presentation( const TDesC8& aBuf )
       
   287     {
       
   288     TUint32 result = 0;
       
   289 
       
   290     const TInt KProEngByteLength( 8 );
       
   291     const TInt length( aBuf.Length() );
       
   292     const TInt maxBitShift( KProEngByteLength * ( length - 1 ) );
       
   293 
       
   294     for ( TInt i( 0 ); i < length; ++i )
       
   295         {
       
   296         result |= ( aBuf[i] <<
       
   297                    ( maxBitShift - ( KProEngByteLength * i ) ) );
       
   298         }
       
   299     return result;
       
   300     }
       
   301 
       
   302 // ----------------------------------------------------
       
   303 // CFMRadioMusicStoreHandler::IsMusicStoreCommandId
       
   304 // Goes through known command ids and compares to them
       
   305 // ----------------------------------------------------
       
   306 //
       
   307 TBool CFMRadioMusicStoreHandler::IsMusicStoreCommandId( TInt aCommandId )
       
   308     {
       
   309     TBool isHandled = EFalse;
       
   310     switch( aCommandId )
       
   311         {
       
   312         case EFMRadioMusicStore:
       
   313         case EFMRadioMusicStoreGoogle:
       
   314         case EFMRadioMusicStoreWikipedia:
       
   315         case EFMRadioMusicStoreAmg:
       
   316         case EFMRadioMusicStoreNokiaMusicShop:
       
   317         case EFMRadioMusicStoreMusicPortl:
       
   318         case EFMRadioMusicStoreOperator:
       
   319             isHandled = ETrue;
       
   320             break;
       
   321         default:
       
   322             break;
       
   323         }
       
   324     return isHandled;
       
   325     }
       
   326 
       
   327 // ----------------------------------------------------
       
   328 // CFMRadioMusicStoreHandler::MusicStoreCount
       
   329 // ----------------------------------------------------
       
   330 //
       
   331 TInt CFMRadioMusicStoreHandler::MusicStoreCount()
       
   332     {
       
   333     TInt count = 0;
       
   334     if ( NokiaMusicStoreAvailable() )
       
   335         {
       
   336         count++;
       
   337         }
       
   338     if ( OperatorMusicStoreAvailable() )
       
   339         {
       
   340         count++;
       
   341         }
       
   342     return count;
       
   343     }
       
   344 
       
   345 // ----------------------------------------------------
       
   346 // CFMRadioMusicStoreHandler::OperatorMusicStoreAvailable
       
   347 // ----------------------------------------------------
       
   348 //
       
   349 TBool CFMRadioMusicStoreHandler::OperatorMusicStoreAvailable()
       
   350     {
       
   351     return ( iOperatorMusicStoreName.Length() != 0 );
       
   352     }
       
   353 
       
   354 // ----------------------------------------------------
       
   355 // CFMRadioMusicStoreHandler::NokiaMusicStoreAvailable
       
   356 // ----------------------------------------------------
       
   357 //
       
   358 TBool CFMRadioMusicStoreHandler::NokiaMusicStoreAvailable()
       
   359     {
       
   360     TBool response = EFalse;
       
   361     
       
   362     if ( iMusicStoreUID != 0 && iMusicStoreAppInstalled )
       
   363         {
       
   364         response = ETrue;
       
   365         }
       
   366     return response;
       
   367     }
       
   368 
       
   369 // ----------------------------------------------------
       
   370 // CFMRadioMusicStoreHandler::InitializeMenuL
       
   371 // Takes care of dynamically initializing menu items related to Music shop.
       
   372 // Takes care of adding either menu item or cascaded menuitem
       
   373 // based on how many Music shops there is available. Fills the
       
   374 // cascaded menuitem automatically.
       
   375 // ----------------------------------------------------
       
   376 //
       
   377 TBool CFMRadioMusicStoreHandler::InitializeMenuL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   378     {
       
   379     TBool resourceHandled = EFalse;
       
   380 
       
   381     if ( aResourceId == R_FMRADIO_OPTIONS_MUSIC_STORE_SUB_MENU )
       
   382         {
       
   383         if ( NokiaMusicStoreAvailable() )
       
   384             {
       
   385             aMenuPane->SetItemDimmed( EFMRadioMusicStoreNokiaMusicShop, EFalse );
       
   386             }
       
   387         else
       
   388             {
       
   389             aMenuPane->SetItemDimmed( EFMRadioMusicStoreNokiaMusicShop, ETrue );
       
   390             }
       
   391         if ( OperatorMusicStoreAvailable() )
       
   392             {
       
   393             aMenuPane->SetItemTextL( EFMRadioMusicStoreOperator, iOperatorMusicStoreName );
       
   394             aMenuPane->SetItemDimmed( EFMRadioMusicStoreOperator, EFalse );
       
   395             }
       
   396         else
       
   397             {
       
   398             aMenuPane->SetItemDimmed( EFMRadioMusicStoreOperator, ETrue );
       
   399             }
       
   400         resourceHandled = ETrue;
       
   401         }
       
   402     else if ( iResourceId == aResourceId )
       
   403         {
       
   404         const TInt firstIndex = 0;
       
   405         TInt firstCommand = aMenuPane->MenuItemCommandId( firstIndex );
       
   406         if ( MusicStoreCount() > 1 || OperatorMusicStoreAvailable() )
       
   407             {
       
   408             aMenuPane->AddMenuItemsL( R_FMRADIO_OPTIONS_MUSIC_STORE_WITH_SUB_MENU, firstCommand );
       
   409             }
       
   410         else
       
   411             {
       
   412             aMenuPane->AddMenuItemsL( R_FMRADIO_OPTIONS_MUSIC_STORE, firstCommand );
       
   413             }
       
   414 
       
   415         // Show or hide menu item based on Music store state
       
   416         if ( iState == EFMRadioMusicStoreDisabled || iState == EFMRadioMusicStoreUninitialized )
       
   417             {
       
   418             aMenuPane->SetItemDimmed( EFMRadioMusicStore, ETrue );
       
   419             }
       
   420         else if ( iState == EFMRadioMusicStoreEnabled && !MusicStoreCount() )
       
   421             {
       
   422             aMenuPane->SetItemDimmed( EFMRadioMusicStore, ETrue );
       
   423             }
       
   424         else
       
   425             {
       
   426             aMenuPane->SetItemDimmed( EFMRadioMusicStore, EFalse );
       
   427             }
       
   428         }
       
   429     else
       
   430         {
       
   431         //NOP
       
   432         }
       
   433     return resourceHandled;
       
   434     }
       
   435 
       
   436 // ----------------------------------------------------
       
   437 // CFMRadioMusicStoreHandler::EnableMusicStore
       
   438 // Shows or hides Music store related functionality
       
   439 // ----------------------------------------------------
       
   440 //
       
   441 void CFMRadioMusicStoreHandler::EnableMusicStore( TBool aEnable, TBool aForce )
       
   442     {
       
   443     if ( aForce && aEnable )
       
   444         {
       
   445         iState = EFMRadioMusicStoreForceEnabled;
       
   446         }
       
   447     else if ( aEnable )
       
   448         {
       
   449         iState = EFMRadioMusicStoreEnabled;
       
   450         }
       
   451     else
       
   452         {
       
   453         iState = EFMRadioMusicStoreDisabled;
       
   454         }
       
   455     }
       
   456 
       
   457 // ----------------------------------------------------
       
   458 // CFMRadioMusicStoreHandler::LaunchMusicStoreL
       
   459 // Launches appropriate Music Store functionality based on parameters.
       
   460 // ----------------------------------------------------
       
   461 //
       
   462 void CFMRadioMusicStoreHandler::LaunchMusicStoreL(
       
   463         TInt aCommandId,
       
   464         const TDesC& aTitle,
       
   465         const TDesC& aArtist,
       
   466         const TDesC& aAlbum )
       
   467     {
       
   468     if ( aCommandId == EFMRadioMusicStore )
       
   469         {
       
   470         aCommandId = EFMRadioMusicStoreNokiaMusicShop;
       
   471         }
       
   472 
       
   473     HBufC* searchString = NULL;
       
   474 
       
   475     TBool isHandled = ETrue;
       
   476     switch( aCommandId )
       
   477         {
       
   478         case EFMRadioMusicStoreGoogle:
       
   479         case EFMRadioMusicStoreWikipedia:
       
   480         case EFMRadioMusicStoreAmg:
       
   481         case EFMRadioMusicStoreMusicPortl:
       
   482             isHandled = EFalse;
       
   483             break;
       
   484         case EFMRadioMusicStoreNokiaMusicShop:
       
   485             searchString = NokiaMusicShopSearchLC( aTitle, aArtist, aAlbum );
       
   486             break;
       
   487         case EFMRadioMusicStoreOperator:
       
   488             if ( iOperatorStoreWebsite.Length() != 0 )
       
   489                 {
       
   490                 searchString = iOperatorStoreWebsite.AllocLC();
       
   491                 
       
   492                 }
       
   493             else if ( iOperatorStoreNativeUID )
       
   494                 {
       
   495                 // It is assumed that both Nokia Music Shop and operator specific music store use
       
   496                 // same kind of interface to communicate
       
   497                 searchString = NokiaMusicShopSearchLC( aTitle, aArtist, aAlbum );
       
   498                 }
       
   499             else
       
   500                 {
       
   501                 isHandled = EFalse;
       
   502                 }
       
   503             break;
       
   504         default:
       
   505             FTRACE( FPrint( _L("CFMRadioMusicStoreHandler::LaunchMusicStoreL - Unknown id = %d"), aCommandId ) );
       
   506             isHandled = EFalse;
       
   507             break;
       
   508         }
       
   509 
       
   510     if ( isHandled )
       
   511         {
       
   512         switch( aCommandId )
       
   513             {
       
   514             case EFMRadioMusicStoreNokiaMusicShop:
       
   515                 {
       
   516                 TUid musicshopUid( TUid::Uid( iMusicStoreUID ) );
       
   517                 LaunchMusicShopL( musicshopUid, *searchString );
       
   518                 break;
       
   519                 }
       
   520             case EFMRadioMusicStoreOperator:
       
   521                 LaunchOperatorMusicStoreL( *searchString );
       
   522                 break;
       
   523             default:
       
   524                 LaunchWebPageL( *searchString );
       
   525                 break;
       
   526             }
       
   527         CleanupStack::PopAndDestroy( searchString );
       
   528         }
       
   529     }
       
   530 
       
   531 // -----------------------------------------------------------------------------
       
   532 // CFMRadioMusicStoreHandler::LaunchOperatorMusicStoreL
       
   533 // -----------------------------------------------------------------------------
       
   534 //
       
   535 void CFMRadioMusicStoreHandler::LaunchOperatorMusicStoreL( const TDesC& aSearchString )
       
   536     {
       
   537     if ( iOperatorStoreWebsite.Length() != 0 )
       
   538         {
       
   539         LaunchWebPageL( aSearchString );
       
   540         }
       
   541     else if ( iOperatorStoreNativeUID )
       
   542         {
       
   543         // It is assumed that both Nokia Music Shop and operator specific music store use
       
   544         // same kind of interface to communicate
       
   545         TUid musicshopUid( TUid::Uid( iOperatorStoreNativeUID ) );
       
   546         LaunchMusicShopL( musicshopUid, aSearchString );
       
   547         }
       
   548     else
       
   549         {
       
   550         //NOP
       
   551         }
       
   552     }
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // CFMRadioMusicStoreHandler::NokiaMusicShopSearchL
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 HBufC* CFMRadioMusicStoreHandler::NokiaMusicShopSearchLC(
       
   559         const TDesC& aSongName,
       
   560         const TDesC& aArtistName,
       
   561         const TDesC& aAlbumName )
       
   562     {
       
   563     CMPXFindInMShop* finder = CMPXFindInMShop::NewL();  //ECom Plugin
       
   564     CleanupStack::PushL( finder );
       
   565     HBufC* url = finder->CreateSearchURLL(  aSongName,
       
   566                                      aArtistName,
       
   567                                      aAlbumName,
       
   568                                      KNullDesC,     // Composer - Not used
       
   569                                      KNullDesC );   // Genre - Not used
       
   570 
       
   571     CleanupStack::PopAndDestroy( finder ); // finder
       
   572     REComSession::FinalClose();
       
   573     CleanupStack::PushL( url );
       
   574     return url;
       
   575     }
       
   576 
       
   577 // -----------------------------------------------------------------------------
       
   578 // CFMRadioMusicStoreHandler::LaunchMusicShopL
       
   579 // Launch Nokia music shop application
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 void CFMRadioMusicStoreHandler::LaunchMusicShopL( TUid aMusicshopUid, const TDesC& aSearchString )
       
   583     {
       
   584     RProperty::Set( aMusicshopUid,
       
   585             KMShopCategoryName,
       
   586             aSearchString );
       
   587 
       
   588     RProperty::Set( aMusicshopUid,
       
   589             KMShopCategoryId,
       
   590             KFindInMShopKeyValid );  // Set Key to Valid
       
   591 
       
   592     TApaTaskList taskList( iCoeEnv->WsSession() );
       
   593     TApaTask task = taskList.FindApp( aMusicshopUid );
       
   594 
       
   595     if ( task.Exists() )
       
   596         {
       
   597         task.BringToForeground();
       
   598         }
       
   599     else
       
   600         {
       
   601         RApaLsSession session;
       
   602         User::LeaveIfError( session.Connect() );
       
   603         TThreadId threadId;
       
   604         session.CreateDocument( KNullDesC, aMusicshopUid, threadId );
       
   605         session.Close();
       
   606         }
       
   607     }
       
   608 
       
   609 // ----------------------------------------------------
       
   610 // CFMRadioMusicStoreHandler::LaunchWebPageL
       
   611 // Opens web site based on the string
       
   612 // ----------------------------------------------------
       
   613 //
       
   614 void CFMRadioMusicStoreHandler::LaunchWebPageL( const TDesC& aWebpage )
       
   615     {
       
   616     _LIT( KCommand, "4 ");
       
   617     RBuf param;
       
   618     param.CreateL( KCommand().Length() + aWebpage.Length() );
       
   619     param.CleanupClosePushL();
       
   620     param.Copy( KCommand() );   //Web Browser requires this in order to fetch url.
       
   621     param.Append( aWebpage );
       
   622 
       
   623     const TInt KWebBrowserUid = 0x10008D39;
       
   624     TUid browserId( TUid::Uid( KWebBrowserUid ) );
       
   625     TApaTaskList taskList( iCoeEnv->WsSession() );
       
   626     TApaTask task = taskList.FindApp( browserId );
       
   627     if ( task.Exists() )
       
   628         {
       
   629         HBufC8* param8 = HBufC8::NewLC( param.Length() );
       
   630         param8->Des().Append( param );
       
   631         task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
       
   632         CleanupStack::PopAndDestroy( param8 );
       
   633         }
       
   634     else
       
   635         {
       
   636         RApaLsSession session;
       
   637         User::LeaveIfError( session.Connect() );
       
   638         TThreadId threadId;
       
   639         session.StartDocument( param, browserId, threadId );
       
   640         session.Close();
       
   641         }
       
   642     CleanupStack::PopAndDestroy( &param );
       
   643     }
       
   644 
       
   645 // ----------------------------------------------------
       
   646 // CFMRadioMusicStoreHandler::IsMusicStoreLaunchable
       
   647 // ----------------------------------------------------
       
   648 //
       
   649 TBool CFMRadioMusicStoreHandler::IsMusicStoreEnabled()
       
   650     {
       
   651     TBool musicStoreLaunchable = EFalse;
       
   652     
       
   653     if ( iState != CFMRadioMusicStoreHandler::EFMRadioMusicStoreDisabled &&
       
   654          iState != CFMRadioMusicStoreHandler::EFMRadioMusicStoreUninitialized )
       
   655         {
       
   656         musicStoreLaunchable = ETrue;
       
   657         }
       
   658     return musicStoreLaunchable;
       
   659     }
       
   660 
       
   661 // ----------------------------------------------------
       
   662 // CFMRadioMusicStoreHandler::OperatorMusicStoreName
       
   663 // ----------------------------------------------------
       
   664 //
       
   665 const TDesC& CFMRadioMusicStoreHandler::OperatorMusicStoreName() const
       
   666     {
       
   667     return iOperatorMusicStoreName;
       
   668     }
       
   669 
       
   670 // ----------------------------------------------------
       
   671 // CFMRadioMusicStoreHandler::IsAppInstalled
       
   672 // ----------------------------------------------------
       
   673 //
       
   674 TBool CFMRadioMusicStoreHandler::IsAppInstalledL( const TUid& aAppUid )
       
   675     {
       
   676     TBool response = EFalse;
       
   677     
       
   678     RApaLsSession apaSession;
       
   679     CleanupClosePushL( apaSession );
       
   680     User::LeaveIfError( apaSession.Connect() );
       
   681     apaSession.GetAllApps();
       
   682     
       
   683     TApaAppInfo appInfo;
       
   684     TInt err = apaSession.GetAppInfo( appInfo, aAppUid );
       
   685     CleanupStack::PopAndDestroy( &apaSession );
       
   686     
       
   687     if ( !err )
       
   688         {
       
   689         // app was found
       
   690         response = ETrue;
       
   691         }
       
   692     return response;
       
   693     }