diff -r 000000000000 -r d11fb78c4374 ImagePrint/ImagePrintEngine/DeviceProtocols/btprotocol/src/cprintjob.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ImagePrint/ImagePrintEngine/DeviceProtocols/btprotocol/src/cprintjob.cpp Thu Dec 17 08:45:53 2009 +0200 @@ -0,0 +1,443 @@ +/* +* Copyright (c) 2004-2007 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Contains the CPrintJob class definition and the PJS enum. +* +*/ + + +#include +#include +#include + +#include "cprintjob.h" +#include "printcapabilitycodes.h" +#include "imageprint.h" +#include "clog.h" +#include "tbtmapper.h" +#include "btprotocolconsts.h" + + + + +// Public functions +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::NewL +// +//-------------------------------------------------------------------------------------------- +CPrintJob* CPrintJob::NewL(CRsBtDevice* aDevice, RArray& aImages, + const TDesC8& aUserName) +{ + CPrintJob* self = new (ELeave) CPrintJob(aDevice); + CleanupStack::PushL(self); + self->ConstructL(aImages, aUserName); + CleanupStack::Pop(); // self + return self; +} + + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::~CPrintJob +// +//-------------------------------------------------------------------------------------------- +CPrintJob::~CPrintJob() +{ + iImages.Reset(); + iImages.Close(); + iDevice = NULL; +} + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::SetJobId +// +//-------------------------------------------------------------------------------------------- +void CPrintJob::SetJobId(const TInt aId) +{ + iJobId = aId; +} + + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::GetJobId +// +//-------------------------------------------------------------------------------------------- +TInt CPrintJob::JobId() +{ + return iJobId; +} + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::GetJobName +// +//-------------------------------------------------------------------------------------------- +void CPrintJob::GetJobName(TDes8& aJobName) +{ + // Return the name of first image + if (iImages.Count() > 0) + { + iImages[0].GetFilePath(aJobName); + } + else + { + aJobName.Append(KNullDesC8()); + } +} + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::ImageCount +// +//-------------------------------------------------------------------------------------------- +TInt CPrintJob::ImageCount() +{ + return iImages.Count(); +} + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::Images +// +//-------------------------------------------------------------------------------------------- +void CPrintJob::Images(RArray& aImages) +{ + for (TInt i=0; i < iImages.Count(); i++) + { + aImages.Append(iImages[i]); + } +} + + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::PrinterId +// +//-------------------------------------------------------------------------------------------- +TInt CPrintJob::PrinterId() +{ + if(Device()) + return Device()->DeviceId(); + + return KErrNotFound; +} + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::GetUserName +// +//-------------------------------------------------------------------------------------------- +void CPrintJob::GetUserName(TPtrC8& aUserName) +{ + aUserName.Set(iUserName); +} + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::GetUserName +// +//-------------------------------------------------------------------------------------------- +CRsBtDevice* CPrintJob::Device() +{ + if(iDevice) + return iDevice; + else + return NULL; +} + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::SetNumsOfCopies +// +//-------------------------------------------------------------------------------------------- +TInt CPrintJob::SetNumsOfCopies( const RArray& aNumsOfCopies) +{ + TInt err = KErrNone; + + for(TInt arrayIx = 0, imgIx = 0; arrayIx < aNumsOfCopies.Count(); ++arrayIx) + { + if(iImages[imgIx].Index() < aNumsOfCopies.Count()) + { + TInt copies = aNumsOfCopies[iImages[imgIx].Index()]; + if(0 < copies) + iImages[imgIx].SetCopies(copies); + ++imgIx; + } + else + err = KErrCorrupt; + } + return err; +} + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::GetPrintFileL +// +//-------------------------------------------------------------------------------------------- +void CPrintJob::GetPrintFileL(TDes8& aPrintFile) +{ + LOG("[CPrintJob::GetPrintFileL]\t begin"); + + TInt layout; + TInt paper; + TInt quality; + + GetPrintSetting(EPrintCapabLayout, layout); + GetPrintSetting(EPrintCapabPaperSize, paper); + GetPrintSetting(EPrintCapabQuality, quality); + + TFileName tmpFile; + tmpFile.Copy(aPrintFile); + + CXhtmlFileComposer* fileComposer = CXhtmlFileComposer::NewLC(KNullDesC()); + + LOG("[CPrintJob::GetPrintFileL]\t create file"); + fileComposer->CreateXhtmlFileL( iImages, layout, paper, quality, tmpFile, iSheets ); + + CleanupStack::PopAndDestroy(fileComposer); + aPrintFile.Copy(tmpFile); + + LOG("[CPrintJob::GetPrintFileL]\t file created"); +} + + +//-------------------------------------------------------------------------------------------- +// +// CPrintJob::Sheets +// +//-------------------------------------------------------------------------------------------- +TInt CPrintJob::Sheets() +{ + if(0 == iSheets) + { + TInt layout; + TInt layoutNbr = 1; + TInt imageNbr = 0; + + // We don't care about return value here: if GetPrintSetting + // fails, we can anyway tell there will be at least an image/page + GetPrintSetting(EPrintCapabLayout, layout); + + switch( layout ) + { + case EPrintCapabLayout1Up: + case EPrintCapabLayout1UpBorderless: + case EPrintCapabLayout1UpBorder: + layoutNbr = 1; + break; + case EPrintCapabLayout2Up: + layoutNbr = 2; + break; + case EPrintCapabLayout4Up: + layoutNbr = 4; + break; + case EPrintCapabLayout6Up: + layoutNbr = 6; + break; + case EPrintCapabLayout9Up: + layoutNbr = 9; + break; + case EPrintCapabLayout12Up: + layoutNbr = 12; + break; + case EPrintCapabLayout16Up: + layoutNbr = 16; + break; + default: + break; + } + + for (TInt i = 0; i& aImages, const TDesC8& aUserName) +{ + if (aImages.Count() < 1) + { + User::Leave(KErrArgument); + } + + _LIT(KObex, "obex:"); + _LIT(KMmc, "\\mmc"); + _LIT(KLocal, "\\media"); + _LIT(KSlash, "/"); + _LIT(KBackSlash, "\\"); + + // Initialize iImages array + for (TInt i=0 ; iCapabilityCount(); ++i) + { + TPrintCapability c; + if(KErrNone == Device()->GetCapability(aCapabilityID, c) ) + { + aValue = c.iDefaultValue; + LOG2("[CPrintJob::GetPrintSetting]\t %d = %d", aCapabilityID, aValue); + return KErrNone; + } + } + } + + aValue = KErrNotFound; + + LOG("[CPrintJob::GetPrintSetting]\t out: KErrInvalidData"); + return KErrInvalidData; +} + +//-------------------------------------------------------------------------------------------- +// CPrintJob::SetPrintSetting +//-------------------------------------------------------------------------------------------- +TInt CPrintJob::SetPrintSetting(TInt aCapabilityID, TInt aValue) +{ + LOG2("[CPrintJob::SetPrintSetting]\t %d = %d", aCapabilityID, aValue); + + if(Device()) + return Device()->SetDefaultCapability(aCapabilityID, aValue); + + LOG("[CPrintJob::GetPrintSetting]\t out: KErrInvalidData"); + return KErrInvalidSequence; +} + +// End of File