Mercurial > pidgin
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 7963:96b71ea64386 | 7964:a5c70e43ee43 |
|---|---|
| 19 * You should have received a copy of the GNU General Public License | 19 * You should have received a copy of the GNU General Public License |
| 20 * along with this program; if not, write to the Free Software | 20 * along with this program; if not, write to the Free Software |
| 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 */ | 22 */ |
| 23 #include "request.h" | 23 #include "request.h" |
| 24 #include "debug.h" | |
| 24 | 25 |
| 25 static GaimRequestUiOps *request_ui_ops = NULL; | 26 static GaimRequestUiOps *request_ui_ops = NULL; |
| 26 static GList *handles = NULL; | 27 static GList *handles = NULL; |
| 27 | 28 |
| 28 typedef struct | 29 typedef struct |
| 299 g_list_foreach(field->u.list.selected, (GFunc)g_free, NULL); | 300 g_list_foreach(field->u.list.selected, (GFunc)g_free, NULL); |
| 300 g_list_free(field->u.list.selected); | 301 g_list_free(field->u.list.selected); |
| 301 } | 302 } |
| 302 | 303 |
| 303 g_hash_table_destroy(field->u.list.item_data); | 304 g_hash_table_destroy(field->u.list.item_data); |
| 305 g_hash_table_destroy(field->u.list.selected_table); | |
| 304 } | 306 } |
| 305 | 307 |
| 306 g_free(field); | 308 g_free(field); |
| 307 } | 309 } |
| 308 | 310 |
| 661 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_LIST); | 663 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_LIST); |
| 662 | 664 |
| 663 field->u.list.item_data = g_hash_table_new_full(g_str_hash, g_str_equal, | 665 field->u.list.item_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 664 g_free, NULL); | 666 g_free, NULL); |
| 665 | 667 |
| 668 field->u.list.selected_table = | |
| 669 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
| 670 | |
| 666 return field; | 671 return field; |
| 667 } | 672 } |
| 668 | 673 |
| 669 void | 674 void |
| 670 gaim_request_field_list_set_multi_select(GaimRequestField *field, | 675 gaim_request_field_list_set_multi_select(GaimRequestField *field, |
| 715 { | 720 { |
| 716 g_return_if_fail(field != NULL); | 721 g_return_if_fail(field != NULL); |
| 717 g_return_if_fail(item != NULL); | 722 g_return_if_fail(item != NULL); |
| 718 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST); | 723 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST); |
| 719 | 724 |
| 725 if (!gaim_request_field_list_get_multi_select(field) && | |
| 726 field->u.list.selected != NULL) | |
| 727 { | |
| 728 gaim_debug_warning("request", | |
| 729 "More than one item added to non-multi-select " | |
| 730 "field %s\n", | |
| 731 gaim_request_field_get_id(field)); | |
| 732 return; | |
| 733 } | |
| 734 | |
| 720 field->u.list.selected = g_list_append(field->u.list.selected, | 735 field->u.list.selected = g_list_append(field->u.list.selected, |
| 721 g_strdup(item)); | 736 g_strdup(item)); |
| 737 | |
| 738 g_hash_table_insert(field->u.list.selected_table, g_strdup(item), NULL); | |
| 722 } | 739 } |
| 723 | 740 |
| 724 void | 741 void |
| 725 gaim_request_field_list_clear_selected(GaimRequestField *field) | 742 gaim_request_field_list_clear_selected(GaimRequestField *field) |
| 726 { | 743 { |
| 731 { | 748 { |
| 732 g_list_foreach(field->u.list.selected, (GFunc)g_free, NULL); | 749 g_list_foreach(field->u.list.selected, (GFunc)g_free, NULL); |
| 733 g_list_free(field->u.list.selected); | 750 g_list_free(field->u.list.selected); |
| 734 field->u.list.selected = NULL; | 751 field->u.list.selected = NULL; |
| 735 } | 752 } |
| 753 | |
| 754 g_hash_table_destroy(field->u.list.selected_table); | |
| 755 | |
| 756 field->u.list.selected_table = | |
| 757 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
| 736 } | 758 } |
| 737 | 759 |
| 738 void | 760 void |
| 739 gaim_request_field_list_set_selected(GaimRequestField *field, GList *items) | 761 gaim_request_field_list_set_selected(GaimRequestField *field, GList *items) |
| 740 { | 762 { |
| 763 GList *l; | |
| 764 | |
| 741 g_return_if_fail(field != NULL); | 765 g_return_if_fail(field != NULL); |
| 742 g_return_if_fail(items != NULL); | 766 g_return_if_fail(items != NULL); |
| 743 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST); | 767 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST); |
| 744 | 768 |
| 745 gaim_request_field_list_clear_selected(field); | 769 gaim_request_field_list_clear_selected(field); |
| 746 | 770 |
| 771 if (!gaim_request_field_list_get_multi_select(field) && | |
| 772 g_list_length(items) > 1) | |
| 773 { | |
| 774 gaim_debug_warning("request", | |
| 775 "More than one item added to non-multi-select " | |
| 776 "field %s\n", | |
| 777 gaim_request_field_get_id(field)); | |
| 778 return; | |
| 779 } | |
| 780 | |
| 747 field->u.list.selected = items; | 781 field->u.list.selected = items; |
| 782 | |
| 783 for (l = field->u.list.selected; l != NULL; l = l->next) | |
| 784 { | |
| 785 g_hash_table_insert(field->u.list.selected_table, | |
| 786 g_strdup((char *)l->data), NULL); | |
| 787 } | |
| 788 } | |
| 789 | |
| 790 gboolean | |
| 791 gaim_request_field_list_is_selected(const GaimRequestField *field, | |
| 792 const char *item) | |
| 793 { | |
| 794 g_return_val_if_fail(field != NULL, FALSE); | |
| 795 g_return_val_if_fail(item != NULL, FALSE); | |
| 796 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, FALSE); | |
| 797 | |
| 798 return g_hash_table_lookup_extended(field->u.list.selected_table, | |
| 799 item, NULL, NULL); | |
| 748 } | 800 } |
| 749 | 801 |
| 750 const GList * | 802 const GList * |
| 751 gaim_request_field_list_get_selected(const GaimRequestField *field) | 803 gaim_request_field_list_get_selected(const GaimRequestField *field) |
| 752 { | 804 { |
