Issue #40: Finish

This commit is contained in:
Jakub Melka 2023-02-26 15:54:19 +01:00
parent 361ee247e5
commit edf7642151
3 changed files with 43 additions and 1 deletions

View File

@ -186,6 +186,36 @@ void PDFDocumentSanitizer::performSanitizeFileAttachments()
return annotation->getType() == AnnotationType::FileAttachment; return annotation->getType() == AnnotationType::FileAttachment;
}; };
removeAnnotations(filter, tr("File attachments removed: %1.")); removeAnnotations(filter, tr("File attachments removed: %1."));
// Remove files in name tree
PDFDocumentBuilder builder(m_storage, PDFVersion(2, 0));
PDFObject catalogObject = builder.getObjectByReference(builder.getCatalogReference());
const PDFDictionary* catalogDictionary = builder.getDictionaryFromObject(catalogObject);
const bool hasNames = catalogDictionary && catalogDictionary->hasKey("Names");
if (hasNames)
{
PDFObject namesObject = builder.getObject(catalogDictionary->get("Names"));
const PDFDictionary* namesDictionary = builder.getDictionaryFromObject(namesObject);
if (namesDictionary->hasKey("EmbeddedFiles"))
{
PDFDictionary dictionaryCopy = *namesDictionary;
dictionaryCopy.setEntry(PDFInplaceOrMemoryString("EmbeddedFiles"), PDFObject());
namesObject = PDFObject::createDictionary(std::make_shared<PDFDictionary>(qMove(dictionaryCopy)));
PDFObjectFactory factory;
factory.beginDictionary();
factory.beginDictionaryItem("Names");
factory << namesObject;
factory.endDictionaryItem();
factory.endDictionary();
PDFObject newCatalog = factory.takeObject();
builder.mergeTo(builder.getCatalogReference(), std::move(newCatalog));
PDFDocument document = builder.build();
m_storage = document.getStorage();
Q_EMIT sanitizationProgress(tr("Embedded files were removed."));
}
}
} }
void PDFDocumentSanitizer::performSanitizeEmbeddedSearchIndex() void PDFDocumentSanitizer::performSanitizeEmbeddedSearchIndex()

View File

@ -320,6 +320,7 @@ PDFProgramController::PDFProgramController(QObject* parent) :
m_recentFileManager(new PDFRecentFileManager(this)), m_recentFileManager(new PDFRecentFileManager(this)),
m_optionalContentActivity(nullptr), m_optionalContentActivity(nullptr),
m_textToSpeech(nullptr), m_textToSpeech(nullptr),
m_isDocumentSetInProgress(false),
m_futureWatcher(nullptr), m_futureWatcher(nullptr),
m_CMSManager(new pdf::PDFCMSManager(this)), m_CMSManager(new pdf::PDFCMSManager(this)),
m_toolManager(nullptr), m_toolManager(nullptr),
@ -1670,6 +1671,7 @@ void PDFProgramController::onDocumentModified(pdf::PDFModifiedDocument document)
// We will create undo/redo step from old document, with flags from the new, // We will create undo/redo step from old document, with flags from the new,
// because new document is modification of old document with flags. // because new document is modification of old document with flags.
pdf::PDFBoolGuard guard(m_isDocumentSetInProgress);
Q_ASSERT(m_pdfDocument); Q_ASSERT(m_pdfDocument);
if (m_undoRedoManager) if (m_undoRedoManager)
@ -1677,6 +1679,12 @@ void PDFProgramController::onDocumentModified(pdf::PDFModifiedDocument document)
m_undoRedoManager->createUndo(document, m_pdfDocument); m_undoRedoManager->createUndo(document, m_pdfDocument);
} }
// Retain pointer on old document, because during the update,
// old pointer must be valid, because some widgets holds raw
// pointer.
pdf::PDFDocumentPointer oldDocument = std::move(m_pdfDocument);
Q_UNUSED(oldDocument);
m_pdfDocument = document; m_pdfDocument = document;
document.setOptionalContentActivity(m_optionalContentActivity); document.setOptionalContentActivity(m_optionalContentActivity);
setDocument(document); setDocument(document);
@ -2015,7 +2023,10 @@ void PDFProgramController::onActionCertificateManagerTriggered()
void PDFProgramController::onDrawSpaceChanged() void PDFProgramController::onDrawSpaceChanged()
{ {
m_mainWindowInterface->updateUI(false); if (!m_isDocumentSetInProgress)
{
m_mainWindowInterface->updateUI(false);
}
} }
void PDFProgramController::onPageLayoutChanged() void PDFProgramController::onPageLayoutChanged()

View File

@ -394,6 +394,7 @@ private:
pdf::PDFOptionalContentActivity* m_optionalContentActivity; pdf::PDFOptionalContentActivity* m_optionalContentActivity;
pdf::PDFDocumentPointer m_pdfDocument; pdf::PDFDocumentPointer m_pdfDocument;
PDFTextToSpeech* m_textToSpeech; PDFTextToSpeech* m_textToSpeech;
bool m_isDocumentSetInProgress;
QFuture<AsyncReadingResult> m_future; QFuture<AsyncReadingResult> m_future;
QFutureWatcher<AsyncReadingResult>* m_futureWatcher; QFutureWatcher<AsyncReadingResult>* m_futureWatcher;