Пример #1
0
void
muc_autocomplete(char *input, int *size)
{
    char *recipient = ui_current_recipient();
    Autocomplete nick_ac = muc_get_roster_ac(recipient);
    if (nick_ac != NULL) {
        input[*size] = '\0';
        gchar *last_space = g_strrstr(input, " ");
        char *result = NULL;
        if (last_space == NULL) {
            result = autocomplete_complete(nick_ac, input);
        } else {
            int len = (last_space - input);
            char *start_str = strndup(input, len);
            result = autocomplete_param_with_ac(input, size, start_str, nick_ac);
            free(start_str);
        }
        if (result != NULL) {
            ui_replace_input(input, result, size);
            g_free(result);
            return;
        }
    }
}
Пример #2
0
void
muc_autocomplete(char *input, int *size)
{
    char *recipient = ui_current_recipient();
    ChatRoom *chat_room = g_hash_table_lookup(rooms, recipient);

    if (chat_room && chat_room->nick_ac) {
        input[*size] = '\0';
        char *search_str = NULL;

        gchar *last_space = g_strrstr(input, " ");
        if (!last_space) {
            search_str = input;
            if (!chat_room->autocomplete_prefix) {
                chat_room->autocomplete_prefix = strdup("");
            }
        } else {
            search_str = last_space+1;
            if (!chat_room->autocomplete_prefix) {
                chat_room->autocomplete_prefix = g_strndup(input, search_str - input);
            }
        }

        char *result = autocomplete_complete(chat_room->nick_ac, search_str, FALSE);
        if (result) {
            GString *replace_with = g_string_new(chat_room->autocomplete_prefix);
            g_string_append(replace_with, result);
            if (!last_space || (*(last_space+1) == '\0')) {
                g_string_append(replace_with, ": ");
            }
            ui_replace_input(input, replace_with->str, size);
            g_string_free(replace_with, TRUE);
            g_free(result);
        }
    }
}