From 8b77f527c0184f1780a021e77b966f6441ae90ac Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 11 Oct 2014 23:13:48 +0100 Subject: Moved /room subject to /subject --- src/command/command.c | 31 +++++++++++--------- src/command/commands.c | 79 ++++++++++++++++++++++++++++++-------------------- src/command/commands.h | 1 + 3 files changed, 66 insertions(+), 45 deletions(-) (limited to 'src/command') diff --git a/src/command/command.c b/src/command/command.c index de87390a..e8697920 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -338,6 +338,15 @@ static struct cmd_t command_defs[] = "reason - Optional reason for banning the user.", NULL } } }, + { "/subject", + cmd_subject, parse_args_with_freetext, 0, 2, NULL, + { "/subject set|clear [subject]", "Set or clear room subject.", + { "/subject set|clear [subject]", + "----------------------------", + "set subject - Set the room subject.", + "clear - Clear the room subject.", + NULL } } }, + { "/occupants", cmd_occupants, parse_args, 1, 2, &cons_occupants_setting, { "/occupants show|hide|default [show|hide]", "Show or hide room occupants.", @@ -1007,7 +1016,7 @@ static Autocomplete room_ac; static Autocomplete room_affiliation_ac; static Autocomplete room_role_ac; static Autocomplete room_cmd_ac; -static Autocomplete room_subject_ac; +static Autocomplete subject_ac; static Autocomplete form_ac; static Autocomplete occupants_ac; static Autocomplete occupants_default_ac; @@ -1283,7 +1292,6 @@ cmd_init(void) autocomplete_add(room_ac, "destroy"); autocomplete_add(room_ac, "config"); autocomplete_add(room_ac, "info"); - autocomplete_add(room_ac, "subject"); autocomplete_add(room_ac, "role"); autocomplete_add(room_ac, "affiliation"); @@ -1304,9 +1312,9 @@ cmd_init(void) autocomplete_add(room_cmd_ac, "list"); autocomplete_add(room_cmd_ac, "set"); - room_subject_ac = autocomplete_new(); - autocomplete_add(room_subject_ac, "set"); - autocomplete_add(room_subject_ac, "clear"); + subject_ac = autocomplete_new(); + autocomplete_add(subject_ac, "set"); + autocomplete_add(subject_ac, "clear"); form_ac = autocomplete_new(); autocomplete_add(form_ac, "submit"); @@ -1372,7 +1380,7 @@ cmd_uninit(void) autocomplete_free(room_affiliation_ac); autocomplete_free(room_role_ac); autocomplete_free(room_cmd_ac); - autocomplete_free(room_subject_ac); + autocomplete_free(subject_ac); autocomplete_free(form_ac); autocomplete_free(occupants_ac); autocomplete_free(occupants_default_ac); @@ -1505,7 +1513,7 @@ cmd_reset_autocomplete() autocomplete_reset(room_affiliation_ac); autocomplete_reset(room_role_ac); autocomplete_reset(room_cmd_ac); - autocomplete_reset(room_subject_ac); + autocomplete_reset(subject_ac); autocomplete_reset(form_ac); autocomplete_reset(occupants_ac); autocomplete_reset(occupants_default_ac); @@ -1766,8 +1774,8 @@ _cmd_complete_parameters(char *input, int *size) } } - gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins" }; - Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac }; + gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject" }; + Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac }; for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, size, cmds[i], completers[i], TRUE); @@ -2443,11 +2451,6 @@ _room_autocomplete(char *input, int *size) return result; } - result = autocomplete_param_with_ac(input, size, "/room subject", room_subject_ac, TRUE); - if (result != NULL) { - return result; - } - result = autocomplete_param_with_ac(input, size, "/room", room_ac, TRUE); if (result != NULL) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index 9f62647e..3f927407 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2169,6 +2169,54 @@ cmd_ban(gchar **args, struct cmd_help_t help) return TRUE; } +gboolean +cmd_subject(gchar **args, struct cmd_help_t help) +{ + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); + return TRUE; + } + + win_type_t win_type = ui_current_win_type(); + if (win_type != WIN_MUC) { + cons_show("Command '/room' does not apply to this window."); + return TRUE; + } + + char *room = ui_current_recipient(); + ProfWin *window = wins_get_by_recipient(room); + + if (args[0] == NULL) { + char *subject = muc_subject(room); + if (subject) { + win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room subject: "); + win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); + } else { + win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room has no subject"); + } + return TRUE; + } + + if (g_strcmp0(args[0], "set") == 0) { + if (args[1]) { + message_send_groupchat_subject(room, args[1]); + } else { + cons_show("Usage: %s", help.usage); + } + return TRUE; + } + + if (g_strcmp0(args[0], "clear") == 0) { + message_send_groupchat_subject(room, NULL); + return TRUE; + } + + cons_show("Usage: %s", help.usage); + return TRUE; +} + gboolean cmd_room(gchar **args, struct cmd_help_t help) { @@ -2188,7 +2236,6 @@ cmd_room(gchar **args, struct cmd_help_t help) if ((g_strcmp0(args[0], "accept") != 0) && (g_strcmp0(args[0], "destroy") != 0) && (g_strcmp0(args[0], "config") != 0) && - (g_strcmp0(args[0], "subject") != 0) && (g_strcmp0(args[0], "role") != 0) && (g_strcmp0(args[0], "affiliation") != 0) && (g_strcmp0(args[0], "info") != 0)) { @@ -2211,36 +2258,6 @@ cmd_room(gchar **args, struct cmd_help_t help) return TRUE; } - if (g_strcmp0(args[0], "subject") == 0) { - if (args[1] == NULL) { - char *subject = muc_subject(room); - if (subject) { - win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room subject: "); - win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); - } else { - win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room has no subject"); - } - return TRUE; - } - - if (g_strcmp0(args[1], "set") == 0) { - if (args[2]) { - message_send_groupchat_subject(room, args[2]); - } else { - cons_show("Usage: %s", help.usage); - } - return TRUE; - } - - if (g_strcmp0(args[1], "clear") == 0) { - message_send_groupchat_subject(room, NULL); - return TRUE; - } - - cons_show("Usage: %s", help.usage); - return TRUE; - } - if (g_strcmp0(args[0], "affiliation") == 0) { char *cmd = args[1]; if (cmd == NULL) { diff --git a/src/command/commands.h b/src/command/commands.h index d6a0254c..9cd2e9a1 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -129,5 +129,6 @@ gboolean cmd_form(gchar **args, struct cmd_help_t help); gboolean cmd_occupants(gchar **args, struct cmd_help_t help); gboolean cmd_kick(gchar **args, struct cmd_help_t help); gboolean cmd_ban(gchar **args, struct cmd_help_t help); +gboolean cmd_subject(gchar **args, struct cmd_help_t help); #endif -- cgit 1.4.1-2-gfad0