| 120 const char *icon_name = NULL; |
120 const char *icon_name = NULL; |
| 121 |
121 |
| 122 /* Dialog icon. */ |
122 /* Dialog icon. */ |
| 123 icon_data = purple_request_cpar_get_custom_icon(cpar, &icon_size); |
123 icon_data = purple_request_cpar_get_custom_icon(cpar, &icon_size); |
| 124 if (icon_data) { |
124 if (icon_data) { |
| 125 GdkPixbuf *pixbuf; |
125 GBytes *contents = NULL; |
| 126 |
126 GError *error = NULL; |
| 127 pixbuf = purple_gdk_pixbuf_from_data(icon_data, icon_size); |
127 GdkTexture *texture = NULL; |
| 128 if (pixbuf) { |
128 |
| 129 GdkTexture *texture = NULL; |
129 contents = g_bytes_new(icon_data, icon_size); |
| 130 /* scale the image if it is too large */ |
130 texture = gdk_texture_new_from_bytes(contents, &error); |
| 131 int width = gdk_pixbuf_get_width(pixbuf); |
131 g_clear_pointer(&contents, g_bytes_unref); |
| 132 int height = gdk_pixbuf_get_height(pixbuf); |
132 |
| 133 if (width > 128 || height > 128) { |
133 if(error != NULL) { |
| 134 int scaled_width = width > height ? |
134 purple_debug_info("pidgin", "failed to parse dialog icon: %s", |
| 135 128 : (128 * width) / height; |
135 error->message); |
| 136 int scaled_height = height > width ? |
136 g_clear_error(&error); |
| 137 128 : (128 * height) / width; |
137 } else { |
| 138 GdkPixbuf *scaled; |
|
| 139 |
|
| 140 purple_debug_info("pidgin", "dialog icon was " |
|
| 141 "too large, scaling it down"); |
|
| 142 |
|
| 143 scaled = gdk_pixbuf_scale_simple(pixbuf, |
|
| 144 scaled_width, scaled_height, |
|
| 145 GDK_INTERP_BILINEAR); |
|
| 146 if (scaled) { |
|
| 147 g_object_unref(pixbuf); |
|
| 148 pixbuf = scaled; |
|
| 149 } |
|
| 150 } |
|
| 151 texture = gdk_texture_new_for_pixbuf(pixbuf); |
|
| 152 img = gtk_image_new_from_paintable(GDK_PAINTABLE(texture)); |
138 img = gtk_image_new_from_paintable(GDK_PAINTABLE(texture)); |
| 153 g_object_unref(texture); |
139 g_object_unref(texture); |
| 154 g_object_unref(pixbuf); |
140 |
| 155 } else { |
141 gtk_image_set_icon_size(GTK_IMAGE(img), GTK_ICON_SIZE_LARGE); |
| 156 purple_debug_info("pidgin", |
|
| 157 "failed to parse dialog icon"); |
|
| 158 } |
142 } |
| 159 } |
143 } |
| 160 |
144 |
| 161 if (img) |
145 if (img) |
| 162 return img; |
146 return img; |
| 465 |
449 |
| 466 static GtkWidget * |
450 static GtkWidget * |
| 467 create_image_field(PurpleRequestField *field) |
451 create_image_field(PurpleRequestField *field) |
| 468 { |
452 { |
| 469 PurpleRequestFieldImage *ifield = PURPLE_REQUEST_FIELD_IMAGE(field); |
453 PurpleRequestFieldImage *ifield = PURPLE_REQUEST_FIELD_IMAGE(field); |
| |
454 GBytes *contents = NULL; |
| |
455 GError *error = NULL; |
| 470 GdkTexture *texture = NULL; |
456 GdkTexture *texture = NULL; |
| 471 GtkWidget *widget; |
457 GtkWidget *widget; |
| 472 GdkPixbuf *buf, *scale; |
458 gconstpointer data = NULL; |
| 473 |
459 gsize size = 0; |
| 474 buf = purple_gdk_pixbuf_from_data( |
460 |
| 475 (const guchar *)purple_request_field_image_get_buffer(ifield), |
461 data = purple_request_field_image_get_buffer(ifield); |
| 476 purple_request_field_image_get_size(ifield)); |
462 size = purple_request_field_image_get_size(ifield); |
| 477 |
463 |
| 478 scale = gdk_pixbuf_scale_simple(buf, |
464 contents = g_bytes_new(data, size); |
| 479 purple_request_field_image_get_scale_x(ifield) * gdk_pixbuf_get_width(buf), |
465 texture = gdk_texture_new_from_bytes(contents, &error); |
| 480 purple_request_field_image_get_scale_y(ifield) * gdk_pixbuf_get_height(buf), |
466 g_clear_pointer(&contents, g_bytes_unref); |
| 481 GDK_INTERP_BILINEAR); |
467 |
| 482 texture = gdk_texture_new_for_pixbuf(scale); |
468 if(error != NULL) { |
| |
469 purple_debug_warning("requests", |
| |
470 "failed to create text from image field: %s", |
| |
471 error->message); |
| |
472 g_clear_error(&error); |
| |
473 |
| |
474 return NULL; |
| |
475 } |
| |
476 |
| 483 widget = gtk_image_new_from_paintable(GDK_PAINTABLE(texture)); |
477 widget = gtk_image_new_from_paintable(GDK_PAINTABLE(texture)); |
| 484 g_object_unref(texture); |
478 g_object_unref(texture); |
| 485 g_object_unref(scale); |
|
| 486 g_object_unref(buf); |
|
| 487 |
479 |
| 488 return widget; |
480 return widget; |
| 489 } |
481 } |
| 490 |
482 |
| 491 static gboolean |
483 static gboolean |
| 588 if(purple_request_field_list_has_icons(field)) { |
580 if(purple_request_field_list_has_icons(field)) { |
| 589 GtkWidget *image = NULL; |
581 GtkWidget *image = NULL; |
| 590 GdkTexture *texture = NULL; |
582 GdkTexture *texture = NULL; |
| 591 |
583 |
| 592 image = gtk_widget_get_last_child(box); |
584 image = gtk_widget_get_last_child(box); |
| 593 texture = gdk_texture_new_for_pixbuf(g_object_get_data(wrapper, "pixbuf")); |
585 texture = g_object_get_data(wrapper, "texture"); |
| 594 gtk_image_set_from_paintable(GTK_IMAGE(image), GDK_PAINTABLE(texture)); |
586 gtk_image_set_from_paintable(GTK_IMAGE(image), GDK_PAINTABLE(texture)); |
| 595 g_object_unref(texture); |
|
| 596 } |
587 } |
| 597 } |
588 } |
| 598 |
589 |
| 599 static void |
590 static void |
| 600 list_field_select_changed_cb(GtkSelectionModel *self, |
591 list_field_select_changed_cb(GtkSelectionModel *self, |
| 676 purple_request_field_list_get_data(listfield, text)); |
667 purple_request_field_list_get_data(listfield, text)); |
| 677 g_object_set_data_full(wrapper, "text", g_strdup(text), g_free); |
668 g_object_set_data_full(wrapper, "text", g_strdup(text), g_free); |
| 678 |
669 |
| 679 if(has_icons) { |
670 if(has_icons) { |
| 680 const char *icon_path = (const char *)item->value; |
671 const char *icon_path = (const char *)item->value; |
| 681 GdkPixbuf* pixbuf = NULL; |
672 GdkTexture *texture = NULL; |
| 682 |
673 |
| 683 if(icon_path) { |
674 if(icon_path) { |
| 684 pixbuf = purple_gdk_pixbuf_new_from_file(icon_path); |
675 GError *error = NULL; |
| |
676 |
| |
677 texture = gdk_texture_new_from_filename(icon_path, &error); |
| |
678 if(error != NULL) { |
| |
679 purple_debug_warning("requests", |
| |
680 "failed to load icon from %s: %s", |
| |
681 icon_path, error->message); |
| |
682 g_clear_error(&error); |
| |
683 } |
| 685 } |
684 } |
| 686 |
685 |
| 687 g_object_set_data_full(wrapper, "pixbuf", pixbuf, g_object_unref); |
686 g_object_set_data_full(wrapper, "texture", texture, g_object_unref); |
| 688 } |
687 } |
| 689 |
688 |
| 690 if(purple_request_field_list_is_selected(listfield, text)) { |
689 if(purple_request_field_list_is_selected(listfield, text)) { |
| 691 gtk_selection_model_select_item(sel, index, FALSE); |
690 gtk_selection_model_select_item(sel, index, FALSE); |
| 692 } |
691 } |