Mercurial > pidgin.yaz
changeset 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 | 96b71ea64386 |
children | b02b30247e7a |
files | src/gtkrequest.c src/request.c src/request.h |
diffstat | 3 files changed, 67 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkrequest.c Wed Dec 31 07:51:37 2003 +0000 +++ b/src/gtkrequest.c Wed Dec 31 08:05:22 2003 +0000 @@ -683,6 +683,9 @@ 0, gaim_request_field_list_get_data(field, text), 1, text, -1); + + if (gaim_request_field_list_is_selected(field, text)) + gtk_tree_selection_select_iter(sel, &iter); } gtk_container_add(GTK_CONTAINER(sw), treeview);
--- 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 *
--- a/src/request.h Wed Dec 31 07:51:37 2003 +0000 +++ b/src/request.h Wed Dec 31 08:05:22 2003 +0000 @@ -106,6 +106,7 @@ GList *items; GHashTable *item_data; GList *selected; + GHashTable *selected_table; gboolean multiple_selection; @@ -780,6 +781,17 @@ GList *items); /** + * Returns whether or not a particular item is selected in a list field. + * + * @param field The field. + * @param item The item. + * + * @return TRUE if the item is selected. FALSE otherwise. + */ +gboolean gaim_request_field_list_is_selected(const GaimRequestField *field, + const char *item); + +/** * Returns a list of selected items in a list field. * * To retrieve the data for each item, use