[gnome-tour/bilelmoussaoui/video] make the video configurable




commit c8cb8a7fb0745faf4dc11a00ab9dd1cba3d96667
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Mon Aug 10 11:25:06 2020 +0200

    make the video configurable
    
    you should be able to configure the video path at build
    time by passing --video_path=absolute_path
    which will be played instead of displaying the LOGO

 Cargo.toml                         |  5 ++
 build-aux/cargo.sh                 |  5 +-
 build-aux/org.gnome.TourDevel.json |  5 +-
 data/resources.gresource.xml       |  1 -
 meson.build                        |  7 ++-
 meson_options.txt                  |  6 +++
 src/config.rs.in                   |  2 +
 src/main.rs                        |  2 +
 src/meson.build                    |  7 ++-
 src/widgets/pages/mod.rs           |  2 -
 src/widgets/pages/welcome.rs       | 57 +++++++++++++++++++++--
 src/widgets/pages/welcome_video.rs | 94 --------------------------------------
 src/widgets/window.rs              |  4 +-
 13 files changed, 85 insertions(+), 112 deletions(-)
---
diff --git a/Cargo.toml b/Cargo.toml
index 5cccfc5..8626c38 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,6 +4,9 @@ version = "0.0.1"
 authors = ["Bilal Elmoussaoui <bil elmoussaoui gmail com>"]
 edition = "2018"
 
+[features]
+video = ["gst_player", "gst"]
+
 [dependencies]
 glib = { version = "0.10", features = ["v2_64"] }
 gdk = "0.13"
@@ -18,7 +21,9 @@ anyhow = "1.0"
 [dependencies.gst_player]
 version = "0.16"
 package = "gstreamer-player"
+optional = true
 
 [dependencies.gst]
 version = "0.16"
 package = "gstreamer"
+optional = true
diff --git a/build-aux/cargo.sh b/build-aux/cargo.sh
index 1a3a2c4..9ffe0ce 100644
--- a/build-aux/cargo.sh
+++ b/build-aux/cargo.sh
@@ -4,17 +4,18 @@ export MESON_BUILD_ROOT="$1"
 export MESON_SOURCE_ROOT="$2"
 export CARGO_TARGET_DIR="$MESON_BUILD_ROOT"/target
 export CARGO_HOME="$CARGO_TARGET_DIR"/cargo-home
+FEATURES="$6"
 
 if [[ $4 = "Devel" ]]
 then
     echo "DEBUG MODE"
     cargo build --manifest-path \
-        "$MESON_SOURCE_ROOT"/Cargo.toml --verbose && \
+        "$MESON_SOURCE_ROOT"/Cargo.toml $FEATURES && \
         cp "$CARGO_TARGET_DIR"/debug/$5 $3
 else
     echo "RELEASE MODE"
     cargo build --manifest-path \
-        "$MESON_SOURCE_ROOT"/Cargo.toml --release && \
+        "$MESON_SOURCE_ROOT"/Cargo.toml $FEATURES --release && \
         cp "$CARGO_TARGET_DIR"/release/$5 $3
 fi
 
diff --git a/build-aux/org.gnome.TourDevel.json b/build-aux/org.gnome.TourDevel.json
index 70534a3..4aa0dfa 100644
--- a/build-aux/org.gnome.TourDevel.json
+++ b/build-aux/org.gnome.TourDevel.json
@@ -15,10 +15,7 @@
         "--socket=fallback-x11",
         "--socket=wayland",
         "--device=dri",
-        "--filesystem=xdg-run/dconf",
-        "--filesystem=~/.config/dconf:ro",
-        "--talk-name=ca.desrt.dconf",
-        "--env=DCONF_USER_CONFIG_DIR=.config/dconf"
+        "--filesystem=home"
     ],
     "build-options" : {
         "append-path" : "/usr/lib/sdk/rust-stable/bin",
diff --git a/data/resources.gresource.xml b/data/resources.gresource.xml
index 19c7242..688446a 100644
--- a/data/resources.gresource.xml
+++ b/data/resources.gresource.xml
@@ -2,7 +2,6 @@
 <gresources>
   <gresource prefix="/org/gnome/Tour/">
       <file compressed="true" alias="style.css">resources/style.css</file>
-      <file alias="welcome.mp4">resources/assets/welcome.mp4</file>
       <file compressed="true" alias="activities.svg">resources/assets/activities.svg</file>
       <file compressed="true" alias="calendar.svg">resources/assets/calendar.svg</file>
       <file compressed="true" alias="search.svg">resources/assets/search.svg</file>
diff --git a/meson.build b/meson.build
index 8261f1e..2c70f9e 100644
--- a/meson.build
+++ b/meson.build
@@ -12,7 +12,12 @@ dependency('glib-2.0', version: '>= 2.64')
 dependency('gio-2.0', version: '>= 2.56')
 dependency('gdk-pixbuf-2.0')
 dependency('gtk+-3.0', version: '>= 3.16')
-
+message(get_option('video_path'))
+if get_option('video_path') != ''
+  dependency('gstreamer-1.0', version: '>= 1.12')
+  dependency('gstreamer-video-1.0', version: '>= 1.12')
+  dependency('gstreamer-player-1.0', version: '>= 1.12')
+endif
 
 glib_compile_resources = find_program('glib-compile-resources', required: true)
 desktop_file_validate = find_program('desktop-file-validate', required: false)
diff --git a/meson_options.txt b/meson_options.txt
index 9163edb..c6a5d3e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -9,3 +9,9 @@ option (
   description: 'The build profile for GNOME Tour. One of "default" or "development".'
 )
 
+option(
+  'video_path',
+  type : 'string',
+  value: '',
+  description : 'Sets the absolute path of a welcome video'
+)
diff --git a/src/config.rs.in b/src/config.rs.in
index d7f8d8f..eaf7c7b 100644
--- a/src/config.rs.in
+++ b/src/config.rs.in
@@ -5,3 +5,5 @@ pub static NAME_SUFFIX: &str = @NAME_SUFFIX@;
 pub static VERSION: &str = @VERSION@;
 pub static GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
 pub static LOCALEDIR: &str = @LOCALEDIR@;
+#[cfg(feature="video")]
+pub static VIDEO_PATH: &str = @VIDEO_PATH@;
diff --git a/src/main.rs b/src/main.rs
index 2370965..70a894d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,7 +25,9 @@ fn main() {
     glib::set_prgname(Some("Tour"));
 
     gtk::init().expect("Unable to start GTK3");
+    #[cfg(feature = "video")]
     gst::init().expect("Unable to start gst");
+
     static_resources::init().expect("Failed to initialize the resource file.");
 
     let app = Application::new();
diff --git a/src/meson.build b/src/meson.build
index 83ea2ca..bb21c2e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -6,6 +6,7 @@ global_conf.set_quoted('NAME_SUFFIX', name_suffix)
 global_conf.set_quoted('VERSION', version + version_suffix)
 global_conf.set_quoted('GETTEXT_PACKAGE', gettext_package)
 global_conf.set_quoted('LOCALEDIR', localedir)
+global_conf.set_quoted('VIDEO_PATH', get_option('video_path'))
 config = configure_file(
   input: 'config.rs.in',
   output: 'config.rs',
@@ -39,7 +40,6 @@ sources = files(
   'widgets/pages/image.rs',
   'widgets/pages/mod.rs',
   'widgets/pages/welcome.rs',
-  'widgets/pages/welcome_video.rs',
   'widgets/mod.rs',
   'widgets/paginator.rs',
   'widgets/window.rs',
@@ -50,6 +50,10 @@ sources = files(
   'utils.rs',
 )
 
+features = ''
+if get_option('video_path') != ''
+  features = '--features video'
+endif
 custom_target(
   'cargo-build',
   build_by_default: true,
@@ -66,6 +70,7 @@ custom_target(
     '@OUTPUT@',
     profile,
     meson.project_name(),
+    features
   ]
 )
 
diff --git a/src/widgets/pages/mod.rs b/src/widgets/pages/mod.rs
index 259a734..4c7ee37 100644
--- a/src/widgets/pages/mod.rs
+++ b/src/widgets/pages/mod.rs
@@ -1,7 +1,5 @@
 mod image;
 mod welcome;
-mod welcome_video;
 
 pub use image::ImagePageWidget;
 pub use welcome::WelcomePageWidget;
-pub use welcome_video::WelcomeVideoPageWidget;
diff --git a/src/widgets/pages/welcome.rs b/src/widgets/pages/welcome.rs
index b645c3b..32dca9c 100644
--- a/src/widgets/pages/welcome.rs
+++ b/src/widgets/pages/welcome.rs
@@ -1,4 +1,8 @@
+#[cfg(feature = "video")]
+use crate::config;
 use gettextrs::gettext;
+#[cfg(feature = "video")]
+use gio::FileExt;
 use gtk::prelude::*;
 
 pub struct WelcomePageWidget {
@@ -14,6 +18,52 @@ impl WelcomePageWidget {
         welcome_page
     }
 
+    #[cfg(not(feature = "video"))]
+    fn get_header_widget(&self) -> gtk::Widget {
+        let icon = glib::get_os_info("LOGO").unwrap_or_else(|| "start-here-symbolic".into());
+
+        let logo = gtk::Image::from_icon_name(Some(&icon), gtk::IconSize::Dialog);
+        logo.set_pixel_size(196);
+        logo.show();
+
+        logo.upcast::<gtk::Widget>()
+    }
+
+    #[cfg(feature = "video")]
+    fn get_header_widget(&self) -> gtk::Widget {
+        let dispatcher = gst_player::PlayerGMainContextSignalDispatcher::new(None);
+        let sink = gst::ElementFactory::make("gtksink", None).expect("Missing dependency: element gtksink is 
needed (usually, in gstreamer-plugins-good or in gst-plugin-gtk).");
+        let renderer = gst_player::PlayerVideoOverlayVideoRenderer::with_sink(&sink).upcast();
+        let player = gst_player::Player::new(Some(&renderer), 
Some(&dispatcher.upcast::<gst_player::PlayerSignalDispatcher>()));
+
+        let video_file = gio::File::new_for_path(config::VIDEO_PATH);
+        player.set_uri(&video_file.get_uri());
+
+        let video_widget = player
+            .get_pipeline()
+            .get_property("video-sink")
+            .unwrap()
+            .get::<gst::Element>()
+            .expect("The player of a VideoPlayerWidget should not use the default sink.")
+            .unwrap()
+            .get_property("widget")
+            .unwrap()
+            .get::<gtk::Widget>()
+            .unwrap()
+            .unwrap();
+
+        video_widget.set_size_request(-1, 300);
+        video_widget.set_property("ignore-alpha", &false).unwrap();
+        video_widget.show();
+
+        gtk::idle_add(clone!(@strong player => move || {
+            player.play();
+            glib::Continue(true)
+        }));
+
+        video_widget
+    }
+
     fn init(&self) {
         self.widget.set_property_expand(true);
         self.widget.set_valign(gtk::Align::Center);
@@ -23,12 +73,9 @@ impl WelcomePageWidget {
 
         let name = glib::get_os_info("NAME").unwrap_or_else(|| "GNOME".into());
         let version = glib::get_os_info("VERSION").unwrap_or_else(|| "3.36".into());
-        let icon = glib::get_os_info("LOGO").unwrap_or_else(|| "start-here-symbolic".into());
 
-        let logo = gtk::Image::from_icon_name(Some(&icon), gtk::IconSize::Dialog);
-        logo.set_pixel_size(196);
-        logo.show();
-        self.widget.add(&logo);
+        let header = self.get_header_widget();
+        self.widget.add(&header);
 
         let title = gtk::Label::new(Some(&gettext(format!("Welcome to {} {}", name, version))));
         title.set_margin_top(36);
diff --git a/src/widgets/window.rs b/src/widgets/window.rs
index 6a0d04f..1f79740 100644
--- a/src/widgets/window.rs
+++ b/src/widgets/window.rs
@@ -4,7 +4,7 @@ use gtk::prelude::*;
 use std::cell::RefCell;
 use std::rc::Rc;
 
-use super::pages::{ImagePageWidget, WelcomePageWidget, WelcomeVideoPageWidget};
+use super::pages::{ImagePageWidget, WelcomePageWidget};
 use super::paginator::PaginatorWidget;
 use crate::config::{APP_ID, PROFILE};
 
@@ -42,7 +42,7 @@ impl Window {
         if PROFILE == "Devel" {
             self.widget.get_style_context().add_class("devel");
         }
-        self.paginator.borrow_mut().add_page(WelcomeVideoPageWidget::new().widget.upcast::<gtk::Widget>());
+        self.paginator.borrow_mut().add_page(WelcomePageWidget::new().widget.upcast::<gtk::Widget>());
 
         self.paginator.borrow_mut().add_page(
             ImagePageWidget::new(


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