static void _chatwin_history(ProfChatWin *chatwin, const char *const contact) { if (!chatwin->history_shown) { Jid *jid = jid_create(jabber_get_fulljid()); GSList *history = chat_log_get_previous(jid->barejid, contact); jid_destroy(jid); GSList *curr = history; while (curr) { char *line = curr->data; // entry if (line[2] == ':') { char hh[3]; memcpy(hh, &line[0], 2); hh[2] = '\0'; int ihh = atoi(hh); char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm); char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss); GDateTime *timestamp = g_date_time_new_local(2000, 1, 1, ihh, imm, iss); win_print((ProfWin*)chatwin, '-', 0, timestamp, NO_COLOUR_DATE, 0, "", curr->data+11); g_date_time_unref(timestamp); // header } else { win_print((ProfWin*)chatwin, '-', 0, NULL, 0, 0, "", curr->data); } curr = g_slist_next(curr); } chatwin->history_shown = TRUE; g_slist_free_full(history, free); } }
static void _win_handle_page(const wint_t * const ch) { ProfWin *current = wins_get_current(); int rows = getmaxy(stdscr); int y = getcury(current->win); int page_space = rows - 4; int *page_start = &(current->y_pos); if (prefs_get_boolean(PREF_MOUSE)) { MEVENT mouse_event; if (*ch == KEY_MOUSE) { if (getmouse(&mouse_event) == OK) { #ifdef PLATFORM_CYGWIN if (mouse_event.bstate & BUTTON5_PRESSED) { // mouse wheel down #else if (mouse_event.bstate & BUTTON2_PRESSED) { // mouse wheel down #endif *page_start += 4; // only got half a screen, show full screen if ((y - (*page_start)) < page_space) *page_start = y - page_space; // went past end, show full screen else if (*page_start >= y) *page_start = y - page_space; current->paged = 1; wins_refresh_current(); } else if (mouse_event.bstate & BUTTON4_PRESSED) { // mouse wheel up *page_start -= 4; // went past beginning, show first page if (*page_start < 0) *page_start = 0; current->paged = 1; wins_refresh_current(); } } } } // page up if (*ch == KEY_PPAGE) { *page_start -= page_space; // went past beginning, show first page if (*page_start < 0) *page_start = 0; current->paged = 1; wins_refresh_current(); // page down } else if (*ch == KEY_NPAGE) { *page_start += page_space; // only got half a screen, show full screen if ((y - (*page_start)) < page_space) *page_start = y - page_space; // went past end, show full screen else if (*page_start >= y) *page_start = y - page_space; current->paged = 1; wins_refresh_current(); } } static void _win_show_history(WINDOW *win, int win_index, const char * const contact) { ProfWin *window = wins_get_by_num(win_index); if (!window->history_shown) { GSList *history = NULL; Jid *jid = jid_create(jabber_get_fulljid()); history = chat_log_get_previous(jid->barejid, contact, history); jid_destroy(jid); while (history != NULL) { wprintw(win, "%s\n", history->data); history = g_slist_next(history); } window->history_shown = 1; g_slist_free_full(history, free); } }