ImagePrint/ImagePrintUI/imgpprintdll/src/cimgpprintdlgmanager.cpp
changeset 0 d11fb78c4374
equal deleted inserted replaced
-1:000000000000 0:d11fb78c4374
       
     1 /*
       
     2 * Copyright (c) 2004-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <StringLoader.h>
       
    20 #include <AknWaitDialog.h>
       
    21 #include <aknstaticnotedialog.h>
       
    22 #include <eikprogi.h>
       
    23 #include <aknnotewrappers.h>
       
    24 #include <coecntrl.h>
       
    25 #include <eikmenup.h>
       
    26 #include <bautils.h>
       
    27 #include <bluetooth/hci/hcierrors.h>
       
    28 #include <f32file.h>
       
    29 #include <imageprintapp.rsg>
       
    30 
       
    31 #include "cimgpprintdlgmanager.h"
       
    32 #include "imgpprintapputil.h"
       
    33 #include "cimgpprintprogressdlg.h"
       
    34 #include "clog.h"
       
    35 #include "cimgpprintutils.h"
       
    36 #include "mprintingobserver.h"
       
    37 #include "tprinter.h"
       
    38 #include "printmessagecodes.h"
       
    39 #include "imageprintconsts.h"
       
    40 
       
    41 _LIT(KPlain, "%S");
       
    42 
       
    43 const TUint KProgressFinalValue = 100;
       
    44 
       
    45 // Timeout for MMC InformationNote ( timeout = 5 000 000 ms -> 5 s )
       
    46 const TInt KTimeOut = 5000000;  
       
    47 
       
    48 
       
    49 // CONSTRUCTION
       
    50 EXPORT_C CIMGPPrintDlgManager* CIMGPPrintDlgManager::NewL(
       
    51 	TInt aNoc,
       
    52     MPrintJob* aPrintJob,
       
    53     TUint aNumOfPages,
       
    54     TBool aMMCPrinting,
       
    55     TUint aVendor,
       
    56     CIMGPPrintUtils* aPrintUtils,
       
    57     MPrintingObserver* aPrintingObserver )
       
    58     {
       
    59     CIMGPPrintDlgManager* self =
       
    60         CIMGPPrintDlgManager::NewLC( aNoc,
       
    61         							 aPrintJob,
       
    62                                      aNumOfPages,
       
    63                                      aMMCPrinting,
       
    64                                      aVendor,
       
    65                                      aPrintUtils,
       
    66                                      aPrintingObserver );
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 CIMGPPrintDlgManager* CIMGPPrintDlgManager::NewLC(
       
    72 	TInt aNoc,
       
    73     MPrintJob* aPrintJob,
       
    74     TUint aNumOfPages,
       
    75     TBool aMMCPrinting,
       
    76     TUint aVendor,
       
    77     CIMGPPrintUtils* aPrintUtils,
       
    78     MPrintingObserver* aPrintingObserver )
       
    79     {
       
    80     CIMGPPrintDlgManager* self =
       
    81         new ( ELeave ) CIMGPPrintDlgManager( aNoc, 
       
    82         								 aPrintJob,
       
    83                                          aNumOfPages,
       
    84                                          aMMCPrinting,
       
    85                                          aVendor,
       
    86                                          aPrintUtils,
       
    87                                          aPrintingObserver );
       
    88     self->ConstructL();
       
    89     CleanupStack::PushL( self );
       
    90 
       
    91     return self;
       
    92     }
       
    93 
       
    94 
       
    95 // Second class constructor
       
    96 void CIMGPPrintDlgManager::ConstructL()
       
    97     {
       
    98  
       
    99     }
       
   100 
       
   101 // Default constructor
       
   102 CIMGPPrintDlgManager::CIMGPPrintDlgManager(
       
   103 	TInt aNoc,
       
   104     MPrintJob* aPrintJob,
       
   105     TUint aNumOfPages,
       
   106     TBool aMMCPrinting,
       
   107     TUint aVendor,
       
   108     CIMGPPrintUtils* aPrintUtils,
       
   109     MPrintingObserver* aPrintingObserver ) :
       
   110     iPrintJob( aPrintJob ),
       
   111     iNumOfPages( aNumOfPages ),
       
   112     iMMCPrinting( aMMCPrinting ),
       
   113     iVendor( aVendor )
       
   114     {
       
   115     iCancellingDialog = 0;
       
   116     // Used only in aiw printing
       
   117     if( aPrintUtils )
       
   118         {
       
   119         iPrintUtils = aPrintUtils;
       
   120         }
       
   121 	if( aPrintingObserver )
       
   122         {
       
   123         iPrintingObserver = aPrintingObserver;
       
   124         }
       
   125 	iNoc = aNoc;
       
   126     }
       
   127 
       
   128 // Destructor
       
   129 CIMGPPrintDlgManager::~CIMGPPrintDlgManager()
       
   130     {
       
   131 	LOG("CIMGPPrintDlgManager::~CIMGPPrintDlgManager BEGIN");
       
   132     if ( iDialog )
       
   133         {
       
   134         delete iDialog;
       
   135         iDialog = 0;
       
   136         }
       
   137 	LOG("CIMGPPrintDlgManager::~CIMGPPrintDlgManager END");
       
   138     }
       
   139 
       
   140 // Starts the print job
       
   141 EXPORT_C void CIMGPPrintDlgManager::StartPrintingL()
       
   142     {
       
   143 	LOG("CIMGPPrintDlgManager::StartPrintingL BEGIN");
       
   144     
       
   145 	iFirstNote = ETrue;
       
   146 	
       
   147     TRAPD( err, iPrintJob->PrintL( this ));
       
   148     if ( err == KErrNone )
       
   149     	{
       
   150     	LOG("CIMGPPrintDlgManager::StartPrintingL printing...");
       
   151     	PrepareProgressDialogL();
       
   152     	iCancelling = EFalse;
       
   153     	iPrintingCancelled = EFalse;
       
   154     	iDialog->RunLD();
       
   155     	}
       
   156 	else
       
   157 		{
       
   158 		LOG("CIMGPPrintDlgManager::StartPrintingL failed");
       
   159 		if ( iDialog )
       
   160         	{
       
   161         	delete iDialog;
       
   162         	iDialog = 0;
       
   163         	}
       
   164     	if( iPrintUtils )
       
   165     	    {
       
   166     	    iPrintUtils->JobFinished();
       
   167     	    }
       
   168 		if( iPrintingObserver )
       
   169 			{
       
   170 			TRAP_IGNORE( iPrintingObserver->PrintingCompletedL( EFalse ));
       
   171 			}
       
   172 		// Don't leave for KErrNotFound, as there's another note for it
       
   173 		if ( err != KErrNotFound )
       
   174 			{
       
   175 			TRAP_IGNORE( IMGPPrintAppUtil::ShowErrorMsgL( err ));
       
   176 			}
       
   177 		}
       
   178 	LOG("CIMGPPrintDlgManager::StartPrintingL END");
       
   179     }
       
   180 
       
   181 void CIMGPPrintDlgManager::PrepareProgressDialogL()
       
   182 	{
       
   183 	LOG("CIMGPPrintDlgManager::PrepareProgressDialogL START");
       
   184 	HBufC* txt;
       
   185     if ( !iMMCPrinting )
       
   186         {
       
   187         txt = StringLoader::LoadLC(
       
   188             R_QTN_PRINT_PROGRESS_NOTE_TITLE );
       
   189         }
       
   190     else
       
   191         {
       
   192         txt = StringLoader::LoadLC(
       
   193             R_QTN_COPY_PROGRESS_NOTE_TITLE);
       
   194         }
       
   195   
       
   196 	TBuf<128> buf;
       
   197 	buf.Format( KPlain, txt );
       
   198 	CleanupStack::PopAndDestroy( txt );
       
   199 
       
   200     iDialog = new ( ELeave ) CAknProgressDialog(
       
   201    	    (REINTERPRET_CAST( CEikDialog**, &iDialog )), EFalse );
       
   202 	iDialog->PrepareLC( R_PRINT_PROGRESS_PLAIN_PROG_NOTE );
       
   203 	
       
   204     CEikProgressInfo* info = iDialog->GetProgressInfoL();
       
   205     info->SetFinalValue( KProgressFinalValue );
       
   206     iDialog->SetTextL( buf );
       
   207     iDialog->SetCallback( this );
       
   208     LOG("CIMGPPrintDlgManager::PrepareProgressDialogL END");
       
   209 	}
       
   210 
       
   211 
       
   212 // Called to update the print progress
       
   213 void CIMGPPrintDlgManager::PrintProgress(
       
   214     TUint aComplete )
       
   215     {
       
   216     TInt err = KErrNone;
       
   217     TRAP( err, PrintProgressL( aComplete ) );
       
   218     if ( err != KErrNone )
       
   219         {
       
   220         TRAP_IGNORE( IMGPPrintAppUtil::ShowErrorMsgL( err ) );
       
   221         }
       
   222     }
       
   223 
       
   224 // Called to update the print progress
       
   225 void CIMGPPrintDlgManager::PrintProgressL(
       
   226     TUint aComplete )
       
   227     {
       
   228     LOG1( "CIMGPPrintDlgManager::PrintProgressL START with: %d", aComplete );
       
   229 	if( !iCancelling )
       
   230 		{
       
   231 		if ( !iDialog )
       
   232         	{
       
   233         	LOG("CIMGPPrintDlgManager::PrintProgressL: creating dialog again");
       
   234 			PrepareProgressDialogL();
       
   235     		iDialog->RunLD();
       
   236         	}
       
   237     	CEikProgressInfo* info = iDialog->GetProgressInfoL();
       
   238     	info->SetAndDraw( aComplete );
       
   239 		}
       
   240     LOG("CIMGPPrintDlgManager::PrintProgressL END");
       
   241     }
       
   242 
       
   243 // Called when the print job is finished
       
   244 void CIMGPPrintDlgManager::JobFinished()
       
   245     {
       
   246 			
       
   247 	LOG("CIMGPPrintDlgManager::JobFinished BEGIN");
       
   248     if ( iDialog )
       
   249         {
       
   250         delete iDialog;
       
   251         iDialog = 0;
       
   252         }    
       
   253     if ( iMMCPrinting && !iCancelling )
       
   254         {
       
   255 		LOG("CIMGPPrintDlgManager::JobFinished mmc note");
       
   256         TRAP_IGNORE( ShowMMCPrintingCompletedDlgL() );
       
   257  		LOG("CIMGPPrintDlgManager::JobFinished mmc note done");
       
   258         }
       
   259     if ( iCancelling )
       
   260 		{
       
   261 		if(iCancellingDialog)
       
   262 			{
       
   263 		TRAP_IGNORE( iCancellingDialog->ProcessFinishedL() );
       
   264 		iCancellingDialog = 0;
       
   265 		iCancelling = EFalse;
       
   266 			}
       
   267 		}
       
   268 	else
       
   269 		{
       
   270 	    if( iPrintUtils )
       
   271 	        {
       
   272 			LOG("CIMGPPrintDlgManager::JobFinished iPrintUtils");
       
   273 	        iPrintUtils->JobFinished();
       
   274 			LOG("CIMGPPrintDlgManager::JobFinished iPrintUtils done");
       
   275 	        }
       
   276 		if( iPrintingObserver )
       
   277 			{
       
   278 			TRAP_IGNORE( iPrintingObserver->PrintingCompletedL( EFalse ));
       
   279 			}
       
   280 		}
       
   281 	LOG("CIMGPPrintDlgManager::JobFinished END");
       
   282     }
       
   283 
       
   284 // Manages print job errors
       
   285 void CIMGPPrintDlgManager::JobError(
       
   286     TInt aErrCode, TInt aErrorStringCode )
       
   287     {
       
   288     LOG2("CIMGPPrintDlgManager::JobError BEGIN, error = %d, stringcode = %d", aErrCode, aErrorStringCode );
       
   289     
       
   290     if( iMMCPrinting && aErrCode == ECancellingNoMessage ) 
       
   291         {
       
   292        	if ( iDialog )
       
   293     	    {
       
   294     	    delete iDialog;
       
   295     	    iDialog = 0;
       
   296     	    }
       
   297        return;
       
   298        }
       
   299     
       
   300     if ( iMMCPrinting && !iCancelling )
       
   301         {
       
   302         TRAP_IGNORE( IMGPPrintAppUtil::ShowErrorNoteL( R_NOTE_IMAGEPRINT_MMCCOPYFAIL ) );
       
   303         // Nothing to do if the displaying of error note fails
       
   304         // Just need to make sure that this method never leaves
       
   305         }
       
   306 	if ( iCancelling )
       
   307 		{
       
   308         LOG( "CIMGPPrintDlgManager::JobError ---> iCancellingDialog->ProcessFinishedL()" );
       
   309 		TRAP_IGNORE( iCancellingDialog->ProcessFinishedL() );
       
   310 		iCancellingDialog = 0;
       
   311 		iCancelling = EFalse;
       
   312 		}
       
   313 	else
       
   314 		{
       
   315     	// Delete dialog
       
   316     	if ( iDialog )
       
   317     	    {
       
   318     	    delete iDialog;
       
   319     	    iDialog = 0;
       
   320     	    }
       
   321     	if( iPrintUtils &&
       
   322 		    aErrCode != KHCIErrorBase-EPageTimedOut &&
       
   323 		    aErrorStringCode != EObexConnectError )
       
   324     	    {
       
   325     	    iPrintUtils->JobFinished();
       
   326     	    }
       
   327 		if( iPrintingObserver )
       
   328 			{
       
   329 			TRAP_IGNORE( iPrintingObserver->PrintingCompletedL( EFalse ));
       
   330 			}
       
   331 		}
       
   332 
       
   333      /* Error note is shown to user in normal cases, but not when
       
   334       * printing is done to MMC, canceled, done via quickprint, or
       
   335       * BT timeout happens, as these cases are handled in other parts
       
   336       * of code
       
   337       */
       
   338     if ( !iMMCPrinting &&
       
   339          aErrCode != ECancelling &&
       
   340          ( !iPrintUtils ||
       
   341 		   ( aErrCode != KHCIErrorBase-EPageTimedOut &&
       
   342 		     aErrorStringCode != EObexConnectError )))
       
   343         {
       
   344         TRAP_IGNORE( IMGPPrintAppUtil::ShowErrorMsgL( aErrCode, aErrorStringCode ));
       
   345         // Nothing to do to handle err
       
   346         }
       
   347 	LOG("CIMGPPrintDlgManager::JobError END");
       
   348     }
       
   349 
       
   350 // Manages print job status events
       
   351 void CIMGPPrintDlgManager::JobStatusEvent( TInt aErrCode, TInt aErrorStringCode )
       
   352     {
       
   353     LOG2("CIMGPPrintDlgManager::JobStatusEvent = %d, stringcode = %d", aErrCode, aErrorStringCode );
       
   354     // If printer is disconnected cancel printing else
       
   355     // just show the error message
       
   356     if ( aErrCode == KErrDisconnected )
       
   357         {
       
   358         TRAP_IGNORE( IMGPPrintAppUtil::ShowErrorMsgL( KErrDisconnected, aErrorStringCode ));
       
   359         if ( iDialog )
       
   360             {
       
   361             // This ends the printing
       
   362             delete iDialog;
       
   363             iDialog = 0;
       
   364             }
       
   365         }
       
   366     else
       
   367         {
       
   368         TRAP_IGNORE( IMGPPrintAppUtil::ShowErrorMsgL( aErrCode, aErrorStringCode ));
       
   369         }
       
   370 	LOG("CIMGPPrintDlgManager::JobStatusEvent END");
       
   371     }
       
   372 
       
   373 // Shows printing completed dlg
       
   374 void CIMGPPrintDlgManager::ShowMMCPrintingCompletedDlgL()
       
   375     {
       
   376 	LOG("CIMGPPrintDlgManager::ShowMMCPrintingCompletedDlgL BEGIN");
       
   377     
       
   378     RPointerArray<TDesC> allImages;
       
   379 	CleanupClosePushL( allImages );
       
   380     iPrintJob->GetPrintJobL( allImages );
       
   381     TInt imagesCount = allImages.Count();
       
   382     CleanupStack::PopAndDestroy( &allImages );
       
   383     HBufC* buf = NULL;
       
   384 
       
   385     // Blocks possibility to show note when exiting image print. 
       
   386     if (iFirstNote)
       
   387     	{    
       
   388     	if ( iNoc == 1 && imagesCount == 1 )
       
   389 	        {
       
   390 	        buf = StringLoader::LoadLC( R_SETTINGS_IMAGEPRINT_MMC_PRINT_NOTE_ONE_PICTURE ); //r_settings_imageprint_mmc_print_note_one_picture
       
   391 	        }
       
   392 	    else
       
   393 	        {
       
   394 	        buf = StringLoader::LoadLC( R_SETTINGS_IMAGEPRINT_MMC_PRINT_NOTE );
       
   395 	        }
       
   396 	    	
       
   397 	       	CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue );
       
   398 		    dlg->SetTimeout( (CAknNoteDialog::TTimeout) KTimeOut );        
       
   399 		    dlg->ExecuteLD( *buf );
       
   400 		    CleanupStack::PopAndDestroy( buf );
       
   401 		    
       
   402 		iFirstNote = EFalse;    
       
   403 	    
       
   404     	} 
       
   405 	
       
   406 	    LOG("CIMGPPrintDlgManager::ShowMMCPrintingCompletedDlgL END");
       
   407     }
       
   408 
       
   409 // Called when dialog gets dismissed
       
   410 void CIMGPPrintDlgManager::DialogDismissedL(
       
   411     TInt aButtonId )
       
   412     {
       
   413 	LOG("CIMGPPrintDlgManager::DialogDismissedL BEGIN");
       
   414     // If user pressed cancel, cancel printing
       
   415     LOG1( "CIMGPPrintDlgManager::DialogDismissedL iPrintingCancelled: %d", iPrintingCancelled );
       
   416     if ( ( aButtonId == EAknSoftkeyCancel ) && ( iPrintingCancelled == EFalse ) )
       
   417         {
       
   418 		LOG("CIMGPPrintDlgManager::DialogDismissedL aButtonId == EAknSoftkeyCancel");
       
   419         iDialog = 0;
       
   420 		iCancelling = ETrue;
       
   421 		
       
   422 		// Printing cancelled
       
   423 		iPrintingCancelled = ETrue;
       
   424 
       
   425         TRAPD( err, iPrintJob->CancelL() );
       
   426         if( err == KErrNone )
       
   427         	{
       
   428 			ShowCancelWaitNoteL();
       
   429         	}
       
   430 		else
       
   431 			{
       
   432 			iCancelling = EFalse;
       
   433 			}        	
       
   434         }
       
   435 
       
   436 	LOG("CIMGPPrintDlgManager::DialogDismissedL END");
       
   437     }
       
   438 
       
   439 // Displays the cancel wait note
       
   440 void CIMGPPrintDlgManager::ShowCancelWaitNoteL()
       
   441 	{
       
   442 	iCancellingDialog  =
       
   443 		new ( ELeave ) CAknWaitDialog(
       
   444 			(REINTERPRET_CAST(CEikDialog**,&iCancellingDialog)));
       
   445     iCancellingDialog->PrepareLC(R_CANCEL_PRINTING_DIALOG);
       
   446     HBufC* text = StringLoader::LoadLC( R_QTN_PRINT_PROGRESS_PROMPT_CANCEL );
       
   447     iCancellingDialog->SetTextL( *text );
       
   448     CleanupStack::PopAndDestroy(text);
       
   449 
       
   450     iCancellingDialog->SetTone( CAknNoteDialog::ENoTone );
       
   451     iCancellingDialog->RunLD();
       
   452 
       
   453     if( iPrintUtils )
       
   454         {
       
   455         iPrintUtils->JobFinished();
       
   456         }
       
   457 	if( iPrintingObserver )
       
   458 		{
       
   459 		iPrintingObserver->PrintingCompletedL( ETrue );
       
   460 		}
       
   461 	}
       
   462 
       
   463 //  End of File