static GdkPixbuf * photos_base_item_create_placeholder_icon (const gchar *icon_name) { GApplication *app; GdkPixbuf *centered_pixbuf = NULL; GdkPixbuf *pixbuf = NULL; GdkPixbuf *ret_val = NULL; GError *error; GIcon *icon = NULL; GList *windows; GtkIconInfo *info = NULL; GtkIconTheme *theme; GtkStyleContext *context; gint icon_size; gint scale; app = g_application_get_default (); windows = gtk_application_get_windows (GTK_APPLICATION (app)); if (windows == NULL) goto out; icon = g_themed_icon_new (icon_name); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); theme = gtk_icon_theme_get_default (); info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, 16, scale, GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_FORCE_SYMBOLIC); if (info == NULL) goto out; context = gtk_widget_get_style_context (GTK_WIDGET (windows->data)); error = NULL; pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, &error); if (error != NULL) { g_warning ("Unable to load icon '%s': %s", icon_name, error->message); g_error_free (error); goto out; } icon_size = photos_utils_get_icon_size (); centered_pixbuf = photos_utils_center_pixbuf (pixbuf, icon_size); photos_utils_border_pixbuf (centered_pixbuf); ret_val = centered_pixbuf; centered_pixbuf = NULL; out: g_clear_object (¢ered_pixbuf); g_clear_object (&pixbuf); g_clear_object (&info); g_clear_object (&icon); return ret_val; }
gint photos_utils_get_icon_size (void) { GApplication *app; gint scale; gint size; app = g_application_get_default (); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); size = photos_utils_get_icon_size_unscaled (); return scale * size; }
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 photos_tool_filter_button_constructed (GObject *object) { PhotosToolFilterButton *self = PHOTOS_TOOL_FILTER_BUTTON (object); GApplication *app; g_autoptr (GdkPixbuf) preview_icon = NULL; GtkWidget *image; PhotosWidgetShader *shader; cairo_surface_t *preview_icon_surface = NULL; /* TODO: use g_autoptr */ gint scale; G_OBJECT_CLASS (photos_tool_filter_button_parent_class)->constructed (object); app = g_application_get_default (); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); preview_icon = photos_utils_create_placeholder_icon_for_scale ("content-loading-symbolic", 96, scale); if (preview_icon != NULL) preview_icon_surface = gdk_cairo_surface_create_from_pixbuf (preview_icon, scale, NULL); image = gtk_image_new_from_surface (preview_icon_surface); gtk_container_add (GTK_CONTAINER (self->overlay), image); shader = photos_widget_shader_new (image); gtk_widget_show (image); self->button = gtk_radio_button_new_with_label_from_widget (self->group, self->label); gtk_button_set_always_show_image (GTK_BUTTON (self->button), TRUE); gtk_button_set_image (GTK_BUTTON (self->button), self->overlay); gtk_button_set_image_position (GTK_BUTTON (self->button), GTK_POS_TOP); gtk_button_set_relief (GTK_BUTTON (self->button), GTK_RELIEF_NONE); gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (self->button), FALSE); gtk_container_add (GTK_CONTAINER (self), self->button); g_object_bind_property (self->button, "active", shader, "active", G_BINDING_SYNC_CREATE); g_signal_connect_swapped (self->button, "toggled", G_CALLBACK (photos_tool_filter_button_toggled), self); photos_tool_filter_button_toggled (self); g_clear_pointer (&preview_icon_surface, (GDestroyNotify) cairo_surface_destroy); self->group = NULL; /* We will not need it any more */ }
static void photos_base_item_check_effects_and_update_info (PhotosBaseItem *self) { PhotosBaseItemPrivate *priv = self->priv; GApplication *app; GIcon *pix; GList *emblem_icons = NULL; GList *windows; GdkPixbuf *emblemed_pixbuf = NULL; GdkPixbuf *thumbnailed_pixbuf = NULL; GdkWindow *window; gint scale; if (priv->original_icon == NULL) goto out; emblemed_pixbuf = g_object_ref (priv->original_icon); if (priv->favorite) { pix = photos_base_item_create_symbolic_emblem (PHOTOS_ICON_FAVORITE); emblem_icons = g_list_prepend (emblem_icons, pix); } if (g_list_length (emblem_icons) > 0) { GIcon *emblemed_icon; GList *l; GtkIconInfo *icon_info; GtkIconTheme *theme; gint height; gint size; gint width; emblem_icons = g_list_reverse (emblem_icons); emblemed_icon = g_emblemed_icon_new (G_ICON (priv->original_icon), NULL); for (l = emblem_icons; l != NULL; l = g_list_next (l)) { GEmblem *emblem; GIcon *emblem_icon = G_ICON (l->data); emblem = g_emblem_new (emblem_icon); g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem); g_object_unref (emblem); } theme = gtk_icon_theme_get_default (); width = gdk_pixbuf_get_width (priv->original_icon); height = gdk_pixbuf_get_height (priv->original_icon); size = (width > height) ? width : height; icon_info = gtk_icon_theme_lookup_by_gicon (theme, emblemed_icon, size, GTK_ICON_LOOKUP_FORCE_SIZE); if (icon_info != NULL) { GError *error = NULL; GdkPixbuf *tmp; tmp = gtk_icon_info_load_icon (icon_info, &error); if (error != NULL) { g_warning ("Unable to render the emblem: %s", error->message); g_error_free (error); } else { g_object_unref (emblemed_pixbuf); emblemed_pixbuf = tmp; } g_object_unref (icon_info); } g_object_unref (emblemed_icon); } g_clear_pointer (&priv->surface, (GDestroyNotify) cairo_surface_destroy); if (priv->thumb_path != NULL) { GtkBorder *slice; slice = photos_utils_get_thumbnail_frame_border (); thumbnailed_pixbuf = gd_embed_image_in_frame (emblemed_pixbuf, "resource:///org/gnome/photos/thumbnail-frame.png", slice, slice); gtk_border_free (slice); } else thumbnailed_pixbuf = g_object_ref (emblemed_pixbuf); app = g_application_get_default (); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); windows = gtk_application_get_windows (GTK_APPLICATION (app)); window = gtk_widget_get_window (GTK_WIDGET (windows->data)); priv->surface = gdk_cairo_surface_create_from_pixbuf (thumbnailed_pixbuf, scale, window); g_signal_emit (self, signals[INFO_UPDATED], 0); out: g_clear_object (&thumbnailed_pixbuf); g_clear_object (&emblemed_pixbuf); g_list_free_full (emblem_icons, g_object_unref); }