[gnome-software] snap: Replace libsoup icon loading code with AsIcon
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] snap: Replace libsoup icon loading code with AsIcon
- Date: Thu, 20 Jul 2017 04:20:17 +0000 (UTC)
commit e601be0bc1de566629c1099d23bb43030d4f9f16
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Jul 20 16:20:06 2017 +1200
snap: Replace libsoup icon loading code with AsIcon
plugins/snap/gs-plugin-snap.c | 48 +++-------------------------------------
1 files changed, 4 insertions(+), 44 deletions(-)
---
diff --git a/plugins/snap/gs-plugin-snap.c b/plugins/snap/gs-plugin-snap.c
index ba03d87..ef7faa7 100644
--- a/plugins/snap/gs-plugin-snap.c
+++ b/plugins/snap/gs-plugin-snap.c
@@ -402,50 +402,10 @@ load_icon (GsPlugin *plugin, GsApp *app, const gchar *icon_url, GCancellable *ca
return FALSE;
}
} else {
- g_autofree gchar *cache_fn = NULL;
- g_autoptr(SoupMessage) message = NULL;
- g_autoptr(GdkPixbufLoader) loader = NULL;
- g_autoptr(GError) local_error = NULL;
-
- /* attempt to load from cache */
- cache_fn = gs_utils_get_cache_filename ("snap-icons", icon_url, GS_UTILS_CACHE_FLAG_USE_HASH
| GS_UTILS_CACHE_FLAG_WRITEABLE, error);
- if (cache_fn == NULL)
- return FALSE;
- if (g_file_test (cache_fn, G_FILE_TEST_EXISTS)) {
- g_autofree gchar *data = NULL;
- gsize data_len;
-
- if (g_file_get_contents (cache_fn, &data, &data_len, &local_error) &&
- gs_plugin_snap_set_app_pixbuf_from_data (app,
- data, data_len,
- &local_error))
- return TRUE;
-
- g_warning ("Failed to load cached icon: %s", local_error->message);
- }
-
- /* load from URL */
- message = soup_message_new (SOUP_METHOD_GET, icon_url);
- if (message == NULL) {
- g_set_error (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_NOT_SUPPORTED,
- "Failed to parse icon URL: %s",
- icon_url);
- return FALSE;
- }
- soup_session_send_message (gs_plugin_get_soup_session (plugin), message);
- if (!gs_plugin_snap_set_app_pixbuf_from_data (app,
- (const gchar *) message->response_body->data,
- message->response_body->length,
- error)) {
- g_prefix_error (error, "Failed to load %s: ", icon_url);
- return FALSE;
- }
-
- /* write to cache */
- if (!g_file_set_contents (cache_fn, message->response_body->data,
message->response_body->length, &local_error))
- g_warning ("Failed to save icon to cache: %s", local_error->message);
+ g_autoptr(AsIcon) icon = as_icon_new ();
+ as_icon_set_kind (icon, AS_ICON_KIND_REMOTE);
+ as_icon_set_url (icon, icon_url);
+ gs_app_add_icon (app, icon);
}
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]