mediasettings/videoplayersettingsengine/src/videoplayersettingsengine.cpp
changeset 0 96612d01cf9f
child 1 6711b85517b7
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2006-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 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:   App settings handles storing and loading of application settings*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32def.h>
       
    21 #include <bldvariant.hrh>
       
    22 #include <bautils.h>
       
    23 #include <centralrepository.h>
       
    24 #include <commdb.h>
       
    25 #include <sysutil.h>
       
    26 #include <mmtsy_names.h>
       
    27 #include <SecUi.h>
       
    28 #include <SecUiSecurityHandler.h>
       
    29 
       
    30 #include "videosettingsdrivemonitor.h"
       
    31 
       
    32 #include "videoplayersettingsengine.pan"
       
    33 #include "videoplayersettingsengine.h"
       
    34 #include "videoplayercenrepkeys.h"
       
    35 #include "mpxlog.h"
       
    36 
       
    37 // CONSTANTS
       
    38 const TInt KTimeBeforeRetryingServerConnection = 50000;
       
    39 
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CVcxNsSettingsEngine::CVcxNsSettings()
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CVcxNsSettingsEngine::CVcxNsSettingsEngine( )
       
    48  :  iPhoneConnected( EFalse )
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CVcxNsSettingsEngine::ConstructL
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CVcxNsSettingsEngine::ConstructL()
       
    57     {
       
    58     iCenRep = CRepository::NewL( KIptvCenRepUid );
       
    59     iAlrCenRep = CRepository::NewL( KIptvAlrCenRepUid );
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CVcxNsSettingsEngine::NewL()
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CVcxNsSettingsEngine* CVcxNsSettingsEngine::NewL( )
       
    67     {
       
    68     MPX_FUNC("IptvUiEngine ## CIptvAppSettings::NewL()");
       
    69     
       
    70     CVcxNsSettingsEngine* self = new (ELeave) CVcxNsSettingsEngine();
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     CleanupStack::Pop( self );
       
    74     return self;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CVcxNsSettingsEngine::~CIptvAppSettings()
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CVcxNsSettingsEngine::~CVcxNsSettingsEngine()
       
    82     {
       
    83     MPX_FUNC("IptvUiEngine ## CIptvAppSettings::~CIptvAppSettings()");
       
    84 
       
    85     if ( iPhoneConnected )
       
    86 	    {
       
    87 	    // close phone
       
    88 	    if ( iPhone.SubSessionHandle() )
       
    89 	        {
       
    90 	        iPhone.Close();
       
    91 	        }
       
    92 
       
    93 	    //close ETel connection
       
    94 	    if ( iServer.Handle() )
       
    95 	        {
       
    96 	        iServer.UnloadPhoneModule( KMmTsyModuleName );
       
    97 	        iServer.Close();
       
    98 	        }
       
    99     	}
       
   100 
       
   101     delete iCenRep;
       
   102     delete iAlrCenRep;
       
   103 
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CVcxNsSettingsEngine::GetUsedMemory()
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void CVcxNsSettingsEngine::GetUsedMemoryL( TInt& aUsedMemory )
       
   111     {
       
   112     MPX_FUNC("CVcxNsSettingsEngine::GetUsedMemoryL() start");
       
   113 
       
   114     CVideoSettingsDriveMonitor* driveMonitor = CVideoSettingsDriveMonitor::NewL();
       
   115     CleanupStack::PushL( driveMonitor ); // 1->
       
   116                 
       
   117     driveMonitor->GetUsedMemoryL( aUsedMemory );
       
   118 
       
   119     CleanupStack::PopAndDestroy( driveMonitor ); // <-1    
       
   120     }
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CVcxNsSettingsEngine::SetUsedMemory()
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C TBool CVcxNsSettingsEngine::SetUsedMemory( TInt aUsedMemory )
       
   128     {
       
   129     return SetCenRepIntKey( KIptvCenRepUid, 
       
   130                             KIptvCenRepPreferredMemoryKey, 
       
   131                             aUsedMemory );
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CVcxNsSettingsEngine::GetParentControl()
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 EXPORT_C TBool CVcxNsSettingsEngine::GetParentControl( TInt& aParentControl )
       
   139     {
       
   140     return GetCenRepIntKey( KIptvCenRepUid, 
       
   141                             KIptvCenRepParentControlKey,
       
   142                             aParentControl );
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CVcxNsSettingsEngine::SetParentControl()
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C TBool CVcxNsSettingsEngine::SetParentControl( TInt aParentControl )
       
   150     {
       
   151     return SetCenRepIntKey( KIptvCenRepUid, 
       
   152                             KIptvCenRepParentControlKey, 
       
   153                             aParentControl );
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CVcxNsSettingsEngine::GetVideoOnDemandThumbnails()
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C TBool CVcxNsSettingsEngine::GetVideoOnDemandThumbnails( TInt& aVodThumbnails )
       
   161     {
       
   162     return GetCenRepIntKey( KIptvCenRepUid, 
       
   163                             KIptvCenRepVoDThumbnailsKey, 
       
   164                             aVodThumbnails ); 
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CVcxNsSettingsEngine::SetVideoOnDemandThumbnails()
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C TBool CVcxNsSettingsEngine::SetVideoOnDemandThumbnails( TInt aVodThumbnails )
       
   172     {
       
   173     return SetCenRepIntKey( KIptvCenRepUid, KIptvCenRepVoDThumbnailsKey, aVodThumbnails );
       
   174     }
       
   175 
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CVcxNsSettingsEngine::GetUsedSnapId()
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 EXPORT_C TBool CVcxNsSettingsEngine::GetUsedSnapId( TInt& aUsedSnapId )
       
   182     {
       
   183     return GetCenRepIntKey( KIptvAlrCenRepUid, KIptvCenRepUsedSnapIdKey, aUsedSnapId );
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CVcxNsSettingsEngine::SetUsedSnapId()
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 EXPORT_C TBool CVcxNsSettingsEngine::SetUsedSnapId( TInt aUsedSnapId )
       
   191     {
       
   192     return SetCenRepIntKey( KIptvAlrCenRepUid, KIptvCenRepUsedSnapIdKey, aUsedSnapId );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CVcxNsSettingsEngine::GetAllowUseGprs()
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C TBool CVcxNsSettingsEngine::GetAllowUseGprs( TInt& aAllowUseGprs )
       
   200     {
       
   201     return GetCenRepIntKey( KIptvAlrCenRepUid, KIptvCenRepAllowUseGprsKey, aAllowUseGprs );
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CVcxNsSettingsEngine::SetAllowUseGprs()
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C TBool CVcxNsSettingsEngine::SetAllowUseGprs( TInt aAllowUseGprs )
       
   209     {
       
   210     return SetCenRepIntKey( KIptvAlrCenRepUid, KIptvCenRepAllowUseGprsKey, aAllowUseGprs );
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CVcxNsSettingsEngine::GetAllowRoaming()
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 EXPORT_C TBool CVcxNsSettingsEngine::GetAllowRoaming( TInt& aAllowRoaming )
       
   218     {
       
   219     return GetCenRepIntKey( KIptvAlrCenRepUid, KIptvCenRepAllowRoamingKey, aAllowRoaming );
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CVcxNsSettingsEngine::SetAllowRoaming()
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 EXPORT_C TBool CVcxNsSettingsEngine::SetAllowRoaming( TInt aAllowRoaming )
       
   227     {
       
   228     return SetCenRepIntKey( KIptvAlrCenRepUid, KIptvCenRepAllowRoamingKey, aAllowRoaming );
       
   229     }
       
   230 
       
   231     
       
   232 // -----------------------------------------------------------------------------
       
   233 // CVcxNsSettingsEngine::CheckLockCodeL()
       
   234 // -----------------------------------------------------------------------------
       
   235 //   
       
   236 EXPORT_C TBool CVcxNsSettingsEngine::CheckLockCodeL()
       
   237     {
       
   238     TBool lockCodeAccepted = EFalse ;
       
   239     
       
   240     if ( !iPhoneConnected )
       
   241         {
       
   242         // Connect to ETel server
       
   243         // All server connections are retried because occasional
       
   244         // fails on connections are possible, at least on some servers.
       
   245         TInt err = iServer.Connect();
       
   246         if ( err != KErrNone )
       
   247             {
       
   248             User::After( KTimeBeforeRetryingServerConnection );
       
   249             TInt err = iServer.Connect();
       
   250             }
       
   251         User::LeaveIfError( err );
       
   252         User::LeaveIfError( iServer.SetExtendedErrorGranularity(
       
   253             RTelServer::EErrorExtended ) );
       
   254 
       
   255         // Load TSY.
       
   256         err = iServer.LoadPhoneModule( KMmTsyModuleName );
       
   257         if ( KErrAlreadyExists != err )
       
   258             {
       
   259             // May also return KErrAlreadyExists if something else
       
   260             // has already loaded the TSY module. And that is
       
   261             // not an error.
       
   262             User::LeaveIfError( err );
       
   263             }
       
   264 
       
   265         // Open phones
       
   266         User::LeaveIfError( iPhone.Open( iServer, KMmTsyPhoneName ) );
       
   267         iPhoneConnected = ETrue;
       
   268         }
       
   269 
       
   270 #ifndef __WINS__
       
   271     // Initialize sec ui.
       
   272     CSecurityHandler* handler = new( ELeave ) CSecurityHandler( iPhone );
       
   273     CleanupStack::PushL( handler );
       
   274     TSecUi::InitializeLibL();
       
   275 
       
   276     lockCodeAccepted = handler->AskSecCodeL();
       
   277 
       
   278 	// Uninitialize security ui.
       
   279 	CleanupStack::PopAndDestroy( handler );
       
   280 	TSecUi::UnInitializeLib();
       
   281 #else
       
   282         lockCodeAccepted = ETrue;
       
   283 #endif
       
   284 
       
   285     return lockCodeAccepted;
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CVcxNsSettingsEngine::GetCenRepIntKey()
       
   290 // -----------------------------------------------------------------------------
       
   291 //            
       
   292 TBool CVcxNsSettingsEngine::GetCenRepIntKey( TUid aCategory, TInt aKey, TInt& aValue )
       
   293     {
       
   294     TInt error = KErrNotFound;
       
   295 
       
   296     if ( aCategory == KIptvCenRepUid && iCenRep )
       
   297         {
       
   298         error = iCenRep->Get( aKey, aValue );
       
   299         }
       
   300     else if ( aCategory == KIptvAlrCenRepUid && iAlrCenRep )
       
   301         {
       
   302         error = iAlrCenRep->Get( aKey, aValue );
       
   303         }
       
   304     
       
   305     return (error == KErrNone) ? ETrue : EFalse;
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CVcxNsSettingsEngine::SetCenRepIntKey()
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 TBool CVcxNsSettingsEngine::SetCenRepIntKey( TUid aCategory, TInt aKey, TInt aValue )
       
   313     {
       
   314     TInt error = KErrNotFound;
       
   315 
       
   316     if ( aCategory == KIptvCenRepUid && iCenRep )
       
   317         {
       
   318         error = iCenRep->Set( aKey, aValue );
       
   319         }
       
   320 
       
   321     else if ( aCategory == KIptvAlrCenRepUid && iAlrCenRep )
       
   322         {
       
   323         error = iAlrCenRep->Set( aKey, aValue );
       
   324         }
       
   325 
       
   326     return (error == KErrNone) ? ETrue : EFalse;    
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CVcxNsSettingsEngine::GetPlayerVolume()
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 EXPORT_C TBool CVcxNsSettingsEngine::GetPlayerVolume( TInt& aVolume )
       
   334     {
       
   335     return GetCenRepIntKey( KIptvCenRepUid, 
       
   336                             KIptvCenRepVideoPlayerVolumeKey, 
       
   337                             aVolume );
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CVcxNsSettingsEngine::SetPlayerVolume()
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 EXPORT_C TBool CVcxNsSettingsEngine::SetPlayerVolume( TInt aVolume )
       
   345     {
       
   346     return SetCenRepIntKey( KIptvCenRepUid, 
       
   347                             KIptvCenRepVideoPlayerVolumeKey, 
       
   348                             aVolume );
       
   349     }
       
   350 
       
   351 // End of File