poppler-movie.cc 4.62 KB
Newer Older
1 2 3 4
/* poppler-movie.cc: glib interface to Movie
 *
 * Copyright (C) 2010 Carlos Garcia Campos <carlosgc@gnome.org>
 * Copyright (C) 2008 Hugo Mercier <hmercier31[@]gmail.com>
5
 * Copyright (C) 2017 Francesco Poli <invernomuto@paranoici.org>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "poppler-movie.h"
#include "poppler-private.h"

25 26 27 28 29 30
/**
 * SECTION: poppler-movie
 * @short_description: Movies
 * @title: PopplerMovie
 */

31 32 33 34 35 36 37 38 39
typedef struct _PopplerMovieClass PopplerMovieClass;

struct _PopplerMovie
{
  GObject   parent_instance;

  gchar   *filename;
  gboolean need_poster;
  gboolean show_controls;
40
  PopplerMoviePlayMode mode;
41 42 43 44 45 46 47
};

struct _PopplerMovieClass
{
  GObjectClass parent_class;
};

Albert Astals Cid's avatar
Albert Astals Cid committed
48
G_DEFINE_TYPE (PopplerMovie, poppler_movie, G_TYPE_OBJECT)
49 50 51 52 53 54 55 56

static void
poppler_movie_finalize (GObject *object)
{
  PopplerMovie* movie = POPPLER_MOVIE(object);

  if (movie->filename) {
    g_free (movie->filename);
57
    movie->filename = nullptr;
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  }

  G_OBJECT_CLASS (poppler_movie_parent_class)->finalize (object);
}

static void
poppler_movie_class_init (PopplerMovieClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

  gobject_class->finalize = poppler_movie_finalize;
}

static void
poppler_movie_init (PopplerMovie *movie)
{
}

PopplerMovie *
Albert Astals Cid's avatar
Albert Astals Cid committed
77
_poppler_movie_new (const Movie *poppler_movie)
78 79 80
{
  PopplerMovie *movie;

81
  g_assert (poppler_movie != nullptr);
82

83
  movie = POPPLER_MOVIE (g_object_new (POPPLER_TYPE_MOVIE, nullptr));
84 85 86

  movie->filename = g_strdup (poppler_movie->getFileName()->getCString());
  if (poppler_movie->getShowPoster()) {
Albert Astals Cid's avatar
Albert Astals Cid committed
87
    Object tmp = poppler_movie->getPoster();
88 89 90 91 92
    movie->need_poster = (!tmp.isRef() && !tmp.isStream());
  }

  movie->show_controls = poppler_movie->getActivationParameters()->showControls;

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
  switch (poppler_movie->getActivationParameters()->repeatMode) {
  case MovieActivationParameters::repeatModeOnce:
    movie->mode = POPPLER_MOVIE_PLAY_MODE_ONCE;
    break;
  case MovieActivationParameters::repeatModeOpen:
    movie->mode = POPPLER_MOVIE_PLAY_MODE_OPEN;
    break;
  case MovieActivationParameters::repeatModeRepeat:
    movie->mode = POPPLER_MOVIE_PLAY_MODE_REPEAT;
    break;
  case MovieActivationParameters::repeatModePalindrome:
    movie->mode = POPPLER_MOVIE_PLAY_MODE_PALINDROME;
    break;
  }

108 109 110 111 112 113 114 115 116 117 118
  return movie;
}

/**
* poppler_movie_get_filename:
* @poppler_movie: a #PopplerMovie
*
* Returns the local filename identifying a self-describing movie file
*
* Return value: a local filename, return value is owned by #PopplerMovie and
*               should not be freed
119 120
*
* Since: 0.14
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
*/
const gchar *
poppler_movie_get_filename (PopplerMovie *poppler_movie)
{
  g_return_val_if_fail (POPPLER_IS_MOVIE (poppler_movie), NULL);

  return poppler_movie->filename;
}

/**
 * poppler_movie_need_poster:
 * @poppler_movie: a #PopplerMovie
 *
 * Returns whether a poster image representing the Movie
 * shall be displayed. The poster image must be retrieved
 * from the movie file.
 *
 * Return value: %TRUE if move needs a poster image, %FALSE otherwise
139 140
 *
 * Since: 0.14
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
 */
gboolean
poppler_movie_need_poster (PopplerMovie *poppler_movie)
{
  g_return_val_if_fail (POPPLER_IS_MOVIE (poppler_movie), FALSE);

  return poppler_movie->need_poster;
}

/**
 * poppler_movie_show_controls:
 * @poppler_movie: a #PopplerMovie
 *
 * Returns whether to display a movie controller bar while playing the movie
 *
 * Return value: %TRUE if controller bar should be displayed, %FALSE otherwise
157 158
 *
 * Since: 0.14
159 160 161 162 163 164 165 166
 */
gboolean
poppler_movie_show_controls (PopplerMovie *poppler_movie)
{
  g_return_val_if_fail (POPPLER_IS_MOVIE (poppler_movie), FALSE);

  return poppler_movie->show_controls;
}
167 168 169 170 171 172 173

/**
 * poppler_movie_get_play_mode:
 * @poppler_movie: a #PopplerMovie
 *
 * Returns the play mode of @poppler_movie.
 *
174
 * Return value: a #PopplerMoviePlayMode.
175 176 177 178 179 180 181 182 183 184
 *
 * Since: 0.54
 */
PopplerMoviePlayMode
poppler_movie_get_play_mode (PopplerMovie *poppler_movie)
{
  g_return_val_if_fail (POPPLER_IS_MOVIE (poppler_movie), POPPLER_MOVIE_PLAY_MODE_ONCE);

  return poppler_movie->mode;
}