2008-04-13 15:57:34 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <poppler-annotation.h>
|
|
|
|
|
2008-04-13 16:20:21 +00:00
|
|
|
// qt/kde includes
|
|
|
|
#include <qvariant.h>
|
|
|
|
|
2008-04-13 15:57:34 +00:00
|
|
|
#include <okular/core/annotations.h>
|
|
|
|
|
2008-04-13 16:40:47 +00:00
|
|
|
#include "popplerembeddedfile.h"
|
|
|
|
#include "config-okular-poppler.h"
|
|
|
|
|
2008-04-13 16:20:21 +00:00
|
|
|
Q_DECLARE_METATYPE( Poppler::Annotation* )
|
|
|
|
|
|
|
|
static void disposeAnnotation( const Okular::Annotation *ann )
|
|
|
|
{
|
|
|
|
Poppler::Annotation *popplerAnn = qvariant_cast< Poppler::Annotation * >( ann->nativeId() );
|
|
|
|
delete popplerAnn;
|
|
|
|
}
|
|
|
|
|
2008-04-13 16:17:33 +00:00
|
|
|
Okular::Annotation* createAnnotationFromPopplerAnnotation( Poppler::Annotation *ann, bool *doDelete )
|
2008-04-13 15:57:34 +00:00
|
|
|
{
|
|
|
|
Okular::Annotation *annotation = 0;
|
|
|
|
*doDelete = true;
|
2008-04-13 16:20:21 +00:00
|
|
|
bool tieToOkularAnn = false;
|
2008-04-13 15:57:34 +00:00
|
|
|
switch ( ann->subType() )
|
|
|
|
{
|
2008-04-13 16:40:47 +00:00
|
|
|
#ifdef HAVE_POPPLER_0_9
|
|
|
|
case Poppler::Annotation::AFileAttachment:
|
|
|
|
{
|
|
|
|
Poppler::FileAttachmentAnnotation * attachann = static_cast< Poppler::FileAttachmentAnnotation * >( ann );
|
|
|
|
Okular::FileAttachmentAnnotation * f = new Okular::FileAttachmentAnnotation();
|
|
|
|
annotation = f;
|
|
|
|
tieToOkularAnn = true;
|
|
|
|
*doDelete = false;
|
|
|
|
|
|
|
|
f->setFileIconName( attachann->fileIconName() );
|
|
|
|
f->setEmbeddedFile( new PDFEmbeddedFile( attachann->embeddedFile() ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2008-04-13 15:57:34 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
// this is uber ugly but i don't know a better way to do it without introducing a poppler::annotation dependency on core
|
|
|
|
QDomDocument doc;
|
|
|
|
QDomElement root = doc.createElement( "root" );
|
|
|
|
doc.appendChild( root );
|
|
|
|
Poppler::AnnotationUtils::storeAnnotation( ann, root, doc );
|
|
|
|
annotation = Okular::AnnotationUtils::createAnnotation( root );
|
|
|
|
return annotation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( annotation )
|
|
|
|
{
|
|
|
|
annotation->setAuthor( ann->author() );
|
|
|
|
annotation->setContents( ann->contents() );
|
|
|
|
annotation->setUniqueName( ann->uniqueName() );
|
|
|
|
annotation->setModificationDate( ann->modificationDate() );
|
|
|
|
annotation->setCreationDate( ann->creationDate() );
|
|
|
|
annotation->setFlags( ann->flags() );
|
|
|
|
annotation->setBoundingRectangle( Okular::NormalizedRect::fromQRectF( ann->boundary() ) );
|
|
|
|
// TODO clone style
|
|
|
|
// TODO clone window
|
|
|
|
// TODO clone revisions
|
2008-04-13 16:20:21 +00:00
|
|
|
if ( tieToOkularAnn )
|
|
|
|
{
|
|
|
|
annotation->setNativeId( qVariantFromValue( ann ) );
|
|
|
|
annotation->setDisposeDataFunction( disposeAnnotation );
|
|
|
|
}
|
2008-04-13 15:57:34 +00:00
|
|
|
}
|
|
|
|
return annotation;
|
|
|
|
}
|