Open PS files, NOOOOO, we have not coded generator_ps, we just use ps2pdf (if installed) and open the resulting file, results are quite acceptable in the few ps i've tried. Testing and feedback are welcome.

svn path=/trunk/KDE/kdegraphics/kpdf/; revision=430941
remotes/origin/kpdf
Albert Astals Cid 21 years ago
parent 48bfc9caa5
commit 7ed5ae7867
  1. 47
      part.cpp
  2. 2
      part.h
  3. 2
      shell/shell.cpp

@ -47,9 +47,12 @@
#include <kiconloader.h>
#include <kio/netaccess.h>
#include <kpopupmenu.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <ktempfile.h>
#include <ktrader.h>
#include <kxmlguiclient.h>
#include <kxmlguifactory.h>
#include <ktrader.h>
// local includes
#include "xpdf/GlobalParams.h"
@ -332,6 +335,36 @@ KAboutData* Part::createAboutData()
bool Part::openFile()
{
KMimeType::Ptr mime = KMimeType::findByPath( m_file );
if ( (*mime).is( "application/postscript" ) )
{
QString app = KStandardDirs::findExe( "ps2pdf" );
if ( !app.isNull() )
{
KTempFile tf( QString::null, ".pdf" );
if ( tf.status() == 0 )
{
tf.close();
m_temporaryLocalFile = tf.name();
KProcess *p = new KProcess;
*p << app;
*p << m_file << m_temporaryLocalFile;
m_pageView->showText(i18n("Transforming from ps to pdf..."), 0);
connect(p, SIGNAL(processExited(KProcess *)), this, SLOT(psTransformEnded()));
p -> start();
return true;
}
}
else
{
KMessageBox::error(widget(), i18n("You don't have ps2pdf installed so kpdf can not open postscript files."));
return false;
}
}
m_temporaryLocalFile = QString::null;
bool ok = m_document->openDocument( m_file, url() );
// update one-time actions
@ -386,6 +419,12 @@ bool Part::openURL(const KURL &url)
bool Part::closeURL()
{
if (!m_temporaryLocalFile.isNull())
{
QFile::remove( m_temporaryLocalFile );
m_temporaryLocalFile = QString::null;
}
m_find->setEnabled( false );
m_findNext->setEnabled( false );
m_saveAs->setEnabled( false );
@ -476,6 +515,12 @@ void Part::enableTOC(bool enable)
m_toolBox->setItemEnabled(0, enable);
}
void Part::psTransformEnded()
{
m_file = m_temporaryLocalFile;
openFile();
}
//BEGIN go to page dialog
class KPDFGotoPageDialog : public KDialogBase
{

@ -106,6 +106,7 @@ protected slots:
// can be connected to widget elements
void updateViewActions();
void enableTOC(bool enable);
void psTransformEnded();
public slots:
// connected to Shell action (and browserExtension), not local one
@ -120,6 +121,7 @@ private:
// the document
KPDFDocument * m_document;
QString m_temporaryLocalFile;
// main widgets
QSplitter *m_splitter;

@ -210,7 +210,7 @@ Shell::fileOpen()
// this slot is called whenever the File->Open menu is selected,
// the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
// button is clicked
KURL url = KFileDialog::getOpenURL( QString::null, "application/pdf" );//getOpenFileName();
KURL url = KFileDialog::getOpenURL( QString::null, "application/pdf application/postscript" );//getOpenFileName();
if (!url.isEmpty())
openURL(url);

Loading…
Cancel
Save