Permalink
Browse files

Add DVI and PS support. Use a temporary copy of the file.

  • Loading branch information...
1 parent 7c52b31 commit 1588330e8359149f9e6edc9a300b4b0ed2130b96 @jeremysanders committed May 19, 2010
Showing with 25 additions and 6 deletions.
  1. +1 −1 okularpluginui.rc
  2. +18 −4 partwin.cpp
  3. +6 −1 partwin.h
View
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="kparttut1" version="1">
+<kpartgui name="okularplugin" version="1">
<MenuBar>
<Menu name="file" >
View
@@ -77,12 +77,26 @@ PartWin::PartWin(QWidget *parent)
PartWin::~PartWin()
{
+ QDir d;
+ for( QList<QString>::const_iterator i = toDeleteFiles.begin();
+ i != toDeleteFiles.end(); ++i )
+ {
+ d.remove(*i);
+ }
}
-bool PartWin::readData(QIODevice *source, const QString &/*format*/)
+bool PartWin::readData(QIODevice *source, const QString &format)
{
- // read data into temporary file
- QTemporaryFile file( QDir::tempPath() + "/okularplugin_XXXXXX.pdf" );
+ QString filetype;
+ if( format == "application/postscript" )
+ filetype = ".ps";
+ else if ( format == "application/x-dvi" )
+ filetype = ".dvi";
+ else
+ filetype= ".pdf";
+
+ QTemporaryFile file("/tmp/kpart_plugin_XXXXXX" + filetype);
+ file.setAutoRemove(false);
if (!source->open(QIODevice::ReadOnly))
return false;
@@ -96,7 +110,7 @@ bool PartWin::readData(QIODevice *source, const QString &/*format*/)
file.flush();
}
- // open up temporary file into okular
+ toDeleteFiles.push_back( file.fileName() );
QString url = QString("file://") + file.fileName();
m_part->openUrl( url );
View
@@ -34,7 +34,10 @@ class PartWin : public KParts::MainWindow, QtNPBindable
Q_PROPERTY(QString src READ dataSourceUrl WRITE setDataSourceUrl)
- Q_CLASSINFO("MIME", "application/pdf:pdf:PDF document")
+ Q_CLASSINFO("MIME",
+ "application/pdf:pdf:PDF document;"
+ "application/postscript:ps:PostScript document;"
+ "application/x-dvi:dvi:DVI document")
public:
PartWin(QWidget *parent = 0);
@@ -59,4 +62,6 @@ class PartWin : public KParts::MainWindow, QtNPBindable
Reason lastConfReason;
KAction* m_printAction;
+
+ QList<QString> toDeleteFiles;
};

0 comments on commit 1588330

Please sign in to comment.