File indexing completed on 2024-04-28 04:32:44
0001 /* 0002 SPDX-FileCopyrightText: 2008 Pino Toscano <pino@kde.org> 0003 SPDX-FileCopyrightText: 2012 Guillermo A. Amaral B. <gamaral@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "movie.h" 0009 0010 // qt/kde includes 0011 #include <QDir> 0012 #include <QImage> 0013 #include <QString> 0014 #include <QTemporaryFile> 0015 0016 #include <QDebug> 0017 0018 #include "debug_p.h" 0019 0020 using namespace Okular; 0021 0022 class Movie::Private 0023 { 0024 public: 0025 explicit Private(const QString &url) 0026 : m_url(url) 0027 , m_rotation(Rotation0) 0028 , m_playMode(PlayLimited) 0029 , m_playRepetitions(1.0) 0030 , m_tmp(nullptr) 0031 , m_showControls(false) 0032 , m_autoPlay(false) 0033 , m_startPaused(false) 0034 , m_showPosterImage(false) 0035 { 0036 } 0037 0038 QString m_url; 0039 QSize m_aspect; 0040 Rotation m_rotation; 0041 PlayMode m_playMode; 0042 double m_playRepetitions; 0043 QTemporaryFile *m_tmp; 0044 QImage m_posterImage; 0045 bool m_showControls : 1; 0046 bool m_autoPlay : 1; 0047 bool m_startPaused : 1; 0048 bool m_showPosterImage : 1; 0049 }; 0050 0051 Movie::Movie(const QString &fileName) 0052 : d(new Private(fileName)) 0053 { 0054 } 0055 0056 Movie::Movie(const QString &fileName, const QByteArray &data) 0057 : d(new Private(fileName)) 0058 { 0059 /* Store movie data as temporary file. 0060 * 0061 * Originally loaded movie data directly using a QBuffer, but sadly phonon 0062 * fails to play on a few of my test systems (I think it's the Phonon 0063 * GStreamer backend). Storing the data in a temporary file works fine 0064 * though, not to mention, it releases much needed memory. (gamaral) 0065 */ 0066 d->m_tmp = new QTemporaryFile(QStringLiteral("%1/okrXXXXXX").arg(QDir::tempPath())); 0067 if (d->m_tmp->open()) { 0068 d->m_tmp->write(data); 0069 d->m_tmp->flush(); 0070 } else { 0071 qCDebug(OkularCoreDebug) << "Failed to create temporary file for video data."; 0072 } 0073 } 0074 0075 Movie::~Movie() 0076 { 0077 delete d->m_tmp; 0078 delete d; 0079 } 0080 0081 QString Movie::url() const 0082 { 0083 if (d->m_tmp) { 0084 return d->m_tmp->fileName(); 0085 } else { 0086 return d->m_url; 0087 } 0088 } 0089 0090 void Movie::setSize(const QSize aspect) 0091 { 0092 d->m_aspect = aspect; 0093 } 0094 0095 QSize Movie::size() const 0096 { 0097 return d->m_aspect; 0098 } 0099 0100 void Movie::setRotation(Rotation rotation) 0101 { 0102 d->m_rotation = rotation; 0103 } 0104 0105 Rotation Movie::rotation() const 0106 { 0107 return d->m_rotation; 0108 } 0109 0110 void Movie::setShowControls(bool show) 0111 { 0112 d->m_showControls = show; 0113 } 0114 0115 bool Movie::showControls() const 0116 { 0117 return d->m_showControls; 0118 } 0119 0120 void Movie::setPlayMode(Movie::PlayMode mode) 0121 { 0122 d->m_playMode = mode; 0123 } 0124 0125 Movie::PlayMode Movie::playMode() const 0126 { 0127 return d->m_playMode; 0128 } 0129 0130 void Movie::setPlayRepetitions(double repetitions) 0131 { 0132 d->m_playRepetitions = repetitions; 0133 } 0134 0135 double Movie::playRepetitions() const 0136 { 0137 return d->m_playRepetitions; 0138 } 0139 0140 void Movie::setAutoPlay(bool autoPlay) 0141 { 0142 d->m_autoPlay = autoPlay; 0143 } 0144 0145 bool Movie::autoPlay() const 0146 { 0147 return d->m_autoPlay; 0148 } 0149 0150 void Movie::setStartPaused(bool startPaused) 0151 { 0152 d->m_startPaused = startPaused; 0153 } 0154 0155 bool Movie::startPaused() const 0156 { 0157 return d->m_startPaused; 0158 } 0159 0160 void Movie::setShowPosterImage(bool show) 0161 { 0162 d->m_showPosterImage = show; 0163 } 0164 0165 bool Movie::showPosterImage() const 0166 { 0167 return d->m_showPosterImage; 0168 } 0169 0170 void Movie::setPosterImage(const QImage &image) 0171 { 0172 d->m_posterImage = image; 0173 } 0174 0175 QImage Movie::posterImage() const 0176 { 0177 return d->m_posterImage; 0178 }