GdkPixbuf* utils_download_picture(SoupSession* soup, const gchar* url) { SoupMessage* msg; GdkPixbuf* ret = NULL; GInputStream* input; GError* err = NULL; msg = soup_message_new("GET", url); input = soup_session_send(soup, msg, NULL, &err); if (err) { g_warning("{Utils} Error downloading picture code '%d' message '%s'", err->code, err->message); g_error_free(err); } else { ret = gdk_pixbuf_new_from_stream(input, NULL, NULL); g_input_stream_close(input, NULL, NULL); } g_object_unref(msg); return ret; }
GdkPixbuf* utils_download_picture(SoupSession* soup, const gchar* url) { SoupMessage* msg; GdkPixbuf* ret; GInputStream* input; msg = soup_message_new("GET", url); input = soup_session_send(soup, msg, NULL, NULL); ret = gdk_pixbuf_new_from_stream(input, NULL, NULL); g_input_stream_close(input, NULL, NULL); g_object_unref(msg); return ret; }
GdkPixbuf* gt_resource_downloader_download_image(GtResourceDownloader* self, const gchar* uri, const gchar* name, GError** error) { RETURN_VAL_IF_FAIL(GT_IS_RESOURCE_DOWNLOADER(self), NULL); RETURN_VAL_IF_FAIL(!utils_str_empty(uri), NULL); GtResourceDownloaderPrivate* priv = gt_resource_downloader_get_instance_private(self); g_autoptr(SoupMessage) msg = NULL; g_autoptr(GInputStream) istream = NULL; g_autoptr(GdkPixbuf) ret = NULL; g_autoptr(GError) err = NULL; DEBUG("Downloading image from uri '%s'", uri); msg = soup_message_new(SOUP_METHOD_GET, uri); /* NOTE: So libsoup isn't actually all that thread safe and * calling soup_session_send from multiple threads causes it to * crash, so we wrap a mutex around it. One should use the * download_image_immediately func if one wants to download * several images at the same time */ g_mutex_lock(&priv->mutex); istream = soup_session_send(priv->soup, msg, NULL, &err); g_mutex_unlock(&priv->mutex); if (err) { WARNING("Unable to download image from uri '%s' because: %s", uri, err->message); g_propagate_prefixed_error(error, g_steal_pointer(&err), "Unable to download image from uri '%s' because: ", uri); return NULL; } ret = download_image(self, uri, name, msg, istream, NULL, error); return g_steal_pointer(&ret); }