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  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_showPosterImage(false)
34  {
35  }
36 
37  QString m_url;
38  QSize m_aspect;
39  Rotation m_rotation;
40  PlayMode m_playMode;
41  double m_playRepetitions;
42  QTemporaryFile *m_tmp;
43  QImage m_posterImage;
44  bool m_showControls : 1;
45  bool m_autoPlay : 1;
46  bool m_showPosterImage : 1;
47 };
48 
49 Movie::Movie(const QString &fileName)
50  : d(new Private(fileName))
51 {
52 }
53 
54 Movie::Movie(const QString &fileName, const QByteArray &data)
55  : d(new Private(fileName))
56 {
57  /* Store movie data as temporary file.
58  *
59  * Originally loaded movie data directly using a QBuffer, but sadly phonon
60  * fails to play on a few of my test systems (I think it's the Phonon
61  * GStreamer backend). Storing the data in a temporary file works fine
62  * though, not to mention, it releases much needed memory. (gamaral)
63  */
64  d->m_tmp = new QTemporaryFile(QStringLiteral("%1/okrXXXXXX").arg(QDir::tempPath()));
65  if (d->m_tmp->open()) {
66  d->m_tmp->write(data);
67  d->m_tmp->flush();
68  } else
69  qCDebug(OkularCoreDebug) << "Failed to create temporary file for video data.";
70 }
71 
73 {
74  delete d->m_tmp;
75  delete d;
76 }
77 
79 {
80  if (d->m_tmp)
81  return d->m_tmp->fileName();
82  else
83  return d->m_url;
84 }
85 
86 void Movie::setSize(const QSize &aspect) // clazy:exclude=function-args-by-value TODO remove the & when we do a BIC change elsewhere
87 {
88  d->m_aspect = aspect;
89 }
90 
92 {
93  return d->m_aspect;
94 }
95 
97 {
98  d->m_rotation = rotation;
99 }
100 
102 {
103  return d->m_rotation;
104 }
105 
106 void Movie::setShowControls(bool show)
107 {
108  d->m_showControls = show;
109 }
110 
112 {
113  return d->m_showControls;
114 }
115 
117 {
118  d->m_playMode = mode;
119 }
120 
122 {
123  return d->m_playMode;
124 }
125 
126 void Movie::setPlayRepetitions(double repetitions)
127 {
128  d->m_playRepetitions = repetitions;
129 }
130 
132 {
133  return d->m_playRepetitions;
134 }
135 
137 {
138  d->m_autoPlay = autoPlay;
139 }
140 
141 bool Movie::autoPlay() const
142 {
143  return d->m_autoPlay;
144 }
145 
147 {
148  d->m_showPosterImage = show;
149 }
150 
152 {
153  return d->m_showPosterImage;
154 }
155 
156 void Movie::setPosterImage(const QImage &image)
157 {
158  d->m_posterImage = image;
159 }
160 
162 {
163  return d->m_posterImage;
164 }
Rotation
A rotation.
Definition: global.h:45
Movie(const QString &fileName)
Creates a new movie object with the given external fileName.
Definition: movie.cpp:49
void setSize(const QSize &aspect)
Sets the size for the movie.
Definition: movie.cpp:86
Rotation rotation() const
Returns the rotation of the movie.
Definition: movie.cpp:101
global.h
Definition: action.h:16
void setShowPosterImage(bool show)
Sets whether to show a poster image.
Definition: movie.cpp:146
Not rotated.
Definition: global.h:46
double playRepetitions() const
How many times to play the movie.
Definition: movie.cpp:131
void setPlayMode(PlayMode mode)
Sets the way the movie should be played.
Definition: movie.cpp:116
void setAutoPlay(bool autoPlay)
Sets whether to play the movie automatically.
Definition: movie.cpp:136
bool autoPlay() const
Whether to play the movie automatically.
Definition: movie.cpp:141
QString tempPath()
Play a fixed amount of times, closing the movie controls at the end.
Definition: movie.h:32
~Movie()
Destroys the movie object.
Definition: movie.cpp:72
void setPosterImage(const QImage &image)
Sets the poster image.
Definition: movie.cpp:156
PlayMode
The play mode for playing the movie.
Definition: movie.h:31
bool showControls() const
Whether show a bar with movie controls.
Definition: movie.cpp:111
QSize size() const
Returns the size of the movie.
Definition: movie.cpp:91
void setPlayRepetitions(double repetitions)
Sets how many times the movie should be played.
Definition: movie.cpp:126
PlayMode playMode() const
How to play the movie.
Definition: movie.cpp:121
void setRotation(Rotation rotation)
Sets the rotation of the movie.
Definition: movie.cpp:96
QImage posterImage() const
Returns the poster image.
Definition: movie.cpp:161
void setShowControls(bool show)
Sets whether show a bar with movie controls.
Definition: movie.cpp:106
bool showPosterImage() const
Whether to show a poster image.
Definition: movie.cpp:151
QString url() const
Returns the url of the movie.
Definition: movie.cpp:78
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jul 29 2021 22:36:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.