diff -r 6b1dc67b861d -r 78a984e17548 pidgin/gtkutils.c --- a/pidgin/gtkutils.c Fri Sep 30 03:12:09 2022 -0500 +++ b/pidgin/gtkutils.c Fri Sep 30 04:02:12 2022 -0500 @@ -175,12 +175,6 @@ void pidgin_set_accessible_label(GtkWidget *w, GtkLabel *l) { - pidgin_set_accessible_relations(w, l); -} - -void -pidgin_set_accessible_relations (GtkWidget *w, GtkLabel *l) -{ GtkAccessible *acc, *label; acc = GTK_ACCESSIBLE(w); @@ -194,23 +188,6 @@ label, NULL, -1); } -void pidgin_buddy_icon_get_scale_size(GdkPixbuf *buf, PurpleBuddyIconSpec *spec, PurpleBuddyIconScaleFlags rules, int *width, int *height) -{ - *width = gdk_pixbuf_get_width(buf); - *height = gdk_pixbuf_get_height(buf); - - if ((spec == NULL) || !(spec->scale_rules & rules)) - return; - - purple_buddy_icon_spec_get_scaled_size(spec, width, height); - - /* and now for some arbitrary sanity checks */ - if(*width > 100) - *width = 100; - if(*height > 100) - *height = 100; -} - static gboolean buddyname_completion_match_func(GtkEntryCompletion *completion, const gchar *key, GtkTreeIter *iter, gpointer user_data) { @@ -473,207 +450,6 @@ } /* - * str_array_match: - * - * Returns: %TRUE if any string from array @a exists in array @b. - */ -static gboolean -str_array_match(char **a, char **b) -{ - int i, j; - - if (!a || !b) - return FALSE; - for (i = 0; a[i] != NULL; i++) - for (j = 0; b[j] != NULL; j++) - if (!g_ascii_strcasecmp(a[i], b[j])) - return TRUE; - return FALSE; -} - -gpointer -pidgin_convert_buddy_icon(PurpleProtocol *protocol, const char *path, size_t *len) -{ - PurpleBuddyIconSpec *spec; - int orig_width, orig_height, new_width, new_height; - GdkPixbufFormat *format; - char **pixbuf_formats; - char **protocol_formats; - GError *error = NULL; - gchar *contents; - gsize length; - GdkPixbuf *pixbuf, *original; - float scale_factor; - int i; - gchar *tmp; - - spec = purple_protocol_get_icon_spec(protocol); - if(spec->format == NULL) { - purple_buddy_icon_spec_free(spec); - - return NULL; - } - - format = gdk_pixbuf_get_file_info(path, &orig_width, &orig_height); - if (format == NULL) { - purple_debug_warning("buddyicon", "Could not get file info of %s\n", path); - - purple_buddy_icon_spec_free(spec); - - return NULL; - } - - pixbuf_formats = gdk_pixbuf_format_get_extensions(format); - protocol_formats = g_strsplit(spec->format, ",", 0); - - if (str_array_match(pixbuf_formats, protocol_formats) && /* This is an acceptable format AND */ - (!(spec->scale_rules & PURPLE_ICON_SCALE_SEND) || /* The protocol doesn't scale before it sends OR */ - (spec->min_width <= orig_width && spec->max_width >= orig_width && - spec->min_height <= orig_height && spec->max_height >= orig_height))) /* The icon is the correct size */ - { - g_strfreev(pixbuf_formats); - - if (!g_file_get_contents(path, &contents, &length, &error)) { - purple_debug_warning("buddyicon", "Could not get file contents " - "of %s: %s\n", path, error->message); - g_strfreev(protocol_formats); - purple_buddy_icon_spec_free(spec); - return NULL; - } - - if (spec->max_filesize == 0 || length < spec->max_filesize) { - /* The supplied image fits the file size, dimensions and type - constraints. Great! Return it without making any changes. */ - if (len) - *len = length; - g_strfreev(protocol_formats); - purple_buddy_icon_spec_free(spec); - return contents; - } - - /* The image was too big. Fall-through and try scaling it down. */ - g_free(contents); - } else { - g_strfreev(pixbuf_formats); - } - - /* The original image wasn't compatible. Scale it or convert file type. */ - pixbuf = gdk_pixbuf_new_from_file(path, &error); - if (error) { - purple_debug_warning("buddyicon", "Could not open icon '%s' for " - "conversion: %s\n", path, error->message); - g_error_free(error); - g_strfreev(protocol_formats); - purple_buddy_icon_spec_free(spec); - return NULL; - } - original = g_object_ref(pixbuf); - - new_width = orig_width; - new_height = orig_height; - - /* Make sure the image is the correct dimensions */ - if (spec->scale_rules & PURPLE_ICON_SCALE_SEND && - (orig_width < spec->min_width || orig_width > spec->max_width || - orig_height < spec->min_height || orig_height > spec->max_height)) - { - purple_buddy_icon_spec_get_scaled_size(spec, &new_width, &new_height); - - g_object_unref(G_OBJECT(pixbuf)); - pixbuf = gdk_pixbuf_scale_simple(original, new_width, new_height, GDK_INTERP_HYPER); - } - - scale_factor = 1; - do { - for (i = 0; protocol_formats[i]; i++) { - int quality = 100; - do { - const char *key = NULL; - const char *value = NULL; - gchar tmp_buf[4]; - - purple_debug_info("buddyicon", "Converting buddy icon to %s\n", protocol_formats[i]); - - if (purple_strequal(protocol_formats[i], "png")) { - key = "compression"; - value = "9"; - } else if (purple_strequal(protocol_formats[i], "jpeg")) { - sprintf(tmp_buf, "%u", quality); - key = "quality"; - value = tmp_buf; - } - - if (!gdk_pixbuf_save_to_buffer(pixbuf, &contents, &length, - protocol_formats[i], &error, key, value, NULL)) - { - /* The NULL checking of error is necessary due to this bug: - * http://bugzilla.gnome.org/show_bug.cgi?id=405539 */ - purple_debug_warning("buddyicon", - "Could not convert to %s: %s\n", protocol_formats[i], - (error && error->message) ? error->message : "Unknown error"); - g_error_free(error); - error = NULL; - - /* We couldn't convert to this image type. Try the next - image type. */ - break; - } - - if (spec->max_filesize == 0 || length <= spec->max_filesize) { - /* We were able to save the image as this image type and - have it be within the size constraints. Great! Return - the image. */ - purple_debug_info("buddyicon", "Converted image from " - "%dx%d to %dx%d, format=%s, quality=%u, " - "filesize=%" G_GSIZE_FORMAT "\n", - orig_width, orig_height, new_width, new_height, - protocol_formats[i], quality, length); - if (len) - *len = length; - g_strfreev(protocol_formats); - g_object_unref(G_OBJECT(pixbuf)); - g_object_unref(G_OBJECT(original)); - purple_buddy_icon_spec_free(spec); - return contents; - } - - g_free(contents); - - if (!purple_strequal(protocol_formats[i], "jpeg")) { - /* File size was too big and we can't lower the quality, - so skip to the next image type. */ - break; - } - - /* File size was too big, but we're dealing with jpeg so try - lowering the quality. */ - quality -= 5; - } while (quality >= 70); - } - - /* We couldn't save the image in any format that was below the max - file size. Maybe we can reduce the image dimensions? */ - scale_factor *= 0.8; - new_width = orig_width * scale_factor; - new_height = orig_height * scale_factor; - g_object_unref(G_OBJECT(pixbuf)); - pixbuf = gdk_pixbuf_scale_simple(original, new_width, new_height, GDK_INTERP_HYPER); - } while ((new_width > 10 || new_height > 10) && new_width > spec->min_width && new_height > spec->min_height); - g_strfreev(protocol_formats); - g_object_unref(G_OBJECT(pixbuf)); - g_object_unref(G_OBJECT(original)); - - tmp = g_strdup_printf(_("The file '%s' is too large for %s. Please try a smaller image.\n"), - path, purple_protocol_get_name(protocol)); - purple_notify_error(NULL, _("Icon Error"), _("Could not set icon"), tmp, NULL); - g_free(tmp); - - purple_buddy_icon_spec_free(spec); - - return NULL; -} - -/* * "This is so dead sexy." * "Two thumbs up." * "Best movie of the year."