homescreenplugins/videoahlplugin/src/videoactionhandler.cpp
changeset 0 96612d01cf9f
child 1 6711b85517b7
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     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 the License "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:  interface class definition for action handler plugin*
       
    15 */
       
    16 
       
    17 
       
    18 // Version : %version: 19 %
       
    19 
       
    20 #include <e32def.h>
       
    21 #include <e32uid.h>
       
    22 #include <apgcli.h>
       
    23 #include <apacmdln.h>
       
    24 #include <apgtask.h>
       
    25 #include <eikenv.h>
       
    26 #include <vwsdef.h>
       
    27 #include <coeaui.h>
       
    28 #include <avkon.rsg>
       
    29 #include <AknGlobalNote.h>
       
    30 #include <MediatorEventProvider.h>
       
    31 #include <centralrepository.h>
       
    32 #include <LiwVariant.h>
       
    33 #include <videoplayeractivationmessage.h>
       
    34 #include <vcxmyvideosdefs.h>
       
    35 #include <ErrorUI.h>
       
    36 
       
    37 #include "videoahpluginconstants.h"
       
    38 #include "videoactionhandler.h"
       
    39 #include "videoplayerpskeys.h"
       
    40 #include "iptvlastwatcheddata.h"
       
    41 #include "iptvlastwatchedapi.h"
       
    42 #include "vcxhgvodtelephonyclient.h"
       
    43 
       
    44 // CONSTANTS
       
    45 const TUid KUidMPXVideoPlayerApp = { 0x200159B2 };
       
    46 const TUid KUidMediaSettingsApp  = { 0x10005A3F };
       
    47 
       
    48 _LIT8( KKeyMessage,     "message" );
       
    49 _LIT8( KKeyMessageData, "message_data" );
       
    50 
       
    51 //  Constants for wg name. Used to identify if wg is actually ours.
       
    52 _LIT( KVideoPlayerWgName, "*200159b2*");
       
    53 const TUint KVideoPlayerWgNameSize = 50;
       
    54 
       
    55 // ======== MEMBER FUNCTIONS ========
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // CVideoActionHandler::ConstructL
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 void CVideoActionHandler::ConstructL()
       
    62     {   
       
    63     iMediatorEventProvider = CMediatorEventProvider::NewL();
       
    64     }
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // CVideoActionHandler::NewL
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 CVideoActionHandler* CVideoActionHandler::NewL()
       
    71     {
       
    72     CVideoActionHandler* self = CVideoActionHandler::NewLC();
       
    73     CleanupStack::Pop( self );
       
    74     return self;
       
    75     }
       
    76 
       
    77 // ----------------------------------------------------------------------------
       
    78 // CVideoActionHandler::NewLC
       
    79 // ----------------------------------------------------------------------------
       
    80 //
       
    81 CVideoActionHandler* CVideoActionHandler::NewLC()
       
    82     {
       
    83     CVideoActionHandler* self = new( ELeave ) CVideoActionHandler;
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CVideoActionHandler::~CVideoActionHandler
       
    91 // ---------------------------------------------------------------------------
       
    92 CVideoActionHandler::~CVideoActionHandler()
       
    93 	{  
       
    94 	delete iMediatorEventProvider;
       
    95 	}
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CVideoActionHandler::ExecuteActionL
       
    99 // Executes provided action
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 TInt CVideoActionHandler::ExecuteActionL( const CLiwMap* aMap )
       
   103     {    
       
   104     TInt errCode( KErrNotFound );   
       
   105     
       
   106     TVideoPlayerActivationMessage*  activationMsg = new( ELeave ) TVideoPlayerActivationMessage;
       
   107     CleanupStack::PushL( activationMsg );
       
   108     
       
   109     errCode = PrepareMessageL( aMap, *activationMsg );
       
   110     if( KErrNone == errCode )
       
   111         {
       
   112         errCode = StartAppL( *activationMsg );
       
   113         }
       
   114     CleanupStack::PopAndDestroy( activationMsg );
       
   115     
       
   116     return errCode;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CVideoActionHandler::PrepareMessageL
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 TInt CVideoActionHandler::PrepareMessageL( const CLiwMap* aMap, 
       
   124                                            TVideoPlayerActivationMessage& aActivationMsg )
       
   125     {
       
   126     TInt err( KErrNone );
       
   127 
       
   128     TLiwVariant variant; 
       
   129     variant.PushL();
       
   130     err = ExtractVariant( aMap, variant, KKeyMessage );
       
   131     
       
   132     if( err != KErrNone )    
       
   133 	    {
       
   134 	    CleanupStack::PopAndDestroy( &variant );     
       
   135 	    return err;
       
   136 	    }
       
   137 	    
       
   138     TPtrC message = variant.AsDes();
       
   139        
       
   140 
       
   141     aActivationMsg.iServiceId = 0;
       
   142     aActivationMsg.iFileId    = 0;
       
   143     aActivationMsg.iDrive     = 0;            	
       
   144     aActivationMsg.iMsgSender = TVideoPlayerActivationMessage::EMatrixMenu;         
       
   145        
       
   146     if ( !message.CompareF( KVcxNsExtLaunchVideoCmd ) )
       
   147         {
       
   148         aActivationMsg.iMsgType = TVideoPlayerActivationMessage::ELaunchVideoToPlayer;
       
   149         TLiwVariant variantData;
       
   150         variantData.PushL();
       
   151         err = ExtractVariant( aMap, variantData, KKeyMessageData );
       
   152 
       
   153         if( err == KErrNone )
       
   154             {
       
   155             TPtrC data = variantData.AsDes();
       
   156             aActivationMsg.iFullPath = data;
       
   157             }
       
   158         else if( err == KErrNotFound )
       
   159             {
       
   160             err = KErrNone;
       
   161             }
       
   162         CleanupStack::PopAndDestroy( &variantData );
       
   163         }
       
   164     else if ( !message.CompareF( KVcxNsExtLaunchLastWatchedCmd ) )
       
   165         {
       
   166         aActivationMsg.iMsgType = TVideoPlayerActivationMessage::ELaunchVideoToPlayer;
       
   167         LoadLwDataL( aActivationMsg );
       
   168         }
       
   169     else if ( !message.CompareF( KVcxNsExtOpenStorageCmd ) )
       
   170         {
       
   171         aActivationMsg.iMsgType = TVideoPlayerActivationMessage::EOpenVideoStorage;    
       
   172         }
       
   173     else if ( !message.CompareF( KVcxNsExtInternetVideoCmd ) )
       
   174         {
       
   175         aActivationMsg.iMsgType = TVideoPlayerActivationMessage::EOpenInternetVideos;
       
   176         }
       
   177     else if ( !message.CompareF( KVcxNsExtServiceCatalCmd ) )
       
   178         {
       
   179         aActivationMsg.iMsgType = TVideoPlayerActivationMessage::EOpenServiceCatalogue;
       
   180         }
       
   181     else if ( !message.CompareF( KVcxNsExtVideoShopCmd ) )
       
   182         {
       
   183         aActivationMsg.iMsgType = TVideoPlayerActivationMessage::EOpenVideoShop;
       
   184         }
       
   185     else if ( !message.CompareF( KVcxNsExtLaunchVCSettingsCmd ) )
       
   186         {
       
   187         aActivationMsg.iMsgType = TVideoPlayerActivationMessage::EOpenVCSettings;
       
   188         }
       
   189     else if ( !message.CompareF( KVcxNsExtOpenLiveTVCmd ) )
       
   190 		{
       
   191 		aActivationMsg.iMsgType = TVideoPlayerActivationMessage::ELiveTVMessage;
       
   192 		}
       
   193     else if( !message.CompareF( KVcxNsExtLaunchLiveTVLastWatch ) )
       
   194         {
       
   195         aActivationMsg.iMsgType = TVideoPlayerActivationMessage::ELiveTVMessageLastWatched;
       
   196         }
       
   197     else if( !message.CompareF( KVcxNsExtLoadTvVideoSuite ) )
       
   198         {
       
   199         // If the player app is running 
       
   200         // in background, switch to that
       
   201         TryBringVideoPlayerToForegroundL();
       
   202 
       
   203         SendMediatorEvent( KVcxNsAhEventSuiteLoaded ); 
       
   204         // This needs cleaner way to not to execute the cmd.
       
   205         err = KErrNotSupported;
       
   206         }
       
   207     else if ( !message.CompareF( KVcxNsExtUnloadTvVideoSuite ) )
       
   208         {
       
   209         SendMediatorEvent( KVcxNsAhEventSuiteUnloaded ); 
       
   210         // This needs cleaner way to not to execute the cmd.
       
   211         err = KErrNotSupported;
       
   212         }
       
   213     else
       
   214         {
       
   215         err = KErrNotSupported;
       
   216         }
       
   217     CleanupStack::PopAndDestroy( &variant );
       
   218     
       
   219     return err;
       
   220 	}
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CVideoActionHandler::StartAppL
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 TInt CVideoActionHandler::StartAppL( TVideoPlayerActivationMessage& aMessage )
       
   227     {
       
   228     TInt err(KErrNone);    
       
   229     
       
   230     // If settings are requested launch them, otherwise launch my videos
       
   231     if (aMessage.iMsgType == TVideoPlayerActivationMessage::EOpenVCSettings)
       
   232         {
       
   233         err = LaunchMediaSettingsL( aMessage );
       
   234         }
       
   235     else
       
   236         {
       
   237         err = LaunchMyVideosL( aMessage );
       
   238         }
       
   239     
       
   240     return err;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // CVideoActionHandler::ExtractVariant
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 TInt CVideoActionHandler::ExtractVariant( const CLiwMap* aMap,
       
   248 								          TLiwVariant& aVariant,
       
   249 								          const TDesC8& aKeyName )
       
   250    
       
   251     {
       
   252     TInt errCode( KErrNone );
       
   253 	TBool found( EFalse );
       
   254     TRAP( errCode, found = aMap->FindL( aKeyName, aVariant ) );
       
   255     
       
   256     if ( errCode == KErrNone && !found )
       
   257        	{
       
   258        	errCode = KErrNotFound;
       
   259     	}
       
   260 	
       
   261 	return errCode;
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // CVideoActionHandler::SendMediatorEvent
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CVideoActionHandler::SendMediatorEvent( TInt aEvent )
       
   269     {
       
   270     iMediatorEventProvider->RaiseEvent( 
       
   271                                     TUid::Uid( KVcxNsAhMediatorDomain ),
       
   272                                     TUid::Uid( KVcxNsAhMediatorCategory ), 
       
   273                                     aEvent,
       
   274                                     TVersion( KVcxNsAhEventVersion, 0, 0 ),
       
   275                                     KNullDesC8() );
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CVideoActionHandler::LaunchMediaSettingsL
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 TInt CVideoActionHandler::LaunchMediaSettingsL( TVideoPlayerActivationMessage& aMessage )
       
   283     {
       
   284     // KIptvVodStartPlayer is not currently used. Any case we need it?    
       
   285     return LaunchMatrixTaskL( aMessage, KUidMediaSettingsApp, KVideoPlayerVodStartPlayer );
       
   286     }
       
   287 
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CVideoActionHandler::LaunchMyVideosL
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 TInt CVideoActionHandler::LaunchMyVideosL( TVideoPlayerActivationMessage& aMessage )
       
   294     {
       
   295     // KIptvVodStartPlayer is not currently used. Any case we need it?    
       
   296     return LaunchMatrixTaskL( aMessage, KUidMPXVideoPlayerApp, KVideoPlayerVodStartPlayer );    
       
   297     }
       
   298 
       
   299 
       
   300 // ---------------------------------------------------------------------------
       
   301 // CVideoActionHandler::LaunchMatrixTaskL
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 TInt CVideoActionHandler::LaunchMatrixTaskL( TVideoPlayerActivationMessage& aMessage, TUid appUID, TInt aActivationMessage )
       
   305     {
       
   306 
       
   307     TInt err(KErrNone);
       
   308 
       
   309     TPckg<TVideoPlayerActivationMessage> message(aMessage);
       
   310 
       
   311     RWsSession session;
       
   312     User::LeaveIfError(session.Connect());
       
   313 
       
   314     // check if there is existing stand alone running
       
   315     TInt ourWgId( 0 );
       
   316     TInt ret( 0 );
       
   317 
       
   318     // No need to check wgId if we are lauching Media Settings
       
   319     if ( appUID != KUidMediaSettingsApp )
       
   320         {
       
   321         ret = RProperty::Get( KVideoPlayerRPropertyCategory, KVideoPlayerRPropertyWGIdKey, ourWgId );
       
   322         }
       
   323         
       
   324     if( !ret )
       
   325         {
       
   326         // check if the wgId is really one of our own
       
   327         TBuf<KVideoPlayerWgNameSize> wgName;
       
   328         session.GetWindowGroupNameFromIdentifier(ourWgId, wgName );        
       
   329         if( wgName.MatchF( KVideoPlayerWgName ) == KErrNotFound )
       
   330             {
       
   331             // Clear wg id, it is not ours anymore
       
   332             ourWgId = 0;
       
   333             }
       
   334         }
       
   335         
       
   336     if( ourWgId != 0 )
       
   337         {
       
   338         // Send message to our wg id            
       
   339         TUid play = TUid::Uid(aActivationMessage);        
       
   340         session.SetWindowGroupOrdinalPosition( ourWgId, 0 );
       
   341         err = session.SendMessageToWindowGroup( ourWgId, play, message );             
       
   342         }        
       
   343     else
       
   344         {
       
   345         // No stand alone available, create new one
       
   346         RApaLsSession lsSession;
       
   347         err = lsSession.Connect();
       
   348         TApaAppInfo appInfo;
       
   349 
       
   350         if (lsSession.GetAppInfo(appInfo, appUID) == KErrNone)
       
   351             {
       
   352             CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   353             cmdLine->SetExecutableNameL(appInfo.iFullName);
       
   354             cmdLine->SetTailEndL(message);
       
   355             User::LeaveIfError(lsSession.StartApp(*cmdLine));
       
   356             CleanupStack::PopAndDestroy(cmdLine);
       
   357             }
       
   358         else
       
   359             {
       
   360             err = KErrNotFound;
       
   361             }
       
   362 
       
   363         lsSession.Close();   
       
   364         }    
       
   365     
       
   366     session.Close();
       
   367     return err;
       
   368     }
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // CVideoActionHandler::LoadLwDataL
       
   372 // ---------------------------------------------------------------------------
       
   373 //
       
   374 void CVideoActionHandler::LoadLwDataL( TVideoPlayerActivationMessage& aMessage )
       
   375     {
       
   376     CIptvLastWatchedData* data = CIptvLastWatchedData::NewL();
       
   377     CleanupStack::PushL( data );
       
   378     
       
   379     CIptvLastWatchedApi* lwApi = CIptvLastWatchedApi::NewL();
       
   380     CleanupStack::PushL( lwApi );
       
   381     
       
   382     lwApi->GetLastWatchedDataL( *data );
       
   383     
       
   384     if ( data->ParentalControl() != KVcxMyvideosCenRepParentControlKeyOff )
       
   385         {
       
   386         TInt parentControlSetting( KVcxMyvideosCenRepParentControlKeyDefault );
       
   387         CRepository* rep = NULL;
       
   388         TInt error;
       
   389         TRAP( error, rep = CRepository::NewL( TUid::Uid( KVcxMyVideosCenRepUid ) ) )
       
   390 
       
   391         if ( error == KErrNone )
       
   392             {
       
   393             CleanupStack::PushL( rep );
       
   394             
       
   395             error = rep->Get( KVcxMyvideosCenRepParentControlKey, parentControlSetting );
       
   396             
       
   397             if ( error == KErrNone && parentControlSetting != KVcxMyvideosCenRepParentControlKeyOff )
       
   398                 {
       
   399                 if ( static_cast<TInt>( data->ParentalControl() ) >= parentControlSetting )
       
   400                     {
       
   401                     CVcxHgVodTelephonyClient* tc = new( ELeave ) CVcxHgVodTelephonyClient();
       
   402                     CleanupStack::PushL(tc);
       
   403                     
       
   404                     if ( !tc->CheckLockCodeL() )
       
   405                         {
       
   406                         CErrorUI* eu = CErrorUI::NewLC();
       
   407                         eu->ShowGlobalErrorNoteL( KErrPermissionDenied );
       
   408                         CleanupStack::PopAndDestroy( eu );
       
   409                         User::Leave( KErrPermissionDenied );
       
   410                         }
       
   411                     
       
   412                     CleanupStack::PopAndDestroy( tc );
       
   413                     }
       
   414                 }
       
   415             CleanupStack::PopAndDestroy( rep );
       
   416             }
       
   417         }
       
   418 
       
   419     if( data->MpxId() != KIdUndefined )
       
   420         {
       
   421         aMessage.iServiceId = data->MpxId();
       
   422 		aMessage.iFullPath  = data->Uri();
       
   423         }
       
   424     else
       
   425         {
       
   426 		aMessage.iServiceId = 0;
       
   427 		aMessage.iFullPath = data->Uri();
       
   428         }
       
   429     
       
   430     CleanupStack::PopAndDestroy( lwApi );
       
   431     CleanupStack::PopAndDestroy( data );
       
   432     }
       
   433 
       
   434 // ---------------------------------------------------------------------------
       
   435 // CVideoActionHandler::TryBringVideoPlayerToForegroundL
       
   436 // ---------------------------------------------------------------------------
       
   437 //
       
   438 TInt CVideoActionHandler::TryBringVideoPlayerToForegroundL()
       
   439     {
       
   440     TInt ret ( KErrNotFound );
       
   441     RWsSession session;
       
   442     User::LeaveIfError( session.Connect() );
       
   443 	CleanupClosePushL( session );
       
   444 
       
   445     TInt ourWgId( 0 );
       
   446     TInt error = RProperty::Get( KVideoPlayerRPropertyCategory, KVideoPlayerRPropertyWGIdKey, ourWgId );
       
   447         
       
   448     if( error == KErrNone && ourWgId != 0 )
       
   449         {
       
   450         TBuf<KVideoPlayerWgNameSize> wgName;
       
   451         session.GetWindowGroupNameFromIdentifier(ourWgId, wgName );
       
   452         
       
   453         if( wgName.MatchF( KVideoPlayerWgName ) != KErrNotFound )
       
   454             {
       
   455             ret = session.SetWindowGroupOrdinalPosition( ourWgId, 0 );
       
   456             }
       
   457         }
       
   458 
       
   459 	CleanupStack::PopAndDestroy( &session );
       
   460     return ret;
       
   461     }