pidgin: 63708026: Use gdk_pixbuf_save_to_buffer() instead ...
markdoliner at pidgin.im
markdoliner at pidgin.im
Fri Mar 26 05:36:06 EDT 2010
-----------------------------------------------------------------
Revision: 6370802635d22e21c8fa94f4c67275f8e545de51
Ancestor: a20e7dec081cc6cb6b2145e2858df8d2e736e334
Author: markdoliner at pidgin.im
Date: 2010-03-26T09:30:00
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/6370802635d22e21c8fa94f4c67275f8e545de51
Modified files:
pidgin/gtkutils.c
ChangeLog:
Use gdk_pixbuf_save_to_buffer() instead of gdk_pixbuf_save() to avoid saving
the image to a temporary file, reading the temporary file, then deleting it.
save_to_buffer() was added in gdk-pixbuf 2.4. It's safe to assume that if
the user has gtk 2.10 then they have gdk_pixbuf 2.4, right?
-------------- next part --------------
============================================================
--- pidgin/gtkutils.c a8b5ac4ca516bcc377c0a0c524a9addac9687de5
+++ pidgin/gtkutils.c 65607cf59581e5034561d50f8dd7c0c42017dc59
@@ -2395,7 +2395,6 @@ pidgin_convert_buddy_icon(PurplePlugin *
GError *error = NULL;
GdkPixbuf *scale;
gboolean success = FALSE;
- char *filename = NULL;
g_strfreev(pixbuf_formats);
@@ -2425,35 +2424,26 @@ pidgin_convert_buddy_icon(PurplePlugin *
}
for (i = 0; prpl_formats[i]; i++) {
- FILE *fp;
-
- g_free(filename);
- fp = purple_mkstemp(&filename, TRUE);
- if (!fp)
- {
- g_free(filename);
- return NULL;
- }
- fclose(fp);
-
- purple_debug_info("buddyicon", "Converting buddy icon to %s as %s\n", prpl_formats[i], filename);
+ purple_debug_info("buddyicon", "Converting buddy icon to %s\n", prpl_formats[i]);
/* The "compression" param wasn't supported until gdk-pixbuf 2.8.
* Using it in previous versions causes the save to fail (and an assert message). */
if ((gdk_pixbuf_major_version > 2 || (gdk_pixbuf_major_version == 2
&& gdk_pixbuf_minor_version >= 8))
&& strcmp(prpl_formats[i], "png") == 0) {
- if (gdk_pixbuf_save(pixbuf, filename, prpl_formats[i],
- &error, "compression", "9", NULL)) {
+ if (gdk_pixbuf_save_to_buffer(pixbuf, &contents, &length,
+ prpl_formats[i], &error, "compression", "9", NULL))
+ {
success = TRUE;
break;
}
- } else if (gdk_pixbuf_save(pixbuf, filename, prpl_formats[i],
- &error, NULL)) {
+ } else if (gdk_pixbuf_save_to_buffer(pixbuf, &contents, &length,
+ prpl_formats[i], &error, NULL))
+ {
success = TRUE;
break;
}
- /* The NULL checking is necessary due to this bug:
+ /* 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", prpl_formats[i],
(error && error->message) ? error->message : "Unknown error");
@@ -2464,24 +2454,8 @@ pidgin_convert_buddy_icon(PurplePlugin *
g_object_unref(G_OBJECT(pixbuf));
if (!success) {
purple_debug_error("buddyicon", "Could not convert icon to usable format.\n");
- g_free(filename);
return NULL;
}
-
- contents = NULL;
- if (!g_file_get_contents(filename, &contents, &length, NULL))
- {
- purple_debug_error("buddyicon",
- "Could not read '%s', which we just wrote to disk.\n",
- filename);
-
- g_free(contents);
- g_free(filename);
- return NULL;
- }
-
- g_unlink(filename);
- g_free(filename);
}
/* Check the image size */
More information about the Commits
mailing list