commondrm/drmsettingsplugin/src/drmsettingsmodel.cpp
branchRCL_3
changeset 26 1221b68b8a5f
parent 25 50c53e893c3f
child 27 1481bf457703
equal deleted inserted replaced
25:50c53e893c3f 26:1221b68b8a5f
     1 /*
       
     2 * Copyright (c) 2006-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:  Model for DRMSettinsPlugin.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <utf.h>
       
    21 #include <commdb.h>
       
    22 #include <featmgr.h>
       
    23 
       
    24 #include "drmsettingsmodel.h"
       
    25 #include "drmsettingsplugininternalcrkeys.h"
       
    26 #include "DRMRIContext.h"
       
    27 
       
    28 // CONSTANTS
       
    29 #ifdef _DEBUG
       
    30 // debug panic
       
    31 _LIT( KDRMSettingsDebugPanicMessage, "DrmSettingsDebugPanic" );
       
    32 const TInt KDRMSettingsDebugPanicCode( 1 );
       
    33 #endif
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // CDRMSettingsModel::NewL
       
    40 //
       
    41 // EPOC two-phased constructor
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 CDRMSettingsModel* CDRMSettingsModel::NewL()
       
    45     {
       
    46     CDRMSettingsModel* self = new( ELeave ) CDRMSettingsModel;
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CDRMSettingsModel::CDRMSettingsModel
       
    56 //
       
    57 // C++ default constructor can NOT contain any code, that
       
    58 // might leave.
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 CDRMSettingsModel::CDRMSettingsModel()
       
    62     {
       
    63     }
       
    64 
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // CDRMSettingsModel::ConstructL
       
    68 //
       
    69 // EPOC default constructor can leave.
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 void CDRMSettingsModel::ConstructL()
       
    73     {
       
    74     // create an instance of Central Repository
       
    75     iDRMSettingsRepository = CRepository::NewL( KCRUidDRMSettings );
       
    76 
       
    77 #ifdef RD_DRM_METERING
       
    78 
       
    79     // Create an instance of roap storage client
       
    80     iRoapStorageClient = new (ELeave) Roap::RRoapStorageClient;
       
    81 
       
    82     // Connect to server
       
    83     User::LeaveIfError( iRoapStorageClient->Connect() );
       
    84 
       
    85     // Fill the list
       
    86     iRoapStorageClient->GetAllRIContextsL( iRIContextList );
       
    87 
       
    88 #endif // RD_DRM_METERING
       
    89 
       
    90     }
       
    91 
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CDRMSettingsModel::~CDRMSettingsModel
       
    95 //
       
    96 // Destructor
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 CDRMSettingsModel::~CDRMSettingsModel()
       
   100     {
       
   101     if ( iDRMSettingsRepository )
       
   102         {
       
   103         delete iDRMSettingsRepository;
       
   104         }
       
   105     if ( iRoapStorageClient )
       
   106         {
       
   107         iRoapStorageClient->Close();
       
   108         delete iRoapStorageClient;
       
   109         }
       
   110 
       
   111     iRIContextList.ResetAndDestroy();
       
   112     iRIContextList.Close();
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CDRMSettingsModel::SetTransactionTrackingStateL()
       
   118 //
       
   119 // Set transaction tracking state
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CDRMSettingsModel::SetTransactionTrackingStateL( TInt aValue )
       
   123     {
       
   124     User::LeaveIfError( iDRMSettingsRepository->
       
   125                                 Set( KDRMSettingsTransactionTracking,
       
   126                                      aValue ) );
       
   127     }
       
   128 
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // CDRMSettingsModel::TransactionTrackingStateL()
       
   132 //
       
   133 // Get transaction tracking state
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 TInt CDRMSettingsModel::TransactionTrackingStateL()
       
   137     {
       
   138     TInt value( KErrNone );
       
   139 
       
   140     User::LeaveIfError( iDRMSettingsRepository->Get(
       
   141                                     KDRMSettingsTransactionTracking,
       
   142                                     value ) );
       
   143 
       
   144     return value;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CDRMSettingsModel::SetAutomaticActivationStateL()
       
   149 //
       
   150 // Set automatic activation state
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CDRMSettingsModel::SetAutomaticActivationStateL( TInt aValue )
       
   154     {
       
   155     User::LeaveIfError( iDRMSettingsRepository->
       
   156                                 Set( KDRMSettingsSilentRightsAcquisition,
       
   157                                      aValue ) );
       
   158     }
       
   159 
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CDRMSettingsModel::AutomaticActivationStateL()
       
   163 //
       
   164 // Get automatic activation state
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 TInt CDRMSettingsModel::AutomaticActivationStateL()
       
   168     {
       
   169     TInt value( KErrNone );
       
   170 
       
   171     User::LeaveIfError( iDRMSettingsRepository->Get(
       
   172                                 KDRMSettingsSilentRightsAcquisition,
       
   173                                 value ) );
       
   174 
       
   175     return value;
       
   176     }
       
   177 
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CDRMSettingsModel::UsageReportingCount()
       
   181 //
       
   182 // Get usage reporting state. Return count of allowed services.
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 TInt CDRMSettingsModel::UsageReportingCount()
       
   186     {
       
   187     TInt count( 0 );
       
   188 
       
   189     for ( TInt i( 0 ); i < iRIContextList.Count(); i++ )
       
   190         {
       
   191         if ( iRIContextList[i]->IsMeteringAllowed() )
       
   192             {
       
   193             count++;
       
   194             }
       
   195         }
       
   196 
       
   197     return count;
       
   198     }
       
   199 
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // CDRMSettingsModel::GetSingleRIAliasL()
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 HBufC* CDRMSettingsModel::GetSingleRIAliasL( TInt aIndex )
       
   206     {
       
   207     __ASSERT_DEBUG( aIndex >= 0 ||
       
   208                     aIndex < iRIContextList.Count(),
       
   209                         User::Panic( KDRMSettingsDebugPanicMessage,
       
   210                                      KDRMSettingsDebugPanicCode ) );
       
   211 
       
   212     HBufC* alias( NULL );
       
   213 
       
   214     if ( &iRIContextList[aIndex]->RIAlias() )
       
   215         {
       
   216         alias =
       
   217             CnvUtfConverter::ConvertToUnicodeFromUtf8L(
       
   218                 iRIContextList[aIndex]->RIAlias() );
       
   219         }
       
   220     else
       
   221         {
       
   222         alias =
       
   223             CnvUtfConverter::ConvertToUnicodeFromUtf8L(
       
   224                 iRIContextList[aIndex]->RightsIssuerURL() );
       
   225         }
       
   226 
       
   227     return alias;
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // CDRMSettingsModel::GetFirstAllowedMeteringRIAliasL()
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 HBufC* CDRMSettingsModel::GetFirstAllowedMeteringRIAliasL()
       
   235     {
       
   236     for ( TInt i( 0 ); i < iRIContextList.Count(); i++ )
       
   237         {
       
   238         if( IsMeteringAllowed( i ) )
       
   239             {
       
   240             return GetSingleRIAliasL( i );
       
   241             }
       
   242         }
       
   243     return NULL;
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // CDRMSettingsModel::GetRiContextCount()
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 TInt CDRMSettingsModel::GetRiContextCount()
       
   251     {
       
   252     return iRIContextList.Count();
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // CDRMSettingsModel::IsMeteringAllowed()
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 TBool CDRMSettingsModel::IsMeteringAllowed( TInt aIndex )
       
   260     {
       
   261     __ASSERT_DEBUG( aIndex >= 0 ||
       
   262                     aIndex < iRIContextList.Count(),
       
   263                         User::Panic( KDRMSettingsDebugPanicMessage,
       
   264                                      KDRMSettingsDebugPanicCode ) );
       
   265 
       
   266     return iRIContextList[aIndex]->IsMeteringAllowed();
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // CDRMSettingsModel::IsMeteringAllowedForAll()
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 TBool CDRMSettingsModel::IsMeteringAllowedForAll()
       
   274     {
       
   275     TBool isAllowed( ETrue );
       
   276 
       
   277     for ( TInt i( 0 ); i < iRIContextList.Count() && isAllowed; i++ )
       
   278         {
       
   279         if( !IsMeteringAllowed( i ) )
       
   280             {
       
   281             isAllowed = EFalse;
       
   282             }
       
   283         }
       
   284 
       
   285     return isAllowed;
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CDRMSettingsModel::SetMeteringStatus()
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 void CDRMSettingsModel::SetMeteringStatus( TInt aIndex, TBool aIsAllowed )
       
   293     {
       
   294     __ASSERT_DEBUG( aIndex >= 0 ||
       
   295                     aIndex < iRIContextList.Count(),
       
   296                         User::Panic( KDRMSettingsDebugPanicMessage,
       
   297                                      KDRMSettingsDebugPanicCode ) );
       
   298 
       
   299     iRIContextList[aIndex]->SetMeteringStatus( aIsAllowed );
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 // CDRMSettingsModel::SaveMeteringChanges()
       
   304 // ---------------------------------------------------------------------------
       
   305 //
       
   306 void CDRMSettingsModel::SaveMeteringChanges()
       
   307     {
       
   308     for ( TInt i( 0 ); i < iRIContextList.Count(); i++ )
       
   309         {
       
   310         TRAP_IGNORE(
       
   311             iRoapStorageClient->UpdateRIContextL( *iRIContextList[i] ) );
       
   312         }
       
   313     }
       
   314 
       
   315 //  End of File