Make compressed PPD loading and usage functional

pull/16/head
Timothy Pearson 10 years ago
parent 880fec0918
commit 5a97ffdaae

@ -114,6 +114,8 @@ TQString KMCupsManager::driverDirectory()
d.append(":/usr/local/share/foomatic/db/source"); d.append(":/usr/local/share/foomatic/db/source");
#else #else
d.append(":/usr/share/foomatic/db/source"); d.append(":/usr/share/foomatic/db/source");
// compressed foomatic support
d.append(":/usr/lib/cups/driver/foomatic-db-compressed-ppds");
#endif #endif
return d; return d;
} }
@ -626,6 +628,8 @@ DrMain* KMCupsManager::loadFileDriver(const TQString& filename)
{ {
if (filename.startsWith("ppd:")) if (filename.startsWith("ppd:"))
return loadDriverFile(filename.mid(4)); return loadDriverFile(filename.mid(4));
else if (filename.startsWith("compressed-ppd:"))
return loadDriverFile(filename);
else if (filename.startsWith("foomatic/")) else if (filename.startsWith("foomatic/"))
return loadMaticDriver(filename); return loadMaticDriver(filename);
else else
@ -685,7 +689,7 @@ DrMain* KMCupsManager::loadMaticDriver(const TQString& drname)
DrMain* KMCupsManager::loadDriverFile(const TQString& fname) DrMain* KMCupsManager::loadDriverFile(const TQString& fname)
{ {
if (TQFile::exists(fname)) if ((fname.startsWith("compressed-ppd:")) || TQFile::exists(fname))
{ {
TQString msg; /* possible error message */ TQString msg; /* possible error message */
DrMain *driver = PPDLoader::loadDriver( fname, &msg ); DrMain *driver = PPDLoader::loadDriver( fname, &msg );
@ -704,7 +708,11 @@ DrMain* KMCupsManager::loadDriverFile(const TQString& fname)
void KMCupsManager::saveDriverFile(DrMain *driver, const TQString& filename) void KMCupsManager::saveDriverFile(DrMain *driver, const TQString& filename)
{ {
kdDebug( 500 ) << "Saving PPD file with template=" << driver->get( "template" ) << endl; kdDebug( 500 ) << "Saving PPD file with template=" << driver->get( "template" ) << endl;
TQIODevice *in = KFilterDev::deviceForFile( driver->get( "template" ) ); TQString templateFile = driver->get( "template" );
if (templateFile.startsWith("compressed-ppd:")) {
templateFile = driver->get( "temporary-cppd" );
}
TQIODevice *in = KFilterDev::deviceForFile( templateFile );
TQFile out(filename); TQFile out(filename);
if (in && in->open(IO_ReadOnly) && out.open(IO_WriteOnly)) if (in && in->open(IO_ReadOnly) && out.open(IO_WriteOnly))
{ {

@ -276,10 +276,15 @@ int parseCompressedPpdFile(const char *ppdfilename, const char *origin, const ch
} }
} }
manufacturer = manufacturer.stripWhiteSpace();
modelName = modelName.stripWhiteSpace();
driver = driver.stripWhiteSpace();
TQStringList driverList = TQStringList::split(",", driver, TRUE); TQStringList driverList = TQStringList::split(",", driver, TRUE);
driver = driverList[0]; driver = driverList[0];
if (driver.startsWith("D")) { if (driver.startsWith("D")) {
driver = driver.mid(1); driver = driver.mid(1);
driver = driver.stripWhiteSpace();
} }
model = manufacturer + " " + modelName + " " + driver; model = manufacturer + " " + modelName + " " + driver;
description = description + " [" + languageVersion + "]"; description = description + " [" + languageVersion + "]";

@ -110,6 +110,8 @@ DrMain::~DrMain()
// remove a possible temporary file // remove a possible temporary file
if (has("temporary")) if (has("temporary"))
TQFile::remove(get("temporary")); TQFile::remove(get("temporary"));
if (has("temporary-cppd"))
TQFile::remove(get("temporary-cppd"));
} }
DriverItem* DrMain::createTreeView(TQListView *parent) DriverItem* DrMain::createTreeView(TQListView *parent)

@ -117,10 +117,11 @@ void initFiles(void)
void freeFiles(void) void freeFiles(void)
{ {
int i; int i;
for (i=0; i<nfiles; i++) for (i=0; i<nfiles; i++) {
free(files[i]); free(files[i]);
free(fileorigins[i]); free(fileorigins[i]);
free(filemetadata[i]); free(filemetadata[i]);
}
free(files); free(files);
free(fileorigins); free(fileorigins);
free(filemetadata); free(filemetadata);

@ -24,8 +24,10 @@
#include <kfilterdev.h> #include <kfilterdev.h>
#include <kdebug.h> #include <kdebug.h>
#include <tdelocale.h> #include <tdelocale.h>
#include <tdetempfile.h>
#include <tqfile.h> #include <tqfile.h>
#include <math.h> #include <math.h>
#include <stdlib.h>
void tdeprint_ppdscanner_init( TQIODevice* ); void tdeprint_ppdscanner_init( TQIODevice* );
void tdeprint_ppdscanner_terminate( bool deleteIt = true ); void tdeprint_ppdscanner_terminate( bool deleteIt = true );
@ -119,12 +121,62 @@ PPDLoader::~PPDLoader()
DrMain* PPDLoader::readFromFile( const TQString& filename ) DrMain* PPDLoader::readFromFile( const TQString& filename )
{ {
bool ppdFilenameIsTempFile = false;
TQString ppdFilename = filename;
if (filename.startsWith("compressed-ppd:")) {
KTempFile tempFile(TQString::null, "ppd", 0600);
tempFile.setAutoDelete(false);
ppdFilename = tempFile.name();
TQStringList filenameParts = TQStringList::split(":", filename);
TQString databaseFilename = TQString::null;
TQString compressedFilename = TQString::null;
int i = 0;
for (TQStringList::Iterator it = filenameParts.begin(); it != filenameParts.end(); ++it) {
if (i == 1) {
databaseFilename = *it;
}
else if (i > 1) {
compressedFilename += *it;
}
i++;
}
TQString command = databaseFilename + " cat " + compressedFilename;
FILE* file = popen(command.ascii(), "r");
if (file) {
char * line = NULL;
size_t len = 0;
ssize_t read;
FILE* tmpFileStream = tempFile.fstream();
while ((read = getline(&line, &len, file)) != -1) {
fputs(line, tmpFileStream);
}
if (line) {
free(line);
}
tempFile.close();
pclose(file);
}
else {
fprintf(stderr, "Can't open driver file : %s\n", compressedFilename.ascii());
return 0;
}
ppdFilenameIsTempFile = true;
}
// Initialization // Initialization
m_groups.clear(); m_groups.clear();
m_option = NULL; m_option = NULL;
m_fonts.clear(); m_fonts.clear();
// Open driver file // Open driver file
TQIODevice *d = KFilterDev::deviceForFile( filename ); TQIODevice *d = KFilterDev::deviceForFile( ppdFilename );
if ( d && d->open( IO_ReadOnly ) ) if ( d && d->open( IO_ReadOnly ) )
{ {
DrMain *driver = new DrMain; DrMain *driver = new DrMain;
@ -153,6 +205,9 @@ DrMain* PPDLoader::readFromFile( const TQString& filename )
processPageSizes( driver ); processPageSizes( driver );
if ( !m_fonts.isEmpty() ) if ( !m_fonts.isEmpty() )
driver->set( "fonts", m_fonts.join( "," ) ); driver->set( "fonts", m_fonts.join( "," ) );
if (ppdFilenameIsTempFile) {
driver->set("temporary-cppd", ppdFilename);
}
return driver; return driver;
} }
else else
@ -161,7 +216,7 @@ DrMain* PPDLoader::readFromFile( const TQString& filename )
m_ps.clear(); m_ps.clear();
} }
else else
kdWarning( 500 ) << "PPD read error, unable to open device for file " << filename << endl; kdWarning( 500 ) << "PPD read error, unable to open device for file " << ppdFilename << endl;
return 0; return 0;
} }

Loading…
Cancel
Save