diff --git a/core/movie.cpp b/core/movie.cpp index 8c7ffa5..57fb1de 100644 --- a/core/movie.cpp +++ b/core/movie.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2008 by Pino Toscano * + * Copyright (C) 2012 by Guillermo A. Amaral B. * * * * 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 * @@ -10,6 +11,7 @@ #include "movie.h" // qt/kde includes +#include #include using namespace Okular; @@ -21,7 +23,8 @@ class Movie::Private : m_url( url ), m_rotation( Rotation0 ), m_playMode( PlayOnce ), - m_showControls( false ) + m_showControls( false ), + m_autoPlay( false ) { } @@ -29,7 +32,9 @@ class Movie::Private QSize m_aspect; Rotation m_rotation; PlayMode m_playMode; + QByteArray m_data; bool m_showControls : 1; + bool m_autoPlay : 1; }; Movie::Movie( const QString& fileName ) @@ -47,6 +52,16 @@ QString Movie::url() const return d->m_url; } +void Movie::setData( const QByteArray &data ) +{ + d->m_data = data; +} + +const QByteArray & Movie::data() const +{ + return d->m_data; +} + void Movie::setSize( const QSize &aspect ) { d->m_aspect = aspect; @@ -86,3 +101,14 @@ Movie::PlayMode Movie::playMode() const { return d->m_playMode; } + +void Movie::setAutoPlay( bool autoPlay ) +{ + d->m_autoPlay = autoPlay; +} + +bool Movie::autoPlay() const +{ + return d->m_autoPlay; +} + diff --git a/core/movie.h b/core/movie.h index f4b64e1..d92994d 100644 --- a/core/movie.h +++ b/core/movie.h @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2008 by Pino Toscano * + * Copyright (C) 2012 by Guillermo A. Amaral B. * * * * 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 * @@ -52,6 +53,18 @@ class OKULAR_EXPORT Movie QString url() const; /** + * Sets the movie data to be used instead of the file name. + * \optional + */ + void setData( const QByteArray &data ); + + /** + * Returns the movie data to be used instead of the file name. + * \optional + */ + const QByteArray & data() const; + + /** * Sets the size for the movie. */ void setSize( const QSize &aspect ); @@ -91,6 +104,16 @@ class OKULAR_EXPORT Movie */ PlayMode playMode() const; + /** + * Sets whether to play the movie automatically + */ + void setAutoPlay( bool autoPlay ); + + /** + * Whether to play the movie automatically + */ + bool autoPlay() const; + private: class Private; Private* const d; diff --git a/generators/poppler/annots.cpp b/generators/poppler/annots.cpp index 2944b64..1b6fa2f 100644 --- a/generators/poppler/annots.cpp +++ b/generators/poppler/annots.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2008 by Pino Toscano * + * Copyright (C) 2012 by Guillermo A. Amaral B. * * * * 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 * @@ -21,6 +22,7 @@ Q_DECLARE_METATYPE( Poppler::Annotation* ) extern Okular::Sound* createSoundFromPopplerSound( const Poppler::SoundObject *popplerSound ); extern Okular::Movie* createMovieFromPopplerMovie( const Poppler::MovieObject *popplerMovie ); +extern Okular::Movie* createMovieFromPopplerScreen( const Poppler::LinkRendition *popplerScreen ); static void disposeAnnotation( const Okular::Annotation *ann ) { @@ -69,6 +71,16 @@ Okular::Annotation* createAnnotationFromPopplerAnnotation( Poppler::Annotation * break; } + case Poppler::Annotation::AScreen: + { + Poppler::ScreenAnnotation * screenann = static_cast< Poppler::ScreenAnnotation * >( ann ); + Okular::MovieAnnotation * m = new Okular::MovieAnnotation(); + annotation = m; + + m->setMovie( createMovieFromPopplerScreen( screenann->action() ) ); + + break; + } default: { // this is uber ugly but i don't know a better way to do it without introducing a poppler::annotation dependency on core diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index 391d304..1b6c65e 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -1,6 +1,7 @@ /*************************************************************************** * Copyright (C) 2004-2008 by Albert Astals Cid * * Copyright (C) 2004 by Enrico Ros * + * Copyright (C) 2012 by Guillermo A. Amaral B. * * * * 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 * @@ -45,6 +46,8 @@ #include +#include + #include "formfields.h" #include "popplerembeddedfile.h" @@ -151,6 +154,18 @@ Okular::Movie* createMovieFromPopplerMovie( const Poppler::MovieObject *popplerM return movie; } +Okular::Movie* createMovieFromPopplerScreen( const Poppler::LinkRendition *popplerScreen ) +{ + Poppler::MediaRendition *rendition = popplerScreen->rendition(); + Okular::Movie *movie = new Okular::Movie( rendition->fileName() ); + movie->setData( rendition->data() ); + movie->setSize( rendition->size() ); + movie->setShowControls( rendition->showControls() ); + movie->setPlayMode( Okular::Movie::PlayOnce ); + movie->setAutoPlay( rendition->autoPlay() ); + return movie; +} + Okular::Action* createLinkFromPopplerLink(const Poppler::Link *popplerLink) { Okular::Action *link = 0; @@ -215,6 +230,10 @@ Okular::Action* createLinkFromPopplerLink(const Poppler::Link *popplerLink) } break; + case Poppler::Link::Rendition: + // not implemented + break; + case Poppler::Link::Movie: // not implemented break; diff --git a/ui/videowidget.cpp b/ui/videowidget.cpp index 2a48772..667c302 100644 --- a/ui/videowidget.cpp +++ b/ui/videowidget.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2008 by Pino Toscano * + * Copyright (C) 2012 by Guillermo A. Amaral B. * * * * 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 * @@ -15,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -89,6 +91,26 @@ void VideoWidget::Private::load() loaded = true; QString url = anno->movie()->url(); + + /* Load existing movie data if available + * + * Originally loaded data directly using a QBuffer, but sadly phonon fails + * to play on a few of my test systems. Storing the data in a temporary + * file works fine though. (gamaral) + */ + if ( !anno->movie()->data().isEmpty() ) + { + QTemporaryFile *tmp = new QTemporaryFile( q ); + + if (tmp->open()) + { + url = tmp->fileName(); + tmp->write( anno->movie()->data() ); + tmp->flush(); + } + else qDebug("Failed to create a temporary file movie data."); + } + KUrl newurl; if ( QDir::isRelativePath( url ) ) { @@ -105,6 +127,10 @@ void VideoWidget::Private::load() player->load( newurl ); seekSlider->setEnabled( true ); + + /* XXX: should we trigger on first show? (gamaral) */ + if (anno->movie()->autoPlay()) + q->play(); } void VideoWidget::Private::setupPlayPauseAction( PlayPauseMode mode )