summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-01-22 16:18:08 +0000
committerRichard Hughes <richard@hughsie.com>2016-01-22 17:11:30 +0000
commit7972026fda210e8d8001df7ad2b11b8cb3bcd8b5 (patch)
treeb8523d41a46a48ae0873e1f0ab8bbe9bbbe6f1ba
parentd12d2cffe4d8ae10d84aa57bb21927256040894b (diff)
downloadappstream-glib-7972026fda210e8d8001df7ad2b11b8cb3bcd8b5.tar.gz
Only load supported icon kinds when using appstream-compose
-rw-r--r--client/as-compose.c1
-rw-r--r--libappstream-builder/plugins/asb-plugin-desktop.c38
-rw-r--r--libappstream-glib/as-image.c23
-rw-r--r--libappstream-glib/as-image.h2
4 files changed, 35 insertions, 29 deletions
diff --git a/client/as-compose.c b/client/as-compose.c
index 6bca881..579661c 100644
--- a/client/as-compose.c
+++ b/client/as-compose.c
@@ -88,6 +88,7 @@ add_icons (AsApp *app,
im = as_image_new ();
if (!as_image_load_filename_full (im, fn,
64, min_icon_size,
+ AS_IMAGE_LOAD_FLAG_ONLY_SUPPORTED |
AS_IMAGE_LOAD_FLAG_SHARPEN,
error)) {
g_prefix_error (error, "Failed to load icon: ");
diff --git a/libappstream-builder/plugins/asb-plugin-desktop.c b/libappstream-builder/plugins/asb-plugin-desktop.c
index ff0382d..f15eb40 100644
--- a/libappstream-builder/plugins/asb-plugin-desktop.c
+++ b/libappstream-builder/plugins/asb-plugin-desktop.c
@@ -56,7 +56,7 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs)
* asb_app_load_icon:
*/
static GdkPixbuf *
-asb_app_load_icon (AsbApp *app,
+asb_app_load_icon (AsbPlugin *plugin,
const gchar *filename,
const gchar *logfn,
guint icon_size,
@@ -65,13 +65,18 @@ asb_app_load_icon (AsbApp *app,
{
g_autoptr(AsImage) im = NULL;
g_autoptr(GError) error_local = NULL;
+ AsImageLoadFlags load_flags = AS_IMAGE_LOAD_FLAG_NONE;
+
+ /* is icon in a unsupported format */
+ if (!asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_IGNORE_LEGACY_ICONS))
+ load_flags |= AS_IMAGE_LOAD_FLAG_ONLY_SUPPORTED;
im = as_image_new ();
if (!as_image_load_filename_full (im,
filename,
icon_size,
min_icon_size,
- AS_IMAGE_LOAD_FLAG_NONE,
+ load_flags,
&error_local)) {
g_set_error (error,
ASB_PLUGIN_ERROR,
@@ -112,34 +117,9 @@ asb_plugin_desktop_add_icons (AsbPlugin *plugin,
return FALSE;
}
- /* is icon in a unsupported format */
- if (!asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_IGNORE_LEGACY_ICONS)) {
- if (g_str_has_suffix (fn, ".xpm")) {
- g_set_error (error,
- ASB_PLUGIN_ERROR,
- ASB_PLUGIN_ERROR_NOT_SUPPORTED,
- "Uses XPM icon: %s", key);
- return FALSE;
- }
- if (g_str_has_suffix (fn, ".gif")) {
- g_set_error (error,
- ASB_PLUGIN_ERROR,
- ASB_PLUGIN_ERROR_NOT_SUPPORTED,
- "Uses GIF icon: %s", key);
- return FALSE;
- }
- if (g_str_has_suffix (fn, ".ico")) {
- g_set_error (error,
- ASB_PLUGIN_ERROR,
- ASB_PLUGIN_ERROR_NOT_SUPPORTED,
- "Uses ICO icon: %s", key);
- return FALSE;
- }
- }
-
/* load the icon */
min_icon_size = asb_context_get_min_icon_size (plugin->ctx);
- pixbuf = asb_app_load_icon (app, fn, fn + strlen (tmpdir),
+ pixbuf = asb_app_load_icon (plugin, fn, fn + strlen (tmpdir),
64, min_icon_size, error);
if (pixbuf == NULL) {
g_prefix_error (error, "Failed to load icon: ");
@@ -174,7 +154,7 @@ asb_plugin_desktop_add_icons (AsbPlugin *plugin,
return TRUE;
/* load the HiDPI icon */
- pixbuf_hidpi = asb_app_load_icon (app, fn_hidpi,
+ pixbuf_hidpi = asb_app_load_icon (plugin, fn_hidpi,
fn_hidpi + strlen (tmpdir),
128, 128, NULL);
if (pixbuf_hidpi == NULL)
diff --git a/libappstream-glib/as-image.c b/libappstream-glib/as-image.c
index 10e1032..49a86c2 100644
--- a/libappstream-glib/as-image.c
+++ b/libappstream-glib/as-image.c
@@ -503,6 +503,29 @@ as_image_load_filename_full (AsImage *image,
g_autoptr(GdkPixbuf) pixbuf_src = NULL;
g_autoptr(GdkPixbuf) pixbuf_tmp = NULL;
+ /* only support non-deprecated types */
+ if (flags & AS_IMAGE_LOAD_FLAG_ONLY_SUPPORTED) {
+ GdkPixbufFormat *fmt;
+ fmt = gdk_pixbuf_get_file_info (filename, NULL, NULL);
+ if (fmt == NULL) {
+ g_set_error_literal (error,
+ AS_UTILS_ERROR,
+ AS_UTILS_ERROR_FAILED,
+ "image format was not recognized");
+ return FALSE;
+ }
+ if (g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "png") != 0 &&
+ g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "jpeg") != 0 &&
+ g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "svg") != 0) {
+ g_set_error (error,
+ AS_UTILS_ERROR,
+ AS_UTILS_ERROR_FAILED,
+ "image format %s is not supported",
+ gdk_pixbuf_format_get_name (fmt));
+ return FALSE;
+ }
+ }
+
/* update basename */
if (flags & AS_IMAGE_LOAD_FLAG_SET_BASENAME) {
g_autofree gchar *basename = NULL;
diff --git a/libappstream-glib/as-image.h b/libappstream-glib/as-image.h
index fb5fa07..376670d 100644
--- a/libappstream-glib/as-image.h
+++ b/libappstream-glib/as-image.h
@@ -88,6 +88,7 @@ typedef enum {
* @AS_IMAGE_LOAD_FLAG_SHARPEN: Sharpen the resulting image
* @AS_IMAGE_LOAD_FLAG_SET_BASENAME: Set the image basename
* @AS_IMAGE_LOAD_FLAG_SET_CHECKSUM: Set the image checksum
+ * @AS_IMAGE_LOAD_FLAG_ONLY_SUPPORTED: Only load supported formats like PNG and JPG
*
* The flags used for loading images.
**/
@@ -96,6 +97,7 @@ typedef enum {
AS_IMAGE_LOAD_FLAG_SHARPEN = 1, /* Since: 0.5.6 */
AS_IMAGE_LOAD_FLAG_SET_BASENAME = 2, /* Since: 0.5.6 */
AS_IMAGE_LOAD_FLAG_SET_CHECKSUM = 4, /* Since: 0.5.6 */
+ AS_IMAGE_LOAD_FLAG_ONLY_SUPPORTED = 8, /* Since: 0.5.6 */
/*< private >*/
AS_IMAGE_LOAD_FLAG_LAST
} AsImageLoadFlags;