diff options
author | James Booth <boothj5@gmail.com> | 2015-12-29 23:32:32 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-12-29 23:32:32 +0000 |
commit | 6a8656a06b209e7e181ad8670fe50b7e6fe89572 (patch) | |
tree | 468eaad8c1576d70fb51e4202dd2257268d68235 | |
parent | 8ea228480c0c991814d057b2fe380396d3da4381 (diff) | |
download | profani-tty-6a8656a06b209e7e181ad8670fe50b7e6fe89572.tar.gz |
Added /console command
-rw-r--r-- | src/command/command.c | 53 | ||||
-rw-r--r-- | src/command/commands.c | 20 | ||||
-rw-r--r-- | src/command/commands.h | 1 | ||||
-rw-r--r-- | src/event/server_events.c | 1 | ||||
-rw-r--r-- | src/ui/console.c | 9 | ||||
-rw-r--r-- | src/ui/ui.h | 1 | ||||
-rw-r--r-- | tests/unittests/ui/stub_ui.c | 1 |
7 files changed, 85 insertions, 1 deletions
diff --git a/src/command/command.c b/src/command/command.c index 31e9d2ea..91c25131 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -113,6 +113,7 @@ static char* _wins_autocomplete(ProfWin *window, const char *const input); static char* _tls_autocomplete(ProfWin *window, const char *const input); static char* _script_autocomplete(ProfWin *window, const char *const input); static char* _subject_autocomplete(ProfWin *window, const char *const input); +static char* _console_autocomplete(ProfWin *window, const char *const input); GHashTable *commands = NULL; @@ -972,6 +973,23 @@ static struct cmd_t command_defs[] = CMD_NOEXAMPLES }, + { "/console", + cmd_console, parse_args, 2, 2, &cons_console_setting, + CMD_TAGS( + CMD_TAG_UI, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/console muc all|first|none") + CMD_DESC( + "Configure what is displayed in the console window when new chat room messages are received. " + "The default is set to 'all'.") + CMD_ARGS( + { "muc all", "Indicate all new chat room messages in the console." }, + { "muc first", "Indicate only the first new message in each room in the console." }, + { "muc none", "Do not show any new messages in the console window." }) + CMD_NOEXAMPLES + }, + { "/encwarn", cmd_encwarn, parse_args, 1, 1, &cons_encwarn_setting, CMD_TAGS( @@ -1888,6 +1906,8 @@ static Autocomplete tls_ac; static Autocomplete tls_certpath_ac; static Autocomplete script_ac; static Autocomplete script_show_ac; +static Autocomplete console_ac; +static Autocomplete console_muc_ac; /* * Initialise command autocompleter and history @@ -2373,6 +2393,14 @@ cmd_init(void) autocomplete_add(script_ac, "show"); script_show_ac = NULL; + + console_ac = autocomplete_new(); + autocomplete_add(console_ac, "muc"); + + console_muc_ac = autocomplete_new(); + autocomplete_add(console_muc_ac, "all"); + autocomplete_add(console_muc_ac, "first"); + autocomplete_add(console_muc_ac, "none"); } void @@ -2450,6 +2478,8 @@ cmd_uninit(void) autocomplete_free(tls_certpath_ac); autocomplete_free(script_ac); autocomplete_free(script_show_ac); + autocomplete_free(console_ac); + autocomplete_free(console_muc_ac); } gboolean @@ -2642,6 +2672,8 @@ cmd_reset_autocomplete(ProfWin *window) autocomplete_reset(pgp_log_ac); autocomplete_reset(tls_ac); autocomplete_reset(tls_certpath_ac); + autocomplete_reset(console_ac); + autocomplete_reset(console_muc_ac); autocomplete_reset(script_ac); if (script_show_ac) { autocomplete_free(script_show_ac); @@ -2903,7 +2935,8 @@ _cmd_complete_parameters(ProfWin *window, const char *const input) g_hash_table_insert(ac_funcs, "/wins", _wins_autocomplete); g_hash_table_insert(ac_funcs, "/tls", _tls_autocomplete); g_hash_table_insert(ac_funcs, "/script", _script_autocomplete); - g_hash_table_insert(ac_funcs, "/subject", _subject_autocomplete); + g_hash_table_insert(ac_funcs, "/subject", _subject_autocomplete); + g_hash_table_insert(ac_funcs, "/console", _console_autocomplete); int len = strlen(input); char parsed[len+1]; @@ -4136,6 +4169,24 @@ _join_autocomplete(ProfWin *window, const char *const input) } static char* +_console_autocomplete(ProfWin *window, const char *const input) +{ + char *result = NULL; + + result = autocomplete_param_with_ac(input, "/console muc", console_muc_ac, TRUE); + if (result) { + return result; + } + + result = autocomplete_param_with_ac(input, "/console", console_ac, TRUE); + if (result) { + return result; + } + + return NULL; +} + +static char* _subject_autocomplete(ProfWin *window, const char *const input) { char *result = NULL; diff --git a/src/command/commands.c b/src/command/commands.c index d3a648ac..404db139 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4035,6 +4035,26 @@ cmd_beep(ProfWin *window, const char *const command, gchar **args) } gboolean +cmd_console(ProfWin *window, const char *const command, gchar **args) +{ + if (g_strcmp0(args[0], "muc") != 0) { + cons_bad_cmd_usage(command); + return TRUE; + } + + char *setting = args[1]; + if ((g_strcmp0(setting, "all") != 0) && (g_strcmp0(setting, "first") != 0) && (g_strcmp0(setting, "none") != 0)) { + cons_bad_cmd_usage(command); + return TRUE; + } + + prefs_set_string(PREF_CONSOLE_MUC, setting); + cons_show("Console MUC messages set: %s", setting); + + return TRUE; +} + +gboolean cmd_presence(ProfWin *window, const char *const command, gchar **args) { return _cmd_set_boolean_preference(args[0], command, "Contact presence", PREF_PRESENCE); diff --git a/src/command/commands.h b/src/command/commands.h index 76794f71..69d7ea89 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -152,6 +152,7 @@ gboolean cmd_encwarn(ProfWin *window, const char *const command, gchar **args); gboolean cmd_script(ProfWin *window, const char *const command, gchar **args); gboolean cmd_export(ProfWin *window, const char *const command, gchar **args); gboolean cmd_charset(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_console(ProfWin *window, const char *const command, gchar **args); gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args); diff --git a/src/event/server_events.c b/src/event/server_events.c index 9760d157..ec7e2e51 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -246,6 +246,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, } else if (g_strcmp0(muc_show, "first") == 0 && mucwin->unread == 0) { cons_show_incoming_room_message(NULL, mucwin->roomjid, num); } + prefs_free_string(muc_show); if (prefs_get_boolean(PREF_FLASH) && (strcmp(nick, my_nick) != 0)) { flash(); diff --git a/src/ui/console.c b/src/ui/console.c index c0d3fabe..14487b7c 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1080,6 +1080,14 @@ cons_encwarn_setting(void) } void +cons_console_setting(void) +{ + char *setting = prefs_get_string(PREF_CONSOLE_MUC); + cons_show("Console MUC messages (/console) : %s", setting); + prefs_free_string(setting); +} + +void cons_tlsshow_setting(void) { if (prefs_get_boolean(PREF_TLS_SHOW)) { @@ -1349,6 +1357,7 @@ cons_show_ui_prefs(void) cons_resource_setting(); cons_vercheck_setting(); cons_statuses_setting(); + cons_console_setting(); cons_occupants_setting(); cons_roster_setting(); cons_privileges_setting(); diff --git a/src/ui/ui.h b/src/ui/ui.h index d6d71b24..6398381d 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -268,6 +268,7 @@ void cons_theme_setting(void); void cons_resource_setting(void); void cons_privileges_setting(void); void cons_beep_setting(void); +void cons_console_setting(void); void cons_flash_setting(void); void cons_splash_setting(void); void cons_encwarn_setting(void); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 1ed6f43d..45468214 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -403,6 +403,7 @@ void cons_alert(void) {} void cons_theme_setting(void) {} void cons_privileges_setting(void) {} void cons_beep_setting(void) {} +void cons_console_setting(void) {} void cons_flash_setting(void) {} void cons_splash_setting(void) {} void cons_vercheck_setting(void) {} |