[gnome-software/wip/ubuntu-3-20: 34/34] snap: Replace libsoup icon loading code with AsIcon



commit 775d7a053b90e1d9f72b667eef2f56dffc3219be
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Aug 24 11:35:54 2017 +1200

    snap: Replace libsoup icon loading code with AsIcon

 src/plugins/gs-plugin-snap.c |   40 +++++++++-------------------------------
 1 files changed, 9 insertions(+), 31 deletions(-)
---
diff --git a/src/plugins/gs-plugin-snap.c b/src/plugins/gs-plugin-snap.c
index 1af7db0..b626afd 100644
--- a/src/plugins/gs-plugin-snap.c
+++ b/src/plugins/gs-plugin-snap.c
@@ -396,6 +396,10 @@ load_icon (GsPlugin *plugin, GsApp *app, const gchar *icon_url, GCancellable *ca
                g_autoptr(SoupMessage) message = NULL;
                g_autoptr(GdkPixbufLoader) loader = NULL;
                g_autoptr(GError) local_error = NULL;
+               g_autoptr(AsIcon) icon = NULL;
+
+               icon = as_icon_new ();
+               gs_app_set_icon (app, icon);
 
                /* attempt to load from cache */
                basename_tmp = g_path_get_basename (icon_url);
@@ -403,43 +407,17 @@ load_icon (GsPlugin *plugin, GsApp *app, const gchar *icon_url, GCancellable *ca
                basename = g_strdup_printf ("%s-%s", hash, basename_tmp);
                cache_dir = gs_utils_get_cachedir ("snap-icons", error);
                cache_fn = g_build_filename (cache_dir, basename, NULL);
-               if (cache_fn == NULL)
-                       return FALSE;
+               as_icon_set_filename (icon, cache_fn);
                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))
+                       as_icon_set_kind (icon, AS_ICON_KIND_LOCAL);
+                       if (gs_app_load_icon (app, plugin->scale, &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 (plugin->soup_session, 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);
+               as_icon_set_kind (icon, AS_ICON_KIND_REMOTE);
+               as_icon_set_url (icon, icon_url);
        }
 
        return TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]