upnpframework/upnpfiletransferengine/src/upnpnotehandler.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     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 the CUpnpNoteHandler class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include <AknUtils.h>                           // CEikonEnv
       
    21 #include <bautils.h>                            // BaflUtils
       
    22 #include <eikprogi.h>                           // CEikProgressInfo
       
    23 #include <AknWaitDialog.h>                      // CAknWaitDialog
       
    24 #include <upnpstring.h>                         // UpnpString
       
    25 #include <upnpfiletransferengineresources.rsg>  // Dialog resources
       
    26 #include <data_caging_path_literals.hrh>        // KDC_RESOURCE_FILES_DIR
       
    27 #include <StringLoader.h>                       // StringLoader
       
    28 #include <aknnotewrappers.h>                    // CAknErrorNote
       
    29 
       
    30 #include "upnpnotehandler.h"
       
    31 #include "upnpprogressdialogobserver.h"
       
    32 
       
    33 _LIT( KComponentLogfile, "filetransferengine.txt");
       
    34 #include "upnplog.h"
       
    35 
       
    36 // CONSTANTS
       
    37 _LIT( KResFileName,  "upnpfiletransferengineresources.rsc");
       
    38 const TInt KProgressInfoInitialValue = 0;
       
    39 
       
    40 
       
    41 // --------------------------------------------------------------------------
       
    42 // CUpnpNoteHandler::NewL
       
    43 // NewL.
       
    44 // --------------------------------------------------------------------------
       
    45 //
       
    46 CUpnpNoteHandler* CUpnpNoteHandler::NewL( 
       
    47                                     MUPnPProgressDialogobserver* aObserver )
       
    48     {
       
    49     __LOG( "[UpnpNoteHandler] CUpnpNoteHandler: NewL" );
       
    50 
       
    51     CUpnpNoteHandler* self = NULL;
       
    52     self = new (ELeave) CUpnpNoteHandler( aObserver );
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop( self );
       
    56     __LOG( "[UpnpNoteHandler] CUpnpNoteHandler: NewL end" );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // --------------------------------------------------------------------------
       
    61 // Constuctor
       
    62 // --------------------------------------------------------------------------
       
    63 //
       
    64 CUpnpNoteHandler::CUpnpNoteHandler( MUPnPProgressDialogobserver* aObserver )
       
    65     {
       
    66     __LOG( "[UpnpNoteHandler] Constructor" );
       
    67     iProgressDialogObserver = aObserver;
       
    68     iProgressNoteFinish = EFalse;
       
    69     __LOG( "[UpnpNoteHandler] Constructor - end" );
       
    70     }
       
    71 
       
    72 // --------------------------------------------------------------------------
       
    73 // Destructor
       
    74 // --------------------------------------------------------------------------
       
    75 //
       
    76 CUpnpNoteHandler::~CUpnpNoteHandler()
       
    77     {
       
    78     __LOG( "[UpnpNoteHandler] Destructor" );
       
    79 
       
    80     // Un-load resource file
       
    81     if ( iResFileOffset )
       
    82         {
       
    83         iCoeEnv->DeleteResourceFile( iResFileOffset );
       
    84         iResFileOffset = 0;
       
    85         }
       
    86     __LOG( "[UpnpNoteHandler] Destructor end" );
       
    87     }
       
    88 
       
    89 // --------------------------------------------------------------------------
       
    90 // CUpnpNoteHandler::ConstructL
       
    91 // Second phase constructor
       
    92 // --------------------------------------------------------------------------
       
    93 //
       
    94 void CUpnpNoteHandler::ConstructL()
       
    95     {
       
    96     __LOG( "[UpnpNoteHandler] ConstructL" );
       
    97 
       
    98     // Leave if UI context is not available
       
    99     iCoeEnv = CEikonEnv::Static(); // Not owned
       
   100     if( !iCoeEnv )
       
   101         {
       
   102         User::Leave( KErrNotSupported );
       
   103         }
       
   104 
       
   105     // Get the file server session handle
       
   106     RFs fileSession = iCoeEnv->FsSession(); // Not owned
       
   107 
       
   108     // Parse the resource file path
       
   109     TParse parse;
       
   110     parse.Set( KResFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   111     TFileName rscFileName;
       
   112     rscFileName.Append( parse.FullName() );
       
   113     TFileName dllName;
       
   114     Dll::FileName( dllName );
       
   115     TBuf<2> drive = dllName.Left( 2 ); // Drive letter followed by ':' 
       
   116     rscFileName.Insert( 0, drive );
       
   117     
       
   118     // Get the exact filename of the resource file
       
   119     BaflUtils::NearestLanguageFile( fileSession, rscFileName );
       
   120 
       
   121     // Check if the resource file exists or not
       
   122     if ( !BaflUtils::FileExists( fileSession, rscFileName ) )
       
   123         {
       
   124         __LOG( "[UpnpNoteHandler] Resource file does not exist!" );
       
   125         User::Leave( KErrNotFound );
       
   126         }
       
   127 
       
   128     // Read the resource file offset
       
   129     iResFileOffset = iCoeEnv->AddResourceFileL( rscFileName );
       
   130     __LOG( "[UpnpNoteHandler] ConstructL end" );
       
   131     }
       
   132 
       
   133 // --------------------------------------------------------------------------
       
   134 // CUpnpNoteHandler::SetValueL
       
   135 // Sets the value of the progress note.
       
   136 // --------------------------------------------------------------------------
       
   137 //
       
   138 void CUpnpNoteHandler::SetValue( TInt aProgressValue )
       
   139     {
       
   140     __LOG1( "[UpnpNoteHandler] SetValueL: %d", aProgressValue );
       
   141     __LOG1( "[UpnpNoteHandler] iMaxProgressValue: %d", iMaxProgressValue );
       
   142     // Update the progress value
       
   143     iCurrentProgressValue = aProgressValue;
       
   144     
       
   145     if( iCurrentProgressValue >= 0 && 
       
   146         iCurrentProgressValue <= iMaxProgressValue )
       
   147         {
       
   148         // Re-draw the note
       
   149         if( iProgressInfo && !iProgressNoteFinish )
       
   150             {
       
   151             iProgressInfo->SetAndDraw( iCurrentProgressValue );
       
   152             }    
       
   153         }
       
   154     
       
   155     __LOG( "[UpnpNoteHandler] SetValueL" );
       
   156     }
       
   157     
       
   158 // --------------------------------------------------------------------------
       
   159 // CUpnpNoteHandler::SetValueL
       
   160 // Sets the max value of the progress note.
       
   161 // --------------------------------------------------------------------------
       
   162 //    
       
   163 void CUpnpNoteHandler::SetMaxValue( TInt aMaxValue )
       
   164     {
       
   165     __LOG( "[UpnpNoteHandler] SetMaxValue" );
       
   166     iMaxProgressValue = aMaxValue;
       
   167     if( iProgressInfo && !iProgressNoteFinish )
       
   168         {
       
   169         iProgressInfo->SetFinalValue( aMaxValue );        
       
   170         }
       
   171     __LOG( "[UpnpNoteHandler] SetMaxValue end" );
       
   172     }
       
   173 
       
   174 // --------------------------------------------------------------------------
       
   175 // CUpnpNoteHandler::DialogDismissedL
       
   176 // ProgressDialog call back method. Get's called when a dialog is dismissed.
       
   177 // --------------------------------------------------------------------------
       
   178 //
       
   179 void CUpnpNoteHandler::DialogDismissedL( TInt aButtonId )
       
   180     {
       
   181     __LOG( "[UpnpNoteHandler] DialogDismissedL" );
       
   182     if( aButtonId == EEikBidCancel )
       
   183         {
       
   184         iProgressDialogObserver->DialogDismissedL();
       
   185         }
       
   186     __LOG( "[UpnpNoteHandler] DialogDismissedL end" );
       
   187     }
       
   188 
       
   189 // --------------------------------------------------------------------------
       
   190 // CUpnpNoteHandler::RunProgressNoteL
       
   191 // Initialises and runs the progress note.
       
   192 // --------------------------------------------------------------------------
       
   193 //
       
   194 void CUpnpNoteHandler::RunProgressNoteL( TUpnpProgressNoteType aNoteType )
       
   195     {
       
   196     __LOG( "[UpnpNoteHandler] RunProgressNoteL()" );
       
   197 
       
   198     // Check the status of the note
       
   199     if( iProgressNoteDialog )
       
   200         {
       
   201         User::Leave( KErrInUse );
       
   202         }
       
   203 
       
   204     // reset the iProgressNote flag
       
   205     iProgressNoteFinish = EFalse;
       
   206 
       
   207     // Create the note
       
   208     iProgressNoteDialog = new (ELeave) CAknProgressDialog(
       
   209                           ( REINTERPRET_CAST( CEikDialog**,
       
   210                           &iProgressNoteDialog ) ) );
       
   211 
       
   212     // Select correct resource
       
   213     if( aNoteType == EUpnpMoveProgressNote )
       
   214         {
       
   215         iProgressNoteDialog->PrepareLC( R_FT_MOVE_PROGRESS_NOTE_DIALOG );
       
   216         }
       
   217     else
       
   218         {
       
   219         iProgressNoteDialog->PrepareLC( R_FT_COPY_PROGRESS_NOTE_DIALOG );
       
   220         }
       
   221 
       
   222     // Set values
       
   223     iProgressNoteDialog->SetCallback( this );
       
   224     iProgressInfo = iProgressNoteDialog->GetProgressInfoL();
       
   225     iCurrentProgressValue = KProgressInfoInitialValue;
       
   226 
       
   227     // Draw
       
   228     iProgressInfo->SetAndDraw( iCurrentProgressValue );
       
   229 
       
   230     // Run the note
       
   231     iProgressNoteDialog->RunLD();
       
   232     
       
   233     __LOG( "[UpnpNoteHandler] RunProgressNoteL() end" );
       
   234     }
       
   235 
       
   236 // --------------------------------------------------------------------------
       
   237 // CUpnpNoteHandler::FinishProgressNote
       
   238 // Finishes the progress note.
       
   239 // --------------------------------------------------------------------------
       
   240 //
       
   241 void CUpnpNoteHandler::FinishProgressNote()
       
   242     {
       
   243     __LOG( "[UpnpNoteHandler] FinishProgressNote()" );
       
   244     
       
   245     iProgressNoteFinish = ETrue;
       
   246     // If the progress note is running, finish it
       
   247     if( iProgressNoteDialog )
       
   248         {
       
   249         TRAP_IGNORE( iProgressNoteDialog->ProcessFinishedL() );
       
   250         }
       
   251     __LOG( "[UpnpNoteHandler] FinishProgressNote() end" );
       
   252     }
       
   253 
       
   254 // --------------------------------------------------------------------------
       
   255 // CUpnpNoteHandler::ShowSkippingDRMFilesNote
       
   256 // Shows 'Skipping DRM protected files.' -note
       
   257 // --------------------------------------------------------------------------
       
   258 //
       
   259 void CUpnpNoteHandler::ShowSkippingDRMFilesNoteL()
       
   260     {
       
   261     __LOG( "[CUpnpNoteHandler] ShowSkippingDRMFilesNote" );
       
   262                    
       
   263     // Load the string, and show the note
       
   264     HBufC* errorText = StringLoader::LoadLC( 
       
   265             R_FT_DRM_FILE_TEXT );
       
   266     CAknInformationNote* errorNote = 
       
   267         new ( ELeave ) CAknInformationNote( ETrue );
       
   268     errorNote->ExecuteLD( *errorText );
       
   269     CleanupStack::PopAndDestroy( errorText );
       
   270     }
       
   271 
       
   272 // End of file