Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Allow AppStream to parse recommendations #45

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -63,6 +63,7 @@ set(APPSTREAM_LIB_SRC
as-validator-issue.c
as-icon.c
as-translation.c
as-suggested.c
)

set(APPSTREAM_LIB_PUBLIC_HEADERS
@@ -84,6 +85,7 @@ set(APPSTREAM_LIB_PUBLIC_HEADERS
as-validator-issue.h
as-icon.h
as-translation.h
as-suggested.h
)

set(APPSTREAM_LIB_PRIVATE_HEADERS
@@ -37,6 +37,7 @@ extern "C" {
#include <as-distro-details.h>
#include <as-icon.h>
#include <as-screenshot.h>
#include <as-suggested.h>
#include <as-image.h>

#include <as-validator.h>
@@ -70,6 +70,7 @@ typedef struct
GPtrArray *extensions; /* of string */
GPtrArray *screenshots; /* of AsScreenshot elements */
GPtrArray *releases; /* of AsRelease elements */
GPtrArray *suggestions; /* of AsSuggested elements */

GHashTable *provided; /* of int:object */
GHashTable *urls; /* of int:utf8 */
@@ -119,7 +120,8 @@ enum {
AS_COMPONENT_PROJECT_LICENSE,
AS_COMPONENT_PROJECT_GROUP,
AS_COMPONENT_DEVELOPER_NAME,
AS_COMPONENT_SCREENSHOTS
AS_COMPONENT_SCREENSHOTS,
AS_COMPONENT_SUGGESTIONS
};

/**
@@ -141,6 +143,7 @@ as_component_kind_get_type (void)
{AS_COMPONENT_KIND_INPUTMETHOD, "AS_COMPONENT_KIND_INPUTMETHOD", "inputmethod"},
{AS_COMPONENT_KIND_ADDON, "AS_COMPONENT_KIND_ADDON", "addon"},
{AS_COMPONENT_KIND_FIRMWARE, "AS_COMPONENT_KIND_FIRMWARE", "firmware"},
{AS_COMPONENT_KIND_MERGE, "AS_COMPONENT_KIND_MERGE", "merge"},
{AS_COMPONENT_KIND_LAST, "AS_COMPONENT_KIND_LAST", "last"},
{0, NULL, NULL}
};
@@ -176,6 +179,8 @@ as_component_kind_to_string (AsComponentKind kind)
return "addon";
if (kind == AS_COMPONENT_KIND_FIRMWARE)
return "firmware";
if (kind == AS_COMPONENT_KIND_MERGE)
return "merge";
return "unknown";
}

@@ -204,6 +209,8 @@ as_component_kind_from_string (const gchar *kind_str)
return AS_COMPONENT_KIND_ADDON;
if (g_strcmp0 (kind_str, "firmware") == 0)
return AS_COMPONENT_KIND_FIRMWARE;
if (g_strcmp0 (kind_str, "merge") == 0)
return AS_COMPONENT_KIND_MERGE;
return AS_COMPONENT_KIND_UNKNOWN;
}

@@ -227,6 +234,7 @@ as_component_init (AsComponent *cpt)

priv->screenshots = g_ptr_array_new_with_free_func (g_object_unref);
priv->releases = g_ptr_array_new_with_free_func (g_object_unref);
priv->suggestions = g_ptr_array_new_with_free_func (g_object_unref);

priv->icons = g_ptr_array_new_with_free_func (g_object_unref);
priv->icons_sizetab = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
@@ -268,6 +276,7 @@ as_component_finalize (GObject* object)

g_ptr_array_unref (priv->screenshots);
g_ptr_array_unref (priv->releases);
g_ptr_array_unref (priv->suggestions);
g_hash_table_unref (priv->provided);
g_hash_table_unref (priv->urls);
g_hash_table_unref (priv->languages);
@@ -401,6 +410,22 @@ as_component_add_release (AsComponent *cpt, AsRelease* release)
g_ptr_array_add (releases, g_object_ref (release));
}

/**
* as_component_add_suggestion:
* @cpt: a #AsComponent instance.
* @suggested: The #AsSuggested to add
*
* Add an #AsSuggested to this component.
**/
void
as_component_add_suggestion (AsComponent *cpt, AsSuggested* suggested)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should likely be add_suggested for consistency.

{
GPtrArray* suggestions;

suggestions = as_component_get_suggestions (cpt);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this, just access the variable directly.

g_ptr_array_add (suggestions, g_object_ref (suggested));
}

/**
* as_component_get_urls_table:
* @cpt: a #AsComponent instance.
@@ -1360,6 +1385,22 @@ as_component_get_compulsory_for_desktops (AsComponent *cpt)
return priv->compulsory_for_desktops;
}

/**
* as_component_get_suggestions:
* @cpt: a #AsComponent instance.
*
* Get a list of associated suggestions.
*
* Returns: (element-type AsSuggested) (transfer none): an array of #AsSuggested instances
*/
GPtrArray*
as_component_get_suggestions (AsComponent *cpt)
{
AsComponentPrivate *priv = GET_PRIVATE (cpt);

return priv->suggestions;
}

/**
* as_component_set_compulsory_for_desktops:
* @cpt: a #AsComponent instance.
@@ -2234,6 +2275,9 @@ as_component_get_property (GObject * object, guint property_id, GValue * value,
case AS_COMPONENT_SCREENSHOTS:
g_value_set_boxed (value, as_component_get_screenshots (cpt));
break;
case AS_COMPONENT_SUGGESTIONS:
g_value_set_boxed (value, as_component_get_suggestions (cpt));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -2411,6 +2455,14 @@ as_component_class_init (AsComponentClass * klass)
g_object_class_install_property (object_class,
AS_COMPONENT_SCREENSHOTS,
g_param_spec_boxed ("screenshots", "screenshots", "screenshots", G_TYPE_PTR_ARRAY, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
/**
* AsComponent:suggestions: (type GPtrArray(AsSuggested)):
*
* An array of #AsSuggested instances
*/
g_object_class_install_property (object_class,
AS_COMPONENT_SUGGESTIONS,
g_param_spec_boxed ("suggestions", "suggestions", "suggestions", G_TYPE_PTR_ARRAY, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
}

/**
@@ -32,6 +32,7 @@
#include "as-screenshot.h"
#include "as-release.h"
#include "as-translation.h"
#include "as-suggested.h"

G_BEGIN_DECLS

@@ -60,6 +61,7 @@ struct _AsComponentClass
* @AS_COMPONENT_KIND_INPUTMETHOD: An input-method provider
* @AS_COMPONENT_KIND_ADDON: An extension of existing software, which does not run standalone
* @AS_COMPONENT_KIND_FIRMWARE: Firmware
* @AS_COMPONENT_KIND_MERGE: A component used to provide additional information to an existing component
*
* The type of an #AsComponent.
**/
@@ -72,6 +74,7 @@ typedef enum {
AS_COMPONENT_KIND_INPUTMETHOD,
AS_COMPONENT_KIND_ADDON,
AS_COMPONENT_KIND_FIRMWARE,
AS_COMPONENT_KIND_MERGE,
/*< private >*/
AS_COMPONENT_KIND_LAST
} AsComponentKind;
@@ -155,6 +158,10 @@ GPtrArray *as_component_get_screenshots (AsComponent *cpt);
void as_component_add_screenshot (AsComponent *cpt,
AsScreenshot *sshot);

GPtrArray *as_component_get_suggestions (AsComponent *cpt);
void as_component_add_suggestion (AsComponent *cpt,
AsSuggested *suggested);

gchar **as_component_get_keywords (AsComponent *cpt);
void as_component_set_keywords (AsComponent *cpt,
gchar **value,
@@ -215,10 +215,17 @@ as_data_pool_merge_components (AsDataPool *dpool, AsComponent *src_cpt, AsCompon
guint i;
gchar **cats;
gchar **pkgnames;
GPtrArray* suggestions;
AsComponentKind src_kind;

/* FIXME: We only do this for GNOME Software compatibility. In future, we need better rules on what to merge how, and
* whether we want to merge stuff at all. */

src_kind = as_component_get_kind (src_cpt);

if (src_kind != AS_COMPONENT_KIND_MERGE)
return;

cats = as_component_get_categories (src_cpt);
if (cats != NULL) {
g_autoptr(GHashTable) cat_table = NULL;
@@ -243,6 +250,12 @@ as_data_pool_merge_components (AsDataPool *dpool, AsComponent *src_cpt, AsCompon
if ((pkgnames != NULL) && (pkgnames[0] != '\0'))
as_component_set_pkgnames (dest_cpt, as_component_get_pkgnames (src_cpt));

suggestions = as_component_get_suggestions (src_cpt);
if (suggestions != NULL) {
for (i = 0; i < suggestions->len; i++)
as_component_add_suggestion (dest_cpt, g_ptr_array_index (suggestions, i));
}

if (as_component_has_bundle (src_cpt))
as_component_set_bundles_table (dest_cpt, as_component_get_bundles_table (src_cpt));
}