Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 2da30e74 authored by Albert Astals Cid's avatar Albert Astals Cid

Fix crash on saving time if some of the existing annotations where removed

Also rename a variable to make it more clear what it does
parent e29892fd
......@@ -62,8 +62,8 @@ static int maskExportedFlags(int flags)
}
//BEGIN PopplerAnnotationProxy implementation
PopplerAnnotationProxy::PopplerAnnotationProxy( Poppler::Document *doc, QMutex *userMutex )
: ppl_doc ( doc ), mutex ( userMutex )
PopplerAnnotationProxy::PopplerAnnotationProxy( Poppler::Document *doc, QMutex *userMutex, QHash<Okular::Annotation*, Poppler::Annotation*> *annotsOnOpenHash )
: ppl_doc ( doc ), mutex ( userMutex ), annotationsOnOpenHash( annotsOnOpenHash )
{
}
......@@ -254,6 +254,7 @@ void PopplerAnnotationProxy::notifyRemoval( Okular::Annotation *okl_ann, int pag
QMutexLocker ml(mutex);
Poppler::Page *ppl_page = ppl_doc->page( page );
annotationsOnOpenHash->remove( okl_ann );
ppl_page->removeAnnotation( ppl_ann ); // Also destroys ppl_ann
delete ppl_page;
......
......@@ -23,7 +23,7 @@ extern Okular::Annotation* createAnnotationFromPopplerAnnotation( Poppler::Annot
class PopplerAnnotationProxy : public Okular::AnnotationProxy
{
public:
PopplerAnnotationProxy( Poppler::Document *doc, QMutex *userMutex );
PopplerAnnotationProxy( Poppler::Document *doc, QMutex *userMutex, QHash<Okular::Annotation*, Poppler::Annotation*> *annotsOnOpenHash );
~PopplerAnnotationProxy();
bool supports( Capability capability ) const override;
......@@ -33,6 +33,7 @@ class PopplerAnnotationProxy : public Okular::AnnotationProxy
private:
Poppler::Document *ppl_doc;
QMutex *mutex;
QHash<Okular::Annotation*, Poppler::Annotation*> *annotationsOnOpenHash;
};
#endif
......@@ -579,7 +579,7 @@ Okular::Document::OpenResult PDFGenerator::init(QVector<Okular::Page*> & pagesVe
pagesVector.resize(pageCount);
rectsGenerated.fill(false, pageCount);
annotationsHash.clear();
annotationsOnOpenHash.clear();
loadPages(pagesVector, 0, false);
......@@ -587,7 +587,7 @@ Okular::Document::OpenResult PDFGenerator::init(QVector<Okular::Page*> & pagesVe
reparseConfig();
// create annotation proxy
annotProxy = new PopplerAnnotationProxy( pdfdoc, userMutex() );
annotProxy = new PopplerAnnotationProxy( pdfdoc, userMutex(), &annotationsOnOpenHash );
// the file has been loaded correctly
return Okular::Document::OpenSuccess;
......@@ -1006,8 +1006,8 @@ void PDFGenerator::resolveMediaLinkReference( Okular::Action *action )
if ( (action->actionType() != Okular::Action::Movie) && (action->actionType() != Okular::Action::Rendition) )
return;
resolveMediaLinks<Poppler::LinkMovie, Okular::MovieAction, Poppler::MovieAnnotation, Okular::MovieAnnotation>( action, Okular::Annotation::AMovie, annotationsHash );
resolveMediaLinks<Poppler::LinkRendition, Okular::RenditionAction, Poppler::ScreenAnnotation, Okular::ScreenAnnotation>( action, Okular::Annotation::AScreen, annotationsHash );
resolveMediaLinks<Poppler::LinkMovie, Okular::MovieAction, Poppler::MovieAnnotation, Okular::MovieAnnotation>( action, Okular::Annotation::AMovie, annotationsOnOpenHash );
resolveMediaLinks<Poppler::LinkRendition, Okular::RenditionAction, Poppler::ScreenAnnotation, Okular::ScreenAnnotation>( action, Okular::Annotation::AScreen, annotationsOnOpenHash );
}
void PDFGenerator::resolveMediaLinkReferences( Okular::Page *page )
......@@ -1564,7 +1564,7 @@ void PDFGenerator::addAnnotations( Poppler::Page * popplerPage, Okular::Page * p
}
if ( !doDelete )
annotationsHash.insert( newann, a );
annotationsOnOpenHash.insert( newann, a );
}
if ( doDelete )
delete a;
......@@ -1718,7 +1718,7 @@ bool PDFGenerator::save( const QString &fileName, SaveOptions options, QString *
QMutexLocker locker( userMutex() );
QHashIterator<Okular::Annotation*, Poppler::Annotation*> it( annotationsHash );
QHashIterator<Okular::Annotation*, Poppler::Annotation*> it( annotationsOnOpenHash );
while ( it.hasNext() )
{
it.next();
......
......@@ -137,7 +137,9 @@ class PDFGenerator : public Okular::Generator, public Okular::ConfigInterface, p
mutable QList<Okular::EmbeddedFile*> docEmbeddedFiles;
int nextFontPage;
PopplerAnnotationProxy *annotProxy;
QHash<Okular::Annotation*, Poppler::Annotation*> annotationsHash;
// the hash below only contains annotations that were present on the file at open time
// this is enough for what we use it for
QHash<Okular::Annotation*, Poppler::Annotation*> annotationsOnOpenHash;
QBitArray rectsGenerated;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment