void cons_show_account_list(gchar **accounts) { int size = g_strv_length(accounts); if (size > 0) { cons_show("Accounts:"); int i = 0; for (i = 0; i < size; i++) { if ((jabber_get_connection_status() == JABBER_CONNECTED) && (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { resource_presence_t presence = accounts_get_last_presence(accounts[i]); win_print_time(console, '-'); win_presence_colour_on(console, string_from_resource_presence(presence)); wprintw(console->win, "%s\n", accounts[i]); win_presence_colour_off(console, string_from_resource_presence(presence)); } else { cons_show(accounts[i]); } } cons_show(""); } else { cons_show("No accounts created yet."); cons_show(""); } ui_console_dirty(); cons_alert(); }
static void _presence_update(const resource_presence_t presence_type, const char * const msg, const int idle) { if (jabber_get_connection_status() != JABBER_CONNECTED) { log_warning("Error setting presence, not connected."); return; } if (msg != NULL) { log_debug("Updating presence: %s, \"%s\"", string_from_resource_presence(presence_type), msg); } else { log_debug("Updating presence: %s", string_from_resource_presence(presence_type)); } xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_conn_t * const conn = connection_get_conn(); const int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), presence_type); const char *show = stanza_get_presence_string_from_type(presence_type); connection_set_presence_message(msg); connection_set_priority(pri); xmpp_stanza_t *presence = stanza_create_presence(ctx); char *id = create_unique_id("presence"); xmpp_stanza_set_id(presence, id); stanza_attach_show(ctx, presence, show); stanza_attach_status(ctx, presence, msg); stanza_attach_priority(ctx, presence, pri); stanza_attach_last_activity(ctx, presence, idle); stanza_attach_caps(ctx, presence); xmpp_send(conn, presence); _send_room_presence(conn, presence); xmpp_stanza_release(presence); // set last presence for account const char *last = show; if (last == NULL) { last = STANZA_TEXT_ONLINE; } accounts_set_last_presence(jabber_get_account_name(), last); free(id); }
static int _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { char *id = xmpp_stanza_get_id(stanza); if (id != NULL) { log_debug("IQ version result handler fired, id: %s.", id); } else { log_debug("IQ version result handler fired."); } const char *jid = xmpp_stanza_get_attribute(stanza, "from"); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); if (query == NULL) { return 1; } char *ns = xmpp_stanza_get_ns(query); if (g_strcmp0(ns, STANZA_NS_VERSION) != 0) { return 1; } char *name_str = NULL; char *version_str = NULL; char *os_str = NULL; xmpp_stanza_t *name = xmpp_stanza_get_child_by_name(query, "name"); xmpp_stanza_t *version = xmpp_stanza_get_child_by_name(query, "version"); xmpp_stanza_t *os = xmpp_stanza_get_child_by_name(query, "os"); if (name != NULL) { name_str = xmpp_stanza_get_text(name); } if (version != NULL) { version_str = xmpp_stanza_get_text(version); } if (os != NULL) { os_str = xmpp_stanza_get_text(os); } PContact contact; Jid *jidp = jid_create(jid); if (muc_room_is_active(jidp->barejid)) { contact = muc_get_participant(jidp->barejid, jidp->resourcepart); } else { contact = roster_get_contact(jidp->barejid); } Resource *resource = p_contact_get_resource(contact, jidp->resourcepart); const char *presence = string_from_resource_presence(resource->presence); handle_software_version_result(jid, presence, name_str, version_str, os_str); jid_destroy(jidp); return 1; }
void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity) { assert(chatwin != NULL); const char *show = string_from_resource_presence(resource->presence); PContact contact = roster_get_contact(chatwin->barejid); char *display_str = p_contact_create_display_string(contact, resource->name); win_show_status_string((ProfWin*)chatwin, display_str, show, resource->status, last_activity, "++", "online"); free(display_str); }
const char * p_contact_presence(const PContact contact) { assert(contact != NULL); // no available resources, offline if (g_hash_table_size(contact->available_resources) == 0) { return "offline"; } Resource *resource = _get_most_available_resource(contact); return string_from_resource_presence(resource->presence); }
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 handle_contact_online(char *contact, Resource *resource, GDateTime *last_activity) { gboolean updated = roster_update_presence(contact, resource, last_activity); if (updated && prefs_get_boolean(PREF_STATUSES)) { PContact result = roster_get_contact(contact); if (p_contact_subscription(result) != NULL) { if (strcmp(p_contact_subscription(result), "none") != 0) { const char *show = string_from_resource_presence(resource->presence); ui_contact_online(contact, resource->name, show, resource->status, last_activity); ui_current_page_off(); } } } }
void cons_show_login_success(ProfAccount *account) { win_print_time(console, '-'); wprintw(console->win, "%s logged in successfully, ", account->jid); resource_presence_t presence = accounts_get_login_presence(account->name); const char *presence_str = string_from_resource_presence(presence); win_presence_colour_on(console, presence_str); wprintw(console->win, "%s", presence_str); win_presence_colour_off(console, presence_str); wprintw(console->win, " (priority %d)", accounts_get_priority_for_presence_type(account->name, presence)); wprintw(console->win, ".\n"); ui_console_dirty(); cons_alert(); }
void sv_ev_contact_online(char *barejid, Resource *resource, GDateTime *last_activity, char *pgpsig) { gboolean updated = roster_update_presence(barejid, resource, last_activity); if (updated) { plugins_on_contact_presence(barejid, resource->name, string_from_resource_presence(resource->presence), resource->status, resource->priority); ui_contact_online(barejid, resource, last_activity); } #ifdef HAVE_LIBGPGME if (pgpsig) { p_gpg_verify(barejid, pgpsig); } #endif rosterwin_roster(); chat_session_remove(barejid); }
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 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, "", ""); } }
void presence_send(const resource_presence_t presence_type, const int idle, char *signed_status) { if (connection_get_status() != JABBER_CONNECTED) { log_warning("Error setting presence, not connected."); return; } char *msg = connection_get_presence_msg(); if (msg) { log_debug("Updating presence: %s, \"%s\"", string_from_resource_presence(presence_type), msg); } else { log_debug("Updating presence: %s", string_from_resource_presence(presence_type)); } const int pri = accounts_get_priority_for_presence_type(session_get_account_name(), presence_type); connection_set_priority(pri); xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_stanza_t *presence = xmpp_presence_new(ctx); char *id = create_unique_id("presence"); xmpp_stanza_set_id(presence, id); free(id); const char *show = stanza_get_presence_string_from_type(presence_type); stanza_attach_show(ctx, presence, show); stanza_attach_status(ctx, presence, msg); if (signed_status) { xmpp_stanza_t *x = xmpp_stanza_new(ctx); xmpp_stanza_set_name(x, STANZA_NAME_X); xmpp_stanza_set_ns(x, STANZA_NS_SIGNED); xmpp_stanza_t *signed_text = xmpp_stanza_new(ctx); xmpp_stanza_set_text(signed_text, signed_status); xmpp_stanza_add_child(x, signed_text); xmpp_stanza_release(signed_text); xmpp_stanza_add_child(presence, x); xmpp_stanza_release(x); } stanza_attach_priority(ctx, presence, pri); if (idle > 0) { stanza_attach_last_activity(ctx, presence, idle); } stanza_attach_caps(ctx, presence); _send_presence_stanza(presence); _send_room_presence(presence); xmpp_stanza_release(presence); // set last presence for account const char *last = show; if (last == NULL) { last = STANZA_TEXT_ONLINE; } char *account = session_get_account_name(); accounts_set_last_presence(account, last); accounts_set_last_status(account, msg); }
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); } }
void win_show_info(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 *sub = p_contact_subscription(contact); GList *resources = p_contact_get_available_resources(contact); GList *ordered_resources = NULL; GDateTime *last_activity = p_contact_last_activity(contact); WINDOW *win = window->win; win_print_time(window, '-'); wprintw(win, "\n"); win_print_time(window, '-'); win_presence_colour_on(window, presence); wprintw(win, "%s", barejid); if (name != NULL) { wprintw(win, " (%s)", name); } win_presence_colour_off(window, presence); wprintw(win, ":\n"); if (sub != NULL) { win_print_time(window, '-'); wprintw(win, "Subscription: %s\n", sub); } if (last_activity != NULL) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); win_print_time(window, '-'); wprintw(win, "Last activity: "); int hours = span / G_TIME_SPAN_HOUR; span = span - hours * G_TIME_SPAN_HOUR; if (hours > 0) { wprintw(win, "%dh", hours); } int minutes = span / G_TIME_SPAN_MINUTE; span = span - minutes * G_TIME_SPAN_MINUTE; wprintw(win, "%dm", minutes); int seconds = span / G_TIME_SPAN_SECOND; wprintw(win, "%ds", seconds); wprintw(win, "\n"); g_date_time_unref(now); } if (resources != NULL) { win_print_time(window, '-'); wprintw(win, "Resources:\n"); // sort in order of availabiltiy while (resources != NULL) { Resource *resource = resources->data; ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability); resources = g_list_next(resources); } } while (ordered_resources != NULL) { Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); win_print_time(window, '-'); win_presence_colour_on(window, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { wprintw(win, ", \"%s\"", resource->status); } wprintw(win, "\n"); win_presence_colour_off(window, resource_presence); if (resource->caps_str != NULL) { Capabilities *caps = caps_get(resource->caps_str); if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { win_print_time(window, '-'); wprintw(win, " Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); if ((caps->category != NULL) || (caps->type != NULL)) { wprintw(win, " "); } } if (caps->type != NULL) { wprintw(win, "%s", caps->type); if (caps->category != NULL) { wprintw(win, " "); } } if (caps->category != NULL) { wprintw(win, "%s", caps->category); } wprintw(win, "\n"); } if (caps->software != NULL) { win_print_time(window, '-'); wprintw(win, " Software: %s", caps->software); } if (caps->software_version != NULL) { wprintw(win, ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { wprintw(win, "\n"); } if (caps->os != NULL) { win_print_time(window, '-'); wprintw(win, " OS: %s", caps->os); } if (caps->os_version != NULL) { wprintw(win, ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { wprintw(win, "\n"); } } } ordered_resources = g_list_next(ordered_resources); } }
void cons_show_account(ProfAccount *account) { cons_show(""); cons_show("Account %s:", account->name); if (account->enabled) { cons_show ("enabled : TRUE"); } else { cons_show ("enabled : FALSE"); } cons_show ("jid : %s", account->jid); if (account->resource != NULL) { cons_show ("resource : %s", account->resource); } if (account->server != NULL) { cons_show ("server : %s", account->server); } if (account->last_presence != NULL) { cons_show ("Last presence : %s", account->last_presence); } if (account->login_presence != NULL) { cons_show ("Login presence : %s", account->login_presence); } cons_show ("Priority : chat:%d, online:%d, away:%d, xa:%d, dnd:%d", account->priority_chat, account->priority_online, account->priority_away, account->priority_xa, account->priority_dnd); if ((jabber_get_connection_status() == JABBER_CONNECTED) && (g_strcmp0(jabber_get_account_name(), account->name) == 0)) { GList *resources = jabber_get_available_resources(); GList *ordered_resources = NULL; WINDOW *win = console->win; if (resources != NULL) { win_print_time(console, '-'); wprintw(win, "Resources:\n"); // sort in order of availabiltiy while (resources != NULL) { Resource *resource = resources->data; ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability); resources = g_list_next(resources); } } while (ordered_resources != NULL) { Resource *resource = ordered_resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); win_print_time(console, '-'); win_presence_colour_on(console, resource_presence); wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { wprintw(win, ", \"%s\"", resource->status); } wprintw(win, "\n"); win_presence_colour_off(console, resource_presence); if (resource->caps_str != NULL) { Capabilities *caps = caps_get(resource->caps_str); if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { win_print_time(console, '-'); wprintw(win, " Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); if ((caps->category != NULL) || (caps->type != NULL)) { wprintw(win, " "); } } if (caps->type != NULL) { wprintw(win, "%s", caps->type); if (caps->category != NULL) { wprintw(win, " "); } } if (caps->category != NULL) { wprintw(win, "%s", caps->category); } wprintw(win, "\n"); } if (caps->software != NULL) { win_print_time(console, '-'); wprintw(win, " Software: %s", caps->software); } if (caps->software_version != NULL) { wprintw(win, ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { wprintw(win, "\n"); } if (caps->os != NULL) { win_print_time(console, '-'); wprintw(win, " OS: %s", caps->os); } if (caps->os_version != NULL) { wprintw(win, ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { wprintw(win, "\n"); } } } ordered_resources = g_list_next(ordered_resources); } } ui_console_dirty(); cons_alert(); }
void win_show_occupant_info(ProfWin *window, const char *const room, Occupant *occupant) { const char *presence_str = string_from_resource_presence(occupant->presence); const char *occupant_affiliation = muc_occupant_affiliation_str(occupant); const char *occupant_role = muc_occupant_role_str(occupant); 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_newline(window); if (occupant->jid) { win_vprint(window, '!', 0, NULL, 0, 0, "", " Jid: %s", occupant->jid); } win_vprint(window, '!', 0, NULL, 0, 0, "", " Affiliation: %s", occupant_affiliation); win_vprint(window, '!', 0, NULL, 0, 0, "", " Role: %s", occupant_role); Jid *jidp = jid_create_from_bare_and_resource(room, occupant->nick); EntityCapabilities *caps = caps_lookup(jidp->fulljid); jid_destroy(jidp); if (caps) { // show identity if (caps->identity) { DiscoIdentity *identity = caps->identity; win_print(window, '!', 0, NULL, NO_EOL, 0, "", " Identity: "); if (identity->name) { win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->name); if (identity->category || identity->type) { win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (identity->type) { win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->type); if (identity->category) { win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (identity->category) { win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->category); } win_newline(window); } if (caps->software_version) { SoftwareVersion *software_version = caps->software_version; if (software_version->software) { win_vprint(window, '!', 0, NULL, NO_EOL, 0, "", " Software: %s", software_version->software); } if (software_version->software_version) { win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->software_version); } if (software_version->software || software_version->software_version) { win_newline(window); } if (software_version->os) { win_vprint(window, '!', 0, NULL, NO_EOL, 0, "", " OS: %s", software_version->os); } if (software_version->os_version) { win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->os_version); } if (software_version->os || software_version->os_version) { win_newline(window); } } caps_destroy(caps); } win_print(window, '-', 0, NULL, 0, 0, "", ""); }
void cons_show_caps(const char * const contact, Resource *resource) { WINDOW *win = console->win; cons_show(""); const char *resource_presence = string_from_resource_presence(resource->presence); win_print_time(console, '-'); win_presence_colour_on(console, resource_presence); wprintw(console->win, "%s", contact); win_presence_colour_off(console, resource_presence); wprintw(win, ":\n"); if (resource->caps_str != NULL) { Capabilities *caps = caps_get(resource->caps_str); if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { win_print_time(console, '-'); wprintw(win, "Identity: "); if (caps->name != NULL) { wprintw(win, "%s", caps->name); if ((caps->category != NULL) || (caps->type != NULL)) { wprintw(win, " "); } } if (caps->type != NULL) { wprintw(win, "%s", caps->type); if (caps->category != NULL) { wprintw(win, " "); } } if (caps->category != NULL) { wprintw(win, "%s", caps->category); } wprintw(win, "\n"); } if (caps->software != NULL) { win_print_time(console, '-'); wprintw(win, "Software: %s", caps->software); } if (caps->software_version != NULL) { wprintw(win, ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { wprintw(win, "\n"); } if (caps->os != NULL) { win_print_time(console, '-'); wprintw(win, "OS: %s", caps->os); } if (caps->os_version != NULL) { wprintw(win, ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { wprintw(win, "\n"); } if (caps->features != NULL) { win_print_time(console, '-'); wprintw(win, "Features:\n"); GSList *feature = caps->features; while (feature != NULL) { win_print_time(console, '-'); wprintw(win, " %s\n", feature->data); feature = g_slist_next(feature); } } } } ui_console_dirty(); cons_alert(); }
void win_show_info(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 *sub = p_contact_subscription(contact); GDateTime *last_activity = p_contact_last_activity(contact); theme_item_t presence_colour = theme_main_presence_attrs(presence); win_print(window, '-', 0, NULL, 0, 0, "", ""); win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", barejid); if (name) { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name); } win_print(window, '-', 0, NULL, NO_DATE, 0, "", ":"); if (sub) { win_vprint(window, '-', 0, NULL, 0, 0, "", "Subscription: %s", sub); } if (last_activity) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); 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, 0, 0, "", "Last activity: %dh%dm%ds", hours, minutes, seconds); } else { win_vprint(window, '-', 0, NULL, 0, 0, "", "Last activity: %dm%ds", minutes, seconds); } g_date_time_unref(now); } GList *resources = p_contact_get_available_resources(contact); GList *ordered_resources = NULL; if (resources) { win_print(window, '-', 0, NULL, 0, 0, "", "Resources:"); // sort in order of availability GList *curr = resources; while (curr) { Resource *resource = curr->data; ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability); curr = g_list_next(curr); } } g_list_free(resources); GList *curr = ordered_resources; while (curr) { Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); win_vprint(window, '-', 0, NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status) { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } win_newline(window); Jid *jidp = jid_create_from_bare_and_resource(barejid, resource->name); EntityCapabilities *caps = caps_lookup(jidp->fulljid); jid_destroy(jidp); if (caps) { // show identity if (caps->identity) { DiscoIdentity *identity = caps->identity; win_print(window, '-', 0, NULL, NO_EOL, 0, "", " Identity: "); if (identity->name) { win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->name); if (identity->category || identity->type) { win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (identity->type) { win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->type); if (identity->category) { win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (identity->category) { win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->category); } win_newline(window); } if (caps->software_version) { SoftwareVersion *software_version = caps->software_version; if (software_version->software) { win_vprint(window, '-', 0, NULL, NO_EOL, 0, "", " Software: %s", software_version->software); } if (software_version->software_version) { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->software_version); } if (software_version->software || software_version->software_version) { win_newline(window); } if (software_version->os) { win_vprint(window, '-', 0, NULL, NO_EOL, 0, "", " OS: %s", software_version->os); } if (software_version->os_version) { win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->os_version); } if (software_version->os || software_version->os_version) { win_newline(window); } } caps_destroy(caps); } curr = g_list_next(curr); } g_list_free(ordered_resources); }