2008-08-23 00:07:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
2012-03-22 17:35:33 +00:00
|
|
|
* Copyright (C) 2012 by Guillermo A. Amaral B. <gamaral@kde.org> *
|
2008-08-23 00:07:59 +00:00
|
|
|
* *
|
|
|
|
* 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 "movie.h"
|
|
|
|
|
|
|
|
// qt/kde includes
|
2012-03-22 17:35:33 +00:00
|
|
|
#include <qdir.h>
|
2012-06-29 09:16:28 +00:00
|
|
|
#include <qimage.h>
|
2008-08-23 00:07:59 +00:00
|
|
|
#include <qstring.h>
|
2012-03-22 17:35:33 +00:00
|
|
|
#include <qtemporaryfile.h>
|
|
|
|
|
2014-09-11 19:12:27 +00:00
|
|
|
#include <QtCore/QDebug>
|
2012-03-22 17:35:33 +00:00
|
|
|
|
|
|
|
#include "debug_p.h"
|
2008-08-23 00:07:59 +00:00
|
|
|
|
|
|
|
using namespace Okular;
|
|
|
|
|
|
|
|
class Movie::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private( const QString &url )
|
|
|
|
: m_url( url ),
|
2008-08-24 21:33:23 +00:00
|
|
|
m_rotation( Rotation0 ),
|
2015-09-26 15:29:11 +00:00
|
|
|
m_playMode( PlayLimited ),
|
|
|
|
m_playRepetitions( 1.0 ),
|
2017-09-05 21:27:18 +00:00
|
|
|
m_tmp( nullptr ),
|
2012-03-22 17:35:33 +00:00
|
|
|
m_showControls( false ),
|
2012-06-29 09:16:28 +00:00
|
|
|
m_autoPlay( false ),
|
|
|
|
m_showPosterImage( false )
|
2008-08-23 00:07:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString m_url;
|
|
|
|
QSize m_aspect;
|
|
|
|
Rotation m_rotation;
|
2008-08-24 21:33:23 +00:00
|
|
|
PlayMode m_playMode;
|
2015-09-26 15:29:11 +00:00
|
|
|
double m_playRepetitions;
|
2012-03-22 17:35:33 +00:00
|
|
|
QTemporaryFile *m_tmp;
|
2012-06-29 09:16:28 +00:00
|
|
|
QImage m_posterImage;
|
2008-08-24 21:33:23 +00:00
|
|
|
bool m_showControls : 1;
|
2012-03-22 17:35:33 +00:00
|
|
|
bool m_autoPlay : 1;
|
2012-06-29 09:16:28 +00:00
|
|
|
bool m_showPosterImage : 1;
|
2008-08-23 00:07:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Movie::Movie( const QString& fileName )
|
|
|
|
: d( new Private( fileName ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:35:33 +00:00
|
|
|
Movie::Movie( const QString& fileName, const QByteArray &data )
|
|
|
|
: d( new Private( fileName ) )
|
|
|
|
{
|
|
|
|
/* Store movie data as temporary file.
|
|
|
|
*
|
|
|
|
* Originally loaded movie data directly using a QBuffer, but sadly phonon
|
|
|
|
* fails to play on a few of my test systems (I think it's the Phonon
|
|
|
|
* GStreamer backend). Storing the data in a temporary file works fine
|
|
|
|
* though, not to mention, it releases much needed memory. (gamaral)
|
|
|
|
*/
|
2015-10-29 12:37:11 +00:00
|
|
|
d->m_tmp = new QTemporaryFile( QStringLiteral( "%1/okrXXXXXX" ).arg( QDir::tempPath() ) );
|
2012-03-22 17:35:33 +00:00
|
|
|
if ( d->m_tmp->open() ) {
|
|
|
|
d->m_tmp->write( data );
|
|
|
|
d->m_tmp->flush();
|
|
|
|
}
|
2014-09-11 17:36:01 +00:00
|
|
|
else qCDebug(OkularCoreDebug) << "Failed to create temporary file for video data.";
|
2012-03-22 17:35:33 +00:00
|
|
|
}
|
|
|
|
|
2008-08-23 00:07:59 +00:00
|
|
|
Movie::~Movie()
|
|
|
|
{
|
2012-03-22 17:35:33 +00:00
|
|
|
delete d->m_tmp;
|
2008-08-23 00:07:59 +00:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Movie::url() const
|
|
|
|
{
|
2012-03-22 17:35:33 +00:00
|
|
|
if (d->m_tmp)
|
|
|
|
return d->m_tmp->fileName();
|
|
|
|
else
|
|
|
|
return d->m_url;
|
2008-08-23 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Movie::setSize( const QSize &aspect )
|
|
|
|
{
|
|
|
|
d->m_aspect = aspect;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize Movie::size() const
|
|
|
|
{
|
|
|
|
return d->m_aspect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Movie::setRotation( Rotation rotation )
|
|
|
|
{
|
|
|
|
d->m_rotation = rotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rotation Movie::rotation() const
|
|
|
|
{
|
|
|
|
return d->m_rotation;
|
|
|
|
}
|
2008-08-24 21:33:23 +00:00
|
|
|
|
|
|
|
void Movie::setShowControls( bool show )
|
|
|
|
{
|
|
|
|
d->m_showControls = show;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Movie::showControls() const
|
|
|
|
{
|
|
|
|
return d->m_showControls;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Movie::setPlayMode( Movie::PlayMode mode )
|
|
|
|
{
|
|
|
|
d->m_playMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
Movie::PlayMode Movie::playMode() const
|
|
|
|
{
|
|
|
|
return d->m_playMode;
|
|
|
|
}
|
2012-03-22 17:35:33 +00:00
|
|
|
|
2015-09-26 15:29:11 +00:00
|
|
|
void Movie::setPlayRepetitions( double repetitions )
|
|
|
|
{
|
|
|
|
d->m_playRepetitions = repetitions;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Movie::playRepetitions() const
|
|
|
|
{
|
|
|
|
return d->m_playRepetitions;
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:35:33 +00:00
|
|
|
void Movie::setAutoPlay( bool autoPlay )
|
|
|
|
{
|
|
|
|
d->m_autoPlay = autoPlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Movie::autoPlay() const
|
|
|
|
{
|
|
|
|
return d->m_autoPlay;
|
|
|
|
}
|
|
|
|
|
2012-06-29 09:16:28 +00:00
|
|
|
void Movie::setShowPosterImage( bool show )
|
|
|
|
{
|
|
|
|
d->m_showPosterImage = show;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Movie::showPosterImage() const
|
|
|
|
{
|
|
|
|
return d->m_showPosterImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Movie::setPosterImage( const QImage &image )
|
|
|
|
{
|
|
|
|
d->m_posterImage = image;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage Movie::posterImage() const
|
|
|
|
{
|
|
|
|
return d->m_posterImage;
|
|
|
|
}
|