diff options
author | Bastien Nocera <hadess@hadess.net> | 2022-02-08 15:22:47 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-02-08 15:54:33 +0100 |
commit | c53d5052ee1183c6fa7d7cc0726d1ad79318b93e (patch) | |
tree | 46c78f8aa8489b96e955bae0d9dbf9c13ff847cc /src/backend | |
parent | 65682262b6b4f6b1507bb917f403e4a36e6a34fd (diff) | |
download | totem-c53d5052ee1183c6fa7d7cc0726d1ad79318b93e.tar.gz |
backend: Use GtkBuilder template
Except for the video widget itself, which requires code.
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/bacon-video-widget.c | 36 | ||||
-rw-r--r-- | src/backend/bacon-video-widget.gresource.xml | 6 | ||||
-rw-r--r-- | src/backend/bacon-video-widget.ui | 35 | ||||
-rw-r--r-- | src/backend/meson.build | 8 |
4 files changed, 66 insertions, 19 deletions
diff --git a/src/backend/bacon-video-widget.c b/src/backend/bacon-video-widget.c index eed9677db..b0e257ea5 100644 --- a/src/backend/bacon-video-widget.c +++ b/src/backend/bacon-video-widget.c @@ -81,6 +81,7 @@ #include "bacon-video-widget.h" #include "bacon-video-widget-gst-missing-plugins.h" #include "bacon-video-widget-enums.h" +#include "bacon-video-widget-resources.h" #define DEFAULT_USER_AGENT "Videos/"VERSION @@ -156,6 +157,12 @@ struct _BaconVideoWidget { GtkOverlay parent; + /* widgets */ + GtkWidget *stack; + GtkWidget *audio_only; + GtkWidget *broken_video; + GtkWidget *video_widget; + char *user_agent; char *referrer; @@ -188,9 +195,6 @@ struct _BaconVideoWidget gboolean got_redirect; - GtkWidget *stack; - GtkWidget *video_widget; - GdkCursor *cursor; /* Visual effects */ @@ -921,6 +925,12 @@ bacon_video_widget_class_init (BaconVideoWidgetClass * klass) 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + g_resources_register (_bvw_get_resource ()); + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/totem/bvw/bacon-video-widget.ui"); + gtk_widget_class_bind_template_child (widget_class, BaconVideoWidget, stack); + gtk_widget_class_bind_template_child (widget_class, BaconVideoWidget, audio_only); + gtk_widget_class_bind_template_child (widget_class, BaconVideoWidget, broken_video); } static void @@ -5305,7 +5315,6 @@ bacon_video_widget_initable_init (GInitable *initable, GstElement *audio_sink = NULL; gchar *version_str; GstPlayFlags flags; - GtkWidget *tmp; GstElement *glsinkbin, *audio_bin; GstPad *audio_pad; char *template; @@ -5333,6 +5342,7 @@ bacon_video_widget_initable_init (GInitable *initable, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK); + gtk_widget_init_template (GTK_WIDGET (bvw)); /* Instantiate all the fallible plugins */ bvw->play = element_make_or_warn ("playbin", "play"); @@ -5380,10 +5390,7 @@ bacon_video_widget_initable_init (GInitable *initable, bvw->cursor_shown = TRUE; - /* Create video output widget and logo */ - bvw->stack = gtk_stack_new (); - gtk_container_add (GTK_CONTAINER (bvw), bvw->stack); - gtk_widget_show (bvw->stack); + /* Create video output widget */ if (is_feature_enabled ("FPS_DISPLAY")) { GstElement *fps; @@ -5394,19 +5401,10 @@ bacon_video_widget_initable_init (GInitable *initable, g_object_set (glsinkbin, "sink", bvw->video_sink, NULL); } g_object_get (bvw->video_sink, "widget", &bvw->video_widget, NULL); - gtk_stack_add_named (GTK_STACK (bvw->stack), bvw->video_widget, "video"); gtk_widget_show (bvw->video_widget); + gtk_stack_add_named (GTK_STACK (bvw->stack), bvw->video_widget, "video"); g_object_unref (bvw->video_widget); - - tmp = gtk_image_new_from_icon_name ("audio-only-symbolic", GTK_ICON_SIZE_DIALOG); - gtk_image_set_pixel_size (GTK_IMAGE (tmp), LOGO_SIZE); - gtk_stack_add_named (GTK_STACK (bvw->stack), tmp, "audio-only"); - gtk_widget_show (tmp); - - tmp = gtk_image_new_from_icon_name ("broken-video-symbolic", GTK_ICON_SIZE_DIALOG); - gtk_image_set_pixel_size (GTK_IMAGE (tmp), LOGO_SIZE); - gtk_stack_add_named (GTK_STACK (bvw->stack), tmp, "broken-video"); - gtk_widget_show (tmp); + gtk_stack_set_visible_child_name (GTK_STACK (bvw->stack), "video"); g_object_set (bvw->video_sink, "rotate-method", GST_VIDEO_ORIENTATION_AUTO, diff --git a/src/backend/bacon-video-widget.gresource.xml b/src/backend/bacon-video-widget.gresource.xml new file mode 100644 index 000000000..cf4abcd4b --- /dev/null +++ b/src/backend/bacon-video-widget.gresource.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/gnome/totem/bvw"> + <file compressed="true">bacon-video-widget.ui</file> + </gresource> +</gresources> diff --git a/src/backend/bacon-video-widget.ui b/src/backend/bacon-video-widget.ui new file mode 100644 index 000000000..adf618522 --- /dev/null +++ b/src/backend/bacon-video-widget.ui @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <template class="BaconVideoWidget" parent="GtkOverlay"> + <property name="visible">True</property> + <property name="border_width">0</property> + <child> + <object class="GtkStack" id="stack"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkImage" id="audio_only"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="icon-name">audio-only-symbolic</property> + <property name="icon-size">6</property> + </object> + <packing> + <property name="name">audio-only</property> + </packing> + </child> + <child> + <object class="GtkImage" id="broken_video"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="icon-name">broken-video-symbolic</property> + <property name="icon-size">6</property> + </object> + <packing> + <property name="name">broken-video</property> + </packing> + </child> + </object> + </child> + </template> +</interface> diff --git a/src/backend/meson.build b/src/backend/meson.build index 38fc7d658..67f3c636f 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -39,6 +39,14 @@ sources = files( 'bacon-video-widget.c', ) +sources += gnome.compile_resources( + 'bacon-video-widget-resources', + 'bacon-video-widget.gresource.xml', + export: true, + source_dir: '.', + c_name: '_bvw' +) + enum_headers = files('bacon-video-widget.h') enum_sources = gnome.mkenums_simple( 'bacon-video-widget-enums', |