static void background_loaded_cb (GObject *source, GAsyncResult *res, gpointer data) { BackgroundData *bd = data; GtkWidget *child; GdkPixbuf *pixbuf; GError *error = NULL; pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (error) { g_warning ("Error loading '%s': %s", bd->filename, error->message); g_error_free (error); return; } child = gtk_image_new_from_pixbuf (pixbuf); gtk_widget_show (child); gtk_flow_box_insert (GTK_FLOW_BOX (bd->flowbox), child, -1); child = gtk_widget_get_parent (child); g_object_set_data_full (G_OBJECT (child), "filename", bd->filename, g_free); g_free (bd); }
static void picture_scaled (GObject *source_object, GAsyncResult *res, gpointer user_data) { BgPicturesSource *bg_source; CcBackgroundItem *item; GError *error = NULL; GdkPixbuf *pixbuf; const char *software; const char *uri; GtkTreeIter iter; GtkListStore *store; pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (pixbuf == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to load image: %s", error->message); g_error_free (error); return; } /* since we were not cancelled, we can now cast user_data * back to BgPicturesSource. */ bg_source = BG_PICTURES_SOURCE (user_data); store = bg_source_get_liststore (BG_SOURCE (bg_source)); item = g_object_get_data (source_object, "item"); uri = cc_background_item_get_uri (item); /* Ignore screenshots */ software = gdk_pixbuf_get_option (pixbuf, "tEXt::Software"); if (software != NULL && g_str_equal (software, "gnome-screenshot")) { g_debug ("Ignored URL '%s' as it's a screenshot from gnome-screenshot", cc_background_item_get_uri (item)); g_object_unref (pixbuf); g_object_unref (item); return; } cc_background_item_load (item, NULL); /* insert the item into the liststore */ gtk_list_store_insert_with_values (store, &iter, -1, 0, pixbuf, 1, item, -1); g_hash_table_insert (bg_source->priv->known_items, bg_pictures_source_get_unique_filename (uri), GINT_TO_POINTER (TRUE)); g_object_unref (pixbuf); }
static void pixbuf_from_stream_async_cb (GObject *source, GAsyncResult *res, gpointer user_data) { NemoPreviewCoverArtFetcher *self = user_data; NemoPreviewCoverArtFetcherPrivate *priv = NEMO_PREVIEW_COVER_ART_FETCHER_GET_PRIVATE (self); GError *error = NULL; GdkPixbuf *pix; GFile *file, *cache_file; pix = gdk_pixbuf_new_from_stream_finish (res, &error); if (error != NULL) { if (!self->priv->tried_cache) { self->priv->tried_cache = TRUE; file = get_gfile_for_amazon (self); try_read_from_file (self, file); g_object_unref (file); } else { g_print ("Unable to fetch Amazon cover art: %s\n", error->message); } g_error_free (error); return; } priv->cover = pix; g_object_notify (G_OBJECT (self), "cover"); if (self->priv->tried_cache) { /* the pixbuf has been loaded. if we didn't hit the cache, * save it now. */ cache_file = get_gfile_for_cache (self); g_file_replace_async (cache_file, NULL, FALSE, G_FILE_CREATE_PRIVATE, G_PRIORITY_DEFAULT, NULL, cache_replace_ready_cb, self); g_object_unref (cache_file); } }
static void image_pixbuf_loaded (GInputStream *stream, GAsyncResult *result, GtkWidget *popover) { dg_lerr GError *gerror = NULL; dg_lobj GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream_finish (result, &gerror); if (!pixbuf || gerror) { g_printerr ("Could not decode image from pixbuf: %s", gerror->message); return; } GtkWidget *image = gtk_image_new_from_pixbuf (pixbuf); gtk_container_add (GTK_CONTAINER (popover), image); g_signal_connect (popover, "closed", G_CALLBACK (image_popover_closed), NULL); gtk_widget_show_all (popover); }
static void photos_base_item_refresh_thumb_path_pixbuf (GObject *source_object, GAsyncResult *res, gpointer user_data) { PhotosBaseItem *self = PHOTOS_BASE_ITEM (user_data); PhotosBaseItemPrivate *priv = self->priv; GApplication *app; GdkPixbuf *pixbuf = NULL; GdkPixbuf *scaled_pixbuf = NULL; GError *error = NULL; GInputStream *stream = G_INPUT_STREAM (source_object); gint icon_size; gint scale; pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (error != NULL) { GFile *file; gchar *uri; file = G_FILE (g_object_get_data (G_OBJECT (stream), "file")); uri = g_file_get_uri (file); g_warning ("Unable to create pixbuf from %s: %s", uri, error->message); priv->failed_thumbnailing = TRUE; priv->thumb_path = NULL; g_file_delete_async (file, G_PRIORITY_DEFAULT, NULL, NULL, NULL); photos_base_item_set_failed_icon (self); g_free (uri); g_error_free (error); goto out; } app = g_application_get_default (); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); icon_size = photos_utils_get_icon_size_unscaled (); scaled_pixbuf = photos_utils_downscale_pixbuf_for_scale (pixbuf, icon_size, scale); photos_base_item_set_original_icon (self, scaled_pixbuf); out: g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_clear_object (&scaled_pixbuf); g_clear_object (&pixbuf); g_object_unref (self); }
static void album_art_received (GObject *object, GAsyncResult *result, gpointer user_data) { IdoMediaPlayerMenuItem *self = user_data; GdkPixbuf *pixbuf; GError *error = NULL; pixbuf = gdk_pixbuf_new_from_stream_finish (result, &error); if (pixbuf == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("unable to fetch album art: %s", error->message); g_error_free (error); return; } gtk_image_set_from_pixbuf (GTK_IMAGE (self->album_art), pixbuf); g_object_unref (pixbuf); }
static void www_pixbufRead_cb (GObject *source_object, GAsyncResult *res, struct rom_romItem *item) { GError *error = NULL; GInputStream *stream = G_INPUT_STREAM (source_object); item->tile = gdk_pixbuf_new_from_stream_finish (res, &error); g_input_stream_close_async (stream, G_PRIORITY_HIGH, NULL, (GAsyncReadyCallback) www_closeStream_cb, NULL); gchar* localName = www_getFileNameWWW (item->name); if (!error) { g_print ("%s fetched %s \n", item->name, SUCCESS_MSG); if (gdk_pixbuf_save (item->tile, localName, "png", &error, NULL)) { g_print ("%s saved %s \n", item->name, SUCCESS_MSG); } else { g_print ("%s not saved %s \n", item->name, FAIL_MSG); g_warning ("can't save: %s\n", error->message); g_error_free (error); } } else { g_warning ("pixbuf stream error:%s\n", error->message); g_error_free (error); item->tile = NULL; } item->tileLoaded = TRUE; item->tileLoading = FALSE; g_free (localName); if (ui_tileIsVisible (item)) { ui_invalidateDrawingArea (); } www_downloadingItm--; }
static void picture_scaled (GObject *source_object, GAsyncResult *res, gpointer user_data) { BgPicturesSource *bg_source; CcBackgroundItem *item; GError *error = NULL; GdkPixbuf *pixbuf = NULL; const char *software; const char *uri; GtkTreeIter iter; GtkTreePath *path; GtkTreeRowReference *row_ref; GtkListStore *store; cairo_surface_t *surface = NULL; int scale_factor; item = g_object_get_data (source_object, "item"); pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (pixbuf == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_warning ("Failed to load image: %s", error->message); remove_placeholder (BG_PICTURES_SOURCE (user_data), item); } g_error_free (error); goto out; } /* since we were not cancelled, we can now cast user_data * back to BgPicturesSource. */ bg_source = BG_PICTURES_SOURCE (user_data); store = bg_source_get_liststore (BG_SOURCE (bg_source)); uri = cc_background_item_get_uri (item); if (uri == NULL) uri = cc_background_item_get_source_url (item); /* Ignore screenshots */ software = gdk_pixbuf_get_option (pixbuf, "tEXt::Software"); if (software != NULL && g_str_equal (software, "gnome-screenshot")) { g_debug ("Ignored URL '%s' as it's a screenshot from gnome-screenshot", uri); remove_placeholder (BG_PICTURES_SOURCE (user_data), item); goto out; } scale_factor = bg_source_get_scale_factor (BG_SOURCE (bg_source)); surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL); cc_background_item_load (item, NULL); row_ref = g_object_get_data (G_OBJECT (item), "row-ref"); if (row_ref == NULL) { /* insert the item into the liststore if it did not exist */ gtk_list_store_insert_with_values (store, NULL, -1, 0, surface, 1, item, -1); } else { path = gtk_tree_row_reference_get_path (row_ref); if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) { /* otherwise update the thumbnail */ gtk_list_store_set (store, &iter, 0, surface, -1); } } g_hash_table_insert (bg_source->priv->known_items, bg_pictures_source_get_unique_filename (uri), GINT_TO_POINTER (TRUE)); out: g_clear_pointer (&surface, (GDestroyNotify) cairo_surface_destroy); g_clear_object (&pixbuf); }
static void picture_scaled (GObject *source_object, GAsyncResult *res, gpointer user_data) { BgPicturesSource *bg_source; CcBackgroundItem *item; GError *error = NULL; GdkPixbuf *pixbuf; const char *source_url; const char *software; GtkTreeIter iter; GtkListStore *store; pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (pixbuf == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to load image: %s", error->message); g_error_free (error); return; } /* since we were not cancelled, we can now cast user_data * back to BgPicturesSource. */ bg_source = BG_PICTURES_SOURCE (user_data); store = bg_source_get_liststore (BG_SOURCE (bg_source)); item = g_object_get_data (source_object, "item"); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store), 1, (GtkTreeIterCompareFunc)sort_func, bg_source, NULL); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 1, GTK_SORT_ASCENDING); /* Ignore screenshots */ software = gdk_pixbuf_get_option (pixbuf, "tEXt::Software"); if (software != NULL && g_str_equal (software, "gnome-screenshot")) { g_debug ("Ignored URL '%s' as it's a screenshot from gnome-screenshot", cc_background_item_get_uri (item)); g_object_unref (pixbuf); g_object_unref (item); return; } cc_background_item_load (item, NULL); /* insert the item into the liststore */ gtk_list_store_insert_with_values (store, &iter, 0, 0, pixbuf, 1, item, -1); source_url = cc_background_item_get_source_url (item); if (source_url != NULL) { g_hash_table_insert (bg_source->priv->known_items, bg_pictures_source_get_unique_filename (source_url), GINT_TO_POINTER (TRUE)); } else { char *cache_path; GFile *file, *parent, *dir; cache_path = bg_pictures_source_get_cache_path (); dir = g_file_new_for_path (cache_path); g_free (cache_path); file = g_file_new_for_uri (cc_background_item_get_uri (item)); parent = g_file_get_parent (file); if (g_file_equal (parent, dir)) { char *basename; basename = g_file_get_basename (file); g_hash_table_insert (bg_source->priv->known_items, basename, GINT_TO_POINTER (TRUE)); } g_object_unref (file); g_object_unref (parent); } g_object_unref (pixbuf); }
/* Callback when loading icon asynchronously has finished */ static void _xfdashboard_image_content_loading_async_callback(GObject *inSource, GAsyncResult *inResult, gpointer inUserData) { XfdashboardImageContent *self=XFDASHBOARD_IMAGE_CONTENT(inUserData); XfdashboardImageContentPrivate *priv=self->priv; GdkPixbuf *pixbuf; GError *error=NULL; priv->loadState=XFDASHBOARD_IMAGE_CONTENT_LOADING_STATE_LOADED_SUCCESSFULLY; /* Get pixbuf loaded */ pixbuf=gdk_pixbuf_new_from_stream_finish(inResult, &error); if(pixbuf) { /* Set image data into content */ if(!clutter_image_set_data(CLUTTER_IMAGE(self), gdk_pixbuf_get_pixels(pixbuf), gdk_pixbuf_get_has_alpha(pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), gdk_pixbuf_get_rowstride(pixbuf), &error)) { g_warning(_("Failed to load image data into content for key '%s': %s"), priv->key ? priv->key : "<nil>", error ? error->message : _("Unknown error")); if(error) { g_error_free(error); error=NULL; } /* Set failed state and empty image */ _xfdashboard_image_content_set_empty_image(self); priv->loadState=XFDASHBOARD_IMAGE_CONTENT_LOADING_STATE_LOADED_FAILED; } } else { g_warning(_("Failed to load image for key '%s': %s"), priv->key ? priv->key : "<nil>", error ? error->message : _("Unknown error")); if(error) { g_error_free(error); error=NULL; } /* Set failed state and empty image */ _xfdashboard_image_content_set_empty_image(self); priv->loadState=XFDASHBOARD_IMAGE_CONTENT_LOADING_STATE_LOADED_FAILED; } /* Release allocated resources */ if(pixbuf) g_object_unref(pixbuf); /* Emit "loaded" signal if loading was successful ... */ if(priv->loadState==XFDASHBOARD_IMAGE_CONTENT_LOADING_STATE_LOADED_SUCCESSFULLY) { g_signal_emit(self, XfdashboardImageContentSignals[SIGNAL_LOADED], 0); g_debug("Successfully loaded image for key '%s' asynchronously", priv->key ? priv->key : "<nil>"); } /* ... or emit "loading-failed" signal if loading has failed. */ else { g_signal_emit(self, XfdashboardImageContentSignals[SIGNAL_LOADING_FAILED], 0); g_debug("Failed to load image for key '%s' asynchronously", priv->key ? priv->key : "<nil>"); } /* Now release the extra reference we took to keep this instance alive * while loading asynchronously. */ g_object_unref(self); }
static void image_rendered_cb (GInputStream *stream, GAsyncResult *res, RendererData *data) { ChamplainTile *tile = data->tile; gboolean error = TRUE; GError *gerror = NULL; ClutterActor *actor = NULL; GdkPixbuf *pixbuf; ClutterContent *content; gfloat width, height; pixbuf = gdk_pixbuf_new_from_stream_finish (res, NULL); if (!pixbuf) { g_warning ("NULL pixbuf"); goto finish; } /* Load the image into clutter */ content = clutter_image_new (); if (!clutter_image_set_data (CLUTTER_IMAGE (content), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), &gerror)) { if (gerror) { g_warning ("Unable to transfer to clutter: %s", gerror->message); g_error_free (gerror); } g_object_unref (content); goto finish; } clutter_content_get_preferred_size (content, &width, &height); actor = clutter_actor_new (); clutter_actor_set_size (actor, width, height); clutter_actor_set_content (actor, content); g_object_unref (content); /* has to be set for proper opacity */ clutter_actor_set_offscreen_redirect (actor, CLUTTER_OFFSCREEN_REDIRECT_AUTOMATIC_FOR_OPACITY); error = FALSE; finish: if (actor) champlain_tile_set_content (tile, actor); g_signal_emit_by_name (tile, "render-complete", data->data, data->size, error); if (pixbuf) g_object_unref (pixbuf); g_object_unref (data->renderer); g_object_unref (tile); g_object_unref (stream); g_free (data->data); g_slice_free (RendererData, data); }
static void picture_scaled (GObject *source_object, GAsyncResult *res, gpointer user_data) { BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data); CcBackgroundItem *item; GError *error = NULL; GdkPixbuf *pixbuf; const char *source_url; GtkTreeIter iter; GtkListStore *store; store = bg_source_get_liststore (BG_SOURCE (bg_source)); item = g_object_get_data (source_object, "item"); pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (pixbuf == NULL) { g_warning ("Failed to load image: %s", error->message); g_error_free (error); g_object_unref (item); return; } /* insert the item into the liststore */ gtk_list_store_insert_with_values (store, &iter, 0, 0, pixbuf, 1, item, -1); source_url = cc_background_item_get_source_url (item); if (source_url != NULL) { g_hash_table_insert (bg_source->priv->known_items, bg_pictures_source_get_unique_filename (source_url), GINT_TO_POINTER (TRUE)); } else { char *cache_path; GFile *file, *parent, *dir; cache_path = bg_pictures_source_get_cache_path (); dir = g_file_new_for_path (cache_path); g_free (cache_path); file = g_file_new_for_uri (cc_background_item_get_uri (item)); parent = g_file_get_parent (file); if (g_file_equal (parent, dir)) { char *basename; basename = g_file_get_basename (file); g_hash_table_insert (bg_source->priv->known_items, basename, GINT_TO_POINTER (TRUE)); } g_object_unref (file); g_object_unref (parent); } g_object_unref (pixbuf); }