commondrm/drmui/drmuidialogs/src/drmuidialogs.cpp
branchRCL_3
changeset 26 1221b68b8a5f
equal deleted inserted replaced
25:50c53e893c3f 26:1221b68b8a5f
       
     1 /*
       
     2 * Copyright (c) 2010 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 CDrmUIDialogs class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "drmuidialogs.h"                       // CDrmUIDialogs
       
    19 #include <hb/hbcore/hbsymbianvariant.h>         // CHbSymbianVariantMap
       
    20 
       
    21 // Identifier of DRM UI device notification dialog plugin
       
    22 _LIT( KDrmUIDeviceDialogPlugin, "com.nokia.hb.drmuidialog/1.0" );
       
    23 
       
    24 // Keys for the parameters passed to notification dialog plugin
       
    25 _LIT( KDrmUIDialogId, "dialogId" );
       
    26 _LIT( KDrmUIInsertText, "insertText" );
       
    27 _LIT( KDrmUIInsertInt, "insertInt" );
       
    28 
       
    29 // Keys name for result sent from notification dialog plugin
       
    30 _LIT( KDrmUIDialogResult, "result");
       
    31 
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CDrmUIDialogs::NewLC()
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 EXPORT_C CDrmUIDialogs* CDrmUIDialogs::NewLC()
       
    40     {
       
    41     CDrmUIDialogs* self = new( ELeave ) CDrmUIDialogs();
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     return self;
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CDrmUIDialogs::NewL()
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C CDrmUIDialogs* CDrmUIDialogs::NewL()
       
    52     {
       
    53     CDrmUIDialogs* self = CDrmUIDialogs::NewLC();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CDrmUIDialogs::~CDrmUIDialogs()
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CDrmUIDialogs::~CDrmUIDialogs()
       
    64     {
       
    65     Cancel();
       
    66     delete iWait;
       
    67     delete iDeviceDialog;
       
    68     delete iVariantMap;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CDrmUIDialogs::ShowNoteL()
       
    73 // ---------------------------------------------------------------------------
       
    74 EXPORT_C TInt CDrmUIDialogs::ShowNoteL( TInt aDialogId, const TDesC& aString, TInt aValue )
       
    75     {
       
    76     // Add the dialog id to the variant map
       
    77     AddParamL( KDrmUIDialogId, aDialogId );
       
    78     
       
    79     // Add the string to the variant map if it exists
       
    80     if ( aString.Compare( KNullDesC ) )
       
    81         {
       
    82         AddParamL( KDrmUIInsertText, aString );
       
    83         }
       
    84 
       
    85     // Add the int to the variant map
       
    86     if ( aValue >= 0 )
       
    87         {
       
    88         AddParamL( KDrmUIInsertInt, aValue );
       
    89         }
       
    90 
       
    91     DisplayDeviceDialogL();
       
    92 
       
    93     TInt error = WaitUntilDeviceDialogClosed();
       
    94     User::LeaveIfError( error );
       
    95 
       
    96     return iReturnValue;
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CDrmUIDialogs::DoCancel()
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CDrmUIDialogs::DoCancel()
       
   104     {
       
   105     if( iWait && iWait->IsStarted() && iWait->CanStopNow() )
       
   106         {
       
   107         iCompletionCode = KErrCancel;
       
   108         iWait->AsyncStop();
       
   109         }
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CDrmUIDialogs::RunL()
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void CDrmUIDialogs::RunL()
       
   117     {
       
   118     if( iWait )
       
   119         {
       
   120         iWait->AsyncStop();
       
   121         }
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CDrmUIDialogs::DataReceived()
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 void CDrmUIDialogs::DataReceived( CHbSymbianVariantMap& aData )
       
   129     {
       
   130     const CHbSymbianVariant* resultVariant = aData.Get( KDrmUIDialogResult );
       
   131  
       
   132     if( resultVariant )
       
   133         {
       
   134         TInt* result = resultVariant->Value<TInt>();
       
   135 
       
   136         if( result )
       
   137             {
       
   138             iReturnValue = *result;
       
   139             }
       
   140         }
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CDrmUIDialogs::DeviceDialogClosed()
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CDrmUIDialogs::DeviceDialogClosed( TInt aCompletionCode )
       
   148     {
       
   149     iCompletionCode = aCompletionCode;
       
   150     iIsDisplayingDialog = EFalse;
       
   151 
       
   152     TRequestStatus* status( &iStatus );
       
   153     User::RequestComplete( status, KErrNone );
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CDrmUIDialogs::CDrmUIDialogs()
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 CDrmUIDialogs::CDrmUIDialogs() : CActive( CActive::EPriorityStandard )
       
   161     {
       
   162     CActiveScheduler::Add( this );
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CDrmUIDialogs::ConstructL()
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CDrmUIDialogs::ConstructL()
       
   170     {
       
   171     iReturnValue = KErrNone;
       
   172     iWait = new( ELeave ) CActiveSchedulerWait;
       
   173     iDeviceDialog = CHbDeviceDialogSymbian::NewL();
       
   174     iVariantMap = CHbSymbianVariantMap::NewL();
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CDrmUIDialogs::ClearParamsL()
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CDrmUIDialogs::ClearParamsL()
       
   182     {
       
   183     if( iVariantMap )
       
   184         {
       
   185         delete iVariantMap;
       
   186         iVariantMap = NULL;
       
   187         }
       
   188     iVariantMap = CHbSymbianVariantMap::NewL();
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // CDrmUIDialogs::ClearParamsAndSetDialogIdL()
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CDrmUIDialogs::ClearParamsAndSetDialogIdL( TInt aDialogId )
       
   196     {
       
   197     ClearParamsL();
       
   198     AddParamL( KDrmUIDialogId, aDialogId );
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // CDrmUIDialogs::AddParamL()
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CDrmUIDialogs::AddParamL( const TDesC& aKey, TInt aValue )
       
   206     {
       
   207     CHbSymbianVariant* variant = NULL;
       
   208     variant = CHbSymbianVariant::NewL( &aValue, CHbSymbianVariant::EInt );
       
   209     iVariantMap->Add( aKey, variant );  // Takes ownership of variant
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CDrmUIDialogs::AddParamL()
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CDrmUIDialogs::AddParamL( const TDesC& aKey, const TDesC& aValue )
       
   217     {
       
   218     CHbSymbianVariant* variant = NULL;
       
   219     variant = CHbSymbianVariant::NewL( &aValue, CHbSymbianVariant::EDes );
       
   220     iVariantMap->Add( aKey, variant );  // Takes ownership of variant
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // CDrmUIDialogs::DisplayDeviceDialogL()
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CDrmUIDialogs::DisplayDeviceDialogL()
       
   228     {
       
   229     if( iIsDisplayingDialog )
       
   230         {
       
   231         iDeviceDialog->Update( *iVariantMap );
       
   232         }
       
   233     else
       
   234         {
       
   235         iDeviceDialog->Show( KDrmUIDeviceDialogPlugin, *iVariantMap, this );
       
   236         iIsDisplayingDialog = ETrue;
       
   237         }
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // CDrmUIDialogs::WaitUntilDeviceDialogClosed()
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 TInt CDrmUIDialogs::WaitUntilDeviceDialogClosed()
       
   245     {
       
   246     iCompletionCode = KErrInUse;
       
   247 
       
   248     if( !IsActive() && iWait && !iWait->IsStarted() )
       
   249         {
       
   250         iStatus = KRequestPending;
       
   251         SetActive();
       
   252         iWait->Start();
       
   253         }
       
   254     return iCompletionCode;
       
   255     }