changeset 7898:9c0ea21997a9

[gaim-migrate @ 8558] Added the core list request stuff. This will be added to in a moment, because I just realized I forgot something really stupid. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 21 Dec 2003 07:52:26 +0000
parents e90d3d430798
children 7b64108b8ae3
files src/request.c src/request.h
diffstat 2 files changed, 151 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/request.c	Sun Dec 21 04:06:30 2003 +0000
+++ b/src/request.c	Sun Dec 21 07:52:26 2003 +0000
@@ -269,22 +269,35 @@
 	if (field->label != NULL)
 		g_free(field->label);
 
-	if (field->type == GAIM_REQUEST_FIELD_STRING) {
+	if (field->type == GAIM_REQUEST_FIELD_STRING)
+	{
 		if (field->u.string.default_value != NULL)
 			g_free(field->u.string.default_value);
 
 		if (field->u.string.value != NULL)
 			g_free(field->u.string.value);
 	}
-	else if (field->type == GAIM_REQUEST_FIELD_CHOICE) {
-		GList *l;
-
-		for (l = field->u.choice.labels; l != NULL; l = l->next) {
-			g_free(l->data);
+	else if (field->type == GAIM_REQUEST_FIELD_CHOICE)
+	{
+		if (field->u.choice.labels != NULL)
+		{
+			g_list_foreach(field->u.choice.labels, (GFunc)g_free, NULL);
+			g_list_free(field->u.choice.labels);
+		}
+	}
+	else if (field->type == GAIM_REQUEST_FIELD_LIST)
+	{
+		if (field->u.list.items != NULL)
+		{
+			g_list_foreach(field->u.list.items, (GFunc)g_free, NULL);
+			g_list_free(field->u.list.items);
 		}
 
-		if (field->u.choice.labels != NULL)
-			g_list_free(field->u.choice.labels);
+		if (field->u.list.selected != NULL)
+		{
+			g_list_foreach(field->u.list.selected, (GFunc)g_free, NULL);
+			g_list_free(field->u.list.selected);
+		}
 	}
 
 	g_free(field);
@@ -618,6 +631,65 @@
 	return field->u.choice.labels;
 }
 
+GaimRequestField *
+gaim_request_field_list_new(const char *id, const char *text, GList *items)
+{
+	GaimRequestField *field;
+
+	g_return_val_if_fail(id    != NULL, NULL);
+	g_return_val_if_fail(items != NULL, NULL);
+
+	field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_LIST);
+
+	gaim_request_field_list_set_items(field, items);
+
+	return field;
+}
+
+void
+gaim_request_field_list_set_items(GaimRequestField *field, GList *items)
+{
+	g_return_if_fail(field != NULL);
+	g_return_if_fail(items != NULL);
+	g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST);
+
+	if (field->u.list.items != NULL)
+	{
+		g_list_foreach(field->u.list.items, (GFunc)g_free, NULL);
+		g_list_free(field->u.list.items);
+	}
+
+	field->u.list.items = items;
+}
+
+void
+gaim_request_field_list_add(GaimRequestField *field, const char *item)
+{
+	g_return_if_fail(field != NULL);
+	g_return_if_fail(item  != NULL);
+	g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST);
+
+	field->u.list.items = g_list_append(field->u.list.items, g_strdup(item));
+}
+
+const GList *
+gaim_request_field_list_get_selected(const GaimRequestField *field)
+{
+	g_return_val_if_fail(field != NULL, NULL);
+	g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, NULL);
+
+	return field->u.list.selected;
+}
+
+const GList *
+gaim_request_field_list_get_items(const GaimRequestField *field)
+{
+	g_return_val_if_fail(field != NULL, NULL);
+	g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, NULL);
+
+	return field->u.list.items;
+}
+
 /* -- */
 
 void *
--- a/src/request.h	Sun Dec 21 04:06:30 2003 +0000
+++ b/src/request.h	Sun Dec 21 07:52:26 2003 +0000
@@ -48,7 +48,8 @@
 	GAIM_REQUEST_FIELD_STRING,
 	GAIM_REQUEST_FIELD_INTEGER,
 	GAIM_REQUEST_FIELD_BOOLEAN,
-	GAIM_REQUEST_FIELD_CHOICE
+	GAIM_REQUEST_FIELD_CHOICE,
+	GAIM_REQUEST_FIELD_LIST
 
 } GaimRequestFieldType;
 
@@ -97,6 +98,15 @@
 
 		} choice;
 
+		struct
+		{
+			GList *items;
+			GList *selected;
+
+			gboolean multiple_selection;
+
+		} list;
+
 	} u;
 
 	void *ui_data;
@@ -434,7 +444,7 @@
  * Returns the default value in a string field.
  *
  * @param field The field.
- * 
+ *
  * @return The default value.
  */
 const char *gaim_request_field_string_get_default_value(
@@ -517,7 +527,7 @@
  * Returns the default value in an integer field.
  *
  * @param field The field.
- * 
+ *
  * @return The default value.
  */
 int gaim_request_field_int_get_default_value(const GaimRequestField *field);
@@ -642,7 +652,7 @@
  * Returns the default value in an choice field.
  *
  * @param field The field.
- * 
+ *
  * @return The default value.
  */
 int gaim_request_field_choice_get_default_value(const GaimRequestField *field);
@@ -668,6 +678,63 @@
 /*@}*/
 
 /**************************************************************************/
+/** @name List Field API                                                  */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Creates a multiple list item field.
+ *
+ * @param id    The field ID.
+ * @param text  The optional label of the field.
+ * @param items The list of items.
+ *
+ * @return The new field.
+ */
+GaimRequestField *gaim_request_field_list_new(const char *id, const char *text,
+											  GList *items);
+
+/**
+ * Sets the list of items in a list field.
+ *
+ * The items are not copied. The actual list passed is assigned to the field.
+ *
+ * @param field The list field.
+ * @param items The items.
+ */
+void gaim_request_field_list_set_items(GaimRequestField *field, GList *items);
+
+/**
+ * Adds an item to a list field.
+ *
+ * @param field The list field.
+ * @param item  The list item.
+ */
+void gaim_request_field_list_add(GaimRequestField *field, const char *item);
+
+/**
+ * Returns a list of selected items in a list field.
+ *
+ * @param field The field.
+ *
+ * @return The list of selected items.
+ */
+const GList *gaim_request_field_list_get_selected(
+	const GaimRequestField *field);
+
+/**
+ * Returns a list of items in a list field.
+ *
+ * @param field The field.
+ *
+ * @return The list of items.
+ */
+const GList *gaim_request_field_list_get_items(const GaimRequestField *field);
+
+/*@}*/
+
+
+/**************************************************************************/
 /** @name Request API                                                     */
 /**************************************************************************/
 /*@{*/