From 2dfd1404ff0337d520c8abd62eec027cac57bdd7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 26 Apr 2020 11:25:23 -0400 Subject: [PATCH] inspector: Make the resource tab play videos We can do this easily, so why not. This can be seen in action with gtk-logo.webm, e.g. in gtk4-demo. --- gtk/inspector/resource-list.c | 18 +++++++++++++++++- gtk/inspector/resource-list.ui | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gtk/inspector/resource-list.c b/gtk/inspector/resource-list.c index dfc0817abd..ebb9008a28 100644 --- a/gtk/inspector/resource-list.c +++ b/gtk/inspector/resource-list.c @@ -30,6 +30,8 @@ #include "gtktreeselection.h" #include "gtktreestore.h" #include "gtkeventcontrollerkey.h" +#include "gtkpicture.h" +#include "gtkmediafile.h" #include @@ -51,6 +53,7 @@ struct _GtkInspectorResourceListPrivate { GtkTreeStore *model; GtkTextBuffer *buffer; + GtkWidget *video; GtkWidget *image; GtkWidget *content; GtkWidget *name_label; @@ -193,9 +196,11 @@ populate_details (GtkInspectorResourceList *rl, gchar *text; gchar *content_image; gchar *content_text; + gchar *content_video; content_image = g_content_type_from_mime_type ("image/*"); content_text = g_content_type_from_mime_type ("text/*"); + content_video = g_content_type_from_mime_type ("video/*"); data = g_bytes_get_data (bytes, &size); type = g_content_type_guess (name, data, size, NULL); @@ -215,9 +220,20 @@ populate_details (GtkInspectorResourceList *rl, } else if (g_content_type_is_a (type, content_image)) { - gtk_image_set_from_resource (GTK_IMAGE (rl->priv->image), path); + gtk_picture_set_resource (GTK_PICTURE (rl->priv->image), path); gtk_stack_set_visible_child_name (GTK_STACK (rl->priv->content), "image"); } + else if (g_content_type_is_a (type, content_video)) + { + GtkMediaStream *stream; + + stream = gtk_media_file_new_for_resource (path); + gtk_media_stream_set_loop (GTK_MEDIA_STREAM (stream), TRUE); + gtk_picture_set_paintable (GTK_PICTURE (rl->priv->image), GDK_PAINTABLE (stream)); + gtk_stack_set_visible_child_name (GTK_STACK (rl->priv->content), "image"); + gtk_media_stream_play (GTK_MEDIA_STREAM (stream)); + g_object_unref (stream); + } else { gtk_text_buffer_set_text (rl->priv->buffer, "", 0); diff --git a/gtk/inspector/resource-list.ui b/gtk/inspector/resource-list.ui index 3dd57024da..114e704182 100644 --- a/gtk/inspector/resource-list.ui +++ b/gtk/inspector/resource-list.ui @@ -230,7 +230,7 @@ - + center center