summaryrefslogtreecommitdiff
path: root/psprint
diff options
context:
space:
mode:
authorVladimir Glazounov <vg@openoffice.org>2003-04-11 16:18:38 +0000
committerVladimir Glazounov <vg@openoffice.org>2003-04-11 16:18:38 +0000
commit0b79ebd4355b7ec7a08b739ead65f28aef9a7f2f (patch)
tree270916984a3acdbf69f00863d43778b6c556ec4b /psprint
parent424b29a9be9efd3d8f352641f91aca5c045ea355 (diff)
INTEGRATION: CWS vcl07 (1.5.2.2.10); FILE MERGED
2003/04/01 11:52:08 pl 1.5.2.2.10.4: #108474# fix imbalance between keys and ordered keys 2003/03/20 12:26:43 pl 1.5.2.2.10.3: RESYNC: (1.5.2.2-1.5.2.3); FILE MERGED 2003/03/12 21:40:32 pl 1.5.2.2.10.2: #103308# emergency printer configuration for setup 2003/03/12 13:09:28 pl 1.5.2.2.10.1: #i10309# more robust PPD file discovery
Diffstat (limited to 'psprint')
-rw-r--r--psprint/source/helper/ppdparser.cxx136
1 files changed, 101 insertions, 35 deletions
diff --git a/psprint/source/helper/ppdparser.cxx b/psprint/source/helper/ppdparser.cxx
index ac6ed16ca1d4..cb7516725470 100644
--- a/psprint/source/helper/ppdparser.cxx
+++ b/psprint/source/helper/ppdparser.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ppdparser.cxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: hr $ $Date: 2003-03-26 14:24:05 $
+ * last change: $Author: vg $ $Date: 2003-04-11 17:18:38 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -80,6 +80,9 @@ struct std::hash< const psp::PPDKey* >
#include <tools/urlobj.hxx>
#include <tools/stream.hxx>
#include <osl/mutex.hxx>
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <osl/thread.h>
#define PRINTER_PPDDIR "driver"
@@ -94,51 +97,112 @@ using namespace rtl;
#define DBG_ASSERT( x, y )
#endif
-::std::list< PPDParser* > PPDParser::aAllParsers;
-
+std::list< PPDParser* > PPDParser::aAllParsers;
+std::hash_map< OUString, OUString, OUStringHash >* PPDParser::pAllPPDFiles = NULL;
static String aEmptyString;
-static String GetPPDFile( const String& rFile )
+void PPDParser::scanPPDDir( const String& rDir )
{
- INetURLObject aPPD( rFile, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
- SvFileStream aStream( aPPD.PathToFileName(), STREAM_READ );
- // someone might enter a full qualified name here
- if( ! aStream.IsOpen() )
+ static const sal_Char* pSuffixes[] = { "PS", "PPD" };
+ static const int nSuffixLens[] = { 2, 3 };
+ const int nSuffixes = sizeof(pSuffixes)/sizeof(pSuffixes[0]);
+
+ osl::Directory aDir( rDir );
+ aDir.open();
+ osl::DirectoryItem aItem;
+ bool bWas = false;
+
+ INetURLObject aPPDDir(rDir);
+ while( aDir.getNextItem( aItem ) == osl::FileBase::E_None )
{
- // check installation directories
- String aFile( aPPD.GetName() );
- String aPathList( getPrinterPath() );
- int nTokenCount = aPathList.GetTokenCount( ':' );
- for( int i = 0; i < nTokenCount && ! aStream.IsOpen(); i++ )
+ osl::FileStatus aStatus( FileStatusMask_FileName |
+ FileStatusMask_Type
+ );
+ if( aItem.getFileStatus( aStatus ) == osl::FileBase::E_None &&
+ ( aStatus.getFileType() == osl::FileStatus::Regular ||
+ aStatus.getFileType() == osl::FileStatus::Link ) )
{
- aPPD = INetURLObject( aPathList.GetToken( i, ':' ), INET_PROT_FILE, INetURLObject::ENCODE_ALL );
- aPPD.Append( String( RTL_CONSTASCII_USTRINGPARAM( PRINTER_PPDDIR ) ) );
- aPPD.Append( aFile );
-
- aStream.Open( aPPD.PathToFileName(), STREAM_READ );
- // append .PS if necessary
- if( ! aStream.IsOpen() )
+ INetURLObject aPPDFile = aPPDDir;
+ aPPDFile.Append( aStatus.getFileName() );
+ String aExt = aPPDFile.getExtension();
+ // match extension
+ for( int nSuffix = 0; nSuffix < nSuffixes; nSuffix++ )
{
- aPPD.setExtension( String( RTL_CONSTASCII_USTRINGPARAM( "PS" ) ) );
- aStream.Open( aPPD.PathToFileName(), STREAM_READ );
- // append .PPD
- if( ! aStream.IsOpen() )
+ if( aExt.EqualsIgnoreCaseAscii( pSuffixes[nSuffix] ) )
{
- aPPD.setExtension( String( RTL_CONSTASCII_USTRINGPARAM( "PPD" ) ) );
- aStream.Open( aPPD.PathToFileName(), STREAM_READ );
+ (*pAllPPDFiles)[ aPPDFile.getBase() ] = aPPDFile.PathToFileName();
+ break;
}
}
}
}
+ aDir.close();
+}
- String aRet;
+void PPDParser::initPPDFiles()
+{
+ if( pAllPPDFiles )
+ return;
+
+ pAllPPDFiles = new std::hash_map< OUString, OUString, OUStringHash >();
+ // check installation directories
+ std::list< OUString > aPathList;
+ psp::getPrinterPathList( aPathList, PRINTER_PPDDIR );
+ for( std::list< OUString >::const_iterator ppd_it = aPathList.begin(); ppd_it != aPathList.end(); ++ppd_it )
+ {
+ INetURLObject aPPDDir( *ppd_it, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
+ scanPPDDir( aPPDDir.GetMainURL( INetURLObject::NO_DECODE ) );
+ }
+ if( pAllPPDFiles->find( OUString( RTL_CONSTASCII_USTRINGPARAM( "SGENPRT" ) ) ) == pAllPPDFiles->end() )
+ {
+ // last try: search in directory of executable (mainly for setup)
+ OUString aExe;
+ if( osl_getExecutableFile( &aExe.pData ) == osl_Process_E_None )
+ {
+ INetURLObject aDir( aExe );
+ aDir.removeSegment();
+#ifdef DEBUG
+ fprintf( stderr, "scanning last chance dir: %s\n", OUStringToOString( aDir.GetMainURL( INetURLObject::NO_DECODE ), osl_getThreadTextEncoding() ).getStr() );
+#endif
+ scanPPDDir( aDir.GetMainURL( INetURLObject::NO_DECODE ) );
+#ifdef DEBUG
+ fprintf( stderr, "SGENPRT %s\n", pAllPPDFiles->find( OUString( RTL_CONSTASCII_USTRINGPARAM( "SGENPRT" ) ) ) == pAllPPDFiles->end() ? "not found" : "found" );
+#endif
+ }
+ }
+}
+
+String PPDParser::getPPDFile( const String& rFile )
+{
+ INetURLObject aPPD( rFile, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
+ // someone might enter a full qualified name here
+ SvFileStream aStream( aPPD.PathToFileName(), STREAM_READ );
+ if( ! aStream.IsOpen() )
+ {
+ initPPDFiles();
+ std::hash_map< OUString, OUString, OUStringHash >::const_iterator it =
+ pAllPPDFiles->find( aPPD.getBase() );
+ if( it == pAllPPDFiles->end() )
+ {
+ // a new file ? rehash
+ delete pAllPPDFiles; pAllPPDFiles = NULL;
+ initPPDFiles();
+ it = pAllPPDFiles->find( aPPD.getBase() );
+ // note this is optimized for office start where
+ // no new files occur and initPPDFiles is called only once
+ }
+ if( it != pAllPPDFiles->end() )
+ aStream.Open( it->second, STREAM_READ );
+ }
+
+ String aRet;
if( aStream.IsOpen() )
{
ByteString aLine;
aStream.ReadLine( aLine );
if( aLine.Search( "*PPD-Adobe" ) == 0 )
- aRet = aPPD.PathToFileName();
+ aRet = aStream.GetFileName();
else
{
// our *Include hack does usually not begin
@@ -147,7 +211,7 @@ static String GetPPDFile( const String& rFile )
while( aLine.Search( "*Include" ) != 0 && --nLines )
aStream.ReadLine( aLine );
if( nLines )
- aRet = aPPD.PathToFileName();
+ aRet = aStream.GetFileName();
}
}
@@ -156,7 +220,7 @@ static String GetPPDFile( const String& rFile )
String PPDParser::getPPDPrinterName( const String& rFile )
{
- String aPath = GetPPDFile( rFile );
+ String aPath = getPPDFile( rFile );
String aName;
// read in the file
@@ -181,7 +245,7 @@ String PPDParser::getPPDPrinterName( const String& rFile )
aCurLine.EraseLeadingChars( '"' );
aCurLine.EraseTrailingChars( '"' );
aStream.Close();
- aStream.Open( GetPPDFile( aCurLine ), STREAM_READ );
+ aStream.Open( getPPDFile( aCurLine ), STREAM_READ );
continue;
}
if( aCurLine.CompareToAscii( "*ModelName:", 11 ) == COMPARE_EQUAL )
@@ -201,7 +265,7 @@ const PPDParser* PPDParser::getParser( String aFile )
static ::osl::Mutex aMutex;
::osl::Guard< ::osl::Mutex > aGuard( aMutex );
- aFile = GetPPDFile( aFile );
+ aFile = getPPDFile( aFile );
if( ! aFile.Len() )
return NULL;
@@ -221,6 +285,8 @@ void PPDParser::freeAll()
delete aAllParsers.front();
aAllParsers.pop_front();
}
+ delete pAllPPDFiles;
+ pAllPPDFiles = NULL;
}
PPDParser::PPDParser( const String& rFile ) :
@@ -261,7 +327,7 @@ PPDParser::PPDParser( const String& rFile ) :
aCurLine.EraseLeadingChars( '"' );
aCurLine.EraseTrailingChars( '"' );
aStream.Close();
- aStream.Open( GetPPDFile( aCurLine ), STREAM_READ );
+ aStream.Open( getPPDFile( aCurLine ), STREAM_READ );
continue;
}
aLines.push_back( aCurLine );
@@ -620,7 +686,7 @@ void PPDParser::parseOpenUI( const String& rLine )
if( keyit == m_aKeys.end() )
{
pKey = new PPDKey( aKey );
- m_aKeys[ aKey ] = pKey;
+ insertKey( aKey, pKey );
}
else
pKey = keyit->second;