diff options
author | Richard Hughes <richard@hughsie.com> | 2014-10-29 15:35:28 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-10-29 17:03:53 +0000 |
commit | 34f917d69fcdddc83037b5073fd9622ab6af4835 (patch) | |
tree | b52f0976890d6ee79f08b83c71d889f26408fe20 /libappstream-glib | |
parent | 88daf0563ae2a8650c8bc4474ba126f5bd490d1f (diff) | |
download | appstream-glib-34f917d69fcdddc83037b5073fd9622ab6af4835.tar.gz |
Support HiDPI YAML icons
Diffstat (limited to 'libappstream-glib')
-rw-r--r-- | libappstream-glib/as-app.c | 52 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 4 |
2 files changed, 49 insertions, 7 deletions
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); |