diff --git a/src/ui/core.c b/src/ui/core.c index 4ae62eb1..2524a5b7 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1908,16 +1908,14 @@ _ui_handle_room_configuration(const char * const room, DataForm *form) win_save_print(window, '-', NULL, NO_DATE | NO_EOL, COLOUR_AWAY, "", field->var); win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", "): "); } -/* -TODO add command to get help for a field - if (field->description != NULL) { - win_save_print(window, '-', NULL, 0, 0, "", field->description); - } -*/ GSList *values = field->values; GSList *curr_value = values; - if (g_strcmp0(field->type, "text-single") == 0) { + + switch (field->type_t) { + case FIELD_HIDDEN: + break; + case FIELD_TEXT_SINGLE: if (curr_value != NULL) { char *value = curr_value->data; if (value != NULL) { @@ -1929,8 +1927,8 @@ TODO add command to get help for a field } } win_save_newline(window); - } - if (g_strcmp0(field->type, "text-private") == 0) { + break; + case FIELD_TEXT_PRIVATE: if (curr_value != NULL) { char *value = curr_value->data; if (value != NULL) { @@ -1938,16 +1936,16 @@ TODO add command to get help for a field } } win_save_newline(window); - } - if (g_strcmp0(field->type, "text-multi") == 0) { + break; + case FIELD_TEXT_MULTI: win_save_newline(window); while (curr_value != NULL) { char *value = curr_value->data; win_save_vprint(window, '-', NULL, 0, COLOUR_ONLINE, "", " %s", value); curr_value = g_slist_next(curr_value); } - } - if (g_strcmp0(field->type, "boolean") == 0) { + break; + case FIELD_BOOLEAN: if (curr_value == NULL) { win_save_print(window, '-', NULL, NO_DATE, COLOUR_OFFLINE, "", "FALSE"); } else { @@ -1962,8 +1960,8 @@ TODO add command to get help for a field } } } - } - if (g_strcmp0(field->type, "list-single") == 0) { + break; + case FIELD_LIST_SINGLE: if (curr_value != NULL) { win_save_newline(window); char *value = curr_value->data; @@ -1979,8 +1977,8 @@ TODO add command to get help for a field curr_option = g_slist_next(curr_option); } } - } - if (g_strcmp0(field->type, "list-multi") == 0) { + break; + case FIELD_LIST_MUTLI: if (curr_value != NULL) { win_save_newline(window); GSList *options = field->options; @@ -1995,8 +1993,8 @@ TODO add command to get help for a field curr_option = g_slist_next(curr_option); } } - } - if (g_strcmp0(field->type, "jid-single") == 0) { + break; + case FIELD_JID_SINGLE: if (curr_value != NULL) { char *value = curr_value->data; if (value != NULL) { @@ -2004,16 +2002,16 @@ TODO add command to get help for a field } } win_save_newline(window); - } - if (g_strcmp0(field->type, "jid-multi") == 0) { + break; + case FIELD_JID_MULTI: win_save_newline(window); while (curr_value != NULL) { char *value = curr_value->data; win_save_vprint(window, '-', NULL, 0, COLOUR_ONLINE, "", " %s", value); curr_value = g_slist_next(curr_value); } - } - if (g_strcmp0(field->type, "fixed") == 0) { + break; + case FIELD_FIXED: if (curr_value != NULL) { char *value = curr_value->data; if (value != NULL) { @@ -2021,7 +2019,17 @@ TODO add command to get help for a field } } win_save_newline(window); + break; + default: + break; } + +/* +TODO add command to get help for a field + if (field->description != NULL) { + win_save_print(window, '-', NULL, 0, 0, "", field->description); + } +*/ } curr_field = g_slist_next(curr_field); diff --git a/src/xmpp/form.c b/src/xmpp/form.c index 002f366c..4b79d8e6 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -137,6 +137,42 @@ _is_required(xmpp_stanza_t * const stanza) } } +static form_field_type_t +_get_field_type(const char * const type) +{ + if (g_strcmp0(type, "hidden") == 0) { + return FIELD_HIDDEN; + } + if (g_strcmp0(type, "text-single") == 0) { + return FIELD_TEXT_SINGLE; + } + if (g_strcmp0(type, "text-private") == 0) { + return FIELD_TEXT_PRIVATE; + } + if (g_strcmp0(type, "text-multi") == 0) { + return FIELD_TEXT_MULTI; + } + if (g_strcmp0(type, "boolean") == 0) { + return FIELD_BOOLEAN; + } + if (g_strcmp0(type, "list-single") == 0) { + return FIELD_LIST_SINGLE; + } + if (g_strcmp0(type, "list-multi") == 0) { + return FIELD_LIST_MUTLI; + } + if (g_strcmp0(type, "jid-single") == 0) { + return FIELD_JID_SINGLE; + } + if (g_strcmp0(type, "jid-multi") == 0) { + return FIELD_JID_MULTI; + } + if (g_strcmp0(type, "fixed") == 0) { + return FIELD_FIXED; + } + return FIELD_UNKNOWN; +} + DataForm * form_create(xmpp_stanza_t * const form_stanza) { @@ -161,6 +197,7 @@ form_create(xmpp_stanza_t * const form_stanza) FormField *field = _field_new(); field->label = _get_attr(field_stanza, "label"); field->type = _get_attr(field_stanza, "type"); + field->type_t = _get_field_type(field->type); field->var = _get_attr(field_stanza, "var"); field->description = _get_property(field_stanza, "desc"); field->required = _is_required(field_stanza); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 6510a50e..c5583517 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -86,6 +86,20 @@ typedef struct disco_identity_t { char *category; } DiscoIdentity; +typedef enum { + FIELD_HIDDEN, + FIELD_TEXT_SINGLE, + FIELD_TEXT_PRIVATE, + FIELD_TEXT_MULTI, + FIELD_BOOLEAN, + FIELD_LIST_SINGLE, + FIELD_LIST_MUTLI, + FIELD_JID_SINGLE, + FIELD_JID_MULTI, + FIELD_FIXED, + FIELD_UNKNOWN +} form_field_type_t; + typedef struct form_option_t { char *label; char *value; @@ -94,6 +108,7 @@ typedef struct form_option_t { typedef struct form_field_t { char *label; char *type; + form_field_type_t type_t; char *var; char *description; gboolean required;