/** * asb_plugin_desktop_add_icons: */ static gboolean asb_plugin_desktop_add_icons (AsbPlugin *plugin, AsbApp *app, const gchar *tmpdir, const gchar *key, GError **error) { guint min_icon_size; _cleanup_free_ gchar *fn_hidpi = NULL; _cleanup_free_ gchar *fn = NULL; _cleanup_free_ gchar *name_hidpi = NULL; _cleanup_free_ gchar *name = NULL; _cleanup_object_unref_ AsIcon *icon_hidpi = NULL; _cleanup_object_unref_ AsIcon *icon = NULL; _cleanup_object_unref_ GdkPixbuf *pixbuf_hidpi = NULL; _cleanup_object_unref_ GdkPixbuf *pixbuf = NULL; /* find 64x64 icon */ fn = as_utils_find_icon_filename_full (tmpdir, key, AS_UTILS_FIND_ICON_NONE, error); if (fn == NULL) { g_prefix_error (error, "Failed to find icon: "); 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), 64, min_icon_size, error); if (pixbuf == NULL) { g_prefix_error (error, "Failed to load icon: "); return FALSE; } /* save in target directory */ if (asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)) { name = g_strdup_printf ("%ix%i/%s.png", 64, 64, as_app_get_id_filename (AS_APP (app))); } else { name = g_strdup_printf ("%s.png", as_app_get_id_filename (AS_APP (app))); } icon = as_icon_new (); as_icon_set_pixbuf (icon, pixbuf); as_icon_set_name (icon, name); as_icon_set_kind (icon, AS_ICON_KIND_CACHED); as_icon_set_prefix (icon, as_app_get_icon_path (AS_APP (app))); as_app_add_icon (AS_APP (app), icon); /* is HiDPI disabled */ if (!asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)) return TRUE; /* try to get a HiDPI icon */ fn_hidpi = as_utils_find_icon_filename_full (tmpdir, key, AS_UTILS_FIND_ICON_HI_DPI, NULL); if (fn_hidpi == NULL) return TRUE; /* load the HiDPI icon */ pixbuf_hidpi = asb_app_load_icon (app, fn_hidpi, fn_hidpi + strlen (tmpdir), 128, 128, NULL); if (pixbuf_hidpi == NULL) return TRUE; if (gdk_pixbuf_get_width (pixbuf_hidpi) <= gdk_pixbuf_get_width (pixbuf) || gdk_pixbuf_get_height (pixbuf_hidpi) <= gdk_pixbuf_get_height (pixbuf)) return TRUE; as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_HI_DPI_ICON); /* save icon */ name_hidpi = g_strdup_printf ("%ix%i/%s.png", 128, 128, as_app_get_id_filename (AS_APP (app))); icon_hidpi = as_icon_new (); as_icon_set_pixbuf (icon_hidpi, pixbuf_hidpi); as_icon_set_name (icon_hidpi, name_hidpi); as_icon_set_kind (icon_hidpi, AS_ICON_KIND_CACHED); as_icon_set_prefix (icon_hidpi, as_app_get_icon_path (AS_APP (app))); as_app_add_icon (AS_APP (app), icon_hidpi); return TRUE; }
static gboolean asb_plugin_desktop_add_icons (AsbPlugin *plugin, AsbApp *app, const gchar *tmpdir, const gchar *key, GError **error) { guint min_icon_size; g_autofree gchar *fn_hidpi = NULL; g_autofree gchar *fn = NULL; g_autofree gchar *name_hidpi = NULL; g_autofree gchar *name = NULL; g_autoptr(AsIcon) icon_hidpi = NULL; g_autoptr(AsIcon) icon = NULL; g_autoptr(GdkPixbuf) pixbuf_hidpi = NULL; g_autoptr(GdkPixbuf) pixbuf = NULL; /* find 64x64 icon */ fn = as_utils_find_icon_filename_full (tmpdir, key, AS_UTILS_FIND_ICON_NONE, error); if (fn == NULL) { g_prefix_error (error, "Failed to find icon: "); return FALSE; } /* load the icon */ min_icon_size = asb_context_get_min_icon_size (plugin->ctx); 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: "); return FALSE; } /* save in target directory */ if (asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)) { name = g_strdup_printf ("%ix%i/%s.png", 64, 64, as_app_get_id_filename (AS_APP (app))); } else { name = g_strdup_printf ("%s.png", as_app_get_id_filename (AS_APP (app))); } icon = as_icon_new (); as_icon_set_pixbuf (icon, pixbuf); as_icon_set_name (icon, name); as_icon_set_kind (icon, AS_ICON_KIND_CACHED); as_icon_set_prefix (icon, as_app_get_icon_path (AS_APP (app))); as_app_add_icon (AS_APP (app), icon); /* is HiDPI disabled */ if (!asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)) return TRUE; /* try to get a HiDPI icon */ fn_hidpi = as_utils_find_icon_filename_full (tmpdir, key, AS_UTILS_FIND_ICON_HI_DPI, NULL); if (fn_hidpi == NULL) return TRUE; /* load the HiDPI icon */ pixbuf_hidpi = asb_app_load_icon (plugin, fn_hidpi, fn_hidpi + strlen (tmpdir), 128, 128, NULL); if (pixbuf_hidpi == NULL) return TRUE; if (gdk_pixbuf_get_width (pixbuf_hidpi) <= gdk_pixbuf_get_width (pixbuf) || gdk_pixbuf_get_height (pixbuf_hidpi) <= gdk_pixbuf_get_height (pixbuf)) return TRUE; as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_HI_DPI_ICON); /* save icon */ name_hidpi = g_strdup_printf ("%ix%i/%s.png", 128, 128, as_app_get_id_filename (AS_APP (app))); icon_hidpi = as_icon_new (); as_icon_set_pixbuf (icon_hidpi, pixbuf_hidpi); as_icon_set_name (icon_hidpi, name_hidpi); as_icon_set_kind (icon_hidpi, AS_ICON_KIND_CACHED); as_icon_set_prefix (icon_hidpi, as_app_get_icon_path (AS_APP (app))); as_app_add_icon (AS_APP (app), icon_hidpi); return TRUE; }