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");
#else
d.append(":/usr/share/foomatic/db/source");
// compressed foomatic support
d.append(":/usr/lib/cups/driver/foomatic-db-compressed-ppds");
#endif
return d;
}
@ -626,6 +628,8 @@ DrMain* KMCupsManager::loadFileDriver(const TQString& filename)
{
if (filename.startsWith("ppd:"))
return loadDriverFile(filename.mid(4));
else if (filename.startsWith("compressed-ppd:"))
return loadDriverFile(filename);
else if (filename.startsWith("foomatic/"))
return loadMaticDriver(filename);
else
@ -685,7 +689,7 @@ DrMain* KMCupsManager::loadMaticDriver(const TQString& drname)
DrMain* KMCupsManager::loadDriverFile(const TQString& fname)
{
if (TQFile::exists(fname))
if ((fname.startsWith("compressed-ppd:")) || TQFile::exists(fname))
{
TQString msg; /* possible error message */
DrMain *driver = PPDLoader::loadDriver( fname, &msg );
@ -704,7 +708,11 @@ DrMain* KMCupsManager::loadDriverFile(const TQString& fname)
void KMCupsManager::saveDriverFile(DrMain *driver, const TQString& filename)
{
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);
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);
driver = driverList[0];
if (driver.startsWith("D")) {
driver = driver.mid(1);
driver = driver.stripWhiteSpace();
}
model = manufacturer + " " + modelName + " " + driver;
description = description + " [" + languageVersion + "]";

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

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

@ -24,8 +24,10 @@
#include <kfilterdev.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <tdetempfile.h>
#include <tqfile.h>
#include <math.h>
#include <stdlib.h>
void tdeprint_ppdscanner_init( TQIODevice* );
void tdeprint_ppdscanner_terminate( bool deleteIt = true );
@ -119,12 +121,62 @@ PPDLoader::~PPDLoader()
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
m_groups.clear();
m_option = NULL;
m_fonts.clear();
// Open driver file
TQIODevice *d = KFilterDev::deviceForFile( filename );
TQIODevice *d = KFilterDev::deviceForFile( ppdFilename );
if ( d && d->open( IO_ReadOnly ) )
{
DrMain *driver = new DrMain;
@ -153,6 +205,9 @@ DrMain* PPDLoader::readFromFile( const TQString& filename )
processPageSizes( driver );
if ( !m_fonts.isEmpty() )
driver->set( "fonts", m_fonts.join( "," ) );
if (ppdFilenameIsTempFile) {
driver->set("temporary-cppd", ppdFilename);
}
return driver;
}
else
@ -161,7 +216,7 @@ DrMain* PPDLoader::readFromFile( const TQString& filename )
m_ps.clear();
}
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;
}

Loading…
Cancel
Save