diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2014-12-15 23:44:27 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2019-11-25 12:01:39 +0100 |
commit | 5406099863d5dfcf91a9ae23b217441d9058687f (patch) | |
tree | 09ecd34fe54ed1d9f87bd3fbe78d05545301be38 /src/pdf/qpdfdocument.cpp | |
parent | eb91828f3d6f34e6f1b38001b435670ad333d8dc (diff) |
Keep reading until all pages are available
Diffstat (limited to 'src/pdf/qpdfdocument.cpp')
-rw-r--r-- | src/pdf/qpdfdocument.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp index 1be6b4a96..a202bc9f0 100644 --- a/src/pdf/qpdfdocument.cpp +++ b/src/pdf/qpdfdocument.cpp @@ -15,6 +15,7 @@ static int libraryRefCount; QPdfDocumentPrivate::QPdfDocumentPrivate() : avail(0) , doc(0) + , loadComplete(true) , lastError(QPdfDocument::NoError) { QMutexLocker lock(pdfMutex()); @@ -55,6 +56,8 @@ void QPdfDocumentPrivate::clear() FPDFAvail_Destroy(avail); avail = 0; + loadComplete = false; + asyncBuffer.close(); asyncBuffer.setData(QByteArray()); asyncBuffer.open(QIODevice::ReadWrite); @@ -121,19 +124,23 @@ void QPdfDocumentPrivate::_q_initiateAsyncLoad() void QPdfDocumentPrivate::_q_readFromDevice() { QMutexLocker lock(pdfMutex()); + if (loadComplete) + return; QByteArray data = remoteDevice->read(remoteDevice->bytesAvailable()); if (data.isEmpty()) return; asyncBuffer.seek(asyncBuffer.size()); asyncBuffer.write(data); - if (!doc) { + if (!doc) tryLoadDocument(); - } + if (doc) + checkComplete(); } void QPdfDocumentPrivate::tryLoadDocument() { + QMutexLocker lock(pdfMutex()); if (!FPDFAvail_IsDocAvail(avail, this)) return; @@ -145,8 +152,23 @@ void QPdfDocumentPrivate::tryLoadDocument() if (lastError == QPdfDocument::IncorrectPasswordError) emit q->passwordRequired(); } - if (doc) - emit q->documentReady(); + if (doc) { + emit q->documentLoadStarted(); + } +} + +void QPdfDocumentPrivate::checkComplete() +{ + QMutexLocker lock(pdfMutex()); + if (!doc || !avail) + return; + + loadComplete = true; + for (int i = 0, count = FPDF_GetPageCount(doc); i < count; ++i) + if (!FPDFAvail_IsPageAvail(avail, i, this)) + loadComplete = false; + if (loadComplete) + emit q->documentLoadFinished(); } bool QPdfDocumentPrivate::fpdf_IsDataAvail(_FX_FILEAVAIL *pThis, size_t offset, size_t size) |