diff options
author | James Booth <boothj5@gmail.com> | 2012-02-29 23:54:48 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-02-29 23:54:48 +0000 |
commit | dfa7c69da636889fe6130b5c1ef2d825eab1d9f9 (patch) | |
tree | d63ebb163c9de95b91f8d815aa3e7a3f76984fbb | |
parent | 5aba98c6aaae6025699afbe8421bd532e675d5c4 (diff) | |
download | profani-tty-dfa7c69da636889fe6130b5c1ef2d825eab1d9f9.tar.gz |
Simplified online/offline notifications
-rw-r--r-- | jabber.c | 11 | ||||
-rw-r--r-- | windows.c | 207 | ||||
-rw-r--r-- | windows.h | 6 |
3 files changed, 118 insertions, 106 deletions
diff --git a/jabber.c b/jabber.c index f3d3905f..6f1803b7 100644 --- a/jabber.c +++ b/jabber.c @@ -305,13 +305,10 @@ static int _jabber_presence_handler(xmpp_conn_t * const conn, else status_str = NULL; - if (type == NULL) { // online - cons_show_contact_online(short_from, show_str, status_str); - win_show_contact_online(short_from, show_str, status_str); - } else { // offline - cons_show_contact_offline(short_from, show_str, status_str); - win_show_contact_offline(short_from, show_str, status_str); - } + if (type == NULL) // online + win_contact_online(short_from, show_str, status_str); + else // offline + win_contact_offline(short_from, show_str, status_str); return 1; } diff --git a/windows.c b/windows.c index fcfa9a1e..36c55484 100644 --- a/windows.c +++ b/windows.c @@ -36,6 +36,10 @@ static void _win_switch_if_active(int i); static void _win_show_time(int win); static void _win_show_user(int win, char *user, int colour); static void _win_show_message(WINDOW *win, char *message); +static void _win_show_contact_online(char *from, char *show, char *status); +static void _win_show_contact_offline(char *from, char *show, char *status); +static void _cons_show_contact_online(char *from, char *show, char *status); +static void _cons_show_contact_offline(char *from, char *show, char *status); void gui_init(void) { @@ -126,63 +130,16 @@ void win_show_outgoing_msg(char *from, char *to, char *message) status_bar_active(win); } -void win_show_contact_online(char *from, char *show, char *status) +void win_contact_online(char *from, char *show, char *status) { - // find the chat window for recipient - int i; - for (i = 1; i < 10; i++) - if (strcmp(_wins[i].from, from) == 0) - break; - - // if we found a window - if (i != 10) { - _win_show_time(i); - wattron(_wins[i].win, COLOR_PAIR(2)); - wprintw(_wins[i].win, "++ %s", from); - - if (show != NULL) - wprintw(_wins[i].win, " is %s", show); - else - wprintw(_wins[i].win, " is online"); - - if (status != NULL) - wprintw(_wins[i].win, ", \"%s\"", status); - - wprintw(_wins[i].win, "\n"); - - wattroff(_wins[i].win, COLOR_PAIR(2)); - } + _cons_show_contact_online(from, show, status); + _win_show_contact_online(from, show, status); } -void win_show_contact_offline(char *from, char *show, char *status) +void win_contact_offline(char *from, char *show, char *status) { - // find the chat window for recipient - int i; - for (i = 1; i < 10; i++) - if (strcmp(_wins[i].from, from) == 0) - break; - - // if we found a window - if (i != 10) { - _win_show_time(i); - wattron(_wins[i].win, COLOR_PAIR(5)); - wattroff(_wins[i].win, A_BOLD); - - wprintw(_wins[i].win, "-- %s", from); - - if (show != NULL) - wprintw(_wins[i].win, " is %s", show); - else - wprintw(_wins[i].win, " is offline"); - - if (status != NULL) - wprintw(_wins[i].win, ", \"%s\"", status); - - wprintw(_wins[i].win, "\n"); - - wattroff(_wins[i].win, COLOR_PAIR(5)); - wattron(_wins[i].win, A_BOLD); - } + _cons_show_contact_offline(from, show, status); + _win_show_contact_offline(from, show, status); } void cons_help(void) @@ -248,48 +205,6 @@ void cons_bad_message(void) cons_show("Usage: /msg user@host message"); } -void cons_show_contact_online(char *from, char *show, char *status) -{ - _win_show_time(0); - wattron(_wins[0].win, COLOR_PAIR(2)); - - wprintw(_wins[0].win, "++ %s", from); - - if (show != NULL) - wprintw(_wins[0].win, " is %s", show); - else - wprintw(_wins[0].win, " is online"); - - if (status != NULL) - wprintw(_wins[0].win, ", \"%s\"", status); - - wprintw(_wins[0].win, "\n"); - - wattroff(_wins[0].win, COLOR_PAIR(2)); -} - -void cons_show_contact_offline(char *from, char *show, char *status) -{ - _win_show_time(0); - wattron(_wins[0].win, COLOR_PAIR(5)); - wattroff(_wins[0].win, A_BOLD); - - wprintw(_wins[0].win, "-- %s", from); - - if (show != NULL) - wprintw(_wins[0].win, " is %s", show); - else - wprintw(_wins[0].win, " is offline"); - - if (status != NULL) - wprintw(_wins[0].win, ", \"%s\"", status); - - wprintw(_wins[0].win, "\n"); - - wattroff(_wins[0].win, COLOR_PAIR(5)); - wattron(_wins[0].win, A_BOLD); -} - void win_handle_switch(int *ch) { if (*ch == KEY_F(1)) { @@ -408,3 +323,105 @@ static void _current_window_refresh() touchwin(_wins[_curr_win].win); wrefresh(_wins[_curr_win].win); } + +static void _win_show_contact_online(char *from, char *show, char *status) +{ + // find the chat window for recipient + int i; + for (i = 1; i < 10; i++) + if (strcmp(_wins[i].from, from) == 0) + break; + + // if we found a window + if (i != 10) { + _win_show_time(i); + wattron(_wins[i].win, COLOR_PAIR(2)); + wprintw(_wins[i].win, "++ %s", from); + + if (show != NULL) + wprintw(_wins[i].win, " is %s", show); + else + wprintw(_wins[i].win, " is online"); + + if (status != NULL) + wprintw(_wins[i].win, ", \"%s\"", status); + + wprintw(_wins[i].win, "\n"); + + wattroff(_wins[i].win, COLOR_PAIR(2)); + } +} + +static void _win_show_contact_offline(char *from, char *show, char *status) +{ + // find the chat window for recipient + int i; + for (i = 1; i < 10; i++) + if (strcmp(_wins[i].from, from) == 0) + break; + + // if we found a window + if (i != 10) { + _win_show_time(i); + wattron(_wins[i].win, COLOR_PAIR(5)); + wattroff(_wins[i].win, A_BOLD); + + wprintw(_wins[i].win, "-- %s", from); + + if (show != NULL) + wprintw(_wins[i].win, " is %s", show); + else + wprintw(_wins[i].win, " is offline"); + + if (status != NULL) + wprintw(_wins[i].win, ", \"%s\"", status); + + wprintw(_wins[i].win, "\n"); + + wattroff(_wins[i].win, COLOR_PAIR(5)); + wattron(_wins[i].win, A_BOLD); + } +} + +static void _cons_show_contact_online(char *from, char *show, char *status) +{ + _win_show_time(0); + wattron(_wins[0].win, COLOR_PAIR(2)); + + wprintw(_wins[0].win, "++ %s", from); + + if (show != NULL) + wprintw(_wins[0].win, " is %s", show); + else + wprintw(_wins[0].win, " is online"); + + if (status != NULL) + wprintw(_wins[0].win, ", \"%s\"", status); + + wprintw(_wins[0].win, "\n"); + + wattroff(_wins[0].win, COLOR_PAIR(2)); +} + +static void _cons_show_contact_offline(char *from, char *show, char *status) +{ + _win_show_time(0); + wattron(_wins[0].win, COLOR_PAIR(5)); + wattroff(_wins[0].win, A_BOLD); + + wprintw(_wins[0].win, "-- %s", from); + + if (show != NULL) + wprintw(_wins[0].win, " is %s", show); + else + wprintw(_wins[0].win, " is offline"); + + if (status != NULL) + wprintw(_wins[0].win, ", \"%s\"", status); + + wprintw(_wins[0].win, "\n"); + + wattroff(_wins[0].win, COLOR_PAIR(5)); + wattron(_wins[0].win, A_BOLD); +} + diff --git a/windows.h b/windows.h index d68b238c..a2c8985c 100644 --- a/windows.h +++ b/windows.h @@ -54,8 +54,8 @@ char *win_get_recipient(void); void win_show_incomming_msg(char *from, char *message); void win_show_outgoing_msg(char *from, char *to, char *message); void win_handle_switch(int *ch); -void win_show_contact_online(char *from, char *show, char *status); -void win_show_contact_offline(char *from, char *show, char *status); +void win_contact_online(char *from, char *show, char *status); +void win_contact_offline(char *from, char *show, char *status); // console window actions void cons_help(void); @@ -68,8 +68,6 @@ void cons_show(char *cmd); void cons_good_show(char *cmd); void cons_bad_show(char *cmd); void cons_highlight_show(char *cmd); -void cons_show_contact_online(char *from, char *show, char *status); -void cons_show_contact_offline(char *from, char *show, char *status); // status bar actions void status_bar_refresh(void); |