void mucwin_handle_role_list(ProfMucWin *mucwin, const char *const role, GSList *nicks) { assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; if (nicks) { win_vprint(window, '!', 0, NULL, 0, 0, "", "Role: %s", role); GSList *curr_nick = nicks; while (curr_nick) { char *nick = curr_nick->data; Occupant *occupant = muc_roster_item(mucwin->roomjid, nick); if (occupant) { if (occupant->jid) { win_vprint(window, '!', 0, NULL, 0, 0, "", " %s (%s)", nick, occupant->jid); } else { win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", nick); } } else { win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", nick); } curr_nick = g_slist_next(curr_nick); } win_print(window, '!', 0, NULL, 0, 0, "", ""); } else { win_vprint(window, '!', 0, NULL, 0, 0, "", "No occupants found with role: %s", role); win_print(window, '!', 0, NULL, 0, 0, "", ""); } }
void mucconfwin_show_form(ProfMucConfWin *confwin) { ProfWin *window = (ProfWin*) confwin; if (confwin->form->title) { win_print(window, '-', 0, NULL, NO_EOL, 0, "", "Form title: "); win_print(window, '-', 0, NULL, NO_DATE, 0, "", confwin->form->title); } else { win_vprint(window, '-', 0, NULL, 0, 0, "", "Configuration for room %s.", confwin->roomjid); } win_print(window, '-', 0, NULL, 0, 0, "", ""); mucconfwin_form_help(confwin); GSList *fields = confwin->form->fields; GSList *curr_field = fields; while (curr_field) { FormField *field = curr_field->data; if ((g_strcmp0(field->type, "fixed") == 0) && field->values) { if (field->values) { char *value = field->values->data; win_print(window, '-', 0, NULL, 0, 0, "", value); } } else if (g_strcmp0(field->type, "hidden") != 0 && field->var) { char *tag = g_hash_table_lookup(confwin->form->var_to_tag, field->var); _mucconfwin_form_field(window, tag, field); } curr_field = g_slist_next(curr_field); } }
void mucwin_requires_config(ProfMucWin *mucwin) { assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; int num = wins_get_num(window); int ui_index = num; if (ui_index == 10) { ui_index = 0; } win_print(window, '-', 0, NULL, 0, 0, "", ""); win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room locked, requires configuration."); win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Use '/room accept' to accept the defaults"); win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Use '/room destroy' to cancel and destroy the room"); win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Use '/room config' to edit the room configuration"); win_print(window, '-', 0, NULL, 0, 0, "", ""); // currently in groupchat window if (wins_is_current(window)) { status_bar_active(num); // not currently on groupchat window } else { status_bar_new(num); } }
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); } }
void chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted) { assert(chatwin != NULL); chatwin->is_otr = TRUE; chatwin->otr_is_trusted = trusted; ProfWin *window = (ProfWin*) chatwin; if (trusted) { win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); } else { win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_UNTRUSTED, "", "OTR session started (untrusted)."); } if (wins_is_current(window)) { title_bar_switch(); } else { int num = wins_get_num(window); status_bar_new(num); int ui_index = num; if (ui_index == 10) { ui_index = 0; } cons_show("%s started an OTR session (%d).", chatwin->barejid, ui_index); cons_alert(); } }
void mucconfwin_form_help(ProfMucConfWin *confwin) { assert(confwin != NULL); if (confwin->form->instructions) { ProfWin *window = (ProfWin*) confwin; win_print(window, '-', 0, NULL, 0, 0, "", "Supplied instructions:"); win_print(window, '-', 0, NULL, 0, 0, "", confwin->form->instructions); win_print(window, '-', 0, NULL, 0, 0, "", ""); } }
void privwin_message_left_room(ProfPrivateWin *privwin) { assert(privwin != NULL); win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_ERROR, NULL, "Unable to send message, you are no longer present in room."); }
void privwin_message_occupant_offline(ProfPrivateWin *privwin) { assert(privwin != NULL); win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_ERROR, NULL, "Unable to send message, occupant no longer present in room."); }
void privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message) { assert(privwin != NULL); win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); }
void win_show_occupant(ProfWin *window, Occupant *occupant) { const char *presence_str = string_from_resource_presence(occupant->presence); theme_item_t presence_colour = theme_main_presence_attrs(presence_str); win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", occupant->nick); win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); if (occupant->status) { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); } win_print(window, '-', 0, NULL, NO_DATE, presence_colour, "", ""); }
void mucconfwin_handle_configuration(ProfMucConfWin *confwin, DataForm *form) { assert(confwin != NULL); ProfWin *window = (ProfWin*)confwin; ui_focus_win(window); mucconfwin_show_form(confwin); win_print(window, '-', 0, NULL, 0, 0, "", ""); win_print(window, '-', 0, NULL, 0, 0, "", "Use '/form submit' to save changes."); win_print(window, '-', 0, NULL, 0, 0, "", "Use '/form cancel' to cancel changes."); win_print(window, '-', 0, NULL, 0, 0, "", "See '/form help' for more information."); win_print(window, '-', 0, NULL, 0, 0, "", ""); }
void ui_handle_room_config_submit_result(const char *const roomjid) { if (roomjid) { ProfWin *form_window = NULL; ProfWin *muc_window = (ProfWin*)wins_get_muc(roomjid); GString *form_recipient = g_string_new(roomjid); g_string_append(form_recipient, " config"); form_window = (ProfWin*) wins_get_muc_conf(form_recipient->str); g_string_free(form_recipient, TRUE); if (form_window) { int num = wins_get_num(form_window); wins_close_by_num(num); } if (muc_window) { ui_focus_win((ProfWin*)muc_window); win_print(muc_window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); } else { ProfWin *console = wins_get_console(); ui_focus_win(console); cons_show("Room configuration successful: %s", roomjid); } } else { cons_show("Room configuration successful"); } }
void mucwin_show_role_list(ProfMucWin *mucwin, muc_role_t role) { assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; GSList *occupants = muc_occupants_by_role(mucwin->roomjid, role); if (!occupants) { switch (role) { case MUC_ROLE_MODERATOR: win_print(window, '!', 0, NULL, 0, 0, "", "No moderators found."); break; case MUC_ROLE_PARTICIPANT: win_print(window, '!', 0, NULL, 0, 0, "", "No participants found."); break; case MUC_ROLE_VISITOR: win_print(window, '!', 0, NULL, 0, 0, "", "No visitors found."); break; default: break; } win_print(window, '-', 0, NULL, 0, 0, "", ""); } else { switch (role) { case MUC_ROLE_MODERATOR: win_print(window, '!', 0, NULL, 0, 0, "", "Moderators:"); break; case MUC_ROLE_PARTICIPANT: win_print(window, '!', 0, NULL, 0, 0, "", "Participants:"); break; case MUC_ROLE_VISITOR: win_print(window, '!', 0, NULL, 0, 0, "", "Visitors:"); break; default: break; } GSList *curr_occupant = occupants; while(curr_occupant) { Occupant *occupant = curr_occupant->data; if (occupant->role == role) { if (occupant->jid) { win_vprint(window, '!', 0, NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid); } else { win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", occupant->nick); } } curr_occupant = g_slist_next(curr_occupant); } win_print(window, '-', 0, NULL, 0, 0, "", ""); } }
void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message) { assert(chatwin != NULL); win_print((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); int num = wins_get_num((ProfWin*)chatwin); status_bar_active(num); }
void mucwin_room_info_error(ProfMucWin *mucwin, const char *const error) { assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; win_vprint(window, '!', 0, NULL, 0, 0, "", "Room info request failed: %s", error); win_print(window, '-', 0, NULL, 0, 0, "", ""); }
void win_show_contact(ProfWin *window, PContact contact) { const char *barejid = p_contact_barejid(contact); const char *name = p_contact_name(contact); const char *presence = p_contact_presence(contact); const char *status = p_contact_status(contact); GDateTime *last_activity = p_contact_last_activity(contact); theme_item_t presence_colour = theme_main_presence_attrs(presence); if (name) { win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", name); } else { win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", barejid); } win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); if (last_activity) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); g_date_time_unref(now); int hours = span / G_TIME_SPAN_HOUR; span = span - hours * G_TIME_SPAN_HOUR; int minutes = span / G_TIME_SPAN_MINUTE; span = span - minutes * G_TIME_SPAN_MINUTE; int seconds = span / G_TIME_SPAN_SECOND; if (hours > 0) { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); } else { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); } } if (status) { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); } win_print(window, '-', 0, NULL, NO_DATE, presence_colour, "", ""); }
void ui_show_lines(ProfWin *window, gchar** lines) { if (lines) { int i; for (i = 0; lines[i] != NULL; i++) { win_print(window, '-', 0, NULL, 0, 0, "", lines[i]); } } }
void ui_handle_otr_error(const char *const barejid, const char *const message) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { win_print((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_ERROR, "", message); } else { cons_show_error("%s - %s", barejid, message); } }
void win_vprint(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...) { va_list arg; va_start(arg, message); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); win_print(window, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str); g_string_free(fmt_msg, TRUE); }
void win_vprintln_ch(ProfWin *window, char ch, const char *const message, ...) { va_list arg; va_start(arg, message); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); win_print(window, ch, 0, NULL, 0, 0, "", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); }
void mucwin_handle_affiliation_list(ProfMucWin *mucwin, const char *const affiliation, GSList *jids) { assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; if (jids) { win_vprint(window, '!', 0, NULL, 0, 0, "", "Affiliation: %s", affiliation); GSList *curr_jid = jids; while (curr_jid) { char *jid = curr_jid->data; win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", jid); curr_jid = g_slist_next(curr_jid); } win_print(window, '!', 0, NULL, 0, 0, "", ""); } else { win_vprint(window, '!', 0, NULL, 0, 0, "", "No users found with affiliation: %s", affiliation); win_print(window, '!', 0, NULL, 0, 0, "", ""); } }
void ui_current_print_formatted_line(const char show_char, int attrs, const char *const msg, ...) { ProfWin *current = wins_get_current(); va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); win_print(current, show_char, 0, NULL, 0, attrs, "", fmt_msg->str); va_end(arg); g_string_free(fmt_msg, TRUE); }
void mucwin_room_disco_info(ProfMucWin *mucwin, GSList *identities, GSList *features) { assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; if ((identities && (g_slist_length(identities) > 0)) || (features && (g_slist_length(features) > 0))) { if (identities) { win_print(window, '!', 0, NULL, 0, 0, "", "Identities:"); } while (identities) { DiscoIdentity *identity = identities->data; // anme trpe, cat GString *identity_str = g_string_new(" "); if (identity->name) { identity_str = g_string_append(identity_str, identity->name); identity_str = g_string_append(identity_str, " "); } if (identity->type) { identity_str = g_string_append(identity_str, identity->type); identity_str = g_string_append(identity_str, " "); } if (identity->category) { identity_str = g_string_append(identity_str, identity->category); } win_print(window, '!', 0, NULL, 0, 0, "", identity_str->str); g_string_free(identity_str, TRUE); identities = g_slist_next(identities); } if (features) { win_print(window, '!', 0, NULL, 0, 0, "", "Features:"); } while (features) { win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", features->data); features = g_slist_next(features); } win_print(window, '-', 0, NULL, 0, 0, "", ""); } }
char* ui_ask_pgp_passphrase(const char *hint, int prev_fail) { ProfWin *current = wins_get_current(); win_println(current, 0, ""); if (prev_fail) { win_print(current, '!', 0, NULL, 0, 0, "", "Incorrect passphrase"); } if (hint) { win_vprint(current, '!', 0, NULL, 0, 0, "", "Enter PGP key passphrase for %s", hint); } else { win_print(current, '!', 0, NULL, 0, 0, "", "Enter PGP key passphrase"); } ui_update(); status_bar_get_password(); status_bar_update_virtual(); return inp_get_password(); }
void mucwin_info(ProfMucWin *mucwin) { assert(mucwin != NULL); char *role = muc_role_str(mucwin->roomjid); char *affiliation = muc_affiliation_str(mucwin->roomjid); ProfWin *window = (ProfWin*) mucwin; win_vprint(window, '!', 0, NULL, 0, 0, "", "Room: %s", mucwin->roomjid); win_vprint(window, '!', 0, NULL, 0, 0, "", "Affiliation: %s", affiliation); win_vprint(window, '!', 0, NULL, 0, 0, "", "Role: %s", role); win_print(window, '-', 0, NULL, 0, 0, "", ""); }
void ui_show_software_version(const char *const jid, const char *const presence, const char *const name, const char *const version, const char *const os) { Jid *jidp = jid_create(jid); ProfWin *window = NULL; ProfWin *chatwin = (ProfWin*)wins_get_chat(jidp->barejid); ProfWin *mucwin = (ProfWin*)wins_get_muc(jidp->barejid); ProfWin *privwin = (ProfWin*)wins_get_private(jidp->fulljid); ProfWin *console = wins_get_console(); jid_destroy(jidp); if (chatwin) { if (wins_is_current(chatwin)) { window = chatwin; } else { window = console; } } else if (privwin) { if (wins_is_current(privwin)) { window = privwin; } else { window = console; } } else if (mucwin) { if (wins_is_current(mucwin)) { window = mucwin; } else { window = console; } } else { window = console; } if (name || version || os) { win_println(window, THEME_DEFAULT, '-', ""); theme_item_t presence_colour = theme_main_presence_attrs(presence); win_print(window, presence_colour, '-', "%s", jid); win_appendln(window, THEME_DEFAULT, ":"); } if (name) { win_println(window, THEME_DEFAULT, '-', "Name : %s", name); } if (version) { win_println(window, THEME_DEFAULT, '-', "Version : %s", version); } if (os) { win_println(window, THEME_DEFAULT, '-', "OS : %s", os); } }
void chatwin_otr_untrust(ProfChatWin *chatwin) { assert(chatwin != NULL); chatwin->is_otr = TRUE; chatwin->otr_is_trusted = FALSE; ProfWin *window = (ProfWin*)chatwin; win_print(window, '!', 0, NULL, 0, THEME_OTR_UNTRUSTED, "", "OTR session untrusted."); if (wins_is_current(window)) { title_bar_switch(); } }
void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message, prof_enc_t enc_mode) { assert(chatwin != NULL); char enc_char = '-'; if (enc_mode == PROF_MSG_PGP) { enc_char = prefs_get_pgp_char(); } win_print((ProfWin*)chatwin, enc_char, 0, NULL, 0, THEME_TEXT_ME, "me", message); int num = wins_get_num((ProfWin*)chatwin); status_bar_active(num); }
void ui_handle_room_config_submit_result_error(const char *const roomjid, const char *const message) { ProfWin *console = wins_get_console(); if (roomjid) { ProfWin *muc_window = NULL; ProfWin *form_window = NULL; muc_window = (ProfWin*)wins_get_muc(roomjid); GString *form_recipient = g_string_new(roomjid); g_string_append(form_recipient, " config"); form_window = (ProfWin*) wins_get_muc_conf(form_recipient->str); g_string_free(form_recipient, TRUE); if (form_window) { if (message) { win_vprint(form_window, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); } else { win_print(form_window, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error"); } } else if (muc_window) { if (message) { win_vprint(muc_window, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); } else { win_print(muc_window, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error"); } } else { if (message) { win_vprint(console, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error for %s: %s", roomjid, message); } else { win_vprint(console, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error for %s", roomjid); } } } else { win_print(console, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error"); } }
void mucwin_roster(ProfMucWin *mucwin, GList *roster, const char *const presence) { assert(mucwin != NULL); ProfWin *window = (ProfWin*)mucwin; if ((roster == NULL) || (g_list_length(roster) == 0)) { if (presence == NULL) { win_print(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room is empty."); } else { win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "No occupants %s.", presence); } } else { int length = g_list_length(roster); if (presence == NULL) { win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "%d occupants: ", length); } else { win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "%d %s: ", length, presence); } while (roster) { Occupant *occupant = roster->data; const char *presence_str = string_from_resource_presence(occupant->presence); theme_item_t presence_colour = theme_main_presence_attrs(presence_str); win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick); if (roster->next) { win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", "); } roster = g_list_next(roster); } win_print(window, '!', 0, NULL, NO_DATE, THEME_ONLINE, "", ""); } }