diff options
author | James Booth <boothj5@gmail.com> | 2012-05-28 23:40:11 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-05-28 23:40:11 +0100 |
commit | 70310bb5afb7a008bdd4069d85ee62921cdf4ac5 (patch) | |
tree | b4e1b34b8869a8f0fb472a7f8171f1c201c45bef | |
parent | 240f7badb0050862320f413aeb53b39f34a35a81 (diff) | |
download | profani-tty-70310bb5afb7a008bdd4069d85ee62921cdf4ac5.tar.gz |
Allow message with status updates
-rw-r--r-- | command.c | 37 | ||||
-rw-r--r-- | jabber.c | 15 | ||||
-rw-r--r-- | jabber.h | 2 | ||||
-rw-r--r-- | windows.c | 23 |
4 files changed, 56 insertions, 21 deletions
diff --git a/command.c b/command.c index c5139c92..743ec5ae 100644 --- a/command.c +++ b/command.c @@ -51,7 +51,7 @@ static gboolean _cmd_chat(const char * const inp); static gboolean _cmd_xa(const char * const inp); static gboolean _cmd_default(const char * const inp); static void _update_presence(const jabber_presence_t presence, - const char * const show); + const char * const show, const char * const inp); gboolean process_input(char *inp) { @@ -269,31 +269,31 @@ static gboolean _cmd_set_flash(const char * const inp) static gboolean _cmd_away(const char * const inp) { - _update_presence(PRESENCE_AWAY, "away"); + _update_presence(PRESENCE_AWAY, "away", inp); return TRUE; } static gboolean _cmd_online(const char * const inp) { - _update_presence(PRESENCE_ONLINE, "online"); + _update_presence(PRESENCE_ONLINE, "online", inp); return TRUE; } static gboolean _cmd_dnd(const char * const inp) { - _update_presence(PRESENCE_DND, "dnd"); + _update_presence(PRESENCE_DND, "dnd", inp); return TRUE; } static gboolean _cmd_chat(const char * const inp) { - _update_presence(PRESENCE_CHAT, "chat"); + _update_presence(PRESENCE_CHAT, "chat", inp); return TRUE; } static gboolean _cmd_xa(const char * const inp) { - _update_presence(PRESENCE_XA, "xa"); + _update_presence(PRESENCE_XA, "xa", inp); return TRUE; } @@ -312,17 +312,32 @@ static gboolean _cmd_default(const char * const inp) } static void _update_presence(const jabber_presence_t presence, - const char * const show) + const char * const show, const char * const inp) { + char *msg; + if (strlen(inp) > strlen(show) + 2) { + msg = strndup(inp+(strlen(show) + 2), strlen(inp)-(strlen(show) + 2)); + } else { + msg = NULL; + } + jabber_conn_status_t conn_status = jabber_connection_status(); if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); } else { - jabber_update_presence(presence); + jabber_update_presence(presence, msg); title_bar_set_status(presence); - char str[16 + strlen(show) + 1]; - sprintf(str, "Status set to \"%s\"", show); - cons_show(str); + if (msg != NULL) { + char str[14 + strlen(show) + 3 + strlen(msg) + 2]; + sprintf(str, "Status set to %s, \"%s\"", show, msg); + cons_show(str); + free(msg); + } else { + char str[14 + strlen(show) + 1]; + sprintf(str, "Status set to %s", show); + cons_show(str); + } } + } diff --git a/jabber.c b/jabber.c index 3dc5a18c..ce04aaa4 100644 --- a/jabber.c +++ b/jabber.c @@ -180,7 +180,7 @@ void jabber_roster_request(void) xmpp_stanza_release(iq); } -void jabber_update_presence(jabber_presence_t status) +void jabber_update_presence(jabber_presence_t status, const char * const msg) { jabber_conn.presence = status; @@ -211,6 +211,19 @@ void jabber_update_presence(jabber_presence_t status) xmpp_stanza_release(show); } + if (msg != NULL) { + xmpp_stanza_t *status = xmpp_stanza_new(jabber_conn.ctx); + xmpp_stanza_set_name(status, "status"); + xmpp_stanza_t *text = xmpp_stanza_new(jabber_conn.ctx); + + xmpp_stanza_set_text(text, msg); + + xmpp_stanza_add_child(status, text); + xmpp_stanza_add_child(pres, status); + xmpp_stanza_release(text); + xmpp_stanza_release(status); + } + xmpp_send(jabber_conn.conn, pres); xmpp_stanza_release(pres); } diff --git a/jabber.h b/jabber.h index 574ea0a1..da6570b3 100644 --- a/jabber.h +++ b/jabber.h @@ -35,6 +35,6 @@ void jabber_roster_request(void); void jabber_process_events(void); void jabber_send(const char * const msg, const char * const recipient); const char * jabber_get_jid(void); -void jabber_update_presence(jabber_presence_t status); +void jabber_update_presence(jabber_presence_t status, const char * const msg); #endif diff --git a/windows.c b/windows.c index 91af2425..8fe91a2f 100644 --- a/windows.c +++ b/windows.c @@ -263,22 +263,28 @@ void win_disconnected(void) void cons_help(void) { cons_show(""); - cons_show("Commands:"); + cons_show("Basic Commands:"); cons_show(""); cons_show("/help : This help."); cons_show("/connect user@host : Login to jabber."); cons_show("/msg user@host mesg : Send mesg to user."); + cons_show("/close : Close a chat window."); cons_show("/who : Find out who is online."); cons_show("/ros : List all contacts."); + cons_show("/quit : Quit Profanity."); + cons_show(""); + cons_show("Settings:"); + cons_show(""); cons_show("/beep <on/off> : Enable/disable sound notification"); cons_show("/flash <on/off> : Enable/disable screen flash notification"); - cons_show("/close : Close a chat window."); - cons_show("/quit : Quit Profanity."); - cons_show("/away : Set status to away."); - cons_show("/online : Set status to online."); - cons_show("/dnd : Set status to dnd (do not disturb)."); - cons_show("/chat : Set status to chat (available for chat)."); - cons_show("/xa : Set status to xa (extended away)."); + cons_show(""); + cons_show("Status changes (msg is optional):"); + cons_show(""); + cons_show("/away <msg> : Set status to away."); + cons_show("/online <msg> : Set status to online."); + cons_show("/dnd <msg> : Set status to dnd (do not disturb)."); + cons_show("/chat <msg> : Set status to chat (available for chat)."); + cons_show("/xa <msg> : Set status to xa (extended away)."); cons_show(""); cons_show("Keys:"); cons_show(""); @@ -288,6 +294,7 @@ void cons_help(void) cons_show("LEFT, RIGHT : Edit current input."); cons_show("TAB : Autocomplete recipient."); cons_show("PAGE UP, PAGE DOWN : Page the chat window."); + cons_show(""); if (_curr_prof_win == 0) dirty = TRUE; |