Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

Commit

Permalink
Fixes #4: Okular hangs when tmp file is deleted too early.
Browse files Browse the repository at this point in the history
  • Loading branch information
afrimberger committed Sep 20, 2012
1 parent 7b72112 commit f6837b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
34 changes: 15 additions & 19 deletions partwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include <KXMLGUIFactory>


//#define PART_DEBUG() kDebugDevNull()
#define PART_DEBUG() kWarning()
#define PART_DEBUG() kDebugDevNull()
//#define PART_DEBUG() kWarning()

PartWin::PartWin(QWidget *parent)
: KParts::MainWindow(), m_progressBarInited(false), m_guiInitialized(false)
Expand Down Expand Up @@ -117,19 +117,16 @@ void PartWin::setupActions() {

PartWin::~PartWin()
{
QDir d;
for( QList<QString>::const_iterator i = toDeleteFiles.begin(); i != toDeleteFiles.end(); ++i ) {
d.remove(*i);
}

this->guiFactory()->removeClient(m_part);
this->guiFactory()->removeClient(this);

m_tmpFile->remove();

delete m_tmpFile;
delete m_part;
delete m_printAction;

QDir d;
for( QList<QString>::const_iterator i = m_filesToDelete.begin(); i != m_filesToDelete.end(); ++i ) {
d.remove(*i);
}
}

/**
Expand Down Expand Up @@ -195,25 +192,24 @@ bool PartWin::readData(QIODevice *source, const QString &format)
fileName = fileName.left(fileName.length() - extension.length() - ((extension.length() > 0) ? 1 : 0));
}

m_tmpFile = new QTemporaryFile("/tmp/" + fileName + "_XXXXXX" + filetype);
m_tmpFile->setAutoRemove(true);
QTemporaryFile tmpFile("/tmp/" + fileName + "_XXXXXX" + filetype);
tmpFile.setAutoRemove(false);

if (!source->open(QIODevice::ReadOnly))
return false;
return false;

if(m_tmpFile->open()) {
if(tmpFile.open()) {
while( ! source->atEnd() ) {
QByteArray data = source->read(1024 * 1024 * 1024);
m_tmpFile->write(data);
tmpFile.write(data);
}
m_tmpFile->flush();
tmpFile.flush();
}

m_filesToDelete.push_back(tmpFile.fileName());
this->setupPart();

toDeleteFiles.push_back(m_tmpFile->fileName());

QString url = QString("file://") + m_tmpFile->fileName();
QString url = QString("file://") + tmpFile.fileName();
m_part->openUrl(url);

return true;
Expand Down
3 changes: 1 addition & 2 deletions partwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ class PartWin : public KParts::MainWindow, QtNPBindable

KAction* m_printAction;
bool m_guiInitialized;
QTemporaryFile *m_tmpFile;

QList<QString> toDeleteFiles;
QList<QString> m_filesToDelete;


};
Expand Down

0 comments on commit f6837b8

Please sign in to comment.