changeset 23128:ce984959bda0

Add a utility function to create a pixbuf from a stored image.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 28 Apr 2008 06:24:01 +0000
parents 3da84b370eda
children b70b4108799e
files ChangeLog.API pidgin/gtkaccount.c pidgin/gtkutils.c pidgin/gtkutils.h
diffstat 4 files changed, 30 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Mon Apr 28 06:11:36 2008 +0000
+++ b/ChangeLog.API	Mon Apr 28 06:24:01 2008 +0000
@@ -5,6 +5,8 @@
 		Added:
 		* gtk_imhtml_smiley_create, gtk_imhtml_smiley_reload and
 		  gtk_imhtml_smiley_destroy to deal with GtkIMHtmlSmiley's.
+		* pidgin_pixbuf_from_imgstore to create a GdkPixbuf from a
+		  PurpleStoredImage.
 
 version 2.x.x:
 	perl:
--- a/pidgin/gtkaccount.c	Mon Apr 28 06:11:36 2008 +0000
+++ b/pidgin/gtkaccount.c	Mon Apr 28 06:24:01 2008 +0000
@@ -176,14 +176,7 @@
 	}
 
 	if (dialog->icon_img != NULL) {
-		GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
-		gdk_pixbuf_loader_write(loader, purple_imgstore_get_data(dialog->icon_img),
-		                        purple_imgstore_get_size(dialog->icon_img), NULL);
-		gdk_pixbuf_loader_close(loader, NULL);
-		pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
-		if (pixbuf)
-			g_object_ref(pixbuf);
-		g_object_unref(loader);
+		pixbuf = pidgin_pixbuf_from_imgstore(dialog->icon_img);
 	}
 
 	if (pixbuf && dialog->prpl_info &&
@@ -1975,21 +1968,14 @@
 	}
 
 	if (img != NULL) {
-		GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
 		GdkPixbuf *buddyicon_pixbuf;
-
-		gdk_pixbuf_loader_write(loader, purple_imgstore_get_data(img),
-		                        purple_imgstore_get_size(img), NULL);
-		gdk_pixbuf_loader_close(loader, NULL);
-		buddyicon_pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
-
+		buddyicon_pixbuf = pidgin_pixbuf_from_imgstore(img);
 		purple_imgstore_unref(img);
 
 		if (buddyicon_pixbuf != NULL) {
 			buddyicon = gdk_pixbuf_scale_simple(buddyicon_pixbuf, 22, 22, GDK_INTERP_HYPER);
+			g_object_unref(G_OBJECT(buddyicon_pixbuf));
 		}
-
-		g_object_unref(loader);
 	}
 
 	gtk_list_store_set(store, iter,
--- a/pidgin/gtkutils.c	Mon Apr 28 06:11:36 2008 +0000
+++ b/pidgin/gtkutils.c	Mon Apr 28 06:24:01 2008 +0000
@@ -3467,3 +3467,17 @@
 #endif
 }
 
+GdkPixbuf * pidgin_pixbuf_from_imgstore(PurpleStoredImage *image)
+{
+	GdkPixbuf *pixbuf;
+	GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
+	gdk_pixbuf_loader_write(loader, purple_imgstore_get_data(image),
+			purple_imgstore_get_size(image), NULL);
+	gdk_pixbuf_loader_close(loader, NULL);
+	pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
+	if (pixbuf)
+		g_object_ref(pixbuf);
+	g_object_unref(loader);
+	return pixbuf;
+}
+
--- a/pidgin/gtkutils.h	Mon Apr 28 06:11:36 2008 +0000
+++ b/pidgin/gtkutils.h	Mon Apr 28 06:24:01 2008 +0000
@@ -689,7 +689,7 @@
  */
 GtkWidget *pidgin_make_mini_dialog(PurpleConnection *handle,
 	const char* stock_id, const char *primary, const char *secondary,
-	void *user_data, ...);
+	void *user_data, ...) G_GNUC_NULL_TERMINATED;
 
 /**
  * This is a callback function to be used for Ctrl+F searching in treeviews.
@@ -809,5 +809,15 @@
  */
 GtkWidget *pidgin_add_widget_to_vbox(GtkBox *vbox, const char *widget_label, GtkSizeGroup *sg, GtkWidget *widget, gboolean expand, GtkWidget **p_label);
 
+/**
+ * Create a GdkPixbuf from a PurpleStoredImage.
+ *
+ * @param  image   A PurpleStoredImage.
+ *
+ * @return   A GdkPixbuf created from the stored image.
+ * @since 2.5.0
+ */
+GdkPixbuf * pidgin_pixbuf_from_imgstore(PurpleStoredImage *image);
+
 #endif /* _PIDGINUTILS_H_ */