commondrm/drmutility/src/DrmUtilityGlobalNoteWrapper.cpp
changeset 0 95b198f216e5
child 18 8a03a285ab14
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     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:  Implementation of CDrmUtilityGlobalNoteWrapper class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <stringloader.h>
       
    22 #include <aknglobalconfirmationquery.h>
       
    23 #include <akngloballistquery.h>
       
    24 #include <badesca.h>
       
    25 #include <avkon.hrh> // EAknSoftkeyNo
       
    26 #include <drmutility.rsg>
       
    27 
       
    28 #include <aknmediatorfacade.h>
       
    29 #include <aknsddata.h>
       
    30 #include <featmgr.h>
       
    31 
       
    32 #include "drmutilitysecondarydisplay.h"
       
    33 #include "drmutilityglobalnotewrapper.h"
       
    34 #include "drmutilityinfonotewrapper.h"
       
    35 
       
    36 // ============================= LOCAL FUNCTIONS ===============================
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CDrmUtilityGlobalNoteWrapper::CDrmUtilityGlobalNoteWrapper
       
    42 // C++ default constructor can NOT contain any code, that
       
    43 // might leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 DRM::CDrmUtilityGlobalNoteWrapper::CDrmUtilityGlobalNoteWrapper() 
       
    47     : CActive( EPriorityStandard )
       
    48     {
       
    49     CActiveScheduler::Add( this );
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CDrmUtilityGlobalNoteWrapper::ConstructL
       
    54 // Symbian 2nd phase constructor can leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void DRM::CDrmUtilityGlobalNoteWrapper::ConstructL( 
       
    58     CStringResourceReader* aResourceReader )
       
    59     {
       
    60     iResourceReader = aResourceReader;
       
    61     iButtonsId = R_AVKON_SOFTKEYS_YES_NO__YES;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CDrmUtilityGlobalNoteWrapper::NewL
       
    66 // Two-phased constructor.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 DRM::CDrmUtilityGlobalNoteWrapper* DRM::CDrmUtilityGlobalNoteWrapper::NewLC( 
       
    70     CStringResourceReader* aResourceReader )
       
    71     {
       
    72     DRM::CDrmUtilityGlobalNoteWrapper* self( 
       
    73                                 new (ELeave) CDrmUtilityGlobalNoteWrapper() );
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL( aResourceReader );
       
    76     return self;
       
    77     }
       
    78 
       
    79 DRM::CDrmUtilityGlobalNoteWrapper* DRM::CDrmUtilityGlobalNoteWrapper::NewL(
       
    80     CStringResourceReader* aResourceReader )
       
    81     {
       
    82     DRM::CDrmUtilityGlobalNoteWrapper* self( NewLC( aResourceReader ) );
       
    83     CleanupStack::Pop( self );
       
    84     return self;
       
    85     }
       
    86 
       
    87     
       
    88 // Destructor
       
    89 DRM::CDrmUtilityGlobalNoteWrapper::~CDrmUtilityGlobalNoteWrapper()
       
    90     {
       
    91     Cancel(); // Cancel active object
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CDrmUtilityGlobalNoteWrapper::ShowNoteL
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt DRM::CDrmUtilityGlobalNoteWrapper::ShowNoteWithButtonsL( 
       
    99     TInt aResourceId, 
       
   100     TInt aButtonsId )
       
   101     {
       
   102     TInt ret( 0 );
       
   103     
       
   104     iTextBuffer = iResourceReader->ReadResourceString( aResourceId );
       
   105     
       
   106     iButtonsId = aButtonsId;   
       
   107     ret = DoShowNoteL( aResourceId );
       
   108     iButtonsId = R_AVKON_SOFTKEYS_YES_NO__YES;
       
   109     return ret;
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CDrmUtilityGlobalNoteWrapper::ShowNoteWithButtonsL
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TInt DRM::CDrmUtilityGlobalNoteWrapper::ShowNoteWithButtonsL( 
       
   117     TInt aResourceId, 
       
   118     TInt aButtonsId,
       
   119     const TDesC& aString )
       
   120     {
       
   121     TInt ret( 0 );
       
   122     
       
   123     TBuf<DRM::KDRMNoteBufferMaxSize> srcBuffer( 
       
   124         iResourceReader->ReadResourceString( aResourceId ) );
       
   125     
       
   126     StringLoader::Format( iTextBuffer, srcBuffer, -1, aString );
       
   127             
       
   128     iButtonsId = aButtonsId;   
       
   129     ret = DoShowNoteL( aResourceId, aString );
       
   130     iButtonsId = R_AVKON_SOFTKEYS_YES_NO__YES;
       
   131     return ret;
       
   132     }
       
   133     
       
   134 // -----------------------------------------------------------------------------
       
   135 // CDrmUtilityGlobalNoteWrapper::ShowNoteL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 TInt DRM::CDrmUtilityGlobalNoteWrapper::ShowNoteL( 
       
   139     TInt aResourceId, 
       
   140     TInt aValue )
       
   141     {
       
   142     TBuf<DRM::KDRMNoteBufferMaxSize> srcBuffer( 
       
   143         iResourceReader->ReadResourceString( aResourceId ) );
       
   144         
       
   145     StringLoader::Format( iTextBuffer, srcBuffer, -1, aValue );
       
   146     return DoShowNoteL( aResourceId, KNullDesC, aValue );
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CDrmUtilityGlobalNoteWrapper::ShowNoteL
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 TInt DRM::CDrmUtilityGlobalNoteWrapper::ShowNoteL( 
       
   154     TInt aResourceId, 
       
   155     const TDesC& aString )
       
   156     {
       
   157     TBuf<DRM::KDRMNoteBufferMaxSize> srcBuffer( 
       
   158         iResourceReader->ReadResourceString( aResourceId ) );
       
   159         
       
   160     StringLoader::Format( iTextBuffer, srcBuffer, -1, aString );
       
   161     return DoShowNoteL( aResourceId, aString );
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CDrmUtilityGlobalNoteWrapper::ShowNoteL
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 TInt DRM::CDrmUtilityGlobalNoteWrapper::ShowNoteL( 
       
   169     TInt aResourceId, 
       
   170     const TDesC& aString,
       
   171     TInt aValue, 
       
   172     TInt aStringPos,
       
   173     TInt aValuePos)
       
   174     {
       
   175     TBuf<DRM::KDRMNoteBufferMaxSize> srcBuffer( 
       
   176         iResourceReader->ReadResourceString( aResourceId ) );
       
   177     
       
   178     StringLoader::Format( iTextBuffer, srcBuffer, aValuePos, aValue );
       
   179     srcBuffer = iTextBuffer;
       
   180     StringLoader::Format( iTextBuffer, srcBuffer, aStringPos, aString );
       
   181     return DoShowNoteL( aResourceId, aString, aValue );
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CDrmUtilityGlobalNoteWrapper::ShowPreviewListQueryL
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
   189 
       
   190 TInt DRM::CDrmUtilityGlobalNoteWrapper::ShowPreviewListQueryL( 
       
   191     TInt aResourceId )
       
   192     {
       
   193     TInt index( 0 );
       
   194     CAknGlobalListQuery* listQuery( CAknGlobalListQuery::NewLC() );
       
   195     HBufC* buffer( HBufC::NewLC( DRM::KDRMNoteBufferMaxSize ) );
       
   196     TPtr bufPtr( buffer->Des() );
       
   197     
       
   198     bufPtr = iResourceReader->ReadResourceString( R_DRMUTILITY_ACTIVATE_PREVIEW );
       
   199     listQuery->SetHeadingL( bufPtr );
       
   200     
       
   201     CDesCArray* listArray( new( ELeave ) CDesCArrayFlat( 2 ) );
       
   202     CleanupStack::PushL( listArray );
       
   203     
       
   204     bufPtr = iResourceReader->ReadResourceString( R_DRMUTILITY_ACTIVATE );
       
   205     listArray->AppendL( bufPtr );
       
   206     
       
   207     switch( aResourceId )
       
   208         {
       
   209         case R_DRMUTILITY_PREV_AUDIO_GET_LIST_QUERY:
       
   210         
       
   211             bufPtr = iResourceReader->ReadResourceString( 
       
   212                                             R_DRMUTILITY_GET_PREVIEW );
       
   213             
       
   214             
       
   215             break;
       
   216             
       
   217         case R_DRMUTILITY_PREV_VIDEO_GET_LIST_QUERY:
       
   218         
       
   219             bufPtr = iResourceReader->ReadResourceString( 
       
   220                                             R_DRMUTILITY_GET_PREVIEW_VIDEO );
       
   221             
       
   222             break;
       
   223             
       
   224         case R_DRMUTILITY_PREV_AUDIO_PLAY_LIST_QUERY:
       
   225         
       
   226             bufPtr = iResourceReader->ReadResourceString( 
       
   227                                             R_DRMUTILITY_PLAY_PREVIEW );
       
   228             
       
   229             break;
       
   230             
       
   231         case R_DRMUTILITY_PREV_VIDEO_PLAY_LIST_QUERY:
       
   232         
       
   233             bufPtr = iResourceReader->ReadResourceString( 
       
   234                                             R_DRMUTILITY_PLAY_PREVIEW_VIDEO );
       
   235             
       
   236             break;
       
   237         
       
   238         default:
       
   239         
       
   240             return 0;
       
   241 
       
   242         }
       
   243     
       
   244     listArray->AppendL( bufPtr );
       
   245     
       
   246     if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) &&
       
   247         DRM::CDrmUtilityInfoNoteWrapper::EvaluateCoverResourceId( aResourceId ) )
       
   248         {
       
   249         RProcess myProcess;
       
   250         TUid myProcessUid( KNullUid );
       
   251         RThread().Process( myProcess );
       
   252         myProcessUid = myProcess.Identity();
       
   253    
       
   254         TUtilitySDData utilityData;
       
   255         // First field is DrmUtility's Uid
       
   256         utilityData.iUtilityUid = KUidCoverUiCategoryDrmUtility;
       
   257         // ProcessId which uses DrmUtility
       
   258         utilityData.iHandlerProcessId = myProcessUid; 
       
   259         TUtilitySDDataPckg pckg( utilityData );                   
       
   260         CAknSDData* sd( CAknSDData::NewL( KUidCoverUiCategoryDrmUtility, 
       
   261                                           aResourceId, 
       
   262                                           pckg ) );
       
   263         
       
   264         // ownership to notifier client                                   
       
   265         listQuery->SetSecondaryDisplayData( sd );
       
   266         }
       
   267     
       
   268     iStatus = KRequestPending;
       
   269     listQuery->ShowListQueryL( listArray, iStatus );
       
   270     SetActive();
       
   271     iWait.Start();
       
   272     
       
   273     CleanupStack::PopAndDestroy( 3, listQuery ); //listArray, buffer, listQuery
       
   274     
       
   275     if ( iStatus.Int() != EAknSoftkeyNo )
       
   276         {
       
   277         index = iStatus.Int() + 1;
       
   278         }
       
   279     
       
   280     return index;
       
   281     }
       
   282 
       
   283 #else
       
   284 
       
   285 TInt DRM::CDrmUtilityGlobalNoteWrapper::ShowPreviewListQueryL( 
       
   286     TInt /*aResourceId*/ )
       
   287     {
       
   288     return 0;
       
   289     }
       
   290 
       
   291 #endif // RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CDrmUtilityGlobalNoteWrapper::DoCancel
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 void DRM::CDrmUtilityGlobalNoteWrapper::DoCancel()
       
   298     {
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CDrmUtilityGlobalNoteWrapper::RunL
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void DRM::CDrmUtilityGlobalNoteWrapper::RunL()
       
   306     {
       
   307     iWait.AsyncStop();
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CDrmUtilityGlobalNoteWrapper::DoShowNoteL
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 TInt DRM::CDrmUtilityGlobalNoteWrapper::DoShowNoteL( 
       
   315     TInt aResourceId, 
       
   316     const TDesC& aString, 
       
   317     TInt aValue )
       
   318     {
       
   319     TPtr bufPtr( NULL, 0 );
       
   320     TInt animation( iButtonsId == R_AVKON_SOFTKEYS_YES_NO__YES ? 
       
   321                                                     0 : R_QGN_NOTE_INFO_ANIM );
       
   322     
       
   323     CAknGlobalConfirmationQuery* globalNote(
       
   324                                         CAknGlobalConfirmationQuery::NewLC() );
       
   325          	
       
   326     bufPtr.Set( const_cast <TUint16*>( iTextBuffer.Ptr() ), 
       
   327                                        iTextBuffer.Length(), 
       
   328                                        iTextBuffer.Length() );
       
   329     
       
   330     AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
   331 
       
   332 
       
   333     if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) &&
       
   334         DRM::CDrmUtilityInfoNoteWrapper::EvaluateCoverResourceId( aResourceId ) )
       
   335         {
       
   336         RProcess myProcess;
       
   337         TUid myProcessUid( KNullUid );
       
   338         RThread().Process( myProcess );
       
   339         myProcessUid = myProcess.Identity();
       
   340    
       
   341         TUtilitySDData utilityData;
       
   342         // First field is DrmUtility's Uid
       
   343         utilityData.iUtilityUid = KUidCoverUiCategoryDrmUtility;
       
   344         // ProcessId which uses DrmUtility
       
   345         utilityData.iHandlerProcessId = myProcessUid; 
       
   346         if ( aString.Compare( KNullDesC ) )
       
   347             {
       
   348             // If there is filename given, it's always in the PrimaryString
       
   349             utilityData.iStringParam.Append( aString );
       
   350             }
       
   351         if ( aValue >= 0 )
       
   352             {
       
   353             // If there is no other than numeric data, put it as SecondaryString
       
   354             utilityData.iNumParam.AppendNum( aValue );
       
   355             }
       
   356 
       
   357         TUtilitySDDataPckg pckg( utilityData );                   
       
   358         CAknSDData* sd( CAknSDData::NewL( KUidCoverUiCategoryDrmUtility, 
       
   359                                           aResourceId, 
       
   360                                           pckg ) );
       
   361         
       
   362         // ownership to notifier client                                   
       
   363         globalNote->SetSecondaryDisplayData( sd );
       
   364         }
       
   365 
       
   366     iStatus = KRequestPending;
       
   367     globalNote->ShowConfirmationQueryL( iStatus, 
       
   368                                         iTextBuffer, 
       
   369                                         iButtonsId,
       
   370                                         animation );
       
   371                                          
       
   372     SetActive();
       
   373     iWait.Start();
       
   374     CleanupStack::PopAndDestroy( globalNote );
       
   375     if ( iStatus.Int() != EAknSoftkeyNo )
       
   376         {
       
   377         return iStatus.Int();    
       
   378         }
       
   379     else
       
   380         {
       
   381         return 0;
       
   382         }
       
   383     }
       
   384 
       
   385 //  End of File