Implemented basic paging of chat windows

This commit is contained in:
James Booth
2012-03-05 00:35:05 +00:00
parent 0ddf97e016
commit 09602a6f4f
2 changed files with 35 additions and 35 deletions

View File

@@ -179,6 +179,7 @@ static int _jabber_message_handler(xmpp_conn_t * const conn,
char *message = xmpp_stanza_get_text(body); char *message = xmpp_stanza_get_text(body);
char *from = xmpp_stanza_get_attribute(stanza, "from"); char *from = xmpp_stanza_get_attribute(stanza, "from");
win_show_incomming_msg(from, message); win_show_incomming_msg(from, message);
win_page_off();
return 1; return 1;
} }
@@ -197,6 +198,7 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn,
title_bar_connected(); title_bar_connected();
cons_show(line); cons_show(line);
win_page_off();
status_bar_print_message(jid); status_bar_print_message(jid);
status_bar_refresh(); status_bar_refresh();
@@ -214,6 +216,7 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn,
} }
else { else {
cons_bad_show("Login failed."); cons_bad_show("Login failed.");
win_page_off();
log_msg(CONN, "disconnected"); log_msg(CONN, "disconnected");
xmpp_stop(ctx); xmpp_stop(ctx);
jabber_conn.conn_status = JABBER_DISCONNECTED; jabber_conn.conn_status = JABBER_DISCONNECTED;
@@ -251,6 +254,8 @@ static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
} }
item = xmpp_stanza_get_next(item); item = xmpp_stanza_get_next(item);
win_page_off();
} }
} }
@@ -310,6 +315,8 @@ static int _jabber_presence_handler(xmpp_conn_t * const conn,
else // offline else // offline
win_contact_offline(short_from, show_str, status_str); win_contact_offline(short_from, show_str, status_str);
win_page_off();
return 1; return 1;
} }

View File

@@ -264,19 +264,17 @@ void win_handle_switch(int *ch)
void win_page_off(void) void win_page_off(void)
{ {
int rows, cols; int rows, cols;
getmaxyx(stdscr, rows, cols); getmaxyx(stdscr, rows, cols);
if (_curr_prof_win == 0) { _wins[_curr_prof_win].paged = 0;
_wins[0].paged = 0;
int y, x; int y, x;
getyx(_cons_win, y, x); getyx(_wins[_curr_prof_win].win, y, x);
int size = rows - 3; int size = rows - 3;
_wins[0].y_pos = y - (size - 1); _wins[_curr_prof_win].y_pos = y - (size - 1);
if (_wins[0].y_pos < 0) if (_wins[_curr_prof_win].y_pos < 0)
_wins[0].y_pos = 0; _wins[_curr_prof_win].y_pos = 0;
}
} }
void win_handle_page(int *ch) void win_handle_page(int *ch)
@@ -285,25 +283,21 @@ void win_handle_page(int *ch)
int rows, cols; int rows, cols;
getmaxyx(stdscr, rows, cols); getmaxyx(stdscr, rows, cols);
if (_curr_prof_win == 0) { _wins[_curr_prof_win].y_pos = _wins[_curr_prof_win].y_pos - (rows - 4);
_wins[0].y_pos = _wins[0].y_pos - (rows - 4); if (_wins[_curr_prof_win].y_pos < 0)
if (_wins[0].y_pos < 0) _wins[_curr_prof_win].y_pos = 0;
_wins[0].y_pos = 0;
}
_wins[0].paged = 1; _wins[_curr_prof_win].paged = 1;
} else if (*ch == KEY_NPAGE) { } else if (*ch == KEY_NPAGE) {
int rows, cols, y, x; int rows, cols, y, x;
getmaxyx(stdscr, rows, cols); getmaxyx(stdscr, rows, cols);
getyx(_cons_win, y, x); getyx(_wins[_curr_prof_win].win, y, x);
if (_curr_prof_win == 0) { _wins[_curr_prof_win].y_pos = _wins[_curr_prof_win].y_pos + (rows - 4);
_wins[0].y_pos = _wins[0].y_pos + (rows - 4); if (_wins[_curr_prof_win].y_pos >= y)
if (_wins[0].y_pos >= y) _wins[_curr_prof_win].y_pos = y - 1;
_wins[0].y_pos = y - 1;
}
_wins[0].paged = 1; _wins[_curr_prof_win].paged = 1;
} }
} }
@@ -334,7 +328,9 @@ static void _create_windows(void)
for (i = 1; i < NUM_WINS; i++) { for (i = 1; i < NUM_WINS; i++) {
struct prof_win chat; struct prof_win chat;
strcpy(chat.from, ""); strcpy(chat.from, "");
chat.win = newwin(rows-3, cols, 1, 0); chat.win = newpad(PAD_SIZE, cols);
chat.y_pos = 0;
chat.paged = 0;
wattrset(chat.win, A_BOLD); wattrset(chat.win, A_BOLD);
scrollok(chat.win, TRUE); scrollok(chat.win, TRUE);
_wins[i] = chat; _wins[i] = chat;
@@ -368,8 +364,10 @@ static int _new_prof_win(char *contact)
} }
static void _win_switch_if_active(int i) static void _win_switch_if_active(int i)
{ {
win_page_off();
if (strcmp(_wins[i].from, "") != 0) { if (strcmp(_wins[i].from, "") != 0) {
_curr_prof_win = i; _curr_prof_win = i;
win_page_off();
if (i == 0) if (i == 0)
title_bar_title(); title_bar_title();
@@ -406,14 +404,9 @@ static void _current_window_refresh()
int rows, cols; int rows, cols;
getmaxyx(stdscr, rows, cols); getmaxyx(stdscr, rows, cols);
if (_curr_prof_win == 0) { WINDOW *current = _wins[_curr_prof_win].win;
touchwin(_cons_win); touchwin(current);
prefresh(_cons_win, _wins[0].y_pos, 0, 1, 0, rows-3, cols-1); prefresh(current, _wins[_curr_prof_win].y_pos, 0, 1, 0, rows-3, cols-1);
} else {
WINDOW *current = _wins[_curr_prof_win].win;
touchwin(current);
wrefresh(current);
}
} }
static void _show_status_string(WINDOW *win, char *from, char *show, char *status, static void _show_status_string(WINDOW *win, char *from, char *show, char *status,