Mercurial > pidgin
diff src/request.c @ 7964:a5c70e43ee43
[gaim-migrate @ 8641]
The multiple item list should now prevent against multiple selections when
it's a non-multi-select list, and should automatically select the items in
the selection list when creating the dialog. Also added a hashtable and a
function for determining if a particular item is selected.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 31 Dec 2003 08:05:22 +0000 |
parents | cc77bd88cd72 |
children | fa6395637e2c |
line wrap: on
line diff
--- a/src/request.c Wed Dec 31 07:51:37 2003 +0000 +++ b/src/request.c Wed Dec 31 08:05:22 2003 +0000 @@ -21,6 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "request.h" +#include "debug.h" static GaimRequestUiOps *request_ui_ops = NULL; static GList *handles = NULL; @@ -301,6 +302,7 @@ } g_hash_table_destroy(field->u.list.item_data); + g_hash_table_destroy(field->u.list.selected_table); } g_free(field); @@ -663,6 +665,9 @@ field->u.list.item_data = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + field->u.list.selected_table = + g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + return field; } @@ -717,8 +722,20 @@ g_return_if_fail(item != NULL); g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST); + if (!gaim_request_field_list_get_multi_select(field) && + field->u.list.selected != NULL) + { + gaim_debug_warning("request", + "More than one item added to non-multi-select " + "field %s\n", + gaim_request_field_get_id(field)); + return; + } + field->u.list.selected = g_list_append(field->u.list.selected, g_strdup(item)); + + g_hash_table_insert(field->u.list.selected_table, g_strdup(item), NULL); } void @@ -733,18 +750,53 @@ g_list_free(field->u.list.selected); field->u.list.selected = NULL; } + + g_hash_table_destroy(field->u.list.selected_table); + + field->u.list.selected_table = + g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); } void gaim_request_field_list_set_selected(GaimRequestField *field, GList *items) { + GList *l; + g_return_if_fail(field != NULL); g_return_if_fail(items != NULL); g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST); gaim_request_field_list_clear_selected(field); + if (!gaim_request_field_list_get_multi_select(field) && + g_list_length(items) > 1) + { + gaim_debug_warning("request", + "More than one item added to non-multi-select " + "field %s\n", + gaim_request_field_get_id(field)); + return; + } + field->u.list.selected = items; + + for (l = field->u.list.selected; l != NULL; l = l->next) + { + g_hash_table_insert(field->u.list.selected_table, + g_strdup((char *)l->data), NULL); + } +} + +gboolean +gaim_request_field_list_is_selected(const GaimRequestField *field, + const char *item) +{ + g_return_val_if_fail(field != NULL, FALSE); + g_return_val_if_fail(item != NULL, FALSE); + g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, FALSE); + + return g_hash_table_lookup_extended(field->u.list.selected_table, + item, NULL, NULL); } const GList *