2021-05-24 07:25:56 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2008 Pino Toscano <pino@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2012 Guillermo A. Amaral B. <gamaral@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2008-08-23 00:07:59 +00:00
|
|
|
|
|
|
|
#include "movie.h"
|
|
|
|
|
|
|
|
// qt/kde includes
|
2020-07-08 11:54:37 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTemporaryFile>
|
2012-03-22 17:35:33 +00:00
|
|
|
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <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
|
|
|
{
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-02-20 17:45:46 +00:00
|
|
|
void Movie::setSize(const QSize &aspect) // clazy:exclude=function-args-by-value TODO remove the & when we do a BIC change elsewhere
|
2008-08-23 00:07:59 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|