usbuis/imageprintui/src/imageprintuiappui.cpp
changeset 93 2dc695882abd
parent 89 3592750162a5
equal deleted inserted replaced
89:3592750162a5 93:2dc695882abd
     1 /*
       
     2 * Copyright (c) 2006, 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:  S60 AppUi class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <avkon.hrh>
       
    20 #include <avkon.rsg> 
       
    21 #include <AiwGenericParam.h>
       
    22 #include <GenericParamConsumer.h>
       
    23 #include <aknnavide.h>
       
    24 #include <imageprintui.rsg>
       
    25 #include <AknWaitDialog.h>
       
    26 #include <f32file.h>
       
    27 #include <s32file.h>
       
    28 // #include <d32usbc.h>
       
    29 
       
    30 #include <badesca.h>
       
    31 #include <bautils.h>
       
    32 #include <e32std.h>
       
    33 #include <pathinfo.h> 
       
    34 
       
    35 #include "imageprintui.hrh"
       
    36 #include "imageprintuiappui.h"
       
    37 #include "imageprintuidocument.h"
       
    38 #include "emptyview.h"
       
    39 #include "settingsview.h"
       
    40 #include "imageprintuidebug.h"
       
    41 #include "connectionmanager.h"
       
    42 #include "capabilitymanager.h"
       
    43 #include "requestmanager.h"
       
    44 #include "eventmanager.h"
       
    45 #include "notes.h"
       
    46 #include "notetimer.h"
       
    47 
       
    48  
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 //  ConstructL()
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CImagePrintUiAppUi::ConstructL()
       
    56     {
       
    57     
       
    58     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::ConstructL()"));
       
    59     
       
    60     BaseConstructL( EAknEnableSkin | EAknEnableMSK );
       
    61     iEngine = static_cast<CImagePrintUiDocument*>(Document())->Engine();
       
    62     
       
    63     iImageFiles = new (ELeave) CDesCArrayFlat(KImageDefaultArray);
       
    64     iNotes = CNotes::NewL(this);
       
    65     iNoteShowed = EFalse;
       
    66     LoadImagesL();
       
    67     
       
    68     CAknView* emptyview = CEmptyView::NewLC();
       
    69     AddViewL(emptyview);
       
    70     CleanupStack::Pop(emptyview); 
       
    71 
       
    72     CAknView* settingsview = CSettingsView::NewLC();
       
    73     AddViewL(settingsview);
       
    74     CleanupStack::Pop(settingsview);
       
    75     ActivateLocalViewL( emptyview->Id() ); 
       
    76  
       
    77     iCableConnected = EFalse;
       
    78     iActiveNote = EFalse;
       
    79     iNumberOfUnSuppFiles = 0;
       
    80     iCapabilityChanged = EFalse;
       
    81     iPrintActive = EFalse;
       
    82     iErrorState = EFalse;
       
    83     iStartJobOK = EFalse;
       
    84     iPaperEmpty = EFalse;
       
    85     iNoteTimeOut = EFalse;
       
    86     iCloseTimeOut = EFalse;
       
    87     iCapabilityTimeOut = EFalse;
       
    88     iRequestTimeOut = EFalse;
       
    89     iNoteTimer = CNoteTimer::NewL(this);
       
    90     ReadNumberOfUnSuppL();
       
    91    
       
    92     iConnectionManager = CConnectionManager::NewL(this, iEngine, iNotes);
       
    93     iConnectionManager->StartSearchPrinter();
       
    94       
       
    95     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::ConstructL() complete"));
       
    96     }
       
    97 
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Destructor
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 CImagePrintUiAppUi::~CImagePrintUiAppUi()
       
   104     {
       
   105     delete iNaviDecorator;
       
   106     delete iCapabilityManager; 
       
   107     delete iRequestManager; 
       
   108     
       
   109     delete iEventManager;
       
   110     delete iConnectionManager; 
       
   111        
       
   112     delete iNoteTimer;    	
       
   113     delete iNotes;
       
   114     delete iImageFiles;
       
   115     }
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Handle global commands
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CImagePrintUiAppUi::HandleCommandL(TInt aCommand)
       
   123     {
       
   124 
       
   125     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::HandleCommandL()"));
       
   126 
       
   127     // Handle global events
       
   128     switch ( aCommand )
       
   129         {
       
   130         case EAknSoftkeyExit: 
       
   131         case EAknSoftkeyBack:
       
   132         case EAknCmdExit:
       
   133         case EEikCmdExit:
       
   134             {
       
   135             Exit(); 
       
   136             break;
       
   137             }
       
   138         default:
       
   139             break;
       
   140         }
       
   141 
       
   142     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::HandleCommandL() complete"));
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // Closes the application when the cable is disconnected or when some other
       
   148 // mode is selected. 
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CImagePrintUiAppUi::CloseApplication(TBool aDisconnect)
       
   152 	{
       
   153     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::CloseApplication"));
       
   154     iNotes->SetDisconnectState(aDisconnect);
       
   155     if(iPrintActive)
       
   156     	{
       
   157     	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::CloseApplication show note"));
       
   158     	TRAP_IGNORE(iNotes->ShowErrorMsgL(R_ERROR_CONNECTION_LOST));
       
   159     	if(!iNoteTimer->IsActive())
       
   160     		iCloseTimeOut = ETrue;
       
   161     		iNoteTimer->After(KRetryClose);
       
   162     	}
       
   163     else
       
   164     	{
       
   165     	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::CloseApplication just now"));
       
   166     	TRAPD(err, ProcessCommandL(EAknCmdExit));  
       
   167     	if(err)
       
   168     		{
       
   169     		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::error when CloseApplication"));
       
   170     		}
       
   171     	}
       
   172     
       
   173 	}
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // Closes the application after showing note
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CImagePrintUiAppUi::CloseAfterNoteL()
       
   180 	{
       
   181 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::CloseAfterNoteL "));
       
   182 	ProcessCommandL(EAknCmdExit);  
       
   183 	}
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // 
       
   187 // ---------------------------------------------------------------------------
       
   188 //	
       
   189 void CImagePrintUiAppUi::NotifyPrintStatus(TInt aStatus)
       
   190 	{
       
   191 	FLOG(_L("[IMAGEPRINTUI]>>> CImagePrintUiAppUi::NotifyPrintStatus "));
       
   192 	FTRACE(FPrint(_L("[IMAGEPRINTUI] CImagePrintUiAppUi  aStatus is %x"), aStatus ));
       
   193 	FTRACE(FPrint(_L("[IMAGEPRINTUI] CImagePrintUiAppUi  aStatus is %d"), aStatus ));
       
   194 	if(aStatus == EDpsPrintServiceStatusPrinting || aStatus == EDpsPrintServiceStatusIdle)
       
   195 		{
       
   196 		FLOG(_L("[IMAGEPRINTUI]>>> CImagePrintUiAppUi::NotifyPrintStatus set flag false "));
       
   197 		iPaperEmpty = EFalse;
       
   198 		}
       
   199 	if(aStatus == EDpsPrintServiceStatusPrinting)
       
   200 		{
       
   201 		FLOG(_L("[IMAGEPRINTUI]>>> CImagePrintUiAppUi::Print status active "));
       
   202 	    iPrintActive = ETrue;	
       
   203 		}
       
   204 	if(aStatus == EDpsPrintServiceStatusIdle)
       
   205 		{
       
   206 		FLOG(_L("[IMAGEPRINTUI]>>> CImagePrintUiAppUi::Print status idle"));
       
   207 		iNotes->PrintProgress(KPrintFinishValue);   
       
   208 	    iPrintActive = EFalse;	
       
   209 		}
       
   210 	FLOG(_L("[IMAGEPRINTUI]>>> CImagePrintUiAppUi::NotifyPrintStatus "));
       
   211 	}
       
   212 // ---------------------------------------------------------------------------
       
   213 // 
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CImagePrintUiAppUi::NotifyPrintProgress(TInt aImagesPrinted, TInt aProgress)
       
   217 	{
       
   218 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress"));
       
   219 	FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi aImagesPrinted value is %d"), aImagesPrinted ));
       
   220 	FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi aProgress value is %d"), aProgress ));
       
   221 	FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi iNumberOfImages value is %d"), iNumberOfImages ));
       
   222     TInt realProgress;
       
   223     TUint currentlayout;
       
   224     
       
   225     currentlayout = iCapabilityManager->Layout();
       
   226 	
       
   227 	if(currentlayout == EDpsLayoutDefault || currentlayout == EDpsLayout1Up)
       
   228 		{
       
   229 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress progress print"));
       
   230 		if(iNumberOfImages == KImageNumber)
       
   231 			{
       
   232 			FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress layout case 1 image"));
       
   233 			aImagesPrinted = aImagesPrinted*KPrintFinishValue;
       
   234 			realProgress = aImagesPrinted/iNumberOfImages;
       
   235 			realProgress = (realProgress <= KPrintFinishValue) ? realProgress : KPrintFinishValue;
       
   236 		    
       
   237 			if(!iErrorState)	
       
   238 				{
       
   239 				FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress no error "));
       
   240 			    iNotes->PrintProgress(realProgress);	
       
   241 				}
       
   242 			}
       
   243 		
       
   244 		if(iNumberOfImages > KImageNumber)
       
   245 			{
       
   246 			FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress one print image several images"));
       
   247 			if(aProgress < KPrintFinishValue)
       
   248 				{
       
   249 				FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress one print image several images update"));
       
   250 			    if(!iErrorState)
       
   251 			    	{
       
   252 			    	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress no error state "));
       
   253 			        iNotes->PrintProgress(aProgress); 	
       
   254 			    	}
       
   255 				}
       
   256 		
       
   257 			}
       
   258 		}
       
   259 	else
       
   260 		{
       
   261 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress NumberOfImages print"));
       
   262 		aImagesPrinted = aImagesPrinted*KPrintFinishValue;
       
   263 		realProgress = aImagesPrinted/iNumberOfImages;
       
   264 		realProgress = (realProgress <= KPrintFinishValue) ? realProgress : KPrintFinishValue;
       
   265 		if(realProgress == KPrintFinishValue)
       
   266 			{
       
   267 			FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress printing done layout big"));
       
   268 			}
       
   269 	    
       
   270 		if(realProgress < KPrintFinishValue)
       
   271 			{
       
   272 			FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress show progress layout big"));
       
   273 			if(!iErrorState)
       
   274 				{
       
   275 				FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress no error state"));
       
   276 			    iNotes->PrintProgress(realProgress); 	
       
   277 				}
       
   278 		    else
       
   279 		    	{
       
   280 		    	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyPrintProgress error state"));
       
   281 		    	}
       
   282 			}
       
   283 		
       
   284 		}
       
   285 	}
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 // To inform about info from eventmanager
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CImagePrintUiAppUi::NotifyEventL( TInt aEventNotifyType)
       
   292 	{
       
   293 	FLOG(_L("[IMAGEPRINTUI] CImagePrintUiAppUi NotifyEvent start"));
       
   294 	FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi aEventNotifyType is  %d"), aEventNotifyType ));
       
   295 	switch(aEventNotifyType)
       
   296 		{
       
   297         case CEventManager::ENewJobOK:
       
   298             FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> New job OK"));
       
   299             break;
       
   300             
       
   301         case CEventManager::ENewJobNOK: 
       
   302         	 FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> New job NOK"));
       
   303              iNotes->ShowErrorMsgL(R_ERROR_PRINTER_BUSY);
       
   304              break;    
       
   305              
       
   306         case CEventManager::ECapabilityChange:
       
   307         	 FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> Capability change"));
       
   308              TRAPD(err, iCapabilityManager->AskCapabilitiesL(ETrue));
       
   309              if(err)
       
   310              	{
       
   311              	iNotes->ShowErrorMsgL(R_ERROR_GENERAL);
       
   312              	}
       
   313              break; 
       
   314              
       
   315         case EDpsPaperJam: 
       
   316         	 FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi Paper Jam"));	 	
       
   317         	 iNotes->ShowErrorMsgL(R_ERROR_PAPER_JAM);
       
   318              break;  
       
   319              
       
   320         case EDpsPaperEmpty: 
       
   321         	 FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi Paper empty"));
       
   322         	 iPaperEmpty = ETrue;
       
   323         	 iNotes->ShowErrorMsgL(R_ERROR_OUT_OF_PAPER);
       
   324              break;       
       
   325              
       
   326         case CEventManager::EInkEmpty:
       
   327         	 FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi Ink empty"));
       
   328         	 iNotes->PrintFinished();	
       
   329         	 iNotes->ShowErrorMsgL(R_ERROR_OUT_OF_INK); 
       
   330              break;
       
   331              
       
   332         case EDpsInkLow: 
       
   333         	 FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi Ink low"));	
       
   334         	 iNotes->ShowErrorMsgL(R_ERROR_INK_LOW);  
       
   335              break;   
       
   336                  
       
   337 		case EDpsJobStatusEndedOther: 
       
   338 			 FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> User cancel from printer"));	
       
   339 			 if(iPrintActive )
       
   340 			 	{
       
   341 			 	iNotes->PrintFinished();
       
   342 				FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> User cancel print active"));
       
   343 				iPrintActive = EFalse;
       
   344 			 	}
       
   345 			 break;	
       
   346         case EDpsJobStatusEndedOk: 
       
   347         	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> Job eneded normally"));
       
   348         	break;
       
   349         	
       
   350 		case EDpsJobStatusEndedAbortImmediately: 
       
   351 			FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi  User aborted"));
       
   352 			break;
       
   353 			
       
   354 		case EDpsErrorStatusFatal: 
       
   355 		    FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi  Fatal error in printer side"));
       
   356 		    if(iPrintActive)
       
   357 		    	{
       
   358 		    	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi  Fatal error in printer side, stop progress note"));
       
   359 		    	iNotes->PrintFinished();
       
   360 		    	iPrintActive = EFalse;
       
   361 		    	}
       
   362 		    iNotes->ShowErrorMsgL(R_ERROR_CHECK_STATUS);
       
   363             break;
       
   364             
       
   365         case CEventManager::EWarning:
       
   366         	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi  Warning in printer side"));
       
   367         	if(!iPaperEmpty)
       
   368         		{
       
   369         		if(iPrintActive)
       
   370 			    	{
       
   371 			    	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi  Warning in printer side, stop progress note"));
       
   372 			    	iNotes->PrintFinished();
       
   373 			    	iPrintActive = EFalse;
       
   374 			    	}
       
   375 			    	iNotes->ShowErrorMsgL(R_ERROR_CHECK_STATUS);
       
   376         		}
       
   377             break;
       
   378             
       
   379         case CEventManager::ENotErrorState:
       
   380         	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi,  Not Error State"));
       
   381         	iErrorState = EFalse;
       
   382         	break;
       
   383         
       
   384         case CEventManager::EErrorState:  
       
   385         	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi,  Error State"));
       
   386         	iErrorState = ETrue;
       
   387         	break;
       
   388         
       
   389         case CEventManager::EShowError:
       
   390         	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi, EShowError"));
       
   391         	if(iPrintActive)
       
   392 		    	{
       
   393 		    	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi  EShowError in printer side, stop progress note"));
       
   394 		    	iNotes->PrintFinished();
       
   395 		    	iPrintActive = EFalse;
       
   396 		    	}
       
   397         	iNotes->ShowErrorMsgL(R_ERROR_GENERAL);
       
   398         	break;
       
   399         
       
   400 	// 	case KErrUsbInterfaceNotReady:
       
   401 		// 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi, KErrUsbInterfaceNotReady"));
       
   402 			// break;
       
   403         
       
   404         default:
       
   405         	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi  NotifyEvent::Default branch"));  		
       
   406             break;   
       
   407 		}
       
   408 	}
       
   409 // ---------------------------------------------------------------------------
       
   410 // To inform about info from requestmanager
       
   411 // ---------------------------------------------------------------------------
       
   412 //
       
   413 void CImagePrintUiAppUi::NotifyRequestL(TInt aNotifyType)
       
   414 	{
       
   415 	FLOG(_L("[IMAGEPRINTUI] CImagePrintUiAppUi NotifyRequest start"));
       
   416 	FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi aNotifyType is  %d"), aNotifyType ));
       
   417 	switch(aNotifyType)
       
   418 		{
       
   419         case CRequestManager::EConfigurePrintServiceOK:
       
   420             FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EConfigurePrintServiceOK "));
       
   421             TRAPD(err, iCapabilityManager->AskCapabilitiesL(EFalse));
       
   422             if(err)
       
   423             	{
       
   424             	iNotes->ShowErrorMsgL(R_ERROR_GENERAL);
       
   425             	}
       
   426             break;
       
   427             
       
   428                  
       
   429         case CRequestManager::EConfigurePrintServiceNOK:
       
   430              //printer does not support
       
   431              FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EConfigurePrintServiceNOK "));
       
   432              iNotes->ShowErrorMsgL(R_ERROR_UNABLE_TO_CONNECT); 
       
   433              break;    
       
   434              
       
   435         case CRequestManager::EGetJobStatusOK:
       
   436         	 FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EGetJobStatusOK "));	
       
   437              break; 
       
   438              
       
   439         case CRequestManager::EGetJobStatusNOK:
       
   440              FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EGetJobStatusNOK "));
       
   441              iNotes->ShowErrorMsgL(R_ERROR_GENERAL);  
       
   442              break;      
       
   443              
       
   444         case CRequestManager::EGetDeviceStatusOK:
       
   445              FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EGetDeviceStatusOK, start print "));
       
   446              break;
       
   447              
       
   448         case CRequestManager::EGetDeviceStatusNOK:
       
   449              // printer is busy
       
   450              FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EGetDeviceStatusNOK "));
       
   451              iNotes->ShowErrorMsgL(R_ERROR_PRINTER_BUSY); 
       
   452              break;  
       
   453              
       
   454         case CRequestManager::EStartJobOK:	
       
   455              //printing start ok
       
   456              FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::EStartJobOK"));
       
   457              iPrintActive = ETrue;
       
   458              iStartJobOK = ETrue;
       
   459              FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi EStartJobOK  iPrintActiveis  %d"), iPrintActive ));
       
   460              break;
       
   461              
       
   462         case CRequestManager::EStartJobNOK:
       
   463              //printing start nok
       
   464              FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EStartJobNOK "));
       
   465              iNotes->ShowErrorMsgL(R_ERROR_GENERAL); 
       
   466              break;     
       
   467              
       
   468         case CRequestManager::EAbortJobOK:
       
   469              FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EAbortJobOK ")); 
       
   470              break; 
       
   471              
       
   472         case CRequestManager::EAbortJobNOK:
       
   473              iNotes->ShowErrorMsgL(R_ERROR_GENERAL); 
       
   474              CloseApplication(EFalse);
       
   475              FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EAbortJobNOK ")); 
       
   476              break;
       
   477              
       
   478         case CRequestManager::EPicturesNotFound:  
       
   479         	FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; EPicturesNotFound ")); 
       
   480         	iNotes->ShowErrorMsgL(R_ERROR_FILE_NOT_FOUND); 
       
   481         	break;
       
   482         		  
       
   483         default:
       
   484             FLOG(_L("[IMAGEPRINTUI]<<< CImagePrintUiAppUi NotifyRequest; Default branch")); 
       
   485             break;   
       
   486 		
       
   487 		}
       
   488 	
       
   489 	FLOG(_L("[IMAGEPRINTUI] CImagePrintUiAppUi NotifyRequest; END "));
       
   490 	}
       
   491 
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // To inform number of images
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 void CImagePrintUiAppUi::NumberOfImages(TInt aNumberOfImages)
       
   498 	{
       
   499 	FTRACE(FPrint(_L("[IMAGEPRINTUI]\t NumberOfImages iNumberOfImages  is %d"), iNumberOfImages));
       
   500 	iNumberOfImages = aNumberOfImages;
       
   501 	}
       
   502 	
       
   503 // ---------------------------------------------------------------------------
       
   504 // To handle timer timeout
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 void CImagePrintUiAppUi::HandleTimeOutL()
       
   508 	{
       
   509 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleTimeOutL"));
       
   510 	if(iNoteTimeOut)
       
   511 		{
       
   512 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleTimeOutL, note"));
       
   513 		iNoteTimeOut = EFalse;
       
   514 		ShowNoteL(); 		
       
   515 		}
       
   516 	else if(iCloseTimeOut)
       
   517 		{
       
   518 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleTimeOutL, close"));
       
   519 		iCloseTimeOut = EFalse;
       
   520 		CloseAfterNoteL();
       
   521 		}
       
   522 	else if(iCapabilityTimeOut)
       
   523 		{
       
   524 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleTimeOutL, capability"));
       
   525 		iCapabilityTimeOut = EFalse;
       
   526 		iCapabilityManager->AskCapabilitiesL(EFalse);
       
   527     	}
       
   528 	else if(iRequestTimeOut)
       
   529 		{
       
   530 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleTimeOutL, request"));
       
   531 		iRequestTimeOut = EFalse;
       
   532 		iRequestManager->ReIssueDoDpsRequestL();
       
   533 		}
       
   534 	
       
   535 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> HandleTimeOutL"));
       
   536 	}
       
   537 	
       
   538 // ---------------------------------------------------------------------------
       
   539 // To handle timer error
       
   540 // ---------------------------------------------------------------------------
       
   541 //
       
   542 void CImagePrintUiAppUi::HandleTimeErrorL(TInt aError)
       
   543 	{
       
   544 	if(iNoteTimeOut)
       
   545 		{
       
   546 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleTimeErrorL, note"));
       
   547 		if(aError == KErrTimedOut)
       
   548 			{
       
   549 			iNoteTimeOut = EFalse;
       
   550 			ShowNoteL();
       
   551 			}
       
   552 		}
       
   553 	else if(iCloseTimeOut)
       
   554 		{
       
   555 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleTimeErrorL, close"));
       
   556 		if(aError == KErrTimedOut)
       
   557 			{
       
   558 		    iCloseTimeOut = EFalse;
       
   559 			CloseAfterNoteL(); 	
       
   560 			}
       
   561 		}
       
   562 	else if(iCapabilityTimeOut)
       
   563 		{
       
   564 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleTimeErrorL, capability"));
       
   565 		if(aError == KErrTimedOut)
       
   566 			{
       
   567 			iCapabilityTimeOut = EFalse;
       
   568 			iCapabilityManager->AskCapabilitiesL(EFalse);
       
   569 			}
       
   570 		}
       
   571 	else if(iRequestTimeOut)
       
   572 		{
       
   573 		FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleTimeErrorL, request"));
       
   574 		if(aError == KErrTimedOut)
       
   575     		{
       
   576 			iRequestTimeOut = EFalse;
       
   577 			iRequestManager->ReIssueDoDpsRequestL();
       
   578     		}
       
   579 		
       
   580 		}
       
   581 	
       
   582 	
       
   583 	}
       
   584 // ---------------------------------------------------------------------------
       
   585 // To handle request timeout
       
   586 // ---------------------------------------------------------------------------
       
   587 //
       
   588 void CImagePrintUiAppUi::HandleRequestTime(TInt aTime)
       
   589 	{	
       
   590 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleRequestTimeL"));
       
   591 	iRequestTimeOut = ETrue;
       
   592 	if(!iNoteTimer->IsActive())
       
   593 		{
       
   594 	    iNoteTimer->After(aTime); 	
       
   595 		}
       
   596 	}
       
   597 	
       
   598 // ---------------------------------------------------------------------------
       
   599 // To handle capability timeout
       
   600 // ---------------------------------------------------------------------------
       
   601 //
       
   602 void CImagePrintUiAppUi::HandleCapabilityTime(TInt aTime)
       
   603 	{	
       
   604 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< HandleCapabilityTimeL"));
       
   605 	iCapabilityTimeOut = ETrue;
       
   606 	if(!iNoteTimer->IsActive())
       
   607 		{
       
   608 	    iNoteTimer->After(aTime);	
       
   609 		}
       
   610 	}
       
   611 		
       
   612 // ---------------------------------------------------------------------------
       
   613 // To inform when the cable is connected
       
   614 // ---------------------------------------------------------------------------
       
   615 //
       
   616 void CImagePrintUiAppUi::CableConnectedL()
       
   617 	{
       
   618     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi <<< CableConnected"));
       
   619       
       
   620     iCableConnected = ETrue;
       
   621     iEventManager = CEventManager::NewL(this, iEngine);
       
   622     iCapabilityManager = CCapabilityManager::NewL(this, iEngine);
       
   623     iRequestManager    = CRequestManager::NewL(iEngine, iCapabilityManager, this);
       
   624     
       
   625     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> CableConnected"));
       
   626 	}
       
   627 
       
   628 
       
   629 // ---------------------------------------------------------------------------
       
   630 // To inform when the cable is disconnected
       
   631 // ---------------------------------------------------------------------------
       
   632 //
       
   633 void CImagePrintUiAppUi::NotifyError()
       
   634 	{
       
   635 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::NotifyError"));
       
   636 	TRAP_IGNORE(iNotes->ShowErrorMsgL(R_ERROR_GENERAL));
       
   637 	}
       
   638 // ---------------------------------------------------------------------------
       
   639 // To inform when the cable is disconnected
       
   640 // ---------------------------------------------------------------------------
       
   641 //
       
   642 void CImagePrintUiAppUi::CableDisConnected()
       
   643 	{
       
   644 	iCableConnected = EFalse;
       
   645 	}
       
   646 // ---------------------------------------------------------------------------
       
   647 // CapabilityManager informs here when capabilities are fetched from dps engine
       
   648 // ---------------------------------------------------------------------------
       
   649 //
       
   650 void CImagePrintUiAppUi::CapabilitiesReady()
       
   651 {
       
   652     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::CapabilitiesReady, activate local view"));
       
   653     TRAPD(err,ActivateLocalViewL(KImagePrintSettingsViewId));
       
   654     if(err)
       
   655     	{
       
   656     	TRAP_IGNORE(iNotes->ShowErrorMsgL(R_ERROR_GENERAL));
       
   657     	}
       
   658     	
       
   659     TRAPD(err2, SetNavipaneTextL()); 
       
   660     if(err2)
       
   661     	{
       
   662     	FLOG(_L("[IMAGEPRINTUI] CImagePrintUiAppUi::Unable to show printer name"));
       
   663     	}
       
   664 } 
       
   665 
       
   666 
       
   667 // ---------------------------------------------------------------------------
       
   668 // This is called when the user presses Options->Print
       
   669 // ---------------------------------------------------------------------------
       
   670 //
       
   671 void CImagePrintUiAppUi::StartPrinting()
       
   672 	{
       
   673     // get first device status, then if OK  dps type start job
       
   674     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> StartPrinting called")); 
       
   675     iCapabilityManager->CheckIfNewCapabilityDiffer();
       
   676     if(iCableConnected)
       
   677     	{
       
   678         iNotes->SetCancelState(EFalse);
       
   679     	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> StartPrinting, cable connected")); 
       
   680         TRAPD(err, iRequestManager->ChooseDpsRequestTypeL(CRequestManager::EGetDeviceStatus )); 
       
   681         if(err)
       
   682         	{
       
   683         	TRAP_IGNORE(iNotes->ShowErrorMsgL(R_ERROR_GENERAL));
       
   684         	}
       
   685     	}
       
   686     else
       
   687     	{
       
   688     	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> StartPrinting, cable NOT connected")); 
       
   689     	TRAP_IGNORE(iNotes->ShowNoteL(R_CONNECT_USB));
       
   690     	iActiveNote = ETrue;
       
   691     	}                                          
       
   692     
       
   693 	}
       
   694 
       
   695 
       
   696 // ---------------------------------------------------------------------------
       
   697 // This is called when the user presses Options->Cancel Print
       
   698 // ---------------------------------------------------------------------------
       
   699 //
       
   700 
       
   701 void CImagePrintUiAppUi::CancelPrinting()
       
   702 	{
       
   703 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> CancelPrinting BEGIN"));
       
   704 	TBool cancel = ETrue;
       
   705     iNotes->SetCancelState(cancel);
       
   706 	TRAPD(err, iRequestManager->ChooseDpsRequestTypeL(CRequestManager::EAbortJob ));
       
   707 	if(err)
       
   708     	{
       
   709         TRAP_IGNORE(iNotes->ShowErrorMsgL(R_ERROR_GENERAL));
       
   710         }
       
   711 
       
   712 	
       
   713 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi >>> CancelPrinting END"));
       
   714 	}
       
   715 // ---------------------------------------------------------------------------
       
   716 // 
       
   717 // ---------------------------------------------------------------------------
       
   718 //
       
   719 CDesCArrayFlat* CImagePrintUiAppUi::ImagesToPrint()
       
   720     {
       
   721     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::ImagesToPrint()"));
       
   722     FTRACE(FPrint(_L("[IMAGEPRINTUI] ImagesToPrint; iImageFiles  is %x"), iImageFiles ));
       
   723     return iImageFiles;
       
   724     }
       
   725 
       
   726 // ---------------------------------------------------------------------------
       
   727 // 
       
   728 // ---------------------------------------------------------------------------
       
   729 //
       
   730 
       
   731 void CImagePrintUiAppUi::ReadNumberOfUnSuppL()
       
   732 	{
       
   733 	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::ReadNumberOfUnSuppL start()"));
       
   734     
       
   735     TFileName unSuppFile( KResource ); 
       
   736     unSuppFile = PathInfo::PhoneMemoryRootPath(); 
       
   737     TBuf<KResource> lengthUn(KUnSuppFile);
       
   738     unSuppFile.SetLength(KDriver + lengthUn.Length());
       
   739     unSuppFile.Replace(KDriver, lengthUn.Length(), KUnSuppFile);
       
   740     
       
   741     
       
   742     RFileReadStream readStream;
       
   743     User::LeaveIfError( readStream.Open(CCoeEnv::Static()->FsSession(), unSuppFile, EFileRead) );
       
   744     readStream.PushL();
       
   745     iNumberOfUnSuppFiles = readStream.ReadInt16L();	
       
   746     FTRACE(FPrint(_L("[IMAGEPRINTUI] CImagePrintUiAppUi iNumberOfUnSuppFiles  is %d"), iNumberOfUnSuppFiles ));
       
   747     CleanupStack::PopAndDestroy(&readStream); 
       
   748     
       
   749     
       
   750     if(iNumberOfUnSuppFiles < KNumberOfUnsupportedFiles)
       
   751     	{
       
   752     	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::ReadNumberOfUnSuppL none"));
       
   753     	}
       
   754     else if(iNumberOfUnSuppFiles == KNumberOfUnsupportedFiles ||
       
   755             iNumberOfUnSuppFiles > KNumberOfUnsupportedFiles)
       
   756     	{
       
   757     	FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::ReadNumberOfUnSuppL one or more"));
       
   758     	if(!iNoteTimer->IsActive())
       
   759     	    iNoteTimeOut = ETrue;
       
   760     		iNoteTimer->After(KRetryInterval);
       
   761     	} 
       
   762 	}
       
   763 
       
   764 // ---------------------------------------------------------------------------
       
   765 // 
       
   766 // ---------------------------------------------------------------------------
       
   767 //
       
   768 void CImagePrintUiAppUi::LoadImagesL()
       
   769     {
       
   770     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::LoadImagesL()"));
       
   771     
       
   772     TFileName printNameFile( KResource ); 
       
   773     printNameFile = PathInfo::PhoneMemoryRootPath();  
       
   774     TBuf<KResource> length(KParamFile);
       
   775     printNameFile.SetLength(KDriver + length.Length());
       
   776     printNameFile.Replace(KDriver, length.Length(), KParamFile);
       
   777     
       
   778   
       
   779     RFileReadStream readStream;
       
   780     CleanupClosePushL(readStream); //1
       
   781     User::LeaveIfError( readStream.Open(CCoeEnv::Static()->FsSession(),
       
   782                         printNameFile, EFileRead) );
       
   783     CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC(readStream); //2
       
   784 
       
   785     TInt index( 0 ); 
       
   786     const TAiwGenericParam* param = paramList->FindFirst(index,
       
   787             EGenericParamFile,
       
   788             EVariantTypeDesC);
       
   789     while ( index != KErrNotFound )
       
   790 		{
       
   791         TFileName filename( param->Value().AsDes() );
       
   792         FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::LoadImagesL; append picture")); 
       
   793         iImageFiles->AppendL( filename ); 	
       
   794         	
       
   795         param = paramList->FindNext(index,
       
   796             EGenericParamFile,
       
   797             EVariantTypeDesC);
       
   798         }
       
   799 
       
   800     CleanupStack::PopAndDestroy(paramList);
       
   801     CleanupStack::PopAndDestroy(&readStream);
       
   802   
       
   803     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::LoadImagesL() complete"));
       
   804     }
       
   805 
       
   806 
       
   807 // ---------------------------------------------------------------------------
       
   808 // Set navi pane text
       
   809 // ---------------------------------------------------------------------------
       
   810 //
       
   811 void CImagePrintUiAppUi::SetNavipaneTextL()
       
   812     {
       
   813     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::SetNavipaneTextL Start"));
       
   814     CEikStatusPane* sp =
       
   815         iEikonEnv->AppUiFactory()->StatusPane();
       
   816        
       
   817     CAknNavigationControlContainer* np =
       
   818         static_cast<CAknNavigationControlContainer*>(
       
   819             sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   820            
       
   821     delete iNaviDecorator;
       
   822     iNaviDecorator = NULL;
       
   823     
       
   824     TInt blank(1);
       
   825     TBuf8<KMaxPrinterName> printername;
       
   826     TBuf8<KMaxPrinterName> productname;
       
   827     
       
   828     iRequestManager->GetPrinterName(printername, productname); 
       
   829     // convert to HBuf16 because CreateNavigationLabel needs TDesC16, not TDesC8
       
   830     HBufC* temp = HBufC::NewLC(printername.Length() + productname.Length() + blank); 
       
   831     HBufC* temp2 = HBufC::NewLC(productname.Length()); 
       
   832     FTRACE(FPrint(_L("[IMAGEPRINTUI] CImagePrintUiAppUi printername  is %S"), &printername ));
       
   833     FTRACE(FPrint(_L("[IMAGEPRINTUI] CImagePrintUiAppUi productname  is %S"), &productname ));
       
   834     temp->Des().Copy(printername); 
       
   835     temp->Des().Append(_L(" "));
       
   836     temp2->Des().Copy(productname);
       
   837     temp->Des().Append(temp2->Des());
       
   838     
       
   839     iNaviDecorator = np->CreateNavigationLabelL( *temp );
       
   840     CleanupStack::PopAndDestroy(temp2);
       
   841     CleanupStack::PopAndDestroy(temp);
       
   842     np->PushL( *iNaviDecorator );
       
   843     sp->DrawNow(); 
       
   844     FLOG(_L("[IMAGEPRINTUI]\t CImagePrintUiAppUi::SetNavipaneText END"));
       
   845     }
       
   846 
       
   847 CCapabilityManager* CImagePrintUiAppUi::CapabilityManager()
       
   848 	{
       
   849 	return iCapabilityManager;
       
   850 	}
       
   851 	
       
   852 CNotes* CImagePrintUiAppUi::Notes()
       
   853 	{
       
   854 	return iNotes;
       
   855 	}
       
   856 
       
   857 // ---------------------------------------------------------------------------
       
   858 // 
       
   859 // ---------------------------------------------------------------------------
       
   860 //
       
   861 TBool CImagePrintUiAppUi::PrintActive()
       
   862 	{
       
   863 	return iPrintActive;
       
   864 	}
       
   865 	
       
   866 
       
   867 // ---------------------------------------------------------------------------
       
   868 // 
       
   869 // ---------------------------------------------------------------------------
       
   870 //
       
   871 void CImagePrintUiAppUi::ShowNoteL()
       
   872 	{
       
   873     iNoteShowed = ETrue;
       
   874     if(iNumberOfUnSuppFiles == KNumberOfUnsupportedFiles)
       
   875     	{
       
   876         iNotes->ShowInfoNoteL(R_ERROR_FILE_NOT_SUPPORTED);	
       
   877     	}
       
   878     else if(iNumberOfUnSuppFiles > KNumberOfUnsupportedFiles)
       
   879     	{
       
   880     	iNotes->ShowInfoNoteL(R_ERROR_UNSUPPORTED_FILES_REMOVED);
       
   881     	}	
       
   882 	}
       
   883 // end of file