systemsettings/GSAccessoryPlugin/src/gsaccessorypluginmodel.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2005-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 of CGSAccessoryPluginModel class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <centralrepository.h>
       
    20 #include <featmgr.h>
       
    21 #include <HWRMDomainCRKeys.h> // HAC feature
       
    22 #include <ProfileEngineDomainCRKeys.h> // HAC feature
       
    23 #include <accessoriescrkeys.h>
       
    24 
       
    25 #include "gsaccessoryplugin.hrh"
       
    26 #include "gsaccessorypluginconst.hrh"
       
    27 #include "gsaccessorypluginmodel.h"
       
    28 #include "gsaccprofilelist.h"
       
    29 #include "trace.h"
       
    30 
       
    31 // ========================= MEMBER FUNCTIONS ================================
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CGSAccessoryPluginModel::NewL
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CGSAccessoryPluginModel* CGSAccessoryPluginModel::NewL()
       
    38     {
       
    39     CGSAccessoryPluginModel* self = new( ELeave ) CGSAccessoryPluginModel;
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CGSAccessoryPluginModel::~CGSAccessoryPluginModel
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CGSAccessoryPluginModel::~CGSAccessoryPluginModel()
       
    52     {
       
    53     FUNC_LOG;
       
    54 
       
    55     delete iProfileList;
       
    56     delete iAccessoryRepository;
       
    57     delete iHwSettingsRepository;
       
    58     delete iProfVariationRepository;
       
    59     delete iProfileRepository;
       
    60     iAccessorySettings.CloseSubSession();
       
    61     iAccServer.Disconnect();
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CGSAccessoryPluginModel::AccessorySupportedL
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TBool CGSAccessoryPluginModel::AccessorySupportedL( TInt aAccessory ) const
       
    70     {
       
    71     FUNC_LOG;
       
    72 
       
    73     TBool supported( EFalse );
       
    74     switch ( aAccessory )
       
    75         {
       
    76         case EGSHeadset:    // Fall through
       
    77         case EGSHeadphones: // Fall through
       
    78         case EGSMusicStand:
       
    79             supported = ETrue;
       
    80             break;
       
    81         case EGSWiredCarkit:
       
    82             User::LeaveIfError( iAccessoryRepository->Get(
       
    83                 KSettingsAccWiredCarkitSupported, supported ) );
       
    84             break;
       
    85         case EGSWirelessCarkit:
       
    86             User::LeaveIfError( iAccessoryRepository->Get(
       
    87                 KSettingsAccWirelessCarkitSupported, supported ) );
       
    88             break;
       
    89         case EGSTvout:
       
    90             supported = FeatureManager::FeatureSupported( KFeatureIdTvOut );
       
    91             break;
       
    92         case EGSLoopset:
       
    93             User::LeaveIfError( iAccessoryRepository->Get(
       
    94                 KSettingsAccLoopsetSupported, supported ) );
       
    95             break;
       
    96         case EGSTextPhone:
       
    97             supported = FeatureManager::FeatureSupported( KFeatureIdPhoneTty );
       
    98             break;
       
    99         case EGSHac:
       
   100             {
       
   101             TInt localFeatures( 0 );
       
   102             User::LeaveIfError( iProfVariationRepository->Get(
       
   103                 KProEngTonesViewLVFlags, localFeatures ) );
       
   104             supported = localFeatures & KTonesViewFeatureIdHac;
       
   105             }
       
   106             break;
       
   107         default:
       
   108             break;
       
   109         }
       
   110 
       
   111     INFO_2( "Accessory %d support status = %d", aAccessory, supported );
       
   112     return supported;
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CGSAccessoryPluginModel::DefaultAccessory
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 TInt CGSAccessoryPluginModel::DefaultAccessory() const
       
   121     {
       
   122     FUNC_LOG;
       
   123 
       
   124     TUint32 value( 0 );
       
   125     TInt error = iAccessorySettings.GetHWDeviceSettings( value );
       
   126     ERROR( error, "Failed to get default accessory" );
       
   127     return ( error == KErrNone ? value : error );
       
   128     }
       
   129 
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CGSAccessoryPluginModel::SetDefaultAccessory()
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CGSAccessoryPluginModel::SetDefaultAccessoryL( TInt aValue )
       
   136     {
       
   137     FUNC_LOG;
       
   138 
       
   139     iAccessorySettings.SetHWDeviceSettingsL( aValue );
       
   140     }
       
   141 
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CGSAccessoryPluginModel::DefaultProfileByKey
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 TInt CGSAccessoryPluginModel::DefaultProfileByKey( TInt aKey ) const
       
   148     {
       
   149     FUNC_LOG;
       
   150 
       
   151     // Feature flagging should be checked in the UI for configurable accessories.
       
   152     TInt profile( 0 );
       
   153     TInt error = iProfileRepository->Get( aKey, profile );
       
   154     ERROR_1( error, "Failed to read key %d value from profile repository", aKey );
       
   155     INFO_2( "Default profile key %d value is %d", aKey, profile );
       
   156     return ( error == KErrNone ? profile : error );
       
   157     }
       
   158 
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CGSAccessoryPluginModel::SetDefaultProfileByKeyL
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CGSAccessoryPluginModel::SetDefaultProfileByKeyL(
       
   165     TInt aKey,
       
   166     TInt aNewProfile )
       
   167     {
       
   168     FUNC_LOG;
       
   169 
       
   170     User::LeaveIfError( iProfileRepository->Set( aKey, aNewProfile ) );
       
   171     INFO_2( "Default profile key %d set to %d", aKey, aNewProfile );
       
   172     }
       
   173 
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CGSAccessoryPluginModel::AutoAnswerModeByKey
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 TInt CGSAccessoryPluginModel::AutoAnswerModeByKey( TInt aKey ) const
       
   180     {
       
   181     FUNC_LOG;
       
   182 
       
   183     TInt mode;
       
   184     TInt error = iAccessoryRepository->Get( aKey, mode );
       
   185     ERROR_1( error, "Failed to read key %d value from accessory repository", aKey );
       
   186     INFO_2( "Auto answer mode key %d value is %d", aKey, mode );
       
   187     if ( error == KErrNone )
       
   188         {
       
   189         return ( mode == 1 ? KIndexOn : KIndexOff ); // Map to list box indexes
       
   190         }
       
   191     return error;
       
   192     }
       
   193 
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CGSAccessoryPluginModel::SetAutoAnswerModeByKeyL
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CGSAccessoryPluginModel::SetAutoAnswerModeByKeyL(
       
   200     TInt aKey,
       
   201     TInt aMode ) const
       
   202     {
       
   203     FUNC_LOG;
       
   204 
       
   205     TInt val = ( aMode == KIndexOn ? 1 : 0 );
       
   206     INFO_1( "Setting automatic answer mode to %d", val );
       
   207     TInt error = iAccessoryRepository->Set( aKey, val );
       
   208     ERROR( error, "Failed to set automatic answer mode" );
       
   209     User::LeaveIfError( error );
       
   210     }
       
   211 
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CGSAccessoryPluginModel::LightModeL
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 TInt CGSAccessoryPluginModel::LightMode(
       
   218     TAccMode aAccMode,
       
   219     TInt aAccSetId ) const
       
   220     {
       
   221     FUNC_LOG;
       
   222 
       
   223     TAccModeSetting setting;
       
   224     setting.SetId( aAccSetId );
       
   225 
       
   226     TInt error = iAccessorySettings.GetAccessoryModeSetting( aAccMode, setting );
       
   227     ERROR_2( error, "Failed to read mode for accessory %d setting %d", aAccMode, aAccSetId );
       
   228 
       
   229     TInt mode( KErrNone );
       
   230     setting.GetTInt( mode );
       
   231 
       
   232     if ( error == KErrNone )
       
   233         {
       
   234         return ( mode == EAccLightsOn ? KIndexOn : KIndexAuto ); // Map to list box indexes
       
   235         }
       
   236     return error;
       
   237     }
       
   238 
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // CGSAccessoryPluginModel::SetLightModeL
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CGSAccessoryPluginModel::SetLightModeL(
       
   245     TAccMode aAccMode,
       
   246     TInt aAccSetId,
       
   247     TInt aLightMode )
       
   248     {
       
   249     FUNC_LOG;
       
   250 
       
   251     TAccModeSetting setting;
       
   252     setting.SetId( aAccSetId );
       
   253     TInt val = ( aLightMode == KIndexOn ? EAccLightsOn : EAccLightsAutomatic );
       
   254     INFO_3( "Setting light mode for accessry %d setting %d to %d", aAccMode, aAccSetId, val );
       
   255     setting.SetTInt( val );
       
   256     iAccessorySettings.SetAccessoryModeSettingL( aAccMode, setting );
       
   257     }
       
   258 
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // CGSAccessoryPluginModel::HacMode()
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 TInt CGSAccessoryPluginModel::HacMode()
       
   265     {
       
   266     FUNC_LOG;
       
   267 
       
   268     TInt mode;
       
   269     TInt error = iHwSettingsRepository->Get( KHWSettingsHearingAidMode, mode );
       
   270     ERROR( error, "Failed to read HAC mode" );
       
   271     INFO_1( "HAC mode = %d", mode );
       
   272     if ( error == KErrNone )
       
   273         {
       
   274         return ( mode == 1 ? KIndexOn : KIndexOff ); // Map to list box indexes
       
   275         }
       
   276     return error;
       
   277     }
       
   278 
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CGSAccessoryPluginModel::SetHACModeL()
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 void CGSAccessoryPluginModel::SetHacModeL( TInt aMode )
       
   285     {
       
   286     FUNC_LOG;
       
   287 
       
   288     TInt val = ( aMode == KIndexOn ? 1 : 0 );
       
   289     INFO_1( "Setting HAC mode to %d", val );
       
   290     TInt error = iHwSettingsRepository->Set( KHWSettingsHearingAidMode, val );
       
   291     ERROR( error, "Failed to set HAC mode" );
       
   292     User::LeaveIfError( error );
       
   293     }
       
   294 
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // CGSAccessoryPluginModel::PalmSupport
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 TBool CGSAccessoryPluginModel::PalmSupport()
       
   301     {
       
   302     return iPalmSupport;
       
   303     }
       
   304 
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // CGSAccessoryPluginModel::ProfileList
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 CGSAccProfileList& CGSAccessoryPluginModel::ProfileList() const
       
   311     {
       
   312     return *iProfileList;
       
   313     }
       
   314 
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CGSAccessoryPluginModel::FlipValue
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 void CGSAccessoryPluginModel::FlipValue( TInt& aValue )
       
   321     {
       
   322     FUNC_LOG;
       
   323 
       
   324     if ( aValue == 0 )
       
   325         {
       
   326         aValue = 1;
       
   327         }
       
   328     else
       
   329         {
       
   330         aValue = 0;
       
   331         }
       
   332     }
       
   333 
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // CGSAccessoryPluginModel::CGSAccessoryPluginModel
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 CGSAccessoryPluginModel::CGSAccessoryPluginModel()
       
   340     {
       
   341     FUNC_LOG;
       
   342     }
       
   343 
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // CGSAccessoryPluginModel::ConstructL
       
   347 // ---------------------------------------------------------------------------
       
   348 //
       
   349 void CGSAccessoryPluginModel::ConstructL()
       
   350     {
       
   351     FUNC_LOG;
       
   352 
       
   353     iAccessoryRepository = CRepository::NewL( KCRUidAccessorySettings );
       
   354     iProfileRepository = CRepository::NewL( KCRUidProfileSettings );
       
   355     iHwSettingsRepository = CRepository::NewL( KCRUidHWSettings );
       
   356     iProfVariationRepository = CRepository::NewL( KCRUidProfilesLV );
       
   357     iPalmSupport = EFalse;
       
   358 
       
   359     CRepository* tvRepository = CRepository::NewL( KCRUidTvoutSettings );
       
   360     CleanupStack::PushL( tvRepository );
       
   361     tvRepository->Get( KSettingsTvoutPalmVisibility, iPalmSupport ); // Ignore error
       
   362     CleanupStack::PopAndDestroy( tvRepository );
       
   363 
       
   364     iProfileList = CGSAccProfileList::NewL();
       
   365 
       
   366     // connect to Accessory server
       
   367     TInt error = iAccServer.Connect();
       
   368     ERROR( error, "Failed to connect to Accessory Server" );
       
   369     if ( !error )
       
   370         {
       
   371         // create a session to accessory settings
       
   372         error = iAccessorySettings.CreateSubSession( iAccServer );
       
   373         ERROR( error, "Failed to create Accessory Settings subsession" );
       
   374         }
       
   375 
       
   376     User::LeaveIfError( error );
       
   377     }
       
   378