[gnome-initial-setup] Add a movie player for the welcome tour



commit 45efc36b07978095baff309d695fc5b67c109242
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Nov 12 08:09:15 2012 -0500

    Add a movie player for the welcome tour
    
    This code had a very brief existence in gnome-getting-started-docs,
    but it is nicer to keep the code in this module, and just the docs
    over there.

 Makefile.am             |    2 +-
 configure.ac            |    3 +
 data/gnome-welcome-tour |    2 +-
 player/Makefile.am      |    6 ++
 player/player.c         |  187 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 198 insertions(+), 2 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index ee1b61e..85f71ee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 
-SUBDIRS = data gnome-initial-setup po
+SUBDIRS = data gnome-initial-setup player po
 
 EXTRA_DIST = \
     autogen.sh \
diff --git a/configure.ac b/configure.ac
index 8cc41b4..0ee932f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,6 +109,8 @@ INITIAL_SETUP_CFLAGS="$INITIAL_SETUP_CFLAGS $GLIB_VERSION_DEFINES"
 AC_SUBST(INITIAL_SETUP_CFLAGS)
 AC_SUBST(INITIAL_SETUP_LIBS)
 
+PKG_CHECK_MODULES(PLAYER, [clutter-gst-1.0 clutter-x11-1.0])
+
 if test "$GCC" = "yes"; then
         CFLAGS="\
         -Wall \
@@ -135,5 +137,6 @@ gnome-initial-setup/pages/network/Makefile
 gnome-initial-setup/pages/goa/Makefile
 gnome-initial-setup/pages/summary/Makefile
 po/Makefile.in
+player/Makefile
 ])
 AC_OUTPUT
diff --git a/data/gnome-welcome-tour b/data/gnome-welcome-tour
index b7b0a79..dcebd7d 100755
--- a/data/gnome-welcome-tour
+++ b/data/gnome-welcome-tour
@@ -24,5 +24,5 @@ for name in $locale $lang 'C'; do
         fi
 done
 
-/usr/libexec/gnome-simple-player $intro_path/figures/yelp-intro0001-0535.ogg &
+/usr/libexec/gnome-initial-setup-player $intro_path/figures/yelp-intro0001-0535.ogg &
 yelp help:getting-started
diff --git a/player/Makefile.am b/player/Makefile.am
new file mode 100644
index 0000000..2fe8b90
--- /dev/null
+++ b/player/Makefile.am
@@ -0,0 +1,6 @@
+
+libexec_PROGRAMS = gnome-initial-setup-player
+
+gnome_initial_setup_player_SOURCES = player.c
+gnome_initial_setup_player_CFLAGS = $(PLAYER_CFLAGS) -DCLUTTER_DISABLE_DEPRECATION_WARNINGS
+gnome_initial_setup_player_LDFLAGS = $(PLAYER_LIBS)
diff --git a/player/player.c b/player/player.c
new file mode 100644
index 0000000..06c2351
--- /dev/null
+++ b/player/player.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2012 Red Hat
+ *
+ * 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 of the
+ * License, 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., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ *     Jasper St. Pierre <jstpierre mecheye net>
+ *
+ * Based on examples/video-player.c in clutter-gst sources
+ *     Copyright 2007,2008 OpenedHand
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+
+#include <clutter/clutter.h>
+#include <clutter/x11/clutter-x11.h>
+#include <clutter-gst/clutter-gst.h>
+
+#define FADE_OUT_TIME 500
+#define BG_COLOR "#d3d8ce"
+static ClutterColor bg_color;
+
+static ClutterActor *stage;
+
+static void
+fade_out (ClutterActor *actor)
+{
+  clutter_actor_save_easing_state (actor);
+  clutter_actor_set_easing_duration (actor, FADE_OUT_TIME);
+  clutter_actor_set_opacity (actor, 0);
+  clutter_actor_restore_easing_state (actor);
+}
+
+static void
+fade_out_and_quit (void)
+{
+  fade_out (stage);
+  g_signal_connect (stage, "transitions-completed",
+                    G_CALLBACK (clutter_main_quit), NULL);
+}
+
+static void
+on_video_texture_eos (ClutterMedia *media)
+{
+  fade_out_and_quit ();
+}
+
+static gboolean
+key_press_cb (ClutterActor *stage,
+              ClutterEvent *event)
+{
+  switch (clutter_event_get_key_symbol ( (event)))
+    {
+    case CLUTTER_Escape:
+      clutter_actor_destroy (stage);
+      break;
+    }
+
+  return TRUE;
+}
+
+/* XXX: not sure how to keep the frame data on screen during
+ * fade out, so just have a solid idle material for now. */
+static void
+set_idle_material (ClutterGstVideoTexture *video_texture)
+{
+  CoglColor transparent;
+  CoglHandle material;
+
+  cogl_color_init_from_4ub (&transparent, 0, 0, 0, 0);
+  material = cogl_material_new ();
+  cogl_material_set_color (material, &transparent);
+  clutter_gst_video_texture_set_idle_material (video_texture, material);
+  cogl_handle_unref (material);
+}
+
+static void
+set_above_and_fullscreen (void)
+{
+  Display *dpy = clutter_x11_get_default_display ();
+  Window win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
+  char *atom_names[2] = {
+    "_NET_WM_STATE_FULLSCREEN",
+    "_NET_WM_STATE_ABOVE",
+  };
+  Atom states[G_N_ELEMENTS (atom_names)];
+
+  XInternAtoms (dpy, atom_names, G_N_ELEMENTS (atom_names),
+                False, states);
+
+  XChangeProperty (dpy, win,
+                   XInternAtom (dpy, "_NET_WM_STATE", False),
+                   XA_ATOM, 32, PropModeReplace,
+                   (unsigned char *) states, G_N_ELEMENTS (atom_names));
+}
+
+int
+main (int argc, char *argv[])
+{
+  ClutterActor *video;
+
+  /* So we can fade out at the end. */
+  clutter_x11_set_use_argb_visual (TRUE);
+
+  if (clutter_gst_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
+    return EXIT_FAILURE;
+
+  if (argc < 2)
+    {
+      g_print ("Usage: %s [OPTIONS] <video file>\n", argv[0]);
+      return EXIT_FAILURE;
+    }
+
+  if (!clutter_color_from_string (&bg_color, BG_COLOR))
+    {
+      g_warning ("Invalid BG_COLOR");
+      exit (1);
+    }
+
+  stage = clutter_stage_new ();
+
+  /* Clutter's full-screening code does not allow us to
+   * set both that and _NET_WM_STATE_ABOVE, so do the state
+   * management ourselves for now. */
+#if 0
+  clutter_stage_set_fullscreen (CLUTTER_STAGE (stage), TRUE);
+#endif
+
+  /* Clutter will set maximum size restrictions (meaning not
+   * full screen) unless I set this. */
+  clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
+
+  clutter_stage_set_use_alpha (CLUTTER_STAGE (stage), TRUE);
+
+  clutter_actor_set_background_color (stage, &bg_color);
+  clutter_actor_set_layout_manager (stage,
+                                    clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FIXED,
+                                                            CLUTTER_BIN_ALIGNMENT_FIXED));
+
+  clutter_actor_realize (stage);
+  set_above_and_fullscreen ();
+
+  video = clutter_gst_video_texture_new ();
+  clutter_actor_set_x_expand (video, TRUE);
+  clutter_actor_set_y_expand (video, TRUE);
+  clutter_actor_set_x_align (video, CLUTTER_ACTOR_ALIGN_CENTER);
+  clutter_actor_set_y_align (video, CLUTTER_ACTOR_ALIGN_CENTER);
+  set_idle_material (CLUTTER_GST_VIDEO_TEXTURE (video));
+
+  g_signal_connect (video,
+                    "eos",
+                    G_CALLBACK (on_video_texture_eos),
+                    NULL);
+
+  g_signal_connect (stage,
+                    "destroy",
+                    G_CALLBACK (clutter_main_quit),
+                    NULL);
+
+  clutter_media_set_filename (CLUTTER_MEDIA (video), argv[1]);
+  clutter_stage_hide_cursor (CLUTTER_STAGE (stage));
+
+  clutter_actor_add_child (stage, video);
+
+  g_signal_connect (stage, "key-press-event", G_CALLBACK (key_press_cb), NULL);
+
+  clutter_media_set_playing (CLUTTER_MEDIA (video), TRUE);
+  clutter_actor_show (stage);
+  clutter_main ();
+
+  return EXIT_SUCCESS;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]