summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/tests/Makefile.am1
-rw-r--r--data/tests/usr/share/app-install/icons/aequorea/iceweasel.png0
-rw-r--r--libappstream-glib/as-app.c52
-rw-r--r--libappstream-glib/as-self-test.c4
4 files changed, 50 insertions, 7 deletions
diff --git a/data/tests/Makefile.am b/data/tests/Makefile.am
index e39b574..9e2546a 100644
--- a/data/tests/Makefile.am
+++ b/data/tests/Makefile.am
@@ -31,6 +31,7 @@ test_files = \
translated.appdata.xml \
usr/share/appdata/broken.appdata.xml \
usr/share/app-install/desktop/test.desktop \
+ usr/share/app-install/icons/aequorea/iceweasel.png \
usr/share/app-install/icons/test.png \
usr/share/icons/hicolor/64x64/apps/test2.png \
usr/share/icons/hicolor/128x128/apps/test3.png \
diff --git a/data/tests/usr/share/app-install/icons/aequorea/iceweasel.png b/data/tests/usr/share/app-install/icons/aequorea/iceweasel.png
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/data/tests/usr/share/app-install/icons/aequorea/iceweasel.png
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index a8782f7..3033e95 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -3467,6 +3467,51 @@ as_app_node_parse (AsApp *app, GNode *node, GError **error)
}
/**
+ * as_app_node_parse_dep11_icons:
+ **/
+static gboolean
+as_app_node_parse_dep11_icons (AsApp *app, GNode *node, GError **error)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ const gchar *sizes[] = { "128x128", "64x64", "", NULL };
+ guint i;
+ guint size;
+ _cleanup_object_unref_ AsIcon *ic_tmp = NULL;
+
+ /* YAML files only specify one icon for various sizes */
+ ic_tmp = as_icon_new ();
+ if (!as_icon_node_parse_dep11 (ic_tmp, node, error))
+ return FALSE;
+
+ /* find each size */
+ for (i = 0; sizes[i] != NULL; i++) {
+ _cleanup_free_ gchar *path = NULL;
+ _cleanup_free_ gchar *size_name = NULL;
+ _cleanup_object_unref_ AsIcon *ic = NULL;
+
+ size_name = g_build_filename (sizes[i],
+ as_icon_get_name (ic_tmp),
+ NULL);
+ path = g_build_filename (priv->icon_path,
+ size_name,
+ NULL);
+ if (!g_file_test (path, G_FILE_TEST_EXISTS))
+ continue;
+
+ /* only the first try is a HiDPI icon, assume 64px otherwise */
+ size = (i == 0) ? 128 : 64;
+ ic = as_icon_new ();
+ as_icon_set_kind (ic, AS_ICON_KIND_CACHED);
+ as_icon_set_prefix (ic, priv->icon_path);
+ as_icon_set_name (ic, size_name, -1);
+ as_icon_set_width (ic, size);
+ as_icon_set_height (ic, size);
+ as_app_add_icon (app, ic);
+ }
+ return TRUE;
+}
+
+/**
* as_app_node_parse_dep11:
* @app: a #AsApp instance.
* @node: a #GNode.
@@ -3481,7 +3526,6 @@ as_app_node_parse (AsApp *app, GNode *node, GError **error)
gboolean
as_app_node_parse_dep11 (AsApp *app, GNode *node, GError **error)
{
- AsAppPrivate *priv = GET_PRIVATE (app);
GNode *c;
GNode *c2;
GNode *n;
@@ -3548,12 +3592,8 @@ as_app_node_parse_dep11 (AsApp *app, GNode *node, GError **error)
}
if (g_strcmp0 (tmp, "Icon") == 0) {
for (c = n->children; c != NULL; c = c->next) {
- _cleanup_object_unref_ AsIcon *ic = NULL;
- ic = as_icon_new ();
- as_icon_set_prefix (ic, priv->icon_path);
- if (!as_icon_node_parse_dep11 (ic, c, error))
+ if (!as_app_node_parse_dep11_icons (app, c, error))
return FALSE;
- as_app_add_icon (app, ic);
}
continue;
}
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index bf27d40..5e3e237 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -2951,6 +2951,7 @@ as_test_store_yaml_func (void)
GError *error = NULL;
gboolean ret;
_cleanup_free_ gchar *filename = NULL;
+ _cleanup_free_ gchar *icon_root = NULL;
_cleanup_object_unref_ AsStore *store = NULL;
_cleanup_object_unref_ GFile *file = NULL;
_cleanup_string_free_ GString *str = NULL;
@@ -2980,8 +2981,9 @@ as_test_store_yaml_func (void)
/* load store */
store = as_store_new ();
filename = as_test_get_filename ("example.yml");
+ icon_root = as_test_get_filename ("usr/share/app-install/icons");
file = g_file_new_for_path (filename);
- ret = as_store_from_file (store, file, NULL, NULL, &error);
+ ret = as_store_from_file (store, file, icon_root, NULL, &error);
g_assert_no_error (error);
g_assert (ret);