libpurple/request.c

changeset 40326
cdca03a74387
parent 40195
fb4b0ae193c0
child 40329
b5e0f65a5d9c
equal deleted inserted replaced
40195:fb4b0ae193c0 40326:cdca03a74387
393 393
394 void 394 void
395 purple_request_cpar_set_extra_actions(PurpleRequestCommonParameters *cpar, ...) 395 purple_request_cpar_set_extra_actions(PurpleRequestCommonParameters *cpar, ...)
396 { 396 {
397 va_list args; 397 va_list args;
398 GSList *extra = NULL, *it; 398 GSList *extra = NULL;
399 399
400 it = cpar->extra_actions; 400 g_slist_free_full(cpar->extra_actions, (GDestroyNotify)purple_named_value_free);
401 while (it != NULL) {
402 gchar *label = it->data;
403
404 g_free(label);
405 it = g_slist_next(it);
406 if (it == NULL)
407 break;
408 it = g_slist_next(it);
409 }
410 401
411 va_start(args, cpar); 402 va_start(args, cpar);
412 403
413 while (TRUE) { 404 while (TRUE) {
414 const gchar *label; 405 const gchar *label;
415 PurpleRequestFieldsCb cb; 406 PurpleRequestFieldsCb cb;
407 PurpleNamedValue *extra_action;
416 408
417 label = va_arg(args, const gchar*); 409 label = va_arg(args, const gchar*);
418 if (label == NULL) 410 if (label == NULL)
419 break; 411 break;
420 cb = va_arg(args, PurpleRequestFieldsCb); 412 cb = va_arg(args, PurpleRequestFieldsCb);
421 413
422 extra = g_slist_append(extra, g_strdup(label)); 414 extra_action = purple_named_value_new(label, cb);
423 extra = g_slist_append(extra, cb); 415
416 extra = g_slist_append(extra, extra_action);
424 } 417 }
425 418
426 va_end(args); 419 va_end(args);
427 420
428 cpar->extra_actions = extra; 421 cpar->extra_actions = extra;
944 g_free(field->u.string.default_value); 937 g_free(field->u.string.default_value);
945 g_free(field->u.string.value); 938 g_free(field->u.string.value);
946 } 939 }
947 else if (field->type == PURPLE_REQUEST_FIELD_CHOICE) 940 else if (field->type == PURPLE_REQUEST_FIELD_CHOICE)
948 { 941 {
949 if (field->u.choice.elements != NULL) 942 for (GList *it = field->u.choice.elements; it != NULL; it = g_list_next(it)) {
950 { 943 PurpleNamedValue *choice = it->data;
951 GList *it = field->u.choice.elements; 944
952 while (it != NULL) { 945 if (choice->value && field->u.choice.data_destroy)
953 g_free(it->data); 946 field->u.choice.data_destroy(choice->value);
954 it = g_list_next(it); /* value */ 947 purple_named_value_free(choice);
955 if (it == NULL) {
956 g_warn_if_reached();
957 break;
958 }
959 if (it->data && field->u.choice.data_destroy)
960 field->u.choice.data_destroy(it->data);
961 it = g_list_next(it); /* next label */
962 }
963 g_list_free(field->u.choice.elements);
964 } 948 }
949 g_list_free(field->u.choice.elements);
965 } 950 }
966 else if (field->type == PURPLE_REQUEST_FIELD_LIST) 951 else if (field->type == PURPLE_REQUEST_FIELD_LIST)
967 { 952 {
968 g_list_free_full(field->u.list.items, g_free); 953 g_list_free_full(field->u.list.items, g_free);
969 g_list_free_full(field->u.list.selected, g_free); 954 g_list_free_full(field->u.list.selected, g_free);
1475 1460
1476 void 1461 void
1477 purple_request_field_choice_add(PurpleRequestField *field, const char *label, 1462 purple_request_field_choice_add(PurpleRequestField *field, const char *label,
1478 gpointer value) 1463 gpointer value)
1479 { 1464 {
1465 PurpleNamedValue *choice;
1466
1480 g_return_if_fail(field != NULL); 1467 g_return_if_fail(field != NULL);
1481 g_return_if_fail(label != NULL); 1468 g_return_if_fail(label != NULL);
1482 g_return_if_fail(field->type == PURPLE_REQUEST_FIELD_CHOICE); 1469 g_return_if_fail(field->type == PURPLE_REQUEST_FIELD_CHOICE);
1483 1470
1471 choice = purple_named_value_new(label, value);
1472
1484 field->u.choice.elements = g_list_append(field->u.choice.elements, 1473 field->u.choice.elements = g_list_append(field->u.choice.elements,
1485 g_strdup(label)); 1474 choice);
1486 field->u.choice.elements = g_list_append(field->u.choice.elements,
1487 value);
1488 } 1475 }
1489 1476
1490 void 1477 void
1491 purple_request_field_choice_set_default_value(PurpleRequestField *field, 1478 purple_request_field_choice_set_default_value(PurpleRequestField *field,
1492 gpointer default_value) 1479 gpointer default_value)

mercurial