diff options
author | James Booth <boothj5@gmail.com> | 2012-07-22 23:07:34 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-07-22 23:07:34 +0100 |
commit | 6b697054b671471edfb422ec7fd9d8ab8c2b0401 (patch) | |
tree | 767e6ac8a8494a8aa62c61cce400f7cf694dab93 /src | |
parent | a3efcb7e05cc22754d0c5551f08c2125f658abea (diff) | |
download | profani-tty-6b697054b671471edfb422ec7fd9d8ab8c2b0401.tar.gz |
Added chlog preference for chat logging
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 19 | ||||
-rw-r--r-- | src/jabber.c | 24 | ||||
-rw-r--r-- | src/preferences.c | 11 | ||||
-rw-r--r-- | src/preferences.h | 5 | ||||
-rw-r--r-- | src/windows.c | 1 |
5 files changed, 47 insertions, 13 deletions
diff --git a/src/command.c b/src/command.c index fb32d683..75cb6593 100644 --- a/src/command.c +++ b/src/command.c @@ -48,6 +48,7 @@ static gboolean _cmd_set_beep(const char * const inp); static gboolean _cmd_set_notify(const char * const inp); static gboolean _cmd_set_flash(const char * const inp); static gboolean _cmd_set_showsplash(const char * const inp); +static gboolean _cmd_set_chlog(const char * const inp); static gboolean _cmd_away(const char * const inp); static gboolean _cmd_online(const char * const inp); static gboolean _cmd_dnd(const char * const inp); @@ -80,11 +81,12 @@ static struct cmd_t commands[] = { { "/quit", _cmd_quit }, { "/ros", _cmd_ros }, { "/showsplash", _cmd_set_showsplash }, + { "/chlog", _cmd_set_chlog }, { "/who", _cmd_who }, { "/xa", _cmd_xa }, }; -static const int num_cmds = 16; +static const int num_cmds = 17; gboolean process_input(char *inp) { @@ -331,6 +333,21 @@ static gboolean _cmd_set_showsplash(const char * const inp) return TRUE; } +static gboolean _cmd_set_chlog(const char * const inp) +{ + if (strcmp(inp, "/chlog on") == 0) { + cons_show("Chat logging enabled."); + prefs_set_chlog(TRUE); + } else if (strcmp(inp, "/chlog off") == 0) { + cons_show("Chat logging disabled."); + prefs_set_chlog(FALSE); + } else { + cons_show("Usage: /chlog <on/off>"); + } + + return TRUE; +} + static gboolean _cmd_away(const char * const inp) { _update_presence(PRESENCE_AWAY, "away", inp); diff --git a/src/jabber.c b/src/jabber.c index 4e8f7244..0d55ef5d 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -166,10 +166,11 @@ void jabber_send(const char * const msg, const char * const recipient) free(coded_msg); free(coded_msg2); free(coded_msg3); - - const char *jid = xmpp_conn_get_jid(jabber_conn.conn); - - chat_log_chat(jid, (char *)recipient, msg, OUT); + + if (prefs_get_chlog()) { + const char *jid = xmpp_conn_get_jid(jabber_conn.conn); + chat_log_chat(jid, (char *)recipient, msg, OUT); + } } void jabber_roster_request(void) @@ -255,13 +256,14 @@ static int _jabber_message_handler(xmpp_conn_t * const conn, win_show_incomming_msg(from, message); win_page_off(); - char from_cpy[strlen(from) + 1]; - strcpy(from_cpy, from); - char *short_from = strtok(from_cpy, "/"); - const char *jid = xmpp_conn_get_jid(jabber_conn.conn); - - - chat_log_chat(jid, short_from, message, IN); + if (prefs_get_chlog()) { + char from_cpy[strlen(from) + 1]; + strcpy(from_cpy, from); + char *short_from = strtok(from_cpy, "/"); + const char *jid = xmpp_conn_get_jid(jabber_conn.conn); + + chat_log_chat(jid, short_from, message, IN); + } return 1; } diff --git a/src/preferences.c b/src/preferences.c index a384642a..b5d2626d 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -195,6 +195,17 @@ void prefs_set_flash(gboolean value) _save_prefs(); } +gboolean prefs_get_chlog(void) +{ + return g_key_file_get_boolean(prefs, "ui", "chlog", NULL); +} + +void prefs_set_chlog(gboolean value) +{ + g_key_file_set_boolean(prefs, "ui", "chlog", value); + _save_prefs(); +} + void prefs_add_login(const char *jid) { gsize njids; diff --git a/src/preferences.h b/src/preferences.h index 93fea268..dd3b7916 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -36,10 +36,13 @@ gboolean prefs_get_notify(void); void prefs_set_notify(gboolean value); gboolean prefs_get_flash(void); void prefs_set_flash(gboolean value); -void prefs_add_login(const char *jid); +gboolean prefs_get_chlog(void); +void prefs_set_chlog(gboolean value); gboolean prefs_get_showsplash(void); void prefs_set_showsplash(gboolean value); +void prefs_add_login(const char *jid); + NCURSES_COLOR_T prefs_get_bkgnd(); NCURSES_COLOR_T prefs_get_text(); NCURSES_COLOR_T prefs_get_online(); diff --git a/src/windows.c b/src/windows.c index b5378069..7804c984 100644 --- a/src/windows.c +++ b/src/windows.c @@ -352,6 +352,7 @@ void cons_help(void) cons_show("/notify <on/off> : Enable/disable desktop notifications"); cons_show("/flash <on/off> : Enable/disable screen flash notification"); cons_show("/showsplash <on/off> : Enable/disable splash logo on startup"); + cons_show("/chlog <on/off> : Enable/disable chat logging"); cons_show(""); cons_show("Status changes (msg is optional):"); cons_show(""); |