mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added /room add for *-multi
This commit is contained in:
parent
b52911f7b4
commit
68b839a508
@ -1921,37 +1921,37 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
if (!form_tag_exists(current->form, tag)) {
|
if (!form_tag_exists(current->form, tag)) {
|
||||||
ui_current_print_line("Form does not contain a field with tag %s", tag);
|
ui_current_print_line("Form does not contain a field with tag %s", tag);
|
||||||
} else {
|
} else {
|
||||||
form_field_type_t field_type = form_get_field_type_by_tag(current->form, tag);
|
form_field_type_t field_type = form_get_field_type(current->form, tag);
|
||||||
gboolean valid = FALSE;
|
gboolean valid = FALSE;
|
||||||
switch (field_type) {
|
switch (field_type) {
|
||||||
case FIELD_TEXT_SINGLE:
|
case FIELD_TEXT_SINGLE:
|
||||||
case FIELD_TEXT_PRIVATE:
|
case FIELD_TEXT_PRIVATE:
|
||||||
case FIELD_JID_SINGLE:
|
case FIELD_JID_SINGLE:
|
||||||
form_set_value_by_tag(current->form, tag, value);
|
form_set_value(current->form, tag, value);
|
||||||
ui_current_print_line("%s set to %s", tag, value);
|
ui_current_print_line("%s set to %s", tag, value);
|
||||||
break;
|
break;
|
||||||
case FIELD_BOOLEAN:
|
case FIELD_BOOLEAN:
|
||||||
if (g_strcmp0(value, "on") == 0) {
|
if (g_strcmp0(value, "on") == 0) {
|
||||||
form_set_value_by_tag(current->form, tag, "1");
|
form_set_value(current->form, tag, "1");
|
||||||
ui_current_print_line("%s set to %s", tag, value);
|
ui_current_print_line("%s set to %s", tag, value);
|
||||||
} else if (g_strcmp0(value, "off") == 0) {
|
} else if (g_strcmp0(value, "off") == 0) {
|
||||||
form_set_value_by_tag(current->form, tag, "0");
|
form_set_value(current->form, tag, "0");
|
||||||
ui_current_print_line("%s set to %s", tag, value);
|
ui_current_print_line("%s set to %s", tag, value);
|
||||||
} else {
|
} else {
|
||||||
ui_current_print_line("Value %s not valid for boolean field: %s", value, tag);
|
ui_current_print_line("Value %s not valid for boolean field: %s", value, tag);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FIELD_LIST_SINGLE:
|
case FIELD_LIST_SINGLE:
|
||||||
valid = form_field_contains_option_by_tag(current->form, tag, value);
|
valid = form_field_contains_option(current->form, tag, value);
|
||||||
if (valid == TRUE) {
|
if (valid == TRUE) {
|
||||||
form_set_value_by_tag(current->form, tag, value);
|
form_set_value(current->form, tag, value);
|
||||||
ui_current_print_line("%s set to %s", tag, value);
|
ui_current_print_line("%s set to %s", tag, value);
|
||||||
} else {
|
} else {
|
||||||
ui_current_print_line("Value %s not a valid option for field: %s", value, tag);
|
ui_current_print_line("Value %s not a valid option for field: %s", value, tag);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ui_current_print_line("Set command not valid for field: %s", value, tag);
|
ui_current_print_line("Set command not valid for field: %s", tag);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1977,7 +1977,27 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
if (!form_tag_exists(current->form, tag)) {
|
if (!form_tag_exists(current->form, tag)) {
|
||||||
ui_current_print_line("Form does not contain a field with tag %s", tag);
|
ui_current_print_line("Form does not contain a field with tag %s", tag);
|
||||||
} else {
|
} else {
|
||||||
ui_current_print_line("Add Tag: %s, Value: %s", tag, value);
|
form_field_type_t field_type = form_get_field_type(current->form, tag);
|
||||||
|
gboolean valid = FALSE;
|
||||||
|
switch (field_type) {
|
||||||
|
case FIELD_LIST_MULTI:
|
||||||
|
valid = form_field_contains_option(current->form, tag, value);
|
||||||
|
if (valid == TRUE) {
|
||||||
|
form_add_value(current->form, tag, value);
|
||||||
|
ui_current_print_line("Added %s to %s", value, tag);
|
||||||
|
} else {
|
||||||
|
ui_current_print_line("Value %s not a valid option for field: %s", value, tag);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FIELD_TEXT_MULTI:
|
||||||
|
case FIELD_JID_MULTI:
|
||||||
|
form_add_value(current->form, tag, value);
|
||||||
|
ui_current_print_line("Added %s to %s", value, tag);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ui_current_print_line("Add command not valid for field: %s", tag);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1942,7 +1942,7 @@ _ui_handle_form_field(ProfWin *window, FormField *field)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FIELD_LIST_MUTLI:
|
case FIELD_LIST_MULTI:
|
||||||
if (curr_value != NULL) {
|
if (curr_value != NULL) {
|
||||||
win_save_newline(window);
|
win_save_newline(window);
|
||||||
GSList *options = field->options;
|
GSList *options = field->options;
|
||||||
|
@ -162,7 +162,7 @@ _get_field_type(const char * const type)
|
|||||||
return FIELD_LIST_SINGLE;
|
return FIELD_LIST_SINGLE;
|
||||||
}
|
}
|
||||||
if (g_strcmp0(type, "list-multi") == 0) {
|
if (g_strcmp0(type, "list-multi") == 0) {
|
||||||
return FIELD_LIST_MUTLI;
|
return FIELD_LIST_MULTI;
|
||||||
}
|
}
|
||||||
if (g_strcmp0(type, "jid-single") == 0) {
|
if (g_strcmp0(type, "jid-single") == 0) {
|
||||||
return FIELD_JID_SINGLE;
|
return FIELD_JID_SINGLE;
|
||||||
@ -300,7 +300,7 @@ form_create_submission(DataForm *form)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_TEXT_MULTI:
|
case FIELD_TEXT_MULTI:
|
||||||
case FIELD_LIST_MUTLI:
|
case FIELD_LIST_MULTI:
|
||||||
case FIELD_JID_MULTI:
|
case FIELD_JID_MULTI:
|
||||||
curr_value = field->values;
|
curr_value = field->values;
|
||||||
while (curr_value != NULL) {
|
while (curr_value != NULL) {
|
||||||
@ -403,7 +403,7 @@ _form_tag_exists(DataForm *form, const char * const tag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static form_field_type_t
|
static form_field_type_t
|
||||||
_form_get_field_type_by_tag(DataForm *form, const char * const tag)
|
_form_get_field_type(DataForm *form, const char * const tag)
|
||||||
{
|
{
|
||||||
char *var = g_hash_table_lookup(form->tag_to_var, tag);
|
char *var = g_hash_table_lookup(form->tag_to_var, tag);
|
||||||
if (var != NULL) {
|
if (var != NULL) {
|
||||||
@ -420,7 +420,7 @@ _form_get_field_type_by_tag(DataForm *form, const char * const tag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_form_set_value_by_tag(DataForm *form, const char * const tag, char *value)
|
_form_set_value(DataForm *form, const char * const tag, char *value)
|
||||||
{
|
{
|
||||||
char *var = g_hash_table_lookup(form->tag_to_var, tag);
|
char *var = g_hash_table_lookup(form->tag_to_var, tag);
|
||||||
if (var != NULL) {
|
if (var != NULL) {
|
||||||
@ -441,8 +441,37 @@ _form_set_value_by_tag(DataForm *form, const char * const tag, char *value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_form_add_value(DataForm *form, const char * const tag, char *value)
|
||||||
|
{
|
||||||
|
char *var = g_hash_table_lookup(form->tag_to_var, tag);
|
||||||
|
if (var != NULL) {
|
||||||
|
GSList *curr = form->fields;
|
||||||
|
while (curr != NULL) {
|
||||||
|
FormField *field = curr->data;
|
||||||
|
if (g_strcmp0(field->var, var) == 0) {
|
||||||
|
gboolean already_set = FALSE;
|
||||||
|
GSList *curr_value = field->values;
|
||||||
|
while (curr_value != NULL) {
|
||||||
|
if (g_strcmp0(curr_value->data, value) == 0) {
|
||||||
|
already_set = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
curr_value = g_slist_next(curr_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!already_set) {
|
||||||
|
field->values = g_slist_append(field->values, strdup(value));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
curr = g_slist_next(curr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_form_field_contains_option_by_tag(DataForm *form, const char * const tag, char *value)
|
_form_field_contains_option(DataForm *form, const char * const tag, char *value)
|
||||||
{
|
{
|
||||||
char *var = g_hash_table_lookup(form->tag_to_var, tag);
|
char *var = g_hash_table_lookup(form->tag_to_var, tag);
|
||||||
if (var != NULL) {
|
if (var != NULL) {
|
||||||
@ -471,8 +500,9 @@ form_init_module(void)
|
|||||||
{
|
{
|
||||||
form_destroy = _form_destroy;
|
form_destroy = _form_destroy;
|
||||||
form_get_form_type_field = _form_get_form_type_field;
|
form_get_form_type_field = _form_get_form_type_field;
|
||||||
form_get_field_type_by_tag = _form_get_field_type_by_tag;
|
form_get_field_type = _form_get_field_type;
|
||||||
form_set_value_by_tag = _form_set_value_by_tag;
|
form_set_value = _form_set_value;
|
||||||
form_field_contains_option_by_tag = _form_field_contains_option_by_tag;
|
form_add_value = _form_add_value;
|
||||||
|
form_field_contains_option = _form_field_contains_option;
|
||||||
form_tag_exists = _form_tag_exists;
|
form_tag_exists = _form_tag_exists;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ typedef enum {
|
|||||||
FIELD_TEXT_MULTI,
|
FIELD_TEXT_MULTI,
|
||||||
FIELD_BOOLEAN,
|
FIELD_BOOLEAN,
|
||||||
FIELD_LIST_SINGLE,
|
FIELD_LIST_SINGLE,
|
||||||
FIELD_LIST_MUTLI,
|
FIELD_LIST_MULTI,
|
||||||
FIELD_JID_SINGLE,
|
FIELD_JID_SINGLE,
|
||||||
FIELD_JID_MULTI,
|
FIELD_JID_MULTI,
|
||||||
FIELD_FIXED,
|
FIELD_FIXED,
|
||||||
@ -208,9 +208,10 @@ void (*roster_send_remove)(const char * const barejid);
|
|||||||
|
|
||||||
void (*form_destroy)(DataForm *form);
|
void (*form_destroy)(DataForm *form);
|
||||||
char * (*form_get_form_type_field)(DataForm *form);
|
char * (*form_get_form_type_field)(DataForm *form);
|
||||||
void (*form_set_value_by_tag)(DataForm *form, const char * const tag, char *value);
|
void (*form_set_value)(DataForm *form, const char * const tag, char *value);
|
||||||
|
void (*form_add_value)(DataForm *form, const char * const tag, char *value);
|
||||||
gboolean (*form_tag_exists)(DataForm *form, const char * const tag);
|
gboolean (*form_tag_exists)(DataForm *form, const char * const tag);
|
||||||
form_field_type_t (*form_get_field_type_by_tag)(DataForm *form, const char * const tag);
|
form_field_type_t (*form_get_field_type)(DataForm *form, const char * const tag);
|
||||||
gboolean (*form_field_contains_option_by_tag)(DataForm *form, const char * const tag, char *value);
|
gboolean (*form_field_contains_option)(DataForm *form, const char * const tag, char *value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user