changeset 11357:f0bc5f121684

[gaim-migrate @ 13579] Image field added to the request API. committer: Tailor Script <tailor@pidgin.im>
author Bartoz Oler <bartosz@pidgin.im>
date Sun, 28 Aug 2005 22:16:17 +0000
parents 0b746a52238d
children fb702c34794b
files src/gtkrequest.c src/request.c src/request.h
diffstat 3 files changed, 157 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkrequest.c	Sun Aug 28 21:43:47 2005 +0000
+++ b/src/gtkrequest.c	Sun Aug 28 22:16:17 2005 +0000
@@ -1241,6 +1241,32 @@
 }
 
 static GtkWidget *
+create_image_field(GaimRequestField *field)
+{
+	GtkWidget *widget;
+	GdkPixbuf *buf, *scale;
+	GdkPixbufLoader *loader;
+
+	loader = gdk_pixbuf_loader_new();
+	gdk_pixbuf_loader_write(loader,
+							(const guchar *)gaim_request_field_image_get_buffer(field),
+							gaim_request_field_image_get_size(field),
+							NULL);
+	gdk_pixbuf_loader_close(loader, NULL);
+	buf = gdk_pixbuf_loader_get_pixbuf(loader);
+
+	scale = gdk_pixbuf_scale_simple(buf,
+			gaim_request_field_image_get_scale_x(field) * gdk_pixbuf_get_width(buf),
+			gaim_request_field_image_get_scale_y(field) * gdk_pixbuf_get_height(buf),
+			GDK_INTERP_BILINEAR);
+	widget = gtk_image_new_from_pixbuf(scale);
+	g_object_unref(G_OBJECT(buf));
+	g_object_unref(G_OBJECT(scale));
+
+	return widget;
+}
+
+static GtkWidget *
 create_account_field(GaimRequestField *field)
 {
 	GtkWidget *widget;
@@ -1604,6 +1630,8 @@
 					widget = create_choice_field(field);
 				else if (type == GAIM_REQUEST_FIELD_LIST)
 					widget = create_list_field(field);
+				else if (type == GAIM_REQUEST_FIELD_IMAGE)
+					widget = create_image_field(field);
 				else if (type == GAIM_REQUEST_FIELD_ACCOUNT)
 					widget = create_account_field(field);
 				else
--- a/src/request.c	Sun Aug 28 21:43:47 2005 +0000
+++ b/src/request.c	Sun Aug 28 22:16:17 2005 +0000
@@ -978,6 +978,71 @@
 	return field;
 }
 
+GaimRequestField *
+gaim_request_field_image_new(const char *id, const char *text, const char *buf, gsize size)
+{
+	GaimRequestField *field;
+
+	g_return_val_if_fail(id   != NULL, NULL);
+	g_return_val_if_fail(text != NULL, NULL);
+	g_return_val_if_fail(buf  != NULL, NULL);
+	g_return_val_if_fail(size > 0, NULL);
+
+	field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_IMAGE);
+
+	field->u.image.buffer  = g_memdup(buf, size);
+	field->u.image.size    = size;
+	field->u.image.scale_x = 1;
+	field->u.image.scale_y = 1;
+
+	return field;
+}
+
+void
+gaim_request_field_image_set_scale(GaimRequestField *field, unsigned int x, unsigned int y)
+{
+	g_return_if_fail(field != NULL);
+	g_return_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE);
+
+	field->u.image.scale_x = x;
+	field->u.image.scale_y = y;
+}
+
+const char *
+gaim_request_field_image_get_buffer(GaimRequestField *field)
+{
+	g_return_val_if_fail(field != NULL, NULL);
+	g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE, NULL);
+
+	return field->u.image.buffer;
+}
+
+gsize
+gaim_request_field_image_get_size(GaimRequestField *field)
+{
+	g_return_val_if_fail(field != NULL, 0);
+	g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE, 0);
+
+	return field->u.image.size;
+}
+
+unsigned int
+gaim_request_field_image_get_scale_x(GaimRequestField *field)
+{
+	g_return_val_if_fail(field != NULL, 0);
+	g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE, 0);
+
+	return field->u.image.scale_x;
+}
+
+unsigned int
+gaim_request_field_image_get_scale_y(GaimRequestField *field)
+{
+	g_return_val_if_fail(field != NULL, 0);
+	g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE, 0);
+
+	return field->u.image.scale_y;
+}
 
 GaimRequestField *
 gaim_request_field_account_new(const char *id, const char *text,
--- a/src/request.h	Sun Aug 28 21:43:47 2005 +0000
+++ b/src/request.h	Sun Aug 28 22:16:17 2005 +0000
@@ -58,6 +58,7 @@
 	GAIM_REQUEST_FIELD_CHOICE,
 	GAIM_REQUEST_FIELD_LIST,
 	GAIM_REQUEST_FIELD_LABEL,
+	GAIM_REQUEST_FIELD_IMAGE,
 	GAIM_REQUEST_FIELD_ACCOUNT
 
 } GaimRequestFieldType;
@@ -161,6 +162,14 @@
 
 		} account;
 
+		struct
+		{
+			unsigned int scale_x;
+			unsigned int scale_y;
+			const char *buffer;
+			gsize size;
+		} image;
+
 	} u;
 
 	void *ui_data;
@@ -952,6 +961,61 @@
 /*@}*/
 
 /**************************************************************************/
+/** @name Image Field API                                                 */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Creates an image field.
+ *
+ * @param id   The field ID.
+ * @param text The label of the field.
+ * @param path Path to the image to be displayed.
+ *
+ * @return The new field.
+ */
+GaimRequestField *gaim_request_field_image_new(const char *id, const char *text,
+											   const char *buf, gsize size);
+
+/**
+ * Returns pointer to the image.
+ *
+ * @param field The image field.
+ *
+ * @return Pointer to the image.
+ */
+const char *gaim_request_field_image_get_buffer(GaimRequestField *field);
+
+/**
+ * Returns size (in bytes) of the image.
+ *
+ * @param field The image field.
+ *
+ * @return Size of the image.
+ */
+gsize gaim_request_field_image_get_size(GaimRequestField *field);
+
+/**
+ * Returns X scale coefficient of the image.
+ *
+ * @param field The image field.
+ *
+ * @return X scale coefficient of the image.
+ */
+unsigned int gaim_request_field_image_get_scale_x(GaimRequestField *field);
+
+/**
+ * Returns Y scale coefficient of the image.
+ *
+ * @param field The image field.
+ *
+ * @return Y scale coefficient of the image.
+ */
+unsigned int gaim_request_field_image_get_scale_y(GaimRequestField *field);
+
+/*@}*/
+
+/**************************************************************************/
 /** @name Account Field API                                               */
 /**************************************************************************/
 /*@{*/