DirectPrint/DirectPrintApp/engine/src/directprintengine.cpp
changeset 19 2275db202402
parent 11 613a5ff70823
equal deleted inserted replaced
2:acc370d7f2f6 19:2275db202402
       
     1 /*
       
     2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * {Description of the file}
       
    16 *
       
    17 */
       
    18 
       
    19 #include <pdrport.h>				// CFilePrinterPort
       
    20 #include <TXTETEXT.H>				// CEditableText
       
    21 #include <TXTRICH.H>				// CRichText
       
    22 #include <FLDBLTIN.H>				// CPageNumField
       
    23 #include <flddef.h>					// KPageNumberFieldUid, KNumPagesFieldUid
       
    24 #include <stringloader.h>			// StringLoader
       
    25 #include <xmlengdocument.h>			// RXmlEngDocument
       
    26 #include <xmlengelement.h>			// TXmlEngElement
       
    27 #include <xmlengattr.h>				// TXmlEngAttr
       
    28 #include <xmlengnodelist.h>			// RXmlEngNodeList
       
    29 #include <bautils.h>				// BaflUtils
       
    30 #include <eikenv.h>					// CEikonEnv
       
    31 
       
    32 #include "clog.h"
       
    33 #include <directprintapp.rsg>
       
    34 #include "directprintengine.h"
       
    35 #include "directprintband.h"
       
    36 #include "directprintengineobserver.h"
       
    37 #include "directprintmodel.h"
       
    38 #include "directprintbanduid.h"
       
    39 
       
    40 //! Default Page spec in Twips
       
    41 #define KDefaultPageSpecInTwips TPageSpec(TPageSpec::EPortrait,TSize(11906,16838))
       
    42 
       
    43 CDirectPrintEngine::CDirectPrintEngine(CDirectPrintModel& aModel)
       
    44 	: iModel(aModel)
       
    45 	{
       
    46 	}
       
    47 
       
    48 CDirectPrintEngine::~CDirectPrintEngine()
       
    49 	{
       
    50 	if (iProgressDialog)
       
    51 		{
       
    52 		TRAP_IGNORE(iProgressDialog->ProcessFinishedL());
       
    53 		delete iProgressDialog;
       
    54 		iProgressDialog = NULL;
       
    55 		}
       
    56 
       
    57 	if (iPrintBand)
       
    58 		{
       
    59 		delete iPrintBand;
       
    60 		iPrintBand = NULL;
       
    61 		}
       
    62 
       
    63 	iPrintSetup->FreeModelList();
       
    64 	delete iPrintSetup;
       
    65 	delete iProgressMessage;
       
    66 	iFs.Close();
       
    67 	}
       
    68 
       
    69 CDirectPrintEngine* CDirectPrintEngine::NewL(CDirectPrintModel& aModel)
       
    70 	{
       
    71 	CDirectPrintEngine* self = CDirectPrintEngine::NewLC(aModel);
       
    72 	CleanupStack::Pop(self);
       
    73 	return self;
       
    74 	}
       
    75 
       
    76 CDirectPrintEngine* CDirectPrintEngine::NewLC(CDirectPrintModel& aModel)
       
    77 	{
       
    78 	CDirectPrintEngine* self = new(ELeave) CDirectPrintEngine(aModel);
       
    79 	CleanupStack::PushL(self);
       
    80 	self->ConstructL();
       
    81 	return self;
       
    82 	}
       
    83 
       
    84 void CDirectPrintEngine::ConstructL()
       
    85 	{
       
    86 	LOG("CDirectPrintEngine::ConstructL BEGIN");
       
    87 	iFs.Connect();
       
    88 
       
    89 	iPrintSetup = CPrintSetup::NewL();
       
    90 	iPrintSetup->AddPrinterDriverDirL(KDefaultPrinterDriverPath);
       
    91 	iModelList = iPrintSetup->ModelNameListL(iFs);
       
    92 
       
    93 #ifdef _DEBUG
       
    94 	LOG1("ModelCount=[%d]", ModelCount());
       
    95 	for (TInt i=0; i < ModelCount(); i++)
       
    96 		{
       
    97 		TPrinterModelEntry entry = (*iModelList)[i];
       
    98 		RDebug::Print(_L("[%d][%S][%d] "), i, &(entry.iModelName), entry.iRequiresPrinterPort);
       
    99 		LOG1("ModelName=[%S]", &(entry.iModelName));
       
   100 		}
       
   101 #endif
       
   102 	// read progress message
       
   103 	iProgressMessage = StringLoader::LoadL( R_DIRECTPRINT_MSG_PRINTING_PROGRESS );
       
   104 
       
   105 	LOG("CDirectPrintEngine::ConstructL END");
       
   106 	}
       
   107 
       
   108 void CDirectPrintEngine::SetObserver(MDirectPrintEngineObserver* aObserver)
       
   109 	{
       
   110 	iObserver = aObserver;
       
   111 	}
       
   112 
       
   113 /**
       
   114   Override of base class virtual.
       
   115   Notifies that a print or print preview operation is about to begin.
       
   116  */
       
   117 void CDirectPrintEngine::NotifyPrintStarted(TPrintParameters /*aPrintParams*/)
       
   118 	{
       
   119 	iPageCounter = 0;
       
   120 	TRAPD(err, StartPrintProgressNoteL());
       
   121 	iLastError = err;
       
   122 	}
       
   123 
       
   124 /**
       
   125   Override of base class virtual.\n
       
   126   Notifies that a band is about to be printed used to display print progress information,
       
   127   including the current page number.\n
       
   128   It is called immediately before each band is printed.\n
       
   129  */
       
   130 void CDirectPrintEngine::NotifyBandPrinted(TInt /*aPercent*/, TInt aCurrentPageNum, TInt /*aCurrentCopyNum*/)
       
   131 	{
       
   132 	if (iPageCounter==0)
       
   133 		{
       
   134 		// start print
       
   135 		}
       
   136 	if (iPageCounter<aCurrentPageNum)
       
   137 		{
       
   138 		// next page
       
   139 		iPageCounter = aCurrentPageNum;
       
   140 		TRAPD(err, UpdatePrintProgressNoteL(iPageCounter));
       
   141 		iLastError = err;
       
   142 		}
       
   143 	}
       
   144 
       
   145 /**
       
   146   Override of base class virtual.\n
       
   147   Notifies that the print or print preview operation has completed.\n
       
   148   used to display information about how the operation completed,
       
   149   for example any errors that occurred.\n
       
   150  */
       
   151 void CDirectPrintEngine::NotifyPrintEnded(TInt aErr)
       
   152 	{
       
   153 	CActiveScheduler::Stop();
       
   154 	TInt err = KErrNone;
       
   155 
       
   156 	if (aErr == KErrNone)
       
   157 		{
       
   158 		if (iObserver)
       
   159 			{
       
   160 			TRAP(err, iObserver->HandlePrintEventL(MDirectPrintEngineObserver::EDirectPrintEngineEventFinishCreatePrintData, 0, KNullDesC));
       
   161 			}
       
   162 		}
       
   163 	else
       
   164 		{
       
   165 		switch (aErr)
       
   166 			{
       
   167 		case KErrCancel:
       
   168 			if (iObserver)
       
   169 				{
       
   170 				TRAP(err, iObserver->HandlePrintEventL(MDirectPrintEngineObserver::EDirectPrintEngineEventCancelCreatePrintData, aErr, KNullDesC));
       
   171 				}
       
   172 			break;
       
   173 		default:
       
   174 			if (iObserver)
       
   175 				{
       
   176 				TRAP(err, iObserver->HandlePrintEventL(MDirectPrintEngineObserver::EDirectPrintEngineEventErrorCreatePrintData, aErr, KNullDesC));
       
   177 				}
       
   178 			break;
       
   179 			}
       
   180 		}
       
   181 
       
   182 	TRAP(err, EndPrintProgressNoteL());
       
   183 	}
       
   184 
       
   185 /**
       
   186   Override of base class virtual.\n
       
   187   Returns the number of pages in the current document.\n
       
   188   @return - TInt (Number of pages).\n
       
   189  */
       
   190 TInt CDirectPrintEngine::UpdateFieldNumPages()const
       
   191 	{
       
   192 	return iMaxPageNum;
       
   193 	}
       
   194 
       
   195 
       
   196 void CDirectPrintEngine::PrintL()
       
   197 	{
       
   198 	
       
   199 	// set the total page
       
   200 	iMaxPageNum = 1;
       
   201 	iPrintSetup->Header()->SetNumPagesInfo(*this);
       
   202 
       
   203 	TInt modelNum = iModelList->UidToNum(ModelUid(iModelIndex));
       
   204 	iPrintSetup->CreatePrinterDeviceL(modelNum);
       
   205 
       
   206 	// create a port if necessary
       
   207 	CPrinterPort* port=NULL;
       
   208 	if ((*iModelList)[modelNum].iRequiresPrinterPort)
       
   209 		{
       
   210 #ifdef __WINSCW__
       
   211 		port = CFilePrinterPort::NewL(_L("c:\\fpr.pcl"));
       
   212 #else
       
   213 //		port = CFilePrinterPort::NewL(_L("e:\\fpr.pcl"));
       
   214 		port = CFilePrinterPort::NewL(_L("c:\\fpr.pcl"));
       
   215 #endif
       
   216 		}
       
   217 
       
   218 	iPrintSetup->PrinterDevice()->SelectPageSpecInTwips(KDefaultPageSpecInTwips);
       
   219 	iPrintSetup->iPageMarginsInTwips.iHeaderOffset = 720;
       
   220 	iPrintSetup->iPageMarginsInTwips.iFooterOffset = 0;
       
   221 	iPrintSetup->iPageMarginsInTwips.iMargins.iLeft = 1440; // 1 inch
       
   222 	iPrintSetup->iPageMarginsInTwips.iMargins.iRight = 1440;
       
   223 	iPrintSetup->iPageMarginsInTwips.iMargins.iTop = 1440;
       
   224 	iPrintSetup->iPageMarginsInTwips.iMargins.iBottom = 1440;
       
   225 
       
   226 	if (iObserver)
       
   227 		{
       
   228 		iObserver->HandlePrintEventL(MDirectPrintEngineObserver::EDirectPrintEngineEventStartCreatePrintData, 0, KNullDesC);
       
   229 		}
       
   230 	
       
   231 
       
   232 	TRAPD(err, DoPrintL(port));
       
   233 	if (err == KErrNone)
       
   234 		{
       
   235 		CActiveScheduler::Start(); // stopped by killing it - subtle...
       
   236 		}
       
   237 	else
       
   238 		{
       
   239 		if (iObserver)
       
   240 			{
       
   241 			iObserver->HandlePrintEventL(MDirectPrintEngineObserver::EDirectPrintEngineEventErrorCreatePrintData, err, KNullDesC);
       
   242 			}
       
   243 		}
       
   244 
       
   245 //	if (iPrintBand)
       
   246 //		{
       
   247 //		delete iPrintBand;
       
   248 //		iPrintBand = NULL;
       
   249 //		}
       
   250 	}
       
   251 
       
   252 void CDirectPrintEngine::DoPrintL(CPrinterPort* aPort)
       
   253 	{
       
   254 	// create a header
       
   255 	iPrintSetup->Header()->CreateTextL();
       
   256 	TBuf<40> buf(_L("This is the header on page  out of "));
       
   257 	buf.Append(CEditableText::EParagraphDelimiter);
       
   258 	iPrintSetup->Header()->Text()->InsertL(0,buf);
       
   259 	CTextField* pNumberfield=iPrintSetup->Header()->Text()->NewTextFieldL(KPageNumberFieldUid);
       
   260 	iPrintSetup->Header()->Text()->InsertFieldL(27,pNumberfield,KPageNumberFieldUid);  
       
   261 	CNumPagesField* numPagesField=(CNumPagesField*)iPrintSetup->Header()->Text()->NewTextFieldL(KNumPagesFieldUid);
       
   262 	iPrintSetup->Header()->Text()->InsertFieldL(35,numPagesField,KNumPagesFieldUid);  
       
   263 	iPrintSetup->Header()->Text()->UpdateFieldL(27);
       
   264 	iPrintSetup->Header()->Text()->UpdateFieldL(35);
       
   265 	iPrintSetup->Header()->SetFirstPageToPrintTo(1); // no header on first 3 pages
       
   266 
       
   267 	iPrintSetup->Footer()->CreateTextL();
       
   268 	TBuf<40> buf2(_L("This is the footer on page "));
       
   269 	buf2.Append(CEditableText::EParagraphDelimiter);
       
   270 	iPrintSetup->Footer()->Text()->InsertL(0,buf2);
       
   271 	CTextField* pNumberfield2=iPrintSetup->Footer()->Text()->NewTextFieldL(KPageNumberFieldUid);
       
   272 	iPrintSetup->Footer()->Text()->InsertFieldL(27,pNumberfield2,KPageNumberFieldUid);	
       
   273 	iPrintSetup->Footer()->Text()->UpdateFieldL(27);
       
   274 
       
   275 	// start print to file
       
   276 	iPrintSetup->iNumOfFirstPage = 1;
       
   277 	TPrintParameters params;
       
   278 	params.iFirstPage = 1; // don't print the first page at all, ie print page no's 3-6
       
   279 	params.iLastPage = 1;
       
   280 	params.iNumCopies = 1;
       
   281 	TPageSpec spec;
       
   282 	spec.iPortraitPageSize = KA4PaperSizeInTwips;
       
   283 	spec.iOrientation = TPageSpec::EPortrait;
       
   284 	iPrintSetup->PrinterDevice()->SelectPageSpecInTwips(spec);
       
   285 
       
   286 	//===========================
       
   287 	// start printing
       
   288 	//===========================
       
   289 	iPrintSetup->StartPrintL(params, *(PageRegionPrinter()), aPort, this);
       
   290 
       
   291 	}
       
   292 
       
   293 
       
   294 TInt CDirectPrintEngine::ModelCount()
       
   295 	{
       
   296 	return iModelList->ModelCount();
       
   297 	}
       
   298 
       
   299 void CDirectPrintEngine::ModelName(TInt aIndex, TDes& aDes)
       
   300 	{
       
   301 	TPtrC name((*iModelList)[aIndex].iModelName);
       
   302 	if (name.Length() <= aDes.MaxLength())
       
   303 		{
       
   304 		aDes.Copy(name);
       
   305 		}
       
   306 	}
       
   307 
       
   308 TUid CDirectPrintEngine::ModelUid(TInt aIndex)
       
   309 	{
       
   310 	return (*iModelList)[aIndex].iUid;
       
   311 	}
       
   312 
       
   313 void CDirectPrintEngine::SetUseModel(TInt aIndex)
       
   314 	{
       
   315 	iModelIndex = aIndex;
       
   316 	}
       
   317 
       
   318 void CDirectPrintEngine::StartPrintProgressNoteL()
       
   319 	{
       
   320 	// Delete possible previous CAknProgressDialog.
       
   321 	delete iProgressDialog;
       
   322 	iProgressDialog = NULL;
       
   323 
       
   324 	// Create new CAknProgressDialog.
       
   325 	iProgressDialog = new ( ELeave ) CAknProgressDialog( reinterpret_cast
       
   326 														 <CEikDialog**> 
       
   327 														 ( &iProgressDialog ) );
       
   328 	
       
   329 	iProgressDialog->SetCallback( this );
       
   330 	iProgressDialog->PrepareLC( R_DIRECTPRINT_PRINT_PROGRESS_NOTE );
       
   331 	iProgressInfo = iProgressDialog->GetProgressInfoL();
       
   332 	iProgressInfo->SetFinalValue( iMaxPageNum );
       
   333 
       
   334 	TBuf<32> msg;
       
   335 	msg.AppendFormat(*iProgressMessage, iPageCounter, iMaxPageNum);
       
   336 	iProgressDialog->SetTextL(msg);
       
   337 	iProgressDialog->RunLD();
       
   338 	}
       
   339 
       
   340 void CDirectPrintEngine::EndPrintProgressNoteL()
       
   341 	{
       
   342 	if (iProgressDialog)
       
   343 		{
       
   344 		iProgressDialog->ProcessFinishedL();
       
   345 		delete iProgressDialog;
       
   346 		iProgressDialog = NULL;
       
   347 		}
       
   348 	}
       
   349 
       
   350 void CDirectPrintEngine::UpdatePrintProgressNoteL(TInt aPage)
       
   351 	{
       
   352 	if (iProgressInfo)
       
   353 		{
       
   354 		TBuf<32> msg;
       
   355 		msg.AppendFormat(*iProgressMessage, aPage, iMaxPageNum);
       
   356 		iProgressDialog->SetTextL(msg);
       
   357 		iProgressInfo->SetAndDraw(aPage);
       
   358 		}
       
   359 	}
       
   360 
       
   361 void CDirectPrintEngine::DialogDismissedL( TInt /*aButtonId*/ )
       
   362 	{
       
   363 	if (iPrintSetup)
       
   364 		{
       
   365 		iPrintSetup->EndPrint();
       
   366 		}
       
   367 	}
       
   368 
       
   369 void CDirectPrintEngine::StartPrintPreviewL()
       
   370 	{
       
   371 	// Clear previous object
       
   372 	EndPrintPreview();
       
   373 
       
   374 	// set the total page
       
   375 	iMaxPageNum = 1;
       
   376 	iPrintSetup->Header()->SetNumPagesInfo(*this);
       
   377 
       
   378 	TInt modelNum = iModelList->UidToNum(ModelUid(iModelIndex));
       
   379 	iPrintSetup->CreatePrinterDeviceL(modelNum);
       
   380 
       
   381 	// create a port if necessary
       
   382 	//CPrinterPort* port=NULL;
       
   383 	//if ((*iModelList)[modelNum].iRequiresPrinterPort)
       
   384 	//	{
       
   385 	//	port = CFilePrinterPort::NewL(_L("e:\\fpr.pcl"));
       
   386 	//	}
       
   387 
       
   388 	iPrintSetup->PrinterDevice()->SelectPageSpecInTwips(KDefaultPageSpecInTwips);
       
   389 	iPrintSetup->iPageMarginsInTwips.iHeaderOffset = 720;
       
   390 	iPrintSetup->iPageMarginsInTwips.iFooterOffset = 0;
       
   391 	iPrintSetup->iPageMarginsInTwips.iMargins.iLeft = 1440; // 1 inch
       
   392 	iPrintSetup->iPageMarginsInTwips.iMargins.iRight = 1440;
       
   393 	iPrintSetup->iPageMarginsInTwips.iMargins.iTop = 1440;
       
   394 	iPrintSetup->iPageMarginsInTwips.iMargins.iBottom = 1440;
       
   395 	}
       
   396 
       
   397 void CDirectPrintEngine::EndPrintPreview()
       
   398 	{
       
   399 	}
       
   400 
       
   401 void CDirectPrintEngine::SetParamL(RXmlEngDocument* aParam)
       
   402 	{
       
   403 	LOG("CDirectPrintEngine::SetParamL BEGIN");
       
   404 
       
   405 	iParam = aParam;
       
   406 	if ( iPrintBand )
       
   407 		{
       
   408 		delete iPrintBand;
       
   409 		iPrintBand = NULL;
       
   410 		}
       
   411 
       
   412 	_LIT8(KElementRecogMode, "RecognizeMode");
       
   413 	_LIT8(KElementRecogModeAttr, "mode");
       
   414 	_LIT8(KElementRecogModeValueFile, "PrintRecognizeModeFile");
       
   415 	_LIT8(KElementRecogModeValuePlugin, "PrintRecognizeModePlugin");
       
   416 	_LIT8(KElementFile, "PrintFile");
       
   417 	_LIT8(KElementFileAttr, "file");
       
   418 	_LIT8(KElementPluginUid, "PluginUid");
       
   419 	_LIT8(KElementPluginUidAttr, "uid");
       
   420 
       
   421 	TXmlEngElement element = iParam->DocumentElement().FirstChild().AsElement();
       
   422 	HBufC* filename = NULL;
       
   423 	TUint uidValue = 0;
       
   424 
       
   425 	enum {
       
   426 		EParamModeFile	 = 0x0001,
       
   427 		EParamModePlugin = 0x0002,
       
   428 		EParamFileExist   = 0x0008,
       
   429 		EParamPluginExist = 0x0010
       
   430 	};
       
   431 	TUint paramFlag = 0;
       
   432 
       
   433 	while (element.NotNull())
       
   434 		{
       
   435 		if (element.Name().CompareF(KElementRecogMode()) == 0)
       
   436 			{
       
   437 			TXmlEngAttr attr = element.AttributeNodeL(KElementRecogModeAttr,KNullDesC8);
       
   438 			if(attr.Value().CompareF(KElementRecogModeValueFile) == 0)
       
   439 				{
       
   440 				paramFlag |= EParamModeFile;
       
   441 				LOG("Param:Mode=File");
       
   442 				}
       
   443 			else if(attr.Value().CompareF(KElementRecogModeValuePlugin) == 0)
       
   444 				{
       
   445 				paramFlag |= EParamModePlugin;
       
   446 				LOG("Param:Mode=Plugin");
       
   447 				}
       
   448 			else
       
   449 				{
       
   450 				LOG("[Error] Param:Mode=Not set");
       
   451 				break;
       
   452 				}
       
   453 			}
       
   454 		else if (element.Name().CompareF(KElementFile()) == 0)
       
   455 			{
       
   456 			TXmlEngAttr attr = element.AttributeNodeL(KElementFileAttr,KNullDesC8);
       
   457 			filename = HBufC::NewLC(attr.Value().Length());
       
   458 			TPtr ptr(filename->Des());
       
   459 			ptr.Copy(attr.Value());
       
   460 			if (ptr.Length() > 0)
       
   461 				{
       
   462 				LOG1("Param:FileName UID=[%S]", &ptr);
       
   463 				if (BaflUtils::FileExists(CEikonEnv::Static()->FsSession(), ptr))
       
   464 					{
       
   465 					paramFlag |= EParamFileExist;
       
   466 					}
       
   467 				}
       
   468 			if (!(paramFlag & EParamFileExist))
       
   469 				{
       
   470 				LOG("[Error] File not exist");
       
   471 				}
       
   472 			}
       
   473 		else if (element.Name().CompareF(KElementPluginUid()) == 0)
       
   474 			{
       
   475 			TXmlEngAttr attr = element.AttributeNodeL(KElementPluginUidAttr,KNullDesC8);
       
   476 			//HBufC8* bufUid = HBufC8::NewLC(attr.Value().Length());
       
   477 			//TPtr8 ptr(bufUid->Des());
       
   478 			HBufC* bufUid = HBufC::NewLC(attr.Value().Length());
       
   479 			TPtr ptr(bufUid->Des());
       
   480 			ptr.Copy(attr.Value());
       
   481 			//_LIT8(KHeadOfHexString, "0x");
       
   482 			_LIT(KHeadOfHexString, "0x");
       
   483 			const TInt KUidStingLength = 8;
       
   484 			if (ptr.Left(KHeadOfHexString().Length()).CompareF(KHeadOfHexString()) == 0)
       
   485 				{
       
   486 				ptr.Delete(0, KHeadOfHexString().Length());
       
   487 				}
       
   488 			if (ptr.Length() == KUidStingLength)
       
   489 				{
       
   490 				//TBuf<8> bufUid;
       
   491 				//bufUid.Copy(ptr);
       
   492 				//TLex lex(bufUid);
       
   493 				TLex lex(ptr);
       
   494 				if (lex.Val(uidValue,EHex) == KErrNone)
       
   495 					{
       
   496 					LOG1("Param:Plugin UID=[0x%X]", uidValue);
       
   497 					paramFlag |= EParamPluginExist;
       
   498 					}
       
   499 				else
       
   500 					{
       
   501 					LOG("[Error] Convert from HEX string to int");
       
   502 					}
       
   503 				}
       
   504 			if (!(paramFlag & EParamPluginExist))
       
   505 				{
       
   506 				LOG("[Error] File not exist");
       
   507 		  		}
       
   508 			CleanupStack::PopAndDestroy(bufUid); //bufUid
       
   509 			}
       
   510 
       
   511 		if (paramFlag == (EParamFileExist|EParamModeFile)
       
   512 		 || paramFlag == (EParamPluginExist|EParamModePlugin))
       
   513 			{
       
   514 			break;
       
   515 			}
       
   516 		element = element.NextSibling().AsElement();
       
   517 		}
       
   518 
       
   519 	if (paramFlag == (EParamFileExist|EParamModeFile)
       
   520 	 && filename)
       
   521 		{
       
   522 		TPtrC ptr(filename->Des());
       
   523 		SearchPluginFromFilenameL(ptr);
       
   524 		}
       
   525 	if (paramFlag == (EParamPluginExist|EParamModePlugin)
       
   526 	 && uidValue)
       
   527 		{
       
   528 		TUid uid = TUid::Uid(uidValue);
       
   529 		LoadPluginFromUidL(uid);
       
   530 		}
       
   531 
       
   532 	if (filename)
       
   533 		{
       
   534 		CleanupStack::PopAndDestroy(filename); //filename
       
   535 		}
       
   536 
       
   537 	if ( !iPrintBand )
       
   538 		{
       
   539 		// error xml parameter
       
   540 		User::Leave(KErrArgument);
       
   541 		}
       
   542 
       
   543 	LOG("CDirectPrintEngine::SetParamL END");
       
   544 	}
       
   545 
       
   546 void CDirectPrintEngine::SearchPluginFromFilenameL(const TDesC& aFileName)
       
   547 	{
       
   548 	LOG("CDirectPrintEngine::SearchPluginFromFilenameL START");
       
   549 	RImplInfoPtrArray infoArray;
       
   550 	TUid interface = TUid::Uid(KDirectPrintBandInterfaceUid);
       
   551 	REComSession::ListImplementationsL( interface, infoArray );
       
   552 	CleanupClosePushL( infoArray );
       
   553 	LOG1("CDirectPrintEngine::SearchPluginFromFilenameL infoArray.Count(): %d", infoArray.Count());
       
   554 
       
   555 	TParsePtrC parse(aFileName);
       
   556 
       
   557 	TPtrC8 dataType;
       
   558 	TPtrC16 dispName;
       
   559 	TPtrC8 opaqueData;
       
   560 	HBufC* dataTypeBuf = NULL;
       
   561 	TBool bFound = EFalse;
       
   562 	TInt findLen;
       
   563 	const TChar KDataTypeSeparator = '|';
       
   564 
       
   565 	for( TInt i = 0; i < infoArray.Count(); i++ )
       
   566 		{
       
   567 		LOG1("[InfoArray] i=%d", i);
       
   568 		CImplementationInformation* info = infoArray[i];
       
   569 		dataType.Set( info->DataType() );
       
   570 		dispName.Set( info->DisplayName() );
       
   571 		opaqueData.Set( info->OpaqueData() );
       
   572 
       
   573 		dataTypeBuf = HBufC::NewLC( dataType.Length() );
       
   574 		TPtr dataTypePtr(dataTypeBuf->Des());
       
   575 		dataTypePtr.Copy( dataType );
       
   576 
       
   577 		LOG1("[DataType]=[%S]", &dataTypePtr);
       
   578 		FOREVER
       
   579 			{
       
   580 			findLen = dataTypePtr.Locate( KDataTypeSeparator );
       
   581 			if (findLen < 0)
       
   582 				{
       
   583 				// the separator is not found
       
   584 				if (dataTypePtr.Length() > 0)
       
   585 					{
       
   586 					findLen = dataTypePtr.Length();
       
   587 					}
       
   588 				else
       
   589 					{
       
   590 					break;
       
   591 					}
       
   592 				}
       
   593 //			LOG1("[Compare]=[%S]", &(dataTypePtr.Left( findLen )));
       
   594 //			LOG1("[Ext]=[%S]", &(parse.Ext()));
       
   595 //			LOG1("[Comp]=[%S]", &(dataTypePtr.Left( findLen )));
       
   596 			if ( parse.Ext().CompareF( dataTypePtr.Left( findLen ) ) == 0 )
       
   597 				{
       
   598 				bFound = ETrue;
       
   599 				break;
       
   600 				}
       
   601 			dataTypePtr.Delete( 0, findLen+1 );
       
   602 			}
       
   603 
       
   604 		CleanupStack::PopAndDestroy(dataTypeBuf); // dataTypeBuf
       
   605 		
       
   606 		if ( bFound )
       
   607 			{
       
   608 			LOG("Match!!!");
       
   609 			LoadPluginFromUidL(info->ImplementationUid());
       
   610 			break;
       
   611 			}
       
   612 		}
       
   613 
       
   614 	infoArray.ResetAndDestroy();
       
   615 	CleanupStack::PopAndDestroy(&infoArray); // infoArray
       
   616 
       
   617 	LOG("CDirectPrintEngine::SearchPluginFromFilenameL End");
       
   618 	}
       
   619 
       
   620 void CDirectPrintEngine::LoadPluginFromUidL(const TUid aUid)
       
   621 	{
       
   622 	LOG1("CDirectPrintEngine::LoadPluginFromUidL(0x%X) Start", aUid.iUid);
       
   623 
       
   624 	CDirectPrintBand* band = NULL;
       
   625 	band = CDirectPrintBand::NewL(aUid);
       
   626 	TCleanupItem clItem( CleanupBand, band );
       
   627 	CleanupStack::PushL( clItem );
       
   628 	band->InitPrintBandL( iPrintSetup,
       
   629 						  iParam,
       
   630 						  KNullDesC );
       
   631 	CleanupStack::Pop(); // band
       
   632 	iPrintBand = band;
       
   633 
       
   634 	LOG("CDirectPrintEngine::LoadPluginFromUidL End");
       
   635 	}
       
   636 
       
   637 void CDirectPrintEngine::CleanupBand( TAny* aData )
       
   638 	{
       
   639 	LOG("[CDirectPrintEngine::CleanupBand]\t Begin");
       
   640 
       
   641 	CDirectPrintBand* band = (CDirectPrintBand*)aData;
       
   642 	delete band;
       
   643 
       
   644 	LOG("[CDirectPrintEngine::CleanupBand]\t End");
       
   645 	}
       
   646 
       
   647 
       
   648 
       
   649 // End of file