diff --git a/generators/poppler/annots.cpp b/generators/poppler/annots.cpp index 02813a1..612d72f 100644 --- a/generators/poppler/annots.cpp +++ b/generators/poppler/annots.cpp @@ -90,7 +90,9 @@ void PopplerAnnotationProxy::notifyAddition( Okular::Annotation *okl_ann, int pa QDomElement dom_ann = doc.createElement( "root" ); Okular::AnnotationUtils::storeAnnotation( okl_ann, dom_ann, doc ); +#ifndef POPPLER_QT_THREADSAFE QMutexLocker ml(mutex); +#endif // Create poppler annotation Poppler::Annotation *ppl_ann = Poppler::AnnotationUtils::createAnnotation( dom_ann ); @@ -143,7 +145,9 @@ void PopplerAnnotationProxy::notifyModification( const Okular::Annotation *okl_a if ( !ppl_ann ) // Ignore non-native annotations return; +#ifndef POPPLER_QT_THREADSAFE QMutexLocker ml(mutex); +#endif if ( okl_ann->flags() & Okular::Annotation::BeingMoved ) { @@ -253,7 +257,9 @@ void PopplerAnnotationProxy::notifyRemoval( Okular::Annotation *okl_ann, int pag if ( !ppl_ann ) // Ignore non-native annotations return; +#ifndef POPPLER_QT_THREADSAFE QMutexLocker ml(mutex); +#endif Poppler::Page *ppl_page = ppl_doc->page( page ); ppl_page->removeAnnotation( ppl_ann ); // Also destroys ppl_ann diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index 9462195..def8f75 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -545,12 +545,16 @@ bool PDFGenerator::init(QVector & pagesVector, const QString &wal bool PDFGenerator::doCloseDocument() { // remove internal objects +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif delete annotProxy; annotProxy = 0; delete pdfdoc; pdfdoc = 0; +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif docInfoDirty = true; docSynopsisDirty = true; docSyn.clear(); @@ -635,7 +639,9 @@ const Okular::DocumentInfo * PDFGenerator::generateDocumentInfo() { if ( docInfoDirty ) { +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif docInfo.set( Okular::DocumentInfo::MimeType, "application/pdf" ); @@ -682,7 +688,9 @@ const Okular::DocumentInfo * PDFGenerator::generateDocumentInfo() docInfo.set( Okular::DocumentInfo::Pages, i18n("Unknown") ); } +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif // if pdfdoc is valid then we cached good info -> don't cache them again if ( pdfdoc ) @@ -699,9 +707,13 @@ const Okular::DocumentSynopsis * PDFGenerator::generateDocumentSynopsis() if ( !pdfdoc ) return NULL; +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif QDomDocument *toc = pdfdoc->toc(); +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif if ( !toc ) return NULL; @@ -780,9 +792,13 @@ Okular::FontInfo::List PDFGenerator::fontsForPage( int page ) return list; QList fonts; +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif pdfdoc->scanForFonts( 1, &fonts ); +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif foreach (const Poppler::FontInfo &font, fonts) { @@ -809,13 +825,17 @@ const QList *PDFGenerator::embeddedFiles() const { if (docEmbeddedFilesDirty) { +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif const QList &popplerFiles = pdfdoc->embeddedFiles(); foreach(Poppler::EmbeddedFile* pef, popplerFiles) { docEmbeddedFiles.append(new PDFEmbeddedFile(pef)); } +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif docEmbeddedFilesDirty = false; } @@ -869,7 +889,9 @@ QImage PDFGenerator::image( Okular::PixmapRequest * request ) bool genObjectRects = !rectsGenerated.at( page->number() ); // 0. LOCK [waits for the thread end] +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif // 1. Set OutputDev parameters and Generate contents // note: thread safety is set on 'false' for the GUI (this) thread @@ -899,7 +921,9 @@ QImage PDFGenerator::image( Okular::PixmapRequest * request ) } // 3. UNLOCK [re-enables shared access] +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif delete p; @@ -977,9 +1001,13 @@ Okular::TextPage* PDFGenerator::textPage( Okular::Page *page ) Poppler::Page *pp = pdfdoc->page( page->number() ); if (pp) { +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif textList = pp->textList(); +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif QSizeF s = pp->pageSizeF(); pageWidth = s.width(); @@ -1020,7 +1048,9 @@ bool PDFGenerator::print( QPrinter& printer ) printer.newPage(); const int page = pageList.at( i ) - 1; +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif Poppler::Page *pp = pdfdoc->page( page ); if (pp) { @@ -1028,7 +1058,9 @@ bool PDFGenerator::print( QPrinter& printer ) painter.drawImage( painter.window(), img, QRectF(0, 0, img.width(), img.height()) ); delete pp; } +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif } painter.end(); return true; @@ -1100,10 +1132,14 @@ bool PDFGenerator::print( QPrinter& printer ) psConverter->setPSOptions(psConverter->psOptions() | Poppler::PSConverter::HideAnnotations ); #endif +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif if (psConverter->convert()) { +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif delete psConverter; tf.close(); int ret = Okular::FilePrinter::printFile( printer, tempfilename, @@ -1120,7 +1156,9 @@ bool PDFGenerator::print( QPrinter& printer ) { lastPrintError = FileConversionPrintError; delete psConverter; +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif } tf.close(); @@ -1133,7 +1171,9 @@ QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) { if ( key == "StartFullScreen" ) { +#ifndef POPPLER_QT_THREADSAFE QMutexLocker ml(userMutex()); +#endif // asking for the 'start in fullscreen mode' (pdf property) if ( pdfdoc->pageMode() == Poppler::Document::FullScreen ) return true; @@ -1153,9 +1193,13 @@ QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) { // asking for the page related to a 'named link destination'. the // option is the link name. @see addSynopsisChildren. +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif Poppler::LinkDestination *ld = pdfdoc->linkDestination( optionString ); +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif if ( ld ) { fillViewportFromLinkDestination( viewport, *ld ); @@ -1167,20 +1211,28 @@ QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) } else if ( key == "DocumentTitle" ) { +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif QString title = pdfdoc->info( "Title" ); +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif return title; } else if ( key == "OpenTOC" ) { +#ifndef POPPLER_QT_THREADSAFE QMutexLocker ml(userMutex()); +#endif if ( pdfdoc->pageMode() == Poppler::Document::UseOutlines ) return true; } else if ( key == "DocumentScripts" && option.toString() == "JavaScript" ) { +#ifndef POPPLER_QT_THREADSAFE QMutexLocker ml(userMutex()); +#endif return pdfdoc->scripts(); } return QVariant(); @@ -1199,9 +1251,13 @@ bool PDFGenerator::reparseConfig() // over the page rendered on 'standard' white background. if ( color != pdfdoc->paperColor() ) { +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif pdfdoc->setPaperColor(color); +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif somethingchanged = true; } bool aaChanged = setDocumentRenderHints(); @@ -1257,13 +1313,17 @@ bool PDFGenerator::exportTo( const QString &fileName, const Okular::ExportFormat for ( int i = 0; i < num; ++i ) { QString text; +#ifndef POPPLER_QT_THREADSAFE userMutex()->lock(); +#endif Poppler::Page *pp = pdfdoc->page(i); if (pp) { text = pp->text(QRect()).normalized(QString::NormalizationForm_KC); } +#ifndef POPPLER_QT_THREADSAFE userMutex()->unlock(); +#endif ts << text; delete pp; } @@ -1789,7 +1849,9 @@ bool PDFGenerator::save( const QString &fileName, SaveOptions options, QString * if ( options & SaveChanges ) pdfConv->setPDFOptions( pdfConv->pdfOptions() | Poppler::PDFConverter::WithChanges ); +#ifndef POPPLER_QT_THREADSAFE QMutexLocker locker( userMutex() ); +#endif bool success = pdfConv->convert(); #ifdef HAVE_POPPLER_0_12_1 if (!success)