SVN commit 598957 by kebekus: fixes problem with DVI files that contain references to non-existent EPS files M +21 -2 psgs.cpp [POSSIBLY UNSAFE: system] M +9 -0 special.cpp --- trunk/KDE/kdegraphics/kviewshell/plugins/dvi/psgs.cpp #598956:598957 @@ -4,7 +4,7 @@ // // Part of KDVI - A framework for multipage text/gfx viewers // -// (C) 2004 Stefan Kebekus +// (C) 2004--2006 Stefan Kebekus // Distributed under the GPL #include @@ -231,7 +231,7 @@ proc << argus; // if (proc.start(KProcess::Block) == false) { -#warning We uses 'system' here because KProcess often crashes if started from a non-gui thread +#warning We use 'system' here because KProcess often crashes if started from a non-gui thread if (system(argus.join(" ").latin1()) != 0) { // Starting ghostscript did not work. @@ -337,6 +337,24 @@ return fi2.absoluteFilePath(); } + // If all else fails, use kpsewhich to find the filename. Note: we + // can't use the convenient "KProcIO" class here because this + // crashes infrequently when this method is called from a + // non-GUI-thread. Instead, we use an ugly "system"-call, make + // kpsewhich write its output to a temporary file and read that + // file. + QTemporaryFile outFile; + outFile.open(); + outFile.close(); // we are want the filename, not the file + + QString cmd_line = "kpsewhich " + filename + ">" + outFile.name(); + system(cmd_line.latin1()); + if (outFile.open() == false) + return QString::null; + QTextStream in(&outFile); + return in.readLine().stripWhiteSpace(); + + /* // Otherwise, use kpsewhich to find the eps file. QString EPSfilename; KProcIO proc; @@ -345,6 +363,7 @@ proc.readln(EPSfilename); return EPSfilename; + */ } #include "psgs.moc" --- trunk/KDE/kdegraphics/kviewshell/plugins/dvi/special.cpp #598956:598957 @@ -354,12 +354,21 @@ parse_special_argument(include_command, "angle=", &angle); // If we have a png, gif, jpeg or mng file, we need to draw it here. +#warning We should be checking mime-types here (see below), but KDE mime-type functions crash if called from a non-GUI thread + bool const isGFX = (EPSfilename.endsWith(".png", Qt::CaseInsensitive) || + EPSfilename.endsWith(".gif", Qt::CaseInsensitive) || + EPSfilename.endsWith(".jpg", Qt::CaseInsensitive) || + EPSfilename.endsWith(".jpeg", Qt::CaseInsensitive) || + EPSfilename.endsWith(".mng", Qt::CaseInsensitive)); + + /* KMimeType::Ptr const mime_type = KMimeType::findByFileContent(EPSfilename); QString const & mime_type_name = mime_type->name(); bool const isGFX = (mime_type_name == "image/png" || mime_type_name == "image/gif" || mime_type_name == "image/jpeg" || mime_type_name == "video/x-mng"); + */ // So, if we do not have a PostScript file, but a graphics file, and // if that file exists, we draw it here.