1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added /console command

This commit is contained in:
James Booth 2015-12-29 23:32:32 +00:00
parent 8ea228480c
commit 6a8656a06b
7 changed files with 85 additions and 1 deletions

View File

@ -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* _tls_autocomplete(ProfWin *window, const char *const input);
static char* _script_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* _subject_autocomplete(ProfWin *window, const char *const input);
static char* _console_autocomplete(ProfWin *window, const char *const input);
GHashTable *commands = NULL; GHashTable *commands = NULL;
@ -972,6 +973,23 @@ static struct cmd_t command_defs[] =
CMD_NOEXAMPLES 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", { "/encwarn",
cmd_encwarn, parse_args, 1, 1, &cons_encwarn_setting, cmd_encwarn, parse_args, 1, 1, &cons_encwarn_setting,
CMD_TAGS( CMD_TAGS(
@ -1888,6 +1906,8 @@ static Autocomplete tls_ac;
static Autocomplete tls_certpath_ac; static Autocomplete tls_certpath_ac;
static Autocomplete script_ac; static Autocomplete script_ac;
static Autocomplete script_show_ac; static Autocomplete script_show_ac;
static Autocomplete console_ac;
static Autocomplete console_muc_ac;
/* /*
* Initialise command autocompleter and history * Initialise command autocompleter and history
@ -2373,6 +2393,14 @@ cmd_init(void)
autocomplete_add(script_ac, "show"); autocomplete_add(script_ac, "show");
script_show_ac = NULL; 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 void
@ -2450,6 +2478,8 @@ cmd_uninit(void)
autocomplete_free(tls_certpath_ac); autocomplete_free(tls_certpath_ac);
autocomplete_free(script_ac); autocomplete_free(script_ac);
autocomplete_free(script_show_ac); autocomplete_free(script_show_ac);
autocomplete_free(console_ac);
autocomplete_free(console_muc_ac);
} }
gboolean gboolean
@ -2642,6 +2672,8 @@ cmd_reset_autocomplete(ProfWin *window)
autocomplete_reset(pgp_log_ac); autocomplete_reset(pgp_log_ac);
autocomplete_reset(tls_ac); autocomplete_reset(tls_ac);
autocomplete_reset(tls_certpath_ac); autocomplete_reset(tls_certpath_ac);
autocomplete_reset(console_ac);
autocomplete_reset(console_muc_ac);
autocomplete_reset(script_ac); autocomplete_reset(script_ac);
if (script_show_ac) { if (script_show_ac) {
autocomplete_free(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, "/wins", _wins_autocomplete);
g_hash_table_insert(ac_funcs, "/tls", _tls_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, "/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); int len = strlen(input);
char parsed[len+1]; char parsed[len+1];
@ -4135,6 +4168,24 @@ _join_autocomplete(ProfWin *window, const char *const input)
return NULL; return NULL;
} }
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* static char*
_subject_autocomplete(ProfWin *window, const char *const input) _subject_autocomplete(ProfWin *window, const char *const input)
{ {

View File

@ -4034,6 +4034,26 @@ cmd_beep(ProfWin *window, const char *const command, gchar **args)
return _cmd_set_boolean_preference(args[0], command, "Sound", PREF_BEEP); return _cmd_set_boolean_preference(args[0], command, "Sound", PREF_BEEP);
} }
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 gboolean
cmd_presence(ProfWin *window, const char *const command, gchar **args) cmd_presence(ProfWin *window, const char *const command, gchar **args)
{ {

View File

@ -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_script(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_export(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_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); gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args);

View File

@ -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) { } else if (g_strcmp0(muc_show, "first") == 0 && mucwin->unread == 0) {
cons_show_incoming_room_message(NULL, mucwin->roomjid, num); 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)) { if (prefs_get_boolean(PREF_FLASH) && (strcmp(nick, my_nick) != 0)) {
flash(); flash();

View File

@ -1079,6 +1079,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 void
cons_tlsshow_setting(void) cons_tlsshow_setting(void)
{ {
@ -1349,6 +1357,7 @@ cons_show_ui_prefs(void)
cons_resource_setting(); cons_resource_setting();
cons_vercheck_setting(); cons_vercheck_setting();
cons_statuses_setting(); cons_statuses_setting();
cons_console_setting();
cons_occupants_setting(); cons_occupants_setting();
cons_roster_setting(); cons_roster_setting();
cons_privileges_setting(); cons_privileges_setting();

View File

@ -268,6 +268,7 @@ void cons_theme_setting(void);
void cons_resource_setting(void); void cons_resource_setting(void);
void cons_privileges_setting(void); void cons_privileges_setting(void);
void cons_beep_setting(void); void cons_beep_setting(void);
void cons_console_setting(void);
void cons_flash_setting(void); void cons_flash_setting(void);
void cons_splash_setting(void); void cons_splash_setting(void);
void cons_encwarn_setting(void); void cons_encwarn_setting(void);

View File

@ -403,6 +403,7 @@ void cons_alert(void) {}
void cons_theme_setting(void) {} void cons_theme_setting(void) {}
void cons_privileges_setting(void) {} void cons_privileges_setting(void) {}
void cons_beep_setting(void) {} void cons_beep_setting(void) {}
void cons_console_setting(void) {}
void cons_flash_setting(void) {} void cons_flash_setting(void) {}
void cons_splash_setting(void) {} void cons_splash_setting(void) {}
void cons_vercheck_setting(void) {} void cons_vercheck_setting(void) {}