static void _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) { GSList *contacts = roster_get_nogroup(); if (contacts) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); win_printline_nowrap(layout->subwin, " -no group"); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GSList *curr_contact = contacts; while (curr_contact) { PContact contact = curr_contact->data; _rosterwin_contact(layout, contact); curr_contact = g_slist_next(curr_contact); } } g_slist_free(contacts); }
ProfWin* win_create_muc(const char *const roomjid) { ProfMucWin *new_win = malloc(sizeof(ProfMucWin)); int cols = getmaxx(stdscr); new_win->window.type = WIN_MUC; ProfLayoutSplit *layout = malloc(sizeof(ProfLayoutSplit)); layout->base.type = LAYOUT_SPLIT; if (prefs_get_boolean(PREF_OCCUPANTS)) { int subwin_cols = win_occpuants_cols(); layout->base.win = newpad(PAD_SIZE, cols - subwin_cols); wbkgd(layout->base.win, theme_attrs(THEME_TEXT)); layout->subwin = newpad(PAD_SIZE, subwin_cols);; wbkgd(layout->subwin, theme_attrs(THEME_TEXT)); } else { layout->base.win = newpad(PAD_SIZE, (cols)); wbkgd(layout->base.win, theme_attrs(THEME_TEXT)); layout->subwin = NULL; } layout->sub_y_pos = 0; layout->memcheck = LAYOUT_SPLIT_MEMCHECK; layout->base.buffer = buffer_create(); layout->base.y_pos = 0; layout->base.paged = 0; scrollok(layout->base.win, TRUE); new_win->window.layout = (ProfLayout*)layout; new_win->roomjid = strdup(roomjid); new_win->unread = 0; new_win->unread_mentions = FALSE; new_win->unread_triggers = FALSE; if (prefs_get_boolean(PREF_OCCUPANTS_JID)) { new_win->showjid = TRUE; } else { new_win->showjid = FALSE; } new_win->memcheck = PROFMUCWIN_MEMCHECK; return &new_win->window; }
static void _show_muc_privacy(ProfMucWin *mucwin) { int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); int encrypted_attrs = theme_attrs(THEME_TITLE_ENCRYPTED); if (mucwin->enctext) { wprintw(win, " "); wattron(win, bracket_attrs); wprintw(win, "["); wattroff(win, bracket_attrs); wattron(win, encrypted_attrs); wprintw(win, mucwin->enctext); wattroff(win, encrypted_attrs); wattron(win, bracket_attrs); wprintw(win, "]"); return; } }
static void _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GString *title = g_string_new(" -"); g_string_append(title, group); win_printline_nowrap(layout->subwin, title->str); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GSList *contacts = roster_get_group(group); if (contacts) { GSList *curr_contact = contacts; while (curr_contact) { PContact contact = curr_contact->data; _rosterwin_contact(layout, contact); curr_contact = g_slist_next(curr_contact); } } g_slist_free(contacts); }
void status_bar_resize(void) { int rows, cols; getmaxyx(stdscr, rows, cols); werase(status_bar); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); mvwin(status_bar, rows-2, 0); wresize(status_bar, 1, cols); wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT)); wattron(status_bar, bracket_attrs); mvwprintw(status_bar, 0, cols - 34, _active); mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); wattroff(status_bar, bracket_attrs); if (message) { char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); gchar *date_fmt = g_date_time_format(last_time, time_pref); assert(date_fmt != NULL); size_t len = strlen(date_fmt); g_free(date_fmt); if (g_strcmp0(time_pref, "") != 0) { /* 01234567890123456 * [HH:MM] message */ mvwprintw(status_bar, 0, 5 + len, message); } else { mvwprintw(status_bar, 0, 1, message); } prefs_free_string(time_pref); } if (last_time) { g_date_time_unref(last_time); } last_time = g_date_time_new_now_local(); _status_bar_draw(); }
static void _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char * const presence, char *title) { GSList *contacts = roster_get_contacts_by_presence(presence); // if this group has contacts, or if we want to show empty groups if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); win_printline_nowrap(layout->subwin, title); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); } if (contacts) { GSList *curr_contact = contacts; while (curr_contact) { PContact contact = curr_contact->data; _rosterwin_contact(layout, contact); curr_contact = g_slist_next(curr_contact); } } g_slist_free(contacts); }
static void _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) { const char *name = p_contact_name_or_jid(contact); const char *presence = p_contact_presence(contact); if ((g_strcmp0(presence, "offline") != 0) || ((g_strcmp0(presence, "offline") == 0) && (prefs_get_boolean(PREF_ROSTER_OFFLINE)))) { theme_item_t presence_colour = theme_main_presence_attrs(presence); wattron(layout->subwin, theme_attrs(presence_colour)); GString *msg = g_string_new(" "); g_string_append(msg, name); win_printline_nowrap(layout->subwin, msg->str); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(presence_colour)); if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { GList *resources = p_contact_get_available_resources(contact); GList *curr_resource = resources; while (curr_resource) { Resource *resource = curr_resource->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence); wattron(layout->subwin, theme_attrs(resource_presence_colour)); GString *msg = g_string_new(" "); g_string_append(msg, resource->name); win_printline_nowrap(layout->subwin, msg->str); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(resource_presence_colour)); curr_resource = g_list_next(curr_resource); } g_list_free(resources); } } }
void create_title_bar(void) { int cols = getmaxx(stdscr); int row = screen_titlebar_row(); win = newwin(1, cols, row, 0); wbkgd(win, theme_attrs(THEME_TITLE_TEXT)); title_bar_console(); title_bar_set_presence(CONTACT_OFFLINE); title_bar_set_tls(FALSE); title_bar_set_connected(FALSE); wnoutrefresh(win); inp_put_back(); }
void win_resize(ProfWin *window) { int cols = getmaxx(stdscr); if (window->layout->type == LAYOUT_SPLIT) { ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout; if (layout->subwin) { int subwin_cols = 0; if (window->type == WIN_CONSOLE) { subwin_cols = win_roster_cols(); } else if (window->type == WIN_MUC) { subwin_cols = win_occpuants_cols(); } wbkgd(layout->base.win, theme_attrs(THEME_TEXT)); wresize(layout->base.win, PAD_SIZE, cols - subwin_cols); wbkgd(layout->subwin, theme_attrs(THEME_TEXT)); wresize(layout->subwin, PAD_SIZE, subwin_cols); if (window->type == WIN_CONSOLE) { rosterwin_roster(); } else if (window->type == WIN_MUC) { ProfMucWin *mucwin = (ProfMucWin *)window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); occupantswin_occupants(mucwin->roomjid); } } else { wbkgd(layout->base.win, theme_attrs(THEME_TEXT)); wresize(layout->base.win, PAD_SIZE, cols); } } else { wbkgd(window->layout->win, theme_attrs(THEME_TEXT)); wresize(window->layout->win, PAD_SIZE, cols); } win_redraw(window); }
void title_bar_resize(void) { int cols = getmaxx(stdscr); werase(win); int row = screen_titlebar_row(); mvwin(win, row, 0); wresize(win, 1, cols); wbkgd(win, theme_attrs(THEME_TITLE_TEXT)); _title_bar_draw(); }
static ProfLayout* _win_create_simple_layout(void) { int cols = getmaxx(stdscr); ProfLayoutSimple *layout = malloc(sizeof(ProfLayoutSimple)); layout->base.type = LAYOUT_SIMPLE; layout->base.win = newpad(PAD_SIZE, cols); wbkgd(layout->base.win, theme_attrs(THEME_TEXT)); layout->base.buffer = buffer_create(); layout->base.y_pos = 0; layout->base.paged = 0; scrollok(layout->base.win, TRUE); return &layout->base; }
static void _mark_active(int num) { int active_pos = 1 + ((num-1) * 3); int cols = getmaxx(stdscr); int status_attrs = theme_attrs(THEME_STATUS_ACTIVE); wattron(status_bar, status_attrs); if (num == 10) { mvwprintw(status_bar, 0, cols - 34 + active_pos, "0"); } else if (num > 10) { mvwprintw(status_bar, 0, cols - 34 + active_pos, ">"); } else { mvwprintw(status_bar, 0, cols - 34 + active_pos, "%d", num); } wattroff(status_bar, status_attrs); }
void inp_win_resize(void) { int col = getcurx(inp_win); int wcols = getmaxx(stdscr); // if lost cursor off screen, move contents to show it if (col >= pad_start + wcols) { pad_start = col - (wcols / 2); if (pad_start < 0) { pad_start = 0; } } wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; _inp_win_update_virtual(); }
static ProfLayout* _win_create_split_layout(void) { int cols = getmaxx(stdscr); ProfLayoutSplit *layout = malloc(sizeof(ProfLayoutSplit)); layout->base.type = LAYOUT_SPLIT; layout->base.win = newpad(PAD_SIZE, cols); wbkgd(layout->base.win, theme_attrs(THEME_TEXT)); layout->base.buffer = buffer_create(); layout->base.y_pos = 0; layout->base.paged = 0; scrollok(layout->base.win, TRUE); layout->subwin = NULL; layout->sub_y_pos = 0; layout->memcheck = LAYOUT_SPLIT_MEMCHECK; return &layout->base; }
void status_bar_current(int i) { if (i == 0) { current = 10; } else if (i > 10) { current = 11; } else { current = i; } int cols = getmaxx(stdscr); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); wattron(status_bar, bracket_attrs); mvwprintw(status_bar, 0, cols - 34, _active); mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); wattroff(status_bar, bracket_attrs); _status_bar_draw(); }
void status_bar_clear_message(void) { if (message) { free(message); message = NULL; } werase(status_bar); int cols = getmaxx(stdscr); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); wattron(status_bar, bracket_attrs); mvwprintw(status_bar, 0, cols - 34, _active); mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); wattroff(status_bar, bracket_attrs); _status_bar_draw(); }
void create_input_window(void) { #ifdef NCURSES_REENTRANT set_escdelay(25); #else ESCDELAY = 25; #endif rl_readline_name = "profanity"; rl_getc_function = _inp_rl_getc; rl_startup_hook = _inp_rl_startup_hook; rl_callback_handler_install(NULL, _inp_rl_linehandler); inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); wmove(inp_win, 0, 0); _inp_win_update_virtual(); }
static void _status_bar_draw(void) { if (last_time) { g_date_time_unref(last_time); } last_time = g_date_time_new_now_local(); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); if (g_strcmp0(time_pref, "minutes") == 0) { gchar *date_fmt = g_date_time_format(last_time, "%H:%M"); assert(date_fmt != NULL); wattron(status_bar, bracket_attrs); mvwaddch(status_bar, 0, 1, '['); wattroff(status_bar, bracket_attrs); mvwprintw(status_bar, 0, 2, date_fmt); wattron(status_bar, bracket_attrs); mvwaddch(status_bar, 0, 7, ']'); wattroff(status_bar, bracket_attrs); g_free(date_fmt); } else if (g_strcmp0(time_pref, "seconds") == 0) { gchar *date_fmt = g_date_time_format(last_time, "%H:%M:%S"); assert(date_fmt != NULL); wattron(status_bar, bracket_attrs); mvwaddch(status_bar, 0, 1, '['); wattroff(status_bar, bracket_attrs); mvwprintw(status_bar, 0, 2, date_fmt); wattron(status_bar, bracket_attrs); mvwaddch(status_bar, 0, 10, ']'); wattroff(status_bar, bracket_attrs); g_free(date_fmt); } _update_win_statuses(); wnoutrefresh(status_bar); inp_put_back(); }
ProfWin* win_create_private(const char * const fulljid) { ProfWin *new_win = malloc(sizeof(ProfWin)); int cols = getmaxx(stdscr); new_win->type = WIN_PRIVATE; new_win->win = newpad(PAD_SIZE, (cols)); wbkgd(new_win->win, theme_attrs(THEME_TEXT)); new_win->from = strdup(fulljid); new_win->buffer = buffer_create(); new_win->y_pos = 0; new_win->paged = 0; new_win->unread = 0; scrollok(new_win->win, TRUE); return new_win; }
void win_show_subwin(ProfWin *window) { int cols = getmaxx(stdscr); int subwin_cols = 0; if (window->layout->type != LAYOUT_SPLIT) { return; } if (window->type == WIN_MUC) { subwin_cols = win_occpuants_cols(); } else if (window->type == WIN_CONSOLE) { subwin_cols = win_roster_cols(); } ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout; layout->subwin = newpad(PAD_SIZE, subwin_cols); wbkgd(layout->subwin, theme_attrs(THEME_TEXT)); wresize(layout->base.win, PAD_SIZE, cols - subwin_cols); win_redraw(window); }
void status_bar_print_message(const char * const msg) { werase(status_bar); if (message) { free(message); } message = strdup(msg); char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); gchar *date_fmt = NULL; if (g_strcmp0(time_pref, "off") == 0) { date_fmt = g_strdup(""); } else { date_fmt = g_date_time_format(last_time, time_pref); } assert(date_fmt != NULL); size_t len = strlen(date_fmt); g_free(date_fmt); if (g_strcmp0(time_pref, "off") != 0) { mvwprintw(status_bar, 0, 5 + len, message); } else { mvwprintw(status_bar, 0, 1, message); } prefs_free_string(time_pref); int cols = getmaxx(stdscr); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); wattron(status_bar, bracket_attrs); mvwprintw(status_bar, 0, cols - 34, _active); mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); wattroff(status_bar, bracket_attrs); _status_bar_draw(); }
static void _win_print(ProfWin *window, const char show_char, GDateTime *time, int flags, theme_item_t theme_item, const char * const from, const char * const message) { // flags : 1st bit = 0/1 - me/not me // 2nd bit = 0/1 - date/no date // 3rd bit = 0/1 - eol/no eol // 4th bit = 0/1 - color from/no color from // 5th bit = 0/1 - color date/no date gboolean me_message = FALSE; int offset = 0; int colour = theme_attrs(THEME_ME); if ((flags & NO_DATE) == 0) { gchar *date_fmt = NULL; char *time_pref = prefs_get_string(PREF_TIME); if (g_strcmp0(time_pref, "minutes") == 0) { date_fmt = g_date_time_format(time, "%H:%M"); } else if (g_strcmp0(time_pref, "seconds") == 0) { date_fmt = g_date_time_format(time, "%H:%M:%S"); } free(time_pref); if (date_fmt) { if ((flags & NO_COLOUR_DATE) == 0) { wattron(window->win, theme_attrs(THEME_TIME)); } wprintw(window->win, "%s %c ", date_fmt, show_char); if ((flags & NO_COLOUR_DATE) == 0) { wattroff(window->win, theme_attrs(THEME_TIME)); } } g_free(date_fmt); } if (strlen(from) > 0) { if (flags & NO_ME) { colour = theme_attrs(THEME_THEM); } if (flags & NO_COLOUR_FROM) { colour = 0; } wattron(window->win, colour); if (strncmp(message, "/me ", 4) == 0) { wprintw(window->win, "*%s ", from); offset = 4; me_message = TRUE; } else { wprintw(window->win, "%s: ", from); wattroff(window->win, colour); } } if (!me_message) { wattron(window->win, theme_attrs(theme_item)); } if (prefs_get_boolean(PREF_WRAP)) { _win_print_wrapped(window->win, message+offset); } else { wprintw(window->win, "%s", message+offset); } if ((flags & NO_EOL) == 0) { wprintw(window->win, "\n"); } if (me_message) { wattroff(window->win, colour); } else { wattroff(window->win, theme_attrs(theme_item)); } }
static void _show_self_presence(void) { int presence_attrs = 0; int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); int encrypted_attrs = theme_attrs(THEME_TITLE_ENCRYPTED); int unencrypted_attrs = theme_attrs(THEME_TITLE_UNENCRYPTED); int cols = getmaxx(stdscr); int tls_start = 0; switch (current_presence) { case CONTACT_ONLINE: presence_attrs = theme_attrs(THEME_TITLE_ONLINE); wattron(win, bracket_attrs); mvwaddch(win, 0, cols - 9, '['); wattroff(win, bracket_attrs); wattron(win, presence_attrs); mvwprintw(win, 0, cols - 8, "online"); wattroff(win, presence_attrs); tls_start = 15; break; case CONTACT_AWAY: presence_attrs = theme_attrs(THEME_TITLE_AWAY); wattron(win, bracket_attrs); mvwaddch(win, 0, cols - 7, '['); wattroff(win, bracket_attrs); wattron(win, presence_attrs); mvwprintw(win, 0, cols - 6, "away"); wattroff(win, presence_attrs); tls_start = 13; break; case CONTACT_DND: presence_attrs = theme_attrs(THEME_TITLE_DND); wattron(win, bracket_attrs); mvwaddch(win, 0, cols - 6, '['); wattroff(win, bracket_attrs); wattron(win, presence_attrs); mvwprintw(win, 0, cols - 5, "dnd"); wattroff(win, presence_attrs); tls_start = 12; break; case CONTACT_CHAT: presence_attrs = theme_attrs(THEME_TITLE_CHAT); wattron(win, bracket_attrs); mvwaddch(win, 0, cols - 7, '['); wattroff(win, bracket_attrs); wattron(win, presence_attrs); mvwprintw(win, 0, cols - 6, "chat"); wattroff(win, presence_attrs); tls_start = 13; break; case CONTACT_XA: presence_attrs = theme_attrs(THEME_TITLE_XA); wattron(win, bracket_attrs); mvwaddch(win, 0, cols - 5, '['); wattroff(win, bracket_attrs); wattron(win, presence_attrs); mvwprintw(win, 0, cols - 4, "xa"); wattroff(win, presence_attrs); tls_start = 11; break; case CONTACT_OFFLINE: presence_attrs = theme_attrs(THEME_TITLE_OFFLINE); wattron(win, bracket_attrs); mvwaddch(win, 0, cols - 10, '['); wattroff(win, bracket_attrs); wattron(win, presence_attrs); mvwprintw(win, 0, cols - 9, "offline"); wattroff(win, presence_attrs); tls_start = 16; break; } wattron(win, bracket_attrs); mvwaddch(win, 0, cols - 2, ']'); wattroff(win, bracket_attrs); if (is_connected && prefs_get_boolean(PREF_TLS_SHOW)) { wattron(win, bracket_attrs); mvwaddch(win, 0, cols - tls_start, '['); wattroff(win, bracket_attrs); if (tls_secured) { wattron(win, encrypted_attrs); mvwprintw(win, 0, cols - (tls_start - 1), "TLS"); wattroff(win, encrypted_attrs); } else { wattron(win, unencrypted_attrs); mvwprintw(win, 0, cols - (tls_start - 1), "TLS"); wattroff(win, unencrypted_attrs); } wattron(win, bracket_attrs); mvwaddch(win, 0, cols - (tls_start - 4), ']'); wattroff(win, bracket_attrs); } }
static void _show_privacy(ProfChatWin *chatwin) { int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); int encrypted_attrs = theme_attrs(THEME_TITLE_ENCRYPTED); int unencrypted_attrs = theme_attrs(THEME_TITLE_UNENCRYPTED); int trusted_attrs = theme_attrs(THEME_TITLE_TRUSTED); int untrusted_attrs = theme_attrs(THEME_TITLE_UNTRUSTED); if (chatwin->enctext) { wprintw(win, " "); wattron(win, bracket_attrs); wprintw(win, "["); wattroff(win, bracket_attrs); wattron(win, encrypted_attrs); wprintw(win, chatwin->enctext); wattroff(win, encrypted_attrs); wattron(win, bracket_attrs); wprintw(win, "]"); return; } if (chatwin->is_otr) { wprintw(win, " "); wattron(win, bracket_attrs); wprintw(win, "["); wattroff(win, bracket_attrs); wattron(win, encrypted_attrs); wprintw(win, "OTR"); wattroff(win, encrypted_attrs); wattron(win, bracket_attrs); wprintw(win, "]"); wattroff(win, bracket_attrs); if (chatwin->otr_is_trusted) { wprintw(win, " "); wattron(win, bracket_attrs); wprintw(win, "["); wattroff(win, bracket_attrs); wattron(win, trusted_attrs); wprintw(win, "trusted"); wattroff(win, trusted_attrs); wattron(win, bracket_attrs); wprintw(win, "]"); wattroff(win, bracket_attrs); } else { wprintw(win, " "); wattron(win, bracket_attrs); wprintw(win, "["); wattroff(win, bracket_attrs); wattron(win, untrusted_attrs); wprintw(win, "untrusted"); wattroff(win, untrusted_attrs); wattron(win, bracket_attrs); wprintw(win, "]"); wattroff(win, bracket_attrs); } return; } if (chatwin->pgp_send || chatwin->pgp_recv) { GString *pgpmsg = g_string_new("PGP "); if (chatwin->pgp_send && !chatwin->pgp_recv) { g_string_append(pgpmsg, "send"); } else if (!chatwin->pgp_send && chatwin->pgp_recv) { g_string_append(pgpmsg, "recv"); } else { g_string_append(pgpmsg, "send/recv"); } wprintw(win, " "); wattron(win, bracket_attrs); wprintw(win, "["); wattroff(win, bracket_attrs); wattron(win, encrypted_attrs); wprintw(win, pgpmsg->str); wattroff(win, encrypted_attrs); wattron(win, bracket_attrs); wprintw(win, "]"); wattroff(win, bracket_attrs); g_string_free(pgpmsg, TRUE); return; } if (prefs_get_boolean(PREF_ENC_WARN)) { wprintw(win, " "); wattron(win, bracket_attrs); wprintw(win, "["); wattroff(win, bracket_attrs); wattron(win, unencrypted_attrs); wprintw(win, "unencrypted"); wattroff(win, unencrypted_attrs); wattron(win, bracket_attrs); wprintw(win, "]"); wattroff(win, bracket_attrs); } }
static void _show_contact_presence(ProfChatWin *chatwin) { int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); char *resource = NULL; ChatSession *session = chat_session_get(chatwin->barejid); if (chatwin->resource_override) { resource = chatwin->resource_override; } else if (session && session->resource) { resource = session->resource; } if (resource && prefs_get_boolean(PREF_RESOURCE_TITLE)) { wprintw(win, "/"); wprintw(win, resource); } if (prefs_get_boolean(PREF_PRESENCE)) { theme_item_t presence_colour = THEME_TITLE_OFFLINE; const char *presence = "offline"; jabber_conn_status_t conn_status = connection_get_status(); if (conn_status == JABBER_CONNECTED) { PContact contact = roster_get_contact(chatwin->barejid); if (contact) { if (resource) { Resource *resourcep = p_contact_get_resource(contact, resource); if (resourcep) { presence = string_from_resource_presence(resourcep->presence); } } else { presence = p_contact_presence(contact); } } } presence_colour = THEME_TITLE_ONLINE; if (g_strcmp0(presence, "offline") == 0) { presence_colour = THEME_TITLE_OFFLINE; } else if (g_strcmp0(presence, "away") == 0) { presence_colour = THEME_TITLE_AWAY; } else if (g_strcmp0(presence, "xa") == 0) { presence_colour = THEME_TITLE_XA; } else if (g_strcmp0(presence, "chat") == 0) { presence_colour = THEME_TITLE_CHAT; } else if (g_strcmp0(presence, "dnd") == 0) { presence_colour = THEME_TITLE_DND; } int presence_attrs = theme_attrs(presence_colour); wprintw(win, " "); wattron(win, bracket_attrs); wprintw(win, "["); wattroff(win, bracket_attrs); wattron(win, presence_attrs); wprintw(win, presence); wattroff(win, presence_attrs); wattron(win, bracket_attrs); wprintw(win, "]"); wattroff(win, bracket_attrs); } }
static void _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt) { // flags : 1st bit = 0/1 - me/not me // 2nd bit = 0/1 - date/no date // 3rd bit = 0/1 - eol/no eol // 4th bit = 0/1 - color from/no color from // 5th bit = 0/1 - color date/no date gboolean me_message = FALSE; int offset = 0; int colour = theme_attrs(THEME_ME); size_t indent = 0; char *time_pref = NULL; switch (window->type) { case WIN_CHAT: time_pref = prefs_get_string(PREF_TIME_CHAT); break; case WIN_MUC: time_pref = prefs_get_string(PREF_TIME_MUC); break; case WIN_MUC_CONFIG: time_pref = prefs_get_string(PREF_TIME_MUCCONFIG); break; case WIN_PRIVATE: time_pref = prefs_get_string(PREF_TIME_PRIVATE); break; case WIN_XML: time_pref = prefs_get_string(PREF_TIME_XMLCONSOLE); break; default: time_pref = prefs_get_string(PREF_TIME_CONSOLE); break; } gchar *date_fmt = NULL; if (g_strcmp0(time_pref, "off") == 0) { date_fmt = g_strdup(""); } else { date_fmt = g_date_time_format(time, time_pref); } prefs_free_string(time_pref); assert(date_fmt != NULL); if(strlen(date_fmt) != 0){ indent = 3 + strlen(date_fmt); } if ((flags & NO_DATE) == 0) { if (date_fmt && strlen(date_fmt)) { if ((flags & NO_COLOUR_DATE) == 0) { wbkgdset(window->layout->win, theme_attrs(THEME_TIME)); wattron(window->layout->win, theme_attrs(THEME_TIME)); } wprintw(window->layout->win, "%s %c ", date_fmt, show_char); if ((flags & NO_COLOUR_DATE) == 0) { wattroff(window->layout->win, theme_attrs(THEME_TIME)); } } } if (from && strlen(from) > 0) { if (flags & NO_ME) { colour = theme_attrs(THEME_THEM); } if (flags & NO_COLOUR_FROM) { colour = 0; } if (receipt && !receipt->received) { colour = theme_attrs(THEME_RECEIPT_SENT); } wbkgdset(window->layout->win, colour); wattron(window->layout->win, colour); if (strncmp(message, "/me ", 4) == 0) { wprintw(window->layout->win, "*%s ", from); offset = 4; me_message = TRUE; } else { wprintw(window->layout->win, "%s: ", from); wattroff(window->layout->win, colour); } } if (!me_message) { if (receipt && !receipt->received) { wbkgdset(window->layout->win, theme_attrs(THEME_RECEIPT_SENT)); wattron(window->layout->win, theme_attrs(THEME_RECEIPT_SENT)); } else { wbkgdset(window->layout->win, theme_attrs(theme_item)); wattron(window->layout->win, theme_attrs(theme_item)); } } if (prefs_get_boolean(PREF_WRAP)) { _win_print_wrapped(window->layout->win, message+offset, indent, pad_indent); } else { wprintw(window->layout->win, "%s", message+offset); } if ((flags & NO_EOL) == 0) { int curx = getcurx(window->layout->win); if (curx != 0) { wprintw(window->layout->win, "\n"); } } if (me_message) { wattroff(window->layout->win, colour); } else { if (receipt && !receipt->received) { wattroff(window->layout->win, theme_attrs(THEME_RECEIPT_SENT)); } else { wattroff(window->layout->win, theme_attrs(theme_item)); } } g_free(date_fmt); }