Commit 800debdc authored by Matthias Klumpp's avatar Matthias Klumpp
Browse files

Implement video support for screenshots

This resolves #175
parent 219d83d9
......@@ -427,7 +427,7 @@
<term>source-image</term>
<listitem>
<para>
Describes the source image for this screenshot. If this field is present, <literal>source-video</literal> must not be present as well.
Describes the source image for this screenshot. If this field is present, <literal>videos</literal> must not be present as well.
The field valus is a dictionary with the following keys:
</para>
<itemizedlist>
......@@ -464,17 +464,17 @@
<para>
A list of an arbitrary number of screenshots. All screenshots are of type <emphasis>dict</emphasis> and must contain the same keys as described for
<literal>source-image</literal>.
This key must not be present if <literal>source-video</literal> is present.
This key must not be present if <literal>videos</literal> is present.
</para>
<literallayout>Field info: <property>value-type</property>:<emphasis>list</emphasis>, <property>required</property>:<emphasis>no</emphasis></literallayout>
</listitem>
</varlistentry>
<varlistentry>
<term>source-video</term>
<term>videos</term>
<listitem>
<para>
Describes the video for this screenshot. If this field is present, <literal>source-image</literal> must not be present as well.
Contains a list of video dicts for this screenshot. If this field is present, <literal>source-image</literal> must not be present as well.
The field valus is a dictionary with the following keys:
</para>
<itemizedlist>
......@@ -509,7 +509,7 @@
</para>
</listitem>
</itemizedlist>
<literallayout>Field info: <property>value-type</property>:<emphasis>dict</emphasis>, <property>required</property>:<emphasis>conditional</emphasis></literallayout>
<literallayout>Field info: <property>value-type</property>:<emphasis>list(dict)</emphasis>, <property>required</property>:<emphasis>conditional</emphasis></literallayout>
</listitem>
</varlistentry>
......
......@@ -402,6 +402,7 @@ as_image_load_from_yaml (AsImage *image, AsContext *ctx, GNode *node, AsImageKin
GNode *n;
priv->kind = kind;
as_image_set_locale (image, "C");
for (n = node->children; n != NULL; n = n->next) {
const gchar *key = as_yaml_node_get_key (n);
const gchar *value = as_yaml_node_get_value (n);
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2012-2017 Matthias Klumpp <matthias@tenstral.net>
* Copyright (C) 2012-2019 Matthias Klumpp <matthias@tenstral.net>
* Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU Lesser General Public License Version 2.1
......@@ -23,10 +23,10 @@
* SECTION:as-screenshot
* @short_description: Object representing a single screenshot
*
* Screenshots have a localized caption and also contain a number of images
* of different resolution.
* Screenshots have a localized caption and contain either a set of images
* of different resolution or a video screencast showcasing the software.
*
* See also: #AsImage
* See also: #AsImage, #AsVideo
*/
#include "as-screenshot.h"
......@@ -35,13 +35,18 @@
#include "as-utils.h"
#include "as-utils-private.h"
#include "as-image-private.h"
#include "as-video-private.h"
typedef struct
{
AsScreenshotKind kind;
AsScreenshotMediaKind media_kind;
GHashTable *caption;
GPtrArray *images;
GPtrArray *images_lang;
GPtrArray *videos;
GPtrArray *videos_lang;
AsContext *context;
gchar *active_locale_override;
......@@ -50,6 +55,23 @@ typedef struct
G_DEFINE_TYPE_WITH_PRIVATE (AsScreenshot, as_screenshot, G_TYPE_OBJECT)
#define GET_PRIVATE(o) (as_screenshot_get_instance_private (o))
/**
* as_screenshot_init:
**/
static void
as_screenshot_init (AsScreenshot *screenshot)
{
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
priv->kind = AS_SCREENSHOT_KIND_EXTRA;
priv->media_kind = AS_SCREENSHOT_MEDIA_KIND_IMAGE;
priv->caption = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
priv->images = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->images_lang = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->videos = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->videos_lang = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
}
/**
* as_screenshot_finalize:
**/
......@@ -62,6 +84,8 @@ as_screenshot_finalize (GObject *object)
g_free (priv->active_locale_override);
g_ptr_array_unref (priv->images);
g_ptr_array_unref (priv->images_lang);
g_ptr_array_unref (priv->videos);
g_ptr_array_unref (priv->videos_lang);
g_hash_table_unref (priv->caption);
if (priv->context != NULL)
g_object_unref (priv->context);
......@@ -69,20 +93,6 @@ as_screenshot_finalize (GObject *object)
G_OBJECT_CLASS (as_screenshot_parent_class)->finalize (object);
}
/**
* as_screenshot_init:
**/
static void
as_screenshot_init (AsScreenshot *screenshot)
{
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
priv->kind = AS_SCREENSHOT_KIND_EXTRA;
priv->caption = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
priv->images = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->images_lang = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
}
/**
* as_screenshot_class_init:
**/
......@@ -160,6 +170,21 @@ as_screenshot_set_kind (AsScreenshot *screenshot, AsScreenshotKind kind)
priv->kind = kind;
}
/**
* as_screenshot_get_media_kind:
* @screenshot: a #AsScreenshot instance.
*
* Gets the screenshot media kind.
*
* Returns: a #AsScreenshotMediaKind
**/
AsScreenshotMediaKind
as_screenshot_get_media_kind (AsScreenshot *screenshot)
{
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
return priv->media_kind;
}
/**
* as_screenshot_get_images:
* @screenshot: a #AsScreenshot instance.
......@@ -195,6 +220,42 @@ as_screenshot_add_image (AsScreenshot *screenshot, AsImage *image)
g_ptr_array_add (priv->images_lang, g_object_ref (image));
}
/**
* as_screenshot_get_videos:
* @screenshot: a #AsScreenshot instance.
*
* Gets the videos for this screenshots. Only videos valid for the current
* language selection are returned. We return all sizes.
*
* Returns: (transfer none) (element-type AsVideo): an array
**/
GPtrArray*
as_screenshot_get_videos (AsScreenshot *screenshot)
{
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
if (priv->videos_lang->len == 0)
return priv->videos;
return priv->videos_lang;
}
/**
* as_screenshot_add_video:
* @screenshot: a #AsScreenshot instance.
* @video: a #AsVideo instance.
*
* Adds a video to the screenshot.
**/
void
as_screenshot_add_video (AsScreenshot *screenshot, AsVideo *video)
{
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
priv->media_kind = AS_SCREENSHOT_MEDIA_KIND_VIDEO;
g_ptr_array_add (priv->videos, g_object_ref (video));
if (as_utils_locale_is_compatible (as_video_get_locale (video), as_screenshot_get_active_locale (screenshot)))
g_ptr_array_add (priv->videos_lang, g_object_ref (video));
}
/**
* as_screenshot_get_caption:
* @screenshot: a #AsScreenshot instance.
......@@ -255,26 +316,37 @@ as_screenshot_is_valid (AsScreenshot *screenshot)
}
/**
* as_screenshot_rebuild_suitable_images_list:
* as_screenshot_rebuild_suitable_media_list:
* @screenshot: a #AsScreenshot instance.
*
* Rebuild list of images suitable for the selected locale.
* Rebuild list of images or videos suitable for the selected locale.
*/
static void
as_screenshot_rebuild_suitable_images_list (AsScreenshot *screenshot)
as_screenshot_rebuild_suitable_media_list (AsScreenshot *screenshot)
{
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
guint i;
/* rebuild our list of images suitable for the current locale */
g_ptr_array_unref (priv->images_lang);
priv->images_lang = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
for (i = 0; i < priv->images->len; i++) {
for (guint i = 0; i < priv->images->len; i++) {
AsImage *img = AS_IMAGE (g_ptr_array_index (priv->images, i));
if (!as_utils_locale_is_compatible (as_image_get_locale (img), as_screenshot_get_active_locale (screenshot)))
continue;
g_ptr_array_add (priv->images_lang, g_object_ref (img));
}
/* rebuild our list of videos suitable for the current locale */
g_ptr_array_unref (priv->videos_lang);
priv->videos_lang = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
for (guint i = 0; i < priv->videos->len; i++) {
AsVideo *vid = AS_VIDEO (g_ptr_array_index (priv->videos, i));
g_print ("Check: %s vs %s\n", as_video_get_locale (vid), as_screenshot_get_active_locale (screenshot));
if (!as_utils_locale_is_compatible (as_video_get_locale (vid), as_screenshot_get_active_locale (screenshot)))
continue;
g_print ("PASS\n");
g_ptr_array_add (priv->videos_lang, g_object_ref (vid));
}
}
/**
......@@ -320,7 +392,7 @@ as_screenshot_set_active_locale (AsScreenshot *screenshot, const gchar *locale)
priv->active_locale_override = g_strdup (locale);
/* rebuild our list of images suitable for the current locale */
as_screenshot_rebuild_suitable_images_list (screenshot);
as_screenshot_rebuild_suitable_media_list (screenshot);
}
/**
......@@ -379,7 +451,7 @@ as_screenshot_set_context (AsScreenshot *screenshot, AsContext *context)
g_free (priv->active_locale_override);
priv->active_locale_override = NULL;
as_screenshot_rebuild_suitable_images_list (screenshot);
as_screenshot_rebuild_suitable_media_list (screenshot);
}
/**
......@@ -417,6 +489,10 @@ as_screenshot_load_from_xml (AsScreenshot *screenshot, AsContext *ctx, xmlNode *
g_autoptr(AsImage) image = as_image_new ();
if (as_image_load_from_xml (image, ctx, iter, NULL))
as_screenshot_add_image (screenshot, image);
} else if (g_strcmp0 (node_name, "video") == 0) {
g_autoptr(AsVideo) video = as_video_new ();
if (as_video_load_from_xml (video, ctx, iter, NULL))
as_screenshot_add_video (screenshot, video);
} else if (g_strcmp0 (node_name, "caption") == 0) {
g_autofree gchar *content = NULL;
g_autofree gchar *lang = NULL;
......@@ -463,7 +539,6 @@ as_screenshot_to_xml_node (AsScreenshot *screenshot, AsContext *ctx, xmlNode *ro
{
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
xmlNode *subnode;
guint i;
subnode = xmlNewChild (root, NULL, (xmlChar*) "screenshot", NULL);
if (priv->kind == AS_SCREENSHOT_KIND_DEFAULT)
......@@ -471,9 +546,16 @@ as_screenshot_to_xml_node (AsScreenshot *screenshot, AsContext *ctx, xmlNode *ro
as_xml_add_localized_text_node (subnode, "caption", priv->caption);
for (i = 0; i < priv->images->len; i++) {
AsImage *image = AS_IMAGE (g_ptr_array_index (priv->images, i));
as_image_to_xml_node (image, ctx, subnode);
if (priv->media_kind == AS_SCREENSHOT_MEDIA_KIND_IMAGE) {
for (guint i = 0; i < priv->images->len; i++) {
AsImage *image = AS_IMAGE (g_ptr_array_index (priv->images, i));
as_image_to_xml_node (image, ctx, subnode);
}
} else if (priv->media_kind == AS_SCREENSHOT_MEDIA_KIND_VIDEO) {
for (guint i = 0; i < priv->videos->len; i++) {
AsVideo *video = AS_VIDEO (g_ptr_array_index (priv->videos, i));
as_video_to_xml_node (video, ctx, subnode);
}
}
}
......@@ -498,7 +580,7 @@ as_screenshot_load_from_yaml (AsScreenshot *screenshot, AsContext *ctx, GNode *n
const gchar *value = as_yaml_node_get_value (n);
if (g_strcmp0 (key, "default") == 0) {
if (g_strcmp0 (value, "yes") == 0)
if ((g_strcmp0 (value, "true") == 0) || (g_strcmp0 (value, "yes") == 0))
priv->kind = AS_SCREENSHOT_KIND_DEFAULT;
else
priv->kind = AS_SCREENSHOT_KIND_EXTRA;
......@@ -517,6 +599,12 @@ as_screenshot_load_from_yaml (AsScreenshot *screenshot, AsContext *ctx, GNode *n
if (as_image_load_from_yaml (image, ctx, in, AS_IMAGE_KIND_THUMBNAIL, NULL))
as_screenshot_add_image (screenshot, image);
}
} else if (g_strcmp0 (key, "videos") == 0) {
for (in = n->children; in != NULL; in = in->next) {
g_autoptr(AsVideo) video = as_video_new ();
if (as_video_load_from_yaml (video, ctx, in, NULL))
as_screenshot_add_video (screenshot, video);
}
} else {
as_yaml_print_unknown ("screenshot", key);
}
......@@ -540,7 +628,6 @@ void
as_screenshot_emit_yaml (AsScreenshot *screenshot, AsContext *ctx, yaml_emitter_t *emitter)
{
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
guint i;
AsImage *source_img = NULL;
as_yaml_mapping_start (emitter);
......@@ -550,24 +637,34 @@ as_screenshot_emit_yaml (AsScreenshot *screenshot, AsContext *ctx, yaml_emitter_
as_yaml_emit_localized_entry (emitter, "caption", priv->caption);
as_yaml_emit_scalar (emitter, "thumbnails");
as_yaml_sequence_start (emitter);
for (i = 0; i < priv->images->len; i++) {
AsImage *img = AS_IMAGE (g_ptr_array_index (priv->images, i));
if (priv->media_kind == AS_SCREENSHOT_MEDIA_KIND_IMAGE) {
as_yaml_emit_scalar (emitter, "thumbnails");
as_yaml_sequence_start (emitter);
for (guint i = 0; i < priv->images->len; i++) {
AsImage *img = AS_IMAGE (g_ptr_array_index (priv->images, i));
if (as_image_get_kind (img) == AS_IMAGE_KIND_SOURCE) {
source_img = img;
continue;
}
if (as_image_get_kind (img) == AS_IMAGE_KIND_SOURCE) {
source_img = img;
continue;
}
as_image_emit_yaml (img, ctx, emitter);
}
as_yaml_sequence_end (emitter);
as_image_emit_yaml (img, ctx, emitter);
}
as_yaml_sequence_end (emitter);
/* we *must* have a source-image by now if the data follows the spec, but better be safe... */
if (source_img != NULL) {
as_yaml_emit_scalar (emitter, "source-image");
as_image_emit_yaml (source_img, ctx, emitter);
/* we *must* have a source-image by now if the data follows the spec, but better be safe... */
if (source_img != NULL) {
as_yaml_emit_scalar (emitter, "source-image");
as_image_emit_yaml (source_img, ctx, emitter);
}
} else if (priv->media_kind == AS_SCREENSHOT_MEDIA_KIND_VIDEO) {
as_yaml_emit_scalar (emitter, "videos");
as_yaml_sequence_start (emitter);
for (guint i = 0; i < priv->videos->len; i++) {
AsVideo *video = AS_VIDEO (g_ptr_array_index (priv->videos, i));
as_video_emit_yaml (video, ctx, emitter);
}
as_yaml_sequence_end (emitter);
}
as_yaml_mapping_end (emitter);
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2012-2017 Matthias Klumpp <matthias@tenstral.net>
* Copyright (C) 2012-2019 Matthias Klumpp <matthias@tenstral.net>
* Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU Lesser General Public License Version 2.1
......@@ -29,6 +29,7 @@
#include <glib-object.h>
#include "as-image.h"
#include "as-video.h"
G_BEGIN_DECLS
......@@ -63,6 +64,22 @@ typedef enum {
AS_SCREENSHOT_KIND_LAST
} AsScreenshotKind;
/**
* AsScreenshotMediaKind:
* @AS_SCREENSHOT_MEDIA_KIND_UNKNOWN: Media kind is unknown
* @AS_SCREENSHOT_MEDIA_KIND_IMAGE: The screenshot contains images
* @AS_SCREENSHOT_MEDIA_KIND_VIDEO: The screenshot contains videos
*
* The media kind contained in this screenshot.
**/
typedef enum {
AS_SCREENSHOT_MEDIA_KIND_UNKNOWN,
AS_SCREENSHOT_MEDIA_KIND_IMAGE,
AS_SCREENSHOT_MEDIA_KIND_VIDEO,
/*< private >*/
AS_SCREENSHOT_MEDIA_KIND_LAST
} AsScreenshotMediaKind;
AsScreenshotKind as_screenshot_kind_from_string (const gchar *kind);
const gchar *as_screenshot_kind_to_string (AsScreenshotKind kind);
gboolean as_screenshot_is_valid (AsScreenshot *screenshot);
......@@ -73,6 +90,8 @@ AsScreenshotKind as_screenshot_get_kind (AsScreenshot *screenshot);
void as_screenshot_set_kind (AsScreenshot *screenshot,
AsScreenshotKind kind);
AsScreenshotMediaKind as_screenshot_get_media_kind (AsScreenshot *screenshot);
const gchar *as_screenshot_get_caption (AsScreenshot *screenshot);
void as_screenshot_set_caption (AsScreenshot *screenshot,
const gchar *caption,
......@@ -83,6 +102,10 @@ GPtrArray *as_screenshot_get_images (AsScreenshot *screenshot);
void as_screenshot_add_image (AsScreenshot *screenshot,
AsImage *image);
GPtrArray *as_screenshot_get_videos (AsScreenshot *screenshot);
void as_screenshot_add_video (AsScreenshot *screenshot,
AsVideo *video);
const gchar *as_screenshot_get_active_locale (AsScreenshot *screenshot);
void as_screenshot_set_active_locale (AsScreenshot *screenshot,
const gchar *locale);
......
......@@ -18,8 +18,8 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __AS_IMAGE_PRIVATE_H
#define __AS_IMAGE_PRIVATE_H
#ifndef __AS_VIDEO_PRIVATE_H
#define __AS_VIDEO_PRIVATE_H
#include "as-video.h"
#include "as-xml.h"
......@@ -47,4 +47,4 @@ void as_video_emit_yaml (AsVideo *video,
#pragma GCC visibility pop
G_END_DECLS
#endif /* __AS_IMAGE_PRIVATE_H */
#endif /* __AS_VIDEO_PRIVATE_H */
......@@ -452,6 +452,7 @@ as_video_load_from_yaml (AsVideo *video, AsContext *ctx, GNode *node, GError **e
AsVideoPrivate *priv = GET_PRIVATE (video);
GNode *n;
as_video_set_locale (video, "C");
for (n = node->children; n != NULL; n = n->next) {
const gchar *key = as_yaml_node_get_key (n);
const gchar *value = as_yaml_node_get_value (n);
......
......@@ -976,6 +976,10 @@ static const gchar *xmldata_screenshots = "<?xml version=\"1.0\" encoding=\"utf-
" <image type=\"thumbnail\" width=\"800\" height=\"600\">https://example.org/beta_small.png</image>\n"
" <image type=\"source\" xml:lang=\"de_DE\">https://example.org/localized_de.png</image>\n"
" </screenshot>\n"
" <screenshot>\n"
" <video codec=\"av1\" container=\"mkv\" width=\"1916\" height=\"1056\">https://example.org/screencast.mkv</video>\n"
" <video codec=\"av1\" container=\"mkv\" width=\"1916\" height=\"1056\" xml:lang=\"de_DE\">https://example.org/screencast_de.mkv</video>\n"
" </screenshot>\n"
" </screenshots>\n"
"</component>\n";
......@@ -991,8 +995,11 @@ test_xml_read_screenshots (void)
GPtrArray *screenshots;
AsScreenshot *scr1;
AsScreenshot *scr2;
AsScreenshot *scr3;
GPtrArray *images;
GPtrArray *videos;
AsImage *img;
AsVideo *vid;
const gchar *xmldata_screenshot_legacy = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<component>\n"
......@@ -1006,13 +1013,15 @@ test_xml_read_screenshots (void)
g_assert_cmpstr (as_component_get_id (cpt), ==, "org.example.ScreenshotTest");
screenshots = as_component_get_screenshots (cpt);
g_assert_cmpint (screenshots->len, ==, 2);
g_assert_cmpint (screenshots->len, ==, 3);
scr1 = AS_SCREENSHOT (g_ptr_array_index (screenshots, 0));
scr2 = AS_SCREENSHOT (g_ptr_array_index (screenshots, 1));
scr3 = AS_SCREENSHOT (g_ptr_array_index (screenshots, 2));
/* screenshot 1 */
g_assert_cmpint (as_screenshot_get_kind (scr1), ==, AS_SCREENSHOT_KIND_DEFAULT);
g_assert_cmpint (as_screenshot_get_media_kind (scr1), ==, AS_SCREENSHOT_MEDIA_KIND_IMAGE);
as_screenshot_set_active_locale (scr1, "C");
g_assert_cmpstr (as_screenshot_get_caption (scr1), ==, "The main window displaying a thing");
as_screenshot_set_active_locale (scr1, "de_DE");
......@@ -1035,6 +1044,7 @@ test_xml_read_screenshots (void)
/* screenshot 2 */
g_assert_cmpint (as_screenshot_get_kind (scr2), ==, AS_SCREENSHOT_KIND_EXTRA);
g_assert_cmpint (as_screenshot_get_media_kind (scr2), ==, AS_SCREENSHOT_MEDIA_KIND_IMAGE);
as_screenshot_set_active_locale (scr2, "C");
images = as_screenshot_get_images (scr2);
g_assert_cmpint (images->len, ==, 2);
......@@ -1059,6 +1069,37 @@ test_xml_read_screenshots (void)
g_assert_cmpint (as_image_get_width (img), ==, 800);
g_assert_cmpint (as_image_get_height (img), ==, 600);
/* screenshot 3 */
g_assert_cmpint (as_screenshot_get_kind (scr3), ==, AS_SCREENSHOT_KIND_EXTRA);
g_assert_cmpint (as_screenshot_get_media_kind (scr3), ==, AS_SCREENSHOT_MEDIA_KIND_VIDEO);
as_screenshot_set_active_locale (scr3, "C");
g_assert_cmpint (as_screenshot_get_images (scr3)->len, ==, 0);
videos = as_screenshot_get_videos (scr3);
g_assert_cmpint (videos->len, ==, 1);
as_screenshot_set_active_locale (scr3, "de_DE");
videos = as_screenshot_get_videos (scr3);
g_assert_cmpint (videos->len, ==, 1);
vid = AS_VIDEO (g_ptr_array_index (videos, 0));
g_assert_cmpstr (as_video_get_url (vid), ==, "https://example.org/screencast_de.mkv");
as_screenshot_set_active_locale (scr3, "ALL");
videos = as_screenshot_get_videos (scr3);
g_assert_cmpint (videos->len, ==, 2);
vid = AS_VIDEO (g_ptr_array_index (videos, 0));
g_assert_cmpint (as_video_get_codec (vid), ==, AS_VIDEO_CODEC_AV1);
g_assert_cmpint (as_video_get_container (vid), ==, AS_VIDEO_CONTAINER_MKV);
g_assert_cmpstr (as_video_get_url (vid), ==, "https://example.org/screencast.mkv");
g_assert_cmpint (as_video_get_width (vid), ==, 1916);
g_assert_cmpint (as_video_get_height (vid), ==, 1056);
vid = AS_VIDEO (g_ptr_array_index (videos, 1));
g_assert_cmpint (as_video_get_codec (vid), ==, AS_VIDEO_CODEC_AV1);
g_assert_cmpint (as_video_get_container (vid), ==, AS_VIDEO_CONTAINER_MKV);
g_assert_cmpstr (as_video_get_url (vid), ==, "https://example.org/screencast_de.mkv");
g_assert_cmpint (as_video_get_width (vid), ==, 1916);
g_assert_cmpint (as_video_get_height (vid), ==, 1056);
/* test a legacy screenshot entry that we briefly supported in an older AppStream release */
g_object_unref (cpt);
cpt = as_xml_test_read_data (xmldata_screenshot_legacy, AS_FORMAT_STYLE_METAINFO);
......@@ -1089,7 +1130,9 @@ test_xml_write_screenshots (void)
g_autofree gchar *res = NULL;
g_autoptr(AsScreenshot) scr1 = NULL;
g_autoptr(AsScreenshot) scr2 = NULL;
g_autoptr(AsScreenshot) scr3 = NULL;
AsImage *img;
AsVideo *vid;
cpt = as_component_new ();
as_component_set_id (cpt, "org.example.ScreenshotTest");
......@@ -1138,8 +1181,29 @@ test_xml_write_screenshots (void)
as_screenshot_add_image (scr2, img);
g_object_unref (img);
scr3 = as_screenshot_new ();
vid = as_video_new ();
as_video_set_codec (vid, AS_VIDEO_CODEC_AV1);
as_video_set_container (vid, AS_VIDEO_CONTAINER_MKV);
as_video_set_width (vid, 1916);
as_video_set_height (vid, 1056);
as_video_set_url (vid, "https://example.org/screencast.mkv");
as_screenshot_add_video (scr3, vid);
g_object_unref (vid);
vid = as_video_new ();
as_video_set_codec (vid, AS_VIDEO_CODEC_AV1);
as_video_set_container (vid, AS_VIDEO_CONTAINER_MKV);
as_video_set_locale (vid, "de_DE");
as_video_set_width (vid, 1916);
as_video_set_height (vid, 1056);
as_video_set_url (vid, "https://example.org/screencast_de.mkv");
as_screenshot_add_video (scr3, vid);
g_object_unref (vid);
as_component_add_screenshot (cpt, scr1);
as_component_add_screenshot (cpt, scr2);
as_component_add_screenshot (cpt, scr3);
res = as_xml_test_serialize (cpt, AS_FORMAT_STYLE_METAINFO);
g_assert (as_test_compare_lines (res, xmldata_screenshots));
......
......@@ -993,6 +993,191 @@ test_yaml_read_agreements (void)
g_assert_cmpstr (as_agreement_section_get_name (sect), ==, "Einführung");
}
static const gchar *yamldata_screenshots = "---\n"
"File: DEP-11\n"
"Version: '0.12'\n"
"---\n"
"Type: generic\n"
"ID: org.example.ScreenshotsTest\n"
"Screenshots:\n"
"- default: true\n"
" caption:\n"
" de_DE: Das Hauptfenster, welches irgendwas zeigt\n"
" C: The main window displaying a thing\n"
" thumbnails:\n"
" - url: https://example.org/alpha_small.png\n"
" width: 800\n"
" height: 600\n"
" source-image:\n"
" url: https://example.org/alpha.png\n"
" width: 1916\n"
" height: 1056\n"
"- caption:\n"
" C: A screencast of this app\n"
" videos:\n"
" - codec: av1\n"
" container: mkv\n"
" url: https://example.org/screencast.mkv\n"
" width: 1916\n"
" height: 1056\n"
" - codec: av1\n"
" container: mkv\n"
" url: https://example.org/screencast_de.mkv\n"
" width: 1916\n"
" height: 1056\n"