Simplified online/offline notifications

This commit is contained in:
James Booth
2012-02-29 23:54:48 +00:00
parent 5aba98c6aa
commit dfa7c69da6
3 changed files with 118 additions and 106 deletions

View File

@@ -305,13 +305,10 @@ static int _jabber_presence_handler(xmpp_conn_t * const conn,
else else
status_str = NULL; status_str = NULL;
if (type == NULL) { // online if (type == NULL) // online
cons_show_contact_online(short_from, show_str, status_str); win_contact_online(short_from, show_str, status_str);
win_show_contact_online(short_from, show_str, status_str); else // offline
} else { // offline win_contact_offline(short_from, show_str, status_str);
cons_show_contact_offline(short_from, show_str, status_str);
win_show_contact_offline(short_from, show_str, status_str);
}
return 1; return 1;
} }

207
windows.c
View File

@@ -36,6 +36,10 @@ static void _win_switch_if_active(int i);
static void _win_show_time(int win); static void _win_show_time(int win);
static void _win_show_user(int win, char *user, int colour); static void _win_show_user(int win, char *user, int colour);
static void _win_show_message(WINDOW *win, char *message); 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) void gui_init(void)
{ {
@@ -126,63 +130,16 @@ void win_show_outgoing_msg(char *from, char *to, char *message)
status_bar_active(win); 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 _cons_show_contact_online(from, show, status);
int i; _win_show_contact_online(from, show, status);
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));
}
} }
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 _cons_show_contact_offline(from, show, status);
int i; _win_show_contact_offline(from, show, status);
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);
}
} }
void cons_help(void) void cons_help(void)
@@ -248,48 +205,6 @@ void cons_bad_message(void)
cons_show("Usage: /msg user@host message"); 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) void win_handle_switch(int *ch)
{ {
if (*ch == KEY_F(1)) { if (*ch == KEY_F(1)) {
@@ -408,3 +323,105 @@ static void _current_window_refresh()
touchwin(_wins[_curr_win].win); touchwin(_wins[_curr_win].win);
wrefresh(_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);
}

View File

@@ -54,8 +54,8 @@ char *win_get_recipient(void);
void win_show_incomming_msg(char *from, char *message); void win_show_incomming_msg(char *from, char *message);
void win_show_outgoing_msg(char *from, char *to, char *message); void win_show_outgoing_msg(char *from, char *to, char *message);
void win_handle_switch(int *ch); void win_handle_switch(int *ch);
void win_show_contact_online(char *from, char *show, char *status); void win_contact_online(char *from, char *show, char *status);
void win_show_contact_offline(char *from, char *show, char *status); void win_contact_offline(char *from, char *show, char *status);
// console window actions // console window actions
void cons_help(void); void cons_help(void);
@@ -68,8 +68,6 @@ void cons_show(char *cmd);
void cons_good_show(char *cmd); void cons_good_show(char *cmd);
void cons_bad_show(char *cmd); void cons_bad_show(char *cmd);
void cons_highlight_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 // status bar actions
void status_bar_refresh(void); void status_bar_refresh(void);