tactilefeedback/tactileactionplugin/src/tactileactionplugin.cpp
changeset 0 d54f32e146dd
equal deleted inserted replaced
-1:000000000000 0:d54f32e146dd
       
     1 /*
       
     2 * Copyright (c) 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:  A plug-in for turning tactile feedback on/off.
       
    15 * Part of:      Tactile Feedback.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <badesca.h>
       
    22 #include <cfactionindication.h>
       
    23 #include <e32property.h>
       
    24 #include <centralrepository.h>
       
    25 
       
    26 #include "tactileactionplugin.h"
       
    27 #include "tactilefeedbackinternalpskeys.h"
       
    28 #include "tactilefeedbackprivatecrkeys.h"
       
    29 #include "tactilefeedbacktrace.h"
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // Constants for tactile feedback actions
       
    34 _LIT( KActionId,         "Tactile" );
       
    35 _LIT( KActionIdCommand,  "Feedback" );
       
    36 _LIT( KActionCommandOn,  "ON" );
       
    37 _LIT( KActionCommandOff, "OFF" );
       
    38 
       
    39 // Constants used for setting Tactile Feedback while in-call and while
       
    40 // no call is in progress. See tactilefeedbackinternalpskeys.h for 
       
    41 // documentation.
       
    42 const TInt KTactilePSValueWhileInCall = 0x00; // Vibra and audio disabled
       
    43 const TInt KTactilePSValueWhileInCallAudioOff = 0x01; // Vibra enabled, audio disabled
       
    44 const TInt KTactilePSValueWhileInCallVibraOff = 0x02; // Vibra disabled, audio enabled
       
    45 const TInt KTactilePSValueWhileNoCall = 0x03; // Vibra and audio enabled
       
    46 
       
    47 // Security policy
       
    48 _LIT_SECURITY_POLICY_PASS( KSecurityPolicy );
       
    49 
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CTactileActionPlugIn::CTactileActionPlugIn
       
    54 // C++ default constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CTactileActionPlugIn::CTactileActionPlugIn( ) 
       
    58  : CCFActionPlugIn()                                  
       
    59     {
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CTactileActionPlugIn::NewL
       
    64 // Two-phased constructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CTactileActionPlugIn* CTactileActionPlugIn::NewL( )
       
    68     {
       
    69     CTactileActionPlugIn* self = CTactileActionPlugIn::NewLC();
       
    70     CleanupStack::Pop( self );
       
    71     return self;
       
    72     }
       
    73   
       
    74 // -----------------------------------------------------------------------------
       
    75 // CTactileActionPlugIn::NewLC
       
    76 // Two-phased constructor.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CTactileActionPlugIn* CTactileActionPlugIn::NewLC( )
       
    80     {
       
    81     CTactileActionPlugIn* self = new( ELeave ) CTactileActionPlugIn();
       
    82     CleanupStack::PushL( self );
       
    83     return self;
       
    84     }
       
    85   
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CTactileActionPlugIn::~CTactileActionPlugIn
       
    89 // Destructor.
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CTactileActionPlugIn::~CTactileActionPlugIn()
       
    93     {
       
    94     }
       
    95 
       
    96 //-----------------------------------------------------------------------------
       
    97 // CTactileActionPlugIn::InitializeL
       
    98 // Initializes the plugin, called by the CF framework.
       
    99 //-----------------------------------------------------------------------------
       
   100 //
       
   101 void CTactileActionPlugIn::InitializeL()
       
   102     {
       
   103     TRACE("CTactileActionPlugIn::InitializeL(): start");
       
   104     CRepository* repository = CRepository::NewL( KCRUidTactileFeedback );
       
   105     CleanupStack::PushL( repository );
       
   106     
       
   107     TInt tactileSettings(0);
       
   108     repository->Get( KTactileInternalSettings, tactileSettings );
       
   109     
       
   110     // Clean all other settings values, leave only in-call settings.
       
   111     tactileSettings &= ( KTactileInternalSettingsCallDisableVibra | 
       
   112                          KTactileInternalSettingsCallDisableAudio );
       
   113     
       
   114     switch ( tactileSettings )                    
       
   115         {
       
   116         case KTactileInternalSettingsCallDisableVibra:
       
   117             iFeedbackInCall = KTactilePSValueWhileInCallVibraOff;
       
   118             break;
       
   119         case KTactileInternalSettingsCallDisableAudio:
       
   120             iFeedbackInCall = KTactilePSValueWhileInCallAudioOff;
       
   121             break;
       
   122         case ( KTactileInternalSettingsCallDisableVibra | 
       
   123                KTactileInternalSettingsCallDisableAudio ):
       
   124             iFeedbackInCall = KTactilePSValueWhileInCall;
       
   125             break;  
       
   126         default:
       
   127             iFeedbackInCall = KTactilePSValueWhileNoCall;
       
   128             break;
       
   129         }    
       
   130     CleanupStack::PopAndDestroy( repository );
       
   131     TRACE("CTactileActionPlugIn::InitializeL(): end");
       
   132     }
       
   133 
       
   134 //-----------------------------------------------------------------------------
       
   135 // CTactileActionPlugIn::ExecuteL
       
   136 // Executes an action.
       
   137 //-----------------------------------------------------------------------------
       
   138 //
       
   139 CCFActionPlugIn::TExecutionTime CTactileActionPlugIn::ExecuteL(
       
   140     CCFActionIndication* aActionIndication )
       
   141     {
       
   142     TRACE("CTactileActionPlugIn::ExecuteL(): start");
       
   143     
       
   144     // get action parameters
       
   145     const RKeyValueArray& parameters = aActionIndication->Parameters();
       
   146     
       
   147     for( TInt i = 0; i < parameters.Count(); i++ )
       
   148         {
       
   149         // get received parameter and its value
       
   150         TPtrC param( parameters[i]->Key() );
       
   151         TPtrC value( parameters[i]->Value() );
       
   152 
       
   153         // check command
       
   154         if ( param == KActionIdCommand )
       
   155             {
       
   156             TInt err = KErrNone;
       
   157             
       
   158             if ( value == KActionCommandOn )
       
   159                 {
       
   160                 // Turn tactile feedback on
       
   161                 TRACE( "CTactileActionPlugIn::ExecuteL(): Feedback set ON");
       
   162                 err = RProperty::Set( KPSUidTactileFeedback, 
       
   163                                       KTactileFeedbackEnabled, 
       
   164                                       KTactilePSValueWhileNoCall );
       
   165                 }
       
   166             else if ( value == KActionCommandOff )
       
   167                 {
       
   168                 // Turn tactile feedback off
       
   169                 TRACE("CTactileActionPlugIn::ExecuteL(): Feedback set OFF");
       
   170                 err = RProperty::Set( KPSUidTactileFeedback, 
       
   171                                       KTactileFeedbackEnabled, 
       
   172                                       iFeedbackInCall );
       
   173                 }
       
   174             
       
   175             TRACE2("CTactileActionPlugIn::ExecuteL(): Set returned %d", err);
       
   176             
       
   177             User::LeaveIfError( err );
       
   178             }
       
   179         }
       
   180         
       
   181     TRACE("CTactileActionPlugIn::ExecuteL(): end");
       
   182     
       
   183     // not async operation --> return always ENone
       
   184     return CCFActionPlugIn::ENone;
       
   185     }
       
   186 
       
   187 //-----------------------------------------------------------------------------
       
   188 // CTactileActionPlugIn::GetActionsL
       
   189 // Returns all the actions the plugin can perform.
       
   190 //-----------------------------------------------------------------------------
       
   191 //
       
   192 void CTactileActionPlugIn::GetActionsL( CDesCArray& aActionList ) const
       
   193     {
       
   194     TRACE("CTactileActionPlugIn::GetActionsL(): start");
       
   195 
       
   196     aActionList.AppendL( KActionId );
       
   197 
       
   198     TRACE("CTactileActionPlugIn::GetActionsL(): end");
       
   199     }
       
   200 
       
   201 //-----------------------------------------------------------------------------
       
   202 // CTactileActionPlugIn::SecurityPolicy
       
   203 // Returns the capabilities required by the plugin.
       
   204 //-----------------------------------------------------------------------------
       
   205 //
       
   206 const TSecurityPolicy& CTactileActionPlugIn::SecurityPolicy() const
       
   207     {
       
   208     TRACE("CTactileActionPlugIn::SecurityPolicy()");
       
   209 
       
   210     return KSecurityPolicy;
       
   211     }
       
   212     
       
   213 // End of File