Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/appstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <as-developer.h>
#include <as-icon.h>
#include <as-screenshot.h>
#include <as-promotional.h>
#include <as-image.h>
#include <as-video.h>
#include <as-branding.h>
Expand Down
83 changes: 83 additions & 0 deletions src/as-component.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "as-context-private.h"
#include "as-icon-private.h"
#include "as-screenshot-private.h"
#include "as-promotional-private.h"
#include "as-bundle-private.h"
#include "as-release-list-private.h"
#include "as-translation-private.h"
Expand Down Expand Up @@ -95,6 +96,7 @@ typedef struct {
GPtrArray *extends; /* of utf8 */
GPtrArray *addons; /* of AsComponent */
GPtrArray *screenshots; /* of AsScreenshot elements */
GPtrArray *promotionals; /* of AsPromotional elements */
GPtrArray *provided; /* of AsProvided */
GPtrArray *bundles; /* of AsBundle */
GPtrArray *suggestions; /* of AsSuggested elements */
Expand Down Expand Up @@ -426,6 +428,7 @@ as_component_init (AsComponent *cpt)
priv->categories = g_ptr_array_new_with_free_func (g_free);
priv->compulsory_for_desktops = g_ptr_array_new_with_free_func (g_free);
priv->screenshots = g_ptr_array_new_with_free_func (g_object_unref);
priv->promotionals = g_ptr_array_new_with_free_func (g_object_unref);
priv->provided = g_ptr_array_new_with_free_func (g_object_unref);
priv->bundles = g_ptr_array_new_with_free_func (g_object_unref);
priv->extends = g_ptr_array_new_with_free_func (g_free);
Expand Down Expand Up @@ -489,6 +492,7 @@ as_component_finalize (GObject *object)
g_ptr_array_unref (priv->compulsory_for_desktops);

g_ptr_array_unref (priv->screenshots);
g_ptr_array_unref (priv->promotionals);
g_ptr_array_unref (priv->provided);
g_ptr_array_unref (priv->bundles);
g_ptr_array_unref (priv->extends);
Expand Down Expand Up @@ -626,6 +630,37 @@ as_component_add_screenshot (AsComponent *cpt, AsScreenshot *sshot)
g_ptr_array_add (priv->screenshots, g_object_ref (sshot));
}

/**
* as_component_add_promotional:
* @cpt: a #AsComponent instance.
* @promotional: The #AsPromotional to add
*
* Add an #AsPromotional to this component.
**/
void
as_component_add_promotional (AsComponent *cpt, AsPromotional *promotional)
{
AsComponentPrivate *priv = GET_PRIVATE (cpt);
g_return_if_fail (promotional != NULL);

g_ptr_array_add (priv->promotionals, g_object_ref (promotional));
}

/**
* as_component_get_promotionals:
* @cpt: a #AsComponent instance.
*
* Get a list of all associated promotional images/videos.
*
* Returns: (element-type AsPromotional) (transfer none): an array of #AsPromotional instances
*/
GPtrArray *
as_component_get_promotionals (AsComponent *cpt)
{
AsComponentPrivate *priv = GET_PRIVATE (cpt);
return priv->promotionals;
}

/**
* as_component_get_releases_plain:
* @cpt: a #AsComponent instance.
Expand Down Expand Up @@ -4752,6 +4787,22 @@ as_component_load_from_xml (AsComponent *cpt, AsContext *ctx, xmlNode *node, GEr
as_component_add_reference (cpt, reference);
}

} else if (tag_id == AS_TAG_PROMOTIONALS) {
xmlNode *iter2;

for (iter2 = iter->children; iter2 != NULL; iter2 = iter2->next) {
if (iter2->type != XML_ELEMENT_NODE)
continue;
if (g_strcmp0 ((const gchar *) iter2->name, "promotional") == 0) {
g_autoptr(AsPromotional) promotional = as_promotional_new ();
if (as_promotional_load_from_xml (promotional,
ctx,
iter2,
NULL))
as_component_add_promotional (cpt, promotional);
}
}

} else if (as_context_get_internal_mode (ctx)) {
g_autofree gchar *content = as_xml_get_node_value (iter);
/* internal information */
Expand Down Expand Up @@ -5210,6 +5261,17 @@ as_component_to_xml_node (AsComponent *cpt, AsContext *ctx, xmlNode *root)
}
}

/* promotionals */
if (priv->promotionals->len > 0) {
xmlNode *pnode = as_xml_add_node (cnode, "promotionals");

for (guint i = 0; i < priv->promotionals->len; i++) {
AsPromotional *promo = AS_PROMOTIONAL (
g_ptr_array_index (priv->promotionals, i));
as_promotional_to_xml_node (promo, ctx, pnode);
}
}

/* custom node */
as_xml_add_custom_node (cnode, "custom", priv->custom);

Expand Down Expand Up @@ -5790,6 +5852,13 @@ as_component_load_from_yaml (AsComponent *cpt, AsContext *ctx, struct fy_node *r
as_component_add_reference (cpt, reference);
}

} else if (field_id == AS_TAG_PROMOTIONALS) {
AS_YAML_SEQUENCE_FOREACH (n, value_n) {
g_autoptr(AsPromotional) promotional = as_promotional_new ();
if (as_promotional_load_from_yaml (promotional, ctx, n, NULL))
as_component_add_promotional (cpt, promotional);
}

} else if (field_id == AS_TAG_CUSTOM) {
as_component_yaml_parse_custom (cpt, value_n);
} else if (field_id == AS_TAG_REVIEWS) {
Expand Down Expand Up @@ -6448,6 +6517,20 @@ as_component_emit_yaml (AsComponent *cpt, AsContext *ctx, struct fy_emitter *emi
as_yaml_sequence_end (emitter);
}

/* Promotionals */
if (priv->promotionals->len > 0) {
as_yaml_emit_scalar (emitter, "Promotionals");
as_yaml_sequence_start (emitter);

for (guint i = 0; i < priv->promotionals->len; i++) {
AsPromotional *promo = AS_PROMOTIONAL (
g_ptr_array_index (priv->promotionals, i));
as_promotional_emit_yaml (promo, ctx, emitter);
}

as_yaml_sequence_end (emitter);
}

/* Custom fields */
as_component_yaml_emit_custom (cpt, emitter);

Expand Down
4 changes: 4 additions & 0 deletions src/as-component.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "as-provided.h"
#include "as-icon.h"
#include "as-screenshot.h"
#include "as-promotional.h"
#include "as-release-list.h"
#include "as-developer.h"
#include "as-translation.h"
Expand Down Expand Up @@ -263,6 +264,9 @@ void as_component_sort_screenshots (AsComponent *cpt,
const gchar *style,
gboolean prioritize_style);

GPtrArray *as_component_get_promotionals (AsComponent *cpt);
void as_component_add_promotional (AsComponent *cpt, AsPromotional *promotional);

GPtrArray *as_component_get_keywords (AsComponent *cpt);
void as_component_set_keywords (AsComponent *cpt,
GPtrArray *new_keywords,
Expand Down
53 changes: 53 additions & 0 deletions src/as-promotional-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2024 Matthias Klumpp <matthias@tenstral.net>
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the license, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __AS_PROMOTIONAL_PRIVATE_H
#define __AS_PROMOTIONAL_PRIVATE_H

#include "as-macros-private.h"
#include "as-promotional.h"
#include "as-xml.h"
#include "as-yaml.h"

AS_BEGIN_PRIVATE_DECLS

AS_INTERNAL_VISIBLE
void as_promotional_set_context_locale (AsPromotional *promotional, const gchar *locale);

gboolean as_promotional_load_from_xml (AsPromotional *promotional,
AsContext *ctx,
xmlNode *node,
GError **error);
void as_promotional_to_xml_node (AsPromotional *promotional, AsContext *ctx, xmlNode *root);

gboolean as_promotional_load_from_yaml (AsPromotional *promotional,
AsContext *ctx,
struct fy_node *node,
GError **error);
void as_promotional_emit_yaml (AsPromotional *promotional,
AsContext *ctx,
struct fy_emitter *emitter);

gint as_promotional_get_position (AsPromotional *promotional);
void as_promotional_set_position (AsPromotional *promotional, gint pos);

AS_END_PRIVATE_DECLS

#endif /* __AS_PROMOTIONAL_PRIVATE_H */
Loading
Loading