wmdrm/camese/wmdrmdlautils/src/wmdrmdlaui.cpp
changeset 0 95b198f216e5
child 12 8a03a285ab14
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2008 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 class for WMDRM DLA UI
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <f32file.h>
       
    21 
       
    22 #ifdef RD_MULTIPLE_DRIVE
       
    23 #include <driveinfo.h>
       
    24 #endif
       
    25 
       
    26 #include <eikfrlb.h>
       
    27 #include <eikfrlbd.h>
       
    28 #include <coemain.h>
       
    29 #include <bautils.h>
       
    30 #include <stringloader.h>
       
    31 #include <aknnotewrappers.h>
       
    32 #include <aknglobalnote.h>
       
    33 #include <aknlistquerydialog.h>
       
    34 #include <badesca.h>
       
    35 #include <gulicon.h>
       
    36 
       
    37 #include <data_caging_path_literals.hrh>
       
    38 #include <wmdrmdlautils.rsg>
       
    39 
       
    40 #include "wmdrmdlaui.h"
       
    41 
       
    42 #define _LOGGING_FILE L"wmdrmdlautils.txt"
       
    43 #include "logfn.h"
       
    44 
       
    45 // CONSTANTS
       
    46 #ifndef RD_MULTIPLE_DRIVE
       
    47 _LIT( KDriveZ, "z:" );
       
    48 #else
       
    49 _LIT( KRomDriveFormatter, "%c:" );                                      
       
    50 #endif
       
    51 
       
    52 _LIT( KWmdrmDlaUtilsResFileName, "wmdrmdlautils.rsc" );
       
    53 
       
    54 // ======== LOCAL FUNCTIONS ========
       
    55 
       
    56 // ======== MEMBER FUNCTIONS ========
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CWmDrmDlaUi::ConstructL
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CWmDrmDlaUi::ConstructL()
       
    63     {
       
    64     LOGFN( "CWmDrmDlaUi::ConstructL" );
       
    65     iCoeEnv = CCoeEnv::Static();
       
    66     if ( !iCoeEnv )
       
    67         {
       
    68         User::Leave( KErrNotSupported );
       
    69         }
       
    70     
       
    71     //Create resource file path
       
    72     TPtr wmdrmDlaUtilsResourcePtr( NULL, 0 );
       
    73     iWmdrmDlaUtilsResourceFile = HBufC::NewL( KMaxFileName );
       
    74     wmdrmDlaUtilsResourcePtr.Set( iWmdrmDlaUtilsResourceFile->Des() );
       
    75 
       
    76     //Append rom drive letter to the path
       
    77 #ifndef RD_MULTIPLE_DRIVE
       
    78 
       
    79     wmdrmDlaUtilsResourcePtr.Append( KDriveZ );
       
    80 
       
    81 #else //RD_MULTIPLE_DRIVE
       
    82 
       
    83     TInt driveNumber( -1 );
       
    84     TChar driveLetter;
       
    85     //Get rom drive number
       
    86     User::LeaveIfError( 
       
    87             DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, 
       
    88                                         driveNumber ) );
       
    89     //Get drive letter from the drive number
       
    90     User::LeaveIfError( 
       
    91             iCoeEnv->FsSession().DriveToChar( driveNumber, 
       
    92                                               driveLetter ) );
       
    93     wmdrmDlaUtilsResourcePtr.AppendFormat( KRomDriveFormatter, 
       
    94                                            (TUint)driveLetter );
       
    95 
       
    96 #endif
       
    97 
       
    98     //Append directory to the path
       
    99     wmdrmDlaUtilsResourcePtr.Append( KDC_RESOURCE_FILES_DIR );
       
   100     //Append name of the resource file to the path
       
   101     wmdrmDlaUtilsResourcePtr.Append( KWmdrmDlaUtilsResFileName );
       
   102 
       
   103     TFileName resourceFile;
       
   104     resourceFile = *iWmdrmDlaUtilsResourceFile;
       
   105     //Find the correct language file for the resource
       
   106     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), 
       
   107                                     resourceFile );
       
   108     //Add resource file to the CCoeEnv. 
       
   109     //Resource file must be removed from the CCoeEnv when we are done
       
   110     iWmdrmDlaUtilsResourceFileOffset 
       
   111         = iCoeEnv->AddResourceFileL( resourceFile );
       
   112     
       
   113     iGlobalNote = CAknGlobalNote::NewL();
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CWmDrmDlaUi::CWmDrmDlaUi
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 CWmDrmDlaUi::CWmDrmDlaUi() : CActive( EPriorityStandard )
       
   121     {
       
   122     LOGFN( "CWmDrmDlaUi::CWmDrmDlaUi" );
       
   123     CActiveScheduler::Add( this );
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CWmDrmDlaUi::NewL
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 EXPORT_C CWmDrmDlaUi* CWmDrmDlaUi::NewL()
       
   131     {
       
   132     LOGFN( "CWmDrmDlaUi::NewL" );
       
   133     CWmDrmDlaUi* self = CWmDrmDlaUi::NewLC();
       
   134     CleanupStack::Pop( self );
       
   135     return self;
       
   136     }
       
   137 
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CWmDrmDlaUi::NewLC
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 EXPORT_C CWmDrmDlaUi* CWmDrmDlaUi::NewLC()
       
   144     {
       
   145     LOGFN( "CWmDrmDlaUi::NewLC" );
       
   146     CWmDrmDlaUi* self = new( ELeave ) CWmDrmDlaUi;
       
   147     CleanupStack::PushL( self );
       
   148     self->ConstructL();
       
   149     return self;
       
   150     }
       
   151 
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CWmDrmDlaUi::~CWmDrmDlaUi
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 CWmDrmDlaUi::~CWmDrmDlaUi()
       
   158     {
       
   159     LOGFN( "CWmDrmDlaUi::~CWmDrmDlaUi" );
       
   160     Cancel();
       
   161     delete iGlobalNote;
       
   162     delete iGlobalNoteText;
       
   163     iCoeEnv->DeleteResourceFile( iWmdrmDlaUtilsResourceFileOffset );
       
   164     delete iWmdrmDlaUtilsResourceFile;
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CWmDrmDlaUi::ShowErrorNoteL
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C void CWmDrmDlaUi::ShowErrorNoteL( 
       
   172     TInt aTextResourceId )
       
   173     {
       
   174     LOGFN( "CWmDrmDlaUi::ShowErrorNoteL" );
       
   175     HBufC* msgText( StringLoader::LoadLC( aTextResourceId, iCoeEnv ) );
       
   176     CAknResourceNoteDialog* note = new ( ELeave ) CAknErrorNote( ETrue );
       
   177     note->ExecuteLD( *msgText );
       
   178     CleanupStack::PopAndDestroy( msgText );
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CWmDrmDlaUi::ShowWaitNoteL
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 EXPORT_C void CWmDrmDlaUi::ShowWaitNoteL( 
       
   186     TInt aTextResourceId,
       
   187     MWmDrmDlaWaitNoteCallback* aCallback )
       
   188     {
       
   189     LOGFN( "CWmDrmDlaUi::ShowWaitNoteL" );
       
   190     if ( IsActive() )
       
   191         {
       
   192         User::Leave( KErrInUse );
       
   193         }
       
   194     iGlobalNoteText = StringLoader::LoadL( aTextResourceId, iCoeEnv );
       
   195     iGlobalNoteId = iGlobalNote->ShowNoteL( iStatus, 
       
   196                                             EAknGlobalWaitNote, 
       
   197                                             *iGlobalNoteText );
       
   198     iCallback = aCallback;
       
   199     SetActive();
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CWmDrmDlaUi::RemoveWaitNote
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 EXPORT_C void CWmDrmDlaUi::RemoveWaitNote()
       
   207     {
       
   208     LOGFN( "CWmDrmDlaUi::RemoveWaitNote" );
       
   209     Cancel();
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CWmDrmDlaUi::ShowListQueryL
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 EXPORT_C TInt CWmDrmDlaUi::ShowListQueryL( 
       
   217     MDesCArray* aItems,
       
   218     CArrayPtr<CGulIcon>* aIcons )
       
   219     {
       
   220     LOGFN( "CWmDrmDlaUi::ShowListQueryL" );
       
   221     
       
   222     //This method takes the ownership of the input parameters
       
   223     //Push the input parameters to the cleanupstack to make sure we won't leak
       
   224     //memory
       
   225     CleanupStack::PushL( aIcons );
       
   226     CleanupStack::PushL( aItems );
       
   227     
       
   228     //Check that both inputs really exist.
       
   229     if ( !aItems || !aIcons )
       
   230         {
       
   231         User::Leave( KErrArgument );
       
   232         }
       
   233     
       
   234     //Create the query with index parameter
       
   235     //Query will take the ownership of the items and icons
       
   236     TInt index( 0 );
       
   237     CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog( &index );
       
   238     dlg->PrepareLC( R_WMDRMDLA_LIST_QUERY );
       
   239     
       
   240     //Arrange cleanupstack in a way that query can take the ownership of the
       
   241     //items and icons
       
   242     CleanupStack::Pop( 2, aItems ); //dlg, aItems
       
   243     //Ownership of the items is transferred to query
       
   244     dlg->SetItemTextArray( aItems );
       
   245     dlg->SetOwnershipType( ELbmOwnsItemArray );
       
   246     CleanupStack::PushL( dlg );
       
   247     //Ownership of the icons in transferred to query
       
   248     dlg->SetIconArrayL( aIcons );
       
   249     CleanupStack::Pop( 2, aIcons ); //dlg, aIcons
       
   250     CleanupStack::PushL( dlg );
       
   251     
       
   252     //Enable marquee scrolling for the text items
       
   253     CEikFormattedCellListBox* listbox( 
       
   254             static_cast<CEikFormattedCellListBox*>( dlg->ListBox() ) /* ,
       
   255             EAknListBoxItemSpecificMenuDisabled */ );
       
   256     listbox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   257     
       
   258     //Launch the query
       
   259     TInt key( dlg->RunLD() );
       
   260     LOG2( "key: %d", key );
       
   261     //If user cancelled query, then return -1
       
   262     //Else return index of the selected service
       
   263     if ( key != EAknSoftkeyOk )
       
   264         {
       
   265         index = -1;
       
   266         }
       
   267     LOG2( "index: %d", index );
       
   268     return index;
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // CWmDrmDlaUi::DoCancel
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 void CWmDrmDlaUi::DoCancel()
       
   276     {
       
   277     LOGFN( "CWmDrmDlaUi::DoCancel" );
       
   278     CancelWaitNote();
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CWmDrmDlaUi::RunL
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 void CWmDrmDlaUi::RunL()
       
   286     {
       
   287     LOGFN( "CWmDrmDlaUi::RunL" );
       
   288     CancelWaitNote();
       
   289     if ( iCallback )
       
   290         {
       
   291         iCallback->UserWaitNoteCancellation();
       
   292         }
       
   293     }    
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // CWmDrmDlaUi::RunError
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 TInt CWmDrmDlaUi::RunError( TInt /*aError*/ )
       
   300     {
       
   301     return KErrNone;
       
   302     }
       
   303 
       
   304     
       
   305 // ---------------------------------------------------------------------------
       
   306 // CWmDrmDlaUi::CancelWaitNote
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 void CWmDrmDlaUi::CancelWaitNote()
       
   310     {
       
   311     LOGFN( "CWmDrmDlaUi::CancelWaitNote" );
       
   312     if ( iGlobalNoteId )
       
   313         {
       
   314         TRAP_IGNORE( iGlobalNote->CancelNoteL( iGlobalNoteId ) );
       
   315         iGlobalNoteId = 0;
       
   316         delete iGlobalNoteText;
       
   317         iGlobalNoteText = NULL;
       
   318         }
       
   319     }