1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added setting of *-single room config values

This commit is contained in:
James Booth 2014-09-12 00:21:28 +01:00
parent 42a14d0182
commit 38959e0c33
4 changed files with 67 additions and 15 deletions

View File

@ -305,14 +305,16 @@ static struct cmd_t command_defs[] =
NULL } } },
{ "/room",
cmd_room, parse_args, 1, 1, NULL,
{ "/room config accept|destroy|edit|cancel", "Room configuration.",
{ "/room config accept|destroy|edit|cancel",
"---------------------------------------",
cmd_room, parse_args, 1, 3, NULL,
{ "/room config accept|destroy|config|submit|cancel [tag value]", "Room configuration.",
{ "/room config accept|destroy|config|submit|cancel [tag value]",
"------------------------------------------------------------",
"config accept - Accept default room configuration.",
"config destroy - Cancel default room configuration.",
"config edit - Edit room configuration.",
"config config - Edit room configuration.",
"config submit - Cancel room configuration.",
"config cancel - Cancel room configuration.",
"config set tag value - Set room configuration field to value.",
NULL } } },
{ "/rooms",
@ -1213,6 +1215,7 @@ cmd_init(void)
autocomplete_add(room_ac, "config");
autocomplete_add(room_ac, "submit");
autocomplete_add(room_ac, "cancel");
autocomplete_add(room_ac, "set");
cmd_history_init();
}

View File

@ -1809,6 +1809,7 @@ cmd_room(gchar **args, struct cmd_help_t help)
(g_strcmp0(args[0], "destroy") != 0) &&
(g_strcmp0(args[0], "config") != 0) &&
(g_strcmp0(args[0], "submit") != 0) &&
(g_strcmp0(args[0], "set") != 0) &&
(g_strcmp0(args[0], "cancel") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
@ -1817,7 +1818,8 @@ cmd_room(gchar **args, struct cmd_help_t help)
// validate subcommand for window type
if (win_type == WIN_MUC &&
((g_strcmp0(args[0], "submit") == 0) ||
(g_strcmp0(args[0], "cancel") == 0))) {
(g_strcmp0(args[0], "cancel") == 0) ||
(g_strcmp0(args[0], "set") == 0))) {
cons_show("Command '/room %s' only allowed in room configuration windows.", args[0]);
return TRUE;
}
@ -1879,7 +1881,8 @@ cmd_room(gchar **args, struct cmd_help_t help)
// commands allowed in room config
if ((g_strcmp0(args[0], "submit") == 0) ||
(g_strcmp0(args[0], "cancel") == 0)) {
(g_strcmp0(args[0], "cancel") == 0) ||
(g_strcmp0(args[0], "set") == 0)) {
ProfWin *current = wins_get_current();
gchar **split_recipient = g_strsplit(room, " ", 2);
@ -1892,15 +1895,37 @@ cmd_room(gchar **args, struct cmd_help_t help)
if (g_strcmp0(args[0], "cancel") == 0) {
iq_room_config_cancel(room);
}
wins_close_current();
current = wins_get_by_recipient(room);
if (current == NULL) {
current = wins_get_console();
if (g_strcmp0(args[0], "set") == 0) {
char *tag = NULL;
char *value = NULL;
if (args[1] != NULL) {
tag = args[1];
} else {
cons_show("Usage: %s", help.usage);
g_strfreev(split_recipient);
return TRUE;
}
if (args[2] != NULL) {
value = args[2];
} else {
cons_show("Usage: %s", help.usage);
g_strfreev(split_recipient);
return TRUE;
}
form_set_value_by_tag(current->form, tag, value);
cons_show("Field set.");
}
if ((g_strcmp0(args[0], "submit") == 0) ||
(g_strcmp0(args[0], "cancel") == 0)) {
wins_close_current();
current = wins_get_by_recipient(room);
if (current == NULL) {
current = wins_get_console();
}
num = wins_get_num(current);
ui_switch_win(num);
}
num = wins_get_num(current);
ui_switch_win(num);
g_strfreev(split_recipient);

View File

@ -382,9 +382,32 @@ _form_get_field_by_var(DataForm *form, const char * const var)
return NULL;
}
static void
_form_set_value_by_tag(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) {
if (g_slist_length(field->values) == 0) {
field->values = g_slist_append(field->values, strdup(value));
} else if (g_slist_length(field->values) == 1) {
free(field->values->data);
field->values->data = strdup(value);
return;
}
}
curr = g_slist_next(curr);
}
}
}
void
form_init_module(void)
{
form_destroy = _form_destroy;
form_get_field_by_var = _form_get_field_by_var;
form_set_value_by_tag = _form_set_value_by_tag;
}

View File

@ -206,5 +206,6 @@ void (*roster_send_remove)(const char * const barejid);
void (*form_destroy)(DataForm *form);
char * (*form_get_field_by_var)(DataForm *form, const char * const var);
void (*form_set_value_by_tag)(DataForm *form, const char * const tag, char *value);
#endif