sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "GDIPANIC.h" sl@0: sl@0: _LIT(KPdrExtension,"*.PDR"); // must be capitalized sl@0: _LIT(KPdlExtension,".PDL"); // must be capitalized sl@0: _LIT(KUdlExtension,".UDL"); // must be capitalized sl@0: _LIT(KRscExtension,".RSC"); sl@0: _LIT(KGdiPrintPanic,"GDI - PRINT"); sl@0: sl@0: _LIT(KGDIPanicDesc1, "GDI Pdr internal Panic %S, in file %S @ line %i"); sl@0: _LIT(KGDIPanicDesc2, "Assert condition = \"%S\""); sl@0: sl@0: enum TPdrStorePanic sl@0: { sl@0: EPdrModelIndexOutOfRange, sl@0: EPdrModelUidNotFound, sl@0: EPdrDirectoryIndexOutOfRange, sl@0: EPdrFileIndexOutOfRange, sl@0: EPdrPrinterDeviceExists, sl@0: EPdrPrinterDeviceDoesNotExist, sl@0: }; sl@0: sl@0: void Panic(TPdrStorePanic aPanic) sl@0: { sl@0: User::Panic(KGdiPrintPanic,aPanic); sl@0: } sl@0: sl@0: void PanicWithCondAndInfo(TPdrStorePanic aError, const TDesC& aCondition, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine) sl@0: { sl@0: TBuf<256> buf; sl@0: buf.Format(KGDIPanicDesc1, &aPanicName, &aFileName, aLine); sl@0: RDebug::Print(buf); sl@0: sl@0: buf.Format(KGDIPanicDesc2, &aCondition); sl@0: RDebug::Print(buf); sl@0: Panic(aError); sl@0: } sl@0: sl@0: // sl@0: // TPrinterModelEntry sl@0: // sl@0: sl@0: sl@0: EXPORT_C void TPrinterModelEntry::InternalizeL(RReadStream& aStream) sl@0: sl@0: /** Internalises a printer model entry from a read stream. sl@0: sl@0: The presence of this function means that the standard templated stream operator>>(), sl@0: defined in s32strm.h, is available to internalise objects of this class. sl@0: sl@0: @param aStream The read stream. */ sl@0: { sl@0: aStream >> iModelName; sl@0: iRequiresPrinterPort=aStream.ReadUint8L(); sl@0: aStream >> iUid; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void TPrinterModelEntry::ExternalizeL(RWriteStream& aStream) const sl@0: /** Externalises the printer model entry to a write stream. sl@0: sl@0: The presence of this function means that the standard templated stream operator<<(), sl@0: defined in s32strm.h, is available to externalise objects of this class. sl@0: sl@0: @param aStream The write stream. */ sl@0: { sl@0: aStream << iModelName; sl@0: aStream.WriteUint8L((TUint8) iRequiresPrinterPort); sl@0: aStream << iUid; sl@0: } sl@0: sl@0: // sl@0: // TPrinterModelHeader sl@0: // sl@0: sl@0: sl@0: EXPORT_C void TPrinterModelHeader::InternalizeL(RReadStream& aStream) sl@0: /** Internalises a printer model header from a read stream. sl@0: sl@0: The presence of this function means that the standard templated stream operator>>(), sl@0: defined in s32strm.h, is available to internalise objects of this class. sl@0: sl@0: @param aStream The read stream. */ sl@0: { sl@0: aStream >> iEntry; sl@0: aStream >> iModelDataStreamId; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void TPrinterModelHeader::ExternalizeL(RWriteStream& aStream) const sl@0: sl@0: /** Externalises the printer model header to a write stream. sl@0: sl@0: The presence of this function means that the standard templated stream operator<<(), sl@0: defined in s32strm.h, is available to externalise objects of this class. sl@0: @param aStream The write stream. */ sl@0: { sl@0: aStream << iEntry; sl@0: aStream << iModelDataStreamId; sl@0: } sl@0: sl@0: // sl@0: // CPrinterDevice sl@0: // sl@0: sl@0: EXPORT_C CPrinterDevice::CPrinterDevice(): sl@0: CGraphicsDevice(), sl@0: iCurrentPageSpecInTwips() sl@0: /** Standard constructor. */ sl@0: {} sl@0: sl@0: sl@0: EXPORT_C CPrinterDevice::~CPrinterDevice() sl@0: sl@0: /** Destructor. sl@0: It frees all resources owned by the object, prior to its destruction. */ sl@0: { sl@0: delete iControl; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CPrinterDevice::SelectPageSpecInTwips(const TPageSpec& aPageSpecInTwips) sl@0: /** Sets the page specification in twips. sl@0: @param aPageSpec The page specification in twips. */ sl@0: { sl@0: iCurrentPageSpecInTwips=aPageSpecInTwips; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TRect CPrinterDevice::PrintablePageInPixels() const sl@0: /** Gets the dimensions of the area to which the printer device can print. sl@0: sl@0: These dimensions are normally less than those returned by TPageSpec::OrientedPageSize() sl@0: because a margin exists between the boundary of the printable page and the sl@0: absolute extent of the page. sl@0: sl@0: @return The dimensions of the printer device area in pixels, respecting the sl@0: page orientation */ sl@0: { sl@0: return TRect(SizeInPixels()); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CPrinterDevice::DeleteControl() sl@0: /** Deletes the printer control owned by this object. sl@0: sl@0: The function sets the iControl member to NULL. */ sl@0: { sl@0: delete iControl; sl@0: iControl=NULL; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CPrinterDevice::RestorePropertiesL() sl@0: /** Restores printer properties. */ sl@0: { sl@0: _LIT(KSystemIniFileNameSpec,"Z:\\System\\System.ini"); sl@0: sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: sl@0: TDriveUnit drive(static_cast(RFs::GetSystemDrive())); sl@0: TParse systemIniFileName; sl@0: systemIniFileName.Set(drive.Name(), &KSystemIniFileNameSpec, NULL); sl@0: sl@0: TUint atts = 0; sl@0: TInt ret = fs.Att(systemIniFileName.FullName(), atts); sl@0: if (ret == KErrNone) sl@0: { sl@0: CDictionaryStore* dictionarystore = NULL; sl@0: TRAPD(err,dictionarystore = CDictionaryFileStore::SystemL(fs)); sl@0: if (err == KErrNone) sl@0: { sl@0: CleanupStack::PushL(dictionarystore); sl@0: if (dictionarystore->IsPresentL(Model().iUid)) sl@0: { sl@0: RDictionaryReadStream stream; sl@0: stream.OpenLC(*dictionarystore,Model().iUid); sl@0: InternalizePropertiesL(stream); sl@0: CleanupStack::PopAndDestroy(); // stream sl@0: } sl@0: CleanupStack::PopAndDestroy(); // dictionarystore sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(); // fs sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CPrinterDevice::StorePropertiesL() const sl@0: /** Stores the printer properties. */ sl@0: { sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: CDictionaryStore* dictionarystore = CDictionaryFileStore::SystemLC(fs); sl@0: RDictionaryWriteStream stream; sl@0: stream.AssignLC(*dictionarystore,Model().iUid); sl@0: ExternalizePropertiesL(stream); sl@0: stream.CommitL(); sl@0: CleanupStack::PopAndDestroy(); // stream sl@0: dictionarystore->CommitL(); sl@0: CleanupStack::PopAndDestroy(2); // dictionarystore, fs sl@0: } sl@0: sl@0: // sl@0: // CPrinterControl sl@0: // sl@0: sl@0: sl@0: EXPORT_C CPrinterControl::~CPrinterControl() sl@0: /** Destructor. sl@0: sl@0: It frees all resources owned by the object, prior to its destruction. */ sl@0: { sl@0: delete iPrinterPort; sl@0: } sl@0: sl@0: EXPORT_C CPrinterControl::CPrinterControl(CPrinterPort* aPrinterPort): sl@0: CBase(), sl@0: iState(ENotPrinting), sl@0: iPrinterPort(aPrinterPort) sl@0: {} sl@0: sl@0: // sl@0: // TPageSpec sl@0: // sl@0: sl@0: sl@0: EXPORT_C TPageSpec::TPageSpec(): sl@0: iPortraitPageSize(TSize(0,0)), sl@0: iOrientation(EPortrait) sl@0: /** Default constructor. sl@0: sl@0: Initialises the page orientation to portrait and the page height and width sl@0: to zero. */ sl@0: {} sl@0: sl@0: sl@0: EXPORT_C TPageSpec::TPageSpec(TPageOrientation anOrientation,const TSize& aSize): sl@0: iPortraitPageSize(aSize), sl@0: iOrientation(anOrientation) sl@0: /** Constructor with page orientation and size. sl@0: sl@0: @param aOrientation Specifies the page orientation. sl@0: @param aSize Specifies the page size. */ sl@0: {} sl@0: sl@0: sl@0: EXPORT_C void TPageSpec::InternalizeL(RReadStream& aStream) sl@0: /** Internalises a page specification object from a read stream. sl@0: sl@0: The presence of this function means that the standard templated stream operator>>(), sl@0: defined in s32strm.h, is available to internalise objects of this class. sl@0: sl@0: @param aStream The read stream. */ sl@0: { sl@0: iPortraitPageSize.iWidth = aStream.ReadInt32L(); sl@0: iPortraitPageSize.iHeight = aStream.ReadInt32L(); sl@0: iOrientation=(TPageSpec::TPageOrientation)aStream.ReadInt8L(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void TPageSpec::ExternalizeL(RWriteStream& aStream) const sl@0: /** Externalises the page specification object to a write stream. sl@0: sl@0: The presence of this function means that the standard templated stream operator<<(), sl@0: defined in s32strm.h, is available to externalise objects of this class. sl@0: @param aStream The write stream. */ sl@0: { sl@0: aStream.WriteInt32L(iPortraitPageSize.iWidth); sl@0: aStream.WriteInt32L(iPortraitPageSize.iHeight); sl@0: aStream.WriteInt8L(iOrientation); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TSize TPageSpec::OrientedPageSize()const sl@0: /** Gets the oriented page size. sl@0: sl@0: The oriented page size is the absolute width and height of the page, respecting sl@0: the page orientation. sl@0: @return The oriented page size (in pixels or twips). */ sl@0: { sl@0: if(iOrientation==EPortrait) sl@0: return(iPortraitPageSize); sl@0: return(TSize(iPortraitPageSize.iHeight,iPortraitPageSize.iWidth)); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TBool TPageSpec::operator==(const TPageSpec& aPageSpec) const sl@0: /** Equality operator. sl@0: sl@0: This operator compares page specifications for equality. Two page specifications sl@0: are equal if both their orientations and portrait page sizes are equal. sl@0: sl@0: @param aPageSpec Page specification to be compared. sl@0: @return ETrue, if the page specifications are equal; EFalse, otherwise. */ sl@0: { sl@0: return(iPortraitPageSize==aPageSpec.iPortraitPageSize && sl@0: iOrientation==aPageSpec.iOrientation); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TBool TPageSpec::operator!=(const TPageSpec& aPageSpec) const sl@0: /** Inequality operator. sl@0: sl@0: This operator compares two page specifications for inequality. Two page specifications sl@0: are unequal if one or both of their orientations and portrait page sizes differ. sl@0: sl@0: @param aPageSpec Page specification to be compared. sl@0: @return ETrue, if the page specifications differ; EFalse, otherwise. */ sl@0: { sl@0: return(!(*this==aPageSpec)); sl@0: } sl@0: sl@0: sl@0: // TMargins sl@0: sl@0: EXPORT_C void TMargins::InternalizeL(RReadStream& aStream) sl@0: /** Internalises a set of margins from a read stream. sl@0: sl@0: The presence of this function means that the standard templated stream operator>>() sl@0: is available to internalise objects of this class. sl@0: sl@0: @param aStream Stream from which the object is internalised. */ sl@0: { sl@0: iLeft = aStream.ReadInt32L(); sl@0: iRight = aStream.ReadInt32L(); sl@0: iTop = aStream.ReadInt32L(); sl@0: iBottom = aStream.ReadInt32L(); sl@0: } sl@0: sl@0: EXPORT_C void TMargins::ExternalizeL(RWriteStream& aStream) const sl@0: /** Externalises a set of margins to a write stream. sl@0: sl@0: The presence of this function means that the standard templated stream operator<<() sl@0: is available to externalise objects of this class. sl@0: sl@0: @param aStream Stream to which the object is externalised. */ sl@0: { sl@0: aStream.WriteInt32L(iLeft); sl@0: aStream.WriteInt32L(iRight); sl@0: aStream.WriteInt32L(iTop); sl@0: aStream.WriteInt32L(iBottom); sl@0: } sl@0: sl@0: EXPORT_C TBool TMargins::operator==(const TMargins& aMargins) const sl@0: /** Tests margins for equality. sl@0: sl@0: @param aMargins The margin to be compared with this margin. sl@0: @return ETrue, if the margins are equal; EFalse, otherwise. */ sl@0: { sl@0: return(iLeft==aMargins.iLeft && iRight==aMargins.iRight && sl@0: iTop==aMargins.iTop && iBottom==aMargins.iBottom); sl@0: } sl@0: sl@0: EXPORT_C TBool TMargins::operator!=(const TMargins& aMargins) const sl@0: /** Tests margins for inequality. sl@0: sl@0: @param aMargins The margin to be compared with this margin. sl@0: @return ETrue, if the margins are unequal; EFalse, otherwise. */ sl@0: { sl@0: return(!(*this==aMargins)); sl@0: } sl@0: sl@0: // sl@0: // CPrinterDriverUI sl@0: // sl@0: sl@0: EXPORT_C CPrinterDriverUI::CPrinterDriverUI() sl@0: { sl@0: __DECLARE_NAME(_S("CPrinterDriverUI")); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TBool CPrinterDriverUI::BeforePrintL() sl@0: /** Provides an opportunity for a dialog to be put up before printing begins. sl@0: sl@0: @return ETrue, if printing is to continue; EFalse, if printing is to be cancelled. sl@0: The default implementation returns ETrue. */ sl@0: { sl@0: return ETrue; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CPrinterDriverUI::AfterPrintL() sl@0: /** Provides an opportunity for a dialog to be put up after printing is complete. sl@0: The default implementation is empty. */ sl@0: { sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CPrinterDriverUI::SetPropertiesL() sl@0: /** Provides an opportunity for a dialog to be put up to capture or change printer sl@0: properties. sl@0: The default implementation is empty. */ sl@0: { sl@0: } sl@0: sl@0: sl@0: EXPORT_C TBool CPrinterDriverUI::CanSetProperties() sl@0: /** Tests whether printer properties can be set. sl@0: sl@0: @return ETrue, if printer properties can be set; EFalse, otherwise. The default sl@0: implementation returns EFalse. */ sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: // sl@0: // CPrinterDriver sl@0: // sl@0: sl@0: sl@0: EXPORT_C CPrinterDriver* CPrinterDriver::NewL() sl@0: /** Constructs, and returns a pointer to a new instance for accessing a printer sl@0: specification data store. sl@0: sl@0: @return Pointer to the object for accessing a printer specification data store. */ sl@0: { sl@0: CPrinterDriver* printerdriver=new(ELeave) CPrinterDriver; sl@0: CleanupStack::PushL(printerdriver); sl@0: User::LeaveIfError(printerdriver->iFs.Connect()); sl@0: CleanupStack::Pop(); sl@0: return printerdriver; sl@0: } sl@0: sl@0: sl@0: EXPORT_C CPrinterDriver::~CPrinterDriver() sl@0: /** Destructor. sl@0: sl@0: It frees all resources owned by the object, prior to its destruction. In particular, sl@0: it closes the printer specification data store and any open session with the file server. */ sl@0: { sl@0: Close(); sl@0: iFs.Close(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CPrinterDriver::OpenPdrL(const TDesC &aName) sl@0: /** Opens the specified printer specification data store. sl@0: sl@0: @return The name of the printer specification data store. This must be a sl@0: valid printer specification data store,otherwise the function leaves with sl@0: KErrNotSupported. */ sl@0: { sl@0: Close(); sl@0: TRAPD(ret,DoOpenPdrL(aName)); sl@0: if (ret!=KErrNone) sl@0: { sl@0: Close(); sl@0: User::Leave(ret); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CPrinterDriver::Close() sl@0: /** Closes the printer specification data store and frees resources. sl@0: sl@0: An open session with the file server remains open. */ sl@0: { sl@0: delete iPdrStore, sl@0: iPdrStore=NULL; sl@0: iNumModels=0; sl@0: delete[] iModelList; sl@0: iModelList=NULL; sl@0: DeletePrinterDevice(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CPrinterDriver::NumModels() const sl@0: /** Gets the number of printer models defined by the printer specification. sl@0: sl@0: @return The number of printer models. */ sl@0: { sl@0: return iNumModels; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TPrinterModelEntry CPrinterDriver::Model(TInt aNum) const sl@0: /** Gets the specified printer model. sl@0: sl@0: @param aNum An index into the list of printer models defined in the printer sl@0: specification data. sl@0: @return Model specific information. */ sl@0: { sl@0: GDI_ASSERT_DEBUG(aNum>=0,EPdrModelIndexOutOfRange); sl@0: GDI_ASSERT_DEBUG(aNumSetPrinterDevice(iPrinterDevice)); sl@0: CleanupStack::Pop(); sl@0: return printerdriverui; sl@0: } sl@0: sl@0: CPrinterDriver::CPrinterDriver() sl@0: {} sl@0: sl@0: void CPrinterDriver::DeletePrinterDevice() sl@0: { sl@0: iUdlLibrary.Close(); sl@0: delete iPrinterDevice; sl@0: iPrinterDevice=NULL; sl@0: iPdlLibrary.Close(); sl@0: } sl@0: sl@0: void CPrinterDriver::DoOpenPdrL(const TDesC &aName) sl@0: { sl@0: Close(); sl@0: iPdrStore=CDirectFileStore::OpenL(iFs,aName,EFileStream|EFileRead|EFileShareReadersOnly); sl@0: if (iPdrStore->Type()[1]!=TUid::Uid(KPdrStoreFileUidVal)) sl@0: User::Leave(KErrNotSupported); sl@0: TStreamId headerid = iPdrStore->Root(); sl@0: RStoreReadStream stream; sl@0: stream.OpenLC(*iPdrStore,headerid); sl@0: stream >> iPdlName; sl@0: stream >> iPdlUid; sl@0: iNumModels = stream.ReadInt32L(); sl@0: iModelList = new(ELeave) TPrinterModelHeader[iNumModels]; sl@0: for (TInt i=0; iSetModel(iModelList[i],*iPdrStore)); sl@0: iPrinterDevice->RestorePropertiesL(); sl@0: } sl@0: sl@0: // sl@0: // CPdrModelList sl@0: // sl@0: sl@0: sl@0: EXPORT_C CPdrModelList* CPdrModelList::NewL() sl@0: /** Constructs, and returns a pointer to a new instance of the printer model sl@0: list interface. sl@0: @return Pointer to the new printer model list interface object. */ sl@0: { sl@0: CPdrModelList* modellist=new(ELeave) CPdrModelList(); sl@0: CleanupStack::PushL(modellist); sl@0: modellist->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return modellist; sl@0: } sl@0: sl@0: sl@0: EXPORT_C CPdrModelList::~CPdrModelList() sl@0: /** Virtual destructor. sl@0: Frees resources owned by the object, prior to its destruction. */ sl@0: { sl@0: delete iModelArray; sl@0: delete iFileArray; sl@0: if (iDirectoryArray) sl@0: {// delete all the HBufC's sl@0: for (TInt i=iDirectoryArray->Count()-1 ; i>=0 ; i--) sl@0: delete (*iDirectoryArray)[i]; sl@0: delete iDirectoryArray; sl@0: } sl@0: iFileServer.Close(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CPdrModelList::ModelCount() const sl@0: /** Gets the number of printer models in the printer model list. sl@0: @return The number of printer models. */ sl@0: { sl@0: return iModelArray->Count(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C const TPrinterModelEntry CPdrModelList::operator [] (TInt anIndex) sl@0: /** Gets printer model name. sl@0: sl@0: This is the name of the printer model at the specified index within the list sl@0: of printer models. sl@0: sl@0: @param anIndex The index of the printer model within the array of printer sl@0: models. Note that this number must be between zero and ModelCount(). sl@0: sl@0: @return Name of printer model, up to 32 characters long */ sl@0: { sl@0: GDI_ASSERT_DEBUG(anIndex>=0,EPdrModelIndexOutOfRange); sl@0: GDI_ASSERT_DEBUG(anIndexCount(),EPdrModelIndexOutOfRange); sl@0: sl@0: return (*iModelArray)[anIndex].iEntry; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CPdrModelList::UidToNum(TUid aModelUid) const sl@0: /** Gets a printer model's index within the model list from its UID. sl@0: sl@0: @param aModelUid The UID of the printer model. sl@0: @return The index of the printer model within the array of printer models if sl@0: found; KErrNotFound, otherwise. */ sl@0: { sl@0: TInt i,count=iModelArray->Count(); sl@0: for (i=0; (iAppendL(buf); sl@0: CleanupStack::Pop(); //buf sl@0: } sl@0: sl@0: LOCAL_C void DereferenceAndDeleteHBufC8(TAny* aPointerToPointerToHBufC8) sl@0: { sl@0: delete *STATIC_CAST(HBufC8**, aPointerToPointerToHBufC8); sl@0: } sl@0: sl@0: sl@0: EXPORT_C CPrinterModelList* CPdrModelList::ScanForModelsL() sl@0: /** Scans through through the list of directories for all .pdr files and generates sl@0: a list of printer models. sl@0: sl@0: @return The list of model names. */ sl@0: { sl@0: iModelArray->Reset(); sl@0: iFileArray->Reset(); sl@0: // check that there is at least one directory to parse? sl@0: // get a list of *.pdr files in all directories specified (using AddDirectory()) sl@0: for (TInt index=iDirectoryArray->Count()-1 ; index>=0 ; index--) sl@0: ScanDirectoryL(index); sl@0: // then go through the files one at a time, adding all models to the list sl@0: TParse* parser = new(ELeave) TParse; sl@0: CleanupStack::PushL(parser); sl@0: TFileName* nameOfLoadedResourceFile=new(ELeave) TFileName; sl@0: CleanupStack::PushL(nameOfLoadedResourceFile); sl@0: TFileName* tempFileName=new(ELeave) TFileName; sl@0: CleanupStack::PushL(tempFileName); sl@0: RResourceFile resourceFile; sl@0: CleanupClosePushL(resourceFile); sl@0: HBufC8* resource=NULL; sl@0: CleanupStack::PushL(TCleanupItem(DereferenceAndDeleteHBufC8, &resource)); sl@0: for (TInt fileNum=iFileArray->Count()-1 ; fileNum>=0 ; fileNum--) sl@0: ListModelsL(fileNum, *parser, *nameOfLoadedResourceFile, *tempFileName, resourceFile, resource); sl@0: CleanupStack::PopAndDestroy(5); // resource, resourceFile, tempFileName, nameOfLoadedResourceFile and parser sl@0: // return a handle to the array of model names sl@0: return this; sl@0: } sl@0: sl@0: sl@0: EXPORT_C CPrinterDriver* CPdrModelList::CreatePrinterDriverL(TInt anIndex) sl@0: /** Creates an object for accessing the specified store that contains printer specification sl@0: data. sl@0: sl@0: @param anIndex An index into a list of files containing printer specification sl@0: data. The files are the complete set of .pdr files found in the directories sl@0: known to this object. sl@0: @return A pointer to the object representing the store containing the printer sl@0: specification data. */ sl@0: { sl@0: GDI_ASSERT_DEBUG(anIndex>=0,EPdrModelIndexOutOfRange); sl@0: GDI_ASSERT_DEBUG(anIndexCount(),EPdrModelIndexOutOfRange); sl@0: sl@0: CPrinterDriver* driver = CPrinterDriver::NewL(); sl@0: CleanupStack::PushL(driver); sl@0: HBufC* file = NewPathBufL(*((*iModelArray)[anIndex].iFile)); sl@0: CleanupStack::PushL(file); sl@0: driver->OpenPdrL(*file); sl@0: driver->CreatePrinterDeviceL((*iModelArray)[anIndex].iEntry.iUid); sl@0: CleanupStack::PopAndDestroy(); sl@0: CleanupStack::Pop(); sl@0: return driver; sl@0: } sl@0: sl@0: sl@0: CPdrModelList::CPdrModelList(): sl@0: iModelArray(NULL), sl@0: iFileArray(NULL), sl@0: iDirectoryArray(NULL) sl@0: { sl@0: } sl@0: sl@0: void CPdrModelList::ConstructL() sl@0: { sl@0: __DECLARE_NAME(_S("CPdrModelList")); sl@0: iModelArray = new(ELeave) CArrayFixSeg(5); sl@0: iFileArray = new(ELeave) CArrayFixFlat(5); sl@0: iDirectoryArray = new(ELeave) CArrayFixFlat(1); sl@0: User::LeaveIfError(iFileServer.Connect()); sl@0: } sl@0: sl@0: void CPdrModelList::ScanDirectoryL(TInt aDirIndex) sl@0: /** Scans the given directory, parsing all files found sl@0: If a file is of the correct type it is appended to the file list*/ sl@0: { sl@0: GDI_ASSERT_DEBUG(aDirIndex>=0,EPdrDirectoryIndexOutOfRange); sl@0: GDI_ASSERT_DEBUG(aDirIndexCount(),EPdrDirectoryIndexOutOfRange); sl@0: sl@0: TDesC* dir = (*iDirectoryArray)[aDirIndex]; sl@0: TParse path; sl@0: path.Set(KPdrExtension,dir,NULL); sl@0: CDir* fileList; sl@0: TInt ret = iFileServer.GetDir(path.FullName(),KEntryAttNormal,ESortByName,fileList); sl@0: if (ret == KErrNone) sl@0: { sl@0: CleanupStack::PushL(fileList); sl@0: for (TInt i=fileList->Count()-1 ; i>=0 ; i--) sl@0: { sl@0: TFileEntry& entry = iFileArray->ExtendL(); sl@0: entry.iFileName = (*fileList)[i].iName; sl@0: entry.iDirectory = dir; sl@0: } sl@0: CleanupStack::PopAndDestroy(); // fileList sl@0: } sl@0: else if (ret == KErrNoMemory) // Ignore errors other than KErrNoMemory sl@0: User::LeaveNoMemory(); sl@0: } sl@0: sl@0: void CPdrModelList::ListModelsL(TInt aFileIndex, TParse& aParser, TFileName& aNameOfLoadedResourceFile, TFileName& aTempFileName, RResourceFile& aResourceFile, HBufC8*& aResource) sl@0: /** given a pdr file list all the models it contains in the model array */ sl@0: { sl@0: GDI_ASSERT_DEBUG(aFileIndex>=0,EPdrFileIndexOutOfRange); sl@0: GDI_ASSERT_DEBUG(aFileIndexCount(),EPdrFileIndexOutOfRange); sl@0: sl@0: CPrinterDriver* driver = CPrinterDriver::NewL() ; sl@0: CleanupStack::PushL(driver); sl@0: // open the file sl@0: HBufC* fullPath = NewPathBufL((*iFileArray)[aFileIndex]); sl@0: TRAPD(ret,driver->OpenPdrL(*fullPath)); sl@0: delete fullPath; sl@0: if ((ret!=KErrNone) && (ret!=KErrNotSupported)) sl@0: User::Leave(ret); sl@0: // get info on the models one by one and insert them into the array sl@0: if (ret==KErrNone) sl@0: { sl@0: TModelEntry modelentry; sl@0: modelentry.iFile = &(*iFileArray)[aFileIndex]; // set the file pointer for the entry sl@0: const TInt numberOfModels = driver->NumModels(); sl@0: for (TInt i=0 ; iModel(i); sl@0: if (UidToNum(modelentry.iEntry.iUid)==KErrNotFound) sl@0: { sl@0: User::LeaveIfError(aParser.SetNoWild(KRscExtension, &modelentry.iFile->iFileName, modelentry.iFile->iDirectory)); sl@0: aTempFileName=aParser.FullName(); sl@0: BaflUtils::NearestLanguageFile(iFileServer, aTempFileName); sl@0: if (aNameOfLoadedResourceFile.CompareF(aTempFileName)!=0) sl@0: { sl@0: if (!BaflUtils::FileExists(iFileServer, aTempFileName)) sl@0: { sl@0: iModelArray->AppendL(modelentry); // no resource file found, so reverting to old behaviour (i.e. where the model-name is set from the PDR file) sl@0: continue; sl@0: } sl@0: aNameOfLoadedResourceFile=KNullDesC; sl@0: aResourceFile.OpenL(iFileServer, aTempFileName); sl@0: HBufC8* resource=aResourceFile.AllocReadL(aResourceFile.Offset()+2); // read the first resource after the RSS_SIGNATURE resource sl@0: delete aResource; sl@0: aResource=resource; sl@0: aNameOfLoadedResourceFile=aTempFileName; sl@0: } sl@0: TResourceReader resourceReader; sl@0: resourceReader.SetBuffer(aResource); sl@0: for (TInt j=resourceReader.ReadUint16()-1; ; --j) sl@0: { sl@0: if (j<0) sl@0: { sl@0: iModelArray->AppendL(modelentry); // no matching uid found in the resource file, so reverting to old behaviour (i.e. where the model-name is set from the PDR file) sl@0: break; sl@0: } sl@0: TInt uid=resourceReader.ReadInt32(); sl@0: TPtrC name=resourceReader.ReadTPtrC(); sl@0: if (uid==modelentry.iEntry.iUid.iUid) sl@0: { sl@0: if (name.Length()>0) sl@0: { sl@0: modelentry.iEntry.iModelName=name; sl@0: iModelArray->AppendL(modelentry); sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(); // driver sl@0: } sl@0: sl@0: sl@0: HBufC* CPdrModelList::NewPathBufL(const TFileEntry& aFileEntry) sl@0: /** Create a buf of the right length and... sl@0: set its contents to the full filename of model aModel */ sl@0: { sl@0: // Create a buf of the right length sl@0: HBufC* buf = HBufC::NewL(aFileEntry.iFileName.Length()+aFileEntry.iDirectory->Length()); sl@0: // Insert the file path sl@0: TPtr filePtr = buf->Des(); sl@0: filePtr.Append(*aFileEntry.iDirectory); sl@0: filePtr.Append(aFileEntry.iFileName); sl@0: return buf; sl@0: } sl@0: sl@0: // !!!! sl@0: // Retained for binary compatibility only: remove if we make a binary incompatible release sl@0: // sl@0: sl@0: IMPORT_C void GDI_Reserved(); sl@0: EXPORT_C void GDI_Reserved() sl@0: {} sl@0: