From b3ae1a7d12bdcffc50701db1e1886c1016042d4b Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 Apr 2012 01:24:54 +0100 Subject: [PATCH] Added beep setting command --- command.c | 16 ++++++++++++++++ windows.c | 12 +++++++++++- windows.h | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/command.c b/command.c index 19b0a9b7..3b80732f 100644 --- a/command.c +++ b/command.c @@ -38,6 +38,7 @@ static int _cmd_ros(void); static int _cmd_connect(const char * const inp); static int _cmd_msg(const char * const inp); static int _cmd_close(const char * const inp); +static int _cmd_set_beep(const char * const inp); static int _cmd_default(const char * const inp); int process_input(char *inp) @@ -84,6 +85,8 @@ static int _handle_command(const char * const command, const char * const inp) result = _cmd_close(inp); } else if (strcmp(command, "/connect") == 0) { result = _cmd_connect(inp); + } else if (strcmp(command, "/beep") == 0) { + result = _cmd_set_beep(inp); } else { result = _cmd_default(inp); } @@ -204,6 +207,19 @@ static int _cmd_close(const char * const inp) return TRUE; } +static int _cmd_set_beep(const char * const inp) +{ + if (strcmp(inp, "/beep on") == 0) { + win_set_beep(TRUE); + } else if (strcmp(inp, "/beep off") == 0) { + win_set_beep(FALSE); + } else { + cons_show("Usage: /beep "); + } + + return TRUE; +} + static int _cmd_default(const char * const inp) { if (win_in_chat()) { diff --git a/windows.c b/windows.c index 97515036..9d9b832e 100644 --- a/windows.c +++ b/windows.c @@ -45,6 +45,9 @@ static int dirty; // max columns for main windows, never resize below static int max_cols = 0; +// allow beep? +static int do_beep = TRUE; + static void _create_windows(void); static int _find_prof_win_index(const char * const contact); static int _new_prof_win(const char * const contact); @@ -149,6 +152,11 @@ int win_in_chat(void) (strcmp(_wins[_curr_prof_win].from, "") != 0)); } +void win_set_beep(int val) +{ + do_beep = val; +} + char *win_get_recipient(void) { struct prof_win current = _wins[_curr_prof_win]; @@ -180,7 +188,8 @@ void win_show_incomming_msg(const char * const from, const char * const message) _cons_show_incoming_message(short_from, win_index); } - beep(); + if (do_beep == TRUE) + beep(); } void win_show_outgoing_msg(const char * const from, const char * const to, @@ -264,6 +273,7 @@ void cons_help(void) cons_show("/msg user@host mesg : Send mesg to user."); cons_show("/who : Find out who is online."); cons_show("/ros : List all contacts."); + cons_show("/beep : Enable/disable sound notification"); cons_show("/close : Close a chat window."); cons_show("/quit : Quit Profanity."); cons_show(""); diff --git a/windows.h b/windows.h index 20914b07..636997a7 100644 --- a/windows.h +++ b/windows.h @@ -67,6 +67,7 @@ void win_contact_online(const char * const from, const char * const show, void win_contact_offline(const char * const from, const char * const show, const char * const status); void win_disconnected(void); +void win_set_beep(int val); // console window actions void cons_help(void);