comparison src/request.c @ 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 9408c12b4a61
children 7b64108b8ae3
comparison
equal deleted inserted replaced
7897:e90d3d430798 7898:9c0ea21997a9
267 g_free(field->id); 267 g_free(field->id);
268 268
269 if (field->label != NULL) 269 if (field->label != NULL)
270 g_free(field->label); 270 g_free(field->label);
271 271
272 if (field->type == GAIM_REQUEST_FIELD_STRING) { 272 if (field->type == GAIM_REQUEST_FIELD_STRING)
273 {
273 if (field->u.string.default_value != NULL) 274 if (field->u.string.default_value != NULL)
274 g_free(field->u.string.default_value); 275 g_free(field->u.string.default_value);
275 276
276 if (field->u.string.value != NULL) 277 if (field->u.string.value != NULL)
277 g_free(field->u.string.value); 278 g_free(field->u.string.value);
278 } 279 }
279 else if (field->type == GAIM_REQUEST_FIELD_CHOICE) { 280 else if (field->type == GAIM_REQUEST_FIELD_CHOICE)
280 GList *l; 281 {
281 282 if (field->u.choice.labels != NULL)
282 for (l = field->u.choice.labels; l != NULL; l = l->next) { 283 {
283 g_free(l->data); 284 g_list_foreach(field->u.choice.labels, (GFunc)g_free, NULL);
285 g_list_free(field->u.choice.labels);
284 } 286 }
285 287 }
286 if (field->u.choice.labels != NULL) 288 else if (field->type == GAIM_REQUEST_FIELD_LIST)
287 g_list_free(field->u.choice.labels); 289 {
290 if (field->u.list.items != NULL)
291 {
292 g_list_foreach(field->u.list.items, (GFunc)g_free, NULL);
293 g_list_free(field->u.list.items);
294 }
295
296 if (field->u.list.selected != NULL)
297 {
298 g_list_foreach(field->u.list.selected, (GFunc)g_free, NULL);
299 g_list_free(field->u.list.selected);
300 }
288 } 301 }
289 302
290 g_free(field); 303 g_free(field);
291 } 304 }
292 305
614 { 627 {
615 g_return_val_if_fail(field != NULL, NULL); 628 g_return_val_if_fail(field != NULL, NULL);
616 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_CHOICE, NULL); 629 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_CHOICE, NULL);
617 630
618 return field->u.choice.labels; 631 return field->u.choice.labels;
632 }
633
634 GaimRequestField *
635 gaim_request_field_list_new(const char *id, const char *text, GList *items)
636 {
637 GaimRequestField *field;
638
639 g_return_val_if_fail(id != NULL, NULL);
640 g_return_val_if_fail(items != NULL, NULL);
641
642 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_LIST);
643
644 gaim_request_field_list_set_items(field, items);
645
646 return field;
647 }
648
649 void
650 gaim_request_field_list_set_items(GaimRequestField *field, GList *items)
651 {
652 g_return_if_fail(field != NULL);
653 g_return_if_fail(items != NULL);
654 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST);
655
656 if (field->u.list.items != NULL)
657 {
658 g_list_foreach(field->u.list.items, (GFunc)g_free, NULL);
659 g_list_free(field->u.list.items);
660 }
661
662 field->u.list.items = items;
663 }
664
665 void
666 gaim_request_field_list_add(GaimRequestField *field, const char *item)
667 {
668 g_return_if_fail(field != NULL);
669 g_return_if_fail(item != NULL);
670 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST);
671
672 field->u.list.items = g_list_append(field->u.list.items, g_strdup(item));
673 }
674
675 const GList *
676 gaim_request_field_list_get_selected(const GaimRequestField *field)
677 {
678 g_return_val_if_fail(field != NULL, NULL);
679 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, NULL);
680
681 return field->u.list.selected;
682 }
683
684 const GList *
685 gaim_request_field_list_get_items(const GaimRequestField *field)
686 {
687 g_return_val_if_fail(field != NULL, NULL);
688 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, NULL);
689
690 return field->u.list.items;
619 } 691 }
620 692
621 /* -- */ 693 /* -- */
622 694
623 void * 695 void *