fmradio/fmradioactionhandler/src/fmradioactionhandler.cpp
changeset 0 f3d95d9c00ab
equal deleted inserted replaced
-1:000000000000 0:f3d95d9c00ab
       
     1 /*
       
     2 * Copyright (c) 2009 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 the FM Radio Action Handler Plugin.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32cmn.h>
       
    19 #include <e32property.h>
       
    20 #include <e32std.h>
       
    21 #include <w32std.h>
       
    22 #include <ecom/implementationproxy.h>
       
    23 #include <liwvariant.h>
       
    24 #include <apgtask.h>
       
    25 #include <apgcli.h>
       
    26 #include <apacmdln.h>
       
    27 #include <fmradiocommandlineparams.h>
       
    28 #include <fmradiointernalpskeys.h>
       
    29 #include <fmradiouids.h>
       
    30 
       
    31 #include "fmradioactionhandler.h"
       
    32 #include "fmradioactionhandler.hrh"
       
    33 #include "fmradioactionhandlerdefs.h"
       
    34 
       
    35 // ---------------------------------------------------------
       
    36 // CFMRadioActionHandler::NewL
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 CFMRadioActionHandler* CFMRadioActionHandler::NewL()
       
    40     {
       
    41     CFMRadioActionHandler* self = new ( ELeave ) CFMRadioActionHandler(); 
       
    42     CleanupStack::PushL( self );
       
    43     
       
    44     self->ConstructL();
       
    45     
       
    46     CleanupStack::Pop( self );
       
    47     return self;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CFMRadioActionHandler::~CFMRadioActionHandler
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 CFMRadioActionHandler::~CFMRadioActionHandler()
       
    55     {
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CFMRadioActionHandler::CFMRadioActionHandler
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 CFMRadioActionHandler::CFMRadioActionHandler()
       
    63     {
       
    64     }
       
    65     
       
    66 // ---------------------------------------------------------
       
    67 // CFMRadioActionHandler::ConstructL
       
    68 // ---------------------------------------------------------
       
    69 //
       
    70 void CFMRadioActionHandler::ConstructL()
       
    71     {
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------
       
    75 // CFMRadioActionHandler::ExecuteActionL
       
    76 // ---------------------------------------------------------
       
    77 //
       
    78 TInt CFMRadioActionHandler::ExecuteActionL( const CLiwMap* aMap )
       
    79     {
       
    80     TInt retValue( KErrNone );
       
    81     RBuf command;
       
    82     CleanupClosePushL( command );
       
    83     
       
    84     retValue = ExtractStringL( aMap, command, KFMRadioCommand);
       
    85     if ( retValue == KErrNone )
       
    86         {
       
    87         if ( !command.CompareF( KFMRadioCommandValueStepPrevious ) )
       
    88             {
       
    89             StepPrevious();
       
    90             }
       
    91         else if ( !command.CompareF( KFMRadioCommandValueStepNext ) )
       
    92             {
       
    93             StepNext();
       
    94             }
       
    95         else if ( !command.CompareF( KFMRadioCommandValueMute) )
       
    96             {
       
    97             Mute();
       
    98             }
       
    99         else if ( !command.CompareF( KFMRadioCommandValueUnmute ) )
       
   100             {
       
   101             Unmute();
       
   102             }
       
   103         else if ( !command.CompareF( KFMRadioCommandValueSeekUp ) )
       
   104             {
       
   105             SeekUp();
       
   106             }
       
   107         else if ( !command.CompareF( KFMRadioCommandValueSeekDown ) )
       
   108             {
       
   109             SeekDown();
       
   110             }
       
   111         else if ( !command.CompareF( KFMRadioCommandValueStartNowPlaying ) )
       
   112             {
       
   113             StartToNowPlayingL();
       
   114             }
       
   115         else
       
   116             {
       
   117             retValue = KErrNotSupported;
       
   118             }
       
   119         }
       
   120     CleanupStack::PopAndDestroy( &command );
       
   121     return retValue;
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CFMRadioActionHandler::StepPrevious
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 void CFMRadioActionHandler::StepPrevious()
       
   129     {
       
   130     RProperty::Set( KFMRadioPSUid, KFMRadioPSControlStepToChannel, EFMRadioPSStepToChannelDown );
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // CFMRadioActionHandler::StepNext
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 void CFMRadioActionHandler::StepNext()
       
   138     {
       
   139     RProperty::Set( KFMRadioPSUid, KFMRadioPSControlStepToChannel, EFMRadioPSStepToChannelUp );
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // CFMRadioActionHandler::Mute
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 void CFMRadioActionHandler::Mute()
       
   147     {
       
   148     RProperty::Set( KFMRadioPSUid, KFMRadioPSControlSetRadioMuteState, EFMRadioPSMuteStateOn );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------
       
   152 // CFMRadioActionHandler::Unmute
       
   153 // ---------------------------------------------------------
       
   154 //
       
   155 void CFMRadioActionHandler::Unmute()
       
   156     {
       
   157     RProperty::Set( KFMRadioPSUid, KFMRadioPSControlSetRadioMuteState, EFMRadioPSMuteStateOff );    
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------
       
   161 // CFMRadioActionHandler::SeekUp
       
   162 // ---------------------------------------------------------
       
   163 //
       
   164 void CFMRadioActionHandler::SeekUp()
       
   165     {
       
   166     //RProperty::Set( KFMRadioPSUid, KFMRadioPSControlSeek, EFMRadioPSSeekUp );
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CFMRadioActionHandler::SeekDown
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CFMRadioActionHandler::SeekDown()
       
   174     {
       
   175     //RProperty::Set( KFMRadioPSUid, KFMRadioPSControlSeek, EFMRadioPSSeekDown );
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------
       
   179 // CFMRadioActionHandler::StartToNowPlayingL
       
   180 // ---------------------------------------------------------
       
   181 //
       
   182 void CFMRadioActionHandler::StartToNowPlayingL()
       
   183     {
       
   184     RWsSession wsSession;
       
   185                 
       
   186     User::LeaveIfError(wsSession.Connect() );
       
   187     CleanupClosePushL( wsSession );
       
   188     
       
   189     TApaTaskList taskList( wsSession );
       
   190     TUid appUid = TUid::Uid( KUidFMRadioApplication );
       
   191     TApaTask fmRadioTask = taskList.FindApp( appUid );
       
   192     
       
   193     const TInt KFMRadioViewIdLength = 3;
       
   194     RBuf8 params;
       
   195     params.CreateL( KFMRadioCommandActivateView().Length() + KFMRadioViewIdLength );
       
   196     params.Copy( KFMRadioCommandActivateView );
       
   197     params.Append( _L(" ") );
       
   198     params.AppendNum( KFMRadioMainViewId.iUid );
       
   199     params.CleanupClosePushL();
       
   200     
       
   201     if ( !fmRadioTask.Exists() )
       
   202         {
       
   203         RApaLsSession apaSession;
       
   204         CleanupClosePushL( apaSession );
       
   205                 
       
   206         User::LeaveIfError( apaSession.Connect() );
       
   207         User::LeaveIfError( apaSession.GetAllApps() );
       
   208                 
       
   209         TApaAppInfo appInfo;
       
   210         User::LeaveIfError( apaSession.GetAppInfo( appInfo, appUid ) );
       
   211                 
       
   212         CApaCommandLine* startParams = CApaCommandLine::NewLC();
       
   213         startParams->SetExecutableNameL( appInfo.iFullName );
       
   214         startParams->SetCommandL( EApaCommandRun ); 
       
   215         startParams->SetTailEndL( params );
       
   216         User::LeaveIfError( apaSession.StartApp( *startParams ) );
       
   217         CleanupStack::PopAndDestroy( 2, &apaSession );
       
   218         }
       
   219     else
       
   220         {
       
   221         User::LeaveIfError( fmRadioTask.SendMessage( appUid, params ) );
       
   222         }
       
   223     CleanupStack::PopAndDestroy( 2 );
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------
       
   227 // CFMRadioActionHandler::ExtractStringLC
       
   228 // ---------------------------------------------------------
       
   229 //
       
   230 TInt CFMRadioActionHandler::ExtractStringL( const CLiwMap* aMap, RBuf& aString, const TDesC8& aMapName )
       
   231     {
       
   232     TInt err( KErrNotFound );
       
   233     TLiwVariant variant;
       
   234     variant.PushL();
       
   235     TPtrC tempString( KNullDesC );    
       
   236     if ( aMap->FindL( aMapName, variant ) )
       
   237         {
       
   238         variant.Get( tempString );
       
   239         aString.Close();
       
   240         aString.CreateL( tempString );
       
   241         err = KErrNone;
       
   242         }
       
   243     CleanupStack::PopAndDestroy( &variant );    
       
   244     return err;
       
   245     }
       
   246 
       
   247 /** Provides a key-value pair table, that is used to identify the correct construction function for the requested interface. */
       
   248 const TImplementationProxy KFMRadioActionHandlerImplementationTable[] =
       
   249     {
       
   250     IMPLEMENTATION_PROXY_ENTRY( KFMRadioActionHandlerImplementationUid, CFMRadioActionHandler::NewL )
       
   251     };
       
   252 
       
   253 const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount );
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // Returns the implementations provided by this ECOM plugin DLL.
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   260     {
       
   261     aTableCount = sizeof( KFMRadioActionHandlerImplementationTable ) / sizeof( TImplementationProxy );
       
   262     return KFMRadioActionHandlerImplementationTable;
       
   263     }