ImagePrint/ImagePrintEngine/DeviceProtocols/dpof/src/crsdpofengine.cpp
branchRCL_3
changeset 27 159fc2f68139
parent 21 26673e532f65
child 28 d59c248c9d36
equal deleted inserted replaced
21:26673e532f65 27:159fc2f68139
     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:  Contains the CRsDpofEngine & TRsPhoneImage class definitions and
       
    15 * 				 the MDpofEngineObserver interface definition.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32std.h>
       
    21 #include <s32file.h>
       
    22 #include <pathinfo.h>
       
    23 #include <sysutil.h>
       
    24 #include <driveinfo.h>
       
    25 
       
    26 #include "crsdpofengine.h"
       
    27 #include "rsutils.h"
       
    28 #include "imgprintkonst.h"
       
    29 #include "clog.h"
       
    30 #include "cfilemanager.h"
       
    31 
       
    32 //  CONSTANTS
       
    33 namespace
       
    34 	{
       
    35 	_LIT(KBackslash, "\\");
       
    36 	const TInt KCopyPercentage = 90;
       
    37 	const TInt KAutoPrintFileAddon=2048;
       
    38 
       
    39 	_LIT(KDpofAutoPrintFilename,	"\\MISC\\AUTPRINT.MRK");
       
    40 	_LIT(KDpofAutoPrintTempFolder,	"\\DPOF\\");
       
    41 	_LIT8(KDoubleQuote,				"\"");
       
    42 
       
    43 	_LIT8(KCrLf,					"\r\n");
       
    44 	_LIT8(KDpofHeader,				"[HDR]\r\nGEN REV = 01.10\r\nGEN CRT = \"ImagePrint\" -02.10\r\nGEN DTM = ");
       
    45 	_LIT8(KDpofJobAndPid,			"[JOB]\r\nPRT PID = ");
       
    46 	_LIT8(KDpofPrtTypSizeSmall,		"PRT TYP = SIZ -03\r\n");
       
    47 	_LIT8(KDpofPrtTypSizeMedium,	"PRT TYP = STD\r\n");
       
    48 	_LIT8(KDpofPrtTypSizeLarge,		"PRT TYP = SIZ -05\r\n");
       
    49 	_LIT8(KDpofPrtTypSize4x6,		"PRT TYP = STD\r\n");
       
    50 	_LIT8(KDpofPrtTypSize2pp,		"PRT TYP = MUL -02\r\n");
       
    51 	_LIT8(KDpofPrtTypSize4pp,		"PRT TYP = MUL -04\r\n");
       
    52 	_LIT8(KDpofPrtTypSize6pp,		"PRT TYP = MUL -06\r\n");
       
    53 	_LIT8(KDpofPrtTypSize9pp,		"PRT TYP = MUL -09\r\n");
       
    54 	_LIT8(KDpofPrtTypSize12pp,		"PRT TYP = MUL -12\r\n");
       
    55 	_LIT8(KDpofPrtTypSize16pp,		"PRT TYP = MUL -16\r\n");
       
    56 	_LIT8(KDpofPrtQtyAndImgFmt,		"PRT QTY = 001\r\nIMG FMT = EXIF2 -J\r\n");
       
    57 	_LIT8(KDpofImgSrc,				"IMG SRC = ");
       
    58 
       
    59 	_LIT8(KDateFormat,"%4d:%02d:%02d:%02d:%02d:%02d");
       
    60 	_LIT( KDotDot, ".." );
       
    61 	_LIT( KSlash, "/" );
       
    62 	const TInt KDpofDelay = 500000;	
       
    63 	}
       
    64 
       
    65 
       
    66 
       
    67 
       
    68 //////////////////////////////////////////////////////////////////////
       
    69 // Construction/Destruction
       
    70 //////////////////////////////////////////////////////////////////////
       
    71 CRsDpofEngine* CRsDpofEngine::NewL(MDpofEngineObserver& aObs)
       
    72 	{
       
    73     CRsDpofEngine* self = new (ELeave) CRsDpofEngine(aObs);
       
    74 	CleanupStack::PushL(self);
       
    75 	self->ConstructL();
       
    76     CleanupStack::Pop(self);
       
    77     return self;
       
    78 	}
       
    79 
       
    80 
       
    81 void CRsDpofEngine::ConstructL()
       
    82 	{	    
       
    83 	LOG("CRsDpofEngine::ConstructL begin");
       
    84 	User::LeaveIfError( iFs.Connect() );
       
    85 	iFileManager = CFileManager::NewL( iFs );
       
    86 	LOG("CRsDpofEngine::ConstructL end");
       
    87 	}
       
    88 
       
    89 CRsDpofEngine::CRsDpofEngine(MDpofEngineObserver& aObs) : 
       
    90 											CActive(CActive::EPriorityStandard),
       
    91 											iHasMmc(EFalse),
       
    92 											iImageLayout(0),
       
    93 											iObs(aObs),
       
    94 											iShouldCancel(EFalse)
       
    95 	{
       
    96 	CActiveScheduler::Add(this);
       
    97 	}
       
    98 
       
    99 CRsDpofEngine::~CRsDpofEngine()
       
   100 	{
       
   101 	Cancel();
       
   102 	if(iDpofPeriodic) iDpofPeriodic->Cancel();
       
   103 	delete iDpofPeriodic;	
       
   104 	delete iMmcDrive;
       
   105 	delete iAutoPrintFile;
       
   106 	delete iTempFolder;
       
   107 	iFileNames.ResetAndDestroy();
       
   108 	iFileNames.Close();
       
   109 	iPhoneImageArray.Close();
       
   110 	delete iFileManager;
       
   111 	iFs.Close();
       
   112 	iNumsOfCopies.Close();
       
   113 	}
       
   114 	
       
   115 void CRsDpofEngine::SetMMCPathL()
       
   116 	{
       
   117 	LOG("CRsDpofEngine::SetMMCPathL begin");
       
   118 
       
   119 	TFileName fileInfo;	
       
   120 	TInt driveId;
       
   121 	TFileName path;
       
   122 	User::LeaveIfError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, driveId ) );
       
   123 	User::LeaveIfError( PathInfo::GetRootPath( path, driveId ) );
       
   124 	HBufC* mmcRoot = path.AllocLC();
       
   125    	
       
   126    	LOG1("CRsDpofEngine::SetMMCPathL mmcRoot: %S", mmcRoot);
       
   127 	iHasMmc = ( mmcRoot && mmcRoot->Length() && RsUtils::PathExists( *mmcRoot, iFs ) );
       
   128 	
       
   129 	if( iHasMmc )
       
   130 		{
       
   131 		LOG("CRsDpofEngine::SetMMCPathL MMC found");		
       
   132 		iMmcDrive = mmcRoot->Left( 2 ).AllocL();
       
   133 		fileInfo.Copy( *iMmcDrive );
       
   134 		fileInfo.Append( KDpofAutoPrintFilename );				
       
   135 		iAutoPrintFile = fileInfo.AllocL();
       
   136 		fileInfo.Copy( *iMmcDrive );
       
   137 		fileInfo.Append( KDpofAutoPrintTempFolder );		
       
   138 		iTempFolder = fileInfo.AllocL();
       
   139 		}
       
   140 
       
   141 	CleanupStack::PopAndDestroy( mmcRoot );	
       
   142 
       
   143 	LOG("CRsDpofEngine::SetMMCPathL end");
       
   144 	}
       
   145 TInt CRsDpofEngine::CleanupTempImages()
       
   146 	{
       
   147 	LOG("CRsDpofEngine::CleanupTempImages begin");
       
   148 	iStatus = KRequestPending;		
       
   149 	TInt retVal = iFileManager->RmDir( *iTempFolder, iStatus );
       
   150 	if( !retVal && !IsActive() ) SetActive();		
       
   151 	LOG1("CRsDpofEngine::CleanupTempImages reurn: %d", retVal);  
       
   152 	return retVal;	
       
   153 	}
       
   154 
       
   155 void CRsDpofEngine::SetImageFileNamesL(const RPointerArray<HBufC>& aImageList)
       
   156 	{
       
   157 	LOG("CRsDpofEngine::SetImageFileNamesL begin");
       
   158 	iFileNames.ResetAndDestroy();
       
   159 	for( TInt i = 0; i < aImageList.Count(); i++)
       
   160 		{
       
   161 		HBufC* fileName = aImageList[i]->AllocLC();
       
   162 		LOG1("CRsDpofEngine::SetImageFileNamesL file: %S", fileName); 
       
   163 		User::LeaveIfError( iFileNames.Append( fileName ) );
       
   164 		CleanupStack::Pop( fileName );
       
   165 		}		
       
   166 	LOG("CRsDpofEngine::SetImageFileNamesL end");
       
   167 	}
       
   168 
       
   169 void CRsDpofEngine::SetImageLayout(TRsDpofImageLayout aImageLayout)
       
   170 	{
       
   171 	iImageLayout = aImageLayout;
       
   172 	}
       
   173 
       
   174 
       
   175 TInt CRsDpofEngine::PrintL()
       
   176 	{
       
   177 	LOG("CRsDpofEngine::PrintL begin");
       
   178 	TInt retVal( KErrNone );
       
   179 	iPhoneImgsSize = 0;
       
   180 
       
   181 	iShouldCancel = EFalse;			
       
   182 	iPhoneImageArray.Reset();
       
   183 
       
   184 	// Check if there are phone memory images, and add up their total space
       
   185 	LOG("CRsDpofEngine::PrintL checking phone memory images...");		
       
   186 	for( TInt i = 0; i < iFileNames.Count() && !retVal; i++ )
       
   187 		{		
       
   188 		if( !RsUtils::FileOnDrive( (*iMmcDrive)[0], *(iFileNames[i]) ) )
       
   189 			{
       
   190 			LOG1("CRsDpofEngine::PrintL phone memory image: %S", iFileNames[i]);
       
   191 			TRsPhoneImage phoneImage;
       
   192 			phoneImage.iIndex = i;
       
   193 			phoneImage.iCopied = EFalse;
       
   194 			iPhoneImageArray.AppendL( phoneImage );				
       
   195 			retVal = RsUtils::CumulativeFileSize( *(iFileNames[i]), iFs, iPhoneImgsSize );
       
   196 			LOG1("CRsDpofEngine::PrintL error checking phone memory images: %d", retVal);									
       
   197 			}								
       
   198 		}
       
   199 	LOG("CRsDpofEngine::PrintL checking phone memory images end");
       
   200 	LOG1("CRsDpofEngine::PrintL checking phone memory images, size: %d", iPhoneImgsSize);
       
   201 									
       
   202 	if( !retVal )
       
   203 		{
       
   204 		retVal = CleanupTempImages();
       
   205 		LOG1("CRsDpofEngine::PrintL error deleting temp folder: %d", retVal);
       
   206 		if( retVal == KErrNone )
       
   207 			{
       
   208 			iStep = EDeleteDirectory;
       
   209 			iObs.HandleDpofEngineEventL( EDeleteDirectory, retVal );	
       
   210 			}	
       
   211 		}
       
   212 	
       
   213 	LOG1("CRsDpofEngine::PrintL return: %d", retVal);
       
   214 	return retVal;						
       
   215 	}
       
   216 	
       
   217 	
       
   218 TInt CRsDpofEngine::PrepareFilenamesL()
       
   219 	{
       
   220 	LOG("CRsDpofEngine::PrepareFilenamesL begin");
       
   221 	TInt retVal( KErrNone );
       
   222 		
       
   223 
       
   224 	// Walk through the list of files
       
   225 	// - replacing long names with short names
       
   226 	// - "\" with "/"
       
   227 	// - MMC drive "e:" with ".."
       
   228 	
       
   229 	LOG1("CRsDpofEngine::PrepareFilenamesL iFileNames->Count(): %d", iFileNames.Count());
       
   230 	for( TInt i = 0; i < iFileNames.Count(); i++ )
       
   231 		{
       
   232 		LOG1("CRsDpofEngine::PrepareFilenamesL original: %S", iFileNames[i]);
       
   233 
       
   234 		TFileName shortFilename;
       
   235 		retVal = iFs.GetShortName( *(iFileNames[i]), shortFilename );
       
   236 		if( retVal != KErrNone )
       
   237 			{
       
   238 			LOG1("CRsDpofEngine::PrepareFilenamesL 1 error getting short name: %d", retVal);
       
   239 			return retVal;	
       
   240 			}
       
   241 		
       
   242 		TParse parse;
       
   243 		parse.Set( *(iFileNames[i]), NULL, NULL );	
       
   244 		parse.Set( parse.DriveAndPath(), NULL, NULL );
       
   245 		while( !parse.IsRoot() )
       
   246 			{
       
   247 			TBuf<16> shortDir;
       
   248 			retVal = iFs.GetShortName( parse.DriveAndPath(), shortDir );
       
   249 			if( retVal != KErrNone )
       
   250 				{
       
   251 				LOG1("CRsDpofEngine::PrepareFilenamesL 2 error getting short name: %d", retVal);
       
   252 				return retVal;	
       
   253 				}
       
   254 
       
   255 			shortFilename.Insert( 0, KSlash );
       
   256 			shortFilename.Insert( 0, shortDir );
       
   257 			
       
   258 			parse.PopDir();
       
   259 			}
       
   260 		shortFilename.Insert( 0, KSlash );
       
   261 		shortFilename.Insert( 0, KDotDot );
       
   262 
       
   263 		delete iFileNames[i];
       
   264 		iFileNames[i] = NULL;
       
   265 		iFileNames[i] = shortFilename.AllocL();
       
   266 		
       
   267 		LOG1("CRsDpofEngine::PrepareFilenamesL changed: %S", iFileNames[i]);	
       
   268 		}
       
   269 
       
   270 	LOG1("CRsDpofEngine::PrepareFilenamesL end with: %d", retVal);
       
   271 	return retVal;
       
   272 	}
       
   273 
       
   274 TInt CRsDpofEngine::WriteSpecificSizeFileL()
       
   275 	{
       
   276 	LOG("CRsDpofEngine::WriteSpecificSizeFile begin");
       
   277 	// Creates the autoprint file for a Specific Size image print
       
   278 	RFile autoPFile;
       
   279 	TBuf8<256> tempDes;
       
   280 	TTime currTime;
       
   281 	TDateTime currDT;
       
   282 	currTime.HomeTime();
       
   283 	currDT = currTime.DateTime();
       
   284 
       
   285 	// Open the autoprint file
       
   286 	TInt retVal = autoPFile.Replace( iFs, *iAutoPrintFile, EFileWrite );
       
   287 	if( retVal != KErrNone )
       
   288 		{
       
   289 		LOG1("CRsDpofEngine::WriteSpecificSizeFile error opening autoprint file: %d", retVal);
       
   290 		return retVal;	
       
   291 		}
       
   292 		
       
   293 	CleanupClosePushL(autoPFile);	
       
   294 	RFileWriteStream writeStream(autoPFile);
       
   295 	CleanupClosePushL(writeStream);		
       
   296 
       
   297 	// Write the common header information
       
   298 	LOG("CRsDpofEngine::WriteSpecificSizeFile Write the common header information");
       
   299 	writeStream.WriteL(KDpofHeader);
       
   300 	tempDes.Format(KDateFormat, currDT.Year(), (currDT.Month()+1), (currDT.Day()+1), currDT.Hour(), currDT.Minute(), currDT.Second());
       
   301 	writeStream.WriteL(tempDes);
       
   302 	writeStream.WriteL(KCrLf);
       
   303 
       
   304 	// For each image in the array
       
   305 	LOG("CRsDpofEngine::WriteSpecificSizeFile For each image in the array");
       
   306 	LOG1("CRsDpofEngine::WriteSpecificSizeFile iFileNames->Count(): %d", iFileNames.Count());
       
   307 	
       
   308 	TInt pid( 1 );
       
   309 
       
   310 	
       
   311 	for( TInt i = 0; i < iFileNames.Count(); i++ )
       
   312 		{
       
   313 		LOG1("CRsDpofEngine::WriteSpecificSizeFile i: %d", i);
       
   314 		LOG1("CRsDpofEngine::WriteSpecificSizeFile iNumsOfCopies[i]: %d", iNumsOfCopies[i]);
       
   315 		for( TInt j = 0; j < iNumsOfCopies[i]; j++ )
       
   316 			{
       
   317 			pid += j;			
       
   318 			// write a job section, followed by the PID
       
   319 			LOG1("CRsDpofEngine::WriteSpecificSizeFile write a job section, followed by the PID: %d", pid);
       
   320 			writeStream.WriteL(KDpofJobAndPid);
       
   321 			tempDes.NumFixedWidth( pid, EDecimal, 3 );
       
   322 			writeStream.WriteL(tempDes);
       
   323 			writeStream.WriteL(KCrLf);
       
   324 
       
   325 			LOG1("CRsDpofEngine::WriteSpecificSizeFile iImageLayout: %d", iImageLayout);
       
   326 			switch( iImageLayout )
       
   327 				{
       
   328 				case EOnePerPageSmall:
       
   329 					writeStream.WriteL(KDpofPrtTypSizeSmall);
       
   330 					break;
       
   331 				case EOnePerPageMedium:
       
   332 					writeStream.WriteL(KDpofPrtTypSizeMedium);
       
   333 					break;
       
   334 				case EOnePerPageLarge:
       
   335 					writeStream.WriteL(KDpofPrtTypSizeLarge);
       
   336 					break;
       
   337 				case EOnePerPage4x6:
       
   338 					writeStream.WriteL(KDpofPrtTypSize4x6);
       
   339 					break;
       
   340 				default:
       
   341 					break;
       
   342 				}
       
   343 
       
   344 			LOG1("CRsDpofEngine::WriteSpecificSizeFile file: %S", iFileNames[i]);
       
   345 			writeStream.WriteL(KDpofPrtQtyAndImgFmt);
       
   346 			writeStream.WriteL(KDpofImgSrc);
       
   347 			writeStream.WriteL(KDoubleQuote);
       
   348 			tempDes.Copy(*(iFileNames[i]));
       
   349 			writeStream.WriteL(tempDes);
       
   350 			writeStream.WriteL(KDoubleQuote);
       
   351 			writeStream.WriteL(KCrLf);
       
   352 			}
       
   353 		}
       
   354 
       
   355 
       
   356 	writeStream.CommitL();	
       
   357 	CleanupStack::PopAndDestroy(2); // writeStream, autoPFile
       
   358 	
       
   359 	LOG1("CRsDpofEngine::WriteSpecificSizeFile end with: %d", retVal);
       
   360 	return retVal;
       
   361 	}
       
   362 
       
   363 TInt CRsDpofEngine::WriteMultipleFileL()
       
   364 	{
       
   365 	LOG("CRsDpofEngine::WriteMultipleFile begin");
       
   366 	// Creates the autoprint file for a Multiple image print
       
   367 	TInt retVal=KErrNone;
       
   368 	RFile autoPFile;
       
   369 	TBuf8<256> tempDes;
       
   370 	TTime currTime;
       
   371 	TDateTime currDT;
       
   372 	currTime.HomeTime();
       
   373 	currDT = currTime.DateTime();
       
   374 
       
   375 	// Open the autoprint file
       
   376 	retVal = autoPFile.Replace( iFs, *iAutoPrintFile, EFileWrite );
       
   377 	if( retVal != KErrNone )
       
   378 		{
       
   379 		LOG1("CRsDpofEngine::WriteMultipleFile error opening autoprint file: %d", retVal);
       
   380 		return retVal;	
       
   381 		}
       
   382 	
       
   383 	CleanupClosePushL(autoPFile);	
       
   384 	RFileWriteStream writeStream(autoPFile);
       
   385 	CleanupClosePushL(writeStream);		
       
   386 		
       
   387 	// Write the common header information
       
   388 	LOG("CRsDpofEngine::WriteMultipleFile Write the common header information");
       
   389 	writeStream.WriteL(KDpofHeader);
       
   390 	tempDes.Format(KDateFormat, currDT.Year(), (currDT.Month()+1), (currDT.Day()+1), currDT.Hour(), currDT.Minute(), currDT.Second());
       
   391 	writeStream.WriteL(tempDes);
       
   392 	writeStream.WriteL(KCrLf);
       
   393 
       
   394 	// Start the job section, followed by the PID
       
   395 	LOG("CRsDpofEngine::WriteMultipleFile Start the job section, followed by the PID");
       
   396 	writeStream.WriteL(KDpofJobAndPid);
       
   397 	tempDes.NumFixedWidth(1, EDecimal, 3);
       
   398 	writeStream.WriteL(tempDes);
       
   399 	writeStream.WriteL(KCrLf);
       
   400 
       
   401 	LOG1("CRsDpofEngine::WriteMultipleFile iImageLayout: %d", iImageLayout);
       
   402 	switch (iImageLayout)
       
   403 		{
       
   404 		case ETwoPerPage:
       
   405 			writeStream.WriteL(KDpofPrtTypSize2pp);
       
   406 			break;
       
   407 		case EFourPerPage:
       
   408 			writeStream.WriteL(KDpofPrtTypSize4pp);
       
   409 			break;
       
   410 		case ESixPerPage:
       
   411 			writeStream.WriteL(KDpofPrtTypSize6pp);
       
   412 			break;
       
   413 		case ENinePerPage:
       
   414 			writeStream.WriteL(KDpofPrtTypSize9pp);
       
   415 			break;
       
   416 		case ETwelvePerPage:
       
   417 			writeStream.WriteL(KDpofPrtTypSize12pp);
       
   418 			break;
       
   419 		case ESixteenPerPage:
       
   420 			writeStream.WriteL(KDpofPrtTypSize16pp);
       
   421 			break;
       
   422 		default:
       
   423 			break;
       
   424 		}
       
   425 	writeStream.WriteL(KDpofPrtQtyAndImgFmt);
       
   426 
       
   427 	// For each image in the array
       
   428 	LOG("CRsDpofEngine::WriteMultipleFile For each image in the array");
       
   429 	LOG1("CRsDpofEngine::WriteMultipleFile iFileNames->Count(): %d", iFileNames.Count());
       
   430 	
       
   431 
       
   432 	for( TInt i = 0; i < iFileNames.Count(); i++)
       
   433 		{
       
   434 		LOG1("CRsDpofEngine::WriteMultipleFile i: %d", i);
       
   435 		LOG1("CRsDpofEngine::WriteMultipleFile iNumsOfCopies[i]: %d", iNumsOfCopies[i]);
       
   436 		for( TInt j = 0; j < iNumsOfCopies[i]; j++ )
       
   437 			{					
       
   438 			LOG1("CRsDpofEngine::WriteMultipleFile file: %S", iFileNames[i]);
       
   439 			// add it to the job section
       
   440 			writeStream.WriteL(KDpofImgSrc);
       
   441 			writeStream.WriteL(KDoubleQuote);
       
   442 			tempDes.Copy(*(iFileNames[i]));
       
   443 			writeStream.WriteL(tempDes);
       
   444 			writeStream.WriteL(KDoubleQuote);
       
   445 			writeStream.WriteL(KCrLf);
       
   446 			}
       
   447 		}
       
   448 
       
   449 	
       
   450 	writeStream.CommitL();	
       
   451 	CleanupStack::PopAndDestroy(2); // writeStream, autoPFile
       
   452 
       
   453 	LOG1("CRsDpofEngine::WriteMultipleFile end with: %d", retVal);
       
   454 	return retVal;
       
   455 	}
       
   456 
       
   457 void CRsDpofEngine::DoCancel()
       
   458 	{	
       
   459 	LOG("CRsDpofEngine::DoCancel begin");
       
   460 	iShouldCancel = ETrue;	
       
   461 	LOG("CRsDpofEngine::DoCancel end");
       
   462 	}
       
   463 	
       
   464 void CRsDpofEngine::Stop()
       
   465 	{
       
   466 	LOG("CRsDpofEngine::Stop begin");
       
   467 	iShouldCancel = ETrue;
       
   468 	iFileManager->CancelCopy();	
       
   469 	iFileManager->CancelRmDir();
       
   470 	LOG("CRsDpofEngine::Stop end");
       
   471 	}	
       
   472 
       
   473 void CRsDpofEngine::RunL()
       
   474 	{
       
   475 	LOG1("CRsDpofEngine::RunL called with iStatus.Int(): %d", iStatus.Int());
       
   476 	TInt retVal( KErrNone );
       
   477 			
       
   478 	if( iStatus.Int() != KErrNone )
       
   479 		{		
       
   480 		LOG("CRsDpofEngine::RunL there was an error, so cleanup");
       
   481 		iObs.HandleDpofEngineEventL(iStep, iStatus.Int());
       
   482 		}
       
   483 	else
       
   484 		{
       
   485 		LOG1("CRsDpofEngine::RunL iStep: %d", iStep);
       
   486 		switch( iStep )
       
   487 			{
       
   488 			case ECopyImageFiles:
       
   489 				{
       
   490 				// change those filename array entries so that the filename is now correct
       
   491 				TParsePtrC parsePtr( *(iFileNames[iCurrentPhoneImage->iIndex]) );
       
   492 				iTempFile.Append( parsePtr.NameAndExt() );
       
   493 				delete iFileNames[iCurrentPhoneImage->iIndex];
       
   494 				iFileNames[iCurrentPhoneImage->iIndex] = NULL;
       
   495 				iFileNames[iCurrentPhoneImage->iIndex] = iTempFile.AllocL();
       
   496 				iCurrentPhoneImage->iCopied = ETrue;												
       
   497 
       
   498 				retVal = CopyPhoneImagesToMMC();
       
   499 				LOG1("CRsDpofEngine::RunL CopyPhoneImagesToMMC returned: %d", retVal);
       
   500 				if( retVal == KErrNone )
       
   501 					{
       
   502 					iObs.HandleDpofEngineEventL(iStep, retVal);
       
   503 					}
       
   504 				else if( retVal == KErrCancel )
       
   505 					{
       
   506 					CreateDpofFileL();						
       
   507 					}					
       
   508 				else
       
   509 					{
       
   510 					iObs.HandleDpofEngineEventL( iStep, retVal );	
       
   511 					}					
       
   512 				}
       
   513 				break;				
       
   514 			case EDeleteDirectory:
       
   515 				{
       
   516 				LOG1("CRsDpofEngine::RunL iPhoneImageArray.Count(): %d", iPhoneImageArray.Count());
       
   517 				if( iPhoneImageArray.Count() )
       
   518 					{
       
   519 					TUint32 size( 0 );
       
   520 					RsUtils::DriveFreeSpace( (*iMmcDrive)[0], iFs, size );
       
   521 										
       
   522 					if( SysUtil::MMCSpaceBelowCriticalLevelL( &iFs, iPhoneImgsSize ) )
       
   523         				{
       
   524         				LOG("CRsDpofEngine::PrintL below MMC critical level");
       
   525 						retVal = KErrTooBig;
       
   526         				}
       
   527         			else if( size < ( iPhoneImgsSize + KAutoPrintFileAddon ) )
       
   528 						{
       
   529 						LOG("CRsDpofEngine::PrintL NO room on MMC for phone memory images");
       
   530 						retVal = KErrTooBig;	
       
   531 						}														
       
   532 					else
       
   533 						{
       
   534 						LOG("CRsDpofEngine::PrintL enough room on MMC for phone memory images");
       
   535 						if( !RsUtils::PathExists( *iTempFolder, iFs ) )
       
   536 							{
       
   537 							retVal = iFs.MkDir( *iTempFolder );
       
   538 							LOG1("CRsDpofEngine::PrintL error making temp folder: %d", retVal);
       
   539 							if( !retVal )
       
   540 								{
       
   541 								retVal = CopyPhoneImagesToMMC();
       
   542 								LOG1("CRsDpofEngine::PrintL error copying phone memory images: %d", retVal);
       
   543 								}																																	
       
   544 							}																								
       
   545 						}
       
   546 										
       
   547 					iObs.HandleDpofEngineEventL( ECopyImageFiles, retVal );																											
       
   548 					}
       
   549 				else
       
   550 					{
       
   551 					CreateDpofFileL();
       
   552 					iObs.HandleDpofEngineEventL( EDPOFGenerate, KErrNone );	
       
   553 					}																
       
   554 				}
       
   555 				break;							
       
   556 			default:
       
   557 				break;
       
   558 			}	
       
   559 		}
       
   560 	LOG("CRsDpofEngine::RunL end");
       
   561 	}
       
   562 
       
   563 
       
   564 TInt CRsDpofEngine::CopyPhoneImagesToMMC()
       
   565 	{	
       
   566 	LOG("CRsDpofEngine::CopyPhoneImagesToMMC begin");
       
   567 	TInt retVal = KErrCancel;
       
   568 	iStep = ECopyImageFiles;
       
   569 	if( iShouldCancel )
       
   570 		{
       
   571 		LOG1("CRsDpofEngine::CopyPhoneImagesToMMC iShouldCancel== ETrue, end with: %d", retVal);
       
   572 		return retVal;	
       
   573 		}
       
   574 				
       
   575 	iCurrentPhoneImage = GetNextImageInfoForCopy();
       
   576 
       
   577 	if( iCurrentPhoneImage )
       
   578 		{
       
   579 		// copy phone mem images to MMC card temp dir
       
   580 		TTime theTime;
       
   581 		theTime.HomeTime();
       
   582 		iTempFile.Copy( *iTempFolder );
       
   583 		iTempFile.AppendNumUC( theTime.Int64(), EHex );													
       
   584 		iTempFile.Append( KBackslash );
       
   585 		retVal = iFs.MkDir( iTempFile );
       
   586 		LOG1("CRsDpofEngine::CopyPhoneImagesToMMC error making directory: %d", retVal);		
       
   587 		if( retVal == KErrNone )
       
   588 			{
       
   589 			retVal = iFileManager->Copy( *(iFileNames[iCurrentPhoneImage->iIndex]), iTempFile, iStatus );
       
   590 			LOG1("CRsDpofEngine::CopyPhoneImagesToMMC error copying: %d", retVal);
       
   591 			if( retVal == KErrNone )
       
   592 				{
       
   593 				iStatus = KRequestPending;
       
   594 				if( !IsActive() ) SetActive();
       
   595 				}										
       
   596 			}						
       
   597 		}
       
   598 
       
   599 	LOG1("CRsDpofEngine::CopyPhoneImagesToMMC end with: %d", retVal);
       
   600 	return retVal;
       
   601 	}
       
   602 
       
   603 TRsPhoneImage* CRsDpofEngine::GetNextImageInfoForCopy()
       
   604 	{		
       
   605 	TRsPhoneImage* phoneImage = NULL;	
       
   606 	for( TInt i = 0; i < iPhoneImageArray.Count() && !phoneImage; i++ )	
       
   607 		{
       
   608 		if( iPhoneImageArray[i].iCopied == EFalse )
       
   609 			{
       
   610 			phoneImage = &( iPhoneImageArray[i] );
       
   611 			}
       
   612 		}
       
   613 	return phoneImage;
       
   614 	}
       
   615 
       
   616 
       
   617 TInt CRsDpofEngine::GetPrintPercentage()
       
   618 	{
       
   619 	LOG("CRsDpofEngine::GetPrintPercentage begin");
       
   620 	// compute the percentage of the printing job has been completed
       
   621 	TInt copied( 0 );
       
   622 	TInt count = iPhoneImageArray.Count();	
       
   623 	
       
   624 	// assumes that writing to autoprint file takes 10% of the work
       
   625 	for( TInt i = 0; i < count; i++ )
       
   626 		{
       
   627 		if( iPhoneImageArray[i].iCopied )
       
   628 			copied++;
       
   629 		}
       
   630 
       
   631 	TInt percentage = (copied == count) ? KCopyPercentage : ((copied*100)/count);
       
   632 	LOG1("CRsDpofEngine::GetPrintPercentage end with: %d", percentage);
       
   633 	return percentage;		
       
   634 	}
       
   635 
       
   636 void CRsDpofEngine::CreateDpofFileL()
       
   637 	{
       
   638 	if(iDpofPeriodic) iDpofPeriodic->Cancel();
       
   639 	delete iDpofPeriodic;
       
   640 	iDpofPeriodic = NULL;	
       
   641 	iDpofPeriodic = CPeriodic::NewL(CActive::EPriorityStandard);
       
   642 	iDpofPeriodic->Start(KDpofDelay,KDpofDelay,TCallBack(CreateDpofFileCbL,this));
       
   643 	}
       
   644 
       
   645 void CRsDpofEngine::StartDiscovery(TRequestStatus& aStatus)
       
   646 	{		
       
   647 	LOG("CRsDpofEngine::StartDiscovery begin");
       
   648 	aStatus = KRequestPending;
       
   649 	TRequestStatus *status = &aStatus;	
       
   650 	if( iHasMmc )
       
   651 		{
       
   652 		LOG1("CRsDpofEngine::StartDiscovery end with: %d", EPrinterDiscovered);
       
   653 		User::RequestComplete(status,EPrinterDiscovered);	
       
   654 		}		
       
   655 	else
       
   656 		{
       
   657 		LOG1("CRsDpofEngine::StartDiscovery end with: %d", EDiscoveryDone);
       
   658 		User::RequestComplete(status,EDiscoveryDone);	
       
   659 		}		
       
   660 	}
       
   661 
       
   662 
       
   663 TBool CRsDpofEngine::WasCancelled() const
       
   664 	{
       
   665 	return iShouldCancel;
       
   666 	}
       
   667 
       
   668 TBool CRsDpofEngine::AutoPrintFileExists()
       
   669 	{
       
   670     return ( RsUtils::FileExists( *iAutoPrintFile, iFs ) );
       
   671 	}
       
   672 
       
   673 TInt CRsDpofEngine::CreateDpofFileCbL(TAny *aObj)	
       
   674 	{	
       
   675 	CRsDpofEngine* obj = static_cast<CRsDpofEngine*>(aObj);
       
   676 	if( obj->iDpofPeriodic ) obj->iDpofPeriodic->Cancel();		
       
   677 	obj->DoCreateDpofFileL();
       
   678 	return EFalse;
       
   679 	}
       
   680 
       
   681 void CRsDpofEngine::DoCreateDpofFileL()
       
   682 	{
       
   683 	LOG("CRsDpofEngine::DoCreateDpofFileL begin");	
       
   684 	
       
   685 	TParsePtrC parse( *iAutoPrintFile );
       
   686 
       
   687 	// Delete existing autoprint file
       
   688 	if( RsUtils::FileExists( *iAutoPrintFile, iFs ) )
       
   689 		{
       
   690 		LOG("CRsDpofEngine::DoCreateDpofFileL deleting existing autoprint file...");
       
   691 		User::LeaveIfError( iFs.Delete( *iAutoPrintFile ) );	
       
   692 		}		
       
   693 	else
       
   694 		{
       
   695 		LOG("CRsDpofEngine::DoCreateDpofFileL making sure that the autoprint file folder exists...");
       
   696 		// Make sure that the autoprint file folder exists
       
   697 		if( !RsUtils::PathExists( parse.DriveAndPath(), iFs ) )
       
   698 			User::LeaveIfError( iFs.MkDir( parse.DriveAndPath() ) );					
       
   699 		}
       
   700 
       
   701 	// Ready the array of filenames for DPOF generation
       
   702 	LOG("CRsDpofEngine::DoCreateDpofFileL preparing file names...");
       
   703 	PrepareFilenamesL();
       
   704 
       
   705 	TInt retVal=KErrNone;
       
   706 	// Generate autoprint file
       
   707 	LOG1("CRsDpofEngine::DoCreateDpofFileL printing layout: %d", iImageLayout);
       
   708 	switch( iImageLayout )
       
   709 		{
       
   710 		case EOnePerPageSmall:
       
   711 		case EOnePerPageMedium:
       
   712 		case EOnePerPageLarge:
       
   713 		case EOnePerPage4x6:
       
   714 			retVal = WriteSpecificSizeFileL();
       
   715 			break;
       
   716 		case ETwoPerPage:
       
   717 		case EFourPerPage:
       
   718 		case ESixPerPage:
       
   719 		case ENinePerPage:
       
   720 		case ETwelvePerPage:
       
   721 		case ESixteenPerPage:
       
   722 			retVal = WriteMultipleFileL();
       
   723 			break;
       
   724 		default:
       
   725 			// Should never be here
       
   726 			User::Leave(KErrGeneral);
       
   727 			break;
       
   728 		}
       
   729 
       
   730 	LOG1("CRsDpofEngine::DoCreateDpofFileL end with: %d", retVal);
       
   731 	if (retVal == KErrNone)
       
   732 		{
       
   733 		iObs.HandleDpofEngineEventL(EJobCompleted, KErrNone);
       
   734 		}
       
   735 	else
       
   736 		{		
       
   737 		iObs.HandleDpofEngineEventL(EJobError, retVal);
       
   738 		}	
       
   739 	}
       
   740 
       
   741 TBool CRsDpofEngine::HasMmc() const
       
   742 	{
       
   743 	return iHasMmc;
       
   744 	}
       
   745 
       
   746 
       
   747 void CRsDpofEngine::SetNumsOfCopiesL( const RArray<TInt>& aNumsOfCopies )
       
   748 	{
       
   749 	LOG("CRsDpofEngine::SetNumsOfCopiesL begin");
       
   750 	iNumsOfCopies.Reset();
       
   751 	TInt count = aNumsOfCopies.Count();
       
   752 	for( TInt i = 0; i < count; i++ )
       
   753 		{
       
   754 		iNumsOfCopies.AppendL( aNumsOfCopies[i] );
       
   755 		}
       
   756 	LOG("CRsDpofEngine::SetNumsOfCopiesL end");	
       
   757 	}
       
   758 
       
   759 //  End of File