Okular

movie.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Pino Toscano <[email protected]>
3  SPDX-FileCopyrightText: 2012 Guillermo A. Amaral B. <[email protected]>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "movie.h"
9 
10 // qt/kde includes
11 #include <QDir>
12 #include <QImage>
13 #include <QString>
14 #include <QTemporaryFile>
15 
16 #include <QDebug>
17 
18 #include "debug_p.h"
19 
20 using namespace Okular;
21 
22 class Movie::Private
23 {
24 public:
25  explicit Private(const QString &url)
26  : m_url(url)
27  , m_rotation(Rotation0)
28  , m_playMode(PlayLimited)
29  , m_playRepetitions(1.0)
30  , m_tmp(nullptr)
31  , m_showControls(false)
32  , m_autoPlay(false)
33  , m_startPaused(false)
34  , m_showPosterImage(false)
35  {
36  }
37 
38  QString m_url;
39  QSize m_aspect;
40  Rotation m_rotation;
41  PlayMode m_playMode;
42  double m_playRepetitions;
43  QTemporaryFile *m_tmp;
44  QImage m_posterImage;
45  bool m_showControls : 1;
46  bool m_autoPlay : 1;
47  bool m_startPaused : 1;
48  bool m_showPosterImage : 1;
49 };
50 
51 Movie::Movie(const QString &fileName)
52  : d(new Private(fileName))
53 {
54 }
55 
56 Movie::Movie(const QString &fileName, const QByteArray &data)
57  : d(new Private(fileName))
58 {
59  /* Store movie data as temporary file.
60  *
61  * Originally loaded movie data directly using a QBuffer, but sadly phonon
62  * fails to play on a few of my test systems (I think it's the Phonon
63  * GStreamer backend). Storing the data in a temporary file works fine
64  * though, not to mention, it releases much needed memory. (gamaral)
65  */
66  d->m_tmp = new QTemporaryFile(QStringLiteral("%1/okrXXXXXX").arg(QDir::tempPath()));
67  if (d->m_tmp->open()) {
68  d->m_tmp->write(data);
69  d->m_tmp->flush();
70  } else {
71  qCDebug(OkularCoreDebug) << "Failed to create temporary file for video data.";
72  }
73 }
74 
76 {
77  delete d->m_tmp;
78  delete d;
79 }
80 
82 {
83  if (d->m_tmp) {
84  return d->m_tmp->fileName();
85  } else {
86  return d->m_url;
87  }
88 }
89 
90 void Movie::setSize(const QSize aspect)
91 {
92  d->m_aspect = aspect;
93 }
94 
96 {
97  return d->m_aspect;
98 }
99 
101 {
102  d->m_rotation = rotation;
103 }
104 
106 {
107  return d->m_rotation;
108 }
109 
110 void Movie::setShowControls(bool show)
111 {
112  d->m_showControls = show;
113 }
114 
116 {
117  return d->m_showControls;
118 }
119 
121 {
122  d->m_playMode = mode;
123 }
124 
126 {
127  return d->m_playMode;
128 }
129 
130 void Movie::setPlayRepetitions(double repetitions)
131 {
132  d->m_playRepetitions = repetitions;
133 }
134 
136 {
137  return d->m_playRepetitions;
138 }
139 
140 void Movie::setAutoPlay(bool autoPlay)
141 {
142  d->m_autoPlay = autoPlay;
143 }
144 
145 bool Movie::autoPlay() const
146 {
147  return d->m_autoPlay;
148 }
149 
150 void Movie::setStartPaused(bool startPaused)
151 {
152  d->m_startPaused = startPaused;
153 }
154 
155 bool Movie::startPaused() const
156 {
157  return d->m_startPaused;
158 }
159 
161 {
162  d->m_showPosterImage = show;
163 }
164 
166 {
167  return d->m_showPosterImage;
168 }
169 
170 void Movie::setPosterImage(const QImage &image)
171 {
172  d->m_posterImage = image;
173 }
174 
176 {
177  return d->m_posterImage;
178 }
void setShowControls(bool show)
Sets whether show a bar with movie controls.
Definition: movie.cpp:110
void setPosterImage(const QImage &image)
Sets the poster image.
Definition: movie.cpp:170
void setPlayMode(PlayMode mode)
Sets the way the movie should be played.
Definition: movie.cpp:120
The documentation to the global Okular namespace.
Definition: action.h:16
bool showControls() const
Whether show a bar with movie controls.
Definition: movie.cpp:115
PlayMode
The play mode for playing the movie.
Definition: movie.h:31
void setSize(const QSize aspect)
Sets the size for the movie.
Definition: movie.cpp:90
Rotation rotation() const
Returns the rotation of the movie.
Definition: movie.cpp:105
void setPlayRepetitions(double repetitions)
Sets how many times the movie should be played.
Definition: movie.cpp:130
QString tempPath()
double playRepetitions() const
How many times to play the movie.
Definition: movie.cpp:135
void setStartPaused(bool startPaused)
Sets whether to start the movie in paused mode.
Definition: movie.cpp:150
QSize size() const
Returns the size of the movie.
Definition: movie.cpp:95
QImage posterImage() const
Returns the poster image.
Definition: movie.cpp:175
bool startPaused() const
Whether to start the movie in paused mode.
Definition: movie.cpp:155
~Movie()
Destroys the movie object.
Definition: movie.cpp:75
@ Rotation0
Not rotated.
Definition: global.h:46
void setShowPosterImage(bool show)
Sets whether to show a poster image.
Definition: movie.cpp:160
QString url() const
Returns the url of the movie.
Definition: movie.cpp:81
@ PlayLimited
Play a fixed amount of times, closing the movie controls at the end.
Definition: movie.h:32
bool showPosterImage() const
Whether to show a poster image.
Definition: movie.cpp:165
Movie(const QString &fileName)
Creates a new movie object with the given external fileName.
Definition: movie.cpp:51
void setRotation(Rotation rotation)
Sets the rotation of the movie.
Definition: movie.cpp:100
void setAutoPlay(bool autoPlay)
Sets whether to play the movie automatically.
Definition: movie.cpp:140
bool autoPlay() const
Whether to play the movie automatically.
Definition: movie.cpp:145
Rotation
A rotation.
Definition: global.h:45
PlayMode playMode() const
How to play the movie.
Definition: movie.cpp:125
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:04:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.