pidgin/gtkrequest.c

changeset 43295
28b187312791
parent 42979
d9f973ac3afd
--- a/pidgin/gtkrequest.c	Fri Jul 25 00:18:05 2025 -0500
+++ b/pidgin/gtkrequest.c	Thu Jul 31 16:54:02 2025 -0500
@@ -122,39 +122,23 @@
 	/* Dialog icon. */
 	icon_data = purple_request_cpar_get_custom_icon(cpar, &icon_size);
 	if (icon_data) {
-		GdkPixbuf *pixbuf;
+		GBytes *contents = NULL;
+		GError *error = NULL;
+		GdkTexture *texture = NULL;
 
-		pixbuf = purple_gdk_pixbuf_from_data(icon_data, icon_size);
-		if (pixbuf) {
-			GdkTexture *texture = NULL;
-			/* scale the image if it is too large */
-			int width = gdk_pixbuf_get_width(pixbuf);
-			int height = gdk_pixbuf_get_height(pixbuf);
-			if (width > 128 || height > 128) {
-				int scaled_width = width > height ?
-					128 : (128 * width) / height;
-				int scaled_height = height > width ?
-					128 : (128 * height) / width;
-				GdkPixbuf *scaled;
+		contents = g_bytes_new(icon_data, icon_size);
+		texture = gdk_texture_new_from_bytes(contents, &error);
+		g_clear_pointer(&contents, g_bytes_unref);
 
-				purple_debug_info("pidgin", "dialog icon was "
-					"too large, scaling it down");
-
-				scaled = gdk_pixbuf_scale_simple(pixbuf,
-					scaled_width, scaled_height,
-					GDK_INTERP_BILINEAR);
-				if (scaled) {
-					g_object_unref(pixbuf);
-					pixbuf = scaled;
-				}
-			}
-			texture = gdk_texture_new_for_pixbuf(pixbuf);
+		if(error != NULL) {
+			purple_debug_info("pidgin", "failed to parse dialog icon: %s",
+			                  error->message);
+			g_clear_error(&error);
+		} else {
 			img = gtk_image_new_from_paintable(GDK_PAINTABLE(texture));
 			g_object_unref(texture);
-			g_object_unref(pixbuf);
-		} else {
-			purple_debug_info("pidgin",
-				"failed to parse dialog icon");
+
+			gtk_image_set_icon_size(GTK_IMAGE(img), GTK_ICON_SIZE_LARGE);
 		}
 	}
 
@@ -467,23 +451,31 @@
 create_image_field(PurpleRequestField *field)
 {
 	PurpleRequestFieldImage *ifield = PURPLE_REQUEST_FIELD_IMAGE(field);
+	GBytes *contents = NULL;
+	GError *error = NULL;
 	GdkTexture *texture = NULL;
 	GtkWidget *widget;
-	GdkPixbuf *buf, *scale;
+	gconstpointer data = NULL;
+	gsize size = 0;
 
-	buf = purple_gdk_pixbuf_from_data(
-			(const guchar *)purple_request_field_image_get_buffer(ifield),
-			purple_request_field_image_get_size(ifield));
+	data = purple_request_field_image_get_buffer(ifield);
+	size = purple_request_field_image_get_size(ifield);
+
+	contents = g_bytes_new(data, size);
+	texture = gdk_texture_new_from_bytes(contents, &error);
+	g_clear_pointer(&contents, g_bytes_unref);
 
-	scale = gdk_pixbuf_scale_simple(buf,
-			purple_request_field_image_get_scale_x(ifield) * gdk_pixbuf_get_width(buf),
-			purple_request_field_image_get_scale_y(ifield) * gdk_pixbuf_get_height(buf),
-			GDK_INTERP_BILINEAR);
-	texture = gdk_texture_new_for_pixbuf(scale);
+	if(error != NULL) {
+		purple_debug_warning("requests",
+		                     "failed to create text from image field: %s",
+		                     error->message);
+		g_clear_error(&error);
+
+		return NULL;
+	}
+
 	widget = gtk_image_new_from_paintable(GDK_PAINTABLE(texture));
 	g_object_unref(texture);
-	g_object_unref(scale);
-	g_object_unref(buf);
 
 	return widget;
 }
@@ -590,9 +582,8 @@
 		GdkTexture *texture = NULL;
 
 		image = gtk_widget_get_last_child(box);
-		texture = gdk_texture_new_for_pixbuf(g_object_get_data(wrapper, "pixbuf"));
+		texture = g_object_get_data(wrapper, "texture");
 		gtk_image_set_from_paintable(GTK_IMAGE(image), GDK_PAINTABLE(texture));
-		g_object_unref(texture);
 	}
 }
 
@@ -678,13 +669,21 @@
 
 		if(has_icons) {
 			const char *icon_path = (const char *)item->value;
-			GdkPixbuf* pixbuf = NULL;
+			GdkTexture *texture = NULL;
 
 			if(icon_path) {
-				pixbuf = purple_gdk_pixbuf_new_from_file(icon_path);
+				GError *error = NULL;
+
+				texture = gdk_texture_new_from_filename(icon_path, &error);
+				if(error != NULL) {
+					purple_debug_warning("requests",
+					                     "failed to load icon from %s: %s",
+					                     icon_path, error->message);
+					g_clear_error(&error);
+				}
 			}
 
-			g_object_set_data_full(wrapper, "pixbuf", pixbuf, g_object_unref);
+			g_object_set_data_full(wrapper, "texture", texture, g_object_unref);
 		}
 
 		if(purple_request_field_list_is_selected(listfield, text)) {

mercurial