From 7ed5ae7867de42cc29233cbe84ddd65115ca3602 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sat, 2 Jul 2005 19:32:08 +0000 Subject: [PATCH] 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 --- part.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- part.h | 2 ++ shell/shell.cpp | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/part.cpp b/part.cpp index ee4a7e87d..3fb44cb1e 100644 --- a/part.cpp +++ b/part.cpp @@ -47,9 +47,12 @@ #include #include #include +#include +#include +#include +#include #include #include -#include // 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 { diff --git a/part.h b/part.h index e8cf9b4f3..0d914e3b5 100644 --- a/part.h +++ b/part.h @@ -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; diff --git a/shell/shell.cpp b/shell/shell.cpp index 7398e7057..8104ffc4e 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -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);