Ejemplo n.º 1
0
static
gint _compare_contacts(PContact a, PContact b)
{
    const char * utf8_str_a = NULL;
    const char * utf8_str_b = NULL;

    if (p_contact_name(a) != NULL) {
        utf8_str_a = p_contact_name(a);
    } else {
        utf8_str_a = p_contact_barejid(a);
    }
    if (p_contact_name(b) != NULL) {
        utf8_str_b = p_contact_name(b);
    } else {
        utf8_str_b = p_contact_barejid(b);
    }

    gchar *key_a = g_utf8_collate_key(utf8_str_a, -1);
    gchar *key_b = g_utf8_collate_key(utf8_str_b, -1);

    gint result = g_strcmp0(key_a, key_b);

    g_free(key_a);
    g_free(key_b);

    return result;
}
Ejemplo n.º 2
0
void
roster_send_add_to_group(const char *const group, PContact contact)
{
    GSList *groups = p_contact_groups(contact);
    GSList *new_groups = NULL;
    while (groups) {
        new_groups = g_slist_append(new_groups, strdup(groups->data));
        groups = g_slist_next(groups);
    }

    new_groups = g_slist_append(new_groups, strdup(group));
    // add an id handler to handle the response
    char *unique_id = create_unique_id(NULL);
    GroupData *data = malloc(sizeof(GroupData));
    data->group = strdup(group);
    if (p_contact_name(contact)) {
        data->name = strdup(p_contact_name(contact));
    } else {
        data->name = strdup(p_contact_barejid(contact));
    }

    xmpp_ctx_t * const ctx = connection_get_ctx();
    iq_id_handler_add(unique_id, _group_add_id_handler, (ProfIdFreeCallback)_free_group_data, data);
    xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, p_contact_barejid(contact),
        p_contact_name(contact), new_groups);
    iq_send_stanza(iq);
    xmpp_stanza_release(iq);
    free(unique_id);
}
Ejemplo n.º 3
0
void
ui_switch_win(const int i)
{
    ui_current_page_off();
    ProfWin *new_current = wins_get_by_num(i);
    if (new_current != NULL) {
        wins_set_current_by_num(i);
        ui_current_page_off();

        new_current->unread = 0;

        if (i == 1) {
            title_bar_title();
            status_bar_active(1);
        } else {
            PContact contact = roster_get_contact(new_current->from);
            if (contact != NULL) {
                if (p_contact_name(contact) != NULL) {
                    title_bar_set_recipient(p_contact_name(contact));
                } else {
                    title_bar_set_recipient(new_current->from);
                }
            } else {
                title_bar_set_recipient(new_current->from);
            }
            title_bar_draw();;
            status_bar_active(i);
        }
        wins_refresh_current();
    }
}
Ejemplo n.º 4
0
void
ui_recipient_gone(const char * const barejid)
{
    if (barejid == NULL)
        return;

    PContact contact = roster_get_contact(barejid);
    const char * display_usr = NULL;
    if (p_contact_name(contact) != NULL) {
        display_usr = p_contact_name(contact);
    } else {
        display_usr = barejid;
    }

    ProfWin *window = wins_get_by_recipient(barejid);
    if (window != NULL) {
        win_print_time(window, '!');
        wattron(window->win, COLOUR_GONE);
        wprintw(window->win, "<- %s ", display_usr);
        wprintw(window->win, "has left the conversation.");
        wprintw(window->win, "\n");
        wattroff(window->win, COLOUR_GONE);
        if (wins_is_current(window)) {
            wins_refresh_current();
        }
    }
}
Ejemplo n.º 5
0
void
roster_send_remove_from_group(const char * const group, PContact contact)
{
    GSList *groups = p_contact_groups(contact);
    GSList *new_groups = NULL;
    while (groups) {
        if (strcmp(groups->data, group) != 0) {
            new_groups = g_slist_append(new_groups, strdup(groups->data));
        }
        groups = g_slist_next(groups);
    }

    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();

    // add an id handler to handle the response
    char *unique_id = create_unique_id(NULL);
    GroupData *data = malloc(sizeof(GroupData));
    data->group = strdup(group);
    if (p_contact_name(contact)) {
        data->name = strdup(p_contact_name(contact));
    } else {
        data->name = strdup(p_contact_barejid(contact));
    }

    xmpp_id_handler_add(conn, _group_remove_handler, unique_id, data);
    xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, p_contact_barejid(contact),
        p_contact_name(contact), new_groups);
    xmpp_send(conn, iq);
    xmpp_stanza_release(iq);
    free(unique_id);
}
Ejemplo n.º 6
0
void
roster_update(const char * const barejid, const char * const name,
    GSList *groups, const char * const subscription, gboolean pending_out)
{
    PContact contact = g_hash_table_lookup(contacts, barejid);
    assert(contact != NULL);

    p_contact_set_subscription(contact, subscription);
    p_contact_set_pending_out(contact, pending_out);

    const char * const new_name = name;
    const char * current_name = NULL;
    if (p_contact_name(contact) != NULL) {
        current_name = strdup(p_contact_name(contact));
    }

    p_contact_set_name(contact, new_name);
    p_contact_set_groups(contact, groups);
    _replace_name(current_name, new_name, barejid);

    // add groups
    while (groups != NULL) {
        autocomplete_add(groups_ac, groups->data);
        groups = g_slist_next(groups);
    }
}
Ejemplo n.º 7
0
char*
roster_get_msg_display_name(const char *const barejid, const char *const resource)
{
    assert(roster != NULL);

    GString *result = g_string_new("");

    PContact contact = roster_get_contact(barejid);
    if (contact) {
        if (p_contact_name(contact)) {
            g_string_append(result, p_contact_name(contact));
        } else {
            g_string_append(result, barejid);
        }
    } else {
        g_string_append(result, barejid);
    }

    if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
        g_string_append(result, "/");
        g_string_append(result, resource);
    }

    char *result_str = result->str;
    g_string_free(result, FALSE);

    return result_str;
}
Ejemplo n.º 8
0
void
roster_change_name(PContact contact, const char * const new_name)
{
    assert(contact != NULL);

    const char *current_name = NULL;
    const char *barejid = p_contact_barejid(contact);

    if (p_contact_name(contact) != NULL) {
        current_name = strdup(p_contact_name(contact));
    }

    p_contact_set_name(contact, new_name);
    _replace_name(current_name, new_name, barejid);
}
Ejemplo n.º 9
0
void
cons_show_typing(const char * const barejid)
{
    PContact contact = roster_get_contact(barejid);
    const char * display_usr = NULL;
    if (p_contact_name(contact) != NULL) {
        display_usr = p_contact_name(contact);
    } else {
        display_usr = barejid;
    }

    win_print_time(console, '-');
    wattron(console->win, COLOUR_TYPING);
    wprintw(console->win, "!! %s is typing a message...\n", display_usr);
    wattroff(console->win, COLOUR_TYPING);

    ui_console_dirty();
    cons_alert();
}
Ejemplo n.º 10
0
void
chatwin_recipient_gone(ProfChatWin *chatwin)
{
    assert(chatwin != NULL);

    const char *display_usr = NULL;
    PContact contact = roster_get_contact(chatwin->barejid);
    if (contact) {
        if (p_contact_name(contact)) {
            display_usr = p_contact_name(contact);
        } else {
            display_usr = chatwin->barejid;
        }
    } else {
        display_usr = chatwin->barejid;
    }

    win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr);
}
Ejemplo n.º 11
0
void
ui_contact_typing(const char *const barejid, const char *const resource)
{
    ProfChatWin *chatwin = wins_get_chat(barejid);
    ProfWin *window = (ProfWin*) chatwin;
    ChatSession *session = chat_session_get(barejid);

    if (prefs_get_boolean(PREF_INTYPE)) {
        // no chat window for user
        if (chatwin == NULL) {
            cons_show_typing(barejid);

        // have chat window but not currently in it
        } else if (!wins_is_current(window)) {
            cons_show_typing(barejid);

        // in chat window with user, no session or session with resource
        } else if (!session || (session && g_strcmp0(session->resource, resource) == 0)) {
            title_bar_set_typing(TRUE);

            int num = wins_get_num(window);
            status_bar_active(num);
       }
    }

    if (prefs_get_boolean(PREF_NOTIFY_TYPING)) {
        gboolean is_current = FALSE;
        if (window) {
            is_current = wins_is_current(window);
        }
        if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT)) ) {
            PContact contact = roster_get_contact(barejid);
            char const *display_usr = NULL;
            if (p_contact_name(contact)) {
                display_usr = p_contact_name(contact);
            } else {
                display_usr = barejid;
            }
            notify_typing(display_usr);
        }
    }
}
Ejemplo n.º 12
0
void
ui_contact_online(const char * const barejid, const char * const resource,
    const char * const show, const char * const status, GDateTime *last_activity)
{
    Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
    PContact contact = roster_get_contact(barejid);
    GString *display_str = g_string_new("");

    // use nickname if exists
    if (p_contact_name(contact) != NULL) {
        g_string_append(display_str, p_contact_name(contact));
    } else {
        g_string_append(display_str, barejid);
    }

    // add resource if not default provided by profanity
    if (strcmp(jid->resourcepart, "__prof_default") != 0) {
        g_string_append(display_str, " (");
        g_string_append(display_str, jid->resourcepart);
        g_string_append(display_str, ")");
    }

    ProfWin *console = wins_get_console();
    _show_status_string(console, display_str->str, show, status, last_activity,
        "++", "online");

    ProfWin *window = wins_get_by_recipient(barejid);
    if (window != NULL) {
        _show_status_string(window, display_str->str, show, status,
            last_activity, "++", "online");
    }

    jid_destroy(jid);
    g_string_free(display_str, TRUE);

    if (wins_is_current(console)) {
        wins_refresh_current();
    } else if ((window != NULL) && (wins_is_current(window))) {
        wins_refresh_current();
    }
}
Ejemplo n.º 13
0
void
ui_contact_offline(const char * const from, const char * const show,
    const char * const status)
{
    Jid *jidp = jid_create(from);
    PContact contact = roster_get_contact(jidp->barejid);
    GString *display_str = g_string_new("");

    // use nickname if exists
    if (p_contact_name(contact) != NULL) {
        g_string_append(display_str, p_contact_name(contact));
    } else {
        g_string_append(display_str, jidp->barejid);
    }

    // add resource if not default provided by profanity
    if (strcmp(jidp->resourcepart, "__prof_default") != 0) {
        g_string_append(display_str, " (");
        g_string_append(display_str, jidp->resourcepart);
        g_string_append(display_str, ")");
    }

    ProfWin *console = wins_get_console();
    _show_status_string(console, display_str->str, show, status, NULL, "--",
        "offline");

    ProfWin *window = wins_get_by_recipient(jidp->barejid);
    if (window != NULL) {
        _show_status_string(window, display_str->str, show, status, NULL, "--",
            "offline");
    }

    jid_destroy(jidp);
    g_string_free(display_str, TRUE);

    if (wins_is_current(console)) {
        wins_refresh_current();
    } else if ((window != NULL) && (wins_is_current(window))) {
        wins_refresh_current();
    }
}
Ejemplo n.º 14
0
void
ui_contact_typing(const char * const barejid)
{
    ProfWin *window = wins_get_by_recipient(barejid);

    if (prefs_get_boolean(PREF_INTYPE)) {
        // no chat window for user
        if (window == NULL) {
            cons_show_typing(barejid);

        // have chat window but not currently in it
        } else if (!wins_is_current(window)) {
            cons_show_typing(barejid);
            wins_refresh_current();

        // in chat window with user
        } else {
            title_bar_set_typing(TRUE);
            title_bar_draw();

            int num = wins_get_num(window);
            status_bar_active(num);
            wins_refresh_current();
       }
    }

    if (prefs_get_boolean(PREF_NOTIFY_TYPING)) {
        PContact contact = roster_get_contact(barejid);
        char const *display_usr = NULL;
        if (p_contact_name(contact) != NULL) {
            display_usr = p_contact_name(contact);
        } else {
            display_usr = barejid;
        }
        notify_typing(display_usr);
    }
}
Ejemplo n.º 15
0
void
cons_show_room_invite(const char * const invitor, const char * const room,
    const char * const reason)
{
    char *display_from = NULL;
    PContact contact = roster_get_contact(invitor);
    if (contact != NULL) {
        if (p_contact_name(contact) != NULL) {
            display_from = strdup(p_contact_name(contact));
        } else {
            display_from = strdup(invitor);
        }
    } else {
        display_from = strdup(invitor);
    }

    cons_show("");
    cons_show("Chat room invite received:");
    cons_show("  From   : %s", display_from);
    cons_show("  Room   : %s", room);

    if (reason != NULL) {
        cons_show("  Message: %s", reason);
    }

    cons_show("Use /join or /decline");

    if (prefs_get_boolean(PREF_NOTIFY_INVITE)) {
        notify_invite(display_from, room, reason);
    }

    free(display_from);

    ui_console_dirty();
    cons_alert();
}
Ejemplo n.º 16
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);

    win_print_time(window, '-');
    win_presence_colour_on(window, presence);

    if (name != NULL) {
        wprintw(window->win, "%s", name);
    } else {
        wprintw(window->win, "%s", barejid);
    }

    wprintw(window->win, " is %s", presence);

    if (last_activity != NULL) {
        GDateTime *now = g_date_time_new_now_local();
        GTimeSpan span = g_date_time_difference(now, last_activity);

        wprintw(window->win, ", idle ");

        int hours = span / G_TIME_SPAN_HOUR;
        span = span - hours * G_TIME_SPAN_HOUR;
        if (hours > 0) {
            wprintw(window->win, "%dh", hours);
        }

        int minutes = span / G_TIME_SPAN_MINUTE;
        span = span - minutes * G_TIME_SPAN_MINUTE;
        wprintw(window->win, "%dm", minutes);

        int seconds = span / G_TIME_SPAN_SECOND;
        wprintw(window->win, "%ds", seconds);
    }

    if (status != NULL) {
        wprintw(window->win, ", \"%s\"", p_contact_status(contact));
    }

    wprintw(window->win, "\n");
    win_presence_colour_off(window, presence);
}
Ejemplo n.º 17
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, "", "");
}
Ejemplo n.º 18
0
void
_show_roster_contacts(GSList *list, gboolean show_groups)
{
    GSList *curr = list;
    while(curr) {

        PContact contact = curr->data;
        GString *title = g_string_new("  ");
        title = g_string_append(title, p_contact_barejid(contact));
        if (p_contact_name(contact) != NULL) {
            title = g_string_append(title, " (");
            title = g_string_append(title, p_contact_name(contact));
            title = g_string_append(title, ")");
        }

        const char *presence = p_contact_presence(contact);
        win_print_time(console, '-');
        if (p_contact_subscribed(contact)) {
            win_presence_colour_on(console, presence);
            wprintw(console->win, "%s\n", title->str);
            win_presence_colour_off(console, presence);
        } else {
            win_presence_colour_on(console, "offline");
            wprintw(console->win, "%s\n", title->str);
            win_presence_colour_off(console, "offline");
        }

        g_string_free(title, TRUE);

        win_print_time(console, '-');
        wprintw(console->win, "    Subscription : ");
        GString *sub = g_string_new("");
        sub = g_string_append(sub, p_contact_subscription(contact));
        if (p_contact_pending_out(contact)) {
            sub = g_string_append(sub, ", request sent");
        }
        if (presence_sub_request_exists(p_contact_barejid(contact))) {
            sub = g_string_append(sub, ", request received");
        }
        if (p_contact_subscribed(contact)) {
            wattron(console->win, COLOUR_SUBSCRIBED);
        } else {
            wattron(console->win, COLOUR_UNSUBSCRIBED);
        }
        wprintw(console->win, "%s\n", sub->str);
        if (p_contact_subscribed(contact)) {
            wattroff(console->win, COLOUR_SUBSCRIBED);
        } else {
            wattroff(console->win, COLOUR_UNSUBSCRIBED);
        }

        g_string_free(sub, TRUE);

        if (show_groups) {
            GSList *groups = p_contact_groups(contact);
            if (groups != NULL) {
                GString *groups_str = g_string_new("    Groups : ");
                while (groups != NULL) {
                    g_string_append(groups_str, groups->data);
                    if (g_slist_next(groups) != NULL) {
                        g_string_append(groups_str, ", ");
                    }
                    groups = g_slist_next(groups);
                }

                cons_show(groups_str->str);
                g_string_free(groups_str, TRUE);
            }
        }

        curr = g_slist_next(curr);
    }

}
Ejemplo n.º 19
0
void
ui_incoming_msg(const char * const from, const char * const message,
    GTimeVal *tv_stamp, gboolean priv)
{
    gboolean win_created = FALSE;
    char *display_from = NULL;
    win_type_t win_type;

    if (priv) {
        win_type = WIN_PRIVATE;
        display_from = get_nick_from_full_jid(from);
    } else {
        win_type = WIN_CHAT;
        PContact contact = roster_get_contact(from);
        if (contact != NULL) {
            if (p_contact_name(contact) != NULL) {
                display_from = strdup(p_contact_name(contact));
            } else {
                display_from = strdup(from);
            }
        } else {
            display_from = strdup(from);
        }
    }

    ProfWin *window = wins_get_by_recipient(from);
    if (window == NULL) {
        window = wins_new(from, win_type);
        win_created = TRUE;
    }

    int num = wins_get_num(window);

    // currently viewing chat window with sender
    if (wins_is_current(window)) {
        if (tv_stamp == NULL) {
            win_print_time(window, '-');
        } else {
            GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
            gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
            wattron(window->win, COLOUR_TIME);
            wprintw(window->win, "%s - ", date_fmt);
            wattroff(window->win, COLOUR_TIME);
            g_date_time_unref(time);
            g_free(date_fmt);
        }

        if (strncmp(message, "/me ", 4) == 0) {
            wattron(window->win, COLOUR_THEM);
            wprintw(window->win, "*%s ", display_from);
            waddstr(window->win, message + 4);
            wprintw(window->win, "\n");
            wattroff(window->win, COLOUR_THEM);
        } else {
            _win_show_user(window->win, display_from, 1);
            _win_show_message(window->win, message);
        }
        title_bar_set_typing(FALSE);
        title_bar_draw();
        status_bar_active(num);
        wins_refresh_current();

    // not currently viewing chat window with sender
    } else {
        status_bar_new(num);
        cons_show_incoming_message(display_from, num);
        if (prefs_get_boolean(PREF_FLASH))
            flash();

        window->unread++;
        if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
            _win_show_history(window->win, num, from);
        }

        if (tv_stamp == NULL) {
            win_print_time(window, '-');
        } else {
            // show users status first, when receiving message via delayed delivery
            if (win_created) {
                PContact pcontact = roster_get_contact(from);
                if (pcontact != NULL) {
                    win_show_contact(window, pcontact);
                }
            }
            GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
            gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
            wattron(window->win, COLOUR_TIME);
            wprintw(window->win, "%s - ", date_fmt);
            wattroff(window->win, COLOUR_TIME);
            g_date_time_unref(time);
            g_free(date_fmt);
        }

        if (strncmp(message, "/me ", 4) == 0) {
            wattron(window->win, COLOUR_THEM);
            wprintw(window->win, "*%s ", display_from);
            waddstr(window->win, message + 4);
            wprintw(window->win, "\n");
            wattroff(window->win, COLOUR_THEM);
        } else {
            _win_show_user(window->win, display_from, 1);
            _win_show_message(window->win, message);
        }
    }

    int ui_index = num;
    if (ui_index == 10) {
        ui_index = 0;
    }

    if (prefs_get_boolean(PREF_BEEP))
        beep();
    if (prefs_get_boolean(PREF_NOTIFY_MESSAGE))
        notify_message(display_from, ui_index);

    free(display_from);
}
Ejemplo n.º 20
0
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);
    }
}
Ejemplo n.º 21
0
void
roster_update(const char *const barejid, const char *const name, GSList *groups, const char *const subscription,
    gboolean pending_out)
{
    assert(roster != NULL);

    PContact contact = roster_get_contact(barejid);
    assert(contact != NULL);

    p_contact_set_subscription(contact, subscription);
    p_contact_set_pending_out(contact, pending_out);

    const char * const new_name = name;
    const char * current_name = NULL;
    if (p_contact_name(contact)) {
        current_name = strdup(p_contact_name(contact));
    }

    p_contact_set_name(contact, new_name);
    _replace_name(current_name, new_name, barejid);

    GSList *curr_new_group = groups;
    while (curr_new_group) {
        char *new_group = curr_new_group->data;

        // contact added to group
        if (!p_contact_in_group(contact, new_group)) {

            // group doesn't yet exist
            if (!g_hash_table_contains(roster->group_count, new_group)) {
                g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(1));
                autocomplete_add(roster->groups_ac, curr_new_group->data);

            // increment count
            } else {
                int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, new_group));
                g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(count + 1));
            }
        }
        curr_new_group = g_slist_next(curr_new_group);
    }

    GSList *old_groups = p_contact_groups(contact);
    GSList *curr_old_group = old_groups;
    while (curr_old_group) {
        char *old_group = curr_old_group->data;
        // removed from group
        if (!g_slist_find_custom(groups, old_group, (GCompareFunc)g_strcmp0)) {
            if (g_hash_table_contains(roster->group_count, old_group)) {
                int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, old_group));
                count--;
                if (count < 1) {
                    g_hash_table_remove(roster->group_count, old_group);
                    autocomplete_remove(roster->groups_ac, old_group);
                } else {
                    g_hash_table_insert(roster->group_count, strdup(old_group), GINT_TO_POINTER(count));
                }
            }
        }

        curr_old_group = g_slist_next(curr_old_group);
    }

    p_contact_set_groups(contact, groups);
}
Ejemplo n.º 22
0
void
cons_show_wins(void)
{
    int i = 0;
    int count = 0;
    int ui_index = 0;

    cons_show("");
    cons_show("Active windows:");
    win_print_time(console, '-');
    wprintw(console->win, "1: Console\n");

    for (i = 1; i < NUM_WINS; i++) {
        if (windows[i] != NULL) {
            count++;
        }
    }

    if (count != 0) {
        for (i = 1; i < NUM_WINS; i++) {
            if (windows[i] != NULL) {
                ProfWin *window = windows[i];
                win_print_time(console, '-');
                ui_index = i + 1;
                if (ui_index == 10) {
                    ui_index = 0;
                }

                switch (window->type)
                {
                    case WIN_CHAT:
                        wprintw(console->win, "%d: Chat %s", ui_index, window->from);
                        PContact contact = roster_get_contact(window->from);

                        if (contact != NULL) {
                            if (p_contact_name(contact) != NULL) {
                                wprintw(console->win, " (%s)", p_contact_name(contact));
                            }
                            wprintw(console->win, " - %s", p_contact_presence(contact));
                        }

                        if (window->unread > 0) {
                            wprintw(console->win, ", %d unread", window->unread);
                        }

                        break;

                    case WIN_PRIVATE:
                        wprintw(console->win, "%d: Private %s", ui_index, window->from);

                        if (window->unread > 0) {
                            wprintw(console->win, ", %d unread", window->unread);
                        }

                        break;

                    case WIN_MUC:
                        wprintw(console->win, "%d: Room %s", ui_index, window->from);

                        if (window->unread > 0) {
                            wprintw(console->win, ", %d unread", window->unread);
                        }

                        break;

                    case WIN_DUCK:
                        wprintw(console->win, "%d: DuckDuckGo search", ui_index);

                        break;

                    default:
                        break;
                }

                wprintw(console->win, "\n");
            }
        }
    }

    cons_show("");
    ui_console_dirty();
    cons_alert();
}
Ejemplo n.º 23
0
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);
}